Annotation of loncom/interface/domainprefs.pm, revision 1.447.2.5
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.447.2.5! raeburn 4: # $Id: domainprefs.pm,v 1.447.2.4 2025/01/14 13:20:29 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.447.2.1 raeburn 225: 'privacy','passwords','wafproxy',
1.429 raeburn 226: 'ipaccess','authordefaults'],$dom);
1.320 raeburn 227: my %encconfig =
1.447.2.1 raeburn 228: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','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.394 raeburn 291: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
292: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373 raeburn 293: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 294: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 295: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.447.2.1 raeburn 296: 'authordefaults','ltitools','selfenrollment',
1.429 raeburn 297: 'usersessions','ssl','trust','lti');
1.171 raeburn 298: my %existing;
299: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
300: %existing = %{$domconfig{'loadbalancing'}};
301: }
302: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 303: push(@prefs_order,'loadbalancing');
304: }
1.30 raeburn 305: my %prefs = (
306: 'rolecolors' =>
307: { text => 'Default color schemes',
1.67 raeburn 308: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 309: header => [{col1 => 'Student Settings',
310: col2 => '',},
311: {col1 => 'Coordinator Settings',
312: col2 => '',},
313: {col1 => 'Author Settings',
314: col2 => '',},
315: {col1 => 'Administrator Settings',
316: col2 => '',}],
1.230 raeburn 317: print => \&print_rolecolors,
318: modify => \&modify_rolecolors,
1.30 raeburn 319: },
1.110 raeburn 320: 'login' =>
1.30 raeburn 321: { text => 'Log-in page options',
1.67 raeburn 322: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 323: header => [{col1 => 'Log-in Page Items',
324: col2 => '',},
325: {col1 => 'Log-in Help',
1.256 raeburn 326: col2 => 'Value'},
327: {col1 => 'Custom HTML in document head',
1.386 raeburn 328: col2 => 'Value'},
329: {col1 => 'SSO',
330: col2 => 'Dual login: SSO and non-SSO options'},
331: ],
1.230 raeburn 332: print => \&print_login,
333: modify => \&modify_login,
1.30 raeburn 334: },
1.43 raeburn 335: 'defaults' =>
1.236 raeburn 336: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 337: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 338: header => [{col1 => 'Setting',
1.236 raeburn 339: col2 => 'Value'},
340: {col1 => 'Institutional user types',
1.409 raeburn 341: col2 => 'Name displayed'},
342: {col1 => 'Mapping for missing usernames via standard log-in',
343: col2 => 'Rules in use'}],
1.230 raeburn 344: print => \&print_defaults,
345: modify => \&modify_defaults,
1.43 raeburn 346: },
1.381 raeburn 347: 'wafproxy' =>
348: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 349: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 350: header => [{col1 => 'Domain(s)',
351: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 352: },
1.381 raeburn 353: {col1 => 'Domain(s)',
354: col2 => 'WAF Configuration',}],
1.373 raeburn 355: print => \&print_wafproxy,
1.381 raeburn 356: modify => \&modify_wafproxy,
1.373 raeburn 357: },
1.354 raeburn 358: 'passwords' =>
359: { text => 'Passwords (Internal authentication)',
360: help => 'Domain_Configuration_Passwords',
361: header => [{col1 => 'Resetting Forgotten Password',
362: col2 => 'Settings'},
363: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
364: col2 => 'Settings'},
365: {col1 => 'Rules for LON-CAPA Passwords',
366: col2 => 'Settings'},
367: {col1 => 'Course Owner Changing Student Passwords',
368: col2 => 'Settings'}],
369: print => \&print_passwords,
370: modify => \&modify_passwords,
371: },
1.30 raeburn 372: 'quotas' =>
1.429 raeburn 373: { text => 'Blogs, personal pages/timezones, portfolio/quotas',
1.67 raeburn 374: help => 'Domain_Configuration_Quotas',
1.77 raeburn 375: header => [{col1 => 'User affiliation',
1.72 raeburn 376: col2 => 'Available tools',
1.435 raeburn 377: col3 => 'Portfolio quota (MB)',}],
1.230 raeburn 378: print => \&print_quotas,
379: modify => \&modify_quotas,
1.30 raeburn 380: },
381: 'autoenroll' =>
382: { text => 'Auto-enrollment settings',
1.67 raeburn 383: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 384: header => [{col1 => 'Configuration setting',
385: col2 => 'Value(s)'}],
1.230 raeburn 386: print => \&print_autoenroll,
387: modify => \&modify_autoenroll,
1.30 raeburn 388: },
389: 'autoupdate' =>
390: { text => 'Auto-update settings',
1.67 raeburn 391: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 392: header => [{col1 => 'Setting',
393: col2 => 'Value',},
1.131 raeburn 394: {col1 => 'Setting',
395: col2 => 'Affiliation'},
1.43 raeburn 396: {col1 => 'User population',
1.227 bisitz 397: col2 => 'Updatable user data'}],
1.230 raeburn 398: print => \&print_autoupdate,
399: modify => \&modify_autoupdate,
1.30 raeburn 400: },
1.125 raeburn 401: 'autocreate' =>
402: { text => 'Auto-course creation settings',
403: help => 'Domain_Configuration_Auto_Creation',
404: header => [{col1 => 'Configuration Setting',
405: col2 => 'Value',}],
1.230 raeburn 406: print => \&print_autocreate,
407: modify => \&modify_autocreate,
1.125 raeburn 408: },
1.30 raeburn 409: 'directorysrch' =>
1.277 raeburn 410: { text => 'Directory searches',
1.67 raeburn 411: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 412: header => [{col1 => 'Institutional Directory Setting',
413: col2 => 'Value',},
414: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 415: col2 => 'Value',}],
1.230 raeburn 416: print => \&print_directorysrch,
417: modify => \&modify_directorysrch,
1.30 raeburn 418: },
419: 'contacts' =>
1.286 raeburn 420: { text => 'E-mail addresses and helpform',
1.67 raeburn 421: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 422: header => [{col1 => 'Default e-mail addresses',
423: col2 => 'Value',},
424: {col1 => 'Recipient(s) for notifications',
425: col2 => 'Value',},
1.340 raeburn 426: {col1 => 'Nightly status check e-mail',
427: col2 => 'Settings',},
1.286 raeburn 428: {col1 => 'Ask helpdesk form settings',
429: col2 => 'Value',},],
1.230 raeburn 430: print => \&print_contacts,
431: modify => \&modify_contacts,
1.30 raeburn 432: },
433: 'usercreation' =>
434: { text => 'User creation',
1.67 raeburn 435: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 436: header => [{col1 => 'Format rule type',
437: col2 => 'Format rules in force'},
1.34 raeburn 438: {col1 => 'User account creation',
439: col2 => 'Usernames which may be created',},
1.30 raeburn 440: {col1 => 'Context',
1.43 raeburn 441: col2 => 'Assignable authentication types'}],
1.230 raeburn 442: print => \&print_usercreation,
443: modify => \&modify_usercreation,
1.30 raeburn 444: },
1.224 raeburn 445: 'selfcreation' =>
446: { text => 'Users self-creating accounts',
447: help => 'Domain_Configuration_Self_Creation',
448: header => [{col1 => 'Self-creation with institutional username',
449: col2 => 'Enabled?'},
450: {col1 => 'Institutional user type (login/SSO self-creation)',
451: col2 => 'Information user can enter'},
1.303 raeburn 452: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 453: col2 => 'Settings'}],
1.230 raeburn 454: print => \&print_selfcreation,
455: modify => \&modify_selfcreation,
1.224 raeburn 456: },
1.69 raeburn 457: 'usermodification' =>
1.33 raeburn 458: { text => 'User modification',
1.67 raeburn 459: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 460: header => [{col1 => 'Target user has role',
1.227 bisitz 461: col2 => 'User information updatable in author context'},
1.33 raeburn 462: {col1 => 'Target user has role',
1.443 raeburn 463: col2 => 'User information updatable by co-author manager'},
464: {col1 => 'Target user has role',
1.227 bisitz 465: col2 => 'User information updatable in course context'}],
1.230 raeburn 466: print => \&print_usermodification,
467: modify => \&modify_usermodification,
1.33 raeburn 468: },
1.69 raeburn 469: 'scantron' =>
1.346 raeburn 470: { text => 'Bubblesheet format',
1.67 raeburn 471: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 472: header => [ {col1 => 'Bubblesheet format file',
473: col2 => ''},
474: {col1 => 'Bubblesheet data upload formats',
475: col2 => 'Settings'}],
1.230 raeburn 476: print => \&print_scantron,
477: modify => \&modify_scantron,
1.46 raeburn 478: },
1.86 raeburn 479: 'requestcourses' =>
480: {text => 'Request creation of courses',
481: help => 'Domain_Configuration_Request_Courses',
482: header => [{col1 => 'User affiliation',
1.102 raeburn 483: col2 => 'Availability/Processing of requests',},
484: {col1 => 'Setting',
1.216 raeburn 485: col2 => 'Value'},
486: {col1 => 'Available textbooks',
1.235 raeburn 487: col2 => ''},
1.242 raeburn 488: {col1 => 'Available templates',
489: col2 => ''},
1.235 raeburn 490: {col1 => 'Validation (not official courses)',
491: col2 => 'Value'},],
1.230 raeburn 492: print => \&print_quotas,
493: modify => \&modify_quotas,
1.86 raeburn 494: },
1.163 raeburn 495: 'requestauthor' =>
1.223 bisitz 496: {text => 'Request Authoring Space',
1.163 raeburn 497: help => 'Domain_Configuration_Request_Author',
498: header => [{col1 => 'User affiliation',
499: col2 => 'Availability/Processing of requests',},
500: {col1 => 'Setting',
501: col2 => 'Value'}],
1.230 raeburn 502: print => \&print_quotas,
503: modify => \&modify_quotas,
1.163 raeburn 504: },
1.69 raeburn 505: 'coursecategories' =>
1.120 raeburn 506: { text => 'Cataloging of courses/communities',
1.67 raeburn 507: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 508: header => [{col1 => 'Catalog type/availability',
509: col2 => '',},
510: {col1 => 'Category settings for standard catalog',
1.57 raeburn 511: col2 => '',},
512: {col1 => 'Categories',
513: col2 => '',
514: }],
1.230 raeburn 515: print => \&print_coursecategories,
516: modify => \&modify_coursecategories,
1.69 raeburn 517: },
518: 'serverstatuses' =>
1.77 raeburn 519: {text => 'Access to server status pages',
1.69 raeburn 520: help => 'Domain_Configuration_Server_Status',
521: header => [{col1 => 'Status Page',
522: col2 => 'Other named users',
523: col3 => 'Specific IPs',
524: }],
1.230 raeburn 525: print => \&print_serverstatuses,
526: modify => \&modify_serverstatuses,
1.69 raeburn 527: },
1.118 jms 528: 'helpsettings' =>
1.282 raeburn 529: {text => 'Support settings',
1.118 jms 530: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 531: header => [{col1 => 'Help Page Settings (logged-in users)',
532: col2 => 'Value'},
533: {col1 => 'Helpdesk Roles',
534: col2 => 'Settings'},],
1.230 raeburn 535: print => \&print_helpsettings,
536: modify => \&modify_helpsettings,
1.118 jms 537: },
1.121 raeburn 538: 'coursedefaults' =>
539: {text => 'Course/Community defaults',
540: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 541: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
542: col2 => 'Value',},
543: {col1 => 'Defaults which can be overridden for each course by a DC',
544: col2 => 'Value',},],
1.230 raeburn 545: print => \&print_coursedefaults,
546: modify => \&modify_coursedefaults,
1.121 raeburn 547: },
1.231 raeburn 548: 'selfenrollment' =>
549: {text => 'Self-enrollment in Course/Community',
550: help => 'Domain_Configuration_Selfenrollment',
551: header => [{col1 => 'Configuration Rights',
552: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
553: {col1 => 'Defaults',
554: col2 => 'Value'},
555: {col1 => 'Self-enrollment validation (optional)',
556: col2 => 'Value'},],
557: print => \&print_selfenrollment,
558: modify => \&modify_selfenrollment,
559: },
1.120 raeburn 560: 'privacy' =>
1.427 raeburn 561: {text => 'Role assignments and user privacy',
1.120 raeburn 562: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 563: header => [{col1 => 'Role assigned in different domain',
564: col2 => 'Approval options'},
565: {col1 => 'Role assigned in different domain to user of type',
1.447.2.4 raeburn 566: col2 => 'User information available in that domain'}],
1.230 raeburn 567: print => \&print_privacy,
568: modify => \&modify_privacy,
1.120 raeburn 569: },
1.141 raeburn 570: 'usersessions' =>
1.145 raeburn 571: {text => 'User session hosting/offloading',
1.137 raeburn 572: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 573: header => [{col1 => 'Domain server',
574: col2 => 'Servers to offload sessions to when busy'},
575: {col1 => 'Hosting of users from other domains',
1.137 raeburn 576: col2 => 'Rules'},
577: {col1 => "Hosting domain's own users elsewhere",
578: col2 => 'Rules'}],
1.230 raeburn 579: print => \&print_usersessions,
580: modify => \&modify_usersessions,
1.137 raeburn 581: },
1.279 raeburn 582: 'loadbalancing' =>
1.185 raeburn 583: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 584: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 585: header => [{col1 => 'Balancers',
1.150 raeburn 586: col2 => 'Default destinations',
1.183 bisitz 587: col3 => 'User affiliation',
1.150 raeburn 588: col4 => 'Overrides'},
589: ],
1.230 raeburn 590: print => \&print_loadbalancing,
591: modify => \&modify_loadbalancing,
1.150 raeburn 592: },
1.425 raeburn 593: 'ltitools' =>
1.267 raeburn 594: {text => 'External Tools (LTI)',
1.296 raeburn 595: help => 'Domain_Configuration_LTI_Tools',
1.421 raeburn 596: header => [{col1 => 'Encryption of shared secrets',
597: col2 => 'Settings'},
598: {col1 => 'Rules for shared secrets',
599: col2 => 'Settings'},
600: {col1 => 'Providers',
601: col2 => 'Settings',}],
1.267 raeburn 602: print => \&print_ltitools,
603: modify => \&modify_ltitools,
604: },
1.279 raeburn 605: 'ssl' =>
1.275 raeburn 606: {text => 'LON-CAPA Network (SSL)',
607: help => 'Domain_Configuration_Network_SSL',
608: header => [{col1 => 'Server',
609: col2 => 'Certificate Status'},
610: {col1 => 'Connections to other servers',
611: col2 => 'Rules'},
1.293 raeburn 612: {col1 => 'Connections from other servers',
613: col2 => 'Rules'},
1.275 raeburn 614: {col1 => "Replicating domain's published content",
615: col2 => 'Rules'}],
616: print => \&print_ssl,
617: modify => \&modify_ssl,
618: },
1.279 raeburn 619: 'trust' =>
620: {text => 'Trust Settings',
621: help => 'Domain_Configuration_Trust',
622: header => [{col1 => "Access to this domain's content by others",
623: col2 => 'Rules'},
624: {col1 => "Access to other domain's content by this domain",
625: col2 => 'Rules'},
626: {col1 => "Enrollment in this domain's courses by others",
627: col2 => 'Rules',},
628: {col1 => "Co-author roles in this domain for others",
629: col2 => 'Rules',},
630: {col1 => "Co-author roles for this domain's users elsewhere",
631: col2 => 'Rules',},
632: {col1 => "Domain roles in this domain assignable to others",
633: col2 => 'Rules'},
634: {col1 => "Course catalog for this domain displayed elsewhere",
635: col2 => 'Rules'},
636: {col1 => "Requests for creation of courses in this domain by others",
637: col2 => 'Rules'},
638: {col1 => "Users in other domains can send messages to this domain",
639: col2 => 'Rules'},],
640: print => \&print_trust,
641: modify => \&modify_trust,
642: },
1.425 raeburn 643: 'lti' =>
1.405 raeburn 644: {text => 'LTI Link Protection and LTI Consumers',
1.320 raeburn 645: help => 'Domain_Configuration_LTI_Provider',
1.405 raeburn 646: header => [{col1 => 'Encryption of shared secrets',
647: col2 => 'Settings'},
1.425 raeburn 648: {col1 => 'Rules for shared secrets',
1.405 raeburn 649: col2 => 'Settings'},
1.434 raeburn 650: {col1 => 'Link Protectors in Courses',
1.436 raeburn 651: col2 => 'Values'},
1.406 raeburn 652: {col1 => 'Link Protectors',
1.405 raeburn 653: col2 => 'Settings'},
654: {col1 => 'Consumers',
655: col2 => 'Settings'},],
1.320 raeburn 656: print => \&print_lti,
657: modify => \&modify_lti,
658: },
1.425 raeburn 659: 'ipaccess' =>
1.394 raeburn 660: {text => 'IP-based access control',
661: help => 'Domain_Configuration_IP_Access',
662: header => [{col1 => 'Setting',
663: col2 => 'Value'},],
664: print => \&print_ipaccess,
665: modify => \&modify_ipaccess,
666: },
1.436 raeburn 667: 'authordefaults' =>
1.429 raeburn 668: {text => 'Authoring Space defaults',
669: help => 'Domain_Configuration_Author_Defaults',
670: header => [{col1 => 'Defaults which can be overridden by Author',
671: col2 => 'Settings',},
672: {col1 => 'Defaults which can be overridden by a Dom. Coord.',
673: col2 => 'Settings',},],
674: print => \&print_authordefaults,
675: modify => \&modify_authordefaults,
676: },
1.3 raeburn 677: );
1.110 raeburn 678: if (keys(%servers) > 1) {
679: $prefs{'login'} = { text => 'Log-in page options',
680: help => 'Domain_Configuration_Login_Page',
681: header => [{col1 => 'Log-in Service',
682: col2 => 'Server Setting',},
683: {col1 => 'Log-in Page Items',
1.405 raeburn 684: col2 => 'Settings'},
1.168 raeburn 685: {col1 => 'Log-in Help',
1.256 raeburn 686: col2 => 'Value'},
687: {col1 => 'Custom HTML in document head',
1.386 raeburn 688: col2 => 'Value'},
689: {col1 => 'SSO',
690: col2 => 'Dual login: SSO and non-SSO options'},
691: ],
1.230 raeburn 692: print => \&print_login,
693: modify => \&modify_login,
1.110 raeburn 694: };
695: }
1.174 foxr 696:
1.6 raeburn 697: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 698: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 699: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 700: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 701: text=>"Settings to display/modify"});
1.9 raeburn 702: my $confname = $dom.'-domainconfig';
1.174 foxr 703:
1.3 raeburn 704: if ($phase eq 'process') {
1.212 raeburn 705: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
706: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 707: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 708: $r->rflush();
1.212 raeburn 709: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 710: }
1.30 raeburn 711: } elsif ($phase eq 'display') {
1.192 raeburn 712: my $js = &recaptcha_js().
1.236 raeburn 713: &toggle_display_js();
1.171 raeburn 714: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 715: my ($othertitle,$usertypes,$types) =
716: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 717: $js .= &lonbalance_targets_js($dom,$types,\%servers,
718: $domconfig{'loadbalancing'}).
1.170 raeburn 719: &new_spares_js().
720: &common_domprefs_js().
721: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 722: }
1.216 raeburn 723: if (grep(/^requestcourses$/,@actions)) {
724: my $javascript_validations;
725: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
726: $js .= <<END;
727: <script type="text/javascript">
728: $javascript_validations
729: </script>
730: $coursebrowserjs
731: END
1.394 raeburn 732: } elsif (grep(/^ipaccess$/,@actions)) {
733: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 734: }
1.305 raeburn 735: if (grep(/^selfcreation$/,@actions)) {
736: $js .= &selfcreate_javascript();
737: }
1.286 raeburn 738: if (grep(/^contacts$/,@actions)) {
739: $js .= &contacts_javascript();
740: }
1.346 raeburn 741: if (grep(/^scantron$/,@actions)) {
742: $js .= &scantron_javascript();
743: }
1.150 raeburn 744: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 745: } else {
1.180 raeburn 746: # check if domconfig user exists for the domain.
747: my $servadm = $r->dir_config('lonAdmEMail');
748: my ($configuserok,$author_ok,$switchserver) =
749: &config_check($dom,$confname,$servadm);
750: unless ($configuserok eq 'ok') {
1.181 raeburn 751: &Apache::lonconfigsettings::print_header($r,$phase,$context);
752: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 753: $confname).
1.181 raeburn 754: '<br />'
755: );
1.180 raeburn 756: if ($switchserver) {
1.181 raeburn 757: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
758: '<br />'.
759: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
760: '<br />'.
761: &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).
762: '<br />'.
763: &mt('To do that now, use the following link: [_1]',$switchserver)
764: );
765: } else {
766: $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.').
767: '<br />'.
768: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
769: );
1.180 raeburn 770: }
771: $r->print(&Apache::loncommon::end_page());
772: return OK;
773: }
1.21 raeburn 774: if (keys(%domconfig) == 0) {
775: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 776: my @ids=&Apache::lonnet::current_machine_ids();
777: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 778: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 779: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 780: my $custom_img_count = 0;
781: foreach my $img (@loginimages) {
782: if ($designhash{$dom.'.login.'.$img} ne '') {
783: $custom_img_count ++;
784: }
785: }
786: foreach my $role (@roles) {
787: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
788: $custom_img_count ++;
789: }
790: }
791: if ($custom_img_count > 0) {
1.94 raeburn 792: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 793: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 794: $r->print(
795: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
796: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
797: &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 />'.
798: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
799: if ($switch_server) {
1.30 raeburn 800: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 801: }
1.91 raeburn 802: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 803: return OK;
804: }
805: }
806: }
1.91 raeburn 807: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 808: }
809: return OK;
810: }
811:
812: sub process_changes {
1.205 raeburn 813: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 814: my %domconfig;
815: if (ref($values) eq 'HASH') {
816: %domconfig = %{$values};
817: }
1.3 raeburn 818: my $output;
819: if ($action eq 'login') {
1.205 raeburn 820: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 821: } elsif ($action eq 'rolecolors') {
1.9 raeburn 822: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 823: $lastactref,%domconfig);
1.3 raeburn 824: } elsif ($action eq 'quotas') {
1.216 raeburn 825: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 826: } elsif ($action eq 'autoenroll') {
1.205 raeburn 827: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 828: } elsif ($action eq 'autoupdate') {
829: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 830: } elsif ($action eq 'autocreate') {
831: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 832: } elsif ($action eq 'directorysrch') {
1.295 raeburn 833: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 834: } elsif ($action eq 'usercreation') {
1.28 raeburn 835: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 836: } elsif ($action eq 'selfcreation') {
1.305 raeburn 837: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 838: } elsif ($action eq 'usermodification') {
839: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 840: } elsif ($action eq 'contacts') {
1.205 raeburn 841: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 842: } elsif ($action eq 'defaults') {
1.212 raeburn 843: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 844: } elsif ($action eq 'scantron') {
1.205 raeburn 845: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 846: } elsif ($action eq 'coursecategories') {
1.239 raeburn 847: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 848: } elsif ($action eq 'serverstatuses') {
849: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 850: } elsif ($action eq 'requestcourses') {
1.216 raeburn 851: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 852: } elsif ($action eq 'requestauthor') {
1.216 raeburn 853: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 854: } elsif ($action eq 'helpsettings') {
1.285 raeburn 855: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 856: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 857: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 858: } elsif ($action eq 'selfenrollment') {
859: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 860: } elsif ($action eq 'usersessions') {
1.212 raeburn 861: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 862: } elsif ($action eq 'loadbalancing') {
863: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 864: } elsif ($action eq 'ltitools') {
865: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 866: } elsif ($action eq 'ssl') {
867: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 868: } elsif ($action eq 'trust') {
869: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 870: } elsif ($action eq 'lti') {
871: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 872: } elsif ($action eq 'privacy') {
1.427 raeburn 873: $output = &modify_privacy($dom,$lastactref,%domconfig);
1.354 raeburn 874: } elsif ($action eq 'passwords') {
875: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 876: } elsif ($action eq 'wafproxy') {
877: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 878: } elsif ($action eq 'ipaccess') {
879: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.429 raeburn 880: } elsif ($action eq 'authordefaults') {
881: $output = &modify_authordefaults($dom,$lastactref,%domconfig);
1.3 raeburn 882: }
883: return $output;
884: }
885:
886: sub print_config_box {
1.9 raeburn 887: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 888: my $rowtotal = 0;
1.49 raeburn 889: my $output;
890: if ($action eq 'coursecategories') {
891: $output = &coursecategories_javascript($settings);
1.236 raeburn 892: } elsif ($action eq 'defaults') {
893: $output = &defaults_javascript($settings);
1.354 raeburn 894: } elsif ($action eq 'passwords') {
1.405 raeburn 895: $output = &passwords_javascript($action);
1.282 raeburn 896: } elsif ($action eq 'helpsettings') {
897: my (%privs,%levelscurrent);
898: my %full=();
899: my %levels=(
900: course => {},
901: domain => {},
902: system => {},
903: );
904: my $context = 'domain';
905: my $crstype = 'Course';
906: my $formname = 'display';
907: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
908: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
909: $output =
1.425 raeburn 910: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
1.282 raeburn 911: \@templateroles);
1.334 raeburn 912: } elsif ($action eq 'ltitools') {
1.421 raeburn 913: $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
1.334 raeburn 914: } elsif ($action eq 'lti') {
1.421 raeburn 915: $output .= &passwords_javascript('ltisecrets')."\n".
1.405 raeburn 916: <i_javascript($dom,$settings);
1.381 raeburn 917: } elsif ($action eq 'wafproxy') {
918: $output .= &wafproxy_javascript($dom);
1.385 raeburn 919: } elsif ($action eq 'autoupdate') {
920: $output .= &autoupdate_javascript();
1.399 raeburn 921: } elsif ($action eq 'autoenroll') {
922: $output .= &autoenroll_javascript();
1.386 raeburn 923: } elsif ($action eq 'login') {
924: $output .= &saml_javascript();
1.394 raeburn 925: } elsif ($action eq 'ipaccess') {
926: $output .= &ipaccess_javascript($settings);
1.429 raeburn 927: } elsif ($action eq 'authordefaults') {
928: $output .= &authordefaults_javascript();
1.91 raeburn 929: }
1.236 raeburn 930: $output .=
1.30 raeburn 931: '<table class="LC_nested_outer">
1.3 raeburn 932: <tr>
1.306 raeburn 933: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 934: &mt($item->{text}).' '.
935: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
936: '</tr>';
1.30 raeburn 937: $rowtotal ++;
1.110 raeburn 938: my $numheaders = 1;
939: if (ref($item->{'header'}) eq 'ARRAY') {
940: $numheaders = scalar(@{$item->{'header'}});
941: }
942: if ($numheaders > 1) {
1.64 raeburn 943: my $colspan = '';
1.145 raeburn 944: my $rightcolspan = '';
1.369 raeburn 945: my $leftnobr = '';
1.238 raeburn 946: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 947: ($action eq 'directorysrch') ||
1.386 raeburn 948: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 949: $colspan = ' colspan="2"';
950: }
1.145 raeburn 951: if ($action eq 'usersessions') {
952: $rightcolspan = ' colspan="3"';
953: }
1.369 raeburn 954: if ($action eq 'passwords') {
955: $leftnobr = ' LC_nobreak';
956: }
1.30 raeburn 957: $output .= '
1.3 raeburn 958: <tr>
959: <td>
960: <table class="LC_nested">
961: <tr class="LC_info_row">
1.369 raeburn 962: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 963: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 964: </tr>';
1.69 raeburn 965: $rowtotal ++;
1.230 raeburn 966: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 967: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 968: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 969: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.421 raeburn 970: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') ||
1.429 raeburn 971: ($action eq 'lti') || ($action eq 'ltitools') || ($action eq 'authordefaults')) {
1.230 raeburn 972: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 973: } elsif ($action eq 'passwords') {
974: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 975: } elsif ($action eq 'coursecategories') {
1.230 raeburn 976: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 977: } elsif ($action eq 'scantron') {
978: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 979: } elsif ($action eq 'login') {
1.386 raeburn 980: if ($numheaders == 5) {
1.168 raeburn 981: $colspan = ' colspan="2"';
982: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
983: } else {
984: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
985: }
1.230 raeburn 986: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 987: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 988: } elsif ($action eq 'rolecolors') {
1.30 raeburn 989: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 990: }
1.30 raeburn 991: $output .= '
1.6 raeburn 992: </table>
993: </td>
994: </tr>
995: <tr>
996: <td>
997: <table class="LC_nested">
998: <tr class="LC_info_row">
1.230 raeburn 999: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 1000: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 1001: </tr>';
1002: $rowtotal ++;
1.230 raeburn 1003: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
1004: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 1005: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 1006: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.447.2.4 raeburn 1007: ($action eq 'passwords') || ($action eq 'lti') || ($action eq 'ltitools') ||
1008: ($action eq 'usermodification')) {
1.238 raeburn 1009: if ($action eq 'coursecategories') {
1010: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
1011: $colspan = ' colspan="2"';
1.279 raeburn 1012: } elsif ($action eq 'trust') {
1013: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 1014: } elsif ($action eq 'passwords') {
1015: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.434 raeburn 1016: } elsif ($action eq 'lti') {
1017: $output .= $item->{'print'}->('upper',$dom,$settings,\$rowtotal).'
1018: </table>
1019: </td>
1020: </tr>
1021: <tr>
1022: <td>
1023: <table class="LC_nested">
1024: <tr class="LC_info_row">
1025: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1026: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1027: </tr>'."\n".
1028: $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1.238 raeburn 1029: } else {
1030: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1031: }
1.279 raeburn 1032: if ($action eq 'trust') {
1033: $output .= '
1034: </table>
1035: </td>
1036: </tr>';
1037: my @trusthdrs = qw(2 3 4 5 6 7);
1038: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1039: for (my $i=0; $i<@trusthdrs; $i++) {
1040: $output .= '
1041: <tr>
1042: <td>
1043: <table class="LC_nested">
1044: <tr class="LC_info_row">
1045: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1046: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1047: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1048: </table>
1049: </td>
1050: </tr>';
1051: }
1052: $output .= '
1053: <tr>
1054: <td>
1055: <table class="LC_nested">
1056: <tr class="LC_info_row">
1057: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1058: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1059: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1060: } else {
1.434 raeburn 1061: my $hdridx = 2;
1062: if ($action eq 'lti') {
1063: $hdridx = 3;
1064: }
1.279 raeburn 1065: $output .= '
1.63 raeburn 1066: </table>
1067: </td>
1068: </tr>
1069: <tr>
1070: <td>
1071: <table class="LC_nested">
1072: <tr class="LC_info_row">
1.434 raeburn 1073: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1074: <td class="LC_right_item">'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td>
1.238 raeburn 1075: </tr>'."\n";
1.279 raeburn 1076: if ($action eq 'coursecategories') {
1077: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.447.2.4 raeburn 1078: } elsif (($action eq 'contacts') || ($action eq 'passwords') ||
1079: ($action eq 'lti')) {
1.354 raeburn 1080: if ($action eq 'passwords') {
1081: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1082: } else {
1083: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1084: }
1.434 raeburn 1085: $hdridx ++;
1.354 raeburn 1086: $output .= '
1.340 raeburn 1087: </tr>
1088: </table>
1089: </td>
1090: </tr>
1091: <tr>
1092: <td>
1093: <table class="LC_nested">
1094: <tr class="LC_info_row">
1.434 raeburn 1095: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1096: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td></tr>'."\n";
1.354 raeburn 1097: if ($action eq 'passwords') {
1098: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1099: } else {
1100: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1101: }
1102: $output .= '
1.340 raeburn 1103: </table>
1104: </td>
1105: </tr>
1106: <tr>';
1.279 raeburn 1107: } else {
1108: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1109: }
1.238 raeburn 1110: }
1.63 raeburn 1111: $rowtotal ++;
1.443 raeburn 1112: } elsif (($action eq 'coursedefaults') || ($action eq 'authordefaults') ||
1.409 raeburn 1113: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1.447.2.4 raeburn 1114: ($action eq 'wafproxy') || ($action eq 'privacy')) {
1.230 raeburn 1115: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1116: } elsif ($action eq 'scantron') {
1117: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1118: } elsif ($action eq 'ssl') {
1119: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1120: </table>
1121: </td>
1122: </tr>
1123: <tr>
1124: <td>
1125: <table class="LC_nested">
1126: <tr class="LC_info_row">
1127: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1128: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1129: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1130: </table>
1131: </td>
1132: </tr>
1133: <tr>
1134: <td>
1135: <table class="LC_nested">
1136: <tr class="LC_info_row">
1137: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1138: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1139: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1140: } elsif ($action eq 'login') {
1.386 raeburn 1141: if ($numheaders == 5) {
1.168 raeburn 1142: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1143: </table>
1144: </td>
1145: </tr>
1146: <tr>
1147: <td>
1148: <table class="LC_nested">
1149: <tr class="LC_info_row">
1150: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1151: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1152: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1153: $rowtotal ++;
1154: } else {
1155: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1156: }
1.256 raeburn 1157: $output .= '
1158: </table>
1159: </td>
1160: </tr>
1161: <tr>
1162: <td>
1163: <table class="LC_nested">
1164: <tr class="LC_info_row">';
1.386 raeburn 1165: if ($numheaders == 5) {
1.256 raeburn 1166: $output .= '
1167: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1168: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1169: </tr>';
1170: } else {
1171: $output .= '
1172: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1173: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1174: </tr>';
1175: }
1176: $rowtotal ++;
1.386 raeburn 1177: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1178: </table>
1179: </td>
1180: </tr>
1181: <tr>
1182: <td>
1183: <table class="LC_nested">
1184: <tr class="LC_info_row">';
1185: if ($numheaders == 5) {
1186: $output .= '
1187: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1188: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1189: </tr>';
1190: } else {
1191: $output .= '
1192: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1193: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1194: </tr>';
1195: }
1196: $rowtotal ++;
1197: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1198: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1199: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1200: $rowtotal ++;
1201: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1202: </table>
1203: </td>
1204: </tr>
1205: <tr>
1206: <td>
1207: <table class="LC_nested">
1208: <tr class="LC_info_row">
1209: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1210: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1211: &textbookcourses_javascript($settings).
1212: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1213: </table>
1214: </td>
1215: </tr>
1216: <tr>
1217: <td>
1218: <table class="LC_nested">
1219: <tr class="LC_info_row">
1220: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1221: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1222: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1223: </table>
1224: </td>
1225: </tr>
1226: <tr>
1227: <td>
1228: <table class="LC_nested">
1229: <tr class="LC_info_row">
1.306 raeburn 1230: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1231: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1232: </tr>'.
1233: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1234: } elsif ($action eq 'requestauthor') {
1235: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1236: $rowtotal ++;
1.122 jms 1237: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1238: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1239: </table>
1240: </td>
1241: </tr>
1242: <tr>
1243: <td>
1244: <table class="LC_nested">
1245: <tr class="LC_info_row">
1.306 raeburn 1246: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1247: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1248: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1249: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1250: </tr>'.
1.30 raeburn 1251: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1252: </table>
1253: </td>
1254: </tr>
1255: <tr>
1256: <td>
1257: <table class="LC_nested">
1258: <tr class="LC_info_row">
1.59 bisitz 1259: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1260: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1261: </tr>'.
1.30 raeburn 1262: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1263: $rowtotal += 2;
1.6 raeburn 1264: }
1.3 raeburn 1265: } else {
1.30 raeburn 1266: $output .= '
1.3 raeburn 1267: <tr>
1268: <td>
1269: <table class="LC_nested">
1.30 raeburn 1270: <tr class="LC_info_row">';
1.277 raeburn 1271: if ($action eq 'login') {
1.30 raeburn 1272: $output .= '
1.59 bisitz 1273: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1274: } elsif ($action eq 'serverstatuses') {
1275: $output .= '
1.306 raeburn 1276: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1277: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1278:
1.6 raeburn 1279: } else {
1.30 raeburn 1280: $output .= '
1.306 raeburn 1281: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1282: }
1.72 raeburn 1283: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1284: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1285: &mt($item->{'header'}->[0]->{'col2'});
1286: if ($action eq 'serverstatuses') {
1287: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1288: }
1.69 raeburn 1289: } else {
1.306 raeburn 1290: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1291: &mt($item->{'header'}->[0]->{'col2'});
1292: }
1293: $output .= '</td>';
1294: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1295: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1296: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1297: &mt($item->{'header'}->[0]->{'col3'});
1298: } else {
1.306 raeburn 1299: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1300: &mt($item->{'header'}->[0]->{'col3'});
1301: }
1.69 raeburn 1302: if ($action eq 'serverstatuses') {
1303: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1304: }
1305: $output .= '</td>';
1.6 raeburn 1306: }
1.150 raeburn 1307: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1308: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1309: &mt($item->{'header'}->[0]->{'col4'});
1310: }
1.69 raeburn 1311: $output .= '</tr>';
1.48 raeburn 1312: $rowtotal ++;
1.168 raeburn 1313: if ($action eq 'quotas') {
1.86 raeburn 1314: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1315: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1316: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.447.2.1 raeburn 1317: ($action eq 'ipaccess')) {
1.230 raeburn 1318: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1319: }
1.3 raeburn 1320: }
1.30 raeburn 1321: $output .= '
1.3 raeburn 1322: </table>
1323: </td>
1324: </tr>
1.30 raeburn 1325: </table><br />';
1326: return ($output,$rowtotal);
1.1 raeburn 1327: }
1328:
1.3 raeburn 1329: sub print_login {
1.168 raeburn 1330: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1331: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1332: my %choices = &login_choices();
1.386 raeburn 1333: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1334: %lt = &login_file_options();
1335: $switchserver = &check_switchserver($dom,$confname);
1336: }
1.168 raeburn 1337: if ($caller eq 'service') {
1.149 raeburn 1338: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1339: my $choice = $choices{'disallowlogin'};
1340: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1341: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1342: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1343: '<th>'.$choices{'server'}.'</th>'.
1344: '<th>'.$choices{'serverpath'}.'</th>'.
1345: '<th>'.$choices{'custompath'}.'</th>'.
1346: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1347: my %disallowed;
1348: if (ref($settings) eq 'HASH') {
1349: if (ref($settings->{'loginvia'}) eq 'HASH') {
1350: %disallowed = %{$settings->{'loginvia'}};
1351: }
1352: }
1353: foreach my $lonhost (sort(keys(%servers))) {
1354: my $direct = 'selected="selected"';
1.128 raeburn 1355: if (ref($disallowed{$lonhost}) eq 'HASH') {
1356: if ($disallowed{$lonhost}{'server'} ne '') {
1357: $direct = '';
1358: }
1.110 raeburn 1359: }
1.115 raeburn 1360: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1361: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1362: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1363: '</option>';
1.184 raeburn 1364: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1365: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1366: my $selected = '';
1.128 raeburn 1367: if (ref($disallowed{$lonhost}) eq 'HASH') {
1368: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1369: $selected = 'selected="selected"';
1370: }
1.110 raeburn 1371: }
1372: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1373: $servers{$hostid}.'</option>';
1374: }
1.128 raeburn 1375: $datatable .= '</select></td>'.
1376: '<td><select name="'.$lonhost.'_serverpath">';
1377: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1378: my $pathname = $path;
1379: if ($path eq 'custom') {
1380: $pathname = &mt('Custom Path').' ->';
1381: }
1382: my $selected = '';
1383: if (ref($disallowed{$lonhost}) eq 'HASH') {
1384: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1385: $selected = 'selected="selected"';
1386: }
1387: } elsif ($path eq '') {
1388: $selected = 'selected="selected"';
1389: }
1390: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1391: }
1392: $datatable .= '</select></td>';
1393: my ($custom,$exempt);
1394: if (ref($disallowed{$lonhost}) eq 'HASH') {
1395: $custom = $disallowed{$lonhost}{'custompath'};
1396: $exempt = $disallowed{$lonhost}{'exempt'};
1397: }
1398: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1399: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1400: '</tr>';
1.110 raeburn 1401: }
1402: $datatable .= '</table></td></tr>';
1403: return $datatable;
1.168 raeburn 1404: } elsif ($caller eq 'page') {
1405: my %defaultchecked = (
1406: 'coursecatalog' => 'on',
1.188 raeburn 1407: 'helpdesk' => 'on',
1.168 raeburn 1408: 'adminmail' => 'off',
1409: 'newuser' => 'off',
1410: );
1.188 raeburn 1411: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1412: my (%checkedon,%checkedoff);
1.42 raeburn 1413: foreach my $item (@toggles) {
1.168 raeburn 1414: if ($defaultchecked{$item} eq 'on') {
1415: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1416: $checkedoff{$item} = ' ';
1.168 raeburn 1417: } elsif ($defaultchecked{$item} eq 'off') {
1418: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1419: $checkedon{$item} = ' ';
1420: }
1.1 raeburn 1421: }
1.168 raeburn 1422: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1423: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1424: my @logintext = ('textcol','bgcol');
1425: my @bgs = ('pgbg','mainbg','sidebg');
1426: my @links = ('link','alink','vlink');
1427: my %designhash = &Apache::loncommon::get_domainconf($dom);
1428: my %defaultdesign = %Apache::loncommon::defaultdesign;
1429: my (%is_custom,%designs);
1430: my %defaults = (
1431: font => $defaultdesign{'login.font'},
1432: );
1.6 raeburn 1433: foreach my $item (@images) {
1.168 raeburn 1434: $defaults{$item} = $defaultdesign{'login.'.$item};
1435: $defaults{'showlogo'}{$item} = 1;
1436: }
1437: foreach my $item (@bgs) {
1438: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1439: }
1.41 raeburn 1440: foreach my $item (@logintext) {
1.168 raeburn 1441: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1442: }
1.168 raeburn 1443: foreach my $item (@links) {
1444: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1445: }
1.168 raeburn 1446: if (ref($settings) eq 'HASH') {
1447: foreach my $item (@toggles) {
1448: if ($settings->{$item} eq '1') {
1449: $checkedon{$item} = ' checked="checked" ';
1450: $checkedoff{$item} = ' ';
1451: } elsif ($settings->{$item} eq '0') {
1452: $checkedoff{$item} = ' checked="checked" ';
1453: $checkedon{$item} = ' ';
1454: }
1455: }
1456: foreach my $item (@images) {
1457: if (defined($settings->{$item})) {
1458: $designs{$item} = $settings->{$item};
1459: $is_custom{$item} = 1;
1460: }
1461: if (defined($settings->{'showlogo'}{$item})) {
1462: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1463: }
1464: }
1.402 raeburn 1465: foreach my $item (@alttext) {
1466: if (ref($settings->{'alttext'}) eq 'HASH') {
1467: if ($settings->{'alttext'}->{$item} ne '') {
1468: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1469: }
1470: }
1471: }
1.168 raeburn 1472: foreach my $item (@logintext) {
1473: if ($settings->{$item} ne '') {
1474: $designs{'logintext'}{$item} = $settings->{$item};
1475: $is_custom{$item} = 1;
1476: }
1477: }
1478: if ($settings->{'font'} ne '') {
1479: $designs{'font'} = $settings->{'font'};
1480: $is_custom{'font'} = 1;
1481: }
1482: foreach my $item (@bgs) {
1483: if ($settings->{$item} ne '') {
1484: $designs{'bgs'}{$item} = $settings->{$item};
1485: $is_custom{$item} = 1;
1486: }
1487: }
1488: foreach my $item (@links) {
1489: if ($settings->{$item} ne '') {
1490: $designs{'links'}{$item} = $settings->{$item};
1491: $is_custom{$item} = 1;
1492: }
1493: }
1494: } else {
1495: if ($designhash{$dom.'.login.font'} ne '') {
1496: $designs{'font'} = $designhash{$dom.'.login.font'};
1497: $is_custom{'font'} = 1;
1498: }
1499: foreach my $item (@images) {
1500: if ($designhash{$dom.'.login.'.$item} ne '') {
1501: $designs{$item} = $designhash{$dom.'.login.'.$item};
1502: $is_custom{$item} = 1;
1503: }
1504: }
1505: foreach my $item (@bgs) {
1506: if ($designhash{$dom.'.login.'.$item} ne '') {
1507: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1508: $is_custom{$item} = 1;
1509: }
1.6 raeburn 1510: }
1.168 raeburn 1511: foreach my $item (@links) {
1512: if ($designhash{$dom.'.login.'.$item} ne '') {
1513: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1514: $is_custom{$item} = 1;
1515: }
1.6 raeburn 1516: }
1517: }
1.168 raeburn 1518: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1519: logo => 'Institution Logo',
1520: domlogo => 'Domain Logo',
1521: login => 'Login box');
1522: my $itemcount = 1;
1523: foreach my $item (@toggles) {
1524: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1525: $datatable .=
1526: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1527: '</td><td>'.
1528: '<span class="LC_nobreak"><label><input type="radio" name="'.
1529: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1530: '</label> <label><input type="radio" name="'.$item.'"'.
1531: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1532: '</tr>';
1533: $itemcount ++;
1.6 raeburn 1534: }
1.168 raeburn 1535: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1536: $datatable .= '</tr></table></td></tr>';
1537: } elsif ($caller eq 'help') {
1.386 raeburn 1538: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1539: my $itemcount = 1;
1540: $defaulturl = '/adm/loginproblems.html';
1541: $defaulttype = 'default';
1542: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1543: my @currlangs;
1544: if (ref($settings) eq 'HASH') {
1545: if (ref($settings->{'helpurl'}) eq 'HASH') {
1546: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1547: next if ($settings->{'helpurl'}{$key} eq '');
1548: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1549: $type{$key} = 'custom';
1550: unless ($key eq 'nolang') {
1551: push(@currlangs,$key);
1552: }
1553: }
1554: } elsif ($settings->{'helpurl'} ne '') {
1555: $type{'nolang'} = 'custom';
1556: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1557: }
1558: }
1.168 raeburn 1559: foreach my $lang ('nolang',sort(@currlangs)) {
1560: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1561: $datatable .= '<tr'.$css_class.'>';
1562: if ($url{$lang} eq '') {
1563: $url{$lang} = $defaulturl;
1564: }
1565: if ($type{$lang} eq '') {
1566: $type{$lang} = $defaulttype;
1567: }
1568: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1569: if ($lang eq 'nolang') {
1570: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1571: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1572: } else {
1573: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1574: $langchoices{$lang},
1575: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1576: }
1577: $datatable .= '</span></td>'."\n".
1578: '<td class="LC_left_item">';
1579: if ($type{$lang} eq 'custom') {
1580: $datatable .= '<span class="LC_nobreak"><label>'.
1581: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1582: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1583: } else {
1584: $datatable .= $lt{'upl'};
1585: }
1586: $datatable .='<br />';
1587: if ($switchserver) {
1588: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1589: } else {
1590: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1591: }
1.168 raeburn 1592: $datatable .= '</td></tr>';
1593: $itemcount ++;
1.6 raeburn 1594: }
1.168 raeburn 1595: my @addlangs;
1596: foreach my $lang (sort(keys(%langchoices))) {
1597: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1598: push(@addlangs,$lang);
1599: }
1600: if (@addlangs > 0) {
1601: my %toadd;
1602: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1603: $toadd{''} = &mt('Select');
1604: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1605: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1606: &mt('Add log-in help page for a specific language:').' '.
1607: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1608: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1609: if ($switchserver) {
1610: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1611: } else {
1612: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1613: }
1.168 raeburn 1614: $datatable .= '</td></tr>';
1.169 raeburn 1615: $itemcount ++;
1.6 raeburn 1616: }
1.169 raeburn 1617: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1618: } elsif ($caller eq 'headtag') {
1619: my %domservers = &Apache::lonnet::get_servers($dom);
1620: my $choice = $choices{'headtag'};
1621: $css_class = ' class="LC_odd_row"';
1622: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1623: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1624: '<th>'.$choices{'current'}.'</th>'.
1625: '<th>'.$choices{'action'}.'</th>'.
1626: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1627: my (%currurls,%currexempt);
1628: if (ref($settings) eq 'HASH') {
1629: if (ref($settings->{'headtag'}) eq 'HASH') {
1630: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1631: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1632: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1633: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1634: }
1635: }
1636: }
1637: }
1638: foreach my $lonhost (sort(keys(%domservers))) {
1639: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1640: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1641: if ($currurls{$lonhost}) {
1642: $datatable .= '<td class="LC_right_item"><a href="'.
1643: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1644: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1645: '">'.$lt{'curr'}.'</a></td>'.
1646: '<td><span class="LC_nobreak"><label>'.
1647: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1648: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1649: } else {
1650: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1651: }
1652: $datatable .='<br />';
1653: if ($switchserver) {
1654: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1655: } else {
1656: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1657: }
1.330 raeburn 1658: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1659: }
1660: $datatable .= '</table></td></tr>';
1.386 raeburn 1661: } elsif ($caller eq 'saml') {
1662: my %domservers = &Apache::lonnet::get_servers($dom);
1663: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1664: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1665: '<th>'.$choices{'samllanding'}.'</th>'.
1666: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1667: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1668: foreach my $lonhost (keys(%domservers)) {
1669: $samlurl{$lonhost} = '/adm/sso';
1670: $styleon{$lonhost} = 'display:none';
1671: $styleoff{$lonhost} = '';
1672: }
1.411 raeburn 1673: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1674: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1675: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1676: $saml{$lonhost} = 1;
1677: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1678: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1679: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1680: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1681: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1682: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1683: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1684: $styleon{$lonhost} = '';
1685: $styleoff{$lonhost} = 'display:none';
1686: } else {
1687: $styleon{$lonhost} = 'display:none';
1688: $styleoff{$lonhost} = '';
1689: }
1690: }
1691: }
1692: my $itemcount = 1;
1693: foreach my $lonhost (sort(keys(%domservers))) {
1694: my $samlon = ' ';
1695: my $samloff = ' checked="checked" ';
1696: if ($saml{$lonhost}) {
1697: $samlon = $samloff;
1698: $samloff = ' ';
1699: }
1.412 raeburn 1700: my $samlwinon = '';
1701: my $samlwinoff = ' checked="checked"';
1702: if ($samlwindow{$lonhost}) {
1703: $samlwinon = $samlwinoff;
1704: $samlwinoff = '';
1705: }
1.386 raeburn 1706: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1707: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1708: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1709: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1710: &mt('No').'</label>'.(' 'x2).
1711: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1712: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1713: &mt('Yes').'</label></span></td>'.
1714: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1715: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1716: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1717: '<th>'.&mt('Alt Text').'</th></tr>'.
1718: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1719: $samltext{$lonhost}.'" /></td><td>';
1720: if ($samlimg{$lonhost}) {
1721: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1722: '<span class="LC_nobreak"><label>'.
1723: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1724: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1725: } else {
1726: $datatable .= $lt{'upl'};
1727: }
1728: $datatable .='<br />';
1729: if ($switchserver) {
1730: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1731: } else {
1732: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1733: }
1734: $datatable .= '</td>'.
1.412 raeburn 1735: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1736: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1737: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1738: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1739: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1740: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1741: '<tr'.$css_class.'>'.
1742: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1743: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1744: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1745: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1746: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1747: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1748: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1749: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1750: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1751: '</table></td>'.
1752: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1753: $itemcount ++;
1754: }
1755: $datatable .= '</table></td></tr>';
1.1 raeburn 1756: }
1.6 raeburn 1757: return $datatable;
1758: }
1759:
1760: sub login_choices {
1761: my %choices =
1762: &Apache::lonlocal::texthash (
1.116 bisitz 1763: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1764: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1765: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1766: disallowlogin => "Login page requests redirected",
1767: hostid => "Server",
1.128 raeburn 1768: server => "Redirect to:",
1769: serverpath => "Path",
1770: custompath => "Custom",
1771: exempt => "Exempt IP(s)",
1.110 raeburn 1772: directlogin => "No redirect",
1773: newuser => "Link to create a user account",
1774: img => "Header",
1775: logo => "Main Logo",
1776: domlogo => "Domain Logo",
1777: login => "Log-in Header",
1778: textcol => "Text color",
1779: bgcol => "Box color",
1780: bgs => "Background colors",
1781: links => "Link colors",
1782: font => "Font color",
1783: pgbg => "Header",
1784: mainbg => "Page",
1785: sidebg => "Login box",
1786: link => "Link",
1787: alink => "Active link",
1788: vlink => "Visited link",
1.256 raeburn 1789: headtag => "Custom markup",
1790: action => "Action",
1791: current => "Current",
1.386 raeburn 1792: samllanding => "Dual login?",
1793: samloptions => "Options",
1.402 raeburn 1794: alttext => "Alt text",
1.6 raeburn 1795: );
1796: return %choices;
1797: }
1798:
1.386 raeburn 1799: sub login_file_options {
1800: return &Apache::lonlocal::texthash(
1801: del => 'Delete?',
1802: rep => 'Replace:',
1803: upl => 'Upload:',
1804: curr => 'View contents',
1805: default => 'Default',
1806: custom => 'Custom',
1807: none => 'None',
1808: );
1809: }
1810:
1.394 raeburn 1811: sub print_ipaccess {
1812: my ($dom,$settings,$rowtotal) = @_;
1813: my $css_class;
1814: my $itemcount = 0;
1815: my $datatable;
1816: my %ordered;
1817: if (ref($settings) eq 'HASH') {
1818: foreach my $item (keys(%{$settings})) {
1819: if (ref($settings->{$item}) eq 'HASH') {
1820: my $num = $settings->{$item}{'order'};
1821: if ($num eq '') {
1822: $num = scalar(keys(%{$settings}));
1823: }
1824: $ordered{$num} = $item;
1825: }
1826: }
1827: }
1828: my $maxnum = scalar(keys(%ordered));
1829: if (keys(%ordered)) {
1830: my @items = sort { $a <=> $b } keys(%ordered);
1831: for (my $i=0; $i<@items; $i++) {
1832: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1833: my $item = $ordered{$items[$i]};
1834: my ($name,$ipranges,%commblocks,%courses);
1835: if (ref($settings->{$item}) eq 'HASH') {
1836: $name = $settings->{$item}->{'name'};
1837: $ipranges = $settings->{$item}->{'ip'};
1838: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1839: %commblocks = %{$settings->{$item}->{'commblocks'}};
1840: }
1841: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1842: %courses = %{$settings->{$item}->{'courses'}};
1843: }
1844: }
1845: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1846: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1847: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1848: for (my $k=0; $k<=$maxnum; $k++) {
1849: my $vpos = $k+1;
1850: my $selstr;
1851: if ($k == $i) {
1852: $selstr = ' selected="selected" ';
1853: }
1854: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1855: }
1856: $datatable .= '</select>'.(' 'x2).
1857: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1858: &mt('Delete?').'</label></span></td>'.
1859: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1860: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1861: '</td></tr>';
1862: $itemcount ++;
1863: }
1864: }
1865: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1866: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1867: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1868: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1869: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1870: for (my $k=0; $k<$maxnum+1; $k++) {
1871: my $vpos = $k+1;
1872: my $selstr;
1873: if ($k == $maxnum) {
1874: $selstr = ' selected="selected" ';
1875: }
1876: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1877: }
1878: $datatable .= '</select> '."\n".
1879: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1880: '<td colspan="2">'.
1881: &ipaccess_options('add',$itemcount,$dom).
1882: '</td>'."\n".
1883: '</tr>'."\n";
1884: $$rowtotal ++;
1885: return $datatable;
1886: }
1887:
1888: sub ipaccess_options {
1889: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1890: my (%currblocks,%currcourses,$output);
1891: if (ref($blocksref) eq 'HASH') {
1892: %currblocks = %{$blocksref};
1893: }
1894: if (ref($coursesref) eq 'HASH') {
1895: %currcourses = %{$coursesref};
1896: }
1897: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1898: '<span class="LC_nobreak">'.&mt('Name').': '.
1899: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1900: '</span></fieldset>'.
1901: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1902: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1903: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1904: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1905: $ipranges.'</textarea></fieldset>'.
1906: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1907: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1908: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1909: '<table>';
1910: foreach my $cid (sort(keys(%currcourses))) {
1911: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1912: $output .= '<tr><td><span class="LC_nobreak">'.
1913: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1914: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1915: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1916: }
1917: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1918: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1919: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1920: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1921: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1922: '</span></td></tr></table>'."\n".
1923: '</fieldset>';
1924: return $output;
1925: }
1926:
1927: sub blocker_checkboxes {
1928: my ($num,$blocks) = @_;
1929: my ($typeorder,$types) = &commblocktype_text();
1930: my $numinrow = 6;
1931: my $output = '<table>';
1932: for (my $i=0; $i<@{$typeorder}; $i++) {
1933: my $block = $typeorder->[$i];
1934: my $blockstatus;
1935: if (ref($blocks) eq 'HASH') {
1936: if ($blocks->{$block} eq 'on') {
1937: $blockstatus = 'checked="checked"';
1938: }
1939: }
1940: my $rem = $i%($numinrow);
1941: if ($rem == 0) {
1942: if ($i > 0) {
1943: $output .= '</tr>';
1944: }
1945: $output .= '<tr>';
1946: }
1947: if ($i == scalar(@{$typeorder})-1) {
1948: my $colsleft = $numinrow-$rem;
1949: if ($colsleft > 1) {
1950: $output .= '<td colspan="'.$colsleft.'">';
1951: } else {
1952: $output .= '<td>';
1953: }
1954: } else {
1955: $output .= '<td>';
1956: }
1957: my $item = 'ipaccess_block_'.$num;
1958: if ($blockstatus) {
1959: $blockstatus = ' '.$blockstatus;
1960: }
1961: $output .= '<span class="LC_nobreak"><label>'."\n".
1962: '<input type="checkbox" name="'.$item.'"'.
1963: $blockstatus.' value="'.$block.'"'.' />'.
1964: $types->{$block}.'</label></span>'."\n".
1965: '<br /></td>';
1966: }
1967: $output .= '</tr></table>';
1968: return $output;
1969: }
1970:
1971: sub commblocktype_text {
1972: my %types = &Apache::lonlocal::texthash(
1973: 'com' => 'Messaging',
1974: 'chat' => 'Chat Room',
1975: 'boards' => 'Discussion',
1976: 'port' => 'Portfolio',
1977: 'groups' => 'Groups',
1978: 'blogs' => 'Blogs',
1979: 'about' => 'User Information',
1980: 'printout' => 'Printouts',
1981: 'passwd' => 'Change Password',
1982: 'grades' => 'Gradebook',
1.397 raeburn 1983: 'search' => 'Course search',
1.447 raeburn 1984: 'index' => 'Course content index',
1.397 raeburn 1985: 'wishlist' => 'Stored links',
1986: 'annotate' => 'Annotations',
1.394 raeburn 1987: );
1.447 raeburn 1988: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','index','annotate','passwd'];
1.394 raeburn 1989: return ($typeorder,\%types);
1990: }
1991:
1.6 raeburn 1992: sub print_rolecolors {
1.30 raeburn 1993: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1994: my %choices = &color_font_choices();
1995: my @bgs = ('pgbg','tabbg','sidebg');
1996: my @links = ('link','alink','vlink');
1.445 raeburn 1997: my @images = ();
1.6 raeburn 1998: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1999: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 2000: my %defaultdesign = %Apache::loncommon::defaultdesign;
2001: my (%is_custom,%designs);
1.200 raeburn 2002: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 2003: if (ref($settings) eq 'HASH') {
2004: if (ref($settings->{$role}) eq 'HASH') {
2005: if ($settings->{$role}->{'font'} ne '') {
2006: $designs{'font'} = $settings->{$role}->{'font'};
2007: $is_custom{'font'} = 1;
2008: }
1.97 tempelho 2009: if ($settings->{$role}->{'fontmenu'} ne '') {
2010: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
2011: $is_custom{'fontmenu'} = 1;
2012: }
1.6 raeburn 2013: foreach my $item (@bgs) {
2014: if ($settings->{$role}->{$item} ne '') {
2015: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
2016: $is_custom{$item} = 1;
2017: }
2018: }
2019: foreach my $item (@links) {
2020: if ($settings->{$role}->{$item} ne '') {
2021: $designs{'links'}{$item} = $settings->{$role}->{$item};
2022: $is_custom{$item} = 1;
2023: }
2024: }
2025: }
2026: } else {
1.97 tempelho 2027: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2028: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2029: $is_custom{'fontmenu'} = 1;
2030: }
1.6 raeburn 2031: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2032: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2033: $is_custom{'font'} = 1;
2034: }
2035: foreach my $item (@bgs) {
2036: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2037: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2038: $is_custom{$item} = 1;
2039:
2040: }
2041: }
2042: foreach my $item (@links) {
2043: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2044: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2045: $is_custom{$item} = 1;
2046: }
2047: }
2048: }
2049: my $itemcount = 1;
1.30 raeburn 2050: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2051: $datatable .= '</tr></table></td></tr>';
2052: return $datatable;
2053: }
2054:
1.200 raeburn 2055: sub role_defaults {
2056: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2057: my %defaults;
2058: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2059: return %defaults;
2060: }
2061: my %defaultdesign = %Apache::loncommon::defaultdesign;
2062: if ($role eq 'login') {
2063: %defaults = (
2064: font => $defaultdesign{$role.'.font'},
2065: );
2066: if (ref($logintext) eq 'ARRAY') {
2067: foreach my $item (@{$logintext}) {
2068: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2069: }
2070: }
2071: foreach my $item (@{$images}) {
2072: $defaults{'showlogo'}{$item} = 1;
2073: }
2074: } else {
2075: %defaults = (
2076: font => $defaultdesign{$role.'.font'},
2077: fontmenu => $defaultdesign{$role.'.fontmenu'},
2078: );
2079: }
2080: foreach my $item (@{$bgs}) {
2081: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2082: }
2083: foreach my $item (@{$links}) {
2084: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2085: }
2086: foreach my $item (@{$images}) {
2087: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2088: }
2089: return %defaults;
2090: }
2091:
1.6 raeburn 2092: sub display_color_options {
1.9 raeburn 2093: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2094: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2095: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2096: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2097: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2098: '<td>'.$choices->{'font'}.'</td>';
2099: if (!$is_custom->{'font'}) {
1.329 raeburn 2100: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2101: } else {
2102: $datatable .= '<td> </td>';
2103: }
1.174 foxr 2104: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2105:
1.8 raeburn 2106: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2107: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2108: ' value="'.$current_color.'" /> '.
1.329 raeburn 2109: ' </span></td></tr>';
1.107 raeburn 2110: unless ($role eq 'login') {
2111: $datatable .= '<tr'.$css_class.'>'.
2112: '<td>'.$choices->{'fontmenu'}.'</td>';
2113: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2114: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2115: } else {
2116: $datatable .= '<td> </td>';
2117: }
1.202 raeburn 2118: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2119: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2120: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2121: '<input class="colorchooser" type="text" size="10" name="'
2122: .$role.'_fontmenu"'.
2123: ' value="'.$current_color.'" /> '.
1.329 raeburn 2124: ' </span></td></tr>';
1.97 tempelho 2125: }
1.9 raeburn 2126: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2127: foreach my $img (@{$images}) {
1.18 albertel 2128: $itemcount ++;
1.6 raeburn 2129: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2130: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2131: '<td>'.$choices->{$img};
1.402 raeburn 2132: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2133: if ($role eq 'login') {
2134: if ($img eq 'login') {
2135: $login_hdr_pick =
1.135 bisitz 2136: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2137: $logincolors =
2138: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2139: $designs,$defaults);
1.402 raeburn 2140: } else {
2141: if ($img ne 'domlogo') {
2142: $datatable.= &logo_display_options($img,$defaults,$designs);
2143: }
2144: if (ref($designs->{'alttext'}) eq 'HASH') {
2145: $alttext = $designs->{'alttext'}{$img};
2146: }
1.70 raeburn 2147: }
2148: }
2149: $datatable .= '</td>';
1.6 raeburn 2150: if ($designs->{$img} ne '') {
2151: $imgfile = $designs->{$img};
1.18 albertel 2152: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2153: } else {
2154: $imgfile = $defaults->{$img};
2155: }
2156: if ($imgfile) {
1.9 raeburn 2157: my ($showfile,$fullsize);
2158: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2159: my $urldir = $1;
2160: my $filename = $2;
2161: my @info = &Apache::lonnet::stat_file($designs->{$img});
2162: if (@info) {
2163: my $thumbfile = 'tn-'.$filename;
2164: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2165: if (@thumb) {
2166: $showfile = $urldir.'/'.$thumbfile;
2167: } else {
2168: $showfile = $imgfile;
2169: }
2170: } else {
2171: $showfile = '';
2172: }
2173: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2174: $showfile = $imgfile;
1.6 raeburn 2175: my $imgdir = $1;
2176: my $filename = $2;
1.159 raeburn 2177: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2178: $showfile = "/$imgdir/tn-".$filename;
2179: } else {
1.159 raeburn 2180: my $input = $londocroot.$imgfile;
2181: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2182: if (!-e $output) {
1.9 raeburn 2183: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2184: my ($fullwidth,$fullheight) = &check_dimensions($input);
2185: if ($fullwidth ne '' && $fullheight ne '') {
2186: if ($fullwidth > $width && $fullheight > $height) {
2187: my $size = $width.'x'.$height;
1.316 raeburn 2188: my @args = ('convert','-sample',$size,$input,$output);
2189: system({$args[0]} @args);
1.159 raeburn 2190: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2191: }
2192: }
1.6 raeburn 2193: }
2194: }
1.16 raeburn 2195: }
1.6 raeburn 2196: if ($showfile) {
1.40 raeburn 2197: if ($showfile =~ m{^/(adm|res)/}) {
2198: if ($showfile =~ m{^/res/}) {
2199: my $local_showfile =
2200: &Apache::lonnet::filelocation('',$showfile);
2201: &Apache::lonnet::repcopy($local_showfile);
2202: }
2203: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2204: }
2205: if ($imgfile) {
2206: if ($imgfile =~ m{^/(adm|res)/}) {
2207: if ($imgfile =~ m{^/res/}) {
2208: my $local_imgfile =
2209: &Apache::lonnet::filelocation('',$imgfile);
2210: &Apache::lonnet::repcopy($local_imgfile);
2211: }
2212: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2213: } else {
2214: $fullsize = $imgfile;
2215: }
2216: }
1.41 raeburn 2217: $datatable .= '<td>';
2218: if ($img eq 'login') {
1.135 bisitz 2219: $datatable .= $login_hdr_pick;
2220: }
1.41 raeburn 2221: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2222: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2223: } else {
1.201 raeburn 2224: $datatable .= '<td> </td><td class="LC_left_item">'.
2225: &mt('Upload:').'<br />';
1.6 raeburn 2226: }
2227: } else {
1.201 raeburn 2228: $datatable .= '<td> </td><td class="LC_left_item">'.
2229: &mt('Upload:').'<br />';
1.6 raeburn 2230: }
1.9 raeburn 2231: if ($switchserver) {
2232: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2233: } else {
1.135 bisitz 2234: if ($img ne 'login') { # suppress file selection for Log-in header
2235: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2236: }
1.9 raeburn 2237: }
1.402 raeburn 2238: if (($role eq 'login') && ($img ne 'login')) {
2239: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2240: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2241: '</label></span>';
2242: }
1.9 raeburn 2243: $datatable .= '</td></tr>';
1.6 raeburn 2244: }
2245: $itemcount ++;
2246: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2247: $datatable .= '<tr'.$css_class.'>'.
2248: '<td>'.$choices->{'bgs'}.'</td>';
2249: my $bgs_def;
2250: foreach my $item (@{$bgs}) {
2251: if (!$is_custom->{$item}) {
1.329 raeburn 2252: $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 2253: }
2254: }
2255: if ($bgs_def) {
1.8 raeburn 2256: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2257: } else {
2258: $datatable .= '<td> </td>';
2259: }
2260: $datatable .= '<td class="LC_right_item">'.
2261: '<table border="0"><tr>';
1.174 foxr 2262:
1.6 raeburn 2263: foreach my $item (@{$bgs}) {
1.306 raeburn 2264: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2265: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2266: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2267: $datatable .= ' ';
1.6 raeburn 2268: }
1.174 foxr 2269: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2270: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2271: }
2272: $datatable .= '</tr></table></td></tr>';
2273: $itemcount ++;
2274: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2275: $datatable .= '<tr'.$css_class.'>'.
2276: '<td>'.$choices->{'links'}.'</td>';
2277: my $links_def;
2278: foreach my $item (@{$links}) {
2279: if (!$is_custom->{$item}) {
1.329 raeburn 2280: $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 2281: }
2282: }
2283: if ($links_def) {
1.8 raeburn 2284: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2285: } else {
2286: $datatable .= '<td> </td>';
2287: }
2288: $datatable .= '<td class="LC_right_item">'.
2289: '<table border="0"><tr>';
2290: foreach my $item (@{$links}) {
1.234 raeburn 2291: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2292: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2293: if ($designs->{'links'}{$item}) {
1.174 foxr 2294: $datatable.=' ';
1.6 raeburn 2295: }
1.174 foxr 2296: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2297: '" /></td>';
2298: }
1.30 raeburn 2299: $$rowtotal += $itemcount;
1.3 raeburn 2300: return $datatable;
2301: }
2302:
1.70 raeburn 2303: sub logo_display_options {
2304: my ($img,$defaults,$designs) = @_;
2305: my $checkedon;
2306: if (ref($defaults) eq 'HASH') {
2307: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2308: if ($defaults->{'showlogo'}{$img}) {
2309: $checkedon = 'checked="checked" ';
2310: }
2311: }
2312: }
2313: if (ref($designs) eq 'HASH') {
2314: if (ref($designs->{'showlogo'}) eq 'HASH') {
2315: if (defined($designs->{'showlogo'}{$img})) {
2316: if ($designs->{'showlogo'}{$img} == 0) {
2317: $checkedon = '';
2318: } elsif ($designs->{'showlogo'}{$img} == 1) {
2319: $checkedon = 'checked="checked" ';
2320: }
2321: }
2322: }
2323: }
2324: return '<br /><label> <input type="checkbox" name="'.
2325: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2326: &mt('show').'</label>'."\n";
2327: }
2328:
1.41 raeburn 2329: sub login_header_options {
1.135 bisitz 2330: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2331: my $output = '';
1.41 raeburn 2332: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2333: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2334: if (!$is_custom->{'textcol'}) {
2335: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2336: ' ';
2337: }
2338: if (!$is_custom->{'bgcol'}) {
2339: $output .= $choices->{'bgcol'}.': '.
2340: '<span id="css_'.$role.'_font" style="background-color: '.
2341: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2342: }
2343: $output .= '<br />';
2344: }
2345: $output .='<br />';
2346: return $output;
2347: }
2348:
2349: sub login_text_colors {
1.201 raeburn 2350: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2351: my $color_menu = '<table border="0"><tr>';
2352: foreach my $item (@{$logintext}) {
1.306 raeburn 2353: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2354: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2355: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2356: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2357: }
2358: $color_menu .= '</tr></table><br />';
2359: return $color_menu;
2360: }
2361:
2362: sub image_changes {
2363: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2364: my $output;
1.135 bisitz 2365: if ($img eq 'login') {
1.331 raeburn 2366: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2367: } elsif (!$is_custom) {
1.70 raeburn 2368: if ($img ne 'domlogo') {
1.331 raeburn 2369: $output = &mt('Default image:').'<br />';
1.41 raeburn 2370: } else {
1.331 raeburn 2371: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2372: }
2373: }
1.331 raeburn 2374: if ($img ne 'login') {
1.135 bisitz 2375: if ($img_import) {
2376: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2377: }
2378: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2379: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2380: if ($is_custom) {
2381: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2382: '<input type="checkbox" name="'.
2383: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2384: '</label> '.&mt('Replace:').'</span><br />';
2385: } else {
1.306 raeburn 2386: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2387: }
1.41 raeburn 2388: }
2389: return $output;
2390: }
2391:
1.3 raeburn 2392: sub print_quotas {
1.86 raeburn 2393: my ($dom,$settings,$rowtotal,$action) = @_;
2394: my $context;
2395: if ($action eq 'quotas') {
2396: $context = 'tools';
2397: } else {
2398: $context = $action;
2399: }
1.429 raeburn 2400: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2401: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2402: my $typecount = 0;
1.101 raeburn 2403: my ($css_class,%titles);
1.86 raeburn 2404: if ($context eq 'requestcourses') {
1.325 raeburn 2405: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2406: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2407: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2408: %titles = &courserequest_titles();
1.163 raeburn 2409: } elsif ($context eq 'requestauthor') {
2410: @usertools = ('author');
2411: @options = ('norequest','approval','automatic');
1.210 raeburn 2412: %titles = &authorrequest_titles();
1.86 raeburn 2413: } else {
1.430 raeburn 2414: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 2415: %titles = &tool_titles();
1.86 raeburn 2416: }
1.26 raeburn 2417: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2418: foreach my $type (@{$types}) {
1.429 raeburn 2419: my $currdefquota;
1.163 raeburn 2420: unless (($context eq 'requestcourses') ||
2421: ($context eq 'requestauthor')) {
1.86 raeburn 2422: if (ref($settings) eq 'HASH') {
2423: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2424: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2425: } else {
2426: $currdefquota = $settings->{$type};
2427: }
1.78 raeburn 2428: }
1.72 raeburn 2429: }
1.3 raeburn 2430: if (defined($usertypes->{$type})) {
2431: $typecount ++;
2432: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2433: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2434: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2435: '<td class="LC_left_item">';
1.101 raeburn 2436: if ($context eq 'requestcourses') {
2437: $datatable .= '<table><tr>';
2438: }
2439: my %cell;
1.72 raeburn 2440: foreach my $item (@usertools) {
1.101 raeburn 2441: if ($context eq 'requestcourses') {
2442: my ($curroption,$currlimit);
2443: if (ref($settings) eq 'HASH') {
2444: if (ref($settings->{$item}) eq 'HASH') {
2445: $curroption = $settings->{$item}->{$type};
2446: if ($curroption =~ /^autolimit=(\d*)$/) {
2447: $currlimit = $1;
2448: }
2449: }
2450: }
2451: if (!$curroption) {
2452: $curroption = 'norequest';
2453: }
2454: $datatable .= '<th>'.$titles{$item}.'</th>';
2455: foreach my $option (@options) {
2456: my $val = $option;
2457: if ($option eq 'norequest') {
2458: $val = 0;
2459: }
2460: if ($option eq 'validate') {
2461: my $canvalidate = 0;
2462: if (ref($validations{$item}) eq 'HASH') {
2463: if ($validations{$item}{$type}) {
2464: $canvalidate = 1;
2465: }
2466: }
2467: next if (!$canvalidate);
2468: }
2469: my $checked = '';
2470: if ($option eq $curroption) {
2471: $checked = ' checked="checked"';
2472: } elsif ($option eq 'autolimit') {
2473: if ($curroption =~ /^autolimit/) {
2474: $checked = ' checked="checked"';
2475: }
2476: }
2477: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2478: '<input type="radio" name="crsreq_'.$item.
2479: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2480: $titles{$option}.'</label>';
1.101 raeburn 2481: if ($option eq 'autolimit') {
1.127 raeburn 2482: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2483: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2484: 'value="'.$currlimit.'" />';
1.101 raeburn 2485: }
1.127 raeburn 2486: $cell{$item} .= '</span> ';
1.103 raeburn 2487: if ($option eq 'autolimit') {
1.127 raeburn 2488: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2489: }
1.101 raeburn 2490: }
1.163 raeburn 2491: } elsif ($context eq 'requestauthor') {
2492: my $curroption;
2493: if (ref($settings) eq 'HASH') {
2494: $curroption = $settings->{$type};
2495: }
2496: if (!$curroption) {
2497: $curroption = 'norequest';
2498: }
2499: foreach my $option (@options) {
2500: my $val = $option;
2501: if ($option eq 'norequest') {
2502: $val = 0;
2503: }
2504: my $checked = '';
2505: if ($option eq $curroption) {
2506: $checked = ' checked="checked"';
2507: }
2508: $datatable .= '<span class="LC_nobreak"><label>'.
2509: '<input type="radio" name="authorreq_'.$type.
2510: '" value="'.$val.'"'.$checked.' />'.
2511: $titles{$option}.'</label></span> ';
2512: }
1.101 raeburn 2513: } else {
2514: my $checked = 'checked="checked" ';
1.413 raeburn 2515: if ($item eq 'timezone') {
2516: $checked = '';
2517: }
1.101 raeburn 2518: if (ref($settings) eq 'HASH') {
2519: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2520: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2521: $checked = '';
2522: } elsif ($settings->{$item}->{$type} == 1) {
2523: $checked = 'checked="checked" ';
2524: }
1.78 raeburn 2525: }
1.72 raeburn 2526: }
1.101 raeburn 2527: $datatable .= '<span class="LC_nobreak"><label>'.
2528: '<input type="checkbox" name="'.$context.'_'.$item.
2529: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2530: '</label></span> ';
1.72 raeburn 2531: }
1.101 raeburn 2532: }
2533: if ($context eq 'requestcourses') {
2534: $datatable .= '</tr><tr>';
2535: foreach my $item (@usertools) {
1.106 raeburn 2536: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2537: }
2538: $datatable .= '</tr></table>';
1.72 raeburn 2539: }
1.86 raeburn 2540: $datatable .= '</td>';
1.163 raeburn 2541: unless (($context eq 'requestcourses') ||
2542: ($context eq 'requestauthor')) {
1.86 raeburn 2543: $datatable .=
1.197 raeburn 2544: '<td class="LC_right_item">'.
1.429 raeburn 2545: '<span class="LC_nobreak">'.
1.3 raeburn 2546: '<input type="text" name="quota_'.$type.
1.72 raeburn 2547: '" value="'.$currdefquota.
1.197 raeburn 2548: '" size="5" /></span></td>';
1.86 raeburn 2549: }
2550: $datatable .= '</tr>';
1.3 raeburn 2551: }
2552: }
2553: }
1.163 raeburn 2554: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2555: $defaultquota = '20';
2556: if (ref($settings) eq 'HASH') {
2557: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2558: $defaultquota = $settings->{'defaultquota'}->{'default'};
2559: } elsif (defined($settings->{'default'})) {
2560: $defaultquota = $settings->{'default'};
2561: }
1.3 raeburn 2562: }
2563: }
2564: $typecount ++;
2565: $css_class = $typecount%2?' class="LC_odd_row"':'';
2566: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2567: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2568: '<td class="LC_left_item">';
1.101 raeburn 2569: if ($context eq 'requestcourses') {
2570: $datatable .= '<table><tr>';
2571: }
2572: my %defcell;
1.72 raeburn 2573: foreach my $item (@usertools) {
1.101 raeburn 2574: if ($context eq 'requestcourses') {
2575: my ($curroption,$currlimit);
2576: if (ref($settings) eq 'HASH') {
2577: if (ref($settings->{$item}) eq 'HASH') {
2578: $curroption = $settings->{$item}->{'default'};
2579: if ($curroption =~ /^autolimit=(\d*)$/) {
2580: $currlimit = $1;
2581: }
2582: }
2583: }
2584: if (!$curroption) {
2585: $curroption = 'norequest';
2586: }
2587: $datatable .= '<th>'.$titles{$item}.'</th>';
2588: foreach my $option (@options) {
2589: my $val = $option;
2590: if ($option eq 'norequest') {
2591: $val = 0;
2592: }
2593: if ($option eq 'validate') {
2594: my $canvalidate = 0;
2595: if (ref($validations{$item}) eq 'HASH') {
2596: if ($validations{$item}{'default'}) {
2597: $canvalidate = 1;
2598: }
2599: }
2600: next if (!$canvalidate);
2601: }
2602: my $checked = '';
2603: if ($option eq $curroption) {
2604: $checked = ' checked="checked"';
2605: } elsif ($option eq 'autolimit') {
2606: if ($curroption =~ /^autolimit/) {
2607: $checked = ' checked="checked"';
2608: }
2609: }
2610: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2611: '<input type="radio" name="crsreq_'.$item.
2612: '_default" value="'.$val.'"'.$checked.' />'.
2613: $titles{$option}.'</label>';
2614: if ($option eq 'autolimit') {
1.127 raeburn 2615: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2616: $item.'_limit_default" size="1" '.
2617: 'value="'.$currlimit.'" />';
2618: }
1.127 raeburn 2619: $defcell{$item} .= '</span> ';
1.104 raeburn 2620: if ($option eq 'autolimit') {
1.127 raeburn 2621: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2622: }
1.101 raeburn 2623: }
1.163 raeburn 2624: } elsif ($context eq 'requestauthor') {
2625: my $curroption;
2626: if (ref($settings) eq 'HASH') {
1.172 raeburn 2627: $curroption = $settings->{'default'};
1.163 raeburn 2628: }
2629: if (!$curroption) {
2630: $curroption = 'norequest';
2631: }
2632: foreach my $option (@options) {
2633: my $val = $option;
2634: if ($option eq 'norequest') {
2635: $val = 0;
2636: }
2637: my $checked = '';
2638: if ($option eq $curroption) {
2639: $checked = ' checked="checked"';
2640: }
2641: $datatable .= '<span class="LC_nobreak"><label>'.
2642: '<input type="radio" name="authorreq_default"'.
2643: ' value="'.$val.'"'.$checked.' />'.
2644: $titles{$option}.'</label></span> ';
2645: }
1.101 raeburn 2646: } else {
2647: my $checked = 'checked="checked" ';
2648: if (ref($settings) eq 'HASH') {
2649: if (ref($settings->{$item}) eq 'HASH') {
2650: if ($settings->{$item}->{'default'} == 0) {
2651: $checked = '';
2652: } elsif ($settings->{$item}->{'default'} == 1) {
2653: $checked = 'checked="checked" ';
2654: }
1.78 raeburn 2655: }
1.72 raeburn 2656: }
1.101 raeburn 2657: $datatable .= '<span class="LC_nobreak"><label>'.
2658: '<input type="checkbox" name="'.$context.'_'.$item.
2659: '" value="default" '.$checked.'/>'.$titles{$item}.
2660: '</label></span> ';
2661: }
2662: }
2663: if ($context eq 'requestcourses') {
2664: $datatable .= '</tr><tr>';
2665: foreach my $item (@usertools) {
1.106 raeburn 2666: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2667: }
1.101 raeburn 2668: $datatable .= '</tr></table>';
1.72 raeburn 2669: }
1.86 raeburn 2670: $datatable .= '</td>';
1.163 raeburn 2671: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2672: $datatable .= '<td class="LC_right_item">'.
1.429 raeburn 2673: '<span class="LC_nobreak">'.
1.86 raeburn 2674: '<input type="text" name="defaultquota" value="'.
1.429 raeburn 2675: $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2676: }
2677: $datatable .= '</tr>';
1.72 raeburn 2678: $typecount ++;
2679: $css_class = $typecount%2?' class="LC_odd_row"':'';
2680: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2681: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2682: if ($context eq 'requestcourses') {
1.109 raeburn 2683: $datatable .= &mt('(overrides affiliation, if set)').
2684: '</td>'.
2685: '<td class="LC_left_item">'.
2686: '<table><tr>';
1.101 raeburn 2687: } else {
1.109 raeburn 2688: $datatable .= &mt('(overrides affiliation, if checked)').
2689: '</td>'.
2690: '<td class="LC_left_item" colspan="2">'.
2691: '<br />';
1.101 raeburn 2692: }
2693: my %advcell;
1.72 raeburn 2694: foreach my $item (@usertools) {
1.101 raeburn 2695: if ($context eq 'requestcourses') {
2696: my ($curroption,$currlimit);
2697: if (ref($settings) eq 'HASH') {
2698: if (ref($settings->{$item}) eq 'HASH') {
2699: $curroption = $settings->{$item}->{'_LC_adv'};
2700: if ($curroption =~ /^autolimit=(\d*)$/) {
2701: $currlimit = $1;
2702: }
2703: }
2704: }
2705: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2706: my $checked = '';
2707: if ($curroption eq '') {
2708: $checked = ' checked="checked"';
2709: }
2710: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2711: '<input type="radio" name="crsreq_'.$item.
2712: '__LC_adv" value=""'.$checked.' />'.
2713: &mt('No override set').'</label></span> ';
1.101 raeburn 2714: foreach my $option (@options) {
2715: my $val = $option;
2716: if ($option eq 'norequest') {
2717: $val = 0;
2718: }
2719: if ($option eq 'validate') {
2720: my $canvalidate = 0;
2721: if (ref($validations{$item}) eq 'HASH') {
2722: if ($validations{$item}{'_LC_adv'}) {
2723: $canvalidate = 1;
2724: }
2725: }
2726: next if (!$canvalidate);
2727: }
2728: my $checked = '';
1.104 raeburn 2729: if ($val eq $curroption) {
1.101 raeburn 2730: $checked = ' checked="checked"';
2731: } elsif ($option eq 'autolimit') {
2732: if ($curroption =~ /^autolimit/) {
2733: $checked = ' checked="checked"';
2734: }
2735: }
2736: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2737: '<input type="radio" name="crsreq_'.$item.
2738: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2739: $titles{$option}.'</label>';
2740: if ($option eq 'autolimit') {
1.127 raeburn 2741: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2742: $item.'_limit__LC_adv" size="1" '.
2743: 'value="'.$currlimit.'" />';
2744: }
1.127 raeburn 2745: $advcell{$item} .= '</span> ';
1.104 raeburn 2746: if ($option eq 'autolimit') {
1.127 raeburn 2747: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2748: }
1.101 raeburn 2749: }
1.163 raeburn 2750: } elsif ($context eq 'requestauthor') {
2751: my $curroption;
2752: if (ref($settings) eq 'HASH') {
2753: $curroption = $settings->{'_LC_adv'};
2754: }
2755: my $checked = '';
2756: if ($curroption eq '') {
2757: $checked = ' checked="checked"';
2758: }
2759: $datatable .= '<span class="LC_nobreak"><label>'.
2760: '<input type="radio" name="authorreq__LC_adv"'.
2761: ' value=""'.$checked.' />'.
2762: &mt('No override set').'</label></span> ';
2763: foreach my $option (@options) {
2764: my $val = $option;
2765: if ($option eq 'norequest') {
2766: $val = 0;
2767: }
2768: my $checked = '';
2769: if ($val eq $curroption) {
2770: $checked = ' checked="checked"';
2771: }
2772: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2773: '<input type="radio" name="authorreq__LC_adv"'.
2774: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2775: $titles{$option}.'</label></span> ';
2776: }
1.101 raeburn 2777: } else {
2778: my $checked = 'checked="checked" ';
2779: if (ref($settings) eq 'HASH') {
2780: if (ref($settings->{$item}) eq 'HASH') {
2781: if ($settings->{$item}->{'_LC_adv'} == 0) {
2782: $checked = '';
2783: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2784: $checked = 'checked="checked" ';
2785: }
1.79 raeburn 2786: }
1.72 raeburn 2787: }
1.101 raeburn 2788: $datatable .= '<span class="LC_nobreak"><label>'.
2789: '<input type="checkbox" name="'.$context.'_'.$item.
2790: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2791: '</label></span> ';
2792: }
2793: }
2794: if ($context eq 'requestcourses') {
2795: $datatable .= '</tr><tr>';
2796: foreach my $item (@usertools) {
1.106 raeburn 2797: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2798: }
1.101 raeburn 2799: $datatable .= '</tr></table>';
1.72 raeburn 2800: }
1.98 raeburn 2801: $datatable .= '</td></tr>';
1.30 raeburn 2802: $$rowtotal += $typecount;
1.3 raeburn 2803: return $datatable;
2804: }
2805:
1.163 raeburn 2806: sub print_requestmail {
1.305 raeburn 2807: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2808: my ($now,$datatable,%currapp);
1.102 raeburn 2809: $now = time;
2810: if (ref($settings) eq 'HASH') {
2811: if (ref($settings->{'notify'}) eq 'HASH') {
2812: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2813: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2814: }
2815: }
2816: }
1.191 raeburn 2817: my $numinrow = 2;
1.224 raeburn 2818: my $css_class;
1.305 raeburn 2819: if ($$rowtotal%2) {
2820: $css_class = 'LC_odd_row';
2821: }
2822: if ($customcss) {
2823: $css_class .= " $customcss";
2824: }
2825: $css_class =~ s/^\s+//;
2826: if ($css_class) {
2827: $css_class = ' class="'.$css_class.'"';
2828: }
2829: if ($rowstyle) {
2830: $css_class .= ' style="'.$rowstyle.'"';
2831: }
1.163 raeburn 2832: my $text;
2833: if ($action eq 'requestcourses') {
2834: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2835: } elsif ($action eq 'requestauthor') {
2836: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2837: } else {
1.224 raeburn 2838: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2839: }
1.224 raeburn 2840: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2841: ' <td>'.$text.'</td>'.
1.102 raeburn 2842: ' <td class="LC_left_item">';
1.191 raeburn 2843: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2844: $action.'notifyapproval',%currapp);
1.191 raeburn 2845: if ($numdc > 0) {
2846: $datatable .= $table;
1.102 raeburn 2847: } else {
2848: $datatable .= &mt('There are no active Domain Coordinators');
2849: }
2850: $datatable .='</td></tr>';
2851: return $datatable;
2852: }
2853:
1.216 raeburn 2854: sub print_studentcode {
2855: my ($settings,$rowtotal) = @_;
2856: my $rownum = 0;
1.218 raeburn 2857: my ($output,%current);
1.325 raeburn 2858: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2859: if (ref($settings) eq 'HASH') {
2860: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2861: foreach my $type (@crstypes) {
2862: $current{$type} = $settings->{'uniquecode'}{$type};
2863: }
1.218 raeburn 2864: }
2865: }
2866: $output .= '<tr>'.
2867: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2868: '<td class="LC_left_item">';
2869: foreach my $type (@crstypes) {
2870: my $check = ' ';
2871: if ($current{$type}) {
2872: $check = ' checked="checked" ';
2873: }
2874: $output .= '<span class="LC_nobreak"><label>'.
2875: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2876: &mt($type).'</label></span>'.(' 'x2).' ';
2877: }
2878: $output .= '</td></tr>';
2879: $$rowtotal ++;
2880: return $output;
1.216 raeburn 2881: }
2882:
2883: sub print_textbookcourses {
1.242 raeburn 2884: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2885: my $rownum = 0;
2886: my $css_class;
2887: my $itemcount = 1;
2888: my $maxnum = 0;
2889: my $bookshash;
2890: if (ref($settings) eq 'HASH') {
1.242 raeburn 2891: $bookshash = $settings->{$type};
1.216 raeburn 2892: }
2893: my %ordered;
2894: if (ref($bookshash) eq 'HASH') {
2895: foreach my $item (keys(%{$bookshash})) {
2896: if (ref($bookshash->{$item}) eq 'HASH') {
2897: my $num = $bookshash->{$item}{'order'};
2898: $ordered{$num} = $item;
2899: }
2900: }
2901: }
2902: my $confname = $dom.'-domainconfig';
2903: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2904: my $maxnum = scalar(keys(%ordered));
2905: my $datatable;
1.216 raeburn 2906: if (keys(%ordered)) {
2907: my @items = sort { $a <=> $b } keys(%ordered);
2908: for (my $i=0; $i<@items; $i++) {
2909: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2910: my $key = $ordered{$items[$i]};
2911: my %coursehash=&Apache::lonnet::coursedescription($key);
2912: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2913: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2914: if (ref($bookshash->{$key}) eq 'HASH') {
2915: $subject = $bookshash->{$key}->{'subject'};
2916: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2917: if ($type eq 'textbooks') {
1.243 raeburn 2918: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2919: $author = $bookshash->{$key}->{'author'};
2920: $image = $bookshash->{$key}->{'image'};
2921: if ($image ne '') {
2922: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2923: my $imagethumb = "$path/tn-".$imagefile;
2924: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2925: }
1.216 raeburn 2926: }
2927: }
1.242 raeburn 2928: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2929: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2930: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2931: for (my $k=0; $k<=$maxnum; $k++) {
2932: my $vpos = $k+1;
2933: my $selstr;
2934: if ($k == $i) {
2935: $selstr = ' selected="selected" ';
2936: }
2937: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2938: }
2939: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2940: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2941: &mt('Delete?').'</label></span></td>'.
2942: '<td colspan="2">'.
1.242 raeburn 2943: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2944: (' 'x2).
1.242 raeburn 2945: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2946: if ($type eq 'textbooks') {
2947: $datatable .= (' 'x2).
1.243 raeburn 2948: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2949: (' 'x2).
1.242 raeburn 2950: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2951: (' 'x2).
2952: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2953: if ($image) {
1.267 raeburn 2954: $datatable .= $imgsrc.
1.242 raeburn 2955: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2956: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2957: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2958: }
2959: if ($switchserver) {
2960: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2961: } else {
2962: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2963: }
1.216 raeburn 2964: }
1.242 raeburn 2965: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2966: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2967: $coursetitle.'</span></td></tr>'."\n";
2968: $itemcount ++;
2969: }
2970: }
2971: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2972: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2973: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2974: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2975: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2976: for (my $k=0; $k<$maxnum+1; $k++) {
2977: my $vpos = $k+1;
2978: my $selstr;
2979: if ($k == $maxnum) {
2980: $selstr = ' selected="selected" ';
2981: }
2982: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2983: }
2984: $datatable .= '</select> '."\n".
1.334 raeburn 2985: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2986: '<td colspan="2">'.
1.242 raeburn 2987: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2988: (' 'x2).
1.242 raeburn 2989: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2990: (' 'x2);
2991: if ($type eq 'textbooks') {
1.243 raeburn 2992: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2993: (' 'x2).
2994: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2995: (' 'x2).
2996: '<span class="LC_nobreak">'.&mt('Image:').' ';
2997: if ($switchserver) {
2998: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2999: } else {
3000: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
3001: }
1.334 raeburn 3002: $datatable .= '</span>'."\n";
1.216 raeburn 3003: }
1.334 raeburn 3004: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 3005: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
3006: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 3007: &Apache::loncommon::selectcourse_link
1.334 raeburn 3008: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 3009: '</span></td>'."\n".
3010: '</tr>'."\n";
3011: $itemcount ++;
3012: return $datatable;
3013: }
3014:
1.217 raeburn 3015: sub textbookcourses_javascript {
1.242 raeburn 3016: my ($settings) = @_;
3017: return unless(ref($settings) eq 'HASH');
3018: my (%ordered,%total,%jstext);
3019: foreach my $type ('textbooks','templates') {
3020: $total{$type} = 0;
3021: if (ref($settings->{$type}) eq 'HASH') {
3022: foreach my $item (keys(%{$settings->{$type}})) {
3023: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3024: my $num = $settings->{$type}->{$item}{'order'};
3025: $ordered{$type}{$num} = $item;
3026: }
3027: }
3028: $total{$type} = scalar(keys(%{$settings->{$type}}));
3029: }
3030: my @jsarray = ();
3031: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3032: push(@jsarray,$ordered{$type}{$item});
3033: }
3034: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3035: }
3036: return <<"ENDSCRIPT";
3037: <script type="text/javascript">
3038: // <![CDATA[
1.242 raeburn 3039: function reorderBooks(form,item,caller) {
1.217 raeburn 3040: var changedVal;
1.242 raeburn 3041: $jstext{'textbooks'};
3042: $jstext{'templates'};
3043: var newpos;
3044: var maxh;
3045: if (caller == 'textbooks') {
3046: newpos = 'textbooks_addbook_pos';
3047: maxh = 1 + $total{'textbooks'};
3048: } else {
3049: newpos = 'templates_addbook_pos';
3050: maxh = 1 + $total{'templates'};
3051: }
1.217 raeburn 3052: var current = new Array;
3053: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3054: if (item == newpos) {
3055: changedVal = newitemVal;
3056: } else {
3057: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3058: current[newitemVal] = newpos;
3059: }
1.242 raeburn 3060: if (caller == 'textbooks') {
3061: for (var i=0; i<textbooks.length; i++) {
3062: var elementName = 'textbooks_'+textbooks[i];
3063: if (elementName != item) {
3064: if (form.elements[elementName]) {
3065: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3066: current[currVal] = elementName;
3067: }
3068: }
3069: }
3070: }
3071: if (caller == 'templates') {
3072: for (var i=0; i<templates.length; i++) {
3073: var elementName = 'templates_'+templates[i];
3074: if (elementName != item) {
3075: if (form.elements[elementName]) {
3076: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3077: current[currVal] = elementName;
3078: }
1.217 raeburn 3079: }
3080: }
3081: }
3082: var oldVal;
3083: for (var j=0; j<maxh; j++) {
3084: if (current[j] == undefined) {
3085: oldVal = j;
3086: }
3087: }
3088: if (oldVal < changedVal) {
3089: for (var k=oldVal+1; k<=changedVal ; k++) {
3090: var elementName = current[k];
3091: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3092: }
3093: } else {
3094: for (var k=changedVal; k<oldVal; k++) {
3095: var elementName = current[k];
3096: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3097: }
3098: }
3099: return;
3100: }
3101:
3102: // ]]>
3103: </script>
3104:
3105: ENDSCRIPT
3106: }
3107:
1.267 raeburn 3108: sub ltitools_javascript {
3109: my ($settings) = @_;
1.319 raeburn 3110: my $togglejs = <itools_toggle_js();
3111: unless (ref($settings) eq 'HASH') {
3112: return $togglejs;
3113: }
1.267 raeburn 3114: my (%ordered,$total,%jstext);
3115: $total = 0;
3116: foreach my $item (keys(%{$settings})) {
3117: if (ref($settings->{$item}) eq 'HASH') {
3118: my $num = $settings->{$item}{'order'};
3119: $ordered{$num} = $item;
3120: }
3121: }
3122: $total = scalar(keys(%{$settings}));
3123: my @jsarray = ();
3124: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3125: push(@jsarray,$ordered{$item});
3126: }
3127: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3128: return <<"ENDSCRIPT";
3129: <script type="text/javascript">
3130: // <![CDATA[
1.319 raeburn 3131: function reorderLTITools(form,item) {
1.267 raeburn 3132: var changedVal;
3133: $jstext
3134: var newpos = 'ltitools_add_pos';
3135: var maxh = 1 + $total;
3136: var current = new Array;
3137: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3138: if (item == newpos) {
3139: changedVal = newitemVal;
3140: } else {
3141: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3142: current[newitemVal] = newpos;
3143: }
3144: for (var i=0; i<ltitools.length; i++) {
3145: var elementName = 'ltitools_'+ltitools[i];
3146: if (elementName != item) {
3147: if (form.elements[elementName]) {
3148: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3149: current[currVal] = elementName;
3150: }
3151: }
3152: }
3153: var oldVal;
3154: for (var j=0; j<maxh; j++) {
3155: if (current[j] == undefined) {
3156: oldVal = j;
3157: }
3158: }
3159: if (oldVal < changedVal) {
3160: for (var k=oldVal+1; k<=changedVal ; k++) {
3161: var elementName = current[k];
3162: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3163: }
3164: } else {
3165: for (var k=changedVal; k<oldVal; k++) {
3166: var elementName = current[k];
3167: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3168: }
3169: }
3170: return;
3171: }
3172:
3173: // ]]>
3174: </script>
3175:
1.319 raeburn 3176: $togglejs
3177:
3178: ENDSCRIPT
3179: }
3180:
3181: sub ltitools_toggle_js {
3182: return <<"ENDSCRIPT";
3183: <script type="text/javascript">
3184: // <![CDATA[
3185:
3186: function toggleLTITools(form,setting,item) {
3187: var radioname = '';
3188: var divid = '';
3189: if ((setting == 'passback') || (setting == 'roster')) {
3190: radioname = 'ltitools_'+setting+'_'+item;
3191: divid = 'ltitools_'+setting+'time_'+item;
3192: var num = form.elements[radioname].length;
3193: if (num) {
3194: var setvis = '';
3195: for (var i=0; i<num; i++) {
3196: if (form.elements[radioname][i].checked) {
3197: if (form.elements[radioname][i].value == '1') {
3198: if (document.getElementById(divid)) {
3199: document.getElementById(divid).style.display = 'inline-block';
3200: }
3201: setvis = 1;
3202: }
3203: break;
3204: }
3205: }
3206: }
3207: if (!setvis) {
3208: if (document.getElementById(divid)) {
3209: document.getElementById(divid).style.display = 'none';
3210: }
3211: }
3212: }
1.324 raeburn 3213: if (setting == 'user') {
3214: divid = 'ltitools_'+setting+'_div_'+item;
3215: var checkid = 'ltitools_'+setting+'_field_'+item;
3216: if (document.getElementById(divid)) {
3217: if (document.getElementById(checkid)) {
3218: if (document.getElementById(checkid).checked) {
3219: document.getElementById(divid).style.display = 'inline-block';
3220: } else {
3221: document.getElementById(divid).style.display = 'none';
3222: }
3223: }
3224: }
3225: }
1.319 raeburn 3226: return;
3227: }
3228: // ]]>
3229: </script>
3230:
1.267 raeburn 3231: ENDSCRIPT
3232: }
3233:
1.381 raeburn 3234: sub wafproxy_javascript {
3235: my ($dom) = @_;
3236: return <<"ENDSCRIPT";
3237: <script type="text/javascript">
3238: // <![CDATA[
3239: function updateWAF() {
3240: if (document.getElementById('wafproxy_remoteip')) {
3241: var wafremote = 0;
3242: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3243: wafremote = 1;
3244: }
3245: var fields = new Array('header','trust');
3246: for (var i=0; i<fields.length; i++) {
3247: if (document.getElementById('wafproxy_'+fields[i])) {
3248: if (wafremote == 1) {
3249: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3250: }
3251: else {
3252: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3253: }
3254: }
3255: }
3256: if (document.getElementById('wafproxyranges_$dom')) {
3257: if (wafremote == 1) {
3258: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3259: } else {
3260: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3261: if (document.display.wafproxy_vpnaccess[i].checked) {
3262: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3263: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3264: }
3265: }
3266: }
3267: }
3268: }
3269: }
3270: return;
3271: }
3272:
3273: function checkWAF() {
3274: if (document.getElementById('wafproxy_remoteip')) {
3275: var wafvpn = 0;
3276: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3277: if (document.display.wafproxy_vpnaccess[i].checked) {
3278: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3279: wafvpn = 1;
3280: }
3281: break;
3282: }
3283: }
3284: var vpn = new Array('vpnint','vpnext');
3285: for (var i=0; i<vpn.length; i++) {
3286: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3287: if (wafvpn == 1) {
3288: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3289: }
3290: else {
3291: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3292: }
3293: }
3294: }
3295: if (document.getElementById('wafproxyranges_$dom')) {
3296: if (wafvpn == 1) {
3297: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3298: }
3299: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3300: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3301: }
3302: }
3303: }
3304: return;
3305: }
3306:
3307: function toggleWAF() {
3308: if (document.getElementById('wafproxy_table')) {
3309: var wafproxy = 0;
3310: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3311: if (document.display.wafproxy_${dom}[i].checked) {
3312: if (document.display.wafproxy_${dom}[i].value == 1) {
3313: wafproxy = 1;
3314: break;
3315: }
3316: }
3317: }
3318: if (wafproxy == 1) {
3319: document.getElementById('wafproxy_table').style.display='inline';
3320: }
3321: else {
3322: document.getElementById('wafproxy_table').style.display='none';
3323: }
3324: if (document.getElementById('wafproxyrow_${dom}')) {
3325: if (wafproxy == 1) {
3326: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3327: }
3328: else {
3329: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3330: }
3331: }
3332: if (document.getElementById('nowafproxyrow_$dom')) {
3333: if (wafproxy == 1) {
3334: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3335: }
3336: else {
3337: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3338: }
3339: }
3340: }
3341: return;
3342: }
3343: // ]]>
3344: </script>
3345:
3346: ENDSCRIPT
3347: }
3348:
1.372 raeburn 3349: sub proctoring_javascript {
3350: my ($settings) = @_;
3351: my (%ordered,$total,%jstext);
3352: $total = 0;
3353: if (ref($settings) eq 'HASH') {
3354: foreach my $item (keys(%{$settings})) {
3355: if (ref($settings->{$item}) eq 'HASH') {
3356: my $num = $settings->{$item}{'order'};
3357: $ordered{$num} = $item;
3358: }
3359: }
3360: $total = scalar(keys(%{$settings}));
3361: } else {
3362: %ordered = (
3363: 0 => 'proctorio',
3364: 1 => 'examity',
3365: );
3366: $total = 2;
3367: }
3368: my @jsarray = ();
3369: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3370: push(@jsarray,$ordered{$item});
3371: }
3372: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3373: return <<"ENDSCRIPT";
3374: <script type="text/javascript">
3375: // <![CDATA[
3376: function reorderProctoring(form,item) {
3377: var changedVal;
3378: $jstext
3379: var maxh = $total;
3380: var current = new Array;
3381: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3382: for (var i=0; i<proctors.length; i++) {
3383: var elementName = 'proctoring_pos_'+proctors[i];
3384: if (elementName != item) {
3385: if (form.elements[elementName]) {
3386: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3387: current[currVal] = elementName;
3388: }
3389: }
3390: }
3391: var oldVal;
3392: for (var j=0; j<maxh; j++) {
3393: if (current[j] == undefined) {
3394: oldVal = j;
3395: }
3396: }
3397: if (oldVal < changedVal) {
3398: for (var k=oldVal+1; k<=changedVal ; k++) {
3399: var elementName = current[k];
3400: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3401: }
3402: } else {
3403: for (var k=changedVal; k<oldVal; k++) {
3404: var elementName = current[k];
3405: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3406: }
3407: }
3408: return;
3409: }
3410:
3411: function toggleProctoring(form,item) {
3412: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3413: if (fieldsets.length) {
3414: var radioname = 'proctoring_available_'+item;
3415: var num = form.elements[radioname].length;
3416: if (num) {
3417: var setvis = '';
3418: for (var i=0; i<num; i++) {
3419: if (form.elements[radioname][i].checked) {
3420: if (form.elements[radioname][i].value == '1') {
3421: setvis = 1;
3422: break;
3423: }
3424: }
3425: }
3426: for (var j=0; j<fieldsets.length; j++) {
3427: if (setvis) {
3428: fieldsets[j].style.display = 'block';
3429: } else {
3430: fieldsets[j].style.display = 'none';
3431: }
3432: }
3433: }
3434: }
3435: return;
3436: }
3437:
3438: // ]]>
3439: </script>
3440:
3441: ENDSCRIPT
3442: }
3443:
3444:
1.320 raeburn 3445: sub lti_javascript {
1.405 raeburn 3446: my ($dom,$settings) = @_;
3447: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3448: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3449: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3450: return $togglejs.'
3451: <script type="text/javascript">
3452: // <![CDATA[
3453:
3454: '.$linkprot_js.'
3455:
3456: // ]]>
3457: </script>
3458: ';
1.320 raeburn 3459: }
3460: my (%ordered,$total,%jstext);
1.390 raeburn 3461: $total = scalar(keys(%{$settings}));
1.320 raeburn 3462: foreach my $item (keys(%{$settings})) {
3463: if (ref($settings->{$item}) eq 'HASH') {
3464: my $num = $settings->{$item}{'order'};
1.390 raeburn 3465: if ($num eq '') {
3466: $num = $total - 1;
3467: }
1.320 raeburn 3468: $ordered{$num} = $item;
3469: }
3470: }
3471: my @jsarray = ();
3472: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3473: push(@jsarray,$ordered{$item});
3474: }
3475: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3476: return <<"ENDSCRIPT";
3477: <script type="text/javascript">
3478: // <![CDATA[
3479: function reorderLTI(form,item) {
3480: var changedVal;
3481: $jstext
3482: var newpos = 'lti_pos_add';
3483: var maxh = 1 + $total;
3484: var current = new Array;
3485: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3486: if (item == newpos) {
3487: changedVal = newitemVal;
3488: } else {
3489: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3490: current[newitemVal] = newpos;
3491: }
3492: for (var i=0; i<lti.length; i++) {
3493: var elementName = 'lti_pos_'+lti[i];
3494: if (elementName != item) {
3495: if (form.elements[elementName]) {
3496: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3497: current[currVal] = elementName;
3498: }
3499: }
3500: }
3501: var oldVal;
3502: for (var j=0; j<maxh; j++) {
3503: if (current[j] == undefined) {
3504: oldVal = j;
3505: }
3506: }
3507: if (oldVal < changedVal) {
3508: for (var k=oldVal+1; k<=changedVal ; k++) {
3509: var elementName = current[k];
3510: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3511: }
3512: } else {
3513: for (var k=changedVal; k<oldVal; k++) {
3514: var elementName = current[k];
3515: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3516: }
3517: }
3518: return;
3519: }
1.406 raeburn 3520:
3521: $linkprot_js
3522:
1.320 raeburn 3523: // ]]>
3524: </script>
3525:
3526: $togglejs
3527:
3528: ENDSCRIPT
3529: }
3530:
3531: sub lti_toggle_js {
1.405 raeburn 3532: my ($dom) = @_;
1.325 raeburn 3533: my %lcauthparmtext = &Apache::lonlocal::texthash (
3534: localauth => 'Local auth argument',
3535: krb => 'Kerberos domain',
3536: );
1.391 raeburn 3537: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3538: &js_escape(\$crsincalert);
1.405 raeburn 3539: my %servers = &Apache::lonnet::get_servers($dom,'library');
3540: my $primary = &Apache::lonnet::domain($dom,'primary');
3541: my $course_servers = "'".join("','",keys(%servers))."'";
1.320 raeburn 3542: return <<"ENDSCRIPT";
3543: <script type="text/javascript">
3544: // <![CDATA[
3545:
3546: function toggleLTI(form,setting,item) {
1.391 raeburn 3547: if ((setting == 'requser') || (setting == 'crsinc')) {
3548: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3549: var setvis = '';
3550: var radioname = 'lti_requser_'+item;
3551: var num = form.elements[radioname].length;
3552: if (num) {
3553: for (var i=0; i<num; i++) {
3554: if (form.elements[radioname][i].checked) {
3555: if (form.elements[radioname][i].value == '1') {
3556: setvis = 1;
3557: break;
3558: }
3559: }
3560: }
3561: }
3562: if (usrfieldsets.length) {
3563: for (var j=0; j<usrfieldsets.length; j++) {
3564: if (setvis) {
3565: usrfieldsets[j].style.display = 'block';
3566: } else {
3567: usrfieldsets[j].style.display = 'none';
3568: }
3569: }
3570: }
3571: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3572: if (crsfieldsets.length) {
3573: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3574: var num = form.elements[radioname].length;
3575: if (num) {
1.391 raeburn 3576: var crsvis = '';
1.345 raeburn 3577: for (var i=0; i<num; i++) {
3578: if (form.elements[radioname][i].checked) {
3579: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3580: if (setvis == '') {
3581: if (setting == 'crsinc'){
3582: alert("$crsincalert");
3583: form.elements[radioname][0].checked = true;
3584: }
3585: } else {
3586: crsvis = 1;
3587: }
3588: break;
1.345 raeburn 3589: }
3590: }
3591: }
1.391 raeburn 3592: setvis = crsvis;
3593: }
3594: for (var j=0; j<crsfieldsets.length; j++) {
3595: if (setvis) {
3596: crsfieldsets[j].style.display = 'block';
3597: } else {
3598: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3599: }
3600: }
3601: }
1.363 raeburn 3602: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3603: var radioname = '';
3604: var divid = '';
3605: if (setting == 'user') {
3606: radioname = 'lti_mapuser_'+item;
3607: divid = 'lti_userfield_'+item;
1.343 raeburn 3608: } else if (setting == 'crs') {
1.320 raeburn 3609: radioname = 'lti_mapcrs_'+item;
3610: divid = 'lti_crsfield_'+item;
1.363 raeburn 3611: } else if (setting == 'callback') {
3612: radioname = 'lti_callback_'+item;
3613: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3614: } else {
1.351 raeburn 3615: radioname = 'lti_passback_'+item;
1.337 raeburn 3616: divid = 'lti_passback_'+item;
1.320 raeburn 3617: }
3618: var num = form.elements[radioname].length;
3619: if (num) {
3620: var setvis = '';
3621: for (var i=0; i<num; i++) {
3622: if (form.elements[radioname][i].checked) {
1.363 raeburn 3623: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3624: if (form.elements[radioname][i].value == '1') {
3625: if (document.getElementById(divid)) {
3626: document.getElementById(divid).style.display = 'inline-block';
3627: }
3628: setvis = 1;
3629: break;
3630: }
3631: } else {
3632: if (form.elements[radioname][i].value == 'other') {
3633: if (document.getElementById(divid)) {
3634: document.getElementById(divid).style.display = 'inline-block';
3635: }
3636: setvis = 1;
3637: break;
1.320 raeburn 3638: }
3639: }
1.425 raeburn 3640: }
1.320 raeburn 3641: }
3642: if (!setvis) {
3643: if (document.getElementById(divid)) {
3644: document.getElementById(divid).style.display = 'none';
3645: }
3646: }
3647: }
3648: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3649: var numsec = form.elements['lti_crssec_'+item].length;
3650: if (numsec) {
3651: var setvis = '';
3652: for (var i=0; i<numsec; i++) {
3653: if (form.elements['lti_crssec_'+item][i].checked) {
3654: if (form.elements['lti_crssec_'+item][i].value == '1') {
3655: if (document.getElementById('lti_crssecfield_'+item)) {
3656: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3657: setvis = 1;
3658: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3659: if (numsrcsec) {
3660: var setsrcvis = '';
3661: for (var j=0; j<numsrcsec; j++) {
3662: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3663: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3664: if (document.getElementById('lti_secsrcfield_'+item)) {
3665: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3666: setsrcvis = 1;
3667: }
3668: }
3669: }
3670: }
3671: if (!setsrcvis) {
3672: if (document.getElementById('lti_secsrcfield_'+item)) {
3673: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3674: }
3675: }
3676: }
3677: }
3678: }
3679: }
3680: }
3681: if (!setvis) {
3682: if (document.getElementById('lti_crssecfield_'+item)) {
3683: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3684: }
3685: if (document.getElementById('lti_secsrcfield_'+item)) {
3686: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3687: }
3688: }
3689: }
1.325 raeburn 3690: } else if (setting == 'lcauth') {
3691: var numauth = form.elements['lti_lcauth_'+item].length;
3692: if (numauth) {
3693: for (var i=0; i<numauth; i++) {
3694: if (form.elements['lti_lcauth_'+item][i].checked) {
3695: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3696: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3697: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3698: } else {
3699: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3700: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3701: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3702: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3703: } else {
3704: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3705: }
3706: }
3707: }
3708: }
3709: }
3710: }
3711: }
1.326 raeburn 3712: } else if (setting == 'lcmenu') {
3713: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3714: var divid = 'lti_menufield_'+item;
3715: var setvis = '';
3716: for (var i=0; i<menus.length; i++) {
1.425 raeburn 3717: var radioname = menus[i];
1.326 raeburn 3718: var num = form.elements[radioname].length;
3719: if (num) {
3720: for (var j=0; j<num; j++) {
3721: if (form.elements[radioname][j].checked) {
3722: if (form.elements[radioname][j].value == '1') {
3723: if (document.getElementById(divid)) {
3724: document.getElementById(divid).style.display = 'inline-block';
3725: }
3726: setvis = 1;
3727: break;
3728: }
3729: }
3730: }
3731: }
3732: if (setvis == 1) {
3733: break;
3734: }
3735: }
3736: if (!setvis) {
3737: if (document.getElementById(divid)) {
3738: document.getElementById(divid).style.display = 'none';
3739: }
3740: }
1.320 raeburn 3741: }
3742: return;
3743: }
1.405 raeburn 3744:
1.320 raeburn 3745: // ]]>
3746: </script>
3747:
3748: ENDSCRIPT
3749: }
3750:
1.385 raeburn 3751: sub autoupdate_javascript {
3752: return <<"ENDSCRIPT";
3753: <script type="text/javascript">
3754: // <![CDATA[
3755: function toggleLastActiveDays(form) {
3756: var radioname = 'lastactive';
3757: var divid = 'lastactive_div';
3758: var num = form.elements[radioname].length;
3759: if (num) {
3760: var setvis = '';
3761: for (var i=0; i<num; i++) {
3762: if (form.elements[radioname][i].checked) {
3763: if (form.elements[radioname][i].value == '1') {
3764: if (document.getElementById(divid)) {
3765: document.getElementById(divid).style.display = 'inline-block';
3766: }
3767: setvis = 1;
3768: }
3769: break;
3770: }
3771: }
3772: if (!setvis) {
3773: if (document.getElementById(divid)) {
3774: document.getElementById(divid).style.display = 'none';
3775: }
3776: }
3777: }
3778: return;
3779: }
3780: // ]]>
3781: </script>
3782:
3783: ENDSCRIPT
3784: }
3785:
1.399 raeburn 3786: sub autoenroll_javascript {
3787: return <<"ENDSCRIPT";
3788: <script type="text/javascript">
3789: // <![CDATA[
3790: function toggleFailsafe(form) {
3791: var radioname = 'autoenroll_failsafe';
3792: var divid = 'autoenroll_failsafe_div';
3793: var num = form.elements[radioname].length;
3794: if (num) {
3795: var setvis = '';
3796: for (var i=0; i<num; i++) {
3797: if (form.elements[radioname][i].checked) {
3798: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3799: if (document.getElementById(divid)) {
3800: document.getElementById(divid).style.display = 'inline-block';
3801: }
3802: setvis = 1;
3803: }
3804: break;
3805: }
3806: }
3807: if (!setvis) {
3808: if (document.getElementById(divid)) {
3809: document.getElementById(divid).style.display = 'none';
3810: }
3811: }
3812: }
3813: return;
3814: }
3815: // ]]>
3816: </script>
3817:
3818: ENDSCRIPT
3819: }
3820:
1.386 raeburn 3821: sub saml_javascript {
3822: return <<"ENDSCRIPT";
3823: <script type="text/javascript">
3824: // <![CDATA[
1.425 raeburn 3825: function toggleSamlOptions(form,hostid) {
1.386 raeburn 3826: var radioname = 'saml_'+hostid;
3827: var tablecellon = 'samloptionson_'+hostid;
3828: var tablecelloff = 'samloptionsoff_'+hostid;
3829: var num = form.elements[radioname].length;
3830: if (num) {
1.425 raeburn 3831: var setvis = '';
1.386 raeburn 3832: for (var i=0; i<num; i++) {
3833: if (form.elements[radioname][i].checked) {
1.425 raeburn 3834: if (form.elements[radioname][i].value == '1') {
1.386 raeburn 3835: if (document.getElementById(tablecellon)) {
3836: document.getElementById(tablecellon).style.display='';
3837: }
3838: if (document.getElementById(tablecelloff)) {
3839: document.getElementById(tablecelloff).style.display='none';
3840: }
3841: setvis = 1;
3842: }
3843: break;
3844: }
3845: }
3846: if (!setvis) {
3847: if (document.getElementById(tablecellon)) {
3848: document.getElementById(tablecellon).style.display='none';
3849: }
3850: if (document.getElementById(tablecelloff)) {
3851: document.getElementById(tablecelloff).style.display='';
3852: }
3853: }
3854: }
3855: return;
3856: }
3857: // ]]>
3858: </script>
3859:
3860: ENDSCRIPT
3861: }
3862:
1.394 raeburn 3863: sub ipaccess_javascript {
3864: my ($settings) = @_;
3865: my (%ordered,$total,%jstext);
3866: $total = 0;
3867: if (ref($settings) eq 'HASH') {
3868: foreach my $item (keys(%{$settings})) {
3869: if (ref($settings->{$item}) eq 'HASH') {
3870: my $num = $settings->{$item}{'order'};
3871: $ordered{$num} = $item;
3872: }
3873: }
3874: $total = scalar(keys(%{$settings}));
3875: }
3876: my @jsarray = ();
3877: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3878: push(@jsarray,$ordered{$item});
3879: }
3880: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3881: return <<"ENDSCRIPT";
3882: <script type="text/javascript">
3883: // <![CDATA[
3884: function reorderIPaccess(form,item) {
3885: var changedVal;
3886: $jstext
3887: var newpos = 'ipaccess_pos_add';
3888: var maxh = 1 + $total;
3889: var current = new Array;
3890: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3891: if (item == newpos) {
3892: changedVal = newitemVal;
3893: } else {
3894: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3895: current[newitemVal] = newpos;
3896: }
3897: for (var i=0; i<ipaccess.length; i++) {
3898: var elementName = 'ipaccess_pos_'+ipaccess[i];
3899: if (elementName != item) {
3900: if (form.elements[elementName]) {
3901: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3902: current[currVal] = elementName;
3903: }
3904: }
3905: }
3906: var oldVal;
3907: for (var j=0; j<maxh; j++) {
3908: if (current[j] == undefined) {
3909: oldVal = j;
3910: }
3911: }
3912: if (oldVal < changedVal) {
3913: for (var k=oldVal+1; k<=changedVal ; k++) {
3914: var elementName = current[k];
3915: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3916: }
3917: } else {
3918: for (var k=changedVal; k<oldVal; k++) {
3919: var elementName = current[k];
3920: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3921: }
3922: }
3923: return;
3924: }
3925: // ]]>
3926: </script>
3927:
3928: ENDSCRIPT
3929: }
3930:
1.429 raeburn 3931: sub authordefaults_javascript {
3932: my %alert = &Apache::lonlocal::texthash (
3933: reqd => 'Warning: at least one editor needs to be available.',
3934: rest => 'Unchecking this editor disallowed while others unchecked.',
3935: );
3936: &js_escape(\%alert);
3937: return <<"ENDSCRIPT";
3938: <script type="text/javascript">
3939: // <![CDATA[
3940:
3941: function checkEditors(form,checkbox,current) {
3942: if (form.elements[checkbox].length != undefined) {
3943: var count = 0;
3944: for (var i=0; i<form.elements[checkbox].length; i++) {
3945: if (form.elements[checkbox][i].checked) {
3946: count ++;
3947: }
3948: }
3949: if (count == 0) {
3950: if (current.type =='radio') {
3951: current.checked = true;
3952: alert('$alert{reqd}\\n$alert{rest}');
3953: }
3954: }
3955: }
3956: return;
3957: }
3958: // ]]>
3959: </script>
3960:
3961: ENDSCRIPT
3962: }
3963:
1.3 raeburn 3964: sub print_autoenroll {
1.30 raeburn 3965: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3966: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 3967: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3968: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3969: $failsafesty = 'none';
3970: %failsafechecked = (
3971: off => ' checked="checked"',
3972: );
1.3 raeburn 3973: if (ref($settings) eq 'HASH') {
3974: if (exists($settings->{'run'})) {
3975: if ($settings->{'run'} eq '0') {
3976: $runoff = ' checked="checked" ';
3977: $runon = ' ';
3978: } else {
3979: $runon = ' checked="checked" ';
3980: $runoff = ' ';
3981: }
3982: } else {
3983: if ($autorun) {
3984: $runon = ' checked="checked" ';
3985: $runoff = ' ';
3986: } else {
3987: $runoff = ' checked="checked" ';
3988: $runon = ' ';
3989: }
3990: }
1.129 raeburn 3991: if (exists($settings->{'co-owners'})) {
3992: if ($settings->{'co-owners'} eq '0') {
3993: $coownersoff = ' checked="checked" ';
3994: $coownerson = ' ';
3995: } else {
3996: $coownerson = ' checked="checked" ';
3997: $coownersoff = ' ';
3998: }
3999: } else {
4000: $coownersoff = ' checked="checked" ';
4001: $coownerson = ' ';
4002: }
1.3 raeburn 4003: if (exists($settings->{'sender_domain'})) {
4004: $defdom = $settings->{'sender_domain'};
4005: }
1.399 raeburn 4006: if (exists($settings->{'failsafe'})) {
4007: $failsafe = $settings->{'failsafe'};
4008: if ($failsafe eq 'zero') {
1.400 raeburn 4009: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 4010: $failsafechecked{'off'} = '';
4011: $failsafesty = 'inline-block';
4012: } elsif ($failsafe eq 'any') {
4013: $failsafechecked{'any'} = ' checked="checked"';
4014: $failsafechecked{'off'} = '';
4015: }
4016: $autofailsafe = $settings->{'autofailsafe'};
4017: } elsif (exists($settings->{'autofailsafe'})) {
4018: $autofailsafe = $settings->{'autofailsafe'};
4019: if ($autofailsafe ne '') {
4020: $failsafechecked{'zero'} = ' checked="checked"';
4021: $failsafe = 'zero';
1.400 raeburn 4022: $failsafechecked{'off'} = '';
1.399 raeburn 4023: }
1.274 raeburn 4024: }
1.14 raeburn 4025: } else {
4026: if ($autorun) {
4027: $runon = ' checked="checked" ';
4028: $runoff = ' ';
4029: } else {
4030: $runoff = ' checked="checked" ';
4031: $runon = ' ';
4032: }
1.3 raeburn 4033: }
4034: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4035: my $notif_sender;
4036: if (ref($settings) eq 'HASH') {
4037: $notif_sender = $settings->{'sender_uname'};
4038: }
1.3 raeburn 4039: my $datatable='<tr class="LC_odd_row">'.
4040: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4041: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4042: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4043: $runon.' value="1" />'.&mt('Yes').'</label> '.
4044: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4045: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4046: '</tr><tr>'.
4047: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4048: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4049: &mt('username').': '.
4050: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4051: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4052: ': '.$domform.'</span></td></tr>'.
4053: '<tr class="LC_odd_row">'.
4054: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4055: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4056: '<input type="radio" name="autoassign_coowners"'.
4057: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4058: '<label><input type="radio" name="autoassign_coowners"'.
4059: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4060: '</tr><tr>'.
4061: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4062: '<td class="LC_left_item"><span class="LC_nobreak">'.
4063: '<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> '.
4064: '<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 />'.
4065: '<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 4066: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4067: '<span class="LC_nobreak">'.
4068: &mt('Threshold for number of students in section to drop: [_1]',
4069: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4070: '</span></div></td></tr>';
1.274 raeburn 4071: $$rowtotal += 4;
1.3 raeburn 4072: return $datatable;
4073: }
4074:
4075: sub print_autoupdate {
1.30 raeburn 4076: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4077: my ($enable,$datatable);
1.3 raeburn 4078: if ($position eq 'top') {
1.385 raeburn 4079: my %choices = &Apache::lonlocal::texthash (
4080: run => 'Auto-update active?',
4081: classlists => 'Update information in classlists?',
4082: unexpired => 'Skip updates for users without active or future roles?',
4083: lastactive => 'Skip updates for inactive users?',
4084: );
4085: my $itemcount = 0;
1.3 raeburn 4086: my $updateon = ' ';
4087: my $updateoff = ' checked="checked" ';
4088: if (ref($settings) eq 'HASH') {
4089: if ($settings->{'run'} eq '1') {
4090: $updateon = $updateoff;
4091: $updateoff = ' ';
4092: }
4093: }
1.385 raeburn 4094: $enable = '<tr class="LC_odd_row">'.
4095: '<td>'.$choices{'run'}.'</td>'.
4096: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4097: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4098: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4099: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4100: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4101: '</tr>';
1.385 raeburn 4102: my @toggles = ('classlists','unexpired');
4103: my %defaultchecked = ('classlists' => 'off',
4104: 'unexpired' => 'off'
4105: );
4106: $$rowtotal ++;
4107: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4108: \%choices,$itemcount,'','','left','no');
4109: $datatable = $enable.$datatable;
4110: $$rowtotal += $itemcount;
4111: my $lastactiveon = ' ';
4112: my $lastactiveoff = ' checked="checked" ';
4113: my $lastactivestyle = 'none';
4114: my $lastactivedays;
4115: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4116: if (ref($settings) eq 'HASH') {
4117: if ($settings->{'lastactive'} =~ /^\d+$/) {
4118: $lastactiveon = $lastactiveoff;
4119: $lastactiveoff = ' ';
4120: $lastactivestyle = 'inline-block';
4121: $lastactivedays = $settings->{'lastactive'};
4122: }
4123: }
4124: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4125: $datatable .= '<tr'.$css_class.'>'.
4126: '<td>'.$choices{'lastactive'}.'</td>'.
4127: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4128: '<input type="radio" name="lastactive"'.
4129: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4130: ' <label>'.
4131: '<input type="radio" name="lastactive"'.
4132: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4133: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4134: ': '.&mt('inactive = no activity in last [_1] days',
4135: '<input type="text" size="5" name="lastactivedays" value="'.
4136: $lastactivedays.'" />').
4137: '</span></td>'.
4138: '</tr>';
4139: $$rowtotal ++;
1.131 raeburn 4140: } elsif ($position eq 'middle') {
4141: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4142: my $numinrow = 3;
4143: my $locknamesettings;
4144: $datatable .= &insttypes_row($settings,$types,$usertypes,
4145: $dom,$numinrow,$othertitle,
1.305 raeburn 4146: 'lockablenames',$rowtotal);
1.131 raeburn 4147: $$rowtotal ++;
1.3 raeburn 4148: } else {
1.44 raeburn 4149: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4150: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4151: 'permanentemail','id');
1.33 raeburn 4152: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4153: my $numrows = 0;
1.26 raeburn 4154: if (ref($types) eq 'ARRAY') {
4155: if (@{$types} > 0) {
4156: $datatable =
4157: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4158: \@fields,$types,\$numrows);
1.30 raeburn 4159: $$rowtotal += @{$types};
1.26 raeburn 4160: }
1.3 raeburn 4161: }
4162: $datatable .=
4163: &usertype_update_row($settings,{'default' => $othertitle},
4164: \%fieldtitles,\@fields,['default'],
4165: \$numrows);
1.30 raeburn 4166: $$rowtotal ++;
1.3 raeburn 4167: }
4168: return $datatable;
4169: }
4170:
1.125 raeburn 4171: sub print_autocreate {
4172: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4173: my (%createon,%createoff,%currhash);
1.125 raeburn 4174: my @types = ('xml','req');
4175: if (ref($settings) eq 'HASH') {
4176: foreach my $item (@types) {
4177: $createoff{$item} = ' checked="checked" ';
4178: $createon{$item} = ' ';
4179: if (exists($settings->{$item})) {
4180: if ($settings->{$item}) {
4181: $createon{$item} = ' checked="checked" ';
4182: $createoff{$item} = ' ';
4183: }
4184: }
4185: }
1.210 raeburn 4186: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4187: $currhash{$settings->{'xmldc'}} = 1;
4188: }
1.125 raeburn 4189: } else {
4190: foreach my $item (@types) {
4191: $createoff{$item} = ' checked="checked" ';
4192: $createon{$item} = ' ';
4193: }
4194: }
4195: $$rowtotal += 2;
1.191 raeburn 4196: my $numinrow = 2;
1.125 raeburn 4197: my $datatable='<tr class="LC_odd_row">'.
4198: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4199: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4200: '<input type="radio" name="autocreate_xml"'.
4201: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4202: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4203: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4204: '</td></tr><tr>'.
4205: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4206: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4207: '<input type="radio" name="autocreate_req"'.
4208: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4209: '<label><input type="radio" name="autocreate_req"'.
4210: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4211: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4212: 'autocreate_xmldc',%currhash);
1.247 raeburn 4213: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4214: if ($numdc > 1) {
1.247 raeburn 4215: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4216: '</td><td class="LC_left_item">';
1.125 raeburn 4217: } else {
1.247 raeburn 4218: $datatable .= &mt('Course creation processed as:').
4219: '</td><td class="LC_right_item">';
1.125 raeburn 4220: }
1.247 raeburn 4221: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4222: $$rowtotal += $rows;
1.125 raeburn 4223: return $datatable;
4224: }
4225:
1.23 raeburn 4226: sub print_directorysrch {
1.277 raeburn 4227: my ($position,$dom,$settings,$rowtotal) = @_;
4228: my $datatable;
4229: if ($position eq 'top') {
4230: my $instsrchon = ' ';
4231: my $instsrchoff = ' checked="checked" ';
4232: my ($exacton,$containson,$beginson);
4233: my $instlocalon = ' ';
4234: my $instlocaloff = ' checked="checked" ';
4235: if (ref($settings) eq 'HASH') {
4236: if ($settings->{'available'} eq '1') {
4237: $instsrchon = $instsrchoff;
4238: $instsrchoff = ' ';
4239: }
4240: if ($settings->{'localonly'} eq '1') {
4241: $instlocalon = $instlocaloff;
4242: $instlocaloff = ' ';
4243: }
4244: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4245: foreach my $type (@{$settings->{'searchtypes'}}) {
4246: if ($type eq 'exact') {
4247: $exacton = ' checked="checked" ';
4248: } elsif ($type eq 'contains') {
4249: $containson = ' checked="checked" ';
4250: } elsif ($type eq 'begins') {
4251: $beginson = ' checked="checked" ';
4252: }
4253: }
4254: } else {
4255: if ($settings->{'searchtypes'} eq 'exact') {
4256: $exacton = ' checked="checked" ';
4257: } elsif ($settings->{'searchtypes'} eq 'contains') {
4258: $containson = ' checked="checked" ';
4259: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4260: $exacton = ' checked="checked" ';
4261: $containson = ' checked="checked" ';
4262: }
4263: }
1.277 raeburn 4264: }
4265: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4266: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4267:
4268: my $numinrow = 4;
4269: my $cansrchrow = 0;
4270: $datatable='<tr class="LC_odd_row">'.
4271: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4272: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4273: '<input type="radio" name="dirsrch_available"'.
4274: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4275: '<label><input type="radio" name="dirsrch_available"'.
4276: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4277: '</tr><tr>'.
4278: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4279: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4280: '<input type="radio" name="dirsrch_instlocalonly"'.
4281: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4282: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4283: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4284: '</tr>';
4285: $$rowtotal += 2;
4286: if (ref($usertypes) eq 'HASH') {
4287: if (keys(%{$usertypes}) > 0) {
4288: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4289: $numinrow,$othertitle,'cansearch',
4290: $rowtotal);
1.277 raeburn 4291: $cansrchrow = 1;
1.25 raeburn 4292: }
1.23 raeburn 4293: }
1.277 raeburn 4294: if ($cansrchrow) {
4295: $$rowtotal ++;
4296: $datatable .= '<tr>';
4297: } else {
4298: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4299: }
1.277 raeburn 4300: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4301: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4302: foreach my $title (@{$titleorder}) {
4303: if (defined($searchtitles->{$title})) {
4304: my $check = ' ';
4305: if (ref($settings) eq 'HASH') {
4306: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4307: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4308: $check = ' checked="checked" ';
4309: }
1.39 raeburn 4310: }
1.25 raeburn 4311: }
1.277 raeburn 4312: $datatable .= '<td class="LC_left_item">'.
4313: '<span class="LC_nobreak"><label>'.
4314: '<input type="checkbox" name="searchby" '.
4315: 'value="'.$title.'"'.$check.'/>'.
4316: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4317: }
4318: }
1.277 raeburn 4319: $datatable .= '</tr></table></td></tr>';
4320: $$rowtotal ++;
4321: if ($cansrchrow) {
4322: $datatable .= '<tr class="LC_odd_row">';
4323: } else {
4324: $datatable .= '<tr>';
4325: }
4326: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4327: '<td class="LC_left_item" colspan="2">'.
4328: '<span class="LC_nobreak"><label>'.
4329: '<input type="checkbox" name="searchtypes" '.
4330: $exacton.' value="exact" />'.&mt('Exact match').
4331: '</label> '.
4332: '<label><input type="checkbox" name="searchtypes" '.
4333: $beginson.' value="begins" />'.&mt('Begins with').
4334: '</label> '.
4335: '<label><input type="checkbox" name="searchtypes" '.
4336: $containson.' value="contains" />'.&mt('Contains').
4337: '</label></span></td></tr>';
4338: $$rowtotal ++;
1.26 raeburn 4339: } else {
1.277 raeburn 4340: my $domsrchon = ' checked="checked" ';
4341: my $domsrchoff = ' ';
4342: my $domlocalon = ' ';
4343: my $domlocaloff = ' checked="checked" ';
4344: if (ref($settings) eq 'HASH') {
4345: if ($settings->{'lclocalonly'} eq '1') {
4346: $domlocalon = $domlocaloff;
4347: $domlocaloff = ' ';
4348: }
4349: if ($settings->{'lcavailable'} eq '0') {
4350: $domsrchoff = $domsrchon;
4351: $domsrchon = ' ';
4352: }
4353: }
4354: $datatable='<tr class="LC_odd_row">'.
4355: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4356: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4357: '<input type="radio" name="dirsrch_domavailable"'.
4358: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4359: '<label><input type="radio" name="dirsrch_domavailable"'.
4360: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4361: '</tr><tr>'.
4362: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4363: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4364: '<input type="radio" name="dirsrch_domlocalonly"'.
4365: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4366: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4367: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4368: '</tr>';
4369: $$rowtotal += 2;
1.26 raeburn 4370: }
1.25 raeburn 4371: return $datatable;
4372: }
4373:
1.28 raeburn 4374: sub print_contacts {
1.286 raeburn 4375: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4376: my $datatable;
4377: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4378: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4379: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4380: if ($position eq 'top') {
4381: if (ref($settings) eq 'HASH') {
4382: foreach my $item (@contacts) {
4383: if (exists($settings->{$item})) {
4384: $to{$item} = $settings->{$item};
4385: }
4386: }
4387: }
4388: } elsif ($position eq 'middle') {
4389: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4390: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4391: foreach my $type (@mailings) {
4392: $otheremails{$type} = '';
4393: }
1.340 raeburn 4394: } elsif ($position eq 'lower') {
4395: if (ref($settings) eq 'HASH') {
4396: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4397: %lonstatus = %{$settings->{'lonstatus'}};
4398: }
4399: }
1.286 raeburn 4400: } else {
4401: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4402: foreach my $type (@mailings) {
4403: $otheremails{$type} = '';
4404: }
1.286 raeburn 4405: $bccemails{'helpdeskmail'} = '';
4406: $bccemails{'otherdomsmail'} = '';
4407: $includestr{'helpdeskmail'} = '';
4408: $includestr{'otherdomsmail'} = '';
4409: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4410: }
1.28 raeburn 4411: if (ref($settings) eq 'HASH') {
1.340 raeburn 4412: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4413: foreach my $type (@mailings) {
4414: if (exists($settings->{$type})) {
4415: if (ref($settings->{$type}) eq 'HASH') {
4416: foreach my $item (@contacts) {
4417: if ($settings->{$type}{$item}) {
4418: $checked{$type}{$item} = ' checked="checked" ';
4419: }
4420: }
4421: $otheremails{$type} = $settings->{$type}{'others'};
4422: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4423: $bccemails{$type} = $settings->{$type}{'bcc'};
4424: if ($settings->{$type}{'include'} ne '') {
4425: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4426: $includestr{$type} = &unescape($includestr{$type});
4427: }
4428: }
4429: }
4430: } elsif ($type eq 'lonstatusmail') {
4431: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4432: }
1.28 raeburn 4433: }
4434: }
1.286 raeburn 4435: if ($position eq 'bottom') {
4436: foreach my $type (@mailings) {
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: if (ref($settings->{'helpform'}) eq 'HASH') {
4444: if (ref($fields) eq 'ARRAY') {
4445: foreach my $field (@{$fields}) {
4446: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4447: }
1.286 raeburn 4448: }
4449: if (exists($settings->{'helpform'}{'maxsize'})) {
4450: $maxsize = $settings->{'helpform'}{'maxsize'};
4451: } else {
1.289 raeburn 4452: $maxsize = '1.0';
1.286 raeburn 4453: }
4454: } else {
4455: if (ref($fields) eq 'ARRAY') {
4456: foreach my $field (@{$fields}) {
4457: $currfield{$field} = 'yes';
1.134 raeburn 4458: }
1.28 raeburn 4459: }
1.286 raeburn 4460: $maxsize = '1.0';
1.28 raeburn 4461: }
4462: }
4463: } else {
1.286 raeburn 4464: if ($position eq 'top') {
4465: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4466: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4467: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4468: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4469: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4470: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4471: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4472: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4473: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4474: } elsif ($position eq 'bottom') {
4475: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4476: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4477: if (ref($fields) eq 'ARRAY') {
4478: foreach my $field (@{$fields}) {
4479: $currfield{$field} = 'yes';
4480: }
4481: }
4482: $maxsize = '1.0';
4483: }
1.28 raeburn 4484: }
4485: my ($titles,$short_titles) = &contact_titles();
4486: my $rownum = 0;
4487: my $css_class;
1.286 raeburn 4488: if ($position eq 'top') {
4489: foreach my $item (@contacts) {
4490: $css_class = $rownum%2?' class="LC_odd_row"':'';
4491: $datatable .= '<tr'.$css_class.'>'.
4492: '<td><span class="LC_nobreak">'.$titles->{$item}.
4493: '</span></td><td class="LC_right_item">'.
4494: '<input type="text" name="'.$item.'" value="'.
4495: $to{$item}.'" /></td></tr>';
4496: $rownum ++;
4497: }
1.315 raeburn 4498: } elsif ($position eq 'bottom') {
4499: $css_class = $rownum%2?' class="LC_odd_row"':'';
4500: $datatable .= '<tr'.$css_class.'>'.
4501: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4502: &mt('(e-mail, subject, and description always shown)').
4503: '</td><td class="LC_left_item">';
4504: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4505: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4506: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4507: foreach my $field (@{$fields}) {
4508: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4509: if (($field eq 'screenshot') || ($field eq 'cc')) {
4510: $datatable .= ' '.&mt('(logged-in users)');
4511: }
4512: $datatable .='</td><td>';
4513: my $clickaction;
4514: if ($field eq 'screenshot') {
4515: $clickaction = ' onclick="screenshotSize(this);"';
4516: }
4517: if (ref($possoptions->{$field}) eq 'ARRAY') {
4518: foreach my $option (@{$possoptions->{$field}}) {
4519: my $checked;
4520: if ($currfield{$field} eq $option) {
4521: $checked = ' checked="checked"';
4522: }
4523: $datatable .= '<span class="LC_nobreak"><label>'.
4524: '<input type="radio" name="helpform_'.$field.'" '.
4525: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4526: '</label></span>'.(' 'x2);
4527: }
4528: }
4529: if ($field eq 'screenshot') {
4530: my $display;
4531: if ($currfield{$field} eq 'no') {
4532: $display = ' style="display:none"';
4533: }
1.334 raeburn 4534: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4535: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4536: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4537: }
4538: $datatable .= '</td></tr>';
4539: }
4540: $datatable .= '</table>';
4541: }
4542: $datatable .= '</td></tr>'."\n";
4543: $rownum ++;
4544: }
1.340 raeburn 4545: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4546: foreach my $type (@mailings) {
4547: $css_class = $rownum%2?' class="LC_odd_row"':'';
4548: $datatable .= '<tr'.$css_class.'>'.
4549: '<td><span class="LC_nobreak">'.
4550: $titles->{$type}.': </span></td>'.
4551: '<td class="LC_left_item">';
4552: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4553: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4554: }
4555: $datatable .= '<span class="LC_nobreak">';
4556: foreach my $item (@contacts) {
4557: $datatable .= '<label>'.
4558: '<input type="checkbox" name="'.$type.'"'.
4559: $checked{$type}{$item}.
4560: ' value="'.$item.'" />'.$short_titles->{$item}.
4561: '</label> ';
4562: }
4563: $datatable .= '</span><br />'.&mt('Others').': '.
4564: '<input type="text" name="'.$type.'_others" '.
4565: 'value="'.$otheremails{$type}.'" />';
4566: my %locchecked;
4567: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4568: foreach my $loc ('s','b') {
4569: if ($includeloc{$type} eq $loc) {
4570: $locchecked{$loc} = ' checked="checked"';
4571: last;
4572: }
4573: }
4574: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4575: '<input type="text" name="'.$type.'_bcc" '.
4576: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4577: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4578: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4579: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4580: '<span class="LC_nobreak">'.&mt('Location:').' '.
4581: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4582: (' 'x2).
4583: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4584: '</span></fieldset>';
4585: }
4586: $datatable .= '</td></tr>'."\n";
4587: $rownum ++;
4588: }
1.28 raeburn 4589: }
1.286 raeburn 4590: if ($position eq 'middle') {
4591: my %choices;
1.340 raeburn 4592: my $corelink = &core_link_msu();
4593: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4594: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4595: $corelink);
4596: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4597: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4598: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4599: 'reportupdates' => 'on',
4600: 'reportstatus' => 'on');
1.286 raeburn 4601: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4602: \%choices,$rownum);
4603: $datatable .= $reports;
1.340 raeburn 4604: } elsif ($position eq 'lower') {
1.378 raeburn 4605: my (%current,%excluded,%weights);
1.340 raeburn 4606: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4607: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4608: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4609: } else {
1.378 raeburn 4610: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4611: }
4612: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4613: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4614: } else {
1.378 raeburn 4615: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4616: }
4617: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4618: foreach my $type ('E','W','N','U') {
1.340 raeburn 4619: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4620: $weights{$type} = $lonstatus{'weights'}{$type};
4621: } else {
4622: $weights{$type} = $defaults->{$type};
4623: }
4624: }
4625: } else {
1.341 raeburn 4626: foreach my $type ('E','W','N','U') {
1.340 raeburn 4627: $weights{$type} = $defaults->{$type};
4628: }
4629: }
4630: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4631: if (@{$lonstatus{'excluded'}} > 0) {
4632: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4633: }
4634: }
1.425 raeburn 4635: foreach my $item ('errorthreshold','errorsysmail') {
1.378 raeburn 4636: $css_class = $rownum%2?' class="LC_odd_row"':'';
4637: $datatable .= '<tr'.$css_class.'>'.
4638: '<td class="LC_left_item"><span class="LC_nobreak">'.
4639: $titles->{$item}.
4640: '</span></td><td class="LC_left_item">'.
4641: '<input type="text" name="'.$item.'" value="'.
4642: $current{$item}.'" size="5" /></td></tr>';
4643: $rownum ++;
4644: }
1.340 raeburn 4645: $css_class = $rownum%2?' class="LC_odd_row"':'';
4646: $datatable .= '<tr'.$css_class.'>'.
4647: '<td class="LC_left_item">'.
4648: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4649: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4650: foreach my $type ('E','W','N','U') {
1.340 raeburn 4651: $datatable .= '<td>'.$names->{$type}.'<br />'.
4652: '<input type="text" name="errorweights_'.$type.'" value="'.
4653: $weights{$type}.'" size="5" /></td>';
4654: }
4655: $datatable .= '</tr></table></tr>';
4656: $rownum ++;
4657: $css_class = $rownum%2?' class="LC_odd_row"':'';
4658: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4659: $titles->{'errorexcluded'}.'</td>'.
4660: '<td class="LC_left_item"><table>';
4661: my $numinrow = 4;
4662: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4663: for (my $i=0; $i<@ids; $i++) {
4664: my $rem = $i%($numinrow);
4665: if ($rem == 0) {
4666: if ($i > 0) {
4667: $datatable .= '</tr>';
4668: }
4669: $datatable .= '<tr>';
4670: }
4671: my $check;
4672: if ($excluded{$ids[$i]}) {
4673: $check = ' checked="checked" ';
4674: }
4675: $datatable .= '<td class="LC_left_item">'.
4676: '<span class="LC_nobreak"><label>'.
4677: '<input type="checkbox" name="errorexcluded" '.
4678: 'value="'.$ids[$i].'"'.$check.' />'.
4679: $ids[$i].'</label></span></td>';
4680: }
4681: my $colsleft = $numinrow - @ids%($numinrow);
4682: if ($colsleft > 1 ) {
4683: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4684: ' </td>';
4685: } elsif ($colsleft == 1) {
4686: $datatable .= '<td class="LC_left_item"> </td>';
4687: }
4688: $datatable .= '</tr></table></td></tr>';
4689: $rownum ++;
1.286 raeburn 4690: } elsif ($position eq 'bottom') {
1.315 raeburn 4691: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4692: my (@posstypes,%usertypeshash);
4693: if (ref($types) eq 'ARRAY') {
4694: @posstypes = @{$types};
4695: }
4696: if (@posstypes) {
4697: if (ref($usertypes) eq 'HASH') {
4698: %usertypeshash = %{$usertypes};
4699: }
4700: my @overridden;
4701: my $numinrow = 4;
4702: if (ref($settings) eq 'HASH') {
4703: if (ref($settings->{'overrides'}) eq 'HASH') {
4704: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4705: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4706: push(@overridden,$key);
4707: foreach my $item (@contacts) {
4708: if ($settings->{'overrides'}{$key}{$item}) {
4709: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4710: }
4711: }
4712: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4713: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4714: $includeloc{'override_'.$key} = '';
4715: $includestr{'override_'.$key} = '';
4716: if ($settings->{'overrides'}{$key}{'include'} ne '') {
1.425 raeburn 4717: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
1.315 raeburn 4718: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4719: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4720: }
1.286 raeburn 4721: }
4722: }
4723: }
1.315 raeburn 4724: }
4725: my $customclass = 'LC_helpdesk_override';
4726: my $optionsprefix = 'LC_options_helpdesk_';
4727:
4728: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4729: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4730: $numinrow,$othertitle,'overrides',
4731: \$rownum,$onclicktypes,$customclass);
4732: $rownum ++;
4733: $usertypeshash{'default'} = $othertitle;
4734: foreach my $status (@posstypes) {
4735: my $css_class;
4736: if ($rownum%2) {
4737: $css_class = 'LC_odd_row ';
4738: }
4739: $css_class .= $customclass;
4740: my $rowid = $optionsprefix.$status;
4741: my $hidden = 1;
4742: my $currstyle = 'display:none';
4743: if (grep(/^\Q$status\E$/,@overridden)) {
4744: $currstyle = 'display:table-row';
4745: $hidden = 0;
4746: }
4747: my $key = 'override_'.$status;
4748: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4749: $includeloc{$key},$includestr{$key},$status,$rowid,
4750: $usertypeshash{$status},$css_class,$currstyle,
4751: \@contacts,$short_titles);
4752: unless ($hidden) {
4753: $rownum ++;
1.286 raeburn 4754: }
4755: }
1.134 raeburn 4756: }
1.28 raeburn 4757: }
1.30 raeburn 4758: $$rowtotal += $rownum;
1.28 raeburn 4759: return $datatable;
4760: }
4761:
1.340 raeburn 4762: sub core_link_msu {
4763: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4764: &mt('LON-CAPA core group - MSU'),600,500);
4765: }
4766:
1.315 raeburn 4767: sub overridden_helpdesk {
4768: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4769: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4770: my $class = 'LC_left_item';
4771: if ($css_class) {
4772: $css_class = ' class="'.$css_class.'"';
4773: }
4774: if ($rowid) {
4775: $rowid = ' id="'.$rowid.'"';
4776: }
4777: if ($rowstyle) {
4778: $rowstyle = ' style="'.$rowstyle.'"';
4779: }
4780: my ($output,$description);
4781: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4782: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4783: "<td>$description</td>\n".
4784: '<td class="'.$class.'" colspan="2">'.
4785: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4786: '<span class="LC_nobreak">';
4787: if (ref($contacts) eq 'ARRAY') {
4788: foreach my $item (@{$contacts}) {
4789: my $check;
4790: if (ref($checked) eq 'HASH') {
4791: $check = $checked->{$item};
4792: }
4793: my $title;
4794: if (ref($short_titles) eq 'HASH') {
1.425 raeburn 4795: $title = $short_titles->{$item};
1.315 raeburn 4796: }
4797: $output .= '<label>'.
4798: '<input type="checkbox" name="override_'.$type.'"'.$check.
4799: ' value="'.$item.'" />'.$title.'</label> ';
4800: }
4801: }
4802: $output .= '</span><br />'.&mt('Others').': '.
4803: '<input type="text" name="override_'.$type.'_others" '.
4804: 'value="'.$otheremails.'" />';
4805: my %locchecked;
4806: foreach my $loc ('s','b') {
4807: if ($includeloc eq $loc) {
4808: $locchecked{$loc} = ' checked="checked"';
4809: last;
4810: }
4811: }
4812: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4813: '<input type="text" name="override_'.$type.'_bcc" '.
4814: 'value="'.$bccemails.'" /></fieldset>'.
4815: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4816: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4817: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4818: '<span class="LC_nobreak">'.&mt('Location:').' '.
4819: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4820: (' 'x2).
4821: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4822: '</span></fieldset>'.
4823: '</td></tr>'."\n";
4824: return $output;
4825: }
4826:
1.286 raeburn 4827: sub contacts_javascript {
4828: return <<"ENDSCRIPT";
4829:
4830: <script type="text/javascript">
4831: // <![CDATA[
4832:
4833: function screenshotSize(field) {
4834: if (document.getElementById('help_screenshotsize')) {
4835: if (field.value == 'no') {
1.289 raeburn 4836: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4837: } else {
4838: document.getElementById('help_screenshotsize').style.display="";
4839: }
4840: }
4841: return;
4842: }
4843:
1.315 raeburn 4844: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4845: if (form.elements[checkbox].length != undefined) {
4846: var count = 0;
4847: if (docount) {
4848: for (var i=0; i<form.elements[checkbox].length; i++) {
4849: if (form.elements[checkbox][i].checked) {
4850: count ++;
4851: }
4852: }
4853: }
4854: for (var i=0; i<form.elements[checkbox].length; i++) {
4855: var type = form.elements[checkbox][i].value;
4856: if (document.getElementById(prefix+type)) {
4857: if (form.elements[checkbox][i].checked) {
4858: document.getElementById(prefix+type).style.display = 'table-row';
4859: if (count % 2 == 1) {
4860: document.getElementById(prefix+type).className = target+' LC_odd_row';
4861: } else {
4862: document.getElementById(prefix+type).className = target;
4863: }
4864: count ++;
4865: } else {
4866: document.getElementById(prefix+type).style.display = 'none';
4867: }
4868: }
4869: }
4870: }
4871: return;
4872: }
4873:
1.286 raeburn 4874: // ]]>
4875: </script>
4876:
4877: ENDSCRIPT
4878: }
4879:
1.118 jms 4880: sub print_helpsettings {
1.282 raeburn 4881: my ($position,$dom,$settings,$rowtotal) = @_;
4882: my $confname = $dom.'-domainconfig';
1.285 raeburn 4883: my $formname = 'display';
1.168 raeburn 4884: my ($datatable,$itemcount);
1.282 raeburn 4885: if ($position eq 'top') {
4886: $itemcount = 1;
4887: my (%choices,%defaultchecked,@toggles);
4888: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4889: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4890: &mt('LON-CAPA bug tracker'),600,500));
4891: %defaultchecked = ('submitbugs' => 'on');
4892: @toggles = ('submitbugs');
4893: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4894: \%choices,$itemcount);
4895: $$rowtotal ++;
4896: } else {
4897: my $css_class;
4898: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4899: my (%customroles,%ordered,%current);
1.301 raeburn 4900: if (ref($settings) eq 'HASH') {
4901: if (ref($settings->{'adhoc'}) eq 'HASH') {
4902: %current = %{$settings->{'adhoc'}};
4903: }
1.285 raeburn 4904: }
4905: my $count = 0;
4906: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4907: if ($key=~/^rolesdef\_(\w+)$/) {
4908: my $rolename = $1;
1.285 raeburn 4909: my (%privs,$order);
1.282 raeburn 4910: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4911: $customroles{$rolename} = \%privs;
1.285 raeburn 4912: if (ref($current{$rolename}) eq 'HASH') {
4913: $order = $current{$rolename}{'order'};
4914: }
4915: if ($order eq '') {
4916: $order = $count;
4917: }
4918: $ordered{$order} = $rolename;
4919: $count++;
4920: }
4921: }
4922: my $maxnum = scalar(keys(%ordered));
4923: my @roles_by_num = ();
4924: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4925: push(@roles_by_num,$item);
4926: }
4927: my $context = 'domprefs';
4928: my $crstype = 'Course';
4929: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4930: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4931: my ($numstatustypes,@jsarray);
4932: if (ref($types) eq 'ARRAY') {
4933: if (@{$types} > 0) {
4934: $numstatustypes = scalar(@{$types});
4935: push(@accesstypes,'status');
4936: @jsarray = ('bystatus');
1.282 raeburn 4937: }
4938: }
1.290 raeburn 4939: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4940: if (keys(%domhelpdesk)) {
4941: push(@accesstypes,('inc','exc'));
4942: push(@jsarray,('notinc','notexc'));
4943: }
4944: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4945: my $context = 'domprefs';
4946: my $crstype = 'Course';
1.285 raeburn 4947: my $prefix = 'helproles_';
4948: my $add_class = 'LC_hidden';
4949: foreach my $num (@roles_by_num) {
4950: my $role = $ordered{$num};
4951: my ($desc,$access,@statuses);
4952: if (ref($current{$role}) eq 'HASH') {
4953: $desc = $current{$role}{'desc'};
4954: $access = $current{$role}{'access'};
4955: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4956: @statuses = @{$current{$role}{'insttypes'}};
4957: }
4958: }
4959: if ($desc eq '') {
4960: $desc = $role;
4961: }
4962: my $identifier = 'custhelp'.$num;
1.282 raeburn 4963: my %full=();
4964: my %levels= (
4965: course => {},
4966: domain => {},
4967: system => {},
4968: );
4969: my %levelscurrent=(
4970: course => {},
4971: domain => {},
4972: system => {},
4973: );
4974: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4975: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4976: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4977: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4978: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4979: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4980: for (my $k=0; $k<=$maxnum; $k++) {
4981: my $vpos = $k+1;
4982: my $selstr;
4983: if ($k == $num) {
4984: $selstr = ' selected="selected" ';
4985: }
4986: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4987: }
4988: $datatable .= '</select>'.(' 'x2).
4989: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4990: '</td>'.
4991: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4992: &mt('Name shown to users:').
4993: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4994: '</fieldset>'.
4995: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4996: $othertitle,$usertypes,$types,\%domhelpdesk).
4997: '<fieldset>'.
4998: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4999: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 5000: \%levelscurrent,$identifier,
5001: 'LC_hidden',$prefix.$num.'_privs').
5002: '</fieldset></td>';
1.282 raeburn 5003: $itemcount ++;
5004: }
5005: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5006: my $newcust = 'custhelp'.$count;
5007: my (%privs,%levelscurrent);
5008: my %full=();
5009: my %levels= (
5010: course => {},
5011: domain => {},
5012: system => {},
5013: );
5014: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
5015: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5016: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5017: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5018: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5019: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5020: for (my $k=0; $k<$maxnum+1; $k++) {
5021: my $vpos = $k+1;
5022: my $selstr;
5023: if ($k == $maxnum) {
5024: $selstr = ' selected="selected" ';
5025: }
5026: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5027: }
5028: $datatable .= '</select> '."\n".
1.282 raeburn 5029: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5030: '</label></span></td>'.
1.285 raeburn 5031: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5032: '<span class="LC_nobreak">'.
5033: &mt('Internal name:').
5034: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5035: '</span>'.(' 'x4).
5036: '<span class="LC_nobreak">'.
5037: &mt('Name shown to users:').
5038: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5039: '</span></fieldset>'.
5040: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5041: $usertypes,$types,\%domhelpdesk).
5042: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5043: &Apache::lonuserutils::custom_role_header($context,$crstype,
5044: \@templateroles,$newcust).
5045: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5046: \%levelscurrent,$newcust).
1.334 raeburn 5047: '</fieldset>'.
5048: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5049: '</td></tr>';
1.282 raeburn 5050: $count ++;
5051: $$rowtotal += $count;
5052: }
1.166 raeburn 5053: return $datatable;
1.121 raeburn 5054: }
5055:
1.285 raeburn 5056: sub adhocbutton {
5057: my ($prefix,$num,$field,$visibility) = @_;
5058: my %lt = &Apache::lonlocal::texthash(
5059: show => 'Show details',
5060: hide => 'Hide details',
5061: );
5062: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5063: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5064: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5065: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5066: }
5067:
5068: sub helpsettings_javascript {
5069: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5070: return unless(ref($roles_by_num) eq 'ARRAY');
5071: my %html_js_lt = &Apache::lonlocal::texthash(
5072: show => 'Show details',
5073: hide => 'Hide details',
5074: );
5075: &html_escape(\%html_js_lt);
5076: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5077: return <<"ENDSCRIPT";
5078: <script type="text/javascript">
5079: // <![CDATA[
5080:
5081: function reorderHelpRoles(form,item) {
5082: var changedVal;
5083: $jstext
5084: var newpos = 'helproles_${total}_pos';
5085: var maxh = 1 + $total;
5086: var current = new Array();
5087: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5088: if (item == newpos) {
5089: changedVal = newitemVal;
5090: } else {
5091: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5092: current[newitemVal] = newpos;
5093: }
5094: for (var i=0; i<helproles.length; i++) {
5095: var elementName = 'helproles_'+helproles[i]+'_pos';
5096: if (elementName != item) {
5097: if (form.elements[elementName]) {
5098: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5099: current[currVal] = elementName;
5100: }
5101: }
5102: }
5103: var oldVal;
5104: for (var j=0; j<maxh; j++) {
5105: if (current[j] == undefined) {
5106: oldVal = j;
5107: }
5108: }
5109: if (oldVal < changedVal) {
5110: for (var k=oldVal+1; k<=changedVal ; k++) {
5111: var elementName = current[k];
5112: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5113: }
5114: } else {
5115: for (var k=changedVal; k<oldVal; k++) {
5116: var elementName = current[k];
5117: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5118: }
5119: }
5120: return;
5121: }
5122:
5123: function helpdeskAccess(num) {
5124: var curraccess = null;
5125: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5126: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5127: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5128: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5129: }
5130: }
5131: }
5132: var shown = Array();
5133: var hidden = Array();
5134: if (curraccess == 'none') {
5135: hidden = Array('$hiddenstr');
5136: } else {
5137: if (curraccess == 'status') {
5138: shown = Array('bystatus');
5139: hidden = Array('notinc','notexc');
5140: } else {
5141: if (curraccess == 'exc') {
5142: shown = Array('notexc');
5143: hidden = Array('notinc','bystatus');
5144: }
5145: if (curraccess == 'inc') {
5146: shown = Array('notinc');
5147: hidden = Array('notexc','bystatus');
5148: }
1.293 raeburn 5149: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5150: hidden = Array('notinc','notexc','bystatus');
5151: }
5152: }
5153: }
5154: if (hidden.length > 0) {
5155: for (var i=0; i<hidden.length; i++) {
5156: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5157: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5158: }
5159: }
5160: }
5161: if (shown.length > 0) {
5162: for (var i=0; i<shown.length; i++) {
5163: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5164: if (shown[i] == 'privs') {
5165: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5166: } else {
5167: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5168: }
5169: }
5170: }
5171: }
5172: return;
5173: }
5174:
5175: function toggleHelpdeskItem(num,field) {
5176: if (document.getElementById('helproles_'+num+'_'+field)) {
5177: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5178: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5179: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5180: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5181: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5182: }
5183: } else {
5184: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5185: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5186: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5187: }
5188: }
5189: }
5190: return;
5191: }
5192:
5193: // ]]>
5194: </script>
5195:
5196: ENDSCRIPT
5197: }
5198:
5199: sub helpdeskroles_access {
5200: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5201: $usertypes,$types,$domhelpdesk) = @_;
5202: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5203: my %lt = &Apache::lonlocal::texthash(
5204: 'rou' => 'Role usage',
5205: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5206: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5207: 'dh' => 'All with domain helpdesk role',
5208: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5209: 'none' => 'None',
5210: 'status' => 'Determined based on institutional status',
5211: 'inc' => 'Include all, but exclude specific personnel',
5212: 'exc' => 'Exclude all, but include specific personnel',
5213: );
5214: my %usecheck = (
5215: all => ' checked="checked"',
5216: );
5217: my %displaydiv = (
5218: status => 'none',
5219: inc => 'none',
5220: exc => 'none',
5221: priv => 'block',
5222: );
5223: my $output;
5224: if (ref($current) eq 'HASH') {
5225: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5226: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5227: $usecheck{$current->{access}} = $usecheck{'all'};
5228: delete($usecheck{'all'});
5229: if ($current->{access} =~ /^(status|inc|exc)$/) {
5230: my $access = $1;
5231: $displaydiv{$access} = 'inline';
5232: } elsif ($current->{access} eq 'none') {
5233: $displaydiv{'priv'} = 'none';
5234: }
5235: }
5236: }
5237: }
5238: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5239: '<p>'.$lt{'whi'}.'</p>';
5240: foreach my $access (@{$accesstypes}) {
5241: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5242: ' onclick="helpdeskAccess('."'$num'".');" />'.
5243: $lt{$access}.'</label>';
5244: if ($access eq 'status') {
5245: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5246: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5247: $othertitle,$usertypes,$types).
5248: '</div>';
5249: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5250: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5251: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5252: '</div>';
5253: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5254: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5255: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5256: '</div>';
5257: }
5258: $output .= '</p>';
5259: }
5260: $output .= '</fieldset>';
5261: return $output;
5262: }
5263:
1.121 raeburn 5264: sub radiobutton_prefs {
1.192 raeburn 5265: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5266: $additional,$align,$firstval) = @_;
1.121 raeburn 5267: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5268: (ref($choices) eq 'HASH'));
5269:
1.170 raeburn 5270: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5271:
5272: foreach my $item (@{$toggles}) {
5273: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5274: $checkedon{$item} = ' checked="checked" ';
5275: $checkedoff{$item} = ' ';
1.121 raeburn 5276: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5277: $checkedoff{$item} = ' checked="checked" ';
5278: $checkedon{$item} = ' ';
5279: }
5280: }
5281: if (ref($settings) eq 'HASH') {
1.121 raeburn 5282: foreach my $item (@{$toggles}) {
1.118 jms 5283: if ($settings->{$item} eq '1') {
5284: $checkedon{$item} = ' checked="checked" ';
5285: $checkedoff{$item} = ' ';
5286: } elsif ($settings->{$item} eq '0') {
5287: $checkedoff{$item} = ' checked="checked" ';
5288: $checkedon{$item} = ' ';
5289: }
5290: }
1.121 raeburn 5291: }
1.192 raeburn 5292: if ($onclick) {
5293: $onclick = ' onclick="'.$onclick.'"';
5294: }
1.121 raeburn 5295: foreach my $item (@{$toggles}) {
1.118 jms 5296: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5297: $datatable .=
1.306 raeburn 5298: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5299: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5300: '</span></td>';
5301: if ($align eq 'left') {
5302: $datatable .= '<td class="LC_left_item">';
5303: } else {
5304: $datatable .= '<td class="LC_right_item">';
5305: }
1.385 raeburn 5306: $datatable .= '<span class="LC_nobreak">';
5307: if ($firstval eq 'no') {
5308: $datatable .=
5309: '<label><input type="radio" name="'.
5310: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5311: '</label> <label><input type="radio" name="'.$item.'" '.
5312: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5313: } else {
5314: $datatable .=
5315: '<label><input type="radio" name="'.
5316: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5317: '</label> <label><input type="radio" name="'.$item.'" '.
5318: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5319: }
5320: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5321: $itemcount ++;
1.121 raeburn 5322: }
5323: return ($datatable,$itemcount);
5324: }
5325:
1.267 raeburn 5326: sub print_ltitools {
1.421 raeburn 5327: my ($position,$dom,$settings,$rowtotal) = @_;
5328: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5329: if (ref($settings) eq 'HASH') {
1.421 raeburn 5330: if ($position eq 'top') {
5331: if (exists($settings->{'encrypt'})) {
5332: if (ref($settings->{'encrypt'}) eq 'HASH') {
5333: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5334: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5335: }
5336: }
1.267 raeburn 5337: }
1.421 raeburn 5338: if (exists($settings->{'private'})) {
5339: if (ref($settings->{'private'}) eq 'HASH') {
5340: if (ref($settings->{'private'}) eq 'HASH') {
5341: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5342: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5343: }
5344: }
5345: }
5346: }
1.421 raeburn 5347: } elsif ($position eq 'middle') {
5348: if (exists($settings->{'rules'})) {
5349: if (ref($settings->{'rules'}) eq 'HASH') {
5350: %rules = %{$settings->{'rules'}};
1.273 raeburn 5351: }
5352: }
1.421 raeburn 5353: } else {
5354: foreach my $key ('encrypt','private','rules') {
5355: if (exists($settings->{$key})) {
5356: delete($settings->{$key});
1.267 raeburn 5357: }
5358: }
5359: }
5360: }
1.421 raeburn 5361: my $datatable;
5362: my $itemcount = 1;
5363: if ($position eq 'top') {
5364: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5365: } elsif ($position eq 'middle') {
5366: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5367: $$rowtotal += $itemcount;
5368: } else {
5369: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5370: }
5371: return $datatable;
5372: }
5373:
5374: sub ltitools_names {
5375: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5376: 'title' => 'Title',
5377: 'version' => 'Version',
5378: 'msgtype' => 'Message Type',
1.323 raeburn 5379: 'sigmethod' => 'Signature Method',
1.296 raeburn 5380: 'url' => 'URL',
5381: 'key' => 'Key',
1.322 raeburn 5382: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5383: 'secret' => 'Secret',
1.425 raeburn 5384: 'icon' => 'Icon',
1.324 raeburn 5385: 'user' => 'User',
1.296 raeburn 5386: 'fullname' => 'Full Name',
5387: 'firstname' => 'First Name',
5388: 'lastname' => 'Last Name',
5389: 'email' => 'E-mail',
5390: 'roles' => 'Role',
1.298 raeburn 5391: 'window' => 'Window',
5392: 'tab' => 'Tab',
1.296 raeburn 5393: 'iframe' => 'iFrame',
5394: 'height' => 'Height',
5395: 'width' => 'Width',
5396: 'linktext' => 'Default Link Text',
5397: 'explanation' => 'Default Explanation',
5398: 'passback' => 'Tool can return grades:',
5399: 'roster' => 'Tool can retrieve roster:',
5400: 'crstarget' => 'Display target',
5401: 'crslabel' => 'Course label',
1.425 raeburn 5402: 'crstitle' => 'Course title',
1.296 raeburn 5403: 'crslinktext' => 'Link Text',
5404: 'crsexplanation' => 'Explanation',
1.318 raeburn 5405: 'crsappend' => 'Provider URL',
1.267 raeburn 5406: );
5407: return %lt;
5408: }
5409:
1.421 raeburn 5410: sub secrets_form {
5411: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5412: my @ids=&Apache::lonnet::current_machine_ids();
5413: my %servers = &Apache::lonnet::get_servers($dom,'library');
5414: my $primary = &Apache::lonnet::domain($dom,'primary');
5415: my ($css_class,$extra,$numshown,$itemcount,$output);
5416: $itemcount = 0;
5417: foreach my $hostid (sort(keys(%servers))) {
5418: my ($showextra,$divsty,$switch);
5419: if ($hostid eq $primary) {
5420: if ($context eq 'ltisec') {
5421: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5422: $showextra = 1;
5423: }
5424: if ($encrypt->{'ltisec_crslinkprot'}) {
5425: $showextra = 1;
5426: }
5427: } else {
5428: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5429: $showextra = 1;
5430: }
5431: }
5432: unless (grep(/^\Q$hostid\E$/,@ids)) {
5433: $switch = 1;
5434: }
5435: if ($showextra) {
5436: $numshown ++;
5437: $divsty = 'display:inline-block';
5438: } else {
5439: $divsty = 'display:none';
5440: }
5441: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5442: '<legend>'.$hostid.'</legend>';
5443: if ($switch) {
5444: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5445: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5446: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5447: if (exists($privkeys->{$hostid})) {
5448: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5449: '<span class="LC_nobreak">'.
5450: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5451: '<span class="LC_nobreak">'.&mt('Change?').
5452: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5453: (' 'x2).
5454: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5455: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5456: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5457: '</span></div>';
5458: } else {
5459: $extra .= '<span class="LC_nobreak">'.
5460: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5461: '</span>'."\n";
5462: }
5463: } elsif (exists($privkeys->{$hostid})) {
5464: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5465: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5466: '<span class="LC_nobreak">'.&mt('Change?').
5467: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5468: (' 'x2).
5469: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5470: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5471: '<span class="LC_nobreak">'.&mt('New Key').':'.
5472: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5473: '<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>'.
5474: '</span></div>';
5475: } else {
5476: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5477: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5478: '<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>';
5479: }
5480: $extra .= '</fieldset>';
5481: }
5482: }
5483: my (%choices,@toggles,%defaultchecked);
5484: if ($context eq 'ltisec') {
5485: %choices = &Apache::lonlocal::texthash (
5486: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5487: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5488: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5489: );
5490: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5491: %defaultchecked = (
5492: 'ltisec_crslinkprot' => 'off',
5493: 'ltisec_domlinkprot' => 'off',
5494: 'ltisec_consumers' => 'off',
5495: );
5496: } else {
5497: %choices = &Apache::lonlocal::texthash (
5498: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5499: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5500: );
5501: @toggles = qw(toolsec_crs toolsec_dom);
5502: %defaultchecked = (
5503: 'toolsec_crs' => 'off',
5504: 'toolsec_dom' => 'off',
5505: );
5506: }
5507: my ($onclick,$itemcount);
5508: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5509: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5510: \%choices,$itemcount,$onclick,'','left','no');
5511:
5512: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5513: my $noprivkeysty = 'display:inline-block';
5514: if ($numshown) {
5515: $noprivkeysty = 'display:none';
5516: }
5517: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5518: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5519: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5520: $extra.
5521: '</td></tr>';
5522: $itemcount ++;
5523: $$rowtotal += $itemcount;
5524: return $output;
5525: }
5526:
1.372 raeburn 5527: sub print_proctoring {
5528: my ($dom,$settings,$rowtotal) = @_;
5529: my $itemcount = 1;
5530: my (%ordered,%providernames,%current,%currentdef);
5531: my $confname = $dom.'-domainconfig';
5532: my $switchserver = &check_switchserver($dom,$confname);
5533: if (ref($settings) eq 'HASH') {
5534: foreach my $item (keys(%{$settings})) {
5535: if (ref($settings->{$item}) eq 'HASH') {
5536: my $num = $settings->{$item}{'order'};
5537: $ordered{$num} = $item;
5538: }
5539: }
5540: } else {
5541: %ordered = (
5542: 1 => 'proctorio',
5543: 2 => 'examity',
5544: );
5545: }
5546: %providernames = &proctoring_providernames();
5547: my $maxnum = scalar(keys(%ordered));
5548: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5549: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5550: if (ref($requref) eq 'HASH') {
5551: %requserfields = %{$requref};
5552: }
5553: if (ref($opturef) eq 'HASH') {
5554: %optuserfields = %{$opturef};
5555: }
5556: if (ref($defref) eq 'HASH') {
5557: %defaults = %{$defref};
5558: }
5559: if (ref($extref) eq 'HASH') {
5560: %extended = %{$extref};
5561: }
5562: if (ref($crsref) eq 'HASH') {
5563: %crsconf = %{$crsref};
5564: }
5565: if (ref($rolesref) eq 'ARRAY') {
5566: @courseroles = @{$rolesref};
5567: }
5568: if (ref($ltiref) eq 'ARRAY') {
5569: @ltiroles = @{$ltiref};
5570: }
5571: my $datatable;
5572: my $css_class;
5573: if (keys(%ordered)) {
5574: my @items = sort { $a <=> $b } keys(%ordered);
5575: for (my $i=0; $i<@items; $i++) {
5576: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5577: my $provider = $ordered{$items[$i]};
5578: my $optionsty = 'none';
5579: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5580: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5581: if (ref($settings) eq 'HASH') {
5582: if (ref($settings->{$provider}) eq 'HASH') {
5583: %current = %{$settings->{$provider}};
5584: if ($current{'available'}) {
5585: $optionsty = 'block';
5586: $available = 1;
5587: }
5588: if ($current{'lifetime'} =~ /^\d+$/) {
5589: $lifetime = $current{'lifetime'};
5590: }
5591: if ($current{'version'} =~ /^\d+\.\d+$/) {
5592: $version = $current{'version'};
5593: }
5594: if ($current{'image'} ne '') {
5595: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5596: }
5597: if (ref($current{'fields'}) eq 'ARRAY') {
5598: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5599: }
5600: $userincdom = $current{'incdom'};
5601: if (ref($current{'roles'}) eq 'HASH') {
5602: %rolemaps = %{$current{'roles'}};
5603: $checkedfields{'roles'} = 1;
5604: }
5605: if (ref($current{'defaults'}) eq 'ARRAY') {
5606: foreach my $val (@{$current{'defaults'}}) {
5607: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5608: $inuse{$val} = 1;
5609: } else {
5610: foreach my $poss (keys(%{$extended{$provider}})) {
5611: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5612: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5613: $inuse{$poss} = $val;
5614: last;
5615: }
5616: }
5617: }
5618: }
5619: }
5620: } elsif (ref($current{'defaults'}) eq 'HASH') {
5621: foreach my $key (keys(%{$current{'defaults'}})) {
5622: my $currval = $current{'defaults'}{$key};
5623: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5624: $inuse{$key} = 1;
5625: } else {
5626: my $match;
5627: foreach my $poss (keys(%{$extended{$provider}})) {
5628: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5629: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5630: $inuse{$poss} = $key;
5631: last;
5632: }
5633: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5634: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5635: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5636: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5637: $currentdef{$inner} = $currval;
5638: $match = 1;
5639: last;
5640: }
5641: } elsif ($inner eq $key) {
5642: $currentdef{$key} = $currval;
5643: $match = 1;
5644: last;
5645: }
5646: }
5647: }
5648: last if ($match);
5649: }
5650: }
5651: }
5652: }
5653: if (ref($current{'crsconf'}) eq 'ARRAY') {
5654: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5655: }
5656: }
5657: }
5658: my %lt = &proctoring_titles($provider);
5659: my %fieldtitles = &proctoring_fieldtitles($provider);
5660: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5661: my %checkedavailable = (
5662: yes => '',
5663: no => ' checked="checked"',
5664: );
5665: if ($available) {
5666: $checkedavailable{'yes'} = $checkedavailable{'no'};
5667: $checkedavailable{'no'} = '';
5668: }
5669: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5670: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5671: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5672: for (my $k=0; $k<$maxnum; $k++) {
5673: my $vpos = $k+1;
5674: my $selstr;
5675: if ($k == $i) {
5676: $selstr = ' selected="selected" ';
5677: }
5678: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5679: }
5680: if ($version eq '') {
5681: if ($provider eq 'proctorio') {
5682: $version = '1.0';
5683: } elsif ($provider eq 'examity') {
5684: $version = '1.1';
5685: }
5686: }
5687: if ($lifetime eq '') {
5688: $lifetime = '300';
5689: }
5690: $datatable .=
5691: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5692: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5693: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5694: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5695: '</td>'.
5696: '<td colspan="2">'.
5697: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5698: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5699: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5700: (' 'x2).
5701: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5702: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5703: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5704: (' 'x2).
5705: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5706: '<br />'.
5707: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5708: '<br />'.
5709: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5710: (' 'x2).
5711: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5712: '<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";
5713: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5714: if ($imgsrc) {
5715: $datatable .= $imgsrc.
5716: '<label><input type="checkbox" name="proctoring_image_del"'.
5717: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5718: '<span class="LC_nobreak"> '.&mt('Replace:');
5719: }
5720: $datatable .= ' ';
5721: if ($switchserver) {
5722: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5723: } else {
5724: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5725: }
5726: unless ($imgsrc) {
5727: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5728: }
5729: $datatable .= '</fieldset>'."\n";
5730: if (ref($requserfields{$provider}) eq 'ARRAY') {
5731: if (@{$requserfields{$provider}} > 0) {
5732: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5733: foreach my $field (@{$requserfields{$provider}}) {
5734: $datatable .= '<span class="LC_nobreak">'.
5735: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5736: $lt{$field}.'</label>';
5737: if ($field eq 'user') {
5738: my $seluserdom = '';
5739: my $unseluserdom = ' selected="selected"';
5740: if ($userincdom) {
5741: $seluserdom = $unseluserdom;
5742: $unseluserdom = '';
5743: }
5744: $datatable .= ': '.
5745: '<select name="proctoring_userincdom_'.$provider.'">'.
5746: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5747: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5748: '</select> ';
5749: } else {
5750: $datatable .= ' ';
5751: if ($field eq 'roles') {
5752: $showroles = 1;
5753: }
5754: }
5755: $datatable .= '</span> ';
5756: }
5757: }
5758: $datatable .= '</fieldset>'."\n";
5759: }
5760: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5761: if (@{$optuserfields{$provider}} > 0) {
5762: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5763: foreach my $field (@{$optuserfields{$provider}}) {
5764: my $checked;
5765: if ($checkedfields{$field}) {
5766: $checked = ' checked="checked"';
5767: }
5768: $datatable .= '<span class="LC_nobreak">'.
5769: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5770: }
5771: $datatable .= '</fieldset>'."\n";
5772: }
5773: }
5774: if (ref($defaults{$provider}) eq 'ARRAY') {
5775: if (@{$defaults{$provider}}) {
5776: my (%options,@selectboxes);
5777: if (ref($extended{$provider}) eq 'HASH') {
5778: %options = %{$extended{$provider}};
5779: }
5780: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5781: my ($rem,$numinrow,$dropdowns);
5782: if ($provider eq 'proctorio') {
5783: $datatable .= '<table>';
5784: $numinrow = 4;
5785: }
5786: my $i = 0;
5787: foreach my $field (@{$defaults{$provider}}) {
5788: my $checked;
5789: if ($inuse{$field}) {
5790: $checked = ' checked="checked"';
5791: }
5792: if ($provider eq 'examity') {
5793: if ($field eq 'display') {
5794: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5795: foreach my $option ('iframe','tab','window') {
5796: my $checkdisp;
5797: if ($currentdef{'target'} eq $option) {
5798: $checkdisp = ' checked="checked"';
5799: }
5800: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5801: $fieldtitles{$option}.'</label>'.(' 'x2);
5802: }
5803: $datatable .= (' 'x4);
5804: foreach my $dimen ('width','height') {
5805: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5806: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5807: 'value="'.$currentdef{$dimen}.'" /></label>'.
5808: (' 'x2);
5809: }
5810: $datatable .= '</span><br />'.
5811: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5812: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5813: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5814: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5815: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5816: $currentdef{'explanation'}.
5817: '</textarea></div><div style=""></div><br />';
5818: }
5819: } else {
5820: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5821: my ($output,$selnone);
5822: unless ($checked) {
5823: $selnone = ' selected="selected"';
5824: }
5825: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5826: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5827: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5828: foreach my $option (@{$options{$field}}) {
5829: my $sel;
5830: if ($inuse{$field} eq $option) {
5831: $sel = ' selected="selected"';
5832: }
5833: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5834: }
5835: $output .= '</select></span>';
5836: push(@selectboxes,$output);
5837: } else {
5838: $rem = $i%($numinrow);
5839: if ($rem == 0) {
5840: if ($i > 0) {
5841: $datatable .= '</tr>';
5842: }
5843: $datatable .= '<tr>';
5844: }
5845: $datatable .= '<td class="LC_left_item">'.
5846: '<span class="LC_nobreak">'.
5847: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5848: $fieldtitles{$field}.'</label></span></td>';
5849: $i++;
5850: }
5851: }
5852: }
5853: if ($provider eq 'proctorio') {
5854: if ($numinrow) {
5855: $rem = $i%$numinrow;
5856: }
5857: my $colsleft = $numinrow - $rem;
5858: if ($colsleft > 1) {
5859: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5860: } else {
5861: $datatable .= '<td class="LC_left_item">';
5862: }
5863: $datatable .= ' '.
5864: '</td></tr></table>';
5865: if (@selectboxes) {
5866: $datatable .= '<hr /><table>';
5867: $numinrow = 2;
5868: for (my $i=0; $i<@selectboxes; $i++) {
5869: $rem = $i%($numinrow);
5870: if ($rem == 0) {
5871: if ($i > 0) {
5872: $datatable .= '</tr>';
5873: }
5874: $datatable .= '<tr>';
5875: }
5876: $datatable .= '<td class="LC_left_item">'.
5877: $selectboxes[$i].'</td>';
5878: }
5879: if ($numinrow) {
5880: $rem = $i%$numinrow;
5881: }
5882: $colsleft = $numinrow - $rem;
5883: if ($colsleft > 1) {
5884: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5885: } else {
5886: $datatable .= '<td class="LC_left_item">';
5887: }
5888: $datatable .= ' '.
5889: '</td></tr></table>';
5890: }
5891: }
5892: $datatable .= '</fieldset>';
5893: }
5894: if (ref($crsconf{$provider}) eq 'ARRAY') {
5895: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5896: '<legend>'.&mt('Configurable in course').'</legend>';
5897: my ($rem,$numinrow);
5898: if ($provider eq 'proctorio') {
5899: $datatable .= '<table>';
5900: $numinrow = 4;
5901: }
5902: my $i = 0;
5903: foreach my $item (@{$crsconf{$provider}}) {
5904: my $name;
5905: if ($provider eq 'examity') {
5906: $name = $lt{'crs'.$item};
5907: } elsif ($provider eq 'proctorio') {
5908: $name = $fieldtitles{$item};
5909: $rem = $i%($numinrow);
5910: if ($rem == 0) {
5911: if ($i > 0) {
5912: $datatable .= '</tr>';
5913: }
5914: $datatable .= '<tr>';
5915: }
5916: $datatable .= '<td class="LC_left_item>';
5917: }
5918: my $checked;
5919: if ($crsconfig{$item}) {
5920: $checked = ' checked="checked"';
5921: }
5922: $datatable .= '<span class="LC_nobreak"><label>'.
5923: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5924: $name.'</label></span>';
5925: if ($provider eq 'examity') {
5926: $datatable .= ' ';
5927: }
5928: $datatable .= "\n";
5929: $i++;
5930: }
5931: if ($provider eq 'proctorio') {
5932: if ($numinrow) {
5933: $rem = $i%$numinrow;
5934: }
5935: my $colsleft = $numinrow - $rem;
5936: if ($colsleft > 1) {
5937: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5938: } else {
5939: $datatable .= '<td class="LC_left_item">';
5940: }
5941: $datatable .= ' '.
5942: '</td></tr></table>';
5943: }
5944: $datatable .= '</fieldset>';
5945: }
5946: if ($showroles) {
5947: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5948: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5949: foreach my $role (@courseroles) {
5950: my ($selected,$selectnone);
5951: if (!$rolemaps{$role}) {
5952: $selectnone = ' selected="selected"';
5953: }
5954: $datatable .= '<td style="text-align: center">'.
5955: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5956: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5957: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5958: foreach my $ltirole (@ltiroles) {
5959: unless ($selectnone) {
5960: if ($rolemaps{$role} eq $ltirole) {
5961: $selected = ' selected="selected"';
5962: } else {
5963: $selected = '';
5964: }
5965: }
5966: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5967: }
5968: $datatable .= '</select></td>';
5969: }
5970: $datatable .= '</tr></table></fieldset>'.
5971: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5972: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5973: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5974: '<tr><td></td><td>lms</td>'.
5975: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5976: ' value="Loncapa" disabled="disabled"/></td></tr>';
5977: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5978: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5979: my %custom = %{$settings->{$provider}->{'custom'}};
5980: if (keys(%custom) > 0) {
5981: foreach my $key (sort(keys(%custom))) {
5982: next if ($key eq 'lms');
5983: $datatable .= '<tr><td><span class="LC_nobreak">'.
5984: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5985: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5986: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
5987: ' value="'.$custom{$key}.'" /></td></tr>';
5988: }
5989: }
5990: }
5991: $datatable .= '<tr><td><span class="LC_nobreak">'.
5992: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
5993: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
5994: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
5995: '</table></fieldset></td></tr>'."\n";
5996: }
5997: $datatable .= '</td></tr>';
5998: }
5999: $itemcount ++;
6000: }
6001: }
6002: return $datatable;
6003: }
6004:
6005: sub proctoring_data {
6006: my $requserfields = {
6007: proctorio => ['user'],
6008: examity => ['roles','user'],
6009: };
6010: my $optuserfields = {
6011: proctorio => ['fullname'],
6012: examity => ['fullname','firstname','lastname','email'],
6013: };
6014: my $defaults = {
6015: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6016: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6017: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6018: 'closetabs','onescreen','print','downloads','cache','rightclick',
6019: 'reentry','calculator','whiteboard'],
6020: examity => ['display'],
6021: };
6022: my $extended = {
6023: proctorio => {
6024: verifyid => ['verifyidauto','verifyidlive'],
6025: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6026: tabslinks => ['notabs','linksonly'],
6027: reentry => ['noreentry','agentreentry'],
6028: calculator => ['calculatorbasic','calculatorsci'],
6029: },
6030: examity => {
6031: display => {
6032: target => ['iframe','tab','window'],
6033: width => '',
6034: height => '',
6035: linktext => '',
6036: explanation => '',
6037: },
6038: },
6039: };
6040: my $crsconf = {
6041: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6042: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6043: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6044: 'closetabs','onescreen','print','downloads','cache','rightclick',
6045: 'reentry','calculator','whiteboard'],
6046: examity => ['label','title','target','linktext','explanation','append'],
6047: };
6048: my $courseroles = ['cc','in','ta','ep','st'];
6049: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6050: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6051: }
6052:
6053: sub proctoring_titles {
6054: my ($item) = @_;
6055: my (%common_lt,%custom_lt);
6056: %common_lt = &Apache::lonlocal::texthash (
6057: 'avai' => 'Available?',
6058: 'base' => 'Basic Settings',
6059: 'requ' => 'User data required to be sent on launch',
6060: 'optu' => 'User data optionally sent on launch',
6061: 'udsl' => 'User data sent on launch',
6062: 'defa' => 'Defaults for items configurable in course',
6063: 'sigmethod' => 'Signature Method',
6064: 'key' => 'Key',
6065: 'lifetime' => 'Nonce lifetime (s)',
6066: 'secret' => 'Secret',
6067: 'icon' => 'Icon',
6068: 'fullname' => 'Full Name',
6069: 'visible' => 'Visible input',
6070: 'username' => 'username',
6071: 'user' => 'User',
6072: );
6073: if ($item eq 'proctorio') {
6074: %custom_lt = &Apache::lonlocal::texthash (
6075: 'version' => 'OAuth version',
6076: 'url' => 'API URL',
6077: 'uname:dom' => 'username-domain',
6078: );
6079: } elsif ($item eq 'examity') {
6080: %custom_lt = &Apache::lonlocal::texthash (
6081: 'version' => 'LTI Version',
6082: 'url' => 'URL',
6083: 'uname:dom' => 'username:domain',
6084: 'msgtype' => 'Message Type',
6085: 'firstname' => 'First Name',
6086: 'lastname' => 'Last Name',
6087: 'email' => 'E-mail',
6088: 'roles' => 'Role',
6089: 'crstarget' => 'Display target',
6090: 'crslabel' => 'Course label',
6091: 'crstitle' => 'Course title',
6092: 'crslinktext' => 'Link Text',
6093: 'crsexplanation' => 'Explanation',
6094: 'crsappend' => 'Provider URL',
6095: );
6096: }
6097: my %lt = (%common_lt,%custom_lt);
6098: return %lt;
6099: }
6100:
6101: sub proctoring_fieldtitles {
6102: my ($item) = @_;
6103: if ($item eq 'proctorio') {
6104: return &Apache::lonlocal::texthash (
6105: 'recordvideo' => 'Record video',
6106: 'recordaudio' => 'Record audio',
6107: 'recordscreen' => 'Record screen',
6108: 'recordwebtraffic' => 'Record web traffic',
6109: 'recordroomstart' => 'Record room scan',
6110: 'verifyvideo' => 'Verify webcam',
6111: 'verifyaudio' => 'Verify microphone',
6112: 'verifydesktop' => 'Verify desktop recording',
6113: 'verifyid' => 'Photo ID verification',
6114: 'verifysignature' => 'Require signature',
6115: 'fullscreen' => 'Fullscreen',
6116: 'clipboard' => 'Disable copy/paste',
6117: 'tabslinks' => 'New tabs/windows',
6118: 'closetabs' => 'Close other tabs',
6119: 'onescreen' => 'Limit to single screen',
6120: 'print' => 'Disable Printing',
6121: 'downloads' => 'Disable Downloads',
6122: 'cache' => 'Empty cache after exam',
6123: 'rightclick' => 'Disable right click',
6124: 'reentry' => 'Re-entry to exam',
6125: 'calculator' => 'Onscreen calculator',
6126: 'whiteboard' => 'Onscreen whiteboard',
6127: 'verifyidauto' => 'Automated verification',
6128: 'verifyidlive' => 'Live agent verification',
6129: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6130: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6131: 'fullscreensever' => 'Forced, navigation away ends exam',
6132: 'notabs' => 'Disaallowed',
6133: 'linksonly' => 'Allowed from links in exam',
6134: 'noreentry' => 'Disallowed',
6135: 'agentreentry' => 'Agent required for re-entry',
6136: 'calculatorbasic' => 'Basic',
6137: 'calculatorsci' => 'Scientific',
6138: );
6139: } elsif ($item eq 'examity') {
6140: return &Apache::lonlocal::texthash (
6141: 'target' => 'Display target',
6142: 'window' => 'Window',
6143: 'tab' => 'Tab',
6144: 'iframe' => 'iFrame',
6145: 'height' => 'Height (pixels)',
6146: 'width' => 'Width (pixels)',
6147: 'linktext' => 'Default Link Text',
6148: 'explanation' => 'Default Explanation',
6149: 'append' => 'Provider URL',
6150: );
6151: }
6152: }
6153:
6154: sub proctoring_providernames {
6155: return (
6156: proctorio => 'Proctorio',
6157: examity => 'Examity',
6158: );
6159: }
6160:
1.320 raeburn 6161: sub print_lti {
1.405 raeburn 6162: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6163: my $itemcount = 1;
1.405 raeburn 6164: my ($datatable,$css_class);
1.434 raeburn 6165: my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
1.320 raeburn 6166: if (ref($settings) eq 'HASH') {
1.405 raeburn 6167: if ($position eq 'top') {
6168: if (exists($settings->{'encrypt'})) {
6169: if (ref($settings->{'encrypt'}) eq 'HASH') {
6170: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6171: if ($key eq 'consumers') {
6172: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6173: } else {
6174: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6175: }
6176: }
6177: }
6178: }
6179: if (exists($settings->{'private'})) {
6180: if (ref($settings->{'private'}) eq 'HASH') {
6181: if (ref($settings->{'private'}) eq 'HASH') {
6182: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6183: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6184: }
6185: }
6186: }
6187: }
1.434 raeburn 6188: } elsif ($position eq 'upper') {
1.405 raeburn 6189: if (exists($settings->{'rules'})) {
6190: if (ref($settings->{'rules'}) eq 'HASH') {
6191: %rules = %{$settings->{'rules'}};
6192: }
6193: }
1.434 raeburn 6194: } elsif ($position eq 'middle') {
6195: if (exists($settings->{'suggested'})) {
6196: if (ref($settings->{'suggested'}) eq 'HASH') {
6197: %suggestions = %{$settings->{'suggested'}};
6198: }
6199: }
1.405 raeburn 6200: } elsif ($position eq 'lower') {
6201: if (exists($settings->{'linkprot'})) {
6202: if (ref($settings->{'linkprot'}) eq 'HASH') {
6203: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6204: if ($linkprot{'lock'}) {
6205: delete($linkprot{'lock'});
6206: }
1.405 raeburn 6207: }
6208: }
6209: } else {
1.434 raeburn 6210: foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
1.405 raeburn 6211: if (exists($settings->{$key})) {
6212: delete($settings->{$key});
1.390 raeburn 6213: }
1.320 raeburn 6214: }
6215: }
6216: }
1.405 raeburn 6217: if ($position eq 'top') {
1.421 raeburn 6218: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
1.434 raeburn 6219: } elsif ($position eq 'upper') {
6220: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
6221: $$rowtotal += $itemcount;
1.421 raeburn 6222: } elsif ($position eq 'middle') {
1.434 raeburn 6223: $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
1.421 raeburn 6224: $$rowtotal += $itemcount;
6225: } elsif ($position eq 'lower') {
1.434 raeburn 6226: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
1.421 raeburn 6227: } else {
1.424 raeburn 6228: my ($switchserver,$switchmessage);
6229: $switchserver = &check_switchserver($dom);
6230: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.421 raeburn 6231: my $maxnum = 0;
6232: my %ordered;
6233: if (ref($settings) eq 'HASH') {
6234: foreach my $item (keys(%{$settings})) {
6235: if (ref($settings->{$item}) eq 'HASH') {
6236: my $num = $settings->{$item}{'order'};
6237: if ($num eq '') {
6238: $num = scalar(keys(%{$settings}));
6239: }
6240: $ordered{$num} = $item;
1.405 raeburn 6241: }
1.352 raeburn 6242: }
1.405 raeburn 6243: }
6244: $maxnum = scalar(keys(%ordered));
6245: my %lt = <i_names();
6246: if (keys(%ordered)) {
6247: my @items = sort { $a <=> $b } keys(%ordered);
6248: for (my $i=0; $i<@items; $i++) {
6249: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6250: my $item = $ordered{$items[$i]};
1.424 raeburn 6251: my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
1.405 raeburn 6252: if (ref($settings->{$item}) eq 'HASH') {
6253: $key = $settings->{$item}->{'key'};
1.424 raeburn 6254: $usable = $settings->{$item}->{'usable'};
1.405 raeburn 6255: $lifetime = $settings->{$item}->{'lifetime'};
6256: $consumer = $settings->{$item}->{'consumer'};
6257: $requser = $settings->{$item}->{'requser'};
6258: $crsinc = $settings->{$item}->{'crsinc'};
6259: $current = $settings->{$item};
6260: }
6261: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6262: my %checkedrequser = (
6263: yes => ' checked="checked"',
6264: no => '',
6265: );
6266: if (!$requser) {
6267: $checkedrequser{'no'} = $checkedrequser{'yes'};
6268: $checkedrequser{'yes'} = '';
6269: }
6270: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6271: my %checkedcrsinc = (
1.391 raeburn 6272: yes => ' checked="checked"',
6273: no => '',
1.405 raeburn 6274: );
6275: if (!$crsinc) {
6276: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6277: $checkedcrsinc{'yes'} = '';
6278: }
6279: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6280: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6281: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6282: for (my $k=0; $k<=$maxnum; $k++) {
6283: my $vpos = $k+1;
6284: my $selstr;
6285: if ($k == $i) {
6286: $selstr = ' selected="selected" ';
6287: }
6288: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6289: }
1.405 raeburn 6290: $datatable .= '</select>'.(' 'x2).
6291: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6292: &mt('Delete?').'</label></span></td>'.
6293: '<td colspan="2">'.
6294: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6295: '<span class="LC_nobreak">'.$lt{'consumer'}.
6296: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6297: (' 'x2).
6298: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6299: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6300: (' 'x2).
6301: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.424 raeburn 6302: 'value="'.$lifetime.'" size="3" /></span><br /><br />';
6303: if ($key ne '') {
6304: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6305: if ($switchserver) {
6306: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6307: } else {
6308: $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
6309: }
6310: $datatable .= '</span> '.(' 'x2);
6311: } elsif (!$switchserver) {
6312: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6313: '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
6314: '</span> '.(' 'x2);
6315: }
6316: if ($switchserver) {
6317: if ($usable ne '') {
6318: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6319: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6320: '<span class="LC_nobreak">'.&mt('Change secret?').
6321: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6322: (' 'x2).
6323: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
6324: '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6325: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6326: '</div>';
6327: } elsif ($key eq '') {
6328: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6329: } else {
6330: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6331: }
6332: } else {
6333: if ($usable ne '') {
6334: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6335: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6336: '<span class="LC_nobreak">'.&mt('Change?').
6337: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6338: (' 'x2).
6339: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
6340: '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6341: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6342: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6343: '<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>';
6344: } else {
6345: $datatable .=
6346: '<span class="LC_nobreak">'.$lt{'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>';
6349: }
6350: }
1.425 raeburn 6351: $datatable .= '<br /><br />'.
1.405 raeburn 6352: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6353: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6354: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6355: '<br /><br />'.
6356: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6357: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6358: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6359: (' 'x4).
6360: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6361: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6362: $itemcount ++;
1.320 raeburn 6363: }
6364: }
1.405 raeburn 6365: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6366: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6367: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6368: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6369: '<select name="lti_pos_add"'.$chgstr.'>';
6370: for (my $k=0; $k<$maxnum+1; $k++) {
6371: my $vpos = $k+1;
6372: my $selstr;
6373: if ($k == $maxnum) {
6374: $selstr = ' selected="selected" ';
6375: }
6376: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6377: }
1.405 raeburn 6378: $datatable .= '</select> '."\n".
6379: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6380: '<td colspan="2">'.
6381: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6382: '<span class="LC_nobreak">'.$lt{'consumer'}.
6383: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6384: (' 'x2).
6385: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6386: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6387: (' 'x2).
1.424 raeburn 6388: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
6389: if ($switchserver) {
6390: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6391: } else {
6392: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
6393: (' 'x2).
6394: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
6395: '<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";
6396: }
6397: $datatable .= '<br /><br />'.
1.405 raeburn 6398: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6399: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6400: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6401: '<br /><br />'.
6402: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6403: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6404: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6405: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6406: '</td>'."\n".
6407: '</tr>'."\n";
6408: $itemcount ++;
1.320 raeburn 6409: }
1.405 raeburn 6410: $$rowtotal += $itemcount;
6411: return $datatable;
1.320 raeburn 6412: }
6413:
6414: sub lti_names {
6415: my %lt = &Apache::lonlocal::texthash(
6416: 'version' => 'LTI Version',
6417: 'url' => 'URL',
6418: 'key' => 'Key',
1.322 raeburn 6419: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6420: 'consumer' => 'Consumer',
1.320 raeburn 6421: 'secret' => 'Secret',
1.345 raeburn 6422: 'requser' => "User's identity sent",
1.391 raeburn 6423: 'crsinc' => "Course's identity sent",
1.320 raeburn 6424: 'email' => 'Email address',
6425: 'sourcedid' => 'User ID',
6426: 'other' => 'Other',
6427: 'passback' => 'Can return grades to Consumer:',
6428: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6429: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6430: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6431: );
6432: return %lt;
6433: }
6434:
6435: sub lti_options {
1.325 raeburn 6436: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6437: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6438: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6439: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6440: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6441: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6442: $checked{'mapcrstype'} = {};
6443: $checked{'makeuser'} = {};
6444: $checked{'selfenroll'} = {};
6445: $checked{'crssec'} = {};
6446: $checked{'crssecsrc'} = {};
1.325 raeburn 6447: $checked{'lcauth'} = {};
1.326 raeburn 6448: $checked{'menuitem'} = {};
1.325 raeburn 6449: if ($num eq 'add') {
6450: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6451: }
1.320 raeburn 6452: my $userfieldsty = 'none';
6453: my $crsfieldsty = 'none';
6454: my $crssecfieldsty = 'none';
6455: my $secsrcfieldsty = 'none';
1.363 raeburn 6456: my $callbacksty = 'none';
1.337 raeburn 6457: my $passbacksty = 'none';
1.345 raeburn 6458: my $optionsty = 'block';
1.391 raeburn 6459: my $crssty = 'block';
1.325 raeburn 6460: my $lcauthparm;
6461: my $lcauthparmstyle = 'display:none';
6462: my $lcauthparmtext;
1.326 raeburn 6463: my $menusty;
1.325 raeburn 6464: my $numinrow = 4;
1.326 raeburn 6465: my %menutitles = <imenu_titles();
1.320 raeburn 6466:
6467: if (ref($current) eq 'HASH') {
1.345 raeburn 6468: if (!$current->{'requser'}) {
6469: $optionsty = 'none';
1.391 raeburn 6470: $crssty = 'none';
6471: } elsif (!$current->{'crsinc'}) {
6472: $crssty = 'none';
1.345 raeburn 6473: }
1.320 raeburn 6474: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6475: $checked{'mapuser'}{'sourcedid'} = '';
6476: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
1.425 raeburn 6477: $checked{'mapuser'}{'email'} = ' checked="checked"';
1.320 raeburn 6478: } else {
6479: $checked{'mapuser'}{'other'} = ' checked="checked"';
6480: $userfield = $current->{'mapuser'};
6481: $userfieldsty = 'inline-block';
6482: }
6483: }
6484: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6485: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6486: if ($current->{'mapcrs'} eq 'context_id') {
1.425 raeburn 6487: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
1.320 raeburn 6488: } else {
6489: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6490: $cidfield = $current->{'mapcrs'};
6491: $crsfieldsty = 'inline-block';
6492: }
6493: }
6494: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6495: foreach my $type (@{$current->{'mapcrstype'}}) {
6496: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6497: }
6498: }
1.392 raeburn 6499: if (!$current->{'storecrs'}) {
6500: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6501: $checked{'storecrs'}{'Y'} = '';
6502: }
1.345 raeburn 6503: if ($current->{'makecrs'}) {
1.320 raeburn 6504: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6505: }
1.320 raeburn 6506: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6507: foreach my $role (@{$current->{'makeuser'}}) {
6508: $checked{'makeuser'}{$role} = ' checked="checked"';
6509: }
6510: }
1.325 raeburn 6511: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6512: $checked{'lcauth'}{$1} = ' checked="checked"';
6513: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6514: $lcauthparm = $current->{'lcauthparm'};
1.425 raeburn 6515: $lcauthparmstyle = 'display:table-row';
1.325 raeburn 6516: if ($current->{'lcauth'} eq 'localauth') {
6517: $lcauthparmtext = &mt('Local auth argument');
6518: } else {
6519: $lcauthparmtext = &mt('Kerberos domain');
6520: }
6521: }
6522: }
1.320 raeburn 6523: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6524: foreach my $role (@{$current->{'selfenroll'}}) {
6525: $checked{'selfenroll'}{$role} = ' checked="checked"';
6526: }
6527: }
6528: if (ref($current->{'maproles'}) eq 'HASH') {
6529: %rolemaps = %{$current->{'maproles'}};
6530: }
6531: if ($current->{'section'} ne '') {
1.425 raeburn 6532: $checked{'crssec'}{'Y'} = ' checked="checked"';
1.320 raeburn 6533: $crssecfieldsty = 'inline-block';
6534: if ($current->{'section'} eq 'course_section_sourcedid') {
6535: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6536: } else {
6537: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6538: $crssecsrc = $current->{'section'};
6539: $secsrcfieldsty = 'inline-block';
6540: }
6541: } else {
6542: $checked{'crssec'}{'N'} = ' checked="checked"';
6543: }
1.363 raeburn 6544: if ($current->{'callback'} ne '') {
6545: $callback = $current->{'callback'};
6546: $checked{'callback'}{'Y'} = ' checked="checked"';
6547: $callbacksty = 'inline-block';
6548: } else {
6549: $checked{'callback'}{'N'} = ' checked="checked"';
6550: }
1.326 raeburn 6551: if ($current->{'topmenu'}) {
6552: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6553: } else {
6554: $checked{'topmenu'}{'N'} = ' checked="checked"';
6555: }
6556: if ($current->{'inlinemenu'}) {
6557: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6558: } else {
6559: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6560: }
6561: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6562: $menusty = 'inline-block';
6563: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6564: foreach my $item (@{$current->{'lcmenu'}}) {
6565: if (exists($menutitles{$item})) {
6566: $checked{'menuitem'}{$item} = ' checked="checked"';
6567: }
6568: }
6569: }
6570: } else {
6571: $menusty = 'none';
6572: }
1.320 raeburn 6573: } else {
6574: $checked{'makecrs'}{'N'} = ' checked="checked"';
6575: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6576: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6577: $checked{'topmenu'}{'N'} = ' checked="checked"';
1.425 raeburn 6578: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
1.326 raeburn 6579: $checked{'menuitem'}{'grades'} = ' checked="checked"';
1.425 raeburn 6580: $menusty = 'inline-block';
1.320 raeburn 6581: }
1.325 raeburn 6582: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6583: my %coursetypetitles = &Apache::lonlocal::texthash (
6584: official => 'Official',
6585: unofficial => 'Unofficial',
6586: community => 'Community',
6587: textbook => 'Textbook',
6588: placement => 'Placement Test',
1.325 raeburn 6589: lti => 'LTI Provider',
1.320 raeburn 6590: );
1.325 raeburn 6591: my @authtypes = ('internal','krb4','krb5','localauth');
6592: my %shortauth = (
6593: internal => 'int',
6594: krb4 => 'krb4',
6595: krb5 => 'krb5',
6596: localauth => 'loc'
6597: );
6598: my %authnames = &authtype_names();
1.320 raeburn 6599: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6600: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6601: my @courseroles = ('cc','in','ta','ep','st');
6602: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6603: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6604: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6605: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6606: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6607: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6608: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6609: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6610: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6611: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6612: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6613: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6614: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6615: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6616: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6617: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6618: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6619: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6620: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6621: foreach my $option ('sourcedid','email','other') {
6622: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6623: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6624: ($option eq 'other' ? '' : (' 'x2) );
6625: }
6626: $output .= '</span></div>'.
6627: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6628: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6629: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6630: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6631: foreach my $ltirole (@ltiroles) {
6632: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
1.425 raeburn 6633: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
1.320 raeburn 6634: }
6635: $output .= '</fieldset>'.
1.391 raeburn 6636: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6637: '<table>'.
6638: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6639: '</table>'.
6640: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6641: '<td class="LC_left_item">';
6642: foreach my $auth ('lti',@authtypes) {
6643: my $authtext;
6644: if ($auth eq 'lti') {
6645: $authtext = &mt('None');
6646: } else {
6647: $authtext = $authnames{$shortauth{$auth}};
6648: }
6649: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6650: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6651: $authtext.'</label></span> ';
6652: }
6653: $output .= '</td></tr>'.
6654: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6655: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6656: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6657: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6658: '</table></fieldset>'.
1.391 raeburn 6659: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6660: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6661: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6662: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6663: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6664: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6665: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6666: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6667: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6668: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6669: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6670: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6671: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6672: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6673: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6674: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6675: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6676: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6677: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6678: (' 'x2);
6679: }
6680: $output .= '</span></div></fieldset>'.
6681: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6682: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6683: &mt('Unique course identifier').': ';
6684: foreach my $option ('course_offering_sourcedid','context_id','other') {
6685: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6686: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6687: ($option eq 'other' ? '' : (' 'x2) );
6688: }
1.334 raeburn 6689: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6690: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6691: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6692: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6693: foreach my $type (@coursetypes) {
6694: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6695: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6696: (' 'x2);
6697: }
1.392 raeburn 6698: $output .= '</span><br /><br />'.
6699: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6700: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6701: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6702: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6703: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6704: '</fieldset>'.
1.391 raeburn 6705: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6706: foreach my $ltirole (@lticourseroles) {
6707: my ($selected,$selectnone);
6708: if ($rolemaps{$ltirole} eq '') {
6709: $selectnone = ' selected="selected"';
6710: }
6711: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6712: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6713: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6714: foreach my $role (@courseroles) {
6715: unless ($selectnone) {
6716: if ($rolemaps{$ltirole} eq $role) {
6717: $selected = ' selected="selected"';
6718: } else {
6719: $selected = '';
6720: }
6721: }
6722: $output .= '<option value="'.$role.'"'.$selected.'>'.
6723: &Apache::lonnet::plaintext($role,'Course').
6724: '</option>';
6725: }
6726: $output .= '</select></td>';
6727: }
6728: $output .= '</tr></table></fieldset>'.
6729: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6730: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6731: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6732: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6733: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6734: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6735: '</fieldset>'.
1.391 raeburn 6736: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6737: foreach my $lticrsrole (@lticourseroles) {
6738: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6739: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6740: }
6741: $output .= '</fieldset>'.
1.391 raeburn 6742: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6743: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6744: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6745: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6746: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6747: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6748: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6749: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6750: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6751: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6752: &mt('Standard field').'</label>'.(' 'x2).
6753: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6754: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6755: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6756: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6757: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6758: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6759: foreach my $extra ('roster','passback') {
1.320 raeburn 6760: my $checkedon = '';
6761: my $checkedoff = ' checked="checked"';
1.337 raeburn 6762: if ($extra eq 'passback') {
6763: $pb1p1chk = ' checked="checked"';
6764: $pb1p0chk = '';
1.425 raeburn 6765: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
1.337 raeburn 6766: } else {
1.425 raeburn 6767: $onclickpb = '';
1.337 raeburn 6768: }
1.320 raeburn 6769: if (ref($current) eq 'HASH') {
6770: if (($current->{$extra})) {
6771: $checkedon = $checkedoff;
6772: $checkedoff = '';
1.337 raeburn 6773: if ($extra eq 'passback') {
6774: $passbacksty = 'inline-block';
6775: }
6776: if ($current->{'passbackformat'} eq '1.0') {
6777: $pb1p0chk = ' checked="checked"';
6778: $pb1p1chk = '';
6779: }
1.320 raeburn 6780: }
6781: }
6782: $output .= $lt{$extra}.' '.
1.337 raeburn 6783: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6784: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6785: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6786: &mt('Yes').'</label><br />';
6787: }
1.337 raeburn 6788: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6789: '<span class="LC_nobreak">'.&mt('Grade format').
6790: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6791: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6792: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6793: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6794: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6795: $output .= '</span></div></fieldset>';
1.320 raeburn 6796: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6797: #
6798: # $output .= '</fieldset>'.
6799: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6800: return $output;
6801: }
6802:
1.326 raeburn 6803: sub ltimenu_titles {
6804: return &Apache::lonlocal::texthash(
6805: fullname => 'Full name',
6806: coursetitle => 'Course title',
6807: role => 'Role',
6808: logout => 'Logout',
6809: grades => 'Grades',
6810: );
6811: }
6812:
1.434 raeburn 6813: sub linkprot_suggestions {
6814: my ($suggested,$itemcount) = @_;
6815: my $count = 0;
6816: my $next = 1;
6817: my %lt = &Apache::lonlocal::texthash(
6818: 'name' => 'Suggested Launcher',
6819: 'info' => 'Recommendations',
6820: );
6821: my ($datatable,$css_class,$dest);
6822: if (ref($suggested) eq 'HASH') {
6823: my @current = sort { $a <=> $b } keys(%{$suggested});
6824: $next += $current[-1];
6825: for (my $i=0; $i<@current; $i++) {
6826: my $num = $current[$i];
6827: my %values;
6828: if (ref($suggested->{$num}) eq 'HASH') {
6829: %values = %{$suggested->{$num}};
6830: } else {
6831: next;
6832: }
6833: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6834: $datatable .=
6835: '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6836: '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
6837: &mt('Delete?').'</label></span></td><td>'."\n".
6838: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6839: '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
6840: '</fieldset></div>'.
6841: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6842: '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
6843: '</fieldset></div>'.
6844: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6845: '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
6846: $$itemcount ++;
6847: }
6848: }
6849: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6850: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6851: '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
6852: '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6853: '<td>'."\n".
6854: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6855: '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
6856: '</fieldset></div>'.
6857: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6858: '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
6859: '</fieldset></div>'.
6860: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6861: '</td></tr>'."\n";
6862: return $datatable;
6863: }
6864:
1.121 raeburn 6865: sub print_coursedefaults {
1.139 raeburn 6866: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6867: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6868: my $itemcount = 1;
1.192 raeburn 6869: my %choices = &Apache::lonlocal::texthash (
6870: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6871: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.432 raeburn 6872: coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.192 raeburn 6873: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6874: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6875: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6876: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6877: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6878: texengine => 'Default method to display mathematics',
1.257 raeburn 6879: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6880: canclone => "People who may clone a course (besides course's owner and coordinators)",
6881: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6882: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422 raeburn 6883: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6884: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
1.432 raeburn 6885: crsauthor => 'Standard LON-CAPA problems can be created within a course/community (by type)',
1.438 raeburn 6886: crseditors => 'Available editors for web pages and/or problems created in a course/community',
1.192 raeburn 6887: );
1.198 raeburn 6888: my %staticdefaults = (
6889: anonsurvey_threshold => 10,
6890: uploadquota => 500,
1.428 raeburn 6891: coursequota => 20,
1.257 raeburn 6892: postsubmit => 60,
1.276 raeburn 6893: mysqltables => 172800,
1.422 raeburn 6894: domexttool => 1,
6895: exttool => 0,
1.432 raeburn 6896: crsauthor => 1,
1.438 raeburn 6897: crseditors => ['edit','xml'],
1.198 raeburn 6898: );
1.139 raeburn 6899: if ($position eq 'top') {
1.257 raeburn 6900: %defaultchecked = (
6901: 'canuse_pdfforms' => 'off',
6902: 'uselcmath' => 'on',
6903: 'usejsme' => 'on',
1.398 raeburn 6904: 'inline_chem' => 'on',
1.289 raeburn 6905: 'canclone' => 'none',
1.257 raeburn 6906: );
1.398 raeburn 6907: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6908: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6909: if (ref($settings) eq 'HASH') {
6910: if ($settings->{'texengine'}) {
6911: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6912: $deftex = $settings->{'texengine'};
6913: }
6914: }
6915: }
6916: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6917: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6918: '<span class="LC_nobreak">'.$choices{'texengine'}.
6919: '</span></td><td class="LC_right_item">'.
6920: '<select name="texengine">'."\n";
6921: my %texoptions = (
6922: MathJax => 'MathJax',
6923: mimetex => &mt('Convert to Images'),
6924: tth => &mt('TeX to HTML'),
6925: );
6926: foreach my $renderer ('MathJax','mimetex','tth') {
6927: my $selected = '';
6928: if ($renderer eq $deftex) {
6929: $selected = ' selected="selected"';
6930: }
6931: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6932: }
6933: $mathdisp .= '</select></td></tr>'."\n";
6934: $itemcount ++;
1.139 raeburn 6935: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6936: \%choices,$itemcount);
1.314 raeburn 6937: $datatable = $mathdisp.$datatable;
1.264 raeburn 6938: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6939: $datatable .=
1.306 raeburn 6940: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6941: '<span class="LC_nobreak">'.$choices{'canclone'}.
6942: '</span></td><td class="LC_left_item">';
6943: my $currcanclone = 'none';
6944: my $onclick;
6945: my @cloneoptions = ('none','domain');
1.380 raeburn 6946: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6947: none => 'No additional course requesters',
6948: domain => "Any course requester in course's domain",
6949: instcode => 'Course requests for official courses ...',
6950: );
6951: my (%codedefaults,@code_order,@posscodes);
6952: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6953: \@code_order) eq 'ok') {
6954: if (@code_order > 0) {
6955: push(@cloneoptions,'instcode');
6956: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6957: }
6958: }
6959: if (ref($settings) eq 'HASH') {
6960: if ($settings->{'canclone'}) {
6961: if (ref($settings->{'canclone'}) eq 'HASH') {
6962: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6963: if (@code_order > 0) {
6964: $currcanclone = 'instcode';
6965: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6966: }
6967: }
6968: } elsif ($settings->{'canclone'} eq 'domain') {
6969: $currcanclone = $settings->{'canclone'};
6970: }
6971: }
1.289 raeburn 6972: }
1.264 raeburn 6973: foreach my $option (@cloneoptions) {
6974: my ($checked,$additional);
6975: if ($currcanclone eq $option) {
6976: $checked = ' checked="checked"';
6977: }
6978: if ($option eq 'instcode') {
6979: if (@code_order) {
6980: my $show = 'none';
6981: if ($checked) {
6982: $show = 'block';
6983: }
1.317 raeburn 6984: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6985: &mt('Institutional codes for new and cloned course have identical:').
6986: '<br />';
6987: foreach my $item (@code_order) {
6988: my $codechk;
6989: if ($checked) {
6990: if (grep(/^\Q$item\E$/,@posscodes)) {
6991: $codechk = ' checked="checked"';
6992: }
6993: }
6994: $additional .= '<label>'.
6995: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6996: $item.'</label>';
6997: }
6998: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6999: }
7000: }
7001: $datatable .=
7002: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
7003: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
7004: '</label> '.$additional.'</span><br />';
7005: }
7006: $datatable .= '</td>'.
7007: '</tr>';
7008: $itemcount ++;
1.139 raeburn 7009: } else {
7010: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 7011: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
7012: %deftimeout,%currmysql);
1.192 raeburn 7013: my $currusecredits = 0;
1.257 raeburn 7014: my $postsubmitclient = 1;
1.405 raeburn 7015: my $ltiauth = 0;
1.422 raeburn 7016: my %domexttool;
7017: my %exttool;
1.432 raeburn 7018: my %crsauthor;
1.438 raeburn 7019: my %crseditors;
1.271 raeburn 7020: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 7021: if (ref($settings) eq 'HASH') {
1.404 raeburn 7022: if ($settings->{'ltiauth'}) {
7023: $ltiauth = 1;
1.405 raeburn 7024: }
1.422 raeburn 7025: if (ref($settings->{'domexttool'}) eq 'HASH') {
7026: foreach my $type (@types) {
7027: if ($settings->{'domexttool'}->{$type}) {
7028: $domexttool{$type} = ' checked="checked"';
7029: }
7030: }
7031: } else {
7032: foreach my $type (@types) {
7033: if ($staticdefaults{'domexttool'}) {
7034: $domexttool{$type} = ' checked="checked"';
7035: }
7036: }
7037: }
7038: if (ref($settings->{'exttool'}) eq 'HASH') {
7039: foreach my $type (@types) {
7040: if ($settings->{'exttool'}->{$type}) {
7041: $exttool{$type} = ' checked="checked"';
7042: }
7043: }
7044: }
1.432 raeburn 7045: if (ref($settings->{'crsauthor'}) eq 'HASH') {
7046: foreach my $type (@types) {
7047: if ($settings->{'crsauthor'}->{$type}) {
7048: $crsauthor{$type} = ' checked="checked"';
7049: }
7050: }
7051: } else {
7052: foreach my $type (@types) {
7053: if ($staticdefaults{'crsauthor'}) {
7054: $crsauthor{$type} = ' checked="checked"';
7055: }
7056: }
7057: }
1.438 raeburn 7058: if (ref($settings->{'crseditors'}) eq 'ARRAY') {
7059: foreach my $editor (@{$settings->{'crseditors'}}) {
7060: $crseditors{$editor} = ' checked="checked"';
7061: }
7062: } else {
7063: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7064: $crseditors{$editor} = ' checked="checked"';
7065: }
7066: }
1.139 raeburn 7067: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7068: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7069: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7070: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7071: }
7072: }
1.428 raeburn 7073: if (ref($settings->{'coursequota'}) eq 'HASH') {
7074: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7075: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7076: }
7077: }
1.192 raeburn 7078: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7079: foreach my $type (@types) {
7080: next if ($type eq 'community');
7081: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7082: if ($defcredits{$type} ne '') {
7083: $currusecredits = 1;
7084: }
7085: }
7086: }
7087: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7088: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7089: $postsubmitclient = 0;
7090: foreach my $type (@types) {
7091: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7092: }
7093: } else {
7094: foreach my $type (@types) {
7095: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7096: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7097: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7098: } else {
7099: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7100: }
7101: } else {
7102: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7103: }
7104: }
7105: }
7106: } else {
7107: foreach my $type (@types) {
7108: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7109: }
7110: }
1.276 raeburn 7111: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7112: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7113: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7114: }
7115: } else {
7116: foreach my $type (@types) {
7117: $currmysql{$type} = $staticdefaults{'mysqltables'};
7118: }
7119: }
1.258 raeburn 7120: } else {
7121: foreach my $type (@types) {
7122: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7123: if ($staticdefaults{'domexttool'}) {
7124: $domexttool{$type} = ' checked="checked"';
7125: }
1.432 raeburn 7126: if ($staticdefaults{'crsauthor'}) {
7127: $crsauthor{$type} = ' checked="checked"';
7128: }
1.258 raeburn 7129: }
1.438 raeburn 7130: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7131: $crseditors{$editor} = ' checked="checked"';
7132: }
1.139 raeburn 7133: }
7134: if (!$currdefresponder) {
1.198 raeburn 7135: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7136: } elsif ($currdefresponder < 1) {
7137: $currdefresponder = 1;
7138: }
1.198 raeburn 7139: foreach my $type (@types) {
7140: if ($curruploadquota{$type} eq '') {
7141: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7142: }
1.428 raeburn 7143: if ($currcoursequota{$type} eq '') {
7144: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7145: }
1.198 raeburn 7146: }
1.139 raeburn 7147: $datatable .=
1.192 raeburn 7148: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7149: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7150: '</span></td>'.
7151: '<td class="LC_right_item"><span class="LC_nobreak">'.
7152: '<input type="text" name="anonsurvey_threshold"'.
7153: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7154: '</td></tr>'."\n";
7155: $itemcount ++;
7156: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7157: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7158: $choices{'uploadquota'}.
7159: '</span></td>'.
1.306 raeburn 7160: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7161: '<table><tr>';
1.198 raeburn 7162: foreach my $type (@types) {
1.306 raeburn 7163: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7164: '<input type="text" name="uploadquota_'.$type.'"'.
7165: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7166: }
7167: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7168: $itemcount ++;
1.428 raeburn 7169: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7170: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7171: $choices{'coursequota'}.
7172: '</span></td>'.
7173: '<td style="text-align: right" class="LC_right_item">'.
7174: '<table><tr>';
7175: foreach my $type (@types) {
7176: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7177: '<input type="text" name="coursequota_'.$type.'"'.
7178: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7179: }
7180: $datatable .= '</tr></table></td></tr>'."\n";
7181: $itemcount ++;
1.236 raeburn 7182: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7183: my $display = 'none';
1.192 raeburn 7184: if ($currusecredits) {
7185: $display = 'block';
7186: }
7187: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7188: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7189: foreach my $type (@types) {
7190: next if ($type eq 'community');
1.306 raeburn 7191: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7192: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7193: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7194: }
7195: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7196: %defaultchecked = ('coursecredits' => 'off');
7197: @toggles = ('coursecredits');
7198: my $current = {
7199: 'coursecredits' => $currusecredits,
7200: };
7201: (my $table,$itemcount) =
7202: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7203: \%choices,$itemcount,$onclick,$additional,'left');
7204: $datatable .= $table;
7205: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7206: my $display = 'none';
7207: if ($postsubmitclient) {
7208: $display = 'block';
7209: }
7210: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7211: &mt('Number of seconds submit is disabled').'<br />'.
7212: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7213: '<table><tr>';
1.257 raeburn 7214: foreach my $type (@types) {
1.306 raeburn 7215: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7216: '<input type="text" name="'.$type.'_timeout" value="'.
7217: $deftimeout{$type}.'" size="5" /></td>';
7218: }
7219: $additional .= '</tr></table></div>'."\n";
7220: %defaultchecked = ('postsubmit' => 'on');
7221: @toggles = ('postsubmit');
1.280 raeburn 7222: $current = {
7223: 'postsubmit' => $postsubmitclient,
7224: };
1.257 raeburn 7225: ($table,$itemcount) =
7226: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7227: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7228: $datatable .= $table;
1.276 raeburn 7229: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7230: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7231: $choices{'mysqltables'}.
7232: '</span></td>'.
1.306 raeburn 7233: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7234: '<table><tr>';
7235: foreach my $type (@types) {
1.306 raeburn 7236: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7237: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7238: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7239: }
7240: $datatable .= '</tr></table></td></tr>'."\n";
7241: $itemcount ++;
1.404 raeburn 7242: %defaultchecked = ('ltiauth' => 'off');
7243: @toggles = ('ltiauth');
7244: $current = {
7245: 'ltiauth' => $ltiauth,
7246: };
7247: ($table,$itemcount) =
7248: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7249: \%choices,$itemcount,undef,undef,'left');
7250: $datatable .= $table;
1.422 raeburn 7251: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7252: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7253: $choices{'domexttool'}.
7254: '</span></td>'.
7255: '<td style="text-align: right" class="LC_right_item">'.
7256: '<table><tr>';
7257: foreach my $type (@types) {
7258: $datatable .= '<td style="text-align: left">'.
7259: '<span class="LC_nobreak">'.
1.438 raeburn 7260: '<label><input type="checkbox" name="domexttool"'.
1.422 raeburn 7261: ' value="'.$type.'"'.$domexttool{$type}.' />'.
1.438 raeburn 7262: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7263: }
7264: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7265: $itemcount ++;
1.422 raeburn 7266: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7267: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7268: $choices{'exttool'}.
7269: '</span></td>'.
7270: '<td style="text-align: right" class="LC_right_item">'.
7271: '<table><tr>';
7272: foreach my $type (@types) {
7273: $datatable .= '<td style="text-align: left">'.
7274: '<span class="LC_nobreak">'.
1.438 raeburn 7275: '<label><input type="checkbox" name="exttool"'.
1.422 raeburn 7276: ' value="'.$type.'"'.$exttool{$type}.' />'.
1.438 raeburn 7277: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7278: }
7279: $datatable .= '</tr></table></td></tr>'."\n";
1.432 raeburn 7280: $itemcount ++;
7281: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7282: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7283: $choices{'crsauthor'}.
7284: '</span></td>'.
7285: '<td style="text-align: right" class="LC_right_item">'.
7286: '<table><tr>';
7287: foreach my $type (@types) {
7288: $datatable .= '<td style="text-align: left">'.
7289: '<span class="LC_nobreak">'.
1.438 raeburn 7290: '<label><input type="checkbox" name="crsauthor"'.
1.432 raeburn 7291: ' value="'.$type.'"'.$crsauthor{$type}.' />'.
1.438 raeburn 7292: &mt($type).'</label></span></td>'."\n";
7293: }
7294: $datatable .= '</tr></table></td></tr>'."\n";
7295: $itemcount ++;
7296: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7297: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7298: $choices{'crseditors'}.
7299: '</span></td>'.
7300: '<td style="text-align: right" class="LC_right_item">'.
7301: '<table><tr>';
7302: my @editors = ('edit','xml','daxe');
7303: my %editornames = &crseditor_titles();
7304: foreach my $editor (@editors) {
7305: $datatable .= '<td style="text-align: left">'.
7306: '<span class="LC_nobreak">'.
7307: '<label><input type="checkbox" name="crseditors"'.
7308: ' value="'.$editor.'"'.$crseditors{$editor}.' />'.
7309: $editornames{$editor}.'</label></span></td>'."\n";
1.432 raeburn 7310: }
7311: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7312: }
1.192 raeburn 7313: $$rowtotal += $itemcount;
1.121 raeburn 7314: return $datatable;
1.118 jms 7315: }
7316:
1.438 raeburn 7317: sub crseditor_titles {
7318: return &Apache::lonlocal::texthash(
7319: edit => 'Standard editor (Edit)',
7320: xml => 'Text editor (EditXML)',
7321: daxe => 'Daxe editor (Daxe)',
7322: );
7323: }
7324:
1.429 raeburn 7325: sub print_authordefaults {
7326: my ($position,$dom,$settings,$rowtotal) = @_;
7327: my ($css_class,$datatable,%checkedon,%checkedoff);
7328: my $itemcount = 1;
7329: my %titles = &authordefaults_titles();
7330: if ($position eq 'top') {
7331: my %defaultchecked = (
7332: 'nocodemirror' => 'off',
1.437 raeburn 7333: 'daxecollapse' => 'off',
1.429 raeburn 7334: 'domcoordacc' => 'on',
7335: );
1.437 raeburn 7336: my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
1.429 raeburn 7337: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
7338: \%titles,$itemcount);
7339: my %staticdefaults = (
7340: 'copyright' => 'default',
7341: 'sourceavail' => 'closed',
7342: );
7343: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7344: my %currrights;
7345: foreach my $item ('copyright','sourceavail') {
7346: $currrights{$item} = $staticdefaults{$item};
7347: if (ref($settings) eq 'HASH') {
7348: if (exists($settings->{$item})) {
7349: $currrights{$item} = $settings->{$item};
7350: }
7351: }
7352: }
7353: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7354: '<span class="LC_nobreak">'.$titles{'copyright'}.
7355: '</span></td><td class="LC_right_item">'.
7356: &selectbox('copyright',$currrights{'copyright'},'',
7357: \&Apache::loncommon::copyrightdescription,
7358: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
7359: '</td></tr>'."\n";
7360: $itemcount ++;
7361: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7362: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7363: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
7364: '</span></td><td class="LC_right_item">'.
7365: &selectbox('sourceavail',$currrights{'sourceavail'},'',
7366: \&Apache::loncommon::source_copyrightdescription,
7367: (&Apache::loncommon::source_copyrightids)).
7368: '</td></tr>'."\n";
7369: } else {
7370: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7371: my $curreditors;
7372: my %staticdefaults = (
7373: editors => ['edit','xml'],
7374: authorquota => 500,
7375: webdav => 0,
7376: );
7377: my $curreditors = $staticdefaults{'editors'};
7378: if ((ref($settings) eq 'HASH') &&
7379: (ref($settings->{'editors'}) eq 'ARRAY')) {
7380: $curreditors = $settings->{'editors'};
7381: } else {
7382: $curreditors = $staticdefaults{'editors'};
7383: }
7384: my @editors = ('edit','xml','daxe');
7385: $datatable = '<tr'.$css_class.'>'."\n".
7386: '<td>'.$titles{'editors'}.'</td>'."\n".
7387: '<td class="LC_left_item">'."\n".
7388: '<span class="LC_nobreak">';
7389: foreach my $editor (@editors) {
7390: my $checked;
7391: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
7392: $checked = ' checked="checked"';
7393: }
7394: $datatable .= '<label>'.
7395: '<input type="checkbox" name="author_editors" '.
7396: $checked.' value="'.$editor.'" '.
7397: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
7398: $titles{$editor}.'</label> ';
7399: }
7400: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
7401: $itemcount ++;
7402: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7403: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7404: my @insttypes;
7405: if (ref($types) eq 'ARRAY') {
7406: @insttypes = @{$types};
7407: }
7408: my $typecount = 0;
7409: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
7410: my @items = ('webdav','authorquota');
7411: my %quotas;
7412: if (ref($domconf{'quotas'}) eq 'HASH') {
7413: %quotas = %{$domconf{'quotas'}};
7414: foreach my $item (@items) {
7415: if (ref($quotas{$item}) eq 'HASH') {
7416: foreach my $type (@insttypes,'default') {
7417: if ($item eq 'authorquota') {
7418: if ($quotas{$item}{$type} !~ /^\d+$/) {
7419: $quotas{$item}{$type} = $staticdefaults{$item};
7420: }
7421: } elsif ($item eq 'webdav') {
7422: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
7423: $quotas{$item}{$type} = $staticdefaults{$item};
7424: }
7425: }
7426: }
7427: } else {
7428: foreach my $type (@insttypes,'default') {
7429: $quotas{$item}{$type} = $staticdefaults{$item};
7430: }
7431: }
7432: }
7433: } else {
7434: foreach my $item (@items) {
7435: foreach my $type (@insttypes,'default') {
7436: $quotas{$item}{$type} = $staticdefaults{$item};
7437: }
7438: }
7439: }
7440: if (ref($usertypes) eq 'HASH') {
7441: my $numinrow = 4;
7442: my $onclick = '';
7443: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7444: $numinrow,$othertitle,'authorquota',
7445: \$itemcount,$onclick);
7446: $itemcount ++;
7447: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7448: $numinrow,$othertitle,'webdav',
7449: \$itemcount);
7450: $itemcount ++;
7451: }
7452: my $checkedno = ' checked="checked"';
7453: my ($checkedon,$checkedoff);
7454: if (ref($quotas{'webdav'}) eq 'HASH') {
1.436 raeburn 7455: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
1.429 raeburn 7456: if ($quotas{'webdav'}{'_LC_adv'}) {
7457: $checkedon = $checkedno;
7458: } else {
7459: $checkedoff = $checkedno;
7460: }
7461: undef($checkedno);
7462: }
7463: }
7464: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7465: $datatable .= '<tr'.$css_class.'>'.
7466: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
7467: $titles{'webdav_LC_adv_over'}.
7468: '</td>'.
7469: '<td class="LC_left_item">';
7470: foreach my $option ('none','off','on') {
7471: my ($text,$val,$checked);
7472: if ($option eq 'none') {
7473: $text = $titles{'none'};
7474: $val = '';
7475: $checked = $checkedno;
7476: } elsif ($option eq 'off') {
7477: $text = $titles{'overoff'};
7478: $val = 0;
7479: $checked = $checkedoff;
7480: } elsif ($option eq 'on') {
7481: $text = $titles{'overon'};
7482: $val = 1;
7483: $checked = $checkedon;
1.436 raeburn 7484: }
1.429 raeburn 7485: $datatable .= '<span class="LC_nobreak"><label>'.
7486: '<input type="radio" name="webdav_LC_adv"'.
7487: ' value="'.$val.'"'.$checked.' />'.
7488: $text.'</label></span> ';
7489: }
7490: $datatable .= '</td></tr>';
7491: $itemcount ++;
1.440 raeburn 7492: my %defchecked = (
7493: 'archive' => 'off',
7494: );
7495: my @toggles = ('archive');
7496: (my $archive,$itemcount) = &radiobutton_prefs($settings,['archive'],
7497: {'archive' => 'off'},
7498: \%titles,$itemcount);
7499: $datatable .= $archive."\n";
7500: $itemcount ++;
1.429 raeburn 7501: }
7502: $$rowtotal += $itemcount;
7503: return $datatable;
7504: }
7505:
7506: sub authordefaults_titles {
7507: return &Apache::lonlocal::texthash(
7508: copyright => 'Copyright/Distribution',
7509: sourceavail => ' Source Available',
7510: editors => 'Available Editors',
7511: webdav => 'WebDAV',
7512: authorquota => 'Authoring Space quotas (MB)',
7513: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
1.437 raeburn 7514: daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
1.429 raeburn 7515: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
7516: edit => 'Standard editor (Edit)',
7517: xml => 'Text editor (EditXML)',
7518: daxe => 'Daxe editor (Daxe)',
7519: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
7520: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
7521: none => 'No override set',
7522: overon => 'Override -- webDAV on',
1.436 raeburn 7523: overoff => 'Override -- webDAV off',
1.440 raeburn 7524: archive => 'Authors can download tar.gz file of Authoring Space',
1.429 raeburn 7525: );
7526: }
7527:
7528: sub selectbox {
7529: my ($name,$value,$readonly,$functionref,@idlist)=@_;
7530: my $selout = '<select name="'.$name.'">';
7531: foreach my $id (@idlist) {
7532: $selout.='<option value="'.$id.'"';
7533: if ($id eq $value) {
7534: $selout.=' selected="selected"';
7535: }
7536: if ($readonly) {
7537: $selout .= ' disabled="disabled"';
7538: }
7539: $selout.='>'.&{$functionref}($id).'</option>';
7540: }
7541: $selout.='</select>';
7542: return $selout;
7543: }
7544:
1.231 raeburn 7545: sub print_selfenrollment {
7546: my ($position,$dom,$settings,$rowtotal) = @_;
7547: my ($css_class,$datatable);
7548: my $itemcount = 1;
1.271 raeburn 7549: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7550: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7551: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7552: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7553: my @rows;
7554: my $key;
7555: if ($position eq 'top') {
7556: $key = 'admin';
7557: if (ref($rowsref) eq 'ARRAY') {
7558: @rows = @{$rowsref};
7559: }
7560: } elsif ($position eq 'middle') {
7561: $key = 'default';
7562: @rows = ('types','registered','approval','limit');
7563: }
7564: foreach my $row (@rows) {
7565: if (defined($titlesref->{$row})) {
7566: $itemcount ++;
7567: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7568: $datatable .= '<tr'.$css_class.'>'.
7569: '<td>'.$titlesref->{$row}.'</td>'.
7570: '<td class="LC_left_item">'.
7571: '<table><tr>';
7572: my (%current,%currentcap);
7573: if (ref($settings) eq 'HASH') {
7574: if (ref($settings->{$key}) eq 'HASH') {
7575: foreach my $type (@types) {
7576: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7577: $current{$type} = $settings->{$key}->{$type}->{$row};
7578: }
7579: if (($row eq 'limit') && ($key eq 'default')) {
7580: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7581: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7582: }
7583: }
7584: }
7585: }
7586: }
7587: my %roles = (
7588: '0' => &Apache::lonnet::plaintext('dc'),
7589: );
7590:
7591: foreach my $type (@types) {
7592: unless (($row eq 'registered') && ($key eq 'default')) {
7593: $datatable .= '<th>'.&mt($type).'</th>';
7594: }
7595: }
7596: unless (($row eq 'registered') && ($key eq 'default')) {
7597: $datatable .= '</tr><tr>';
7598: }
7599: foreach my $type (@types) {
7600: if ($type eq 'community') {
7601: $roles{'1'} = &mt('Community personnel');
7602: } else {
7603: $roles{'1'} = &mt('Course personnel');
7604: }
7605: $datatable .= '<td style="vertical-align: top">';
7606: if ($position eq 'top') {
7607: my %checked;
7608: if ($current{$type} eq '0') {
7609: $checked{'0'} = ' checked="checked"';
7610: } else {
7611: $checked{'1'} = ' checked="checked"';
7612: }
7613: foreach my $role ('1','0') {
7614: $datatable .= '<span class="LC_nobreak"><label>'.
7615: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7616: 'value="'.$role.'"'.$checked{$role}.' />'.
7617: $roles{$role}.'</label></span> ';
7618: }
7619: } else {
7620: if ($row eq 'types') {
7621: my %checked;
7622: if ($current{$type} =~ /^(all|dom)$/) {
7623: $checked{$1} = ' checked="checked"';
7624: } else {
7625: $checked{''} = ' checked="checked"';
7626: }
7627: foreach my $val ('','dom','all') {
7628: $datatable .= '<span class="LC_nobreak"><label>'.
7629: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7630: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7631: }
7632: } elsif ($row eq 'registered') {
7633: my %checked;
7634: if ($current{$type} eq '1') {
7635: $checked{'1'} = ' checked="checked"';
7636: } else {
7637: $checked{'0'} = ' checked="checked"';
7638: }
7639: foreach my $val ('0','1') {
7640: $datatable .= '<span class="LC_nobreak"><label>'.
7641: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7642: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7643: }
7644: } elsif ($row eq 'approval') {
7645: my %checked;
7646: if ($current{$type} =~ /^([12])$/) {
7647: $checked{$1} = ' checked="checked"';
7648: } else {
7649: $checked{'0'} = ' checked="checked"';
7650: }
7651: for my $val (0..2) {
7652: $datatable .= '<span class="LC_nobreak"><label>'.
7653: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7654: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7655: }
7656: } elsif ($row eq 'limit') {
7657: my %checked;
7658: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7659: $checked{$1} = ' checked="checked"';
7660: } else {
7661: $checked{'none'} = ' checked="checked"';
7662: }
7663: my $cap;
7664: if ($currentcap{$type} =~ /^\d+$/) {
7665: $cap = $currentcap{$type};
7666: }
7667: foreach my $val ('none','allstudents','selfenrolled') {
7668: $datatable .= '<span class="LC_nobreak"><label>'.
7669: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7670: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7671: }
7672: $datatable .= '<br />'.
7673: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7674: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7675: '</span>';
7676: }
7677: }
7678: $datatable .= '</td>';
7679: }
7680: $datatable .= '</tr>';
7681: }
7682: $datatable .= '</table></td></tr>';
7683: }
7684: } elsif ($position eq 'bottom') {
1.235 raeburn 7685: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7686: }
7687: $$rowtotal += $itemcount;
7688: return $datatable;
7689: }
7690:
7691: sub print_validation_rows {
7692: my ($caller,$dom,$settings,$rowtotal) = @_;
7693: my ($itemsref,$namesref,$fieldsref);
7694: if ($caller eq 'selfenroll') {
7695: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7696: } elsif ($caller eq 'requestcourses') {
7697: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7698: }
7699: my %currvalidation;
7700: if (ref($settings) eq 'HASH') {
7701: if (ref($settings->{'validation'}) eq 'HASH') {
7702: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7703: }
1.235 raeburn 7704: }
7705: my $datatable;
7706: my $itemcount = 0;
7707: foreach my $item (@{$itemsref}) {
7708: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7709: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7710: $namesref->{$item}.
7711: '</span></td>'.
7712: '<td class="LC_left_item">';
7713: if (($item eq 'url') || ($item eq 'button')) {
7714: $datatable .= '<span class="LC_nobreak">'.
7715: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7716: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7717: } elsif ($item eq 'fields') {
7718: my @currfields;
7719: if (ref($currvalidation{$item}) eq 'ARRAY') {
7720: @currfields = @{$currvalidation{$item}};
7721: }
7722: foreach my $field (@{$fieldsref}) {
7723: my $check = '';
7724: if (grep(/^\Q$field\E$/,@currfields)) {
7725: $check = ' checked="checked"';
7726: }
7727: $datatable .= '<span class="LC_nobreak"><label>'.
7728: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7729: ' value="'.$field.'"'.$check.' />'.$field.
7730: '</label></span> ';
7731: }
7732: } elsif ($item eq 'markup') {
1.334 raeburn 7733: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7734: $currvalidation{$item}.
1.231 raeburn 7735: '</textarea>';
1.235 raeburn 7736: }
7737: $datatable .= '</td></tr>'."\n";
7738: if (ref($rowtotal)) {
1.231 raeburn 7739: $itemcount ++;
7740: }
7741: }
1.235 raeburn 7742: if ($caller eq 'requestcourses') {
7743: my %currhash;
1.248 raeburn 7744: if (ref($settings) eq 'HASH') {
7745: if (ref($settings->{'validation'}) eq 'HASH') {
7746: if ($settings->{'validation'}{'dc'} ne '') {
7747: $currhash{$settings->{'validation'}{'dc'}} = 1;
7748: }
1.235 raeburn 7749: }
7750: }
7751: my $numinrow = 2;
7752: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7753: 'validationdc',%currhash);
1.247 raeburn 7754: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7755: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7756: if ($numdc > 1) {
1.247 raeburn 7757: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7758: } else {
1.247 raeburn 7759: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7760: }
1.247 raeburn 7761: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7762: $itemcount ++;
7763: }
7764: if (ref($rowtotal)) {
7765: $$rowtotal += $itemcount;
7766: }
1.231 raeburn 7767: return $datatable;
7768: }
7769:
1.357 raeburn 7770: sub print_privacy {
7771: my ($position,$dom,$settings,$rowtotal) = @_;
7772: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7773: my $itemcount = 0;
1.417 raeburn 7774: if ($position eq 'top') {
7775: $numinrow = 2;
7776: } else {
1.357 raeburn 7777: @items = ('domain','author','course','community');
7778: %names = &Apache::lonlocal::texthash (
7779: domain => 'Assigned domain role(s)',
7780: author => 'Assigned co-author role(s)',
7781: course => 'Assigned course role(s)',
1.416 raeburn 7782: community => 'Assigned community role(s)',
1.357 raeburn 7783: );
7784: $numinrow = 4;
7785: ($othertitle,$usertypes,$types) =
7786: &Apache::loncommon::sorted_inst_types($dom);
7787: }
1.447.2.4 raeburn 7788: if (($position eq 'top') || ($position eq 'bottom')) {
1.357 raeburn 7789: my (%by_ip,%by_location,@intdoms,@instdoms);
7790: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7791: if ($position eq 'top') {
7792: my %curr;
7793: my @options = ('none','user','domain','auto');
7794: my %titles = &Apache::lonlocal::texthash (
7795: none => 'Not allowed',
7796: user => 'User authorizes',
7797: domain => 'DC authorizes',
7798: auto => 'Unrestricted',
7799: instdom => 'Other domain shares institution/provider',
7800: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7801: notify => 'Notify when role needs authorization',
1.357 raeburn 7802: );
7803: my %names = &Apache::lonlocal::texthash (
7804: domain => 'Domain role',
7805: author => 'Co-author role',
7806: course => 'Course role',
7807: community => 'Community role',
7808: );
7809: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7810: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7811: foreach my $domtype ('instdom','extdom') {
7812: my (%checked,$skip);
7813: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7814: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7815: '<td class="LC_left_item">';
7816: if ($domtype eq 'instdom') {
7817: unless (@instdoms > 1) {
7818: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7819: $skip = 1;
7820: }
7821: } elsif ($domtype eq 'extdom') {
7822: if (keys(%by_location) == 0) {
7823: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7824: $skip = 1;
7825: }
7826: }
7827: unless ($skip) {
7828: foreach my $roletype ('domain','author','course','community') {
7829: $checked{'auto'} = ' checked="checked"';
7830: if (ref($settings) eq 'HASH') {
7831: if (ref($settings->{approval}) eq 'HASH') {
7832: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7833: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7834: $checked{$1} = ' checked="checked"';
7835: $checked{'auto'} = '';
7836: }
7837: }
7838: }
7839: }
7840: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7841: foreach my $option (@options) {
7842: $datatable .= '<span class="LC_nobreak"><label>'.
7843: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7844: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7845: '</label></span> ';
7846: }
7847: $datatable .= '</fieldset>';
7848: }
7849: }
7850: $datatable .= '</td></tr>';
7851: $itemcount ++;
7852: }
1.417 raeburn 7853: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7854: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7855: '<td class="LC_left_item">';
7856: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7857: my %curr;
7858: if (ref($settings) eq 'HASH') {
7859: if ($settings->{'notify'} ne '') {
7860: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7861: }
7862: }
7863: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7864: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7865: 'privacy_notify',%curr);
7866: if ($numdc > 0) {
7867: $datatable .= $table;
7868: } else {
7869: $datatable .= &mt('There are no active Domain Coordinators');
7870: }
7871: } else {
7872: $datatable .= &mt('Nothing to set here, as there are no other domains');
7873: }
7874: $datatable .='</td></tr>';
1.447.2.4 raeburn 7875: } elsif ($position eq 'bottom') {
1.357 raeburn 7876: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7877: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7878: foreach my $item (@{$types}) {
7879: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7880: $numinrow,$itemcount,'','','','','',
7881: '',$usertypes->{$item});
7882: $itemcount ++;
7883: }
7884: }
7885: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7886: $numinrow,$itemcount,'','','','','',
7887: '',$othertitle);
7888: $itemcount ++;
7889: } else {
1.360 raeburn 7890: my (@insttypes,%insttitles);
7891: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7892: @insttypes = @{$types};
7893: %insttitles = %{$usertypes};
7894: }
7895: foreach my $item (@insttypes,'default') {
7896: my $title;
7897: if ($item eq 'default') {
7898: $title = $othertitle;
7899: } else {
7900: $title = $insttitles{$item};
7901: }
7902: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7903: $datatable .= '<tr'.$css_class.'>'.
7904: '<td class="LC_left_item">'.$title.'</td>'.
7905: '<td class="LC_left_item">'.
7906: &mt('Nothing to set here, as there are no other domains').
7907: '</td></tr>';
7908: $itemcount ++;
7909: }
1.357 raeburn 7910: }
7911: }
7912: }
7913: if (ref($rowtotal)) {
7914: $$rowtotal += $itemcount;
7915: }
7916: return $datatable;
7917: }
7918:
1.354 raeburn 7919: sub print_passwords {
7920: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7921: my ($datatable,$css_class);
7922: my $itemcount = 0;
7923: my %titles = &Apache::lonlocal::texthash (
7924: captcha => '"Forgot Password" CAPTCHA validation',
7925: link => 'Reset link expiration (hours)',
7926: case => 'Case-sensitive usernames/e-mail',
7927: prelink => 'Information required (form 1)',
7928: postlink => 'Information required (form 2)',
7929: emailsrc => 'LON-CAPA e-mail address type(s)',
7930: customtext => 'Domain specific text (HTML)',
7931: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7932: intauth_check => 'Check bcrypt cost if authenticated',
7933: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7934: permanent => 'Permanent e-mail address',
7935: critical => 'Critical notification address',
7936: notify => 'Notification address',
7937: min => 'Minimum password length',
7938: max => 'Maximum password length',
7939: chars => 'Required characters',
1.356 raeburn 7940: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7941: );
7942: if ($position eq 'top') {
7943: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7944: my $shownlinklife = 2;
7945: my $prelink = 'both';
7946: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7947: if (ref($settings) eq 'HASH') {
7948: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7949: $shownlinklife = $settings->{resetlink};
7950: }
7951: if (ref($settings->{resetcase}) eq 'ARRAY') {
7952: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7953: }
7954: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7955: $prelink = $settings->{resetprelink};
7956: }
7957: if (ref($settings->{resetpostlink}) eq 'HASH') {
7958: %postlink = %{$settings->{resetpostlink}};
7959: }
7960: if (ref($settings->{resetemail}) eq 'ARRAY') {
7961: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7962: }
7963: if ($settings->{resetremove}) {
7964: $nostdtext = 1;
7965: }
7966: if ($settings->{resetcustom}) {
7967: $customurl = $settings->{resetcustom};
7968: }
7969: } else {
7970: if (ref($types) eq 'ARRAY') {
7971: foreach my $item (@{$types}) {
7972: $casesens{$item} = 1;
7973: $postlink{$item} = ['username','email'];
7974: }
7975: }
7976: $casesens{'default'} = 1;
7977: $postlink{'default'} = ['username','email'];
7978: $prelink = 'both';
7979: %emailsrc = (
7980: permanent => 1,
7981: critical => 1,
7982: notify => 1,
7983: );
7984: }
7985: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7986: $itemcount ++;
7987: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7988: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7989: '<td class="LC_left_item">'.
7990: '<input type="textbox" value="'.$shownlinklife.'" '.
7991: 'name="passwords_link" size="3" /></td></tr>';
7992: $itemcount ++;
7993: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7994: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7995: '<td class="LC_left_item">';
7996: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7997: foreach my $item (@{$types}) {
7998: my $checkedcase;
7999: if ($casesens{$item}) {
8000: $checkedcase = ' checked="checked"';
8001: }
8002: $datatable .= '<span class="LC_nobreak"><label>'.
8003: '<input type="checkbox" name="passwords_case_sensitive" value="'.
8004: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 8005: '</span> ';
1.354 raeburn 8006: }
8007: }
8008: my $checkedcase;
8009: if ($casesens{'default'}) {
8010: $checkedcase = ' checked="checked"';
8011: }
8012: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8013: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
8014: $othertitle.'</label></span></td>';
8015: $itemcount ++;
8016: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8017: my %checkedpre = (
8018: both => ' checked="checked"',
8019: either => '',
8020: );
8021: if ($prelink eq 'either') {
8022: $checkedpre{either} = ' checked="checked"';
8023: $checkedpre{both} = '';
8024: }
8025: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
8026: '<td class="LC_left_item"><span class="LC_nobreak">'.
8027: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
8028: &mt('Both username and e-mail address').'</label></span> '.
8029: '<span class="LC_nobreak"><label>'.
8030: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
8031: &mt('Either username or e-mail address').'</label></span></td></tr>';
8032: $itemcount ++;
8033: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8034: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
8035: '<td class="LC_left_item">';
8036: my %postlinked;
8037: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8038: foreach my $item (@{$types}) {
8039: undef(%postlinked);
8040: $datatable .= '<fieldset style="display: inline-block;">'.
8041: '<legend>'.$usertypes->{$item}.'</legend>';
8042: if (ref($postlink{$item}) eq 'ARRAY') {
8043: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
8044: }
8045: foreach my $field ('email','username') {
8046: my $checked;
8047: if ($postlinked{$field}) {
8048: $checked = ' checked="checked"';
8049: }
8050: $datatable .= '<span class="LC_nobreak"><label>'.
8051: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
8052: $field.'"'.$checked.' />'.$field.'</label>'.
8053: '<span> ';
8054: }
8055: $datatable .= '</fieldset>';
8056: }
8057: }
8058: if (ref($postlink{'default'}) eq 'ARRAY') {
8059: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
8060: }
8061: $datatable .= '<fieldset style="display: inline-block;">'.
8062: '<legend>'.$othertitle.'</legend>';
8063: foreach my $field ('email','username') {
8064: my $checked;
8065: if ($postlinked{$field}) {
8066: $checked = ' checked="checked"';
8067: }
8068: $datatable .= '<span class="LC_nobreak"><label>'.
8069: '<input type="checkbox" name="passwords_postlink_default" value="'.
8070: $field.'"'.$checked.' />'.$field.'</label>'.
8071: '<span> ';
8072: }
8073: $datatable .= '</fieldset></td></tr>';
8074: $itemcount ++;
8075: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8076: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
8077: '<td class="LC_left_item">';
8078: foreach my $type ('permanent','critical','notify') {
8079: my $checkedemail;
8080: if ($emailsrc{$type}) {
8081: $checkedemail = ' checked="checked"';
8082: }
8083: $datatable .= '<span class="LC_nobreak"><label>'.
8084: '<input type="checkbox" name="passwords_emailsrc" value="'.
8085: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8086: '<span> ';
8087: }
8088: $datatable .= '</td></tr>';
8089: $itemcount ++;
8090: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8091: my $switchserver = &check_switchserver($dom,$confname);
8092: my ($showstd,$noshowstd);
8093: if ($nostdtext) {
8094: $noshowstd = ' checked="checked"';
8095: } else {
8096: $showstd = ' checked="checked"';
8097: }
8098: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8099: '<td class="LC_left_item"><span class="LC_nobreak">'.
8100: &mt('Retain standard text:').
8101: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8102: &mt('Yes').'</label>'.' '.
8103: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8104: &mt('No').'</label></span><br />'.
8105: '<span class="LC_fontsize_small">'.
8106: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8107: &mt('Include custom text:');
8108: if ($customurl) {
1.369 raeburn 8109: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8110: undef,undef,undef,undef,'background-color:#ffffff');
8111: $datatable .= '<span class="LC_nobreak"> '.$link.
8112: '<label><input type="checkbox" name="passwords_custom_del"'.
8113: ' value="1" />'.&mt('Delete?').'</label></span>'.
8114: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8115: }
8116: if ($switchserver) {
8117: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8118: } else {
8119: $datatable .='<span class="LC_nobreak"> '.
8120: '<input type="file" name="passwords_customfile" /></span>';
8121: }
8122: $datatable .= '</td></tr>';
8123: } elsif ($position eq 'middle') {
8124: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8125: my @items = ('intauth_cost','intauth_check','intauth_switch');
8126: my %defaults;
8127: if (ref($domconf{'defaults'}) eq 'HASH') {
8128: %defaults = %{$domconf{'defaults'}};
8129: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8130: $defaults{'intauth_cost'} = 10;
8131: }
8132: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8133: $defaults{'intauth_check'} = 0;
8134: }
8135: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8136: $defaults{'intauth_switch'} = 0;
8137: }
8138: } else {
8139: %defaults = (
8140: 'intauth_cost' => 10,
8141: 'intauth_check' => 0,
8142: 'intauth_switch' => 0,
8143: );
8144: }
8145: foreach my $item (@items) {
8146: if ($itemcount%2) {
8147: $css_class = '';
8148: } else {
8149: $css_class = ' class="LC_odd_row" ';
8150: }
8151: $datatable .= '<tr'.$css_class.'>'.
8152: '<td><span class="LC_nobreak">'.$titles{$item}.
8153: '</span></td><td class="LC_left_item" colspan="3">';
8154: if ($item eq 'intauth_switch') {
8155: my @options = (0,1,2);
8156: my %optiondesc = &Apache::lonlocal::texthash (
8157: 0 => 'No',
8158: 1 => 'Yes',
8159: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8160: );
8161: $datatable .= '<table width="100%">';
8162: foreach my $option (@options) {
8163: my $checked = ' ';
8164: if ($defaults{$item} eq $option) {
8165: $checked = ' checked="checked"';
8166: }
8167: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8168: '<label><input type="radio" name="'.$item.
8169: '" value="'.$option.'"'.$checked.' />'.
8170: $optiondesc{$option}.'</label></span></td></tr>';
8171: }
8172: $datatable .= '</table>';
8173: } elsif ($item eq 'intauth_check') {
8174: my @options = (0,1,2);
8175: my %optiondesc = &Apache::lonlocal::texthash (
8176: 0 => 'No',
8177: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8178: 2 => 'Yes, disallow login if stored cost is less than domain default',
8179: );
8180: $datatable .= '<table width="100%">';
8181: foreach my $option (@options) {
8182: my $checked = ' ';
8183: my $onclick;
8184: if ($defaults{$item} eq $option) {
8185: $checked = ' checked="checked"';
8186: }
8187: if ($option == 2) {
8188: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8189: }
8190: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8191: '<label><input type="radio" name="'.$item.
8192: '" value="'.$option.'"'.$checked.$onclick.' />'.
8193: $optiondesc{$option}.'</label></span></td></tr>';
8194: }
8195: $datatable .= '</table>';
8196: } else {
8197: $datatable .= '<input type="text" name="'.$item.'" value="'.
8198: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8199: }
8200: $datatable .= '</td></tr>';
8201: $itemcount ++;
8202: }
8203: } elsif ($position eq 'lower') {
1.405 raeburn 8204: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8205: } else {
1.359 raeburn 8206: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8207: my %ownerchg = (
8208: by => {},
8209: for => {},
8210: );
8211: my %ownertitles = &Apache::lonlocal::texthash (
8212: by => 'Course owner status(es) allowed',
8213: for => 'Student status(es) allowed',
8214: );
1.354 raeburn 8215: if (ref($settings) eq 'HASH') {
1.359 raeburn 8216: if (ref($settings->{crsownerchg}) eq 'HASH') {
8217: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8218: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8219: }
8220: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8221: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8222: }
1.354 raeburn 8223: }
8224: }
8225: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8226: $datatable .= '<tr '.$css_class.'>'.
8227: '<td>'.
8228: &mt('Requirements').'<ul>'.
1.359 raeburn 8229: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8230: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8231: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8232: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8233: '</ul>'.
8234: '</td>'.
1.359 raeburn 8235: '<td class="LC_left_item">';
8236: foreach my $item ('by','for') {
8237: $datatable .= '<fieldset style="display: inline-block;">'.
8238: '<legend>'.$ownertitles{$item}.'</legend>';
8239: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8240: foreach my $type (@{$types}) {
8241: my $checked;
8242: if ($ownerchg{$item}{$type}) {
8243: $checked = ' checked="checked"';
8244: }
8245: $datatable .= '<span class="LC_nobreak"><label>'.
8246: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8247: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8248: '</span> ';
1.359 raeburn 8249: }
8250: }
8251: my $checked;
8252: if ($ownerchg{$item}{'default'}) {
8253: $checked = ' checked="checked"';
8254: }
8255: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8256: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8257: $othertitle.'</label></span></fieldset>';
8258: }
8259: $datatable .= '</td></tr>';
1.354 raeburn 8260: }
8261: return $datatable;
8262: }
8263:
1.405 raeburn 8264: sub password_rules {
8265: my ($prefix,$itemcountref,$settings) = @_;
1.447.2.5! raeburn 8266: my ($min,$max,%chars,$numsaved,$numinrow);
1.405 raeburn 8267: my %titles;
8268: if ($prefix eq 'passwords') {
8269: %titles = &Apache::lonlocal::texthash (
8270: min => 'Minimum password length',
8271: max => 'Maximum password length',
8272: chars => 'Required characters',
8273: );
1.421 raeburn 8274: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8275: %titles = &Apache::lonlocal::texthash (
8276: min => 'Minimum secret length',
8277: max => 'Maximum secret length',
8278: chars => 'Required characters',
8279: );
8280: }
8281: $min = $Apache::lonnet::passwdmin;
8282: my $datatable;
8283: my $itemcount;
8284: if (ref($itemcountref)) {
8285: $itemcount = $$itemcountref;
8286: }
8287: if (ref($settings) eq 'HASH') {
8288: if ($settings->{min}) {
8289: $min = $settings->{min};
8290: }
8291: if ($settings->{max}) {
8292: $max = $settings->{max};
8293: }
8294: if (ref($settings->{chars}) eq 'ARRAY') {
8295: map { $chars{$_} = 1; } (@{$settings->{chars}});
8296: }
1.425 raeburn 8297: if ($prefix eq 'passwords') {
1.405 raeburn 8298: if ($settings->{numsaved}) {
8299: $numsaved = $settings->{numsaved};
8300: }
8301: }
8302: }
8303: my %rulenames = &Apache::lonlocal::texthash(
8304: uc => 'At least one upper case letter',
8305: lc => 'At least one lower case letter',
8306: num => 'At least one number',
8307: spec => 'At least one non-alphanumeric',
8308: );
8309: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8310: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8311: '<td class="LC_left_item"><span class="LC_nobreak">'.
8312: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8313: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8314: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8315: '</span></td></tr>';
8316: $itemcount ++;
8317: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8318: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8319: '<td class="LC_left_item"><span class="LC_nobreak">'.
8320: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8321: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8322: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8323: '</span></td></tr>';
8324: $itemcount ++;
8325: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8326: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8327: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8328: '</span></td>';
8329: my $numinrow = 2;
8330: my @possrules = ('uc','lc','num','spec');
8331: $datatable .= '<td class="LC_left_item"><table>';
8332: for (my $i=0; $i<@possrules; $i++) {
8333: my ($rem,$checked);
8334: if ($chars{$possrules[$i]}) {
8335: $checked = ' checked="checked"';
8336: }
8337: $rem = $i%($numinrow);
8338: if ($rem == 0) {
8339: if ($i > 0) {
8340: $datatable .= '</tr>';
8341: }
8342: $datatable .= '<tr>';
8343: }
8344: $datatable .= '<td><span class="LC_nobreak"><label>'.
8345: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8346: $rulenames{$possrules[$i]}.'</label></span></td>';
8347: }
8348: my $rem = @possrules%($numinrow);
8349: my $colsleft = $numinrow - $rem;
8350: if ($colsleft > 1 ) {
8351: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8352: ' </td>';
8353: } elsif ($colsleft == 1) {
8354: $datatable .= '<td class="LC_left_item"> </td>';
8355: }
8356: $datatable .='</table></td></tr>';
8357: $itemcount ++;
8358: if ($prefix eq 'passwords') {
8359: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8360: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8361: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8362: '<td class="LC_left_item"><span class="LC_nobreak">'.
8363: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8364: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8365: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8366: '</span></td></tr>';
8367: $itemcount ++;
8368: }
8369: if (ref($itemcountref)) {
8370: $$itemcountref += $itemcount;
8371: }
8372: return $datatable;
8373: }
8374:
1.373 raeburn 8375: sub print_wafproxy {
8376: my ($position,$dom,$settings,$rowtotal) = @_;
8377: my $css_class;
8378: my $itemcount = 0;
8379: my $datatable;
8380: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8381: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8382: my %lt = &wafproxy_titles();
1.373 raeburn 8383: foreach my $server (sort(keys(%servers))) {
8384: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8385: next if ($serverhome eq '');
1.373 raeburn 8386: my $serverdom;
8387: if ($serverhome ne $server) {
8388: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8389: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8390: $othercontrol{$server} = $serverdom;
8391: }
1.373 raeburn 8392: } else {
8393: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8394: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8395: if ($serverdom ne $dom) {
8396: $othercontrol{$server} = $serverdom;
8397: } else {
8398: $setdom = 1;
8399: if (ref($settings) eq 'HASH') {
8400: if (ref($settings->{'alias'}) eq 'HASH') {
8401: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8402: if ($aliases{$dom} ne '') {
8403: $showdom = 1;
8404: }
1.373 raeburn 8405: }
1.388 raeburn 8406: if (ref($settings->{'saml'}) eq 'HASH') {
8407: $saml{$dom} = $settings->{'saml'};
8408: }
1.373 raeburn 8409: }
8410: }
8411: }
8412: }
1.381 raeburn 8413: if ($setdom) {
8414: %{$values{$dom}} = ();
8415: if (ref($settings) eq 'HASH') {
8416: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8417: $values{$dom}{$item} = $settings->{$item};
8418: }
8419: }
8420: }
1.373 raeburn 8421: if (keys(%othercontrol)) {
8422: %otherdoms = reverse(%othercontrol);
8423: foreach my $domain (keys(%otherdoms)) {
8424: %{$values{$domain}} = ();
8425: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8426: if (ref($config{'wafproxy'}) eq 'HASH') {
8427: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8428: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8429: $saml{$domain} = $config{'wafproxy'}{'saml'};
8430: }
1.383 raeburn 8431: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8432: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8433: }
8434: }
8435: }
8436: }
8437: if ($position eq 'top') {
8438: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8439: my %aliasinfo;
1.373 raeburn 8440: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8441: $itemcount ++;
8442: my $dom_in_effect;
8443: my $aliasrows = '<tr>'.
1.383 raeburn 8444: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.433 raeburn 8445: &mt('Hostname').': '.
8446: '<span class="LC_nobreak LC_cusr_emph">'.
8447: &Apache::lonnet::hostname($server).
8448: '</span></td><td> </td>';
1.373 raeburn 8449: if ($othercontrol{$server}) {
1.381 raeburn 8450: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8451: my ($current,$forsaml);
1.383 raeburn 8452: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8453: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8454: }
1.388 raeburn 8455: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8456: if ($saml{$dom_in_effect}{$server}) {
8457: $forsaml = 1;
8458: }
8459: }
1.383 raeburn 8460: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8461: &mt('Alias').': ';
1.373 raeburn 8462: if ($current) {
1.381 raeburn 8463: $aliasrows .= $current;
1.388 raeburn 8464: if ($forsaml) {
1.396 raeburn 8465: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8466: }
1.373 raeburn 8467: } else {
1.383 raeburn 8468: $aliasrows .= &mt('None');
1.373 raeburn 8469: }
1.383 raeburn 8470: $aliasrows .= ' <span class="LC_small">('.
8471: &mt('controlled by domain: [_1]',
8472: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8473: } else {
1.381 raeburn 8474: $dom_in_effect = $dom;
1.388 raeburn 8475: my ($current,$samlon,$samloff);
8476: $samloff = ' checked="checked"';
1.373 raeburn 8477: if (ref($aliases{$dom}) eq 'HASH') {
8478: if ($aliases{$dom}{$server}) {
8479: $current = $aliases{$dom}{$server};
8480: }
8481: }
1.388 raeburn 8482: if (ref($saml{$dom}) eq 'HASH') {
8483: if ($saml{$dom}{$server}) {
8484: $samlon = $samloff;
8485: undef($samloff);
8486: }
8487: }
1.383 raeburn 8488: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8489: &mt('Alias').': '.
1.381 raeburn 8490: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8491: 'value="'.$current.'" size="30" />'.
8492: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8493: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8494: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8495: &mt('No').'</label> <label>'.
1.388 raeburn 8496: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8497: &mt('Yes').'</label></span>'.
1.425 raeburn 8498: '</td>';
1.381 raeburn 8499: }
8500: $aliasrows .= '</tr>';
8501: $aliasinfo{$dom_in_effect} .= $aliasrows;
8502: }
8503: if ($aliasinfo{$dom}) {
8504: my ($onclick,$wafon,$wafoff,$showtable);
8505: $onclick = ' onclick="javascript:toggleWAF();"';
8506: $wafoff = ' checked="checked"';
8507: $showtable = ' style="display:none";';
8508: if ($showdom) {
8509: $wafon = $wafoff;
8510: $wafoff = '';
8511: $showtable = ' style="display:inline;"';
8512: }
8513: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8514: $datatable = '<tr'.$css_class.'>'.
8515: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8516: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8517: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8518: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8519: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8520: &mt('No').'</label></span></td>'.
8521: '<td class="LC_left_item">'.
8522: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8523: '</table></td></tr>';
8524: $itemcount++;
8525: }
1.383 raeburn 8526: if (keys(%otherdoms)) {
8527: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8528: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8529: $datatable .= '<tr'.$css_class.'>'.
8530: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8531: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8532: '</table></td></tr>';
1.381 raeburn 8533: $itemcount++;
1.373 raeburn 8534: }
8535: }
8536: } else {
1.383 raeburn 8537: my %ip_methods = &remoteip_methods();
1.373 raeburn 8538: if ($setdom) {
8539: $itemcount ++;
8540: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8541: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8542: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8543: $wafstyle = ' style="display:none;"';
8544: $nowafstyle = ' style="display:table-row;"';
8545: $currwafdisplay = ' style="display: none"';
8546: $wafrangestyle = ' style="display: none"';
8547: $curr_remotip = 'n';
1.382 raeburn 8548: $ssltossl = ' checked="checked"';
1.381 raeburn 8549: if ($showdom) {
8550: $wafstyle = ' style="display:table-row;"';
8551: $nowafstyle = ' style="display:none;"';
8552: if (keys(%{$values{$dom}})) {
8553: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8554: $curr_remotip = $values{$dom}{remoteip};
8555: }
8556: if ($curr_remotip eq 'h') {
8557: $currwafdisplay = ' style="display:table-row"';
8558: $wafrangestyle = ' style="display:inline-block;"';
8559: }
1.382 raeburn 8560: if ($values{$dom}{'sslopt'}) {
8561: $alltossl = ' checked="checked"';
8562: $ssltossl = '';
8563: }
1.381 raeburn 8564: }
8565: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8566: $vpndircheck = ' checked="checked"';
8567: $currwafvpn = ' style="display:table-row;"';
8568: $wafrangestyle = ' style="display:inline-block;"';
8569: } else {
8570: $vpnaliascheck = ' checked="checked"';
8571: $currwafvpn = ' style="display:none;"';
8572: }
8573: }
8574: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8575: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8576: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8577: '</tr>'.
8578: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8579: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8580: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8581: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8582: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8583: '<td class="LC_left_item"><table>'.
8584: '<tr>'.
8585: '<td valign="top">'.$lt{'remoteip'}.': '.
8586: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8587: foreach my $option ('m','h','n') {
8588: my $sel;
8589: if ($option eq $curr_remotip) {
8590: $sel = ' selected="selected"';
8591: }
8592: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8593: $ip_methods{$option}.'</option>';
8594: }
8595: $datatable .= '</select></td></tr>'."\n".
8596: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8597: $lt{'ipheader'}.': '.
8598: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8599: 'name="wafproxy_ipheader" />'.
8600: '</td></tr>'."\n".
8601: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8602: $lt{'trusted'}.':<br />'.
1.381 raeburn 8603: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8604: $values{$dom}{'trusted'}.'</textarea>'.
8605: '</td></tr>'."\n".
8606: '<tr><td><hr /></td></tr>'."\n".
8607: '<tr>'.
8608: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8609: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8610: $lt{'vpndirect'}.'</label>'.(' 'x2).
8611: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8612: $lt{'vpnaliased'}.'</label></span></td></tr>';
8613: foreach my $item ('vpnint','vpnext') {
8614: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8615: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8616: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8617: $values{$dom}{$item}.'</textarea>'.
8618: '</td></tr>'."\n";
1.373 raeburn 8619: }
1.382 raeburn 8620: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8621: '<tr>'.
8622: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8623: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8624: $lt{'alltossl'}.'</label>'.(' 'x2).
8625: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8626: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8627: '</table></td></tr>';
1.373 raeburn 8628: }
8629: if (keys(%otherdoms)) {
8630: foreach my $domain (sort(keys(%otherdoms))) {
8631: $itemcount ++;
8632: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8633: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8634: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8635: '<td class="LC_left_item"><table>';
1.382 raeburn 8636: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8637: my $showval = &mt('None');
1.382 raeburn 8638: if ($item eq 'ssl') {
8639: $showval = $lt{'ssltossl'};
8640: }
1.373 raeburn 8641: if ($values{$domain}{$item}) {
1.381 raeburn 8642: $showval = $values{$domain}{$item};
1.382 raeburn 8643: if ($item eq 'ssl') {
8644: $showval = $lt{'alltossl'};
1.383 raeburn 8645: } elsif ($item eq 'remoteip') {
8646: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8647: }
1.373 raeburn 8648: }
8649: $datatable .= '<tr>'.
8650: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8651: }
1.381 raeburn 8652: $datatable .= '</table></td></tr>';
1.373 raeburn 8653: }
8654: }
8655: }
8656: $$rowtotal += $itemcount;
8657: return $datatable;
8658: }
8659:
8660: sub wafproxy_titles {
8661: return &Apache::lonlocal::texthash(
1.381 raeburn 8662: remoteip => "Method for determining user's IP",
8663: ipheader => 'Request header containing remote IP',
8664: trusted => 'Trusted IP range(s)',
8665: vpnaccess => 'Access from institutional VPN',
8666: vpndirect => 'via regular hostname (no WAF)',
8667: vpnaliased => 'via aliased hostname (WAF)',
8668: vpnint => 'Internal IP Range(s) for VPN sessions',
8669: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8670: sslopt => 'Forwarding http/https',
1.381 raeburn 8671: alltossl => 'WAF forwards both http and https requests to https',
8672: ssltossl => 'WAF forwards http requests to http and https to https',
8673: );
8674: }
8675:
8676: sub remoteip_methods {
8677: return &Apache::lonlocal::texthash(
8678: m => 'Use Apache mod_remoteip',
8679: h => 'Use headers parsed by LON-CAPA',
8680: n => 'Not in use',
1.373 raeburn 8681: );
8682: }
8683:
1.137 raeburn 8684: sub print_usersessions {
8685: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8686: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8687: my (%by_ip,%by_location,@intdoms,@instdoms);
8688: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8689:
8690: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8691: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8692: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8693: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8694: if ($position eq 'top') {
1.152 raeburn 8695: if (keys(%serverhomes) > 1) {
1.145 raeburn 8696: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8697: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8698: if (ref($settings) eq 'HASH') {
8699: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8700: $curroffloadnow = $settings->{'offloadnow'};
8701: }
1.371 raeburn 8702: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8703: $curroffloadoth = $settings->{'offloadoth'};
8704: }
1.261 raeburn 8705: }
1.371 raeburn 8706: my $other_insts = scalar(keys(%by_location));
8707: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8708: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8709: } else {
1.140 raeburn 8710: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8711: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8712: '</td></tr>';
1.140 raeburn 8713: }
1.137 raeburn 8714: } else {
1.279 raeburn 8715: my %titles = &usersession_titles();
8716: my ($prefix,@types);
8717: if ($position eq 'bottom') {
8718: $prefix = 'remote';
8719: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8720: } else {
1.279 raeburn 8721: $prefix = 'hosted';
8722: @types = ('excludedomain','includedomain');
8723: }
8724: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8725: }
8726: $$rowtotal += $itemcount;
8727: return $datatable;
8728: }
8729:
8730: sub rules_by_location {
8731: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8732: my ($datatable,$itemcount,$css_class);
8733: if (keys(%{$by_location}) == 0) {
8734: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8735: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8736: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8737: '</td></tr>';
8738: $itemcount = 1;
8739: } else {
8740: $itemcount = 0;
8741: my $numinrow = 5;
8742: my (%current,%checkedon,%checkedoff);
8743: my @locations = sort(keys(%{$by_location}));
8744: foreach my $type (@{$types}) {
8745: $checkedon{$type} = '';
8746: $checkedoff{$type} = ' checked="checked"';
8747: }
8748: if (ref($settings) eq 'HASH') {
8749: if (ref($settings->{$prefix}) eq 'HASH') {
8750: foreach my $key (keys(%{$settings->{$prefix}})) {
8751: $current{$key} = $settings->{$prefix}{$key};
8752: if ($key eq 'version') {
8753: if ($current{$key} ne '') {
1.145 raeburn 8754: $checkedon{$key} = ' checked="checked"';
8755: $checkedoff{$key} = '';
8756: }
1.279 raeburn 8757: } elsif (ref($current{$key}) eq 'ARRAY') {
8758: $checkedon{$key} = ' checked="checked"';
8759: $checkedoff{$key} = '';
1.137 raeburn 8760: }
8761: }
8762: }
1.279 raeburn 8763: }
8764: foreach my $type (@{$types}) {
8765: next if ($type ne 'version' && !@locations);
8766: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8767: $datatable .= '<tr'.$css_class.'>
8768: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8769: <span class="LC_nobreak">
8770: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8771: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8772: if ($type eq 'version') {
8773: my @lcversions = &Apache::lonnet::all_loncaparevs();
8774: my $selector = '<select name="'.$prefix.'_version">';
8775: foreach my $version (@lcversions) {
8776: my $selected = '';
8777: if ($current{'version'} eq $version) {
8778: $selected = ' selected="selected"';
1.145 raeburn 8779: }
1.279 raeburn 8780: $selector .= ' <option value="'.$version.'"'.
8781: $selected.'>'.$version.'</option>';
8782: }
8783: $selector .= '</select> ';
8784: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8785: } else {
8786: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8787: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8788: ' />'.(' 'x2).
8789: '<input type="button" value="'.&mt('uncheck all').'" '.
8790: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8791: "\n".
8792: '</div><div><table>';
8793: my $rem;
8794: for (my $i=0; $i<@locations; $i++) {
8795: my ($showloc,$value,$checkedtype);
8796: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8797: my $ip = $by_location->{$locations[$i]}->[0];
8798: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8799: $value = join(':',@{$by_ip->{$ip}});
8800: $showloc = join(', ',@{$by_ip->{$ip}});
8801: if (ref($current{$type}) eq 'ARRAY') {
8802: foreach my $loc (@{$by_ip->{$ip}}) {
8803: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8804: $checkedtype = ' checked="checked"';
8805: last;
1.145 raeburn 8806: }
1.138 raeburn 8807: }
8808: }
8809: }
1.137 raeburn 8810: }
1.279 raeburn 8811: $rem = $i%($numinrow);
8812: if ($rem == 0) {
8813: if ($i > 0) {
8814: $datatable .= '</tr>';
8815: }
8816: $datatable .= '<tr>';
8817: }
8818: $datatable .= '<td class="LC_left_item">'.
8819: '<span class="LC_nobreak"><label>'.
8820: '<input type="checkbox" name="'.$prefix.'_'.$type.
8821: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8822: '</label></span></td>';
8823: }
8824: $rem = @locations%($numinrow);
8825: my $colsleft = $numinrow - $rem;
8826: if ($colsleft > 1 ) {
8827: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8828: ' </td>';
8829: } elsif ($colsleft == 1) {
8830: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8831: }
1.279 raeburn 8832: $datatable .= '</tr></table>';
1.137 raeburn 8833: }
1.279 raeburn 8834: $datatable .= '</td></tr>';
8835: $itemcount ++;
1.137 raeburn 8836: }
8837: }
1.279 raeburn 8838: return ($datatable,$itemcount);
1.137 raeburn 8839: }
8840:
1.275 raeburn 8841: sub print_ssl {
8842: my ($position,$dom,$settings,$rowtotal) = @_;
8843: my ($css_class,$datatable);
8844: my $itemcount = 1;
8845: if ($position eq 'top') {
1.281 raeburn 8846: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8847: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8848: my $same_institution;
8849: if ($intdom ne '') {
8850: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8851: if (ref($internet_names) eq 'ARRAY') {
8852: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8853: $same_institution = 1;
8854: }
8855: }
8856: }
1.275 raeburn 8857: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8858: $datatable = '<tr'.$css_class.'><td colspan="2">';
8859: if ($same_institution) {
8860: my %domservers = &Apache::lonnet::get_servers($dom);
8861: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8862: } else {
8863: $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.");
8864: }
8865: $datatable .= '</td></tr>';
1.275 raeburn 8866: $itemcount ++;
8867: } else {
8868: my %titles = &ssl_titles();
8869: my (%by_ip,%by_location,@intdoms,@instdoms);
8870: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8871: my @alldoms = &Apache::lonnet::all_domains();
8872: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8873: my @domservers = &Apache::lonnet::get_servers($dom);
8874: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8875: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8876: if (($position eq 'connto') || ($position eq 'connfrom')) {
8877: my $legacy;
8878: unless (ref($settings) eq 'HASH') {
8879: my $name;
8880: if ($position eq 'connto') {
8881: $name = 'loncAllowInsecure';
8882: } else {
8883: $name = 'londAllowInsecure';
8884: }
8885: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8886: my @ids=&Apache::lonnet::current_machine_ids();
8887: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8888: my %what = (
8889: $name => 1,
8890: );
8891: my ($result,$returnhash) =
8892: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8893: if ($result eq 'ok') {
8894: if (ref($returnhash) eq 'HASH') {
8895: $legacy = $returnhash->{$name};
8896: }
8897: }
8898: } else {
8899: $legacy = $Apache::lonnet::perlvar{$name};
8900: }
8901: }
1.275 raeburn 8902: foreach my $type ('dom','intdom','other') {
8903: my %checked;
8904: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8905: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8906: '<td class="LC_right_item">';
8907: my $skip;
8908: if ($type eq 'dom') {
8909: unless (keys(%servers) > 1) {
8910: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8911: $skip = 1;
8912: }
8913: }
8914: if ($type eq 'intdom') {
8915: unless (@instdoms > 1) {
8916: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8917: $skip = 1;
8918: }
8919: } elsif ($type eq 'other') {
8920: if (keys(%by_location) == 0) {
8921: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8922: $skip = 1;
8923: }
8924: }
8925: unless ($skip) {
8926: $checked{'yes'} = ' checked="checked"';
8927: if (ref($settings) eq 'HASH') {
1.293 raeburn 8928: if (ref($settings->{$position}) eq 'HASH') {
8929: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8930: $checked{$1} = $checked{'yes'};
8931: delete($checked{'yes'});
8932: }
8933: }
1.293 raeburn 8934: } else {
8935: if ($legacy == 0) {
8936: $checked{'req'} = $checked{'yes'};
8937: delete($checked{'yes'});
8938: }
1.275 raeburn 8939: }
8940: foreach my $option ('no','yes','req') {
8941: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8942: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8943: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8944: '</label></span>'.(' 'x2);
8945: }
8946: }
8947: $datatable .= '</td></tr>';
8948: $itemcount ++;
8949: }
8950: } else {
8951: my $prefix = 'replication';
8952: my @types = ('certreq','nocertreq');
1.279 raeburn 8953: if (keys(%by_location) == 0) {
8954: $datatable .= '<tr'.$css_class.'><td>'.
8955: &mt('Nothing to set here, as there are no other institutions').
8956: '</td></tr>';
8957: $itemcount ++;
1.275 raeburn 8958: } else {
1.279 raeburn 8959: ($datatable,$itemcount) =
8960: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8961: }
8962: }
8963: }
8964: $$rowtotal += $itemcount;
8965: return $datatable;
8966: }
8967:
8968: sub ssl_titles {
8969: return &Apache::lonlocal::texthash (
8970: dom => 'LON-CAPA servers/VMs from same domain',
8971: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8972: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8973: connto => 'Connections to other servers',
8974: connfrom => 'Connections from other servers',
1.275 raeburn 8975: replication => 'Replicating content to other institutions',
8976: certreq => 'Client certificate required, but specific domains exempt',
8977: nocertreq => 'No client certificate required, except for specific domains',
8978: no => 'SSL not used',
8979: yes => 'SSL Optional (used if available)',
8980: req => 'SSL Required',
8981: );
1.279 raeburn 8982: }
8983:
8984: sub print_trust {
8985: my ($prefix,$dom,$settings,$rowtotal) = @_;
8986: my ($css_class,$datatable,%checked,%choices);
8987: my (%by_ip,%by_location,@intdoms,@instdoms);
8988: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8989: my $itemcount = 1;
8990: my %titles = &trust_titles();
8991: my @types = ('exc','inc');
8992: if ($prefix eq 'top') {
8993: $prefix = 'content';
8994: } elsif ($prefix eq 'bottom') {
8995: $prefix = 'msg';
8996: }
8997: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8998: $$rowtotal += $itemcount;
8999: return $datatable;
9000: }
9001:
9002: sub trust_titles {
9003: return &Apache::lonlocal::texthash(
9004: content => "Access to this domain's content by others",
9005: shared => "Access to other domain's content by this domain",
9006: enroll => "Enrollment in this domain's courses by others",
9007: othcoau => "Co-author roles in this domain for others",
9008: coaurem => "Co-author roles for this domain's users elsewhere",
9009: domroles => "Domain roles in this domain assignable to others",
9010: catalog => "Course Catalog for this domain displayed elsewhere",
9011: reqcrs => "Requests for creation of courses in this domain by others",
9012: msg => "Users in other domains can send messages to this domain",
9013: exc => "Allow all, but exclude specific domains",
9014: inc => "Deny all, but include specific domains",
9015: );
1.275 raeburn 9016: }
9017:
1.138 raeburn 9018: sub build_location_hashes {
1.275 raeburn 9019: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 9020: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 9021: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 9022: my %iphost = &Apache::lonnet::get_iphost();
9023: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
9024: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
9025: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
9026: foreach my $id (@{$iphost{$primary_ip}}) {
9027: my $intdom = &Apache::lonnet::internet_dom($id);
9028: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
9029: push(@{$intdoms},$intdom);
9030: }
9031: }
9032: }
9033: foreach my $ip (keys(%iphost)) {
9034: if (ref($iphost{$ip}) eq 'ARRAY') {
9035: foreach my $id (@{$iphost{$ip}}) {
9036: my $location = &Apache::lonnet::internet_dom($id);
9037: if ($location) {
1.275 raeburn 9038: if (grep(/^\Q$location\E$/,@{$intdoms})) {
9039: my $dom = &Apache::lonnet::host_domain($id);
9040: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
9041: push(@{$instdoms},$dom);
9042: }
9043: next;
9044: }
1.138 raeburn 9045: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9046: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
9047: push(@{$by_ip->{$ip}},$location);
9048: }
9049: } else {
9050: $by_ip->{$ip} = [$location];
9051: }
9052: }
9053: }
9054: }
9055: }
9056: foreach my $ip (sort(keys(%{$by_ip}))) {
9057: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9058: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
9059: my $first = $by_ip->{$ip}->[0];
9060: if (ref($by_location->{$first}) eq 'ARRAY') {
9061: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
9062: push(@{$by_location->{$first}},$ip);
9063: }
9064: } else {
9065: $by_location->{$first} = [$ip];
9066: }
9067: }
9068: }
9069: return;
9070: }
9071:
1.145 raeburn 9072: sub current_offloads_to {
9073: my ($dom,$settings,$servers) = @_;
9074: my (%spareid,%otherdomconfigs);
1.152 raeburn 9075: if (ref($servers) eq 'HASH') {
1.145 raeburn 9076: foreach my $lonhost (sort(keys(%{$servers}))) {
9077: my $gotspares;
1.152 raeburn 9078: if (ref($settings) eq 'HASH') {
9079: if (ref($settings->{'spares'}) eq 'HASH') {
9080: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9081: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9082: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9083: $gotspares = 1;
9084: }
1.145 raeburn 9085: }
9086: }
9087: unless ($gotspares) {
9088: my $gotspares;
9089: my $serverhomeID =
9090: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9091: my $serverhomedom =
9092: &Apache::lonnet::host_domain($serverhomeID);
9093: if ($serverhomedom ne $dom) {
9094: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9095: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9096: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9097: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9098: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9099: $gotspares = 1;
9100: }
9101: }
9102: } else {
9103: $otherdomconfigs{$serverhomedom} =
9104: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9105: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9106: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9107: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9108: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9109: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9110: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9111: $gotspares = 1;
9112: }
9113: }
9114: }
9115: }
9116: }
9117: }
9118: }
9119: unless ($gotspares) {
9120: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9121: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9122: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9123: } else {
9124: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9125: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9126: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9127: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9128: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9129: } else {
1.150 raeburn 9130: my %what = (
9131: spareid => 1,
9132: );
9133: my ($result,$returnhash) =
9134: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9135: if ($result eq 'ok') {
9136: if (ref($returnhash) eq 'HASH') {
9137: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9138: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9139: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9140: }
9141: }
1.145 raeburn 9142: }
9143: }
9144: }
9145: }
9146: }
9147: }
9148: return %spareid;
9149: }
9150:
9151: sub spares_row {
1.371 raeburn 9152: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9153: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9154: my $css_class;
9155: my $numinrow = 4;
9156: my $itemcount = 1;
9157: my $datatable;
1.152 raeburn 9158: my %typetitles = &sparestype_titles();
9159: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9160: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9161: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9162: my ($othercontrol,$serverdom);
9163: if ($serverhome ne $server) {
9164: $serverdom = &Apache::lonnet::host_domain($serverhome);
9165: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9166: } else {
9167: $serverdom = &Apache::lonnet::host_domain($server);
9168: if ($serverdom ne $dom) {
9169: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9170: }
9171: }
9172: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9173: my ($checkednow,$checkedoth);
1.261 raeburn 9174: if (ref($curroffloadnow) eq 'HASH') {
9175: if ($curroffloadnow->{$server}) {
9176: $checkednow = ' checked="checked"';
9177: }
9178: }
1.371 raeburn 9179: if (ref($curroffloadoth) eq 'HASH') {
9180: if ($curroffloadoth->{$server}) {
9181: $checkedoth = ' checked="checked"';
9182: }
9183: }
1.145 raeburn 9184: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9185: $datatable .= '<tr'.$css_class.'>
9186: <td rowspan="2">
1.183 bisitz 9187: <span class="LC_nobreak">'.
9188: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9189: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9190: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9191: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9192: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9193: "\n";
1.371 raeburn 9194: if ($other_insts) {
9195: $datatable .= '<br />'.
9196: '<span class="LC_nobreak">'."\n".
9197: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9198: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9199: "\n";
9200: }
1.145 raeburn 9201: my (%current,%canselect);
1.152 raeburn 9202: my @choices =
9203: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9204: foreach my $type ('primary','default') {
9205: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9206: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9207: my @spares = @{$spareid->{$server}{$type}};
9208: if (@spares > 0) {
1.152 raeburn 9209: if ($othercontrol) {
9210: $current{$type} = join(', ',@spares);
9211: } else {
9212: $current{$type} .= '<table>';
9213: my $numspares = scalar(@spares);
9214: for (my $i=0; $i<@spares; $i++) {
9215: my $rem = $i%($numinrow);
9216: if ($rem == 0) {
9217: if ($i > 0) {
9218: $current{$type} .= '</tr>';
9219: }
9220: $current{$type} .= '<tr>';
1.145 raeburn 9221: }
1.152 raeburn 9222: $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'".');" /> '.
9223: $spareid->{$server}{$type}[$i].
9224: '</label></td>'."\n";
9225: }
9226: my $rem = @spares%($numinrow);
9227: my $colsleft = $numinrow - $rem;
9228: if ($colsleft > 1 ) {
9229: $current{$type} .= '<td colspan="'.$colsleft.
9230: '" class="LC_left_item">'.
9231: ' </td>';
9232: } elsif ($colsleft == 1) {
9233: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9234: }
1.152 raeburn 9235: $current{$type} .= '</tr></table>';
1.150 raeburn 9236: }
1.145 raeburn 9237: }
9238: }
9239: if ($current{$type} eq '') {
9240: $current{$type} = &mt('None specified');
9241: }
1.152 raeburn 9242: if ($othercontrol) {
9243: if ($type eq 'primary') {
9244: $canselect{$type} = $othercontrol;
9245: }
9246: } else {
9247: $canselect{$type} =
9248: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9249: '<select name="newspare_'.$type.'_'.$server.'" '.
9250: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9251: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9252: if (@choices > 0) {
9253: foreach my $lonhost (@choices) {
9254: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9255: }
9256: }
9257: $canselect{$type} .= '</select>'."\n";
9258: }
9259: } else {
9260: $current{$type} = &mt('Could not be determined');
9261: if ($type eq 'primary') {
9262: $canselect{$type} = $othercontrol;
9263: }
1.145 raeburn 9264: }
1.152 raeburn 9265: if ($type eq 'default') {
9266: $datatable .= '<tr'.$css_class.'>';
9267: }
9268: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9269: '<td>'.$current{$type}.'</td>'."\n".
9270: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9271: }
9272: $itemcount ++;
9273: }
9274: }
9275: $$rowtotal += $itemcount;
9276: return $datatable;
9277: }
9278:
1.152 raeburn 9279: sub possible_newspares {
9280: my ($server,$currspares,$serverhomes,$altids) = @_;
9281: my $serverhostname = &Apache::lonnet::hostname($server);
9282: my %excluded;
9283: if ($serverhostname ne '') {
9284: %excluded = (
9285: $serverhostname => 1,
9286: );
9287: }
9288: if (ref($currspares) eq 'HASH') {
9289: foreach my $type (keys(%{$currspares})) {
9290: if (ref($currspares->{$type}) eq 'ARRAY') {
9291: if (@{$currspares->{$type}} > 0) {
9292: foreach my $curr (@{$currspares->{$type}}) {
9293: my $hostname = &Apache::lonnet::hostname($curr);
9294: $excluded{$hostname} = 1;
9295: }
9296: }
9297: }
9298: }
9299: }
9300: my @choices;
9301: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9302: if (keys(%{$serverhomes}) > 1) {
9303: foreach my $name (sort(keys(%{$serverhomes}))) {
9304: unless ($excluded{$name}) {
9305: if (exists($altids->{$serverhomes->{$name}})) {
9306: push(@choices,$altids->{$serverhomes->{$name}});
9307: } else {
9308: push(@choices,$serverhomes->{$name});
1.145 raeburn 9309: }
9310: }
9311: }
9312: }
9313: }
1.152 raeburn 9314: return sort(@choices);
1.145 raeburn 9315: }
9316:
1.150 raeburn 9317: sub print_loadbalancing {
9318: my ($dom,$settings,$rowtotal) = @_;
9319: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9320: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9321: my $numinrow = 1;
9322: my $datatable;
9323: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9324: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9325: if (ref($settings) eq 'HASH') {
9326: %existing = %{$settings};
9327: }
9328: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9329: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9330: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9331: } else {
9332: return;
9333: }
9334: my ($othertitle,$usertypes,$types) =
9335: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9336: my $rownum = 8;
1.150 raeburn 9337: if (ref($types) eq 'ARRAY') {
9338: $rownum += scalar(@{$types});
9339: }
1.171 raeburn 9340: my @css_class = ('LC_odd_row','LC_even_row');
9341: my $balnum = 0;
9342: my $islast;
9343: my (@toshow,$disabledtext);
9344: if (keys(%currbalancer) > 0) {
9345: @toshow = sort(keys(%currbalancer));
9346: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9347: push(@toshow,'');
9348: }
9349: } else {
9350: @toshow = ('');
9351: $disabledtext = &mt('No existing load balancer');
9352: }
9353: foreach my $lonhost (@toshow) {
9354: if ($balnum == scalar(@toshow)-1) {
9355: $islast = 1;
9356: } else {
9357: $islast = 0;
9358: }
9359: my $cssidx = $balnum%2;
9360: my $targets_div_style = 'display: none';
9361: my $disabled_div_style = 'display: block';
9362: my $homedom_div_style = 'display: none';
9363: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9364: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9365: '<p>';
9366: if ($lonhost eq '') {
1.210 raeburn 9367: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9368: if (keys(%currbalancer) > 0) {
9369: $datatable .= &mt('Add balancer:');
9370: } else {
9371: $datatable .= &mt('Enable balancer:');
9372: }
9373: $datatable .= ' '.
9374: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9375: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9376: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9377: '<option value="" selected="selected">'.&mt('None').
9378: '</option>'."\n";
9379: foreach my $server (sort(keys(%servers))) {
9380: next if ($currbalancer{$server});
9381: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9382: }
1.210 raeburn 9383: $datatable .=
1.171 raeburn 9384: '</select>'."\n".
9385: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9386: } else {
9387: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9388: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9389: &mt('Stop balancing').'</label>'.
9390: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9391: $targets_div_style = 'display: block';
9392: $disabled_div_style = 'display: none';
9393: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9394: $homedom_div_style = 'display: block';
9395: }
9396: }
1.306 raeburn 9397: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9398: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9399: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9400: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9401: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9402: my @sparestypes = ('primary','default');
9403: my %typetitles = &sparestype_titles();
1.284 raeburn 9404: my %hostherechecked = (
9405: no => ' checked="checked"',
9406: );
1.342 raeburn 9407: my %balcookiechecked = (
1.425 raeburn 9408: no => ' checked="checked"',
1.342 raeburn 9409: );
1.171 raeburn 9410: foreach my $sparetype (@sparestypes) {
9411: my $targettable;
9412: for (my $i=0; $i<$numspares; $i++) {
9413: my $checked;
9414: if (ref($currtargets{$lonhost}) eq 'HASH') {
9415: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9416: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9417: $checked = ' checked="checked"';
9418: }
9419: }
9420: }
9421: my ($chkboxval,$disabled);
9422: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9423: $chkboxval = $spares[$i];
9424: }
9425: if (exists($currbalancer{$spares[$i]})) {
9426: $disabled = ' disabled="disabled"';
9427: }
1.210 raeburn 9428: $targettable .=
1.253 raeburn 9429: '<td><span class="LC_nobreak"><label>'.
9430: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9431: $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 9432: '</span></label></span></td>';
1.171 raeburn 9433: my $rem = $i%($numinrow);
9434: if ($rem == 0) {
9435: if (($i > 0) && ($i < $numspares-1)) {
9436: $targettable .= '</tr>';
9437: }
9438: if ($i < $numspares-1) {
9439: $targettable .= '<tr>';
1.150 raeburn 9440: }
9441: }
9442: }
1.171 raeburn 9443: if ($targettable ne '') {
9444: my $rem = $numspares%($numinrow);
9445: my $colsleft = $numinrow - $rem;
9446: if ($colsleft > 1 ) {
9447: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9448: ' </td>';
9449: } elsif ($colsleft == 1) {
9450: $targettable .= '<td class="LC_left_item"> </td>';
9451: }
9452: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9453: '<table><tr>'.$targettable.'</tr></table><br />';
9454: }
1.284 raeburn 9455: $hostherechecked{$sparetype} = '';
9456: if (ref($currtargets{$lonhost}) eq 'HASH') {
9457: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9458: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9459: $hostherechecked{$sparetype} = ' checked="checked"';
9460: $hostherechecked{'no'} = '';
9461: }
9462: }
9463: }
9464: }
1.342 raeburn 9465: if ($currcookies{$lonhost}) {
9466: %balcookiechecked = (
9467: yes => ' checked="checked"',
9468: );
9469: }
1.284 raeburn 9470: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9471: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9472: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9473: foreach my $sparetype (@sparestypes) {
9474: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9475: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9476: '</i></label><br />';
1.171 raeburn 9477: }
1.342 raeburn 9478: $datatable .= &mt('Use balancer cookie').'<br />'.
9479: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9480: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9481: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9482: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9483: '</div></td></tr>'.
1.171 raeburn 9484: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9485: $othertitle,$usertypes,$types,\%servers,
9486: \%currbalancer,$lonhost,
9487: $targets_div_style,$homedom_div_style,
9488: $css_class[$cssidx],$balnum,$islast);
9489: $$rowtotal += $rownum;
9490: $balnum ++;
9491: }
9492: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9493: return $datatable;
9494: }
9495:
9496: sub get_loadbalancers_config {
1.342 raeburn 9497: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9498: return unless ((ref($servers) eq 'HASH') &&
9499: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9500: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9501: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9502: if (keys(%{$existing}) > 0) {
9503: my $oldlonhost;
9504: foreach my $key (sort(keys(%{$existing}))) {
9505: if ($key eq 'lonhost') {
9506: $oldlonhost = $existing->{'lonhost'};
9507: $currbalancer->{$oldlonhost} = 1;
9508: } elsif ($key eq 'targets') {
9509: if ($oldlonhost) {
9510: $currtargets->{$oldlonhost} = $existing->{'targets'};
9511: }
9512: } elsif ($key eq 'rules') {
9513: if ($oldlonhost) {
9514: $currrules->{$oldlonhost} = $existing->{'rules'};
9515: }
9516: } elsif (ref($existing->{$key}) eq 'HASH') {
9517: $currbalancer->{$key} = 1;
9518: $currtargets->{$key} = $existing->{$key}{'targets'};
9519: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9520: if ($existing->{$key}{'cookie'}) {
9521: $currcookies->{$key} = 1;
9522: }
1.150 raeburn 9523: }
9524: }
1.171 raeburn 9525: } else {
9526: my ($balancerref,$targetsref) =
9527: &Apache::lonnet::get_lonbalancer_config($servers);
9528: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9529: foreach my $server (sort(keys(%{$balancerref}))) {
9530: $currbalancer->{$server} = 1;
9531: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9532: }
9533: }
9534: }
1.171 raeburn 9535: return;
1.150 raeburn 9536: }
9537:
9538: sub loadbalancing_rules {
9539: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9540: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9541: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9542: my $output;
1.171 raeburn 9543: my $num = 0;
1.210 raeburn 9544: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9545: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9546: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9547: foreach my $type (@{$alltypes}) {
1.171 raeburn 9548: $num ++;
1.150 raeburn 9549: my $current;
9550: if (ref($currrules) eq 'HASH') {
9551: $current = $currrules->{$type};
9552: }
1.253 raeburn 9553: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9554: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9555: $current = '';
9556: }
9557: }
9558: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9559: $servers,$currbalancer,$lonhost,$dom,
9560: $targets_div_style,$homedom_div_style,
9561: $css_class,$balnum,$num,$islast);
1.150 raeburn 9562: }
9563: }
9564: return $output;
9565: }
9566:
9567: sub loadbalancing_titles {
9568: my ($dom,$intdom,$usertypes,$types) = @_;
9569: my %othertypes = (
9570: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9571: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9572: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9573: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9574: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9575: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9576: );
1.209 raeburn 9577: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9578: my @available;
1.150 raeburn 9579: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9580: @available = @{$types};
1.150 raeburn 9581: }
1.302 raeburn 9582: unless (grep(/^default$/,@available)) {
9583: push(@available,'default');
9584: }
9585: unshift(@alltypes,@available);
1.150 raeburn 9586: my %titles;
9587: foreach my $type (@alltypes) {
9588: if ($type =~ /^_LC_/) {
9589: $titles{$type} = $othertypes{$type};
9590: } elsif ($type eq 'default') {
9591: $titles{$type} = &mt('All users from [_1]',$dom);
9592: if (ref($types) eq 'ARRAY') {
9593: if (@{$types} > 0) {
9594: $titles{$type} = &mt('Other users from [_1]',$dom);
9595: }
9596: }
9597: } elsif (ref($usertypes) eq 'HASH') {
9598: $titles{$type} = $usertypes->{$type};
9599: }
9600: }
9601: return (\@alltypes,\%othertypes,\%titles);
9602: }
9603:
9604: sub loadbalance_rule_row {
1.171 raeburn 9605: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9606: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9607: my @rulenames;
1.150 raeburn 9608: my %ruletitles = &offloadtype_text();
1.209 raeburn 9609: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9610: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9611: } else {
1.209 raeburn 9612: @rulenames = ('default','homeserver');
9613: if ($type eq '_LC_external') {
9614: push(@rulenames,'externalbalancer');
9615: } else {
9616: push(@rulenames,'specific');
9617: }
9618: push(@rulenames,'none');
1.150 raeburn 9619: }
9620: my $style = $targets_div_style;
1.253 raeburn 9621: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9622: $style = $homedom_div_style;
9623: }
1.171 raeburn 9624: my $space;
9625: if ($islast && $num == 1) {
1.317 raeburn 9626: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9627: }
1.210 raeburn 9628: my $output =
1.306 raeburn 9629: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9630: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9631: '<td valaign="top">'.$space.
9632: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9633: for (my $i=0; $i<@rulenames; $i++) {
9634: my $rule = $rulenames[$i];
9635: my ($checked,$extra);
9636: if ($rulenames[$i] eq 'default') {
9637: $rule = '';
9638: }
9639: if ($rulenames[$i] eq 'specific') {
9640: if (ref($servers) eq 'HASH') {
9641: my $default;
9642: if (($current ne '') && (exists($servers->{$current}))) {
9643: $checked = ' checked="checked"';
9644: }
9645: unless ($checked) {
9646: $default = ' selected="selected"';
9647: }
1.210 raeburn 9648: $extra =
1.171 raeburn 9649: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9650: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9651: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9652: '<option value=""'.$default.'></option>'."\n";
9653: foreach my $server (sort(keys(%{$servers}))) {
9654: if (ref($currbalancer) eq 'HASH') {
9655: next if (exists($currbalancer->{$server}));
9656: }
1.150 raeburn 9657: my $selected;
1.171 raeburn 9658: if ($server eq $current) {
1.150 raeburn 9659: $selected = ' selected="selected"';
9660: }
1.171 raeburn 9661: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9662: }
9663: $extra .= '</select>';
9664: }
9665: } elsif ($rule eq $current) {
9666: $checked = ' checked="checked"';
9667: }
9668: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9669: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9670: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9671: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9672: ')"'.$checked.' /> ';
9673: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9674: $output .= $ruletitles{'particular'};
9675: } else {
9676: $output .= $ruletitles{$rulenames[$i]};
9677: }
9678: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9679: }
9680: $output .= '</div></td></tr>'."\n";
9681: return $output;
9682: }
9683:
9684: sub offloadtype_text {
9685: my %ruletitles = &Apache::lonlocal::texthash (
9686: 'default' => 'Offloads to default destinations',
9687: 'homeserver' => "Offloads to user's home server",
9688: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9689: 'specific' => 'Offloads to specific server',
1.161 raeburn 9690: 'none' => 'No offload',
1.209 raeburn 9691: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9692: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9693: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9694: );
9695: return %ruletitles;
9696: }
9697:
9698: sub sparestype_titles {
9699: my %typestitles = &Apache::lonlocal::texthash (
9700: 'primary' => 'primary',
9701: 'default' => 'default',
9702: );
9703: return %typestitles;
9704: }
9705:
1.28 raeburn 9706: sub contact_titles {
9707: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9708: 'supportemail' => 'Support E-mail address',
9709: 'adminemail' => 'Default Server Admin E-mail address',
9710: 'errormail' => 'Error reports to be e-mailed to',
9711: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9712: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9713: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9714: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9715: 'requestsmail' => 'E-mail from course requests requiring approval',
9716: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9717: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9718: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9719: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9720: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9721: 'errorweights' => 'Weights used to compute error count',
9722: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9723: );
9724: my %short_titles = &Apache::lonlocal::texthash (
9725: adminemail => 'Admin E-mail address',
9726: supportemail => 'Support E-mail',
9727: );
9728: return (\%titles,\%short_titles);
9729: }
9730:
1.286 raeburn 9731: sub helpform_fields {
9732: my %titles = &Apache::lonlocal::texthash (
9733: 'username' => 'Name',
9734: 'user' => 'Username/domain',
9735: 'phone' => 'Phone',
9736: 'cc' => 'Cc e-mail',
9737: 'course' => 'Course Details',
9738: 'section' => 'Sections',
1.289 raeburn 9739: 'screenshot' => 'File upload',
1.286 raeburn 9740: );
9741: my @fields = ('username','phone','user','course','section','cc','screenshot');
9742: my %possoptions = (
9743: username => ['yes','no','req'],
1.289 raeburn 9744: phone => ['yes','no','req'],
1.286 raeburn 9745: user => ['yes','no'],
1.289 raeburn 9746: cc => ['yes','no'],
1.286 raeburn 9747: course => ['yes','no'],
9748: section => ['yes','no'],
9749: screenshot => ['yes','no'],
9750: );
9751: my %fieldoptions = &Apache::lonlocal::texthash (
9752: 'yes' => 'Optional',
9753: 'req' => 'Required',
9754: 'no' => "Not shown",
9755: );
9756: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9757: }
9758:
1.72 raeburn 9759: sub tool_titles {
9760: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9761: aboutme => 'Personal web page',
1.86 raeburn 9762: blog => 'Blog',
9763: portfolio => 'Portfolio',
1.430 raeburn 9764: portaccess => 'Share portfolio files',
1.413 raeburn 9765: timezone => 'Can set time zone',
1.88 bisitz 9766: official => 'Official courses (with institutional codes)',
9767: unofficial => 'Unofficial courses',
1.98 raeburn 9768: community => 'Communities',
1.216 raeburn 9769: textbook => 'Textbook courses',
1.271 raeburn 9770: placement => 'Placement tests',
1.86 raeburn 9771: );
1.72 raeburn 9772: return %titles;
9773: }
9774:
1.101 raeburn 9775: sub courserequest_titles {
9776: my %titles = &Apache::lonlocal::texthash (
9777: official => 'Official',
9778: unofficial => 'Unofficial',
9779: community => 'Communities',
1.216 raeburn 9780: textbook => 'Textbook',
1.271 raeburn 9781: placement => 'Placement tests',
1.325 raeburn 9782: lti => 'LTI Provider',
1.101 raeburn 9783: norequest => 'Not allowed',
1.325 raeburn 9784: approval => 'Approval by DC',
1.101 raeburn 9785: validate => 'With validation',
9786: autolimit => 'Numerical limit',
1.103 raeburn 9787: unlimited => '(blank for unlimited)',
1.101 raeburn 9788: );
9789: return %titles;
9790: }
9791:
1.163 raeburn 9792: sub authorrequest_titles {
9793: my %titles = &Apache::lonlocal::texthash (
9794: norequest => 'Not allowed',
9795: approval => 'Approval by Dom. Coord.',
9796: automatic => 'Automatic approval',
9797: );
9798: return %titles;
1.210 raeburn 9799: }
1.163 raeburn 9800:
1.101 raeburn 9801: sub courserequest_conditions {
9802: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9803: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9804: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9805: );
9806: return %conditions;
9807: }
9808:
9809:
1.27 raeburn 9810: sub print_usercreation {
1.30 raeburn 9811: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9812: my $numinrow = 4;
1.28 raeburn 9813: my $datatable;
9814: if ($position eq 'top') {
1.30 raeburn 9815: $$rowtotal ++;
1.34 raeburn 9816: my $rowcount = 0;
1.32 raeburn 9817: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9818: if (ref($rules) eq 'HASH') {
9819: if (keys(%{$rules}) > 0) {
1.32 raeburn 9820: $datatable .= &user_formats_row('username',$settings,$rules,
9821: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9822: $$rowtotal ++;
1.32 raeburn 9823: $rowcount ++;
9824: }
9825: }
9826: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9827: if (ref($idrules) eq 'HASH') {
9828: if (keys(%{$idrules}) > 0) {
9829: $datatable .= &user_formats_row('id',$settings,$idrules,
9830: $idruleorder,$numinrow,$rowcount);
9831: $$rowtotal ++;
9832: $rowcount ++;
1.28 raeburn 9833: }
9834: }
1.39 raeburn 9835: if ($rowcount == 0) {
9836: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9837: $$rowtotal ++;
9838: $rowcount ++;
9839: }
1.34 raeburn 9840: } elsif ($position eq 'middle') {
1.224 raeburn 9841: my @creators = ('author','course','requestcrs');
1.37 raeburn 9842: my ($rules,$ruleorder) =
9843: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9844: my %lt = &usercreation_types();
9845: my %checked;
9846: if (ref($settings) eq 'HASH') {
9847: if (ref($settings->{'cancreate'}) eq 'HASH') {
9848: foreach my $item (@creators) {
9849: $checked{$item} = $settings->{'cancreate'}{$item};
9850: }
9851: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9852: foreach my $item (@creators) {
9853: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9854: $checked{$item} = 'none';
9855: }
9856: }
9857: }
9858: }
9859: my $rownum = 0;
9860: foreach my $item (@creators) {
9861: $rownum ++;
1.224 raeburn 9862: if ($checked{$item} eq '') {
9863: $checked{$item} = 'any';
1.34 raeburn 9864: }
9865: my $css_class;
9866: if ($rownum%2) {
9867: $css_class = '';
9868: } else {
9869: $css_class = ' class="LC_odd_row" ';
9870: }
9871: $datatable .= '<tr'.$css_class.'>'.
9872: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9873: '</span></td><td style="text-align: right">';
1.224 raeburn 9874: my @options = ('any');
9875: if (ref($rules) eq 'HASH') {
9876: if (keys(%{$rules}) > 0) {
9877: push(@options,('official','unofficial'));
1.37 raeburn 9878: }
9879: }
1.224 raeburn 9880: push(@options,'none');
1.37 raeburn 9881: foreach my $option (@options) {
1.50 raeburn 9882: my $type = 'radio';
1.34 raeburn 9883: my $check = ' ';
1.224 raeburn 9884: if ($checked{$item} eq $option) {
9885: $check = ' checked="checked" ';
1.34 raeburn 9886: }
9887: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9888: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9889: $item.'" value="'.$option.'"'.$check.'/> '.
9890: $lt{$option}.'</label> </span>';
9891: }
9892: $datatable .= '</td></tr>';
9893: }
1.28 raeburn 9894: } else {
9895: my @contexts = ('author','course','domain');
1.325 raeburn 9896: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9897: my %checked;
9898: if (ref($settings) eq 'HASH') {
9899: if (ref($settings->{'authtypes'}) eq 'HASH') {
9900: foreach my $item (@contexts) {
9901: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9902: foreach my $auth (@authtypes) {
9903: if ($settings->{'authtypes'}{$item}{$auth}) {
9904: $checked{$item}{$auth} = ' checked="checked" ';
9905: }
9906: }
9907: }
9908: }
1.27 raeburn 9909: }
1.35 raeburn 9910: } else {
9911: foreach my $item (@contexts) {
1.36 raeburn 9912: foreach my $auth (@authtypes) {
1.35 raeburn 9913: $checked{$item}{$auth} = ' checked="checked" ';
9914: }
9915: }
1.27 raeburn 9916: }
1.28 raeburn 9917: my %title = &context_names();
9918: my %authname = &authtype_names();
9919: my $rownum = 0;
9920: my $css_class;
9921: foreach my $item (@contexts) {
9922: if ($rownum%2) {
9923: $css_class = '';
9924: } else {
9925: $css_class = ' class="LC_odd_row" ';
9926: }
1.30 raeburn 9927: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9928: '<td>'.$title{$item}.
9929: '</td><td class="LC_left_item">'.
9930: '<span class="LC_nobreak">';
9931: foreach my $auth (@authtypes) {
9932: $datatable .= '<label>'.
9933: '<input type="checkbox" name="'.$item.'_auth" '.
9934: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9935: $authname{$auth}.'</label> ';
9936: }
9937: $datatable .= '</span></td></tr>';
9938: $rownum ++;
1.27 raeburn 9939: }
1.30 raeburn 9940: $$rowtotal += $rownum;
1.27 raeburn 9941: }
9942: return $datatable;
9943: }
9944:
1.224 raeburn 9945: sub print_selfcreation {
9946: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9947: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9948: $emaildomain,$datatable);
1.224 raeburn 9949: if (ref($settings) eq 'HASH') {
9950: if (ref($settings->{'cancreate'}) eq 'HASH') {
9951: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9952: if (ref($createsettings) eq 'HASH') {
9953: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9954: @selfcreate = @{$createsettings->{'selfcreate'}};
9955: } elsif ($createsettings->{'selfcreate'} ne '') {
9956: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9957: @selfcreate = ('email','login','sso');
9958: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9959: @selfcreate = ($createsettings->{'selfcreate'});
9960: }
9961: }
9962: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9963: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9964: }
1.305 raeburn 9965: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9966: $emailoptions = $createsettings->{'emailoptions'};
9967: }
1.303 raeburn 9968: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9969: $emailverified = $createsettings->{'emailverified'};
9970: }
9971: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9972: $emaildomain = $createsettings->{'emaildomain'};
9973: }
1.224 raeburn 9974: }
9975: }
9976: }
9977: my %radiohash;
9978: my $numinrow = 4;
9979: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9980: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9981: if ($position eq 'top') {
9982: my %choices = &Apache::lonlocal::texthash (
9983: cancreate_login => 'Institutional Login',
9984: cancreate_sso => 'Institutional Single Sign On',
9985: );
9986: my @toggles = sort(keys(%choices));
9987: my %defaultchecked = (
9988: 'cancreate_login' => 'off',
9989: 'cancreate_sso' => 'off',
9990: );
1.228 raeburn 9991: my ($onclick,$itemcount);
1.224 raeburn 9992: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9993: \%choices,$itemcount,$onclick);
1.228 raeburn 9994: $$rowtotal += $itemcount;
1.425 raeburn 9995:
1.224 raeburn 9996: if (ref($usertypes) eq 'HASH') {
9997: if (keys(%{$usertypes}) > 0) {
9998: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9999: $dom,$numinrow,$othertitle,
1.305 raeburn 10000: 'statustocreate',$rowtotal);
1.224 raeburn 10001: $$rowtotal ++;
10002: }
10003: }
1.240 raeburn 10004: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
10005: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10006: $fieldtitles{'inststatus'} = &mt('Institutional status');
10007: my $rem;
10008: my $numperrow = 2;
10009: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
10010: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 10011: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 10012: '<td class="LC_left_item">'."\n".
1.334 raeburn 10013: '<table>'."\n";
1.240 raeburn 10014: for (my $i=0; $i<@fields; $i++) {
10015: $rem = $i%($numperrow);
10016: if ($rem == 0) {
10017: if ($i > 0) {
10018: $datatable .= '</tr>';
10019: }
10020: $datatable .= '<tr>';
10021: }
10022: my $currval;
1.248 raeburn 10023: if (ref($createsettings) eq 'HASH') {
10024: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
10025: $currval = $createsettings->{'shibenv'}{$fields[$i]};
10026: }
1.240 raeburn 10027: }
10028: $datatable .= '<td class="LC_left_item">'.
10029: '<span class="LC_nobreak">'.
10030: '<input type="text" name="shibenv_'.$fields[$i].'" '.
10031: 'value="'.$currval.'" size="10" /> '.
10032: $fieldtitles{$fields[$i]}.'</span></td>';
10033: }
10034: my $colsleft = $numperrow - $rem;
10035: if ($colsleft > 1 ) {
10036: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10037: ' </td>';
10038: } elsif ($colsleft == 1) {
10039: $datatable .= '<td class="LC_left_item"> </td>';
10040: }
10041: $datatable .= '</tr></table></td></tr>';
10042: $$rowtotal ++;
1.224 raeburn 10043: } elsif ($position eq 'middle') {
10044: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 10045: my @posstypes;
1.224 raeburn 10046: if (ref($types) eq 'ARRAY') {
1.302 raeburn 10047: @posstypes = @{$types};
10048: }
10049: unless (grep(/^default$/,@posstypes)) {
10050: push(@posstypes,'default');
10051: }
10052: my %usertypeshash;
10053: if (ref($usertypes) eq 'HASH') {
10054: %usertypeshash = %{$usertypes};
10055: }
10056: $usertypeshash{'default'} = $othertitle;
10057: foreach my $status (@posstypes) {
10058: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
10059: $numinrow,$$rowtotal,\%usertypeshash);
10060: $$rowtotal ++;
1.224 raeburn 10061: }
10062: } else {
1.236 raeburn 10063: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 10064: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 10065: );
10066: my @toggles = sort(keys(%choices));
10067: my %defaultchecked = (
10068: 'cancreate_email' => 'off',
10069: );
1.305 raeburn 10070: my $customclass = 'LC_selfcreate_email';
10071: my $classprefix = 'LC_canmodify_emailusername_';
10072: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10073: my $display = 'none';
1.305 raeburn 10074: my $rowstyle = 'display:none';
1.236 raeburn 10075: if (grep(/^\Qemail\E$/,@selfcreate)) {
10076: $display = 'block';
1.305 raeburn 10077: $rowstyle = 'display:table-row';
1.236 raeburn 10078: }
1.305 raeburn 10079: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10080: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10081: \%choices,$$rowtotal,$onclick);
10082: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10083: $rowstyle);
10084: $$rowtotal ++;
10085: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10086: $rowstyle);
10087: $$rowtotal ++;
10088: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10089: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10090: my ($emailrules,$emailruleorder) =
10091: &Apache::lonnet::inst_userrules($dom,'email');
10092: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10093: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10094: if (ref($types) eq 'ARRAY') {
10095: @posstypes = @{$types};
10096: }
10097: if (@posstypes) {
10098: unless (grep(/^default$/,@posstypes)) {
10099: push(@posstypes,'default');
1.302 raeburn 10100: }
10101: if (ref($usertypes) eq 'HASH') {
10102: %usertypeshash = %{$usertypes};
10103: }
1.305 raeburn 10104: my $currassign;
10105: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10106: $currassign = {
10107: selfassign => $domdefaults{'inststatusguest'},
10108: };
10109: @ordered = @{$domdefaults{'inststatusguest'}};
10110: } else {
10111: $currassign = { selfassign => [] };
10112: }
10113: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10114: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10115: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10116: $numinrow,$othertitle,'selfassign',
10117: $rowtotal,$onclicktypes,$customclass,
10118: $rowstyle);
10119: $$rowtotal ++;
1.302 raeburn 10120: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10121: foreach my $status (@posstypes) {
10122: my $css_class;
10123: if ($$rowtotal%2) {
10124: $css_class = 'LC_odd_row ';
10125: }
10126: $css_class .= $customclass;
10127: my $rowid = $optionsprefix.$status;
10128: my $hidden = 1;
10129: my $currstyle = 'display:none';
10130: if (grep(/^\Q$status\E$/,@ordered)) {
10131: $currstyle = $rowstyle;
1.425 raeburn 10132: $hidden = 0;
1.305 raeburn 10133: }
10134: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10135: $emailrules,$emailruleorder,$settings,$status,$rowid,
10136: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10137: unless ($hidden) {
10138: $$rowtotal ++;
10139: }
1.224 raeburn 10140: }
1.302 raeburn 10141: } else {
1.305 raeburn 10142: my $css_class;
10143: if ($$rowtotal%2) {
10144: $css_class = 'LC_odd_row ';
10145: }
10146: $css_class .= $customclass;
1.302 raeburn 10147: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10148: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10149: $emailrules,$emailruleorder,$settings,'default','',
10150: $othertitle,$css_class,$rowstyle,$intdom);
10151: $$rowtotal ++;
1.224 raeburn 10152: }
10153: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10154: $numinrow = 1;
1.305 raeburn 10155: if (@posstypes) {
10156: foreach my $status (@posstypes) {
10157: my $rowid = $classprefix.$status;
10158: my $datarowstyle = 'display:none';
1.425 raeburn 10159: if (grep(/^\Q$status\E$/,@ordered)) {
10160: $datarowstyle = $rowstyle;
1.305 raeburn 10161: }
10162: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10163: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10164: $infotitles,$rowid,$customclass,$datarowstyle);
10165: unless ($datarowstyle eq 'display:none') {
10166: $$rowtotal ++;
10167: }
1.224 raeburn 10168: }
1.305 raeburn 10169: } else {
10170: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10171: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10172: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10173: }
10174: }
10175: return $datatable;
10176: }
10177:
1.305 raeburn 10178: sub selfcreate_javascript {
10179: return <<"ENDSCRIPT";
10180:
10181: <script type="text/javascript">
10182: // <![CDATA[
10183:
10184: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10185: var x = document.getElementsByClassName(target);
10186: var insttypes = 0;
10187: var insttypeRegExp = new RegExp(prefix);
10188: if ((x.length != undefined) && (x.length > 0)) {
10189: if (form.elements[radio].length != undefined) {
10190: for (var i=0; i<form.elements[radio].length; i++) {
10191: if (form.elements[radio][i].checked) {
10192: if (form.elements[radio][i].value == 1) {
10193: for (var j=0; j<x.length; j++) {
10194: if (x[j].id == 'undefined') {
10195: x[j].style.display = 'table-row';
10196: } else if (insttypeRegExp.test(x[j].id)) {
10197: insttypes ++;
10198: } else {
10199: x[j].style.display = 'table-row';
10200: }
10201: }
10202: } else {
10203: for (var j=0; j<x.length; j++) {
10204: x[j].style.display = 'none';
10205: }
1.236 raeburn 10206: }
1.305 raeburn 10207: break;
10208: }
10209: }
10210: if (insttypes > 0) {
10211: toggleDataRow(form,checkbox,target,altprefix);
10212: toggleDataRow(form,checkbox,target,prefix,1);
10213: }
10214: }
10215: }
10216: return;
10217: }
10218:
10219: function toggleDataRow(form,checkbox,target,prefix,docount) {
10220: if (form.elements[checkbox].length != undefined) {
10221: var count = 0;
10222: if (docount) {
10223: for (var i=0; i<form.elements[checkbox].length; i++) {
10224: if (form.elements[checkbox][i].checked) {
10225: count ++;
1.236 raeburn 10226: }
1.305 raeburn 10227: }
10228: }
10229: for (var i=0; i<form.elements[checkbox].length; i++) {
10230: var type = form.elements[checkbox][i].value;
10231: if (document.getElementById(prefix+type)) {
10232: if (form.elements[checkbox][i].checked) {
10233: document.getElementById(prefix+type).style.display = 'table-row';
10234: if (count % 2 == 1) {
10235: document.getElementById(prefix+type).className = target+' LC_odd_row';
10236: } else {
10237: document.getElementById(prefix+type).className = target;
1.236 raeburn 10238: }
1.305 raeburn 10239: count ++;
1.236 raeburn 10240: } else {
1.305 raeburn 10241: document.getElementById(prefix+type).style.display = 'none';
10242: }
10243: }
10244: }
10245: }
10246: return;
10247: }
10248:
10249: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10250: var caller = radio+'_'+status;
10251: if (form.elements[caller].length != undefined) {
10252: for (var i=0; i<form.elements[caller].length; i++) {
10253: if (form.elements[caller][i].checked) {
10254: if (document.getElementById(altprefix+'_inst_'+status)) {
10255: var curr = form.elements[caller][i].value;
10256: if (prefix) {
10257: document.getElementById(prefix+'_'+status).style.display = 'none';
10258: }
10259: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10260: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10261: if (curr == 'custom') {
1.425 raeburn 10262: if (prefix) {
1.305 raeburn 10263: document.getElementById(prefix+'_'+status).style.display = 'inline';
10264: }
10265: } else if (curr == 'inst') {
10266: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10267: } else if (curr == 'noninst') {
10268: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10269: }
1.305 raeburn 10270: break;
1.236 raeburn 10271: }
10272: }
10273: }
10274: }
10275: }
10276:
1.305 raeburn 10277: // ]]>
10278: </script>
10279:
10280: ENDSCRIPT
10281: }
10282:
10283: sub noninst_users {
10284: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10285: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10286: my $class = 'LC_left_item';
10287: if ($css_class) {
1.425 raeburn 10288: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10289: }
10290: if ($rowid) {
10291: $rowid = ' id="'.$rowid.'"';
10292: }
10293: if ($rowstyle) {
10294: $rowstyle = ' style="'.$rowstyle.'"';
10295: }
10296: my ($output,$description);
10297: if ($type eq 'default') {
10298: $description = &mt('Requests for: [_1]',$typetitle);
10299: } else {
10300: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10301: }
10302: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10303: "<td>$description</td>\n".
1.305 raeburn 10304: '<td class="'.$class.'" colspan="2">'.
10305: '<table><tr>';
1.425 raeburn 10306: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10307: approve => 'Processing',
10308: email => 'E-mail',
10309: username => 'Username',
10310: );
10311: foreach my $item ('approve','email','username') {
10312: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10313: }
1.305 raeburn 10314: $output .= '</tr><tr>';
10315: foreach my $item ('approve','email','username') {
1.306 raeburn 10316: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10317: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10318: if ($item eq 'approve') {
10319: %choices = &Apache::lonlocal::texthash (
10320: automatic => 'Automatically approved',
10321: approval => 'Queued for approval',
10322: );
10323: @options = ('automatic','approval');
10324: $hashref = $processing;
10325: $defoption = 'automatic';
10326: $name = 'cancreate_emailprocess_'.$type;
10327: } elsif ($item eq 'email') {
10328: %choices = &Apache::lonlocal::texthash (
10329: any => 'Any e-mail',
10330: inst => 'Institutional only',
10331: noninst => 'Non-institutional only',
10332: custom => 'Custom restrictions',
10333: );
10334: @options = ('any','inst','noninst');
10335: my $showcustom;
10336: if (ref($emailrules) eq 'HASH') {
10337: if (keys(%{$emailrules}) > 0) {
10338: push(@options,'custom');
10339: $showcustom = 'cancreate_emailrule';
10340: if (ref($settings) eq 'HASH') {
10341: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10342: foreach my $rule (@{$settings->{'email_rule'}}) {
10343: if (exists($emailrules->{$rule})) {
10344: $hascustom ++;
10345: }
10346: }
10347: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10348: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10349: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10350: if (exists($emailrules->{$rule})) {
10351: $hascustom ++;
10352: }
10353: }
10354: }
10355: }
10356: }
10357: }
10358: }
10359: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10360: "'cancreate_emaildomain','$type'".');"';
10361: $hashref = $emailoptions;
10362: $defoption = 'any';
10363: $name = 'cancreate_emailoptions_'.$type;
10364: } elsif ($item eq 'username') {
10365: %choices = &Apache::lonlocal::texthash (
10366: all => 'Same as e-mail',
10367: first => 'Omit @domain',
10368: free => 'Free to choose',
10369: );
10370: @options = ('all','first','free');
10371: $hashref = $emailverified;
10372: $defoption = 'all';
10373: $name = 'cancreate_usernameoptions_'.$type;
10374: }
10375: foreach my $option (@options) {
10376: my $checked;
10377: if (ref($hashref) eq 'HASH') {
10378: if ($type eq '') {
10379: if (!exists($hashref->{'default'})) {
10380: if ($option eq $defoption) {
10381: $checked = ' checked="checked"';
10382: }
10383: } else {
10384: if ($hashref->{'default'} eq $option) {
10385: $checked = ' checked="checked"';
10386: }
1.303 raeburn 10387: }
10388: } else {
1.305 raeburn 10389: if (!exists($hashref->{$type})) {
10390: if ($option eq $defoption) {
10391: $checked = ' checked="checked"';
10392: }
10393: } else {
10394: if ($hashref->{$type} eq $option) {
10395: $checked = ' checked="checked"';
10396: }
1.303 raeburn 10397: }
10398: }
1.305 raeburn 10399: } elsif (($item eq 'email') && ($hascustom)) {
10400: if ($option eq 'custom') {
10401: $checked = ' checked="checked"';
10402: }
10403: } elsif ($option eq $defoption) {
10404: $checked = ' checked="checked"';
10405: }
10406: $output .= '<span class="LC_nobreak"><label>'.
10407: '<input type="radio" name="'.$name.'"'.
10408: $checked.' value="'.$option.'"'.$onclick.' />'.
10409: $choices{$option}.'</label></span><br />';
10410: if ($item eq 'email') {
10411: if ($option eq 'custom') {
10412: my $id = 'cancreate_emailrule_'.$type;
10413: my $display = 'none';
10414: if ($checked) {
10415: $display = 'inline';
1.303 raeburn 10416: }
1.305 raeburn 10417: my $numinrow = 2;
10418: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10419: '<legend>'.&mt('Disallow').'</legend><table>'.
10420: &user_formats_row('email',$settings,$emailrules,
10421: $emailruleorder,$numinrow,'',$type);
10422: '</table></fieldset>';
10423: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10424: my %text = &Apache::lonlocal::texthash (
10425: inst => 'must end:',
10426: noninst => 'cannot end:',
10427: );
10428: my $value;
10429: if (ref($emaildomain) eq 'HASH') {
10430: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10431: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10432: }
10433: }
1.305 raeburn 10434: if ($value eq '') {
10435: $value = '@'.$intdom;
10436: }
10437: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10438: my $display = 'none';
10439: if ($checked) {
10440: $display = 'inline';
10441: }
10442: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10443: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10444: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10445: '</div>';
1.303 raeburn 10446: }
10447: }
10448: }
1.305 raeburn 10449: $output .= '</td>'."\n";
1.303 raeburn 10450: }
1.305 raeburn 10451: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10452: return $output;
10453: }
10454:
1.165 raeburn 10455: sub captcha_choice {
1.305 raeburn 10456: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10457: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10458: $vertext,$currver);
1.165 raeburn 10459: my %lt = &captcha_phrases();
10460: $keyentry = 'hidden';
1.354 raeburn 10461: my $colspan=2;
1.165 raeburn 10462: if ($context eq 'cancreate') {
1.224 raeburn 10463: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10464: } elsif ($context eq 'login') {
10465: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10466: } elsif ($context eq 'passwords') {
10467: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10468: $colspan=1;
1.165 raeburn 10469: }
10470: if (ref($settings) eq 'HASH') {
10471: if ($settings->{'captcha'}) {
10472: $checked{$settings->{'captcha'}} = ' checked="checked"';
10473: } else {
10474: $checked{'original'} = ' checked="checked"';
10475: }
10476: if ($settings->{'captcha'} eq 'recaptcha') {
10477: $pubtext = $lt{'pub'};
10478: $privtext = $lt{'priv'};
10479: $keyentry = 'text';
1.269 raeburn 10480: $vertext = $lt{'ver'};
10481: $currver = $settings->{'recaptchaversion'};
10482: if ($currver ne '2') {
10483: $currver = 1;
10484: }
1.165 raeburn 10485: }
10486: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10487: $currpub = $settings->{'recaptchakeys'}{'public'};
10488: $currpriv = $settings->{'recaptchakeys'}{'private'};
10489: }
10490: } else {
10491: $checked{'original'} = ' checked="checked"';
10492: }
1.305 raeburn 10493: my $css_class;
10494: if ($itemcount%2) {
10495: $css_class = 'LC_odd_row';
10496: }
10497: if ($customcss) {
10498: $css_class .= " $customcss";
10499: }
10500: $css_class =~ s/^\s+//;
10501: if ($css_class) {
10502: $css_class = ' class="'.$css_class.'"';
10503: }
10504: if ($rowstyle) {
10505: $css_class .= ' style="'.$rowstyle.'"';
10506: }
1.169 raeburn 10507: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10508: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10509: '<table><tr><td>'."\n";
10510: foreach my $option ('original','recaptcha','notused') {
10511: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10512: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10513: $lt{$option}.'</label></span>';
10514: unless ($option eq 'notused') {
10515: $output .= (' 'x2)."\n";
10516: }
10517: }
10518: #
10519: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10520: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10521: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10522: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10523: #
1.165 raeburn 10524: $output .= '</td></tr>'."\n".
1.305 raeburn 10525: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10526: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10527: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10528: $currpub.'" size="40" /></span><br />'."\n".
10529: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10530: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10531: $currpriv.'" size="40" /></span><br />'.
10532: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10533: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10534: $currver.'" size="3" /></span><br />'.
10535: '</td></tr></table>'."\n".
1.165 raeburn 10536: '</td></tr>';
10537: return $output;
10538: }
10539:
1.32 raeburn 10540: sub user_formats_row {
1.305 raeburn 10541: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10542: my $output;
10543: my %text = (
10544: 'username' => 'new usernames',
10545: 'id' => 'IDs',
10546: );
1.409 raeburn 10547: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10548: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10549: $output = '<tr '.$css_class.'>'.
10550: '<td><span class="LC_nobreak">'.
10551: &mt("Format rules to check for $text{$type}: ").
10552: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10553: }
1.27 raeburn 10554: my $rem;
10555: if (ref($ruleorder) eq 'ARRAY') {
10556: for (my $i=0; $i<@{$ruleorder}; $i++) {
10557: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10558: my $rem = $i%($numinrow);
10559: if ($rem == 0) {
10560: if ($i > 0) {
10561: $output .= '</tr>';
10562: }
10563: $output .= '<tr>';
10564: }
10565: my $check = ' ';
1.39 raeburn 10566: if (ref($settings) eq 'HASH') {
10567: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10568: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10569: $check = ' checked="checked" ';
10570: }
1.305 raeburn 10571: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10572: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10573: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10574: $check = ' checked="checked" ';
10575: }
10576: }
1.27 raeburn 10577: }
10578: }
1.305 raeburn 10579: my $name = $type.'_rule';
10580: if ($type eq 'email') {
10581: $name .= '_'.$status;
10582: }
1.27 raeburn 10583: $output .= '<td class="LC_left_item">'.
10584: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10585: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10586: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10587: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10588: }
10589: }
10590: $rem = @{$ruleorder}%($numinrow);
10591: }
1.305 raeburn 10592: my $colsleft;
10593: if ($rem) {
10594: $colsleft = $numinrow - $rem;
10595: }
1.27 raeburn 10596: if ($colsleft > 1 ) {
10597: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10598: ' </td>';
10599: } elsif ($colsleft == 1) {
10600: $output .= '<td class="LC_left_item"> </td>';
10601: }
1.409 raeburn 10602: $output .= '</tr>';
10603: unless (($type eq 'email') || ($type eq 'unamemap')) {
10604: $output .= '</table></td></tr>';
1.305 raeburn 10605: }
1.27 raeburn 10606: return $output;
10607: }
10608:
1.34 raeburn 10609: sub usercreation_types {
10610: my %lt = &Apache::lonlocal::texthash (
10611: author => 'When adding a co-author',
10612: course => 'When adding a user to a course',
1.100 raeburn 10613: requestcrs => 'When requesting a course',
1.34 raeburn 10614: any => 'Any',
10615: official => 'Institutional only ',
10616: unofficial => 'Non-institutional only',
10617: none => 'None',
10618: );
10619: return %lt;
1.48 raeburn 10620: }
1.34 raeburn 10621:
1.224 raeburn 10622: sub selfcreation_types {
10623: my %lt = &Apache::lonlocal::texthash (
10624: selfcreate => 'User creates own account',
10625: any => 'Any',
10626: official => 'Institutional only ',
10627: unofficial => 'Non-institutional only',
10628: email => 'E-mail address',
10629: login => 'Institutional Login',
10630: sso => 'SSO',
10631: );
10632: }
10633:
1.28 raeburn 10634: sub authtype_names {
10635: my %lt = &Apache::lonlocal::texthash(
10636: int => 'Internal',
10637: krb4 => 'Kerberos 4',
10638: krb5 => 'Kerberos 5',
10639: loc => 'Local',
1.325 raeburn 10640: lti => 'LTI',
1.28 raeburn 10641: );
10642: return %lt;
10643: }
10644:
10645: sub context_names {
10646: my %context_title = &Apache::lonlocal::texthash(
10647: author => 'Creating users when an Author',
10648: course => 'Creating users when in a course',
10649: domain => 'Creating users when a Domain Coordinator',
10650: );
10651: return %context_title;
10652: }
10653:
1.33 raeburn 10654: sub print_usermodification {
10655: my ($position,$dom,$settings,$rowtotal) = @_;
10656: my $numinrow = 4;
10657: my ($context,$datatable,$rowcount);
10658: if ($position eq 'top') {
10659: $rowcount = 0;
10660: $context = 'author';
10661: foreach my $role ('ca','aa') {
10662: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10663: $numinrow,$rowcount);
10664: $$rowtotal ++;
10665: $rowcount ++;
10666: }
1.443 raeburn 10667: } elsif ($position eq 'middle') {
10668: $rowcount = 0;
10669: $context = 'coauthor';
10670: foreach my $role ('ca','aa') {
10671: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10672: $numinrow,$rowcount);
10673: $$rowtotal ++;
10674: $rowcount ++;
10675: }
1.230 raeburn 10676: } elsif ($position eq 'bottom') {
1.33 raeburn 10677: $context = 'course';
10678: $rowcount = 0;
10679: foreach my $role ('st','ep','ta','in','cr') {
10680: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10681: $numinrow,$rowcount);
10682: $$rowtotal ++;
10683: $rowcount ++;
10684: }
10685: }
10686: return $datatable;
10687: }
10688:
1.43 raeburn 10689: sub print_defaults {
1.236 raeburn 10690: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10691: my $rownum = 0;
1.294 raeburn 10692: my ($datatable,$css_class,$titles);
10693: unless ($position eq 'bottom') {
10694: $titles = &defaults_titles($dom);
10695: }
1.236 raeburn 10696: if ($position eq 'top') {
10697: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10698: 'datelocale_def','portal_def');
10699: my %defaults;
10700: if (ref($settings) eq 'HASH') {
10701: %defaults = %{$settings};
1.43 raeburn 10702: } else {
1.236 raeburn 10703: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10704: foreach my $item (@items) {
10705: $defaults{$item} = $domdefaults{$item};
10706: }
1.43 raeburn 10707: }
1.236 raeburn 10708: foreach my $item (@items) {
10709: if ($rownum%2) {
10710: $css_class = '';
10711: } else {
10712: $css_class = ' class="LC_odd_row" ';
10713: }
10714: $datatable .= '<tr'.$css_class.'>'.
10715: '<td><span class="LC_nobreak">'.$titles->{$item}.
10716: '</span></td><td class="LC_right_item" colspan="3">';
10717: if ($item eq 'auth_def') {
1.325 raeburn 10718: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10719: my %shortauth = (
10720: internal => 'int',
10721: krb4 => 'krb4',
10722: krb5 => 'krb5',
1.325 raeburn 10723: localauth => 'loc',
10724: lti => 'lti',
1.236 raeburn 10725: );
10726: my %authnames = &authtype_names();
10727: foreach my $auth (@authtypes) {
10728: my $checked = ' ';
10729: if ($defaults{$item} eq $auth) {
10730: $checked = ' checked="checked" ';
10731: }
10732: $datatable .= '<label><input type="radio" name="'.$item.
10733: '" value="'.$auth.'"'.$checked.'/>'.
10734: $authnames{$shortauth{$auth}}.'</label> ';
10735: }
10736: } elsif ($item eq 'timezone_def') {
10737: my $includeempty = 1;
10738: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10739: } elsif ($item eq 'datelocale_def') {
10740: my $includeempty = 1;
10741: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10742: } elsif ($item eq 'lang_def') {
1.263 raeburn 10743: my $includeempty = 1;
10744: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10745: } elsif ($item eq 'portal_def') {
10746: $datatable .= '<input type="text" name="'.$item.'" value="'.
10747: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10748: my $portalsty = 'none';
10749: if ($defaults{$item}) {
10750: $portalsty = 'block';
10751: }
10752: foreach my $field ('email','web') {
10753: my $checkedoff = ' checked="checked"';
10754: my $checkedon;
10755: if ($defaults{$item.'_'.$field}) {
10756: $checkedon = $checkedoff;
10757: $checkedoff = '';
1.425 raeburn 10758: }
1.414 raeburn 10759: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10760: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10761: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10762: (' 'x2).
10763: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10764: '</div>';
10765: }
1.236 raeburn 10766: } else {
1.414 raeburn 10767: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10768: }
1.236 raeburn 10769: $datatable .= '</td></tr>';
10770: $rownum ++;
10771: }
1.409 raeburn 10772: } elsif ($position eq 'middle') {
1.294 raeburn 10773: my %defaults;
10774: if (ref($settings) eq 'HASH') {
1.354 raeburn 10775: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10776: my $maxnum = @{$settings->{'inststatusorder'}};
10777: for (my $i=0; $i<$maxnum; $i++) {
10778: $css_class = $rownum%2?' class="LC_odd_row"':'';
10779: my $item = $settings->{'inststatusorder'}->[$i];
10780: my $title = $settings->{'inststatustypes'}->{$item};
10781: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10782: $datatable .= '<tr'.$css_class.'>'.
10783: '<td><span class="LC_nobreak">'.
10784: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10785: for (my $k=0; $k<=$maxnum; $k++) {
10786: my $vpos = $k+1;
10787: my $selstr;
10788: if ($k == $i) {
10789: $selstr = ' selected="selected" ';
10790: }
10791: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10792: }
10793: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10794: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10795: &mt('delete').'</span></td>'.
1.380 raeburn 10796: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10797: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10798: '</span></td></tr>';
10799: }
10800: $css_class = $rownum%2?' class="LC_odd_row"':'';
10801: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10802: $datatable .= '<tr '.$css_class.'>'.
10803: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10804: for (my $k=0; $k<=$maxnum; $k++) {
10805: my $vpos = $k+1;
10806: my $selstr;
10807: if ($k == $maxnum) {
10808: $selstr = ' selected="selected" ';
10809: }
10810: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10811: }
10812: $datatable .= '</select> '.&mt('Internal ID:').
10813: '<input type="text" size="10" name="addinststatus" value="" />'.
10814: ' '.&mt('(new)').
10815: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10816: &mt('Name displayed').':'.
1.354 raeburn 10817: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10818: '</tr>'."\n";
10819: $rownum ++;
1.294 raeburn 10820: }
1.354 raeburn 10821: }
1.409 raeburn 10822: } else {
10823: my ($unamemaprules,$ruleorder) =
10824: &Apache::lonnet::inst_userrules($dom,'unamemap');
10825: $css_class = $rownum%2?' class="LC_odd_row"':'';
10826: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10827: my $numinrow = 2;
10828: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10829: &user_formats_row('unamemap',$settings,$unamemaprules,
10830: $ruleorder,$numinrow).
10831: '</table></td></tr>';
10832: }
10833: if ($datatable eq '') {
10834: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10835: &mt('No rules set for domain in customized localenroll.pm').
10836: '</td></tr>';
10837: }
1.354 raeburn 10838: }
10839: $$rowtotal += $rownum;
1.43 raeburn 10840: return $datatable;
10841: }
10842:
1.168 raeburn 10843: sub get_languages_hash {
10844: my %langchoices;
10845: foreach my $id (&Apache::loncommon::languageids()) {
10846: my $code = &Apache::loncommon::supportedlanguagecode($id);
10847: if ($code ne '') {
10848: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10849: }
10850: }
10851: return %langchoices;
10852: }
10853:
1.43 raeburn 10854: sub defaults_titles {
1.141 raeburn 10855: my ($dom) = @_;
1.43 raeburn 10856: my %titles = &Apache::lonlocal::texthash (
10857: 'auth_def' => 'Default authentication type',
10858: 'auth_arg_def' => 'Default authentication argument',
10859: 'lang_def' => 'Default language',
1.54 raeburn 10860: 'timezone_def' => 'Default timezone',
1.68 raeburn 10861: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10862: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10863: 'email' => 'Email links use portal URL',
10864: 'web' => 'Public web links use portal URL',
1.294 raeburn 10865: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10866: 'intauth_check' => 'Check bcrypt cost if authenticated',
10867: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10868: );
1.141 raeburn 10869: if ($dom) {
10870: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10871: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10872: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10873: $protocol = 'http' if ($protocol ne 'https');
10874: if ($uint_dom) {
10875: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10876: $uint_dom);
10877: }
10878: }
1.43 raeburn 10879: return (\%titles);
10880: }
10881:
1.346 raeburn 10882: sub print_scantron {
10883: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10884: if ($position eq 'top') {
10885: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10886: } else {
10887: return &print_scantronconfig($dom,$settings,\$rowtotal);
10888: }
10889: }
10890:
10891: sub scantron_javascript {
10892: return <<"ENDSCRIPT";
10893:
10894: <script type="text/javascript">
10895: // <![CDATA[
10896:
10897: function toggleScantron(form) {
1.347 raeburn 10898: var csvfieldset = new Array();
1.346 raeburn 10899: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10900: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10901: }
10902: if (document.getElementById('scantroncsv_options')) {
10903: csvfieldset.push(document.getElementById('scantroncsv_options'));
10904: }
10905: if (csvfieldset.length) {
1.346 raeburn 10906: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10907: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10908: if (scantroncsv.checked) {
1.347 raeburn 10909: for (var i=0; i<csvfieldset.length; i++) {
10910: csvfieldset[i].style.display = 'block';
10911: }
1.346 raeburn 10912: } else {
1.347 raeburn 10913: for (var i=0; i<csvfieldset.length; i++) {
10914: csvfieldset[i].style.display = 'none';
10915: }
1.346 raeburn 10916: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10917: if (csvselects.length) {
10918: for (var j=0; j<csvselects.length; j++) {
10919: csvselects[j].selectedIndex = 0;
10920: }
10921: }
10922: }
10923: }
10924: }
10925: return;
10926: }
10927: // ]]>
10928: </script>
10929:
10930: ENDSCRIPT
10931:
10932: }
10933:
1.46 raeburn 10934: sub print_scantronformat {
10935: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10936: my $itemcount = 1;
1.60 raeburn 10937: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10938: %confhash);
1.46 raeburn 10939: my $switchserver = &check_switchserver($dom,$confname);
10940: my %lt = &Apache::lonlocal::texthash (
1.95 www 10941: default => 'Default bubblesheet format file error',
10942: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10943: );
10944: my %scantronfiles = (
10945: default => 'default.tab',
10946: custom => 'custom.tab',
10947: );
10948: foreach my $key (keys(%scantronfiles)) {
10949: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10950: .$scantronfiles{$key};
10951: }
10952: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10953: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10954: if (!$switchserver) {
10955: my $servadm = $r->dir_config('lonAdmEMail');
10956: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10957: if ($configuserok eq 'ok') {
10958: if ($author_ok eq 'ok') {
10959: my %legacyfile = (
1.346 raeburn 10960: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10961: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10962: );
10963: my %md5chk;
10964: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10965: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10966: chomp($md5chk{$type});
1.46 raeburn 10967: }
10968: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10969: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10970: ($scantronurls{$type},my $error) =
1.46 raeburn 10971: &legacy_scantronformat($r,$dom,$confname,
10972: $type,$legacyfile{$type},
10973: $scantronurls{$type},
10974: $scantronfiles{$type});
1.60 raeburn 10975: if ($error ne '') {
10976: $error{$type} = $error;
10977: }
10978: }
10979: if (keys(%error) == 0) {
10980: $is_custom = 1;
1.346 raeburn 10981: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10982: $scantronurls{'custom'};
1.346 raeburn 10983: my $putresult =
1.60 raeburn 10984: &Apache::lonnet::put_dom('configuration',
10985: \%confhash,$dom);
10986: if ($putresult ne 'ok') {
1.346 raeburn 10987: $error{'custom'} =
1.60 raeburn 10988: '<span class="LC_error">'.
10989: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10990: }
1.46 raeburn 10991: }
10992: } else {
1.60 raeburn 10993: ($scantronurls{'default'},my $error) =
1.46 raeburn 10994: &legacy_scantronformat($r,$dom,$confname,
10995: 'default',$legacyfile{'default'},
10996: $scantronurls{'default'},
10997: $scantronfiles{'default'});
1.60 raeburn 10998: if ($error eq '') {
10999: $confhash{'scantron'}{'scantronformat'} = '';
11000: my $putresult =
11001: &Apache::lonnet::put_dom('configuration',
11002: \%confhash,$dom);
11003: if ($putresult ne 'ok') {
11004: $error{'default'} =
11005: '<span class="LC_error">'.
11006: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11007: }
11008: } else {
11009: $error{'default'} = $error;
11010: }
1.46 raeburn 11011: }
11012: }
11013: }
11014: } else {
1.95 www 11015: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 11016: }
11017: }
11018: if (ref($settings) eq 'HASH') {
11019: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
11020: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
11021: if ((!@info) || ($info[0] eq 'no_such_dir')) {
11022: $scantronurl = '';
11023: } else {
11024: $scantronurl = $settings->{'scantronformat'};
11025: }
11026: $is_custom = 1;
11027: } else {
11028: $scantronurl = $scantronurls{'default'};
11029: }
11030: } else {
1.60 raeburn 11031: if ($is_custom) {
11032: $scantronurl = $scantronurls{'custom'};
11033: } else {
11034: $scantronurl = $scantronurls{'default'};
11035: }
1.46 raeburn 11036: }
11037: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11038: $datatable .= '<tr'.$css_class.'>';
11039: if (!$is_custom) {
1.65 raeburn 11040: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
11041: '<span class="LC_nobreak">';
1.46 raeburn 11042: if ($scantronurl) {
1.199 raeburn 11043: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
11044: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 11045: } else {
11046: $datatable = &mt('File unavailable for display');
11047: }
1.65 raeburn 11048: $datatable .= '</span></td>';
1.60 raeburn 11049: if (keys(%error) == 0) {
1.306 raeburn 11050: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 11051: if (!$switchserver) {
11052: $datatable .= &mt('Upload:').'<br />';
11053: }
11054: } else {
11055: my $errorstr;
11056: foreach my $key (sort(keys(%error))) {
11057: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11058: }
11059: $datatable .= '<td>'.$errorstr;
11060: }
1.46 raeburn 11061: } else {
11062: if (keys(%error) > 0) {
11063: my $errorstr;
11064: foreach my $key (sort(keys(%error))) {
11065: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11066: }
1.60 raeburn 11067: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 11068: } elsif ($scantronurl) {
1.199 raeburn 11069: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
11070: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 11071: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 11072: $link.
11073: '<label><input type="checkbox" name="scantronformat_del"'.
11074: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 11075: '<td><span class="LC_nobreak"> '.
11076: &mt('Replace:').'</span><br />';
1.46 raeburn 11077: }
11078: }
11079: if (keys(%error) == 0) {
11080: if ($switchserver) {
11081: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
11082: } else {
1.65 raeburn 11083: $datatable .='<span class="LC_nobreak"> '.
11084: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11085: }
11086: }
11087: $datatable .= '</td></tr>';
11088: $$rowtotal ++;
11089: return $datatable;
11090: }
11091:
11092: sub legacy_scantronformat {
11093: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11094: my ($url,$error);
11095: my @statinfo = &Apache::lonnet::stat_file($newurl);
11096: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 11097: my $modified = [];
1.46 raeburn 11098: (my $result,$url) =
1.421 raeburn 11099: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
11100: 'scantron','','',$newfile,$modified);
11101: if ($result eq 'ok') {
11102: &update_modify_urls($r,$modified);
11103: } else {
1.130 raeburn 11104: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11105: }
11106: }
11107: return ($url,$error);
11108: }
1.43 raeburn 11109:
1.346 raeburn 11110: sub print_scantronconfig {
11111: my ($dom,$settings,$rowtotal) = @_;
11112: my $itemcount = 2;
11113: my $is_checked = ' checked="checked"';
1.347 raeburn 11114: my %optionson = (
11115: hdr => ' checked="checked"',
11116: pad => ' checked="checked"',
11117: rem => ' checked="checked"',
11118: );
11119: my %optionsoff = (
11120: hdr => '',
11121: pad => '',
11122: rem => '',
11123: );
1.346 raeburn 11124: my $currcsvsty = 'none';
1.347 raeburn 11125: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11126: my @fields = &scantroncsv_fields();
11127: my %titles = &scantronconfig_titles();
11128: if (ref($settings) eq 'HASH') {
11129: if (ref($settings->{config}) eq 'HASH') {
11130: if ($settings->{config}->{dat}) {
11131: $checked{'dat'} = $is_checked;
11132: }
11133: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11134: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11135: %csvfields = %{$settings->{config}->{csv}->{fields}};
11136: if (keys(%csvfields) > 0) {
11137: $checked{'csv'} = $is_checked;
11138: $currcsvsty = 'block';
11139: }
11140: }
11141: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11142: %csvoptions = %{$settings->{config}->{csv}->{options}};
11143: foreach my $option (keys(%optionson)) {
11144: unless ($csvoptions{$option}) {
11145: $optionsoff{$option} = $optionson{$option};
11146: $optionson{$option} = '';
11147: }
11148: }
1.346 raeburn 11149: }
11150: }
11151: } else {
11152: $checked{'dat'} = $is_checked;
11153: }
11154: } else {
11155: $checked{'dat'} = $is_checked;
11156: }
11157: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11158: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11159: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11160: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11161: foreach my $item ('dat','csv') {
11162: my $id;
11163: if ($item eq 'csv') {
11164: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11165: }
1.346 raeburn 11166: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11167: $titles{$item}.'</label>'.(' 'x3);
11168: if ($item eq 'csv') {
11169: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11170: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11171: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11172: foreach my $col (@fields) {
11173: my $selnone;
11174: if ($csvfields{$col} eq '') {
11175: $selnone = ' selected="selected"';
11176: }
11177: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11178: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11179: '<option value=""'.$selnone.'></option>';
11180: for (my $i=0; $i<20; $i++) {
11181: my $shown = $i+1;
11182: my $sel;
11183: unless ($selnone) {
11184: if (exists($csvfields{$col})) {
11185: if ($csvfields{$col} == $i) {
11186: $sel = ' selected="selected"';
11187: }
11188: }
11189: }
11190: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11191: }
11192: $datatable .= '</select></td></tr>';
11193: }
1.347 raeburn 11194: $datatable .= '</table></fieldset>'.
11195: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11196: '<legend>'.&mt('CSV Options').'</legend>';
11197: foreach my $option ('hdr','pad','rem') {
11198: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11199: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11200: &mt('Yes').'</label>'.(' 'x2)."\n".
11201: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11202: }
11203: $datatable .= '</fieldset>';
1.346 raeburn 11204: $itemcount ++;
11205: }
11206: }
11207: $datatable .= '</td></tr>';
11208: $$rowtotal ++;
11209: return $datatable;
11210: }
11211:
11212: sub scantronconfig_titles {
11213: return &Apache::lonlocal::texthash(
11214: dat => 'Standard format (.dat)',
11215: csv => 'Comma separated values (.csv)',
1.347 raeburn 11216: hdr => 'Remove first line in file (contains column titles)',
11217: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11218: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11219: CODE => 'CODE',
11220: ID => 'Student ID',
11221: PaperID => 'Paper ID',
11222: FirstName => 'First Name',
11223: LastName => 'Last Name',
11224: FirstQuestion => 'First Question Response',
11225: Section => 'Section',
11226: );
11227: }
11228:
11229: sub scantroncsv_fields {
11230: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11231: }
11232:
1.49 raeburn 11233: sub print_coursecategories {
1.57 raeburn 11234: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11235: my $datatable;
11236: if ($position eq 'top') {
1.238 raeburn 11237: my (%checked);
11238: my @catitems = ('unauth','auth');
11239: my @cattypes = ('std','domonly','codesrch','none');
11240: $checked{'unauth'} = 'std';
11241: $checked{'auth'} = 'std';
11242: if (ref($settings) eq 'HASH') {
11243: foreach my $type (@cattypes) {
11244: if ($type eq $settings->{'unauth'}) {
11245: $checked{'unauth'} = $type;
11246: }
11247: if ($type eq $settings->{'auth'}) {
11248: $checked{'auth'} = $type;
11249: }
11250: }
11251: }
11252: my %lt = &Apache::lonlocal::texthash (
11253: unauth => 'Catalog type for unauthenticated users',
11254: auth => 'Catalog type for authenticated users',
11255: none => 'No catalog',
11256: std => 'Standard catalog',
11257: domonly => 'Domain-only catalog',
11258: codesrch => "Code search form",
11259: );
11260: my $itemcount = 0;
11261: foreach my $item (@catitems) {
11262: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11263: $datatable .= '<tr '.$css_class.'>'.
11264: '<td>'.$lt{$item}.'</td>'.
11265: '<td class="LC_right_item"><span class="LC_nobreak">';
11266: foreach my $type (@cattypes) {
11267: my $ischecked;
11268: if ($checked{$item} eq $type) {
11269: $ischecked=' checked="checked"';
11270: }
11271: $datatable .= '<label>'.
11272: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11273: ' />'.$lt{$type}.'</label> ';
11274: }
1.327 raeburn 11275: $datatable .= '</span></td></tr>';
1.238 raeburn 11276: $itemcount ++;
11277: }
11278: $$rowtotal += $itemcount;
11279: } elsif ($position eq 'middle') {
1.57 raeburn 11280: my $toggle_cats_crs = ' ';
11281: my $toggle_cats_dom = ' checked="checked" ';
11282: my $can_cat_crs = ' ';
11283: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11284: my $toggle_catscomm_comm = ' ';
11285: my $toggle_catscomm_dom = ' checked="checked" ';
11286: my $can_catcomm_comm = ' ';
11287: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11288: my $toggle_catsplace_place = ' ';
11289: my $toggle_catsplace_dom = ' checked="checked" ';
11290: my $can_catplace_place = ' ';
11291: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11292:
1.57 raeburn 11293: if (ref($settings) eq 'HASH') {
11294: if ($settings->{'togglecats'} eq 'crs') {
11295: $toggle_cats_crs = $toggle_cats_dom;
11296: $toggle_cats_dom = ' ';
11297: }
11298: if ($settings->{'categorize'} eq 'crs') {
11299: $can_cat_crs = $can_cat_dom;
11300: $can_cat_dom = ' ';
11301: }
1.120 raeburn 11302: if ($settings->{'togglecatscomm'} eq 'comm') {
11303: $toggle_catscomm_comm = $toggle_catscomm_dom;
11304: $toggle_catscomm_dom = ' ';
11305: }
11306: if ($settings->{'categorizecomm'} eq 'comm') {
11307: $can_catcomm_comm = $can_catcomm_dom;
11308: $can_catcomm_dom = ' ';
11309: }
1.272 raeburn 11310: if ($settings->{'togglecatsplace'} eq 'place') {
11311: $toggle_catsplace_place = $toggle_catsplace_dom;
11312: $toggle_catsplace_dom = ' ';
11313: }
11314: if ($settings->{'categorizeplace'} eq 'place') {
11315: $can_catplace_place = $can_catplace_dom;
11316: $can_catplace_dom = ' ';
11317: }
1.57 raeburn 11318: }
11319: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11320: togglecats => 'Show/Hide a course in catalog',
11321: togglecatscomm => 'Show/Hide a community in catalog',
11322: togglecatsplace => 'Show/Hide a placement test in catalog',
11323: categorize => 'Assign a category to a course',
11324: categorizecomm => 'Assign a category to a community',
11325: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11326: );
11327: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11328: dom => 'Set in Domain',
11329: crs => 'Set in Course',
11330: comm => 'Set in Community',
11331: place => 'Set in Placement Test',
1.57 raeburn 11332: );
11333: $datatable = '<tr class="LC_odd_row">'.
11334: '<td>'.$title{'togglecats'}.'</td>'.
11335: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11336: '<input type="radio" name="togglecats"'.
11337: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11338: '<label><input type="radio" name="togglecats"'.
11339: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11340: '</tr><tr>'.
11341: '<td>'.$title{'categorize'}.'</td>'.
11342: '<td class="LC_right_item"><span class="LC_nobreak">'.
11343: '<label><input type="radio" name="categorize"'.
11344: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11345: '<label><input type="radio" name="categorize"'.
11346: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11347: '</tr><tr class="LC_odd_row">'.
11348: '<td>'.$title{'togglecatscomm'}.'</td>'.
11349: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11350: '<input type="radio" name="togglecatscomm"'.
11351: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11352: '<label><input type="radio" name="togglecatscomm"'.
11353: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11354: '</tr><tr>'.
11355: '<td>'.$title{'categorizecomm'}.'</td>'.
11356: '<td class="LC_right_item"><span class="LC_nobreak">'.
11357: '<label><input type="radio" name="categorizecomm"'.
11358: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11359: '<label><input type="radio" name="categorizecomm"'.
11360: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11361: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11362: '<td>'.$title{'togglecatsplace'}.'</td>'.
11363: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11364: '<input type="radio" name="togglecatsplace"'.
11365: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11366: '<label><input type="radio" name="togglecatscomm"'.
11367: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11368: '</tr><tr>'.
11369: '<td>'.$title{'categorizeplace'}.'</td>'.
11370: '<td class="LC_right_item"><span class="LC_nobreak">'.
11371: '<label><input type="radio" name="categorizeplace"'.
11372: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11373: '<label><input type="radio" name="categorizeplace"'.
11374: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11375: '</tr>';
1.272 raeburn 11376: $$rowtotal += 6;
1.57 raeburn 11377: } else {
11378: my $css_class;
11379: my $itemcount = 1;
11380: my $cathash;
11381: if (ref($settings) eq 'HASH') {
11382: $cathash = $settings->{'cats'};
11383: }
11384: if (ref($cathash) eq 'HASH') {
11385: my (@cats,@trails,%allitems,%idx,@jsarray);
11386: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11387: \%allitems,\%idx,\@jsarray);
11388: my $maxdepth = scalar(@cats);
11389: my $colattrib = '';
11390: if ($maxdepth > 2) {
11391: $colattrib = ' colspan="2" ';
11392: }
11393: my @path;
11394: if (@cats > 0) {
11395: if (ref($cats[0]) eq 'ARRAY') {
11396: my $numtop = @{$cats[0]};
11397: my $maxnum = $numtop;
1.120 raeburn 11398: my %default_names = (
11399: instcode => &mt('Official courses'),
11400: communities => &mt('Communities'),
1.272 raeburn 11401: placement => &mt('Placement Tests'),
1.120 raeburn 11402: );
11403:
11404: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11405: ($cathash->{'instcode::0'} eq '') ||
11406: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11407: ($cathash->{'communities::0'} eq '') ||
11408: (!grep(/^placement$/,@{$cats[0]})) ||
11409: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11410: $maxnum ++;
11411: }
11412: my $lastidx;
11413: for (my $i=0; $i<$numtop; $i++) {
11414: my $parent = $cats[0][$i];
11415: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11416: my $item = &escape($parent).'::0';
11417: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11418: $lastidx = $idx{$item};
11419: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11420: .'<select name="'.$item.'"'.$chgstr.'>';
11421: for (my $k=0; $k<=$maxnum; $k++) {
11422: my $vpos = $k+1;
11423: my $selstr;
11424: if ($k == $i) {
11425: $selstr = ' selected="selected" ';
11426: }
11427: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11428: }
1.214 raeburn 11429: $datatable .= '</select></span></td><td>';
1.272 raeburn 11430: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11431: $datatable .= '<span class="LC_nobreak">'
11432: .$default_names{$parent}.'</span>';
11433: if ($parent eq 'instcode') {
11434: $datatable .= '<br /><span class="LC_nobreak">('
11435: .&mt('with institutional codes')
11436: .')</span></td><td'.$colattrib.'>';
11437: } else {
11438: $datatable .= '<table><tr><td>';
11439: }
11440: $datatable .= '<span class="LC_nobreak">'
11441: .'<label><input type="radio" name="'
11442: .$parent.'" value="1" checked="checked" />'
11443: .&mt('Display').'</label>';
11444: if ($parent eq 'instcode') {
11445: $datatable .= ' ';
11446: } else {
11447: $datatable .= '</span></td></tr><tr><td>'
11448: .'<span class="LC_nobreak">';
11449: }
11450: $datatable .= '<label><input type="radio" name="'
11451: .$parent.'" value="0" />'
11452: .&mt('Do not display').'</label></span>';
1.272 raeburn 11453: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11454: $datatable .= '</td></tr></table>';
11455: }
11456: $datatable .= '</td>';
1.57 raeburn 11457: } else {
11458: $datatable .= $parent
1.214 raeburn 11459: .' <span class="LC_nobreak"><label>'
11460: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11461: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11462: }
11463: my $depth = 1;
11464: push(@path,$parent);
11465: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11466: pop(@path);
11467: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11468: $itemcount ++;
11469: }
1.48 raeburn 11470: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11471: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11472: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11473: for (my $k=0; $k<=$maxnum; $k++) {
11474: my $vpos = $k+1;
11475: my $selstr;
1.57 raeburn 11476: if ($k == $numtop) {
1.48 raeburn 11477: $selstr = ' selected="selected" ';
11478: }
11479: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11480: }
1.59 bisitz 11481: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11482: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11483: .'</tr>'."\n";
1.48 raeburn 11484: $itemcount ++;
1.272 raeburn 11485: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11486: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11487: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11488: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11489: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11490: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11491: for (my $k=0; $k<=$maxnum; $k++) {
11492: my $vpos = $k+1;
11493: my $selstr;
11494: if ($k == $maxnum) {
11495: $selstr = ' selected="selected" ';
11496: }
11497: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11498: }
1.120 raeburn 11499: $datatable .= '</select></span></td>'.
11500: '<td><span class="LC_nobreak">'.
11501: $default_names{$default}.'</span>';
11502: if ($default eq 'instcode') {
11503: $datatable .= '<br /><span class="LC_nobreak">('
11504: .&mt('with institutional codes').')</span>';
11505: }
11506: $datatable .= '</td>'
11507: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11508: .&mt('Display').'</label> '
11509: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11510: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11511: }
11512: }
11513: }
1.57 raeburn 11514: } else {
11515: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11516: }
11517: } else {
1.327 raeburn 11518: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11519: .&initialize_categories($itemcount);
1.48 raeburn 11520: }
1.57 raeburn 11521: $$rowtotal += $itemcount;
1.48 raeburn 11522: }
11523: return $datatable;
11524: }
11525:
1.69 raeburn 11526: sub print_serverstatuses {
11527: my ($dom,$settings,$rowtotal) = @_;
11528: my $datatable;
11529: my @pages = &serverstatus_pages();
11530: my (%namedaccess,%machineaccess);
11531: foreach my $type (@pages) {
11532: $namedaccess{$type} = '';
11533: $machineaccess{$type}= '';
11534: }
11535: if (ref($settings) eq 'HASH') {
11536: foreach my $type (@pages) {
11537: if (exists($settings->{$type})) {
11538: if (ref($settings->{$type}) eq 'HASH') {
11539: foreach my $key (keys(%{$settings->{$type}})) {
11540: if ($key eq 'namedusers') {
11541: $namedaccess{$type} = $settings->{$type}->{$key};
11542: } elsif ($key eq 'machines') {
11543: $machineaccess{$type} = $settings->{$type}->{$key};
11544: }
11545: }
11546: }
11547: }
11548: }
11549: }
1.81 raeburn 11550: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11551: my $rownum = 0;
11552: my $css_class;
11553: foreach my $type (@pages) {
11554: $rownum ++;
11555: $css_class = $rownum%2?' class="LC_odd_row"':'';
11556: $datatable .= '<tr'.$css_class.'>'.
11557: '<td><span class="LC_nobreak">'.
11558: $titles->{$type}.'</span></td>'.
11559: '<td class="LC_left_item">'.
11560: '<input type="text" name="'.$type.'_namedusers" '.
11561: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11562: '<td class="LC_right_item">'.
11563: '<span class="LC_nobreak">'.
11564: '<input type="text" name="'.$type.'_machines" '.
11565: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11566: '</span></td></tr>'."\n";
1.69 raeburn 11567: }
11568: $$rowtotal += $rownum;
11569: return $datatable;
11570: }
11571:
11572: sub serverstatus_pages {
11573: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11574: 'checksums','clusterstatus','certstatus','metadata_keywords',
11575: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11576: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11577: }
11578:
1.236 raeburn 11579: sub defaults_javascript {
11580: my ($settings) = @_;
1.354 raeburn 11581: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11582: my $portal_js = <<"ENDPORTAL";
11583:
11584: function portalExtras(caller) {
11585: var x = caller.value;
11586: var y = new Array('email','web');
1.425 raeburn 11587: for (var i=0; i<y.length; i++) {
1.414 raeburn 11588: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11589: var z = document.getElementById('portal_def_'+y[i]+'_div');
11590: if (x.length > 0) {
11591: z.style.display = 'block';
11592: } else {
11593: z.style.display = 'none';
11594: }
11595: }
11596: }
11597: }
11598: ENDPORTAL
1.236 raeburn 11599: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11600: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11601: if ($maxnum eq '') {
11602: $maxnum = 0;
11603: }
11604: $maxnum ++;
1.249 raeburn 11605: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11606: return <<"ENDSCRIPT";
11607: <script type="text/javascript">
11608: // <![CDATA[
11609: function reorderTypes(form,caller) {
11610: var changedVal;
11611: $jstext
11612: var newpos = 'addinststatus_pos';
11613: var current = new Array;
11614: var maxh = $maxnum;
11615: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11616: var oldVal;
11617: if (caller == newpos) {
11618: changedVal = newitemVal;
11619: } else {
11620: var curritem = 'inststatus_pos_'+caller;
11621: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11622: current[newitemVal] = newpos;
11623: }
11624: for (var i=0; i<inststatuses.length; i++) {
11625: if (inststatuses[i] != caller) {
11626: var elementName = 'inststatus_pos_'+inststatuses[i];
11627: if (form.elements[elementName]) {
11628: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11629: current[currVal] = elementName;
11630: }
11631: }
11632: }
11633: for (var j=0; j<maxh; j++) {
11634: if (current[j] == undefined) {
11635: oldVal = j;
11636: }
11637: }
11638: if (oldVal < changedVal) {
11639: for (var k=oldVal+1; k<=changedVal ; k++) {
11640: var elementName = current[k];
11641: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11642: }
11643: } else {
11644: for (var k=changedVal; k<oldVal; k++) {
11645: var elementName = current[k];
11646: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11647: }
11648: }
11649: return;
11650: }
11651:
1.414 raeburn 11652: $portal_js
11653:
11654: // ]]>
11655: </script>
11656:
11657: ENDSCRIPT
11658: } else {
11659: return <<"ENDSCRIPT";
11660: <script type="text/javascript">
11661: // <![CDATA[
11662: $portal_js
1.236 raeburn 11663: // ]]>
11664: </script>
11665:
11666: ENDSCRIPT
11667: }
1.354 raeburn 11668: return;
11669: }
11670:
11671: sub passwords_javascript {
1.405 raeburn 11672: my ($prefix) = @_;
11673: my %intalert;
11674: if ($prefix eq 'passwords') {
11675: %intalert = &Apache::lonlocal::texthash (
11676: 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.',
11677: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11678: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11679: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11680: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11681: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11682: );
1.421 raeburn 11683: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11684: %intalert = &Apache::lonlocal::texthash (
11685: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11686: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11687: );
11688: }
1.365 raeburn 11689: &js_escape(\%intalert);
11690: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11691: my $intauthjs;
1.405 raeburn 11692: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11693:
11694: function warnIntAuth(field) {
11695: if (field.name == 'intauth_check') {
11696: if (field.value == '2') {
1.365 raeburn 11697: alert('$intalert{authcheck}');
1.354 raeburn 11698: }
11699: }
11700: if (field.name == 'intauth_cost') {
11701: field.value.replace(/\s/g,'');
11702: if (field.value != '') {
11703: var regexdigit=/^\\d+\$/;
11704: if (!regexdigit.test(field.value)) {
1.365 raeburn 11705: alert('$intalert{authcost}');
11706: }
11707: }
11708: }
11709: return;
11710: }
11711:
1.405 raeburn 11712: ENDSCRIPT
11713:
11714: }
11715:
11716: $intauthjs .= <<"ENDSCRIPT";
11717:
11718: function warnInt$prefix(field) {
1.365 raeburn 11719: field.value.replace(/^\s+/,'');
11720: field.value.replace(/\s+\$/,'');
11721: var regexdigit=/^\\d+\$/;
1.408 raeburn 11722: if (field.name == '${prefix}_min') {
1.365 raeburn 11723: if (field.value == '') {
11724: alert('$intalert{passmin}');
11725: field.value = '$defmin';
11726: } else {
11727: if (!regexdigit.test(field.value)) {
11728: alert('$intalert{passmin}');
11729: field.value = '$defmin';
11730: }
1.366 raeburn 11731: var minval = parseInt(field.value,10);
1.365 raeburn 11732: if (minval < $defmin) {
11733: alert('$intalert{passmin}');
11734: field.value = '$defmin';
11735: }
11736: }
11737: } else {
11738: if (field.value == '0') {
11739: field.value = '';
11740: }
11741: if (field.value != '') {
1.447.2.5! raeburn 11742: if (!regexdigit.test(field.value)) {
! 11743: if (field.name == '${prefix}_max') {
! 11744: alert('$intalert{passmax}');
1.365 raeburn 11745: } else {
1.447.2.5! raeburn 11746: if (field.name == '${prefix}_numsaved') {
! 11747: alert('$intalert{passnum}');
1.365 raeburn 11748: }
11749: }
1.447.2.5! raeburn 11750: field.value = '';
1.354 raeburn 11751: }
11752: }
11753: }
11754: return;
11755: }
11756:
11757: ENDSCRIPT
11758: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11759: }
11760:
1.49 raeburn 11761: sub coursecategories_javascript {
11762: my ($settings) = @_;
1.57 raeburn 11763: my ($output,$jstext,$cathash);
1.49 raeburn 11764: if (ref($settings) eq 'HASH') {
1.57 raeburn 11765: $cathash = $settings->{'cats'};
11766: }
11767: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11768: my (@cats,@jsarray,%idx);
1.57 raeburn 11769: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11770: if (@jsarray > 0) {
11771: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11772: for (my $i=0; $i<@jsarray; $i++) {
11773: if (ref($jsarray[$i]) eq 'ARRAY') {
11774: my $catstr = join('","',@{$jsarray[$i]});
11775: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11776: }
11777: }
11778: }
11779: } else {
11780: $jstext = ' var categories = Array(1);'."\n".
11781: ' categories[0] = Array("instcode_pos");'."\n";
11782: }
1.237 bisitz 11783: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11784: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11785: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11786: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11787: &js_escape(\$instcode_reserved);
11788: &js_escape(\$communities_reserved);
1.272 raeburn 11789: &js_escape(\$placement_reserved);
1.265 damieng 11790: &js_escape(\$choose_again);
1.49 raeburn 11791: $output = <<"ENDSCRIPT";
11792: <script type="text/javascript">
1.109 raeburn 11793: // <![CDATA[
1.49 raeburn 11794: function reorderCats(form,parent,item,idx) {
11795: var changedVal;
11796: $jstext
11797: var newpos = 'addcategory_pos';
11798: if (parent == '') {
11799: var has_instcode = 0;
11800: var maxtop = categories[idx].length;
11801: for (var j=0; j<maxtop; j++) {
11802: if (categories[idx][j] == 'instcode::0') {
11803: has_instcode == 1;
11804: }
11805: }
11806: if (has_instcode == 0) {
11807: categories[idx][maxtop] = 'instcode_pos';
11808: }
11809: } else {
11810: newpos += '_'+parent;
11811: }
11812: var maxh = 1 + categories[idx].length;
11813: var current = new Array;
11814: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11815: if (item == newpos) {
11816: changedVal = newitemVal;
11817: } else {
11818: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11819: current[newitemVal] = newpos;
11820: }
11821: for (var i=0; i<categories[idx].length; i++) {
11822: var elementName = categories[idx][i];
11823: if (elementName != item) {
11824: if (form.elements[elementName]) {
11825: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11826: current[currVal] = elementName;
11827: }
11828: }
11829: }
11830: var oldVal;
11831: for (var j=0; j<maxh; j++) {
11832: if (current[j] == undefined) {
11833: oldVal = j;
11834: }
11835: }
11836: if (oldVal < changedVal) {
11837: for (var k=oldVal+1; k<=changedVal ; k++) {
11838: var elementName = current[k];
11839: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11840: }
11841: } else {
11842: for (var k=changedVal; k<oldVal; k++) {
11843: var elementName = current[k];
11844: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11845: }
11846: }
11847: return;
11848: }
1.120 raeburn 11849:
11850: function categoryCheck(form) {
11851: if (form.elements['addcategory_name'].value == 'instcode') {
11852: alert('$instcode_reserved\\n$choose_again');
11853: return false;
11854: }
11855: if (form.elements['addcategory_name'].value == 'communities') {
11856: alert('$communities_reserved\\n$choose_again');
11857: return false;
11858: }
1.272 raeburn 11859: if (form.elements['addcategory_name'].value == 'placement') {
11860: alert('$placement_reserved\\n$choose_again');
11861: return false;
11862: }
1.120 raeburn 11863: return true;
11864: }
11865:
1.109 raeburn 11866: // ]]>
1.49 raeburn 11867: </script>
11868:
11869: ENDSCRIPT
11870: return $output;
11871: }
11872:
1.48 raeburn 11873: sub initialize_categories {
11874: my ($itemcount) = @_;
1.120 raeburn 11875: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11876: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11877: instcode => 'Official courses (with institutional codes)',
11878: communities => 'Communities',
1.272 raeburn 11879: placement => 'Placement Tests',
1.120 raeburn 11880: );
1.328 raeburn 11881: my %selnum = (
11882: instcode => '0',
11883: communities => '1',
11884: placement => '2',
11885: );
11886: my %selected;
1.272 raeburn 11887: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11888: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11889: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11890: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11891: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11892: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11893: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11894: .'<option value="0"'.$selected{'0'}.'>1</option>'
11895: .'<option value="1"'.$selected{'1'}.'>2</option>'
11896: .'<option value="2"'.$selected{'2'}.'>3</option>'
11897: .'<option value="3">4</option></select> '
1.120 raeburn 11898: .$default_names{$default}
11899: .'</span></td><td><span class="LC_nobreak">'
11900: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11901: .&mt('Display').'</label> <label>'
11902: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11903: .'</label></span></td></tr>';
1.120 raeburn 11904: $itemcount ++;
11905: }
1.48 raeburn 11906: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11907: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11908: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11909: .'<select name="addcategory_pos"'.$chgstr.'>'
11910: .'<option value="0">1</option>'
11911: .'<option value="1">2</option>'
1.328 raeburn 11912: .'<option value="2">3</option>'
11913: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11914: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11915: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11916: .'</td></tr>';
1.48 raeburn 11917: return $datatable;
11918: }
11919:
11920: sub build_category_rows {
1.49 raeburn 11921: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11922: my ($text,$name,$item,$chgstr);
1.48 raeburn 11923: if (ref($cats) eq 'ARRAY') {
11924: my $maxdepth = scalar(@{$cats});
11925: if (ref($cats->[$depth]) eq 'HASH') {
11926: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11927: my $numchildren = @{$cats->[$depth]{$parent}};
11928: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11929: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11930: my ($idxnum,$parent_name,$parent_item);
11931: my $higher = $depth - 1;
11932: if ($higher == 0) {
11933: $parent_name = &escape($parent).'::'.$higher;
11934: } else {
11935: if (ref($path) eq 'ARRAY') {
11936: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11937: }
11938: }
11939: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11940: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11941: if ($j < $numchildren) {
1.48 raeburn 11942: $name = $cats->[$depth]{$parent}[$j];
11943: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11944: $idxnum = $idx->{$item};
11945: } else {
11946: $name = $parent_name;
11947: $item = $parent_item;
1.48 raeburn 11948: }
1.49 raeburn 11949: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11950: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11951: for (my $i=0; $i<=$numchildren; $i++) {
11952: my $vpos = $i+1;
11953: my $selstr;
11954: if ($j == $i) {
11955: $selstr = ' selected="selected" ';
11956: }
11957: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11958: }
11959: $text .= '</select> ';
11960: if ($j < $numchildren) {
11961: my $deeper = $depth+1;
11962: $text .= $name.' '
11963: .'<label><input type="checkbox" name="deletecategory" value="'
11964: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11965: if(ref($path) eq 'ARRAY') {
11966: push(@{$path},$name);
1.49 raeburn 11967: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11968: pop(@{$path});
11969: }
11970: } else {
1.330 raeburn 11971: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11972: if ($j == $numchildren) {
11973: $text .= $name;
11974: } else {
11975: $text .= $item;
11976: }
11977: $text .= '" value="" />';
11978: }
11979: $text .= '</td></tr>';
11980: }
11981: $text .= '</table></td>';
11982: } else {
11983: my $higher = $depth-1;
11984: if ($higher == 0) {
11985: $name = &escape($parent).'::'.$higher;
11986: } else {
11987: if (ref($path) eq 'ARRAY') {
11988: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11989: }
11990: }
11991: my $colspan;
11992: if ($parent ne 'instcode') {
11993: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11994: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11995: }
11996: }
11997: }
11998: }
11999: return $text;
12000: }
12001:
1.33 raeburn 12002: sub modifiable_userdata_row {
1.305 raeburn 12003: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 12004: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 12005: my ($role,$rolename,$statustype);
12006: $role = $item;
1.224 raeburn 12007: if ($context eq 'cancreate') {
1.305 raeburn 12008: if ($item =~ /^(emailusername)_(.+)$/) {
12009: $role = $1;
12010: $statustype = $2;
1.228 raeburn 12011: if (ref($usertypes) eq 'HASH') {
12012: if ($usertypes->{$statustype}) {
12013: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
12014: } else {
12015: $rolename = &mt('Data provided by user');
12016: }
12017: }
1.224 raeburn 12018: }
12019: } elsif ($context eq 'selfcreate') {
1.63 raeburn 12020: if (ref($usertypes) eq 'HASH') {
12021: $rolename = $usertypes->{$role};
12022: } else {
12023: $rolename = $role;
12024: }
1.325 raeburn 12025: } elsif ($context eq 'lti') {
12026: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 12027: } elsif ($context eq 'privacy') {
12028: $rolename = $itemdesc;
1.33 raeburn 12029: } else {
1.63 raeburn 12030: if ($role eq 'cr') {
12031: $rolename = &mt('Custom role');
12032: } else {
12033: $rolename = &Apache::lonnet::plaintext($role);
12034: }
1.33 raeburn 12035: }
1.224 raeburn 12036: my (@fields,%fieldtitles);
12037: if (ref($fieldsref) eq 'ARRAY') {
12038: @fields = @{$fieldsref};
12039: } else {
12040: @fields = ('lastname','firstname','middlename','generation',
12041: 'permanentemail','id');
12042: }
12043: if ((ref($titlesref) eq 'HASH')) {
12044: %fieldtitles = %{$titlesref};
12045: } else {
12046: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12047: }
1.33 raeburn 12048: my $output;
1.305 raeburn 12049: my $css_class;
12050: if ($rowcount%2) {
12051: $css_class = 'LC_odd_row';
12052: }
12053: if ($customcss) {
12054: $css_class .= " $customcss";
12055: }
12056: $css_class =~ s/^\s+//;
12057: if ($css_class) {
12058: $css_class = ' class="'.$css_class.'"';
12059: }
12060: if ($rowstyle) {
12061: $css_class .= ' style="'.$rowstyle.'"';
12062: }
12063: if ($rowid) {
12064: $rowid = ' id="'.$rowid.'"';
12065: }
12066: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 12067: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
12068: '<td class="LC_left_item" colspan="2"><table>';
12069: my $rem;
12070: my %checks;
12071: if (ref($settings) eq 'HASH') {
1.325 raeburn 12072: my $hashref;
12073: if ($context eq 'lti') {
12074: if (ref($settings) eq 'HASH') {
1.447.2.2 raeburn 12075: my %instdata;
12076: if (ref($settings->{'instdata'}) eq 'ARRAY') {
12077: map { $instdata{$_} = 1; } @{$settings->{'instdata'}};
12078: }
12079: $hashref = \%instdata;
1.325 raeburn 12080: }
1.357 raeburn 12081: } elsif ($context eq 'privacy') {
12082: my ($key,$inner) = split(/_/,$role);
12083: if (ref($settings) eq 'HASH') {
12084: if (ref($settings->{$key}) eq 'HASH') {
12085: $hashref = $settings->{$key}->{$inner};
12086: }
12087: }
1.325 raeburn 12088: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12089: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.447.2.2 raeburn 12090: $hashref = $settings->{$context}->{$role};
1.325 raeburn 12091: }
12092: if ($role eq 'emailusername') {
12093: if ($statustype) {
12094: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12095: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12096: }
1.325 raeburn 12097: }
12098: }
12099: }
1.425 raeburn 12100: if (ref($hashref) eq 'HASH') {
1.325 raeburn 12101: foreach my $field (@fields) {
12102: if ($hashref->{$field}) {
12103: if ($role eq 'emailusername') {
12104: $checks{$field} = $hashref->{$field};
12105: } else {
12106: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12107: }
12108: }
12109: }
12110: }
12111: }
1.305 raeburn 12112: my $total = scalar(@fields);
12113: for (my $i=0; $i<$total; $i++) {
12114: $rem = $i%($numinrow);
1.33 raeburn 12115: if ($rem == 0) {
12116: if ($i > 0) {
12117: $output .= '</tr>';
12118: }
12119: $output .= '<tr>';
12120: }
12121: my $check = ' ';
1.228 raeburn 12122: unless ($role eq 'emailusername') {
12123: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12124: $check = $checks{$fields[$i]};
1.357 raeburn 12125: } elsif ($context eq 'privacy') {
12126: if ($role =~ /^priv_(domain|course)$/) {
12127: if (ref($settings) ne 'HASH') {
12128: $check = ' checked="checked" ';
12129: }
12130: } elsif ($role =~ /^priv_(author|community)$/) {
12131: if (ref($settings) ne 'HASH') {
12132: unless ($fields[$i] eq 'id') {
12133: $check = ' checked="checked" ';
12134: }
12135: }
12136: } elsif ($role =~ /^(unpriv|othdom)_/) {
12137: if (ref($settings) ne 'HASH') {
12138: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12139: $check = ' checked="checked" ';
12140: }
12141: }
12142: }
1.325 raeburn 12143: } elsif ($context ne 'lti') {
1.228 raeburn 12144: if ($role eq 'st') {
12145: if (ref($settings) ne 'HASH') {
12146: $check = ' checked="checked" ';
12147: }
1.33 raeburn 12148: }
12149: }
12150: }
12151: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12152: '<span class="LC_nobreak">';
1.325 raeburn 12153: my $prefix = 'canmodify';
1.228 raeburn 12154: if ($role eq 'emailusername') {
12155: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12156: $checks{$fields[$i]} = 'omit';
12157: }
12158: foreach my $option ('required','optional','omit') {
12159: my $checked='';
12160: if ($checks{$fields[$i]} eq $option) {
12161: $checked='checked="checked" ';
12162: }
12163: $output .= '<label>'.
1.325 raeburn 12164: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12165: &mt($option).'</label>'.(' ' x2);
12166: }
12167: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12168: } else {
1.325 raeburn 12169: if ($context eq 'lti') {
12170: $prefix = 'lti';
1.443 raeburn 12171: } elsif ($context eq 'coauthor') {
12172: $prefix = 'cacanmodify';
1.357 raeburn 12173: } elsif ($context eq 'privacy') {
12174: $prefix = 'privacy';
1.325 raeburn 12175: }
1.228 raeburn 12176: $output .= '<label>'.
1.325 raeburn 12177: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12178: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12179: '</label>';
12180: }
12181: $output .= '</span></td>';
1.33 raeburn 12182: }
1.305 raeburn 12183: $rem = $total%$numinrow;
12184: my $colsleft;
12185: if ($rem) {
12186: $colsleft = $numinrow - $rem;
12187: }
12188: if ($colsleft > 1) {
1.33 raeburn 12189: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12190: ' </td>';
12191: } elsif ($colsleft == 1) {
12192: $output .= '<td class="LC_left_item"> </td>';
12193: }
12194: $output .= '</tr></table></td></tr>';
12195: return $output;
12196: }
1.28 raeburn 12197:
1.93 raeburn 12198: sub insttypes_row {
1.305 raeburn 12199: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12200: $customcss,$rowstyle) = @_;
1.93 raeburn 12201: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12202: cansearch => 'Users allowed to search',
1.93 raeburn 12203: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12204: lockablenames => 'User preference to lock name',
12205: selfassign => 'Self-reportable affiliations',
12206: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12207: webdav => 'WebDAV access available',
12208: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12209: );
1.429 raeburn 12210: my ($showdom,$defaultquota);
1.93 raeburn 12211: if ($context eq 'cansearch') {
12212: $showdom = ' ('.$dom.')';
1.429 raeburn 12213: } elsif ($context eq 'authorquota') {
12214: $defaultquota = 500;
1.93 raeburn 12215: }
1.165 raeburn 12216: my $class = 'LC_left_item';
12217: if ($context eq 'statustocreate') {
12218: $class = 'LC_right_item';
12219: }
1.305 raeburn 12220: my $css_class;
12221: if ($$rowtotal%2) {
12222: $css_class = 'LC_odd_row';
12223: }
12224: if ($customcss) {
12225: $css_class .= ' '.$customcss;
12226: }
12227: $css_class =~ s/^\s+//;
12228: if ($css_class) {
12229: $css_class = ' class="'.$css_class.'"';
12230: }
12231: if ($rowstyle) {
12232: $css_class .= ' style="'.$rowstyle.'"';
12233: }
12234: if ($onclick) {
12235: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12236: }
12237: my $output = '<tr'.$css_class.'>'.
12238: '<td>'.$lt{$context}.$showdom.
12239: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12240: my $rem;
12241: if (ref($types) eq 'ARRAY') {
12242: for (my $i=0; $i<@{$types}; $i++) {
12243: if (defined($usertypes->{$types->[$i]})) {
12244: my $rem = $i%($numinrow);
12245: if ($rem == 0) {
12246: if ($i > 0) {
12247: $output .= '</tr>';
12248: }
12249: $output .= '<tr>';
1.23 raeburn 12250: }
1.429 raeburn 12251: if ($context eq 'authorquota') {
12252: my $currquota;
12253: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12254: $currquota = $settings->{$context}->{$types->[$i]};
12255: } else {
12256: $currquota = $defaultquota;
12257: }
12258: $output .= '<td class="LC_left_item">'."\n".
12259: '<label><span class="LC_nobreak">'."\n".
12260: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12261: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12262: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12263: '</label></td>';
12264: } else {
12265: my $check = ' ';
12266: if (ref($settings) eq 'HASH') {
12267: if (ref($settings->{$context}) eq 'ARRAY') {
12268: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12269: $check = ' checked="checked" ';
12270: }
12271: } elsif (ref($settings->{$context}) eq 'HASH') {
12272: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12273: $check = ' checked="checked" ';
12274: } elsif ($context eq 'webdav') {
12275: if ($settings->{$context}->{$types->[$i]}) {
12276: $check = ' checked="checked" ';
12277: }
12278: }
12279: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12280: $check = ' checked="checked" ';
12281: }
1.26 raeburn 12282: }
1.429 raeburn 12283: $output .= '<td class="LC_left_item">'.
12284: '<span class="LC_nobreak"><label>'.
12285: '<input type="checkbox" name="'.$context.'" '.
12286: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12287: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12288: }
12289: }
12290: }
1.26 raeburn 12291: $rem = @{$types}%($numinrow);
1.23 raeburn 12292: }
12293: my $colsleft = $numinrow - $rem;
1.315 raeburn 12294: if ($context eq 'overrides') {
12295: if ($colsleft > 1) {
12296: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12297: } else {
12298: $output .= '<td class="LC_left_item">';
12299: }
1.425 raeburn 12300: $output .= ' ';
1.23 raeburn 12301: } else {
1.334 raeburn 12302: if ($rem == 0) {
1.315 raeburn 12303: $output .= '<tr>';
12304: }
12305: if ($colsleft > 1) {
12306: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12307: } else {
12308: $output .= '<td class="LC_left_item">';
12309: }
1.429 raeburn 12310: if ($context eq 'authorquota') {
12311: my $currquota = 500;
12312: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12313: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12314: $currquota = $settings->{$context}{'default'};
12315: }
12316: }
12317: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12318: '<input type="text" name="'.$context.'_default" '.
12319: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12320: '</label>';
12321: } else {
12322: my $defcheck = ' ';
12323: if (ref($settings) eq 'HASH') {
12324: if (ref($settings->{$context}) eq 'ARRAY') {
12325: if (grep(/^default$/,@{$settings->{$context}})) {
12326: $defcheck = ' checked="checked" ';
12327: }
12328: } elsif (ref($settings->{$context}) eq 'HASH') {
12329: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12330: $defcheck = ' checked="checked" ';
12331: } elsif ($context eq 'webdav') {
12332: if ($settings->{$context}->{'default'}) {
12333: $defcheck = ' checked="checked" ';
12334: }
12335: }
12336: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12337: $defcheck = ' checked="checked" ';
12338: }
1.99 raeburn 12339: }
1.429 raeburn 12340: $output .= '<span class="LC_nobreak"><label>'.
12341: '<input type="checkbox" name="'.$context.'" '.
12342: 'value="default"'.$defcheck.$onclick.'/>'.
12343: $othertitle.'</label></span>';
1.26 raeburn 12344: }
1.23 raeburn 12345: }
1.315 raeburn 12346: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12347: return $output;
1.23 raeburn 12348: }
12349:
12350: sub sorted_searchtitles {
12351: my %searchtitles = &Apache::lonlocal::texthash(
12352: 'uname' => 'username',
12353: 'lastname' => 'last name',
12354: 'lastfirst' => 'last name, first name',
12355: );
12356: my @titleorder = ('uname','lastname','lastfirst');
12357: return (\%searchtitles,\@titleorder);
12358: }
12359:
1.25 raeburn 12360: sub sorted_searchtypes {
12361: my %srchtypes_desc = (
12362: exact => 'is exact match',
12363: contains => 'contains ..',
12364: begins => 'begins with ..',
12365: );
12366: my @srchtypeorder = ('exact','begins','contains');
12367: return (\%srchtypes_desc,\@srchtypeorder);
12368: }
12369:
1.3 raeburn 12370: sub usertype_update_row {
12371: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12372: my $datatable;
12373: my $numinrow = 4;
12374: foreach my $type (@{$types}) {
12375: if (defined($usertypes->{$type})) {
12376: $$rownums ++;
12377: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12378: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12379: '</td><td class="LC_left_item"><table>';
12380: for (my $i=0; $i<@{$fields}; $i++) {
12381: my $rem = $i%($numinrow);
12382: if ($rem == 0) {
12383: if ($i > 0) {
12384: $datatable .= '</tr>';
12385: }
12386: $datatable .= '<tr>';
12387: }
12388: my $check = ' ';
1.39 raeburn 12389: if (ref($settings) eq 'HASH') {
12390: if (ref($settings->{'fields'}) eq 'HASH') {
12391: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12392: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12393: $check = ' checked="checked" ';
12394: }
1.3 raeburn 12395: }
12396: }
12397: }
12398:
12399: if ($i == @{$fields}-1) {
12400: my $colsleft = $numinrow - $rem;
12401: if ($colsleft > 1) {
12402: $datatable .= '<td colspan="'.$colsleft.'">';
12403: } else {
12404: $datatable .= '<td>';
12405: }
12406: } else {
12407: $datatable .= '<td>';
12408: }
1.8 raeburn 12409: $datatable .= '<span class="LC_nobreak"><label>'.
12410: '<input type="checkbox" name="updateable_'.$type.
12411: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12412: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12413: }
12414: $datatable .= '</tr></table></td></tr>';
12415: }
12416: }
12417: return $datatable;
1.1 raeburn 12418: }
12419:
12420: sub modify_login {
1.205 raeburn 12421: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12422: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12423: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12424: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12425: %title = ( coursecatalog => 'Display course catalog',
12426: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12427: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12428: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12429: loginheader => 'Log-in box header',
12430: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12431: @offon = ('off','on');
1.112 raeburn 12432: if (ref($domconfig{login}) eq 'HASH') {
12433: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12434: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12435: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12436: }
12437: }
1.386 raeburn 12438: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12439: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12440: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12441: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12442: $saml{$lonhost} = 1;
12443: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12444: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12445: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12446: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12447: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12448: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12449: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12450: }
12451: }
12452: }
1.112 raeburn 12453: }
1.9 raeburn 12454: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12455: \%domconfig,\%loginhash);
1.188 raeburn 12456: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12457: foreach my $item (@toggles) {
12458: $loginhash{login}{$item} = $env{'form.'.$item};
12459: }
1.41 raeburn 12460: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12461: if (ref($colchanges{'login'}) eq 'HASH') {
12462: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12463: \%loginhash);
12464: }
1.110 raeburn 12465:
1.149 raeburn 12466: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12467: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12468: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12469: if (keys(%servers) > 1) {
12470: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12471: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12472: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12473: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12474: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12475: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12476: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12477: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12478: $changes{'loginvia'}{$lonhost} = 1;
12479: } else {
12480: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12481: $changes{'loginvia'}{$lonhost} = 1;
12482: }
12483: } else {
12484: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12485: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12486: $changes{'loginvia'}{$lonhost} = 1;
12487: }
12488: }
12489: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12490: foreach my $item (@loginvia_attribs) {
12491: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12492: }
12493: } else {
12494: foreach my $item (@loginvia_attribs) {
12495: my $new = $env{'form.'.$lonhost.'_'.$item};
12496: if (($item eq 'serverpath') && ($new eq 'custom')) {
12497: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12498: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12499: $new = '/';
12500: }
12501: }
12502: if (($item eq 'custompath') &&
12503: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12504: $new = '';
12505: }
12506: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12507: $changes{'loginvia'}{$lonhost} = 1;
12508: }
12509: if ($item eq 'exempt') {
1.256 raeburn 12510: $new = &check_exempt_addresses($new);
1.128 raeburn 12511: }
12512: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12513: }
12514: }
1.112 raeburn 12515: } else {
1.128 raeburn 12516: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12517: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12518: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12519: foreach my $item (@loginvia_attribs) {
12520: my $new = $env{'form.'.$lonhost.'_'.$item};
12521: if (($item eq 'serverpath') && ($new eq 'custom')) {
12522: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12523: $new = '/';
12524: }
12525: }
12526: if (($item eq 'custompath') &&
12527: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12528: $new = '';
12529: }
12530: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12531: }
1.110 raeburn 12532: }
12533: }
12534: }
12535: }
1.119 raeburn 12536:
1.168 raeburn 12537: my $servadm = $r->dir_config('lonAdmEMail');
12538: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12539: if (ref($domconfig{'login'}) eq 'HASH') {
12540: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12541: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12542: if ($lang eq 'nolang') {
12543: push(@currlangs,$lang);
12544: } elsif (defined($langchoices{$lang})) {
12545: push(@currlangs,$lang);
12546: } else {
12547: next;
12548: }
12549: }
12550: }
12551: }
12552: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12553: if (@currlangs > 0) {
12554: foreach my $lang (@currlangs) {
12555: if (grep(/^\Q$lang\E$/,@delurls)) {
12556: $changes{'helpurl'}{$lang} = 1;
12557: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12558: $changes{'helpurl'}{$lang} = 1;
12559: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12560: push(@newlangs,$lang);
12561: } else {
12562: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12563: }
12564: }
12565: }
12566: unless (grep(/^nolang$/,@currlangs)) {
12567: if ($env{'form.loginhelpurl_nolang.filename'}) {
12568: $changes{'helpurl'}{'nolang'} = 1;
12569: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12570: push(@newlangs,'nolang');
12571: }
12572: }
12573: if ($env{'form.loginhelpurl_add_lang'}) {
12574: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12575: ($env{'form.loginhelpurl_add_file.filename'})) {
12576: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12577: $addedfile = $env{'form.loginhelpurl_add_lang'};
12578: }
12579: }
12580: if ((@newlangs > 0) || ($addedfile)) {
12581: my $error;
12582: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12583: if ($configuserok eq 'ok') {
12584: if ($switchserver) {
12585: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12586: } elsif ($author_ok eq 'ok') {
12587: my @allnew = @newlangs;
12588: if ($addedfile ne '') {
12589: push(@allnew,$addedfile);
12590: }
1.421 raeburn 12591: my $modified = [];
1.168 raeburn 12592: foreach my $lang (@allnew) {
12593: my $formelem = 'loginhelpurl_'.$lang;
12594: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12595: $formelem = 'loginhelpurl_add_file';
12596: }
1.425 raeburn 12597: (my $result,$newurl{$lang}) =
1.421 raeburn 12598: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12599: "help/$lang",'','',$newfile{$lang},
12600: $modified);
1.168 raeburn 12601: if ($result eq 'ok') {
12602: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12603: $changes{'helpurl'}{$lang} = 1;
12604: } else {
12605: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12606: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12607: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12608: (!grep(/^\Q$lang\E$/,@delurls))) {
12609: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12610: }
12611: }
12612: }
1.421 raeburn 12613: &update_modify_urls($r,$modified);
1.168 raeburn 12614: } else {
12615: $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);
12616: }
12617: } else {
12618: $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);
12619: }
12620: if ($error) {
12621: &Apache::lonnet::logthis($error);
12622: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12623: }
12624: }
1.256 raeburn 12625:
12626: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12627: if (ref($domconfig{'login'}) eq 'HASH') {
12628: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12629: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12630: if ($domservers{$lonhost}) {
12631: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12632: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12633: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12634: }
12635: }
12636: }
12637: }
12638: }
12639: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12640: foreach my $lonhost (sort(keys(%domservers))) {
12641: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12642: $changes{'headtag'}{$lonhost} = 1;
12643: } else {
12644: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12645: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12646: }
12647: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12648: push(@newhosts,$lonhost);
12649: } elsif ($currheadtagurls{$lonhost}) {
12650: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12651: if ($currexempt{$lonhost}) {
1.289 raeburn 12652: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12653: $changes{'headtag'}{$lonhost} = 1;
12654: }
12655: } elsif ($possexempt{$lonhost}) {
12656: $changes{'headtag'}{$lonhost} = 1;
12657: }
12658: if ($possexempt{$lonhost}) {
12659: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12660: }
12661: }
12662: }
12663: }
12664: if (@newhosts) {
12665: my $error;
12666: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12667: if ($configuserok eq 'ok') {
12668: if ($switchserver) {
12669: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12670: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12671: my $modified = [];
1.256 raeburn 12672: foreach my $lonhost (@newhosts) {
12673: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12674: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12675: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12676: "login/headtag/$lonhost",'','',
12677: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12678: $modified);
1.256 raeburn 12679: if ($result eq 'ok') {
12680: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12681: $changes{'headtag'}{$lonhost} = 1;
12682: if ($possexempt{$lonhost}) {
12683: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12684: }
12685: } else {
12686: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12687: $newheadtagurls{$lonhost},$result);
12688: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12689: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12690: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12691: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12692: }
12693: }
12694: }
1.421 raeburn 12695: &update_modify_urls($r,$modified);
1.256 raeburn 12696: } else {
12697: $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);
12698: }
12699: } else {
12700: $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);
12701: }
12702: if ($error) {
12703: &Apache::lonnet::logthis($error);
12704: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12705: }
12706: }
1.386 raeburn 12707: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12708: my @newsamlimgs;
12709: foreach my $lonhost (keys(%domservers)) {
12710: if ($env{'form.saml_'.$lonhost}) {
12711: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12712: push(@newsamlimgs,$lonhost);
12713: }
1.412 raeburn 12714: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12715: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12716: }
12717: if ($saml{$lonhost}) {
1.412 raeburn 12718: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12719: $env{'form.saml_window_'.$lonhost} = '';
12720: }
1.386 raeburn 12721: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12722: #FIXME Need to obsolete published image
12723: delete($currsaml{$lonhost}{'img'});
12724: $changes{'saml'}{$lonhost} = 1;
12725: }
12726: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12727: $changes{'saml'}{$lonhost} = 1;
12728: }
12729: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12730: $changes{'saml'}{$lonhost} = 1;
12731: }
12732: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12733: $changes{'saml'}{$lonhost} = 1;
12734: }
12735: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12736: $changes{'saml'}{$lonhost} = 1;
12737: }
1.412 raeburn 12738: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12739: $changes{'saml'}{$lonhost} = 1;
12740: }
1.386 raeburn 12741: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12742: $changes{'saml'}{$lonhost} = 1;
12743: }
12744: } else {
12745: $changes{'saml'}{$lonhost} = 1;
12746: }
1.412 raeburn 12747: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12748: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12749: }
12750: } else {
1.425 raeburn 12751: if ($saml{$lonhost}) {
1.389 raeburn 12752: $changes{'saml'}{$lonhost} = 1;
12753: delete($currsaml{$lonhost});
12754: }
1.386 raeburn 12755: }
12756: }
12757: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12758: unless (exists($domservers{$posshost})) {
12759: delete($currsaml{$posshost});
1.386 raeburn 12760: }
12761: }
12762: %{$loginhash{'login'}{'saml'}} = %currsaml;
12763: if (@newsamlimgs) {
12764: my $error;
12765: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12766: if ($configuserok eq 'ok') {
12767: if ($switchserver) {
12768: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12769: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12770: my $modified = [];
1.386 raeburn 12771: foreach my $lonhost (@newsamlimgs) {
12772: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12773: my ($result,$imgurl) =
1.421 raeburn 12774: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12775: "login/saml/$lonhost",'','',
12776: $env{'form.saml_img_'.$lonhost.'.filename'},
12777: $modified);
1.386 raeburn 12778: if ($result eq 'ok') {
12779: $currsaml{$lonhost}{'img'} = $imgurl;
12780: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12781: $changes{'saml'}{$lonhost} = 1;
12782: } else {
12783: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12784: $lonhost,$result);
12785: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12786: }
12787: }
1.421 raeburn 12788: &update_modify_urls($r,$modified);
1.386 raeburn 12789: } else {
12790: $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);
12791: }
12792: } else {
12793: $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);
12794: }
12795: if ($error) {
12796: &Apache::lonnet::logthis($error);
12797: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12798: }
12799: }
1.169 raeburn 12800: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12801:
12802: my $defaulthelpfile = '/adm/loginproblems.html';
12803: my $defaulttext = &mt('Default in use');
12804:
1.1 raeburn 12805: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12806: $dom);
12807: if ($putresult eq 'ok') {
1.188 raeburn 12808: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12809: my %defaultchecked = (
12810: 'coursecatalog' => 'on',
1.188 raeburn 12811: 'helpdesk' => 'on',
1.42 raeburn 12812: 'adminmail' => 'off',
1.43 raeburn 12813: 'newuser' => 'off',
1.42 raeburn 12814: );
1.55 raeburn 12815: if (ref($domconfig{'login'}) eq 'HASH') {
12816: foreach my $item (@toggles) {
12817: if ($defaultchecked{$item} eq 'on') {
12818: if (($domconfig{'login'}{$item} eq '0') &&
12819: ($env{'form.'.$item} eq '1')) {
12820: $changes{$item} = 1;
12821: } elsif (($domconfig{'login'}{$item} eq '' ||
12822: $domconfig{'login'}{$item} eq '1') &&
12823: ($env{'form.'.$item} eq '0')) {
12824: $changes{$item} = 1;
12825: }
12826: } elsif ($defaultchecked{$item} eq 'off') {
12827: if (($domconfig{'login'}{$item} eq '1') &&
12828: ($env{'form.'.$item} eq '0')) {
12829: $changes{$item} = 1;
12830: } elsif (($domconfig{'login'}{$item} eq '' ||
12831: $domconfig{'login'}{$item} eq '0') &&
12832: ($env{'form.'.$item} eq '1')) {
12833: $changes{$item} = 1;
12834: }
1.42 raeburn 12835: }
12836: }
1.41 raeburn 12837: }
1.6 raeburn 12838: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12839: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12840: if (exists($changes{'saml'})) {
12841: my $hostid_in_use;
12842: my @hosts = &Apache::lonnet::current_machine_ids();
12843: if (@hosts > 1) {
12844: foreach my $hostid (@hosts) {
12845: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12846: $hostid_in_use = $hostid;
12847: last;
12848: }
12849: }
12850: } else {
12851: $hostid_in_use = $r->dir_config('lonHostID');
12852: }
12853: if (($hostid_in_use) &&
12854: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12855: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12856: }
12857: if (ref($lastactref) eq 'HASH') {
12858: if (ref($changes{'saml'}) eq 'HASH') {
12859: my %updates;
12860: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12861: $lastactref->{'samllanding'} = \%updates;
12862: }
12863: }
12864: }
1.212 raeburn 12865: if (ref($lastactref) eq 'HASH') {
12866: $lastactref->{'domainconfig'} = 1;
12867: }
1.1 raeburn 12868: $resulttext = &mt('Changes made:').'<ul>';
12869: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12870: if ($item eq 'loginvia') {
1.112 raeburn 12871: if (ref($changes{$item}) eq 'HASH') {
12872: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12873: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12874: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12875: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12876: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12877: $protocol = 'http' if ($protocol ne 'https');
12878: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12879:
12880: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12881: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12882: } else {
12883: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12884: }
12885: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12886: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12887: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12888: }
12889: $resulttext .= '</li>';
12890: } else {
12891: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12892: }
1.112 raeburn 12893: } else {
1.128 raeburn 12894: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12895: }
12896: }
1.128 raeburn 12897: $resulttext .= '</ul></li>';
1.112 raeburn 12898: }
1.168 raeburn 12899: } elsif ($item eq 'helpurl') {
12900: if (ref($changes{$item}) eq 'HASH') {
12901: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12902: if (grep(/^\Q$lang\E$/,@delurls)) {
12903: my ($chg,$link);
12904: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12905: if ($lang eq 'nolang') {
12906: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12907: } else {
12908: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12909: }
12910: $resulttext .= '<li>'.$chg.'</li>';
12911: } else {
12912: my $chg;
12913: if ($lang eq 'nolang') {
12914: $chg = &mt('custom log-in help file for no preferred language');
12915: } else {
12916: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12917: }
12918: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12919: $loginhash{'login'}{'helpurl'}{$lang}.
12920: '?inhibitmenu=yes',$chg,600,500).
12921: '</li>';
12922: }
12923: }
12924: }
1.256 raeburn 12925: } elsif ($item eq 'headtag') {
12926: if (ref($changes{$item}) eq 'HASH') {
12927: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12928: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12929: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12930: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12931: $resulttext .= '<li><a href="'.
12932: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12933: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12934: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12935: if ($possexempt{$lonhost}) {
12936: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12937: } else {
12938: $resulttext .= &mt('included for any client IP');
12939: }
12940: $resulttext .= '</li>';
12941: }
12942: }
12943: }
1.386 raeburn 12944: } elsif ($item eq 'saml') {
12945: if (ref($changes{$item}) eq 'HASH') {
12946: my %notlt = (
12947: text => 'Text for log-in by SSO',
12948: img => 'SSO button image',
12949: alt => 'Alt text for button image',
12950: url => 'SSO URL',
12951: title => 'Tooltip for SSO link',
1.412 raeburn 12952: window => 'Pop-up window if iframe',
1.386 raeburn 12953: notsso => 'Text for non-SSO log-in',
12954: );
12955: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12956: if (ref($currsaml{$lonhost}) eq 'HASH') {
12957: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12958: '<ul>';
1.412 raeburn 12959: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 12960: if ($currsaml{$lonhost}{$key} eq '') {
12961: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12962: } else {
12963: my $value = "'$currsaml{$lonhost}{$key}'";
12964: if ($key eq 'img') {
12965: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 12966: } elsif ($key eq 'window') {
12967: $value = 'On';
1.386 raeburn 12968: }
12969: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12970: $value).'</li>';
12971: }
12972: }
12973: $resulttext .= '</ul></li>';
12974: } else {
12975: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12976: }
12977: }
12978: }
1.169 raeburn 12979: } elsif ($item eq 'captcha') {
12980: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12981: my $chgtxt;
1.169 raeburn 12982: if ($loginhash{'login'}{$item} eq 'notused') {
12983: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12984: } else {
12985: my %captchas = &captcha_phrases();
12986: if ($captchas{$loginhash{'login'}{$item}}) {
12987: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12988: } else {
12989: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12990: }
12991: }
12992: $resulttext .= '<li>'.$chgtxt.'</li>';
12993: }
12994: } elsif ($item eq 'recaptchakeys') {
12995: if (ref($loginhash{'login'}) eq 'HASH') {
12996: my ($privkey,$pubkey);
12997: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
12998: $pubkey = $loginhash{'login'}{$item}{'public'};
12999: $privkey = $loginhash{'login'}{$item}{'private'};
13000: }
13001: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
13002: if (!$pubkey) {
13003: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
13004: } else {
13005: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13006: }
13007: if (!$privkey) {
13008: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
13009: } else {
1.251 raeburn 13010: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 13011: }
13012: $chgtxt .= '</ul>';
13013: $resulttext .= '<li>'.$chgtxt.'</li>';
13014: }
1.269 raeburn 13015: } elsif ($item eq 'recaptchaversion') {
13016: if (ref($loginhash{'login'}) eq 'HASH') {
13017: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 13018: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 13019: '</li>';
13020: }
13021: }
1.41 raeburn 13022: } else {
13023: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
13024: }
1.1 raeburn 13025: }
1.6 raeburn 13026: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 13027: } else {
13028: $resulttext = &mt('No changes made to log-in page settings');
13029: }
13030: } else {
1.11 albertel 13031: $resulttext = '<span class="LC_error">'.
13032: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13033: }
1.6 raeburn 13034: if ($errors) {
1.9 raeburn 13035: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 13036: $errors.'</ul>';
13037: }
13038: return $resulttext;
13039: }
13040:
1.256 raeburn 13041: sub check_exempt_addresses {
13042: my ($iplist) = @_;
13043: $iplist =~ s/^\s+//;
13044: $iplist =~ s/\s+$//;
13045: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
13046: my (@okips,$new);
13047: foreach my $ip (@poss_ips) {
13048: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
13049: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
13050: push(@okips,$ip);
13051: }
13052: }
13053: }
13054: if (@okips > 0) {
13055: $new = join(',',@okips);
13056: } else {
13057: $new = '';
13058: }
13059: return $new;
13060: }
13061:
1.6 raeburn 13062: sub color_font_choices {
13063: my %choices =
13064: &Apache::lonlocal::texthash (
13065: bgs => "Background colors",
13066: links => "Link colors",
1.55 raeburn 13067: images => "Images",
1.6 raeburn 13068: font => "Font color",
1.201 raeburn 13069: fontmenu => "Font menu",
1.76 raeburn 13070: pgbg => "Page",
1.6 raeburn 13071: tabbg => "Header",
13072: sidebg => "Border",
13073: link => "Link",
13074: alink => "Active link",
13075: vlink => "Visited link",
13076: );
13077: return %choices;
13078: }
13079:
1.394 raeburn 13080: sub modify_ipaccess {
13081: my ($dom,$lastactref,%domconfig) = @_;
13082: my (@allpos,%changes,%confhash,$errors,$resulttext);
13083: my (@items,%deletions,%itemids,@warnings);
13084: my ($typeorder,$types) = &commblocktype_text();
13085: if ($env{'form.ipaccess_add'}) {
13086: my $name = $env{'form.ipaccess_name_add'};
13087: my ($newid,$error) = &get_ipaccess_id($dom,$name);
13088: if ($newid) {
13089: $itemids{'add'} = $newid;
13090: push(@items,'add');
13091: $changes{$newid} = 1;
13092: } else {
13093: $error = &mt('Failed to acquire unique ID for new IP access control item');
13094: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13095: }
13096: }
13097: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13098: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13099: if (@todelete) {
13100: map { $deletions{$_} = 1; } @todelete;
13101: }
13102: my $maxnum = $env{'form.ipaccess_maxnum'};
13103: for (my $i=0; $i<$maxnum; $i++) {
13104: my $itemid = $env{'form.ipaccess_id_'.$i};
13105: $itemid =~ s/\D+//g;
13106: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13107: if ($deletions{$itemid}) {
13108: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13109: } else {
13110: push(@items,$i);
13111: $itemids{$i} = $itemid;
13112: }
13113: }
13114: }
13115: }
13116: foreach my $idx (@items) {
13117: my $itemid = $itemids{$idx};
13118: next unless ($itemid);
1.446 raeburn 13119: my ($position,%current);
13120: if ($idx eq 'add') {
13121: $position = $env{'form.ipaccess_pos_add'};
13122: } else {
13123: $position = $env{'form.ipaccess_pos_'.$itemid};
1.394 raeburn 13124: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13125: %current = %{$domconfig{'ipaccess'}{$itemid}};
13126: }
13127: }
13128: $position =~ s/\D+//g;
13129: if ($position ne '') {
13130: $allpos[$position] = $itemid;
13131: }
13132: my $name = $env{'form.ipaccess_name_'.$idx};
13133: $name =~ s/^\s+|\s+$//g;
13134: $confhash{$itemid}{'name'} = $name;
13135: my $possrange = $env{'form.ipaccess_range_'.$idx};
13136: $possrange =~ s/^\s+|\s+$//g;
13137: unless ($possrange eq '') {
13138: $possrange =~ s/[\r\n]+/\s/g;
13139: $possrange =~ s/\s*-\s*/-/g;
13140: $possrange =~ s/\s+/,/g;
13141: $possrange =~ s/,+/,/g;
13142: if ($possrange ne '') {
13143: my (@ok,$count);
1.425 raeburn 13144: $count = 0;
1.394 raeburn 13145: foreach my $poss (split(/\,/,$possrange)) {
13146: $count ++;
13147: $poss = &validate_ip_pattern($poss);
13148: if ($poss ne '') {
13149: push(@ok,$poss);
13150: }
13151: }
13152: my $diff = $count - scalar(@ok);
13153: if ($diff) {
13154: $errors .= '<li><span class="LC_error">'.
13155: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13156: $diff,$name).
13157: '</span></li>';
13158: }
13159: if (@ok) {
13160: my @cidr_list;
13161: foreach my $item (@ok) {
13162: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13163: }
13164: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13165: }
13166: }
13167: }
13168: foreach my $field ('name','ip') {
13169: unless (($idx eq 'add') || ($changes{$itemid})) {
13170: if ($current{$field} ne $confhash{$itemid}{$field}) {
13171: $changes{$itemid} = 1;
13172: last;
13173: }
13174: }
13175: }
13176: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13177:
1.394 raeburn 13178: my %commblocks;
1.425 raeburn 13179: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13180: foreach my $type (@{$typeorder}) {
13181: if ($commblocks{$type}) {
13182: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13183: }
13184: unless (($idx eq 'add') || ($changes{$itemid})) {
13185: if (ref($current{'commblocks'}) eq 'HASH') {
13186: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13187: $changes{$itemid} = 1;
13188: }
13189: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13190: $changes{$itemid} = 1;
13191: }
13192: }
13193: }
13194: $confhash{$itemid}{'courses'} = {};
13195: my %crsdeletions;
13196: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13197: if (@delcrs) {
13198: map { $crsdeletions{$_} = 1; } @delcrs;
13199: }
13200: if (ref($current{'courses'}) eq 'HASH') {
13201: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13202: if ($crsdeletions{$cid}) {
13203: $changes{$itemid} = 1;
13204: } else {
13205: $confhash{$itemid}{'courses'}{$cid} = 1;
13206: }
13207: }
13208: }
13209: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13210: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13211: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13212: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13213: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13214: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13215: $errors .= '<li><span class="LC_error">'.
13216: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13217: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13218: '</span></li>';
13219: } else {
13220: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13221: $changes{$itemid} = 1;
13222: }
13223: }
13224: }
13225: if (@allpos > 0) {
13226: my $idx = 0;
13227: foreach my $itemid (@allpos) {
13228: if ($itemid ne '') {
13229: $confhash{$itemid}{'order'} = $idx;
13230: unless ($changes{$itemid}) {
13231: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13232: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13233: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13234: $changes{$itemid} = 1;
13235: }
13236: }
13237: }
13238: }
13239: $idx ++;
13240: }
13241: }
13242: }
13243: if (keys(%changes)) {
13244: my %defaultshash = (
13245: ipaccess => \%confhash,
13246: );
13247: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13248: $dom);
13249: if ($putresult eq 'ok') {
13250: my $cachetime = 1800;
13251: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13252: if (ref($lastactref) eq 'HASH') {
13253: $lastactref->{'ipaccess'} = 1;
13254: }
13255: $resulttext = &mt('Changes made:').'<ul>';
13256: my %bynum;
13257: foreach my $itemid (sort(keys(%changes))) {
13258: if (ref($confhash{$itemid}) eq 'HASH') {
13259: my $position = $confhash{$itemid}{'order'};
13260: if ($position =~ /^\d+$/) {
13261: $bynum{$position} = $itemid;
13262: }
13263: }
13264: }
13265: if (keys(%deletions)) {
13266: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13267: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13268: }
13269: }
13270: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13271: my $itemid = $bynum{$pos};
13272: if (ref($confhash{$itemid}) eq 'HASH') {
13273: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13274: my $position = $pos + 1;
13275: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13276: if ($confhash{$itemid}{'ip'} eq '') {
13277: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13278: } else {
13279: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13280: }
13281: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13282: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13283: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13284: '</li>';
13285: } else {
13286: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13287: }
13288: if (keys(%{$confhash{$itemid}{'courses'}})) {
13289: my @courses;
13290: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13291: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13292: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13293: }
13294: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13295: join('</li><li>',@courses).'</li></ul>';
13296: } else {
13297: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13298: }
1.395 raeburn 13299: $resulttext .= '</ul></li>';
1.394 raeburn 13300: }
13301: }
1.395 raeburn 13302: $resulttext .= '</ul>';
1.394 raeburn 13303: } else {
13304: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13305: }
13306: } else {
13307: $resulttext = &mt('No changes made');
13308: }
13309: if ($errors) {
13310: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13311: $errors.'</ul></p>';
13312: }
13313: return $resulttext;
13314: }
13315:
13316: sub get_ipaccess_id {
13317: my ($domain,$location) = @_;
13318: # get lock on ipaccess db
13319: my $lockhash = {
13320: lock => $env{'user.name'}.
13321: ':'.$env{'user.domain'},
13322: };
13323: my $tries = 0;
13324: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13325: my ($id,$error);
13326:
13327: while (($gotlock ne 'ok') && ($tries<10)) {
13328: $tries ++;
13329: sleep (0.1);
13330: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13331: }
13332: if ($gotlock eq 'ok') {
13333: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13334: if ($currids{'lock'}) {
13335: delete($currids{'lock'});
13336: if (keys(%currids)) {
13337: my @curr = sort { $a <=> $b } keys(%currids);
13338: if ($curr[-1] =~ /^\d+$/) {
13339: $id = 1 + $curr[-1];
13340: }
13341: } else {
13342: $id = 1;
13343: }
13344: if ($id) {
13345: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13346: $error = 'nostore';
13347: }
13348: } else {
13349: $error = 'nonumber';
13350: }
13351: }
13352: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13353: } else {
13354: $error = 'nolock';
13355: }
13356: return ($id,$error);
13357: }
13358:
1.429 raeburn 13359: sub modify_authordefaults {
13360: my ($dom,$lastactref,%domconfig) = @_;
13361: #
13362: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13363: #
13364: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13365: if (ref($domconfig{'quotas'}) eq 'HASH') {
13366: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13367: if ($key =~ /^webdav|authorquota$/) {
13368: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13369: } else {
13370: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13371: }
13372: }
13373: }
13374: my %staticdefaults = (
13375: 'copyright' => 'default',
13376: 'sourceavail' => 'closed',
13377: 'nocodemirror' => 'off',
1.437 raeburn 13378: 'daxecollapse' => 'off',
1.429 raeburn 13379: 'domcoordacc' => 'on',
1.439 raeburn 13380: 'editors' => ['edit','xml'],
1.429 raeburn 13381: 'authorquota' => 500,
13382: 'webdav' => 0,
1.440 raeburn 13383: 'archive' => 'off',
1.429 raeburn 13384: );
13385: my %titles = &authordefaults_titles();
1.440 raeburn 13386: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.429 raeburn 13387: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13388: $confhash{$item} = $env{'form.'.$item};
13389: }
13390: }
13391: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13392: $confhash{'copyright'} = $1;
13393: }
13394: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13395: $confhash{'sourceavail'} = $1;
13396: }
13397: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13398: my @okeditors = ('edit','xml','daxe');
13399: my @editors;
13400: foreach my $item (@posseditors) {
13401: if (grep(/^\Q$item\E$/,@okeditors)) {
13402: push(@editors,$item);
13403: }
13404: }
13405: $confhash{'editors'} = \@editors;
1.436 raeburn 13406:
1.429 raeburn 13407: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13408: my @insttypes;
13409: if (ref($types) eq 'ARRAY') {
13410: @insttypes = @{$types};
13411: }
13412: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13413: my %webdav;
13414: map { $webdav{$_} = 1; } @webdavon;
13415: foreach my $type (@insttypes,'default') {
13416: my $possquota = $env{'form.authorquota_'.$type};
13417: if ($possquota =~ /^\d+$/) {
13418: $save_quotas{'authorquota'}{$type} = $possquota;
13419: }
13420: if ($webdav{$type}) {
13421: $save_quotas{'webdav'}{$type} = 1;
13422: } else {
13423: $save_quotas{'webdav'}{$type} = 0;
13424: }
13425: }
13426: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13427: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13428: }
13429: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
1.440 raeburn 13430: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail','archive') {
1.429 raeburn 13431: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13432: $changes{$item} = 1;
13433: }
13434: }
13435: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
1.436 raeburn 13436: my @diffs =
1.429 raeburn 13437: &Apache::loncommon::compare_arrays($confhash{'editors'},
13438: $domconfig{'authordefaults'}{'editors'});
13439: unless (@diffs == 0) {
13440: $changes{'editors'} = 1;
13441: }
13442: } else {
13443: my @diffs =
13444: &Apache::loncommon::compare_arrays($confhash{'editors'},
13445: $staticdefaults{'editors'});
13446: unless (@diffs == 0) {
13447: $changes{'editors'} = 1;
13448: }
13449: }
13450: } else {
13451: my @offon = ('off','on');
1.440 raeburn 13452: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.436 raeburn 13453: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
1.429 raeburn 13454: $changes{$item} = 1;
13455: }
13456: }
13457: foreach my $item ('copyright','sourceavail') {
13458: if ($confhash{$item} ne $staticdefaults{$item}) {
13459: $changes{$item} = 1;
13460: }
13461: }
1.439 raeburn 13462: my @diffs =
13463: &Apache::loncommon::compare_arrays($confhash{'editors'},
13464: $staticdefaults{'editors'});
13465: unless (@diffs == 0) {
13466: $changes{'editors'} = 1;
13467: }
1.429 raeburn 13468: }
13469: foreach my $key ('authorquota','webdav') {
13470: if (ref($curr_quotas{$key}) eq 'HASH') {
13471: foreach my $type (@insttypes,'default') {
13472: if (exists($save_quotas{$key}{$type})) {
13473: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13474: $changes{$key}{$type} = 1;
13475: }
13476: } elsif (exists($curr_quotas{$key}{$type})) {
13477: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13478: } else {
13479: $save_quotas{$key}{$type} = $staticdefaults{$key};
13480: }
13481: }
13482: } else {
13483: foreach my $type (@insttypes,'default') {
13484: if (exists($save_quotas{$key}{$type})) {
13485: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13486: $changes{$key}{$type} = 1;
13487: }
13488: } else {
13489: $save_quotas{$key}{$type} = $staticdefaults{$key};
13490: }
13491: }
13492: }
13493: }
13494: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13495: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
1.436 raeburn 13496: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
1.429 raeburn 13497: $changes{'webdav_LC_adv'} = 1;
13498: }
13499: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13500: $changes{'webdav_LC_adv'} = 1;
13501: }
13502: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13503: $changes{'webdav_LC_adv'} = 1;
13504: }
13505: my %confighash = (
13506: quotas => \%save_quotas,
13507: authordefaults => \%confhash,
13508: );
13509: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13510: $dom);
13511: my $resulttext;
13512: if ($putresult eq 'ok') {
13513: if (keys(%changes)) {
1.431 raeburn 13514: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13515: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
1.436 raeburn 13516: ($changes{'webdav_LC_adv'})) {
1.429 raeburn 13517: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13518: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13519: }
13520: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13521: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13522: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13523: }
13524: }
13525: $resulttext = &mt('Changes made:').'<ul>';
13526: my $authoroverride;
1.437 raeburn 13527: foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
1.429 raeburn 13528: if (exists($changes{$key})) {
1.431 raeburn 13529: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13530: my $shown;
13531: unless ($authoroverride) {
13532: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13533: $authoroverride = 1;
13534: }
1.437 raeburn 13535: if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
1.429 raeburn 13536: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13537: } elsif ($key eq 'copyright') {
13538: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13539: } elsif ($key eq 'sourceavail') {
13540: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13541: }
1.436 raeburn 13542: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.429 raeburn 13543: }
13544: }
13545: if ($authoroverride) {
13546: $resulttext .= '</ul></li>';
13547: }
13548: my $domcoordoverride;
1.440 raeburn 13549: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv','archive') {
1.429 raeburn 13550: if (exists($changes{$key})) {
13551: my $shown;
13552: unless ($domcoordoverride) {
13553: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13554: $domcoordoverride = 1;
13555: }
13556: if ($key eq 'editors') {
1.431 raeburn 13557: if (ref($confhash{'editors'}) eq 'ARRAY') {
13558: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
13559: if (@{$confhash{'editors'}}) {
13560: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
13561: } else {
13562: $shown = &mt('None');
13563: }
1.429 raeburn 13564: }
13565: } elsif ($key eq 'authorquota') {
13566: foreach my $type (@insttypes) {
13567: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13568: }
13569: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13570: } elsif ($key eq 'webdav') {
13571: foreach my $type (@insttypes) {
13572: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13573: }
13574: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13575: } elsif ($key eq 'webdav_LC_adv') {
13576: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13577: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13578: } else {
13579: $shown = $titles{'none'};
13580: }
1.440 raeburn 13581: } elsif ($key eq 'archive') {
1.441 raeburn 13582: $domdefaults{$key} = $confhash{$key};
1.440 raeburn 13583: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
1.429 raeburn 13584: }
13585: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.436 raeburn 13586: }
1.429 raeburn 13587: }
13588: if ($domcoordoverride) {
13589: $resulttext .= '</ul></li>';
13590: }
1.439 raeburn 13591: $resulttext .= '</ul>';
1.431 raeburn 13592: my $cachetime = 24*60*60;
13593: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13594: if (ref($lastactref) eq 'HASH') {
13595: $lastactref->{'domdefaults'} = 1;
13596: }
1.429 raeburn 13597: } else {
13598: $resulttext = &mt('No changes made to Authoring Space defaults');
13599: }
13600: }
13601: return $resulttext;
13602: }
13603:
1.6 raeburn 13604: sub modify_rolecolors {
1.205 raeburn 13605: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13606: my ($resulttext,%rolehash);
13607: $rolehash{'rolecolors'} = {};
1.55 raeburn 13608: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13609: if ($domconfig{'rolecolors'} eq '') {
13610: $domconfig{'rolecolors'} = {};
13611: }
13612: }
1.9 raeburn 13613: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13614: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13615: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13616: $dom);
13617: if ($putresult eq 'ok') {
13618: if (keys(%changes) > 0) {
1.41 raeburn 13619: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13620: if (ref($lastactref) eq 'HASH') {
13621: $lastactref->{'domainconfig'} = 1;
13622: }
1.6 raeburn 13623: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13624: $rolehash{'rolecolors'});
13625: } else {
13626: $resulttext = &mt('No changes made to default color schemes');
13627: }
13628: } else {
1.11 albertel 13629: $resulttext = '<span class="LC_error">'.
13630: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13631: }
13632: if ($errors) {
13633: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13634: $errors.'</ul>';
13635: }
13636: return $resulttext;
13637: }
13638:
13639: sub modify_colors {
1.9 raeburn 13640: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13641: my (%changes,%choices);
1.51 raeburn 13642: my @bgs;
1.6 raeburn 13643: my @links = ('link','alink','vlink');
1.41 raeburn 13644: my @logintext;
1.6 raeburn 13645: my @images;
13646: my $servadm = $r->dir_config('lonAdmEMail');
13647: my $errors;
1.200 raeburn 13648: my %defaults;
1.6 raeburn 13649: foreach my $role (@{$roles}) {
13650: if ($role eq 'login') {
1.12 raeburn 13651: %choices = &login_choices();
1.41 raeburn 13652: @logintext = ('textcol','bgcol');
1.12 raeburn 13653: } else {
13654: %choices = &color_font_choices();
13655: }
13656: if ($role eq 'login') {
1.41 raeburn 13657: @images = ('img','logo','domlogo','login');
1.51 raeburn 13658: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13659: } else {
1.445 raeburn 13660: @images = ();
1.200 raeburn 13661: @bgs = ('pgbg','tabbg','sidebg');
13662: }
13663: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
1.444 raeburn 13664: $env{'form.'.$role.'_font'} = lc($env{'form.'.$role.'_font'});
13665: if ($env{'form.'.$role.'_font'} =~ /^\w+/) {
13666: $env{'form.'.$role.'_font'} = '#'.$env{'form.'.$role.'_font'};
13667: }
13668: unless ($env{'form.'.$role.'_font'} eq lc($defaults{'font'})) {
1.200 raeburn 13669: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13670: }
13671: if ($role eq 'login') {
13672: foreach my $item (@logintext) {
1.234 raeburn 13673: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13674: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13675: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13676: }
13677: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13678: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13679: }
13680: }
13681: } else {
1.234 raeburn 13682: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13683: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13684: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13685: }
1.445 raeburn 13686: unless ($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13687: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13688: }
1.6 raeburn 13689: }
1.200 raeburn 13690: foreach my $item (@bgs) {
1.234 raeburn 13691: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13692: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13693: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13694: }
13695: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13696: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13697: }
13698: }
13699: foreach my $item (@links) {
1.234 raeburn 13700: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13701: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13702: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13703: }
13704: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13705: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13706: }
1.6 raeburn 13707: }
1.46 raeburn 13708: my ($configuserok,$author_ok,$switchserver) =
13709: &config_check($dom,$confname,$servadm);
1.9 raeburn 13710: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13711: if (ref($domconfig->{$role}) ne 'HASH') {
13712: $domconfig->{$role} = {};
13713: }
1.8 raeburn 13714: foreach my $img (@images) {
1.402 raeburn 13715: if ($role eq 'login') {
13716: if (($img eq 'img') || ($img eq 'logo')) {
13717: if (defined($env{'form.login_showlogo_'.$img})) {
13718: $confhash->{$role}{'showlogo'}{$img} = 1;
13719: } else {
13720: $confhash->{$role}{'showlogo'}{$img} = 0;
13721: }
13722: }
13723: if ($env{'form.login_alt_'.$img} ne '') {
13724: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13725: }
1.402 raeburn 13726: }
1.18 albertel 13727: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13728: && !defined($domconfig->{$role}{$img})
13729: && !$env{'form.'.$role.'_del_'.$img}
13730: && $env{'form.'.$role.'_import_'.$img}) {
13731: # import the old configured image from the .tab setting
13732: # if they haven't provided a new one
13733: $domconfig->{$role}{$img} =
13734: $env{'form.'.$role.'_import_'.$img};
13735: }
1.6 raeburn 13736: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13737: my $error;
1.6 raeburn 13738: if ($configuserok eq 'ok') {
1.9 raeburn 13739: if ($switchserver) {
1.12 raeburn 13740: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13741: } else {
13742: if ($author_ok eq 'ok') {
1.421 raeburn 13743: my $modified = [];
1.9 raeburn 13744: my ($result,$logourl) =
1.421 raeburn 13745: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13746: $dom,$confname,$img,$width,$height,
13747: '',$modified);
1.9 raeburn 13748: if ($result eq 'ok') {
13749: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13750: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13751: &update_modify_urls($r,$modified);
1.9 raeburn 13752: } else {
1.12 raeburn 13753: $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 13754: }
13755: } else {
1.46 raeburn 13756: $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 13757: }
13758: }
13759: } else {
1.46 raeburn 13760: $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 13761: }
13762: if ($error) {
1.8 raeburn 13763: &Apache::lonnet::logthis($error);
1.11 albertel 13764: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13765: }
13766: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13767: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13768: my $error;
13769: if ($configuserok eq 'ok') {
13770: # is confname an author?
13771: if ($switchserver eq '') {
13772: if ($author_ok eq 'ok') {
1.421 raeburn 13773: my $modified = [];
1.9 raeburn 13774: my ($result,$logourl) =
1.421 raeburn 13775: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13776: $dom,$confname,$img,$width,$height,
13777: '',$modified);
1.9 raeburn 13778: if ($result eq 'ok') {
13779: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13780: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13781: &update_modify_urls($r,$modified);
1.9 raeburn 13782: }
13783: }
13784: }
13785: }
1.6 raeburn 13786: }
13787: }
13788: }
13789: if (ref($domconfig) eq 'HASH') {
13790: if (ref($domconfig->{$role}) eq 'HASH') {
13791: foreach my $img (@images) {
13792: if ($domconfig->{$role}{$img} ne '') {
13793: if ($env{'form.'.$role.'_del_'.$img}) {
13794: $confhash->{$role}{$img} = '';
1.12 raeburn 13795: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13796: } else {
1.9 raeburn 13797: if ($confhash->{$role}{$img} eq '') {
13798: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13799: }
1.6 raeburn 13800: }
13801: } else {
13802: if ($env{'form.'.$role.'_del_'.$img}) {
13803: $confhash->{$role}{$img} = '';
1.12 raeburn 13804: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13805: }
13806: }
1.402 raeburn 13807: if ($role eq 'login') {
13808: if (($img eq 'logo') || ($img eq 'img')) {
13809: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13810: if ($confhash->{$role}{'showlogo'}{$img} ne
13811: $domconfig->{$role}{'showlogo'}{$img}) {
13812: $changes{$role}{'showlogo'}{$img} = 1;
13813: }
13814: } else {
13815: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13816: $changes{$role}{'showlogo'}{$img} = 1;
13817: }
1.70 raeburn 13818: }
1.402 raeburn 13819: }
13820: if ($img ne 'login') {
13821: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13822: if ($confhash->{$role}{'alttext'}{$img} ne
13823: $domconfig->{$role}{'alttext'}{$img}) {
13824: $changes{$role}{'alttext'}{$img} = 1;
13825: }
13826: } else {
13827: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13828: $changes{$role}{'alttext'}{$img} = 1;
13829: }
1.70 raeburn 13830: }
13831: }
13832: }
13833: }
1.6 raeburn 13834: if ($domconfig->{$role}{'font'} ne '') {
13835: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13836: $changes{$role}{'font'} = 1;
13837: }
13838: } else {
13839: if ($confhash->{$role}{'font'}) {
13840: $changes{$role}{'font'} = 1;
13841: }
13842: }
1.107 raeburn 13843: if ($role ne 'login') {
13844: if ($domconfig->{$role}{'fontmenu'} ne '') {
13845: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13846: $changes{$role}{'fontmenu'} = 1;
13847: }
13848: } else {
13849: if ($confhash->{$role}{'fontmenu'}) {
13850: $changes{$role}{'fontmenu'} = 1;
13851: }
1.97 tempelho 13852: }
13853: }
1.6 raeburn 13854: foreach my $item (@bgs) {
13855: if ($domconfig->{$role}{$item} ne '') {
13856: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13857: $changes{$role}{'bgs'}{$item} = 1;
13858: }
13859: } else {
13860: if ($confhash->{$role}{$item}) {
13861: $changes{$role}{'bgs'}{$item} = 1;
13862: }
13863: }
13864: }
13865: foreach my $item (@links) {
13866: if ($domconfig->{$role}{$item} ne '') {
13867: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13868: $changes{$role}{'links'}{$item} = 1;
13869: }
13870: } else {
13871: if ($confhash->{$role}{$item}) {
13872: $changes{$role}{'links'}{$item} = 1;
13873: }
13874: }
13875: }
1.41 raeburn 13876: foreach my $item (@logintext) {
13877: if ($domconfig->{$role}{$item} ne '') {
13878: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13879: $changes{$role}{'logintext'}{$item} = 1;
13880: }
13881: } else {
13882: if ($confhash->{$role}{$item}) {
13883: $changes{$role}{'logintext'}{$item} = 1;
13884: }
13885: }
13886: }
1.6 raeburn 13887: } else {
13888: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13889: \@logintext,$confhash,\%changes);
1.6 raeburn 13890: }
13891: } else {
13892: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13893: \@logintext,$confhash,\%changes);
1.6 raeburn 13894: }
13895: }
13896: return ($errors,%changes);
13897: }
13898:
1.46 raeburn 13899: sub config_check {
13900: my ($dom,$confname,$servadm) = @_;
13901: my ($configuserok,$author_ok,$switchserver,%currroles);
13902: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13903: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13904: $confname,$servadm);
13905: if ($configuserok eq 'ok') {
13906: $switchserver = &check_switchserver($dom,$confname);
13907: if ($switchserver eq '') {
13908: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13909: }
13910: }
13911: return ($configuserok,$author_ok,$switchserver);
13912: }
13913:
1.6 raeburn 13914: sub default_change_checker {
1.41 raeburn 13915: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13916: foreach my $item (@{$links}) {
13917: if ($confhash->{$role}{$item}) {
13918: $changes->{$role}{'links'}{$item} = 1;
13919: }
13920: }
13921: foreach my $item (@{$bgs}) {
13922: if ($confhash->{$role}{$item}) {
13923: $changes->{$role}{'bgs'}{$item} = 1;
13924: }
13925: }
1.41 raeburn 13926: foreach my $item (@{$logintext}) {
13927: if ($confhash->{$role}{$item}) {
13928: $changes->{$role}{'logintext'}{$item} = 1;
13929: }
13930: }
1.6 raeburn 13931: foreach my $img (@{$images}) {
13932: if ($env{'form.'.$role.'_del_'.$img}) {
13933: $confhash->{$role}{$img} = '';
1.12 raeburn 13934: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13935: }
1.70 raeburn 13936: if ($role eq 'login') {
13937: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13938: $changes->{$role}{'showlogo'}{$img} = 1;
13939: }
1.402 raeburn 13940: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13941: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13942: $changes->{$role}{'alttext'}{$img} = 1;
13943: }
13944: }
1.70 raeburn 13945: }
1.6 raeburn 13946: }
13947: if ($confhash->{$role}{'font'}) {
13948: $changes->{$role}{'font'} = 1;
13949: }
1.48 raeburn 13950: }
1.6 raeburn 13951:
13952: sub display_colorchgs {
13953: my ($dom,$changes,$roles,$confhash) = @_;
13954: my (%choices,$resulttext);
13955: if (!grep(/^login$/,@{$roles})) {
13956: $resulttext = &mt('Changes made:').'<br />';
13957: }
13958: foreach my $role (@{$roles}) {
13959: if ($role eq 'login') {
13960: %choices = &login_choices();
13961: } else {
13962: %choices = &color_font_choices();
13963: }
13964: if (ref($changes->{$role}) eq 'HASH') {
13965: if ($role ne 'login') {
13966: $resulttext .= '<h4>'.&mt($role).'</h4>';
13967: }
13968: foreach my $key (sort(keys(%{$changes->{$role}}))) {
13969: if ($role ne 'login') {
13970: $resulttext .= '<ul>';
13971: }
13972: if (ref($changes->{$role}{$key}) eq 'HASH') {
13973: if ($role ne 'login') {
13974: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
13975: }
13976: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 13977: if (($role eq 'login') && ($key eq 'showlogo')) {
13978: if ($confhash->{$role}{$key}{$item}) {
13979: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
13980: } else {
13981: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
13982: }
1.402 raeburn 13983: } elsif (($role eq 'login') && ($key eq 'alttext')) {
13984: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 13985: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 13986: $confhash->{$role}{$key}{$item}).'</li>';
13987: } else {
13988: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
13989: }
1.70 raeburn 13990: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 13991: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
13992: } else {
1.12 raeburn 13993: my $newitem = $confhash->{$role}{$item};
13994: if ($key eq 'images') {
1.306 raeburn 13995: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 13996: }
13997: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 13998: }
13999: }
14000: if ($role ne 'login') {
14001: $resulttext .= '</ul></li>';
14002: }
14003: } else {
14004: if ($confhash->{$role}{$key} eq '') {
14005: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
14006: } else {
14007: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
14008: }
14009: }
14010: if ($role ne 'login') {
14011: $resulttext .= '</ul>';
14012: }
14013: }
14014: }
14015: }
1.3 raeburn 14016: return $resulttext;
1.1 raeburn 14017: }
14018:
1.9 raeburn 14019: sub thumb_dimensions {
14020: return ('200','50');
14021: }
14022:
1.16 raeburn 14023: sub check_dimensions {
14024: my ($inputfile) = @_;
14025: my ($fullwidth,$fullheight);
14026: if ($inputfile =~ m|^[/\w.\-]+$|) {
14027: if (open(PIPE,"identify $inputfile 2>&1 |")) {
14028: my $imageinfo = <PIPE>;
14029: if (!close(PIPE)) {
14030: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
14031: }
14032: chomp($imageinfo);
14033: my ($fullsize) =
1.21 raeburn 14034: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 14035: if ($fullsize) {
14036: ($fullwidth,$fullheight) = split(/x/,$fullsize);
14037: }
14038: }
14039: }
14040: return ($fullwidth,$fullheight);
14041: }
14042:
1.9 raeburn 14043: sub check_configuser {
14044: my ($uhome,$dom,$confname,$servadm) = @_;
14045: my ($configuserok,%currroles);
14046: if ($uhome eq 'no_host') {
14047: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 14048: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 14049: $configuserok =
14050: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
14051: $configpass,'','','','','',undef,$servadm);
14052: } else {
14053: $configuserok = 'ok';
14054: %currroles =
14055: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
14056: }
14057: return ($configuserok,%currroles);
14058: }
14059:
14060: sub check_authorstatus {
14061: my ($dom,$confname,%currroles) = @_;
14062: my $author_ok;
1.40 raeburn 14063: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 14064: my $start = time;
14065: my $end = 0;
14066: $author_ok =
14067: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 14068: 'au',$end,$start,'','','domconfig');
1.9 raeburn 14069: } else {
14070: $author_ok = 'ok';
14071: }
14072: return $author_ok;
14073: }
14074:
1.421 raeburn 14075: sub update_modify_urls {
14076: my ($r,$modified) = @_;
14077: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
14078: push(@{$modified_urls},$modified);
14079: unless ($registered_cleanup) {
14080: my $handlers = $r->get_handlers('PerlCleanupHandler');
14081: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
14082: $registered_cleanup=1;
1.9 raeburn 14083: }
14084: }
1.155 raeburn 14085: }
14086:
14087: sub notifysubscribed {
14088: foreach my $targetsource (@{$modified_urls}){
14089: next unless (ref($targetsource) eq 'ARRAY');
14090: my ($target,$source)=@{$targetsource};
14091: if ($source ne '') {
1.316 raeburn 14092: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 14093: print $logfh "\nCleanup phase: Notifications\n";
14094: my @subscribed=&subscribed_hosts($target);
14095: foreach my $subhost (@subscribed) {
14096: print $logfh "\nNotifying host ".$subhost.':';
14097: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
14098: print $logfh $reply;
14099: }
14100: my @subscribedmeta=&subscribed_hosts("$target.meta");
14101: foreach my $subhost (@subscribedmeta) {
14102: print $logfh "\nNotifying host for metadata only ".$subhost.':';
14103: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
14104: $subhost);
14105: print $logfh $reply;
14106: }
14107: print $logfh "\n============ Done ============\n";
1.160 raeburn 14108: close($logfh);
1.155 raeburn 14109: }
14110: }
14111: }
14112: return OK;
14113: }
14114:
14115: sub subscribed_hosts {
14116: my ($target) = @_;
14117: my @subscribed;
1.316 raeburn 14118: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 14119: while (my $subline=<$fh>) {
14120: if ($subline =~ /^($match_lonid):/) {
14121: my $host = $1;
14122: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
14123: unless (grep(/^\Q$host\E$/,@subscribed)) {
14124: push(@subscribed,$host);
14125: }
14126: }
14127: }
14128: }
14129: }
14130: return @subscribed;
1.9 raeburn 14131: }
14132:
14133: sub check_switchserver {
14134: my ($dom,$confname) = @_;
1.424 raeburn 14135: my ($allowed,$switchserver,$home);
14136: if ($confname eq '') {
1.9 raeburn 14137: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14138: } else {
14139: $home = &Apache::lonnet::homeserver($confname,$dom);
14140: if ($home eq 'no_host') {
14141: $home = &Apache::lonnet::domain($dom,'primary');
14142: }
1.9 raeburn 14143: }
14144: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14145: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14146: if (!$allowed) {
1.426 raeburn 14147: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14148: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14149: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14150: }
14151: return $switchserver;
14152: }
14153:
1.1 raeburn 14154: sub modify_quotas {
1.216 raeburn 14155: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14156: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14157: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14158: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14159: $validationfieldsref);
1.86 raeburn 14160: if ($action eq 'quotas') {
1.429 raeburn 14161: $context = 'tools';
1.163 raeburn 14162: } else {
1.86 raeburn 14163: $context = $action;
14164: }
14165: if ($context eq 'requestcourses') {
1.325 raeburn 14166: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14167: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14168: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14169: %titles = &courserequest_titles();
14170: $toolregexp = join('|',@usertools);
14171: %conditions = &courserequest_conditions();
1.216 raeburn 14172: $confname = $dom.'-domainconfig';
14173: my $servadm = $r->dir_config('lonAdmEMail');
14174: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14175: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14176: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14177: } elsif ($context eq 'requestauthor') {
14178: @usertools = ('author');
14179: %titles = &authorrequest_titles();
1.86 raeburn 14180: } else {
1.430 raeburn 14181: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14182: %titles = &tool_titles();
1.86 raeburn 14183: }
1.212 raeburn 14184: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14185: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14186: foreach my $key (keys(%env)) {
1.101 raeburn 14187: if ($context eq 'requestcourses') {
14188: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14189: my $item = $1;
14190: my $type = $2;
14191: if ($type =~ /^limit_(.+)/) {
14192: $limithash{$item}{$1} = $env{$key};
14193: } else {
14194: $confhash{$item}{$type} = $env{$key};
14195: }
14196: }
1.163 raeburn 14197: } elsif ($context eq 'requestauthor') {
14198: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14199: $confhash{$1} = $env{$key};
14200: }
1.101 raeburn 14201: } else {
1.86 raeburn 14202: if ($key =~ /^form\.quota_(.+)$/) {
14203: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14204: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14205: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14206: }
1.72 raeburn 14207: }
14208: }
1.163 raeburn 14209: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14210: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14211: @approvalnotify = sort(@approvalnotify);
14212: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14213: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14214: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14215: foreach my $type (@hasuniquecode) {
14216: if (grep(/^\Q$type\E$/,@crstypes)) {
14217: $confhash{'uniquecode'}{$type} = 1;
14218: }
1.216 raeburn 14219: }
1.242 raeburn 14220: my (%newbook,%allpos);
1.216 raeburn 14221: if ($context eq 'requestcourses') {
1.242 raeburn 14222: foreach my $type ('textbooks','templates') {
14223: @{$allpos{$type}} = ();
14224: my $invalid;
14225: if ($type eq 'textbooks') {
14226: $invalid = &mt('Invalid LON-CAPA course for textbook');
14227: } else {
14228: $invalid = &mt('Invalid LON-CAPA course for template');
14229: }
14230: if ($env{'form.'.$type.'_addbook'}) {
14231: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14232: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14233: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14234: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14235: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14236: } else {
14237: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14238: my $position = $env{'form.'.$type.'_addbook_pos'};
14239: $position =~ s/\D+//g;
14240: if ($position ne '') {
14241: $allpos{$type}[$position] = $newbook{$type};
14242: }
1.216 raeburn 14243: }
1.242 raeburn 14244: } else {
14245: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14246: }
14247: }
1.242 raeburn 14248: }
1.216 raeburn 14249: }
1.102 raeburn 14250: if (ref($domconfig{$action}) eq 'HASH') {
14251: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14252: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14253: $changes{'notify'}{'approval'} = 1;
14254: }
14255: } else {
1.144 raeburn 14256: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14257: $changes{'notify'}{'approval'} = 1;
14258: }
14259: }
1.218 raeburn 14260: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14261: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14262: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14263: unless ($confhash{'uniquecode'}{$crstype}) {
14264: $changes{'uniquecode'} = 1;
14265: }
14266: }
14267: unless ($changes{'uniquecode'}) {
14268: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14269: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14270: $changes{'uniquecode'} = 1;
14271: }
14272: }
14273: }
14274: } else {
14275: $changes{'uniquecode'} = 1;
14276: }
14277: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14278: $changes{'uniquecode'} = 1;
1.216 raeburn 14279: }
14280: if ($context eq 'requestcourses') {
1.242 raeburn 14281: foreach my $type ('textbooks','templates') {
14282: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14283: my %deletions;
14284: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14285: if (@todelete) {
14286: map { $deletions{$_} = 1; } @todelete;
14287: }
14288: my %imgdeletions;
14289: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14290: if (@todeleteimages) {
14291: map { $imgdeletions{$_} = 1; } @todeleteimages;
14292: }
14293: my $maxnum = $env{'form.'.$type.'_maxnum'};
14294: for (my $i=0; $i<=$maxnum; $i++) {
14295: my $itemid = $env{'form.'.$type.'_id_'.$i};
14296: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14297: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14298: if ($deletions{$key}) {
14299: if ($domconfig{$action}{$type}{$key}{'image'}) {
14300: #FIXME need to obsolete item in RES space
14301: }
14302: next;
14303: } else {
14304: my $newpos = $env{'form.'.$itemid};
14305: $newpos =~ s/\D+//g;
1.243 raeburn 14306: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14307: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14308: ($type eq 'templates'));
1.242 raeburn 14309: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14310: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14311: $changes{$type}{$key} = 1;
14312: }
14313: }
14314: $allpos{$type}[$newpos] = $key;
14315: }
14316: if ($imgdeletions{$key}) {
14317: $changes{$type}{$key} = 1;
1.216 raeburn 14318: #FIXME need to obsolete item in RES space
1.242 raeburn 14319: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14320: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14321: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14322: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14323: } else {
14324: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14325: $cdom,$cnum,$type,$configuserok,
14326: $switchserver,$author_ok);
14327: if ($imgurl) {
14328: $confhash{$type}{$key}{'image'} = $imgurl;
14329: $changes{$type}{$key} = 1;
14330: }
14331: if ($error) {
14332: &Apache::lonnet::logthis($error);
14333: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14334: }
14335: }
1.242 raeburn 14336: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14337: $confhash{$type}{$key}{'image'} =
14338: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14339: }
14340: }
14341: }
14342: }
14343: }
14344: }
1.102 raeburn 14345: } else {
1.144 raeburn 14346: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14347: $changes{'notify'}{'approval'} = 1;
14348: }
1.218 raeburn 14349: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14350: $changes{'uniquecode'} = 1;
14351: }
14352: }
14353: if ($context eq 'requestcourses') {
1.242 raeburn 14354: foreach my $type ('textbooks','templates') {
14355: if ($newbook{$type}) {
14356: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14357: foreach my $item ('subject','title','publisher','author') {
14358: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14359: ($type eq 'template'));
1.242 raeburn 14360: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14361: if ($env{'form.'.$type.'_addbook_'.$item}) {
14362: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14363: }
14364: }
14365: if ($type eq 'textbooks') {
14366: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14367: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14368: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14369: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14370: } else {
14371: my ($imageurl,$error) =
14372: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14373: $configuserok,$switchserver,$author_ok);
14374: if ($imageurl) {
14375: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14376: }
14377: if ($error) {
14378: &Apache::lonnet::logthis($error);
14379: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14380: }
1.242 raeburn 14381: }
14382: }
1.216 raeburn 14383: }
14384: }
1.242 raeburn 14385: if (@{$allpos{$type}} > 0) {
14386: my $idx = 0;
14387: foreach my $item (@{$allpos{$type}}) {
14388: if ($item ne '') {
14389: $confhash{$type}{$item}{'order'} = $idx;
14390: if (ref($domconfig{$action}) eq 'HASH') {
14391: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14392: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14393: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14394: $changes{$type}{$item} = 1;
14395: }
1.216 raeburn 14396: }
14397: }
14398: }
1.242 raeburn 14399: $idx ++;
1.216 raeburn 14400: }
14401: }
14402: }
14403: }
1.235 raeburn 14404: if (ref($validationitemsref) eq 'ARRAY') {
14405: foreach my $item (@{$validationitemsref}) {
14406: if ($item eq 'fields') {
14407: my @changed;
14408: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14409: if (@{$confhash{'validation'}{$item}} > 0) {
14410: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14411: }
1.266 raeburn 14412: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14413: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14414: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14415: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14416: $domconfig{'requestcourses'}{'validation'}{$item});
14417: } else {
14418: @changed = @{$confhash{'validation'}{$item}};
14419: }
1.235 raeburn 14420: } else {
14421: @changed = @{$confhash{'validation'}{$item}};
14422: }
14423: } else {
14424: @changed = @{$confhash{'validation'}{$item}};
14425: }
14426: if (@changed) {
14427: if ($confhash{'validation'}{$item}) {
14428: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14429: } else {
14430: $changes{'validation'}{$item} = &mt('None');
14431: }
14432: }
14433: } else {
14434: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14435: if ($item eq 'markup') {
14436: if ($env{'form.requestcourses_validation_'.$item}) {
14437: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14438: }
14439: }
1.266 raeburn 14440: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14441: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14442: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14443: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14444: }
14445: } else {
14446: if ($confhash{'validation'}{$item} ne '') {
14447: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14448: }
1.235 raeburn 14449: }
14450: } else {
14451: if ($confhash{'validation'}{$item} ne '') {
14452: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14453: }
14454: }
14455: }
14456: }
14457: }
14458: if ($env{'form.validationdc'}) {
14459: my $newval = $env{'form.validationdc'};
1.285 raeburn 14460: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14461: if (exists($domcoords{$newval})) {
14462: $confhash{'validation'}{'dc'} = $newval;
14463: }
14464: }
14465: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14466: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14467: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14468: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14469: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14470: if ($confhash{'validation'}{'dc'} eq '') {
14471: $changes{'validation'}{'dc'} = &mt('None');
14472: } else {
14473: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14474: }
1.235 raeburn 14475: }
1.266 raeburn 14476: } elsif ($confhash{'validation'}{'dc'} ne '') {
14477: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14478: }
14479: } elsif ($confhash{'validation'}{'dc'} ne '') {
14480: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14481: }
14482: } elsif ($confhash{'validation'}{'dc'} ne '') {
14483: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14484: }
1.266 raeburn 14485: } else {
14486: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14487: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14488: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14489: $changes{'validation'}{'dc'} = &mt('None');
14490: }
14491: }
1.235 raeburn 14492: }
14493: }
1.102 raeburn 14494: }
14495: } else {
1.86 raeburn 14496: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14497: }
1.72 raeburn 14498: foreach my $item (@usertools) {
14499: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14500: my $unset;
1.101 raeburn 14501: if ($context eq 'requestcourses') {
1.104 raeburn 14502: $unset = '0';
14503: if ($type eq '_LC_adv') {
14504: $unset = '';
14505: }
1.101 raeburn 14506: if ($confhash{$item}{$type} eq 'autolimit') {
14507: $confhash{$item}{$type} .= '=';
14508: unless ($limithash{$item}{$type} =~ /\D/) {
14509: $confhash{$item}{$type} .= $limithash{$item}{$type};
14510: }
14511: }
1.163 raeburn 14512: } elsif ($context eq 'requestauthor') {
14513: $unset = '0';
14514: if ($type eq '_LC_adv') {
14515: $unset = '';
14516: }
1.72 raeburn 14517: } else {
1.101 raeburn 14518: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14519: $confhash{$item}{$type} = 1;
14520: } else {
14521: $confhash{$item}{$type} = 0;
14522: }
1.72 raeburn 14523: }
1.86 raeburn 14524: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14525: if ($action eq 'requestauthor') {
14526: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14527: $changes{$type} = 1;
14528: }
14529: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14530: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14531: $changes{$item}{$type} = 1;
14532: }
14533: } else {
14534: if ($context eq 'requestcourses') {
1.104 raeburn 14535: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14536: $changes{$item}{$type} = 1;
14537: }
14538: } else {
14539: if (!$confhash{$item}{$type}) {
14540: $changes{$item}{$type} = 1;
14541: }
14542: }
14543: }
14544: } else {
14545: if ($context eq 'requestcourses') {
1.104 raeburn 14546: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14547: $changes{$item}{$type} = 1;
14548: }
1.163 raeburn 14549: } elsif ($context eq 'requestauthor') {
14550: if ($confhash{$type} ne $unset) {
14551: $changes{$type} = 1;
14552: }
1.72 raeburn 14553: } else {
14554: if (!$confhash{$item}{$type}) {
14555: $changes{$item}{$type} = 1;
14556: }
14557: }
14558: }
1.1 raeburn 14559: }
14560: }
1.163 raeburn 14561: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14562: if (ref($domconfig{'quotas'}) eq 'HASH') {
14563: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14564: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14565: if (exists($confhash{'defaultquota'}{$key})) {
14566: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14567: $changes{'defaultquota'}{$key} = 1;
14568: }
14569: } else {
14570: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14571: }
14572: }
1.86 raeburn 14573: } else {
14574: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14575: if (exists($confhash{'defaultquota'}{$key})) {
14576: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14577: $changes{'defaultquota'}{$key} = 1;
14578: }
14579: } else {
14580: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14581: }
1.1 raeburn 14582: }
14583: }
1.197 raeburn 14584: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14585: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14586: }
14587: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14588: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14589: }
1.1 raeburn 14590: }
1.86 raeburn 14591: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14592: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14593: if (ref($domconfig{'quotas'}) eq 'HASH') {
14594: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14595: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14596: $changes{'defaultquota'}{$key} = 1;
14597: }
14598: } else {
14599: if (!exists($domconfig{'quotas'}{$key})) {
14600: $changes{'defaultquota'}{$key} = 1;
14601: }
1.72 raeburn 14602: }
14603: } else {
1.86 raeburn 14604: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14605: }
1.1 raeburn 14606: }
14607: }
14608: }
1.72 raeburn 14609:
1.163 raeburn 14610: if ($context eq 'requestauthor') {
14611: $domdefaults{'requestauthor'} = \%confhash;
14612: } else {
14613: foreach my $key (keys(%confhash)) {
1.242 raeburn 14614: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14615: $domdefaults{$key} = $confhash{$key};
14616: }
1.163 raeburn 14617: }
1.72 raeburn 14618: }
1.163 raeburn 14619:
1.1 raeburn 14620: my %quotahash = (
1.86 raeburn 14621: $action => { %confhash }
1.1 raeburn 14622: );
14623: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14624: $dom);
14625: if ($putresult eq 'ok') {
14626: if (keys(%changes) > 0) {
1.72 raeburn 14627: my $cachetime = 24*60*60;
14628: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14629: if (ref($lastactref) eq 'HASH') {
14630: $lastactref->{'domdefaults'} = 1;
14631: }
1.1 raeburn 14632: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14633: unless (($context eq 'requestcourses') ||
1.163 raeburn 14634: ($context eq 'requestauthor')) {
1.86 raeburn 14635: if (ref($changes{'defaultquota'}) eq 'HASH') {
14636: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14637: foreach my $type (@{$types},'default') {
14638: if (defined($changes{'defaultquota'}{$type})) {
14639: my $typetitle = $usertypes->{$type};
14640: if ($type eq 'default') {
14641: $typetitle = $othertitle;
14642: }
1.213 raeburn 14643: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14644: }
14645: }
1.86 raeburn 14646: $resulttext .= '</ul></li>';
1.72 raeburn 14647: }
14648: }
1.80 raeburn 14649: my %newenv;
1.72 raeburn 14650: foreach my $item (@usertools) {
1.163 raeburn 14651: my (%haschgs,%inconf);
14652: if ($context eq 'requestauthor') {
14653: %haschgs = %changes;
1.210 raeburn 14654: %inconf = %confhash;
1.163 raeburn 14655: } else {
14656: if (ref($changes{$item}) eq 'HASH') {
14657: %haschgs = %{$changes{$item}};
14658: }
14659: if (ref($confhash{$item}) eq 'HASH') {
14660: %inconf = %{$confhash{$item}};
14661: }
14662: }
14663: if (keys(%haschgs) > 0) {
1.80 raeburn 14664: my $newacc =
14665: &Apache::lonnet::usertools_access($env{'user.name'},
14666: $env{'user.domain'},
1.86 raeburn 14667: $item,'reload',$context);
1.210 raeburn 14668: if (($context eq 'requestcourses') ||
1.163 raeburn 14669: ($context eq 'requestauthor')) {
1.108 raeburn 14670: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14671: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14672: }
14673: } else {
14674: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14675: $newenv{'environment.availabletools.'.$item} = $newacc;
14676: }
1.80 raeburn 14677: }
1.163 raeburn 14678: unless ($context eq 'requestauthor') {
14679: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14680: }
1.72 raeburn 14681: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14682: if ($haschgs{$type}) {
1.72 raeburn 14683: my $typetitle = $usertypes->{$type};
14684: if ($type eq 'default') {
14685: $typetitle = $othertitle;
14686: } elsif ($type eq '_LC_adv') {
14687: $typetitle = 'LON-CAPA Advanced Users';
14688: }
1.163 raeburn 14689: if ($inconf{$type}) {
1.101 raeburn 14690: if ($context eq 'requestcourses') {
14691: my $cond;
1.163 raeburn 14692: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14693: if ($1 eq '') {
14694: $cond = &mt('(Automatic processing of any request).');
14695: } else {
14696: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14697: }
14698: } else {
1.163 raeburn 14699: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14700: }
14701: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14702: } elsif ($context eq 'requestauthor') {
14703: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14704: $titles{$inconf{$type}},$typetitle);
14705:
1.101 raeburn 14706: } else {
14707: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14708: }
1.72 raeburn 14709: } else {
1.104 raeburn 14710: if ($type eq '_LC_adv') {
1.163 raeburn 14711: if ($inconf{$type} eq '0') {
1.104 raeburn 14712: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14713: } else {
14714: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14715: }
14716: } else {
14717: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14718: }
1.72 raeburn 14719: }
14720: }
1.26 raeburn 14721: }
1.163 raeburn 14722: unless ($context eq 'requestauthor') {
14723: $resulttext .= '</ul></li>';
14724: }
1.26 raeburn 14725: }
1.1 raeburn 14726: }
1.163 raeburn 14727: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14728: if (ref($changes{'notify'}) eq 'HASH') {
14729: if ($changes{'notify'}{'approval'}) {
14730: if (ref($confhash{'notify'}) eq 'HASH') {
14731: if ($confhash{'notify'}{'approval'}) {
14732: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14733: } else {
1.163 raeburn 14734: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14735: }
14736: }
14737: }
14738: }
14739: }
1.216 raeburn 14740: if ($action eq 'requestcourses') {
14741: my @offon = ('off','on');
14742: if ($changes{'uniquecode'}) {
1.218 raeburn 14743: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14744: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14745: $resulttext .= '<li>'.
14746: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14747: '</li>';
14748: } else {
14749: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14750: '</li>';
14751: }
1.216 raeburn 14752: }
1.242 raeburn 14753: foreach my $type ('textbooks','templates') {
14754: if (ref($changes{$type}) eq 'HASH') {
14755: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14756: foreach my $key (sort(keys(%{$changes{$type}}))) {
14757: my %coursehash = &Apache::lonnet::coursedescription($key);
14758: my $coursetitle = $coursehash{'description'};
14759: my $position = $confhash{$type}{$key}{'order'} + 1;
14760: $resulttext .= '<li>';
1.243 raeburn 14761: foreach my $item ('subject','title','publisher','author') {
14762: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14763: ($type eq 'templates'));
1.242 raeburn 14764: my $name = $item.':';
14765: $name =~ s/^(\w)/\U$1/;
14766: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14767: }
14768: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14769: if ($type eq 'textbooks') {
14770: if ($confhash{$type}{$key}{'image'}) {
14771: $resulttext .= ' '.&mt('Image: [_1]',
14772: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14773: ' alt="Textbook cover" />').'<br />';
14774: }
14775: }
14776: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14777: }
1.242 raeburn 14778: $resulttext .= '</ul></li>';
1.216 raeburn 14779: }
14780: }
1.235 raeburn 14781: if (ref($changes{'validation'}) eq 'HASH') {
14782: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14783: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14784: foreach my $item (@{$validationitemsref}) {
14785: if (exists($changes{'validation'}{$item})) {
14786: if ($item eq 'markup') {
14787: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14788: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14789: } else {
14790: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14791: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14792: }
14793: }
14794: }
14795: if (exists($changes{'validation'}{'dc'})) {
14796: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14797: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14798: }
1.442 raeburn 14799: $resulttext .= '</ul></li>';
1.235 raeburn 14800: }
14801: }
1.216 raeburn 14802: }
1.1 raeburn 14803: $resulttext .= '</ul>';
1.80 raeburn 14804: if (keys(%newenv)) {
14805: &Apache::lonnet::appenv(\%newenv);
14806: }
1.1 raeburn 14807: } else {
1.86 raeburn 14808: if ($context eq 'requestcourses') {
14809: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14810: } elsif ($context eq 'requestauthor') {
14811: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14812: } else {
1.90 weissno 14813: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14814: }
1.1 raeburn 14815: }
14816: } else {
1.11 albertel 14817: $resulttext = '<span class="LC_error">'.
14818: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14819: }
1.216 raeburn 14820: if ($errors) {
14821: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14822: '<ul>'.$errors.'</ul></p>';
14823: }
1.3 raeburn 14824: return $resulttext;
1.1 raeburn 14825: }
14826:
1.216 raeburn 14827: sub process_textbook_image {
1.242 raeburn 14828: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14829: my $filename = $env{'form.'.$caller.'.filename'};
14830: my ($error,$url);
14831: my ($width,$height) = (50,50);
14832: if ($configuserok eq 'ok') {
14833: if ($switchserver) {
14834: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14835: $switchserver);
14836: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14837: my $modified = [];
1.216 raeburn 14838: my ($result,$imageurl) =
1.421 raeburn 14839: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14840: "$type/$cdom/$cnum/cover",$width,$height,
14841: '',$modified);
1.216 raeburn 14842: if ($result eq 'ok') {
14843: $url = $imageurl;
1.421 raeburn 14844: &update_modify_urls($r,$modified);
1.216 raeburn 14845: } else {
14846: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14847: }
14848: } else {
14849: $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);
14850: }
14851: } else {
14852: $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);
14853: }
14854: return ($url,$error);
14855: }
14856:
1.267 raeburn 14857: sub modify_ltitools {
14858: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14859: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14860: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14861:
1.267 raeburn 14862: my $confname = $dom.'-domainconfig';
14863: my $servadm = $r->dir_config('lonAdmEMail');
14864: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14865:
14866: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14867: my $toolserror =
14868: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14869: $lastactref,$configuserok,$switchserver,$author_ok);
14870:
14871: my $home = &Apache::lonnet::domain($dom,'primary');
14872: unless (($home eq 'no_host') || ($home eq '')) {
14873: my @ids=&Apache::lonnet::current_machine_ids();
14874: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14875: }
14876:
14877: if (keys(%ltitoolschg)) {
14878: foreach my $id (keys(%ltitoolschg)) {
14879: if (ref($ltitoolschg{$id}) eq 'HASH') {
14880: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14881: if (($inner eq 'secret') || ($inner eq 'key')) {
14882: if ($is_home) {
14883: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14884: }
14885: }
14886: }
1.267 raeburn 14887: }
1.421 raeburn 14888: }
14889: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14890: if (keys(%ltitoolschg)) {
14891: %newltitools = %ltitoolschg;
14892: }
14893: }
14894: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14895: foreach my $id (%{$domconfig{'ltitools'}}) {
14896: next if ($id !~ /^\d+$/);
14897: unless (exists($ltitoolschg{$id})) {
14898: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14899: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14900: if (($inner eq 'secret') || ($inner eq 'key')) {
14901: if ($is_home) {
14902: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14903: }
14904: } else {
14905: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14906: }
14907: }
14908: } else {
14909: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14910: }
1.421 raeburn 14911: }
14912: }
14913: }
14914: if ($toolserror) {
14915: $errors = '<li>'.$toolserror.'</li>';
14916: }
14917: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14918: $resulttext = &mt('No changes made.');
14919: if ($errors) {
14920: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14921: $errors.'</ul>';
14922: }
14923: return $resulttext;
14924: }
14925: my %ltitoolshash = (
14926: $action => { %newltitools }
14927: );
14928: if (keys(%secchanges)) {
14929: $ltitoolshash{'toolsec'} = \%newtoolsec;
14930: }
14931: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14932: if ($putresult eq 'ok') {
14933: my %keystore;
14934: if ($is_home) {
14935: my %toolsenchash = (
14936: $action => { %newtoolsenc }
14937: );
14938: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 14939: my $cachetime = 24*60*60;
14940: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 14941: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
14942: }
14943: $resulttext = &mt('Changes made:').'<ul>';
14944: if (keys(%secchanges) > 0) {
1.423 raeburn 14945: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 14946: }
14947: if (keys(%ltitoolschg) > 0) {
14948: $resulttext .= $ltitoolsoutput;
14949: }
1.423 raeburn 14950: my $cachetime = 24*60*60;
14951: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
14952: if (ref($lastactref) eq 'HASH') {
14953: $lastactref->{'ltitools'} = 1;
14954: }
1.421 raeburn 14955: } else {
14956: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14957: }
14958: if ($errors) {
14959: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14960: $errors.'</ul></p>';
14961: }
14962: return $resulttext;
14963: }
14964:
14965: sub fetch_secrets {
14966: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
14967: my %keyset;
14968: %{$currsec} = ();
14969: $newsec->{'private'}{'keys'} = [];
14970: $newsec->{'encrypt'} = {};
14971: $newsec->{'rules'} = {};
14972: if ($context eq 'ltisec') {
14973: $newsec->{'linkprot'} = {};
14974: }
14975: if (ref($domconfig->{$context}) eq 'HASH') {
14976: %{$currsec} = %{$domconfig->{$context}};
14977: if ($context eq 'ltisec') {
14978: if (ref($currsec->{'linkprot'}) eq 'HASH') {
14979: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
14980: unless ($id =~ /^\d+$/) {
14981: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 14982: }
1.267 raeburn 14983: }
14984: }
1.421 raeburn 14985: }
14986: if (ref($currsec->{'private'}) eq 'HASH') {
14987: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
14988: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
14989: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 14990: }
1.421 raeburn 14991: }
14992: }
14993: my @items= ('crs','dom');
14994: if ($context eq 'ltisec') {
14995: push(@items,'consumers');
14996: }
14997: foreach my $item (@items) {
14998: my $formelement;
14999: if (($context eq 'toolsec') || ($item eq 'consumers')) {
15000: $formelement = 'form.'.$context.'_'.$item;
15001: } else {
15002: $formelement = 'form.'.$context.'_'.$item.'linkprot';
15003: }
15004: if ($env{$formelement}) {
15005: $newsec->{'encrypt'}{$item} = 1;
15006: if (ref($currsec->{'encrypt'}) eq 'HASH') {
15007: unless ($currsec->{'encrypt'}{$item}) {
15008: $secchanges->{'encrypt'} = 1;
15009: }
15010: } else {
15011: $secchanges->{'encrypt'} = 1;
1.267 raeburn 15012: }
1.421 raeburn 15013: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
15014: if ($currsec->{'encrypt'}{$item}) {
15015: $secchanges->{'encrypt'} = 1;
1.323 raeburn 15016: }
1.421 raeburn 15017: }
15018: }
15019: my $secrets;
15020: if ($context eq 'ltisec') {
15021: $secrets = 'ltisecrets';
15022: } else {
15023: $secrets = 'toolsecrets';
15024: }
15025: unless (exists($currsec->{'rules'})) {
15026: $currsec->{'rules'} = {};
15027: }
15028: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
15029:
15030: my @ids=&Apache::lonnet::current_machine_ids();
15031: my %servers = &Apache::lonnet::get_servers($dom,'library');
15032:
15033: foreach my $hostid (keys(%servers)) {
15034: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
15035: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
15036: if (exists($env{$keyitem})) {
15037: $env{$keyitem} =~ s/(`)/'/g;
15038: if ($keyset{$hostid}) {
15039: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
15040: if ($env{$keyitem} ne '') {
15041: $secchanges->{'private'} = 1;
15042: $newkeyset->{$hostid} = $env{$keyitem};
15043: }
1.296 raeburn 15044: }
1.421 raeburn 15045: } elsif ($env{$keyitem} ne '') {
15046: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
15047: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 15048: }
1.421 raeburn 15049: $secchanges->{'private'} = 1;
15050: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 15051: }
15052: }
1.421 raeburn 15053: }
15054: }
15055: }
15056:
15057: sub store_security {
1.424 raeburn 15058: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 15059: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
15060: (ref($keystore) eq 'HASH'));
15061: if (keys(%{$secchanges})) {
15062: if ($secchanges->{'private'}) {
15063: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
15064: foreach my $hostid (keys(%{$newkeyset})) {
15065: my $storehash = {
15066: key => $newkeyset->{$hostid},
15067: who => $env{'user.name'}.':'.$env{'user.domain'},
15068: };
15069: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
15070: $dom,$hostid);
15071: }
15072: }
15073: }
15074: }
15075:
15076: sub lti_security_results {
1.423 raeburn 15077: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 15078: my $output;
1.423 raeburn 15079: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15080: my $needs_update;
1.421 raeburn 15081: foreach my $item (keys(%{$secchanges})) {
15082: if ($item eq 'encrypt') {
1.423 raeburn 15083: $needs_update = 1;
1.421 raeburn 15084: my %encrypted;
15085: if ($context eq 'lti') {
15086: %encrypted = (
15087: crs => {
15088: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
15089: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
15090: },
15091: dom => {
15092: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
15093: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
15094: },
15095: consumers => {
15096: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
15097: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
15098: },
15099: );
1.267 raeburn 15100: } else {
1.421 raeburn 15101: %encrypted = (
15102: crs => {
15103: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
15104: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
15105: },
15106: dom => {
15107: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
15108: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
15109: },
15110: );
15111: }
15112: my @types= ('crs','dom');
15113: if ($context eq 'lti') {
1.423 raeburn 15114: foreach my $type (@types) {
15115: undef($domdefaults{'linkprotenc_'.$type});
15116: }
1.421 raeburn 15117: push(@types,'consumers');
1.423 raeburn 15118: undef($domdefaults{'ltienc_consumers'});
15119: } elsif ($context eq 'ltitools') {
15120: foreach my $type (@types) {
15121: undef($domdefaults{'toolenc_'.$type});
15122: }
1.267 raeburn 15123: }
1.421 raeburn 15124: foreach my $type (@types) {
15125: my $shown = $encrypted{$type}{'off'};
15126: if (ref($newsec->{$item}) eq 'HASH') {
15127: if ($newsec->{$item}{$type}) {
1.423 raeburn 15128: if ($context eq 'lti') {
15129: if ($type eq 'consumers') {
15130: $domdefaults{'ltienc_consumers'} = 1;
15131: } else {
15132: $domdefaults{'linkprotenc_'.$type} = 1;
15133: }
15134: } elsif ($context eq 'ltitools') {
15135: $domdefaults{'toolenc_'.$type} = 1;
15136: }
1.421 raeburn 15137: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15138: }
1.267 raeburn 15139: }
1.421 raeburn 15140: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15141: }
1.421 raeburn 15142: } elsif ($item eq 'rules') {
15143: my %titles = &Apache::lonlocal::texthash(
15144: min => 'Minimum password length',
15145: max => 'Maximum password length',
15146: chars => 'Required characters',
15147: );
15148: foreach my $rule ('min','max') {
15149: if ($newsec->{rules}{$rule} eq '') {
15150: if ($rule eq 'min') {
15151: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15152: ' '.&mt('Default of [_1] will be used',
15153: $Apache::lonnet::passwdmin).'</li>';
15154: } else {
15155: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15156: }
15157: } else {
15158: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15159: }
15160: }
15161: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15162: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15163: my %rulenames = &Apache::lonlocal::texthash(
15164: uc => 'At least one upper case letter',
15165: lc => 'At least one lower case letter',
15166: num => 'At least one number',
15167: spec => 'At least one non-alphanumeric',
15168: );
15169: my $needed = '<ul><li>'.
15170: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15171: '</li></ul>';
15172: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15173: } else {
15174: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15175: }
1.421 raeburn 15176: } else {
15177: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15178: }
1.421 raeburn 15179: } elsif ($item eq 'private') {
1.423 raeburn 15180: $needs_update = 1;
15181: if ($context eq 'lti') {
15182: undef($domdefaults{'ltiprivhosts'});
15183: } elsif ($context eq 'ltitools') {
15184: undef($domdefaults{'toolprivhosts'});
15185: }
1.421 raeburn 15186: if (keys(%{$newkeyset})) {
1.423 raeburn 15187: my @privhosts;
1.421 raeburn 15188: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15189: if ($keystore->{$hostid} eq 'ok') {
15190: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15191: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15192: push(@privhosts,$hostid);
15193: }
15194: }
15195: }
15196: if (@privhosts) {
15197: if ($context eq 'lti') {
15198: $domdefaults{'ltiprivhosts'} = \@privhosts;
15199: } elsif ($context eq 'ltitools') {
15200: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15201: }
15202: }
15203: }
1.421 raeburn 15204: } elsif ($item eq 'linkprot') {
15205: next;
1.434 raeburn 15206: } elsif ($item eq 'suggested') {
15207: if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
15208: (ref($newsec->{'suggested'}) eq 'HASH')) {
15209: my $suggestions;
15210: foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
15211: if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
15212: my $name = $newsec->{'suggested'}->{$id}->{'name'};
15213: my $info = $newsec->{'suggested'}->{$id}->{'info'};
15214: $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
15215: &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
15216: '</li>';
15217: } else {
15218: $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
15219: $newsec->{'suggested'}->{$id}).'</li>';
15220: }
15221: }
15222: if ($suggestions) {
15223: $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
15224: '<ul>'.$suggestions.'</ul>'.
15225: '</li>';
15226: }
15227: }
1.267 raeburn 15228: }
15229: }
1.423 raeburn 15230: if ($needs_update) {
15231: my $cachetime = 24*60*60;
15232: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15233: }
1.421 raeburn 15234: return $output;
15235: }
15236:
15237: sub modify_proctoring {
15238: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15239: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15240: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15241: my $confname = $dom.'-domainconfig';
15242: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15243: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15244: my %providernames = &proctoring_providernames();
15245: my $maxnum = scalar(keys(%providernames));
15246:
15247: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15248: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15249: if (ref($requref) eq 'HASH') {
15250: %requserfields = %{$requref};
15251: }
15252: if (ref($opturef) eq 'HASH') {
15253: %optuserfields = %{$opturef};
15254: }
15255: if (ref($defref) eq 'HASH') {
15256: %defaults = %{$defref};
15257: }
15258: if (ref($extref) eq 'HASH') {
15259: %extended = %{$extref};
15260: }
15261: if (ref($crsref) eq 'HASH') {
15262: %crsconf = %{$crsref};
15263: }
15264: if (ref($rolesref) eq 'ARRAY') {
15265: @courseroles = @{$rolesref};
15266: }
15267: if (ref($ltiref) eq 'ARRAY') {
15268: @ltiroles = @{$ltiref};
15269: }
15270:
15271: if (ref($domconfig{$action}) eq 'HASH') {
15272: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15273: if (@todeleteimages) {
15274: map { $imgdeletions{$_} = 1; } @todeleteimages;
15275: }
15276: }
15277: my %customadds;
15278: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15279: if (@newcustom) {
15280: map { $customadds{$_} = 1; } @newcustom;
15281: }
15282: foreach my $provider (sort(keys(%providernames))) {
15283: $confhash{$provider} = {};
15284: my $pos = $env{'form.proctoring_pos_'.$provider};
15285: $pos =~ s/\D+//g;
15286: $allpos[$pos] = $provider;
15287: my (%current,%currentenc);
15288: my $showroles = 0;
15289: if (ref($domconfig{$action}) eq 'HASH') {
15290: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15291: %current = %{$domconfig{$action}{$provider}};
15292: foreach my $item ('key','secret') {
15293: $currentenc{$item} = $current{$item};
15294: delete($current{$item});
15295: }
15296: }
15297: }
15298: if ($env{'form.proctoring_available_'.$provider}) {
15299: $confhash{$provider}{'available'} = 1;
15300: unless ($current{'available'}) {
15301: $changes{$provider} = 1;
15302: }
15303: } else {
15304: %{$confhash{$provider}} = %current;
15305: %{$encconfhash{$provider}} = %currentenc;
15306: $confhash{$provider}{'available'} = 0;
15307: if ($current{'available'}) {
15308: $changes{$provider} = 1;
15309: }
15310: }
15311: if ($confhash{$provider}{'available'}) {
15312: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15313: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15314: if ($field eq 'lifetime') {
15315: if ($possval =~ /^\d+$/) {
15316: $confhash{$provider}{$field} = $possval;
15317: }
15318: } elsif ($field eq 'version') {
15319: if ($possval =~ /^\d+\.\d+$/) {
15320: $confhash{$provider}{$field} = $possval;
15321: }
15322: } elsif ($field eq 'sigmethod') {
15323: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15324: $confhash{$provider}{$field} = $possval;
15325: }
15326: } elsif ($field eq 'url') {
15327: $confhash{$provider}{$field} = $possval;
15328: } elsif (($field eq 'key') || ($field eq 'secret')) {
15329: $encconfhash{$provider}{$field} = $possval;
15330: unless ($currentenc{$field} eq $possval) {
15331: $changes{$provider} = 1;
15332: }
15333: }
15334: unless (($field eq 'key') || ($field eq 'secret')) {
15335: unless ($current{$field} eq $confhash{$provider}{$field}) {
15336: $changes{$provider} = 1;
15337: }
15338: }
15339: }
15340: if ($imgdeletions{$provider}) {
15341: $changes{$provider} = 1;
15342: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15343: my ($imageurl,$error) =
15344: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15345: $configuserok,$switchserver,$author_ok);
15346: if ($imageurl) {
15347: $confhash{$provider}{'image'} = $imageurl;
15348: $changes{$provider} = 1;
15349: }
15350: if ($error) {
15351: &Apache::lonnet::logthis($error);
15352: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15353: }
15354: } elsif (exists($current{'image'})) {
15355: $confhash{$provider}{'image'} = $current{'image'};
15356: }
15357: if (ref($requserfields{$provider}) eq 'ARRAY') {
15358: if (@{$requserfields{$provider}} > 0) {
15359: if (grep(/^user$/,@{$requserfields{$provider}})) {
15360: if ($env{'form.proctoring_userincdom_'.$provider}) {
15361: $confhash{$provider}{'incdom'} = 1;
15362: }
15363: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15364: $changes{$provider} = 1;
15365: }
15366: }
15367: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15368: $showroles = 1;
15369: }
15370: }
15371: }
15372: $confhash{$provider}{'fields'} = [];
15373: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15374: if (@{$optuserfields{$provider}} > 0) {
15375: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15376: foreach my $field (@{$optuserfields{$provider}}) {
15377: if (grep(/^\Q$field\E$/,@optfields)) {
15378: push(@{$confhash{$provider}{'fields'}},$field);
15379: }
15380: }
15381: }
15382: if (ref($current{'fields'}) eq 'ARRAY') {
15383: unless ($changes{$provider}) {
15384: my @new = sort(@{$confhash{$provider}{'fields'}});
15385: my @old = sort(@{$current{'fields'}});
15386: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15387: if (@diffs) {
15388: $changes{$provider} = 1;
15389: }
15390: }
15391: } elsif (@{$confhash{$provider}{'fields'}}) {
15392: $changes{$provider} = 1;
15393: }
15394: }
15395: if (ref($defaults{$provider}) eq 'ARRAY') {
15396: if (@{$defaults{$provider}} > 0) {
15397: my %options;
15398: if (ref($extended{$provider}) eq 'HASH') {
15399: %options = %{$extended{$provider}};
15400: }
15401: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15402: foreach my $field (@{$defaults{$provider}}) {
15403: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15404: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15405: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15406: push(@{$confhash{$provider}{'defaults'}},$poss);
15407: }
15408: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15409: foreach my $inner (keys(%{$options{$field}})) {
15410: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15411: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15412: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15413: $confhash{$provider}{'defaults'}{$inner} = $poss;
15414: }
15415: } else {
15416: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15417: }
15418: }
15419: } else {
15420: if (grep(/^\Q$field\E$/,@checked)) {
15421: push(@{$confhash{$provider}{'defaults'}},$field);
15422: }
15423: }
15424: }
15425: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15426: if (ref($current{'defaults'}) eq 'ARRAY') {
15427: unless ($changes{$provider}) {
15428: my @new = sort(@{$confhash{$provider}{'defaults'}});
15429: my @old = sort(@{$current{'defaults'}});
15430: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15431: if (@diffs) {
15432: $changes{$provider} = 1;
15433: }
15434: }
15435: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15436: if (@{$current{'defaults'}}) {
15437: $changes{$provider} = 1;
15438: }
15439: }
15440: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15441: if (ref($current{'defaults'}) eq 'HASH') {
15442: unless ($changes{$provider}) {
15443: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15444: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15445: $changes{$provider} = 1;
15446: last;
15447: }
15448: }
15449: }
15450: unless ($changes{$provider}) {
15451: foreach my $key (keys(%{$current{'defaults'}})) {
15452: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15453: $changes{$provider} = 1;
15454: last;
15455: }
15456: }
15457: }
15458: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15459: $changes{$provider} = 1;
15460: }
15461: }
15462: }
15463: }
15464: if (ref($crsconf{$provider}) eq 'ARRAY') {
15465: if (@{$crsconf{$provider}} > 0) {
15466: $confhash{$provider}{'crsconf'} = [];
15467: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15468: foreach my $crsfield (@{$crsconf{$provider}}) {
15469: if (grep(/^\Q$crsfield\E$/,@checked)) {
15470: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15471: }
15472: }
15473: if (ref($current{'crsconf'}) eq 'ARRAY') {
15474: unless ($changes{$provider}) {
15475: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15476: my @old = sort(@{$current{'crsconf'}});
15477: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15478: if (@diffs) {
15479: $changes{$provider} = 1;
15480: }
15481: }
15482: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15483: $changes{$provider} = 1;
15484: }
15485: }
15486: }
15487: if ($showroles) {
15488: $confhash{$provider}{'roles'} = {};
15489: foreach my $role (@courseroles) {
15490: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15491: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15492: $confhash{$provider}{'roles'}{$role} = $poss;
15493: }
15494: }
15495: unless ($changes{$provider}) {
15496: if (ref($current{'roles'}) eq 'HASH') {
15497: foreach my $role (keys(%{$current{'roles'}})) {
15498: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15499: $changes{$provider} = 1;
15500: last
15501: }
15502: }
15503: unless ($changes{$provider}) {
15504: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15505: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15506: $changes{$provider} = 1;
15507: last;
15508: }
15509: }
15510: }
15511: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15512: $changes{$provider} = 1;
15513: }
15514: }
15515: }
15516: if (ref($current{'custom'}) eq 'HASH') {
15517: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15518: foreach my $key (keys(%{$current{'custom'}})) {
15519: if (grep(/^\Q$key\E$/,@customdels)) {
15520: $changes{$provider} = 1;
15521: } else {
15522: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15523: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15524: $changes{$provider} = 1;
15525: }
15526: }
15527: }
15528: }
15529: if ($customadds{$provider}) {
15530: my $name = $env{'form.proctoring_custom_name_'.$provider};
15531: $name =~ s/(`)/'/g;
15532: $name =~ s/^\s+//;
15533: $name =~ s/\s+$//;
15534: my $value = $env{'form.proctoring_custom_value_'.$provider};
15535: $value =~ s/(`)/'/g;
15536: $value =~ s/^\s+//;
15537: $value =~ s/\s+$//;
15538: if ($name ne '') {
15539: $confhash{$provider}{'custom'}{$name} = $value;
15540: $changes{$provider} = 1;
15541: }
15542: }
15543: }
15544: }
15545: if (@allpos > 0) {
15546: my $idx = 0;
15547: foreach my $provider (@allpos) {
15548: if ($provider ne '') {
15549: $confhash{$provider}{'order'} = $idx;
15550: unless ($changes{$provider}) {
15551: if (ref($domconfig{$action}) eq 'HASH') {
15552: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15553: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15554: $changes{$provider} = 1;
15555: }
15556: }
15557: }
15558: }
15559: $idx ++;
15560: }
15561: }
15562: }
15563: my %proc_hash = (
15564: $action => { %confhash }
15565: );
15566: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15567: $dom);
15568: if ($putresult eq 'ok') {
15569: my %proc_enchash = (
15570: $action => { %encconfhash }
15571: );
1.384 raeburn 15572: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15573: if (keys(%changes) > 0) {
15574: my $cachetime = 24*60*60;
15575: my %procall = %confhash;
15576: foreach my $provider (keys(%procall)) {
15577: if (ref($encconfhash{$provider}) eq 'HASH') {
15578: foreach my $key ('key','secret') {
15579: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15580: }
15581: }
15582: }
15583: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15584: if (ref($lastactref) eq 'HASH') {
15585: $lastactref->{'proctoring'} = 1;
15586: }
15587: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15588: my %bynum;
15589: foreach my $provider (sort(keys(%changes))) {
15590: my $position = $confhash{$provider}{'order'};
15591: $bynum{$position} = $provider;
15592: }
15593: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15594: my $provider = $bynum{$pos};
15595: my %lt = &proctoring_titles($provider);
15596: my %fieldtitles = &proctoring_fieldtitles($provider);
15597: if (!$confhash{$provider}{'available'}) {
15598: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15599: } else {
15600: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15601: if ($confhash{$provider}{'image'}) {
15602: $resulttext .= ' '.
15603: '<img src="'.$confhash{$provider}{'image'}.'"'.
15604: ' alt="'.&mt('Proctoring icon').'" />';
15605: }
15606: $resulttext .= '<ul>';
15607: my $position = $pos + 1;
15608: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15609: foreach my $key ('version','sigmethod','url','lifetime') {
15610: if ($confhash{$provider}{$key} ne '') {
15611: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15612: }
15613: }
15614: if ($encconfhash{$provider}{'key'} ne '') {
15615: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15616: }
15617: if ($encconfhash{$provider}{'secret'} ne '') {
15618: $resulttext .= '<li>'.$lt{'secret'}.': ';
15619: my $num = length($encconfhash{$provider}{'secret'});
15620: $resulttext .= ('*'x$num).'</li>';
15621: }
15622: my (@fields,$showroles);
15623: if (ref($requserfields{$provider}) eq 'ARRAY') {
15624: push(@fields,@{$requserfields{$provider}});
15625: }
15626: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15627: push(@fields,@{$confhash{$provider}{'fields'}});
15628: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15629: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15630: }
15631: if (@fields) {
15632: if (grep(/^roles$/,@fields)) {
15633: $showroles = 1;
15634: }
15635: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15636: join('", "', map { $lt{$_}; } @fields).'"</li>';
15637: }
15638: if (ref($requserfields{$provider}) eq 'ARRAY') {
15639: if (grep(/^user$/,@{$requserfields{$provider}})) {
15640: if ($confhash{$provider}{'incdom'}) {
15641: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15642: } else {
15643: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15644: }
15645: }
15646: }
15647: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15648: if (@{$confhash{$provider}{'defaults'}} > 0) {
15649: $resulttext .= '<li>'.$lt{'defa'};
15650: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15651: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15652: }
15653: $resulttext =~ s/,$//;
15654: $resulttext .= '</li>';
15655: }
15656: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15657: if (keys(%{$confhash{$provider}{'defaults'}})) {
15658: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15659: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15660: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15661: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15662: }
15663: }
15664: $resulttext .= '</ul></li>';
15665: }
15666: }
15667: if (ref($crsconf{$provider}) eq 'ARRAY') {
15668: if (@{$crsconf{$provider}} > 0) {
15669: $resulttext .= '<li>'.&mt('Configurable in course:');
15670: my $numconfig = 0;
15671: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15672: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15673: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15674: $numconfig ++;
15675: if ($provider eq 'examity') {
15676: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15677: } else {
15678: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15679: }
15680: }
15681: $resulttext =~ s/,$//;
15682: }
15683: }
15684: if (!$numconfig) {
15685: $resulttext .= ' '.&mt('None');
15686: }
15687: $resulttext .= '</li>';
15688: }
15689: }
15690: if ($showroles) {
15691: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15692: my $rolemaps;
15693: foreach my $role (@courseroles) {
15694: if ($confhash{$provider}{'roles'}{$role}) {
15695: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15696: $confhash{$provider}{'roles'}{$role}.',';
15697: }
15698: }
15699: if ($rolemaps) {
15700: $rolemaps =~ s/,$//;
15701: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15702: }
15703: }
15704: }
15705: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15706: my $customlist;
15707: if (keys(%{$confhash{$provider}{'custom'}})) {
15708: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15709: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15710: }
15711: $customlist =~ s/,$//;
15712: }
15713: if ($customlist) {
15714: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15715: }
15716: }
15717: $resulttext .= '</ul></li>';
15718: }
15719: }
15720: $resulttext .= '</ul>';
15721: } else {
15722: $resulttext = &mt('No changes made.');
15723: }
15724: } else {
15725: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15726: }
15727: if ($errors) {
15728: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15729: $errors.'</ul>';
15730: }
15731: return $resulttext;
15732: }
15733:
15734: sub process_proctoring_image {
15735: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15736: my $filename = $env{'form.'.$caller.'.filename'};
15737: my ($error,$url);
15738: my ($width,$height) = (21,21);
15739: if ($configuserok eq 'ok') {
15740: if ($switchserver) {
15741: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15742: $switchserver);
15743: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15744: my $modified = [];
1.372 raeburn 15745: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15746: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15747: "proctoring/$provider/icon",$width,$height,
15748: '',$modified);
1.372 raeburn 15749: if ($result eq 'ok') {
15750: if ($madethumb) {
15751: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15752: my $imagethumb = "$path/tn-".$imagefile;
15753: $url = $imagethumb;
15754: } else {
15755: $url = $imageurl;
15756: }
1.421 raeburn 15757: &update_modify_urls($r,$modified);
1.372 raeburn 15758: } else {
15759: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15760: }
15761: } else {
15762: $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);
15763: }
15764: } else {
15765: $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);
15766: }
15767: return ($url,$error);
15768: }
15769:
1.320 raeburn 15770: sub modify_lti {
15771: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15772: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15773: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15774: my (%posslti,%posslticrs,%posscrstype);
15775: my @courseroles = ('cc','in','ta','ep','st');
15776: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15777: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15778: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15779: my %coursetypetitles = &Apache::lonlocal::texthash (
15780: official => 'Official',
15781: unofficial => 'Unofficial',
15782: community => 'Community',
15783: textbook => 'Textbook',
15784: placement => 'Placement Test',
1.392 raeburn 15785: lti => 'LTI Provider',
1.320 raeburn 15786: );
1.325 raeburn 15787: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15788: my %lt = <i_names();
15789: map { $posslti{$_} = 1; } @ltiroles;
15790: map { $posslticrs{$_} = 1; } @lticourseroles;
15791: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15792:
1.326 raeburn 15793: my %menutitles = <imenu_titles();
1.421 raeburn 15794: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15795:
1.421 raeburn 15796: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15797:
1.406 raeburn 15798: my (%linkprotchg,$linkprotoutput,$is_home);
15799: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15800: \%linkprotchg,'domain');
15801: my $home = &Apache::lonnet::domain($dom,'primary');
15802: unless (($home eq 'no_host') || ($home eq '')) {
15803: my @ids=&Apache::lonnet::current_machine_ids();
15804: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15805: }
15806:
15807: if (keys(%linkprotchg)) {
15808: $secchanges{'linkprot'} = 1;
15809: my %oldlinkprot;
15810: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15811: %oldlinkprot = %{$currltisec{'linkprot'}};
15812: }
15813: foreach my $id (keys(%linkprotchg)) {
15814: if (ref($linkprotchg{$id}) eq 'HASH') {
15815: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15816: if (($inner eq 'secret') || ($inner eq 'key')) {
15817: if ($is_home) {
15818: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15819: }
15820: }
15821: }
15822: } else {
15823: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15824: }
15825: }
15826: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15827: if (keys(%linkprotchg)) {
15828: %{$newltisec{'linkprot'}} = %linkprotchg;
15829: }
15830: }
15831: if (ref($currltisec{'linkprot'}) eq 'HASH') {
1.434 raeburn 15832: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
1.406 raeburn 15833: next if ($id !~ /^\d+$/);
15834: unless (exists($linkprotchg{$id})) {
15835: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15836: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15837: if (($inner eq 'secret') || ($inner eq 'key')) {
15838: if ($is_home) {
15839: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15840: }
15841: } else {
15842: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15843: }
15844: }
15845: } else {
15846: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15847: }
15848: }
15849: }
15850: }
15851: if ($proterror) {
15852: $errors .= '<li>'.$proterror.'</li>';
15853: }
1.434 raeburn 15854:
15855: my (%delsuggested,%suggids,@suggested);;
15856: if (ref($currltisec{'suggested'}) eq 'HASH') {
15857: my $maxnum = $env{'form.linkprot_suggested_maxnum'};
15858: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
15859: for (my $i=0; $i<$maxnum; $i++) {
15860: my $itemid = $env{'form.linkprot_suggested_id_'.$i};
15861: $itemid =~ s/\D+//g;
15862: if ($itemid) {
15863: if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
15864: push(@suggested,$i);
15865: $suggids{$i} = $itemid;
15866: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
15867: if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
15868: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15869: }
15870: } else {
15871: if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
15872: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15873: } else {
15874: $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
15875: $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
15876: $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
15877: $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
15878: if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
15879: ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
15880: $secchanges{'suggested'}{$itemid} = 1;
15881: }
15882: }
15883: }
15884: }
15885: }
15886: }
15887: }
15888: foreach my $key (keys(%delsuggested)) {
15889: $newltisec{'suggested'}{$key} = $delsuggested{$key};
15890: $secchanges{'suggested'}{$key} = 1;
15891: }
15892: if (($env{'form.linkprot_suggested_add'}) &&
15893: ($env{'form.linkprot_suggested_name_add'} ne '')) {
15894: $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
15895: $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
15896: my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
15897: if ($newsuggid) {
15898: $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
15899: $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
15900: $secchanges{'suggested'}{$newsuggid} = 1;
15901: } else {
15902: my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
15903: if ($errormsg) {
15904: $error .= ' ('.$errormsg.')';
15905: }
15906: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15907: }
15908: }
1.320 raeburn 15909: my (@items,%deletions,%itemids);
15910: if ($env{'form.lti_add'}) {
15911: my $consumer = $env{'form.lti_consumer_add'};
15912: $consumer =~ s/(`)/'/g;
1.434 raeburn 15913: ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
1.320 raeburn 15914: if ($newid) {
15915: $itemids{'add'} = $newid;
15916: push(@items,'add');
15917: $changes{$newid} = 1;
15918: } else {
15919: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
1.434 raeburn 15920: if ($errormsg) {
15921: $error .= ' ('.$errormsg.')';
15922: }
1.320 raeburn 15923: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15924: }
15925: }
15926: if (ref($domconfig{$action}) eq 'HASH') {
15927: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15928: if (@todelete) {
15929: map { $deletions{$_} = 1; } @todelete;
15930: }
15931: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15932: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15933: my $itemid = $env{'form.lti_id_'.$i};
15934: $itemid =~ s/\D+//g;
15935: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15936: if ($deletions{$itemid}) {
15937: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15938: } else {
1.390 raeburn 15939: push(@items,$i);
15940: $itemids{$i} = $itemid;
1.320 raeburn 15941: }
15942: }
15943: }
15944: }
1.424 raeburn 15945: my (%keystore,$secstored);
15946: if ($is_home) {
15947: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
15948: }
15949:
15950: my ($cipher,$privnum);
15951: if ((@items > 0) && ($is_home)) {
15952: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
15953: $newltisec{'encrypt'},$keystore{$home});
15954: }
1.320 raeburn 15955: foreach my $idx (@items) {
15956: my $itemid = $itemids{$idx};
15957: next unless ($itemid);
1.424 raeburn 15958: my %currlti;
15959: unless ($idx eq 'add') {
15960: if (ref($domconfig{$action}) eq 'HASH') {
15961: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15962: %currlti = %{$domconfig{$action}{$itemid}};
15963: }
15964: }
15965: }
1.390 raeburn 15966: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 15967: $position =~ s/\D+//g;
15968: if ($position ne '') {
15969: $allpos[$position] = $itemid;
15970: }
1.424 raeburn 15971: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 15972: my $formitem = 'form.lti_'.$item.'_'.$idx;
15973: $env{$formitem} =~ s/(`)/'/g;
15974: if ($item eq 'lifetime') {
15975: $env{$formitem} =~ s/[^\d.]//g;
15976: }
15977: if ($env{$formitem} ne '') {
1.424 raeburn 15978: $confhash{$itemid}{$item} = $env{$formitem};
15979: unless (($idx eq 'add') || ($changes{$itemid})) {
15980: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
15981: $changes{$itemid} = 1;
1.320 raeburn 15982: }
15983: }
15984: }
15985: }
15986: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
15987: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
15988: }
1.345 raeburn 15989: if ($confhash{$itemid}{'requser'}) {
15990: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 15991: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 15992: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
15993: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
15994: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
15995: my $mapuser = $env{'form.lti_customuser_'.$idx};
15996: $mapuser =~ s/(`)/'/g;
1.405 raeburn 15997: $mapuser =~ s/^\s+|\s+$//g;
15998: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 15999: }
16000: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
16001: my @makeuser;
16002: foreach my $ltirole (sort(@possmakeuser)) {
16003: if ($posslti{$ltirole}) {
16004: push(@makeuser,$ltirole);
16005: }
16006: }
16007: $confhash{$itemid}{'makeuser'} = \@makeuser;
16008: if (@makeuser) {
16009: my $lcauth = $env{'form.lti_lcauth_'.$idx};
16010: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
16011: $confhash{$itemid}{'lcauth'} = $lcauth;
16012: if ($lcauth ne 'internal') {
16013: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
16014: $lcauthparm =~ s/^(\s+|\s+)$//g;
16015: $lcauthparm =~ s/`//g;
16016: if ($lcauthparm ne '') {
16017: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
16018: }
16019: }
16020: } else {
16021: $confhash{$itemid}{'lcauth'} = 'lti';
16022: }
1.320 raeburn 16023: }
1.345 raeburn 16024: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
16025: if (@possinstdata) {
1.447.2.2 raeburn 16026: foreach my $field (sort(@possinstdata)) {
1.345 raeburn 16027: if (exists($fieldtitles{$field})) {
1.447.2.2 raeburn 16028: push(@{$confhash{$itemid}{'instdata'}},$field);
1.325 raeburn 16029: }
16030: }
16031: }
1.363 raeburn 16032: if ($env{'form.lti_callback_'.$idx}) {
16033: if ($env{'form.lti_callbackparam_'.$idx}) {
16034: my $callback = $env{'form.lti_callbackparam_'.$idx};
16035: $callback =~ s/^\s+|\s+$//g;
16036: $confhash{$itemid}{'callback'} = $callback;
16037: }
16038: }
1.391 raeburn 16039: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 16040: if ($env{'form.lti_'.$field.'_'.$idx}) {
16041: $confhash{$itemid}{$field} = 1;
16042: }
1.320 raeburn 16043: }
1.345 raeburn 16044: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
16045: $confhash{$itemid}{lcmenu} = [];
16046: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
16047: foreach my $field (@possmenu) {
16048: if (exists($menutitles{$field})) {
16049: if ($field eq 'grades') {
16050: next unless ($env{'form.lti_inlinemenu_'.$idx});
16051: }
16052: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 16053: }
16054: }
16055: }
1.391 raeburn 16056: if ($confhash{$itemid}{'crsinc'}) {
16057: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
16058: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
16059: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
16060: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
16061: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
16062: $mapcrs =~ s/(`)/'/g;
16063: $mapcrs =~ s/^\s+|\s+$//g;
16064: $confhash{$itemid}{'mapcrs'} = $mapcrs;
16065: }
16066: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
16067: my @crstypes;
16068: foreach my $type (sort(@posstypes)) {
16069: if ($posscrstype{$type}) {
16070: push(@crstypes,$type);
16071: }
16072: }
16073: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 16074: if ($env{'form.lti_storecrs_'.$idx}) {
16075: $confhash{$itemid}{'storecrs'} = 1;
16076: }
1.391 raeburn 16077: if ($env{'form.lti_makecrs_'.$idx}) {
16078: $confhash{$itemid}{'makecrs'} = 1;
16079: }
16080: foreach my $ltirole (@lticourseroles) {
16081: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
16082: if (grep(/^\Q$possrole\E$/,@courseroles)) {
16083: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
16084: }
16085: }
16086: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
16087: my @selfenroll;
16088: foreach my $type (sort(@possenroll)) {
16089: if ($posslticrs{$type}) {
16090: push(@selfenroll,$type);
16091: }
16092: }
16093: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
16094: if ($env{'form.lti_crssec_'.$idx}) {
16095: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
16096: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
16097: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
16098: my $section = $env{'form.lti_customsection_'.$idx};
16099: $section =~ s/(`)/'/g;
16100: $section =~ s/^\s+|\s+$//g;
16101: if ($section ne '') {
16102: $confhash{$itemid}{'section'} = $section;
16103: }
16104: }
16105: }
16106: foreach my $field ('passback','roster') {
16107: if ($env{'form.lti_'.$field.'_'.$idx}) {
16108: $confhash{$itemid}{$field} = 1;
16109: }
16110: }
16111: if ($env{'form.lti_passback_'.$idx}) {
16112: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
16113: $confhash{$itemid}{'passbackformat'} = '1.0';
16114: } else {
16115: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 16116: }
16117: }
1.391 raeburn 16118: }
16119: unless (($idx eq 'add') || ($changes{$itemid})) {
16120: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 16121: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 16122: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 16123: $changes{$itemid} = 1;
16124: }
1.345 raeburn 16125: }
16126: unless ($changes{$itemid}) {
1.424 raeburn 16127: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
16128: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 16129: $changes{$itemid} = 1;
16130: }
16131: }
1.345 raeburn 16132: }
1.391 raeburn 16133: foreach my $field ('mapcrstype','selfenroll') {
16134: unless ($changes{$itemid}) {
1.424 raeburn 16135: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16136: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16137: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16138: $confhash{$itemid}{$field});
16139: if (@diffs) {
16140: $changes{$itemid} = 1;
16141: }
1.424 raeburn 16142: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16143: $changes{$itemid} = 1;
16144: }
16145: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16146: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 16147: $changes{$itemid} = 1;
16148: }
16149: }
1.391 raeburn 16150: }
16151: }
16152: unless ($changes{$itemid}) {
1.424 raeburn 16153: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 16154: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 16155: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
16156: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 16157: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 16158: $changes{$itemid} = 1;
16159: last;
16160: }
16161: }
1.391 raeburn 16162: unless ($changes{$itemid}) {
16163: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
16164: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 16165: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 16166: $changes{$itemid} = 1;
16167: last;
16168: }
16169: }
16170: }
1.424 raeburn 16171: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 16172: $changes{$itemid} = 1;
1.345 raeburn 16173: }
1.391 raeburn 16174: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16175: unless ($changes{$itemid}) {
16176: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16177: $changes{$itemid} = 1;
16178: }
16179: }
16180: }
16181: }
16182: }
16183: unless ($changes{$itemid}) {
16184: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 16185: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16186: $changes{$itemid} = 1;
1.320 raeburn 16187: }
1.391 raeburn 16188: }
16189: unless ($changes{$itemid}) {
1.447.2.2 raeburn 16190: foreach my $field ('makeuser','lcmenu','instdata') {
1.424 raeburn 16191: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16192: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16193: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16194: $confhash{$itemid}{$field});
16195: if (@diffs) {
16196: $changes{$itemid} = 1;
16197: }
1.424 raeburn 16198: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16199: $changes{$itemid} = 1;
16200: }
16201: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16202: if (@{$confhash{$itemid}{$field}} > 0) {
16203: $changes{$itemid} = 1;
16204: }
1.345 raeburn 16205: }
1.320 raeburn 16206: }
16207: }
16208: }
16209: }
16210: }
1.424 raeburn 16211: if ($is_home) {
16212: my $keyitem = 'form.lti_key_'.$idx;
16213: $env{$keyitem} =~ s/(`)/'/g;
16214: if ($env{$keyitem} ne '') {
16215: $ltienc{$itemid}{'key'} = $env{$keyitem};
16216: unless ($changes{$itemid}) {
16217: if ($currlti{'key'} ne $env{$keyitem}) {
16218: $changes{$itemid} = 1;
16219: }
16220: }
16221: }
16222: my $secretitem = 'form.lti_secret_'.$idx;
16223: $env{$secretitem} =~ s/(`)/'/g;
16224: if ($currlti{'usable'}) {
16225: if ($env{'form.lti_changesecret_'.$idx}) {
16226: if ($env{$secretitem} ne '') {
16227: if ($privnum && $cipher) {
16228: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16229: $confhash{$itemid}{'cipher'} = $privnum;
16230: } else {
16231: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16232: }
16233: $changes{$itemid} = 1;
16234: }
16235: } else {
16236: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16237: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16238: }
16239: if (ref($ltienc{$itemid}) eq 'HASH') {
16240: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16241: $confhash{$itemid}{'usable'} = 1;
16242: }
16243: }
16244: } elsif ($env{$secretitem} ne '') {
16245: if ($privnum && $cipher) {
16246: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16247: $confhash{$itemid}{'cipher'} = $privnum;
16248: } else {
16249: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16250: }
16251: if (ref($ltienc{$itemid}) eq 'HASH') {
16252: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16253: $confhash{$itemid}{'usable'} = 1;
16254: }
16255: }
16256: $changes{$itemid} = 1;
16257: }
16258: }
16259: unless ($changes{$itemid}) {
16260: foreach my $key (keys(%currlti)) {
16261: if (ref($currlti{$key}) eq 'HASH') {
16262: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16263: foreach my $innerkey (keys(%{$currlti{$key}})) {
16264: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16265: $changes{$itemid} = 1;
16266: last;
16267: }
16268: }
16269: } elsif (keys(%{$currlti{$key}}) > 0) {
16270: $changes{$itemid} = 1;
16271: }
16272: }
16273: last if ($changes{$itemid});
16274: }
16275: }
1.320 raeburn 16276: }
16277: if (@allpos > 0) {
16278: my $idx = 0;
16279: foreach my $itemid (@allpos) {
16280: if ($itemid ne '') {
16281: $confhash{$itemid}{'order'} = $idx;
16282: if (ref($domconfig{$action}) eq 'HASH') {
16283: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16284: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16285: $changes{$itemid} = 1;
16286: }
16287: }
16288: }
16289: $idx ++;
16290: }
16291: }
16292: }
1.424 raeburn 16293:
16294: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16295: return &mt('No changes made.');
16296: }
16297:
1.320 raeburn 16298: my %ltihash = (
1.405 raeburn 16299: $action => { %confhash }
16300: );
1.424 raeburn 16301: my %ltienchash;
16302:
16303: if ($is_home) {
16304: %ltienchash = (
16305: $action => { %ltienc }
16306: );
16307: }
1.405 raeburn 16308: if (keys(%secchanges)) {
16309: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16310: if ($secchanges{'linkprot'}) {
16311: if ($is_home) {
16312: $ltienchash{'linkprot'} = \%newltienc;
16313: }
16314: }
1.405 raeburn 16315: }
16316: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16317: if ($putresult eq 'ok') {
1.424 raeburn 16318: if (keys(%ltienchash)) {
16319: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16320: }
16321: $resulttext = &mt('Changes made:').'<ul>';
16322: if (keys(%secchanges) > 0) {
1.423 raeburn 16323: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16324: if (exists($secchanges{'linkprot'})) {
16325: $resulttext .= $linkprotoutput;
1.405 raeburn 16326: }
16327: }
1.320 raeburn 16328: if (keys(%changes) > 0) {
16329: my $cachetime = 24*60*60;
1.424 raeburn 16330: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16331: if (ref($lastactref) eq 'HASH') {
16332: $lastactref->{'lti'} = 1;
16333: }
16334: my %bynum;
16335: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16336: if (ref($confhash{$itemid}) eq 'HASH') {
16337: my $position = $confhash{$itemid}{'order'};
16338: $bynum{$position} = $itemid;
16339: }
1.320 raeburn 16340: }
16341: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16342: my $itemid = $bynum{$pos};
1.424 raeburn 16343: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16344: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16345: my $position = $pos + 1;
16346: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16347: foreach my $item ('version','lifetime') {
16348: if ($confhash{$itemid}{$item} ne '') {
16349: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16350: }
16351: }
1.424 raeburn 16352: if ($ltienc{$itemid}{'key'} ne '') {
16353: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16354: }
1.424 raeburn 16355: if ($ltienc{$itemid}{'secret'} ne '') {
16356: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16357: }
1.345 raeburn 16358: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16359: if ($confhash{$itemid}{'callback'}) {
16360: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16361: } else {
1.392 raeburn 16362: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16363: }
1.345 raeburn 16364: if ($confhash{$itemid}{'mapuser'}) {
16365: my $shownmapuser;
16366: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16367: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16368: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16369: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16370: } else {
16371: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16372: }
1.345 raeburn 16373: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16374: }
1.345 raeburn 16375: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16376: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16377: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16378: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16379: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16380: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16381: } else {
16382: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16383: $confhash{$itemid}{'lcauth'});
16384: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16385: $resulttext .= '; '.&mt('a randomly generated password will be created');
16386: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16387: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16388: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16389: }
16390: } else {
16391: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16392: }
16393: }
16394: $resulttext .= '</li>';
16395: } else {
16396: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16397: }
1.320 raeburn 16398: }
1.345 raeburn 16399: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16400: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16401: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16402: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16403: } else {
1.447.2.2 raeburn 16404: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user').'</li>';
1.325 raeburn 16405: }
1.447.2.2 raeburn 16406: } else {
16407: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user').'</li>';
1.320 raeburn 16408: }
1.391 raeburn 16409: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16410: $resulttext .= '<li>'.$lt{$item}.': ';
16411: if ($confhash{$itemid}{$item}) {
16412: $resulttext .= &mt('Yes');
16413: } else {
16414: $resulttext .= &mt('No');
1.337 raeburn 16415: }
1.345 raeburn 16416: $resulttext .= '</li>';
1.320 raeburn 16417: }
1.345 raeburn 16418: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16419: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16420: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16421: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16422: } else {
16423: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16424: }
16425: }
16426: if ($confhash{$itemid}{'crsinc'}) {
16427: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16428: my $rolemaps;
16429: foreach my $role (@ltiroles) {
16430: if ($confhash{$itemid}{'maproles'}{$role}) {
16431: $rolemaps .= (' 'x2).$role.'='.
16432: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16433: 'Course').',';
16434: }
16435: }
16436: if ($rolemaps) {
16437: $rolemaps =~ s/,$//;
16438: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16439: }
16440: }
16441: if ($confhash{$itemid}{'mapcrs'}) {
16442: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16443: }
16444: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16445: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16446: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16447: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16448: '</li>';
16449: } else {
16450: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16451: }
16452: }
1.392 raeburn 16453: if ($confhash{$itemid}{'storecrs'}) {
16454: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16455: }
1.391 raeburn 16456: if ($confhash{$itemid}{'makecrs'}) {
16457: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16458: } else {
16459: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16460: }
16461: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16462: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16463: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16464: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16465: '</li>';
16466: } else {
16467: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16468: }
16469: }
16470: if ($confhash{$itemid}{'section'}) {
16471: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16472: $resulttext .= '<li>'.&mt('User section from standard field:').
16473: ' (course_section_sourcedid)'.'</li>';
16474: } else {
16475: $resulttext .= '<li>'.&mt('User section from:').' '.
16476: $confhash{$itemid}{'section'}.'</li>';
16477: }
1.345 raeburn 16478: } else {
1.391 raeburn 16479: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16480: }
16481: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16482: $resulttext .= '<li>'.$lt{$item}.': ';
16483: if ($confhash{$itemid}{$item}) {
16484: $resulttext .= &mt('Yes');
16485: if ($item eq 'passback') {
16486: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16487: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16488: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16489: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16490: }
16491: }
16492: } else {
16493: $resulttext .= &mt('No');
16494: }
16495: $resulttext .= '</li>';
16496: }
16497: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16498: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16499: $resulttext .= '<li>'.&mt('Menu items:').' '.
16500: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16501: } else {
16502: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16503: }
1.345 raeburn 16504: }
1.326 raeburn 16505: }
16506: }
1.320 raeburn 16507: $resulttext .= '</ul></li>';
16508: }
16509: }
1.424 raeburn 16510: if (keys(%deletions)) {
16511: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16512: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16513: }
16514: }
1.320 raeburn 16515: }
1.405 raeburn 16516: $resulttext .= '</ul>';
1.424 raeburn 16517: if (ref($lastactref) eq 'HASH') {
1.434 raeburn 16518: if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
16519: &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 16520: $lastactref->{'domdefaults'} = 1;
16521: }
16522: }
1.320 raeburn 16523: } else {
16524: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16525: }
16526: if ($errors) {
16527: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16528: $errors.'</ul>';
16529: }
16530: return $resulttext;
16531: }
16532:
1.424 raeburn 16533: sub get_priv_creds {
16534: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16535: my ($needenc,$cipher,$privnum);
16536: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16537: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16538: $needenc = $encrypt->{'consumers'}
16539: } else {
16540: $needenc = $domdefs{'ltienc_consumers'};
16541: }
16542: if ($needenc) {
16543: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16544: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16545: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16546: my $privkey = $privhash{'key'};
16547: $privnum = $privhash{'version'};
16548: if (($privnum) && ($privkey ne '')) {
16549: $cipher = Crypt::CBC->new({'key' => $privkey,
16550: 'cipher' => 'DES'});
16551: }
16552: }
16553: }
16554: return ($cipher,$privnum);
16555: }
16556:
1.320 raeburn 16557: sub get_lti_id {
1.434 raeburn 16558: my ($domain,$consumer,$dbname) = @_;
16559: unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
16560: return ('','invalid db');
16561: }
16562: # get lock on db
1.320 raeburn 16563: my $lockhash = {
16564: lock => $env{'user.name'}.
16565: ':'.$env{'user.domain'},
16566: };
16567: my $tries = 0;
1.434 raeburn 16568: my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16569: my ($id,$error);
16570:
16571: while (($gotlock ne 'ok') && ($tries<10)) {
16572: $tries ++;
16573: sleep (0.1);
1.434 raeburn 16574: $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16575: }
16576: if ($gotlock eq 'ok') {
1.434 raeburn 16577: my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1.320 raeburn 16578: if ($currids{'lock'}) {
16579: delete($currids{'lock'});
16580: if (keys(%currids)) {
16581: my @curr = sort { $a <=> $b } keys(%currids);
16582: if ($curr[-1] =~ /^\d+$/) {
16583: $id = 1 + $curr[-1];
16584: }
16585: } else {
16586: $id = 1;
16587: }
16588: if ($id) {
1.434 raeburn 16589: unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1.320 raeburn 16590: $error = 'nostore';
16591: }
16592: } else {
16593: $error = 'nonumber';
16594: }
16595: }
1.434 raeburn 16596: my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1.320 raeburn 16597: } else {
16598: $error = 'nolock';
16599: }
16600: return ($id,$error);
16601: }
16602:
1.3 raeburn 16603: sub modify_autoenroll {
1.205 raeburn 16604: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16605: my ($resulttext,%changes);
16606: my %currautoenroll;
16607: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16608: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16609: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16610: }
16611: }
16612: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16613: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16614: sender => 'Sender for notification messages',
1.274 raeburn 16615: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16616: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16617: my @offon = ('off','on');
1.17 raeburn 16618: my $sender_uname = $env{'form.sender_uname'};
16619: my $sender_domain = $env{'form.sender_domain'};
16620: if ($sender_domain eq '') {
16621: $sender_uname = '';
16622: } elsif ($sender_uname eq '') {
16623: $sender_domain = '';
16624: }
1.129 raeburn 16625: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16626: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16627: $autofailsafe =~ s{^\s+|\s+$}{}g;
16628: if ($autofailsafe =~ /\D/) {
16629: undef($autofailsafe);
16630: }
1.274 raeburn 16631: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16632: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16633: $failsafe = 'off';
1.400 raeburn 16634: undef($autofailsafe);
1.274 raeburn 16635: }
1.1 raeburn 16636: my %autoenrollhash = (
1.129 raeburn 16637: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16638: 'sender_uname' => $sender_uname,
16639: 'sender_domain' => $sender_domain,
16640: 'co-owners' => $coowners,
1.399 raeburn 16641: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16642: 'failsafe' => $failsafe,
1.1 raeburn 16643: }
16644: );
1.4 raeburn 16645: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16646: $dom);
1.1 raeburn 16647: if ($putresult eq 'ok') {
16648: if (exists($currautoenroll{'run'})) {
16649: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16650: $changes{'run'} = 1;
16651: }
16652: } elsif ($autorun) {
16653: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16654: $changes{'run'} = 1;
1.1 raeburn 16655: }
16656: }
1.17 raeburn 16657: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16658: $changes{'sender'} = 1;
16659: }
1.17 raeburn 16660: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16661: $changes{'sender'} = 1;
16662: }
1.129 raeburn 16663: if ($currautoenroll{'co-owners'} ne '') {
16664: if ($currautoenroll{'co-owners'} ne $coowners) {
16665: $changes{'coowners'} = 1;
16666: }
16667: } elsif ($coowners) {
16668: $changes{'coowners'} = 1;
1.274 raeburn 16669: }
1.399 raeburn 16670: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16671: $changes{'autofailsafe'} = 1;
16672: }
1.399 raeburn 16673: if ($currautoenroll{'failsafe'} ne $failsafe) {
16674: $changes{'failsafe'} = 1;
16675: }
1.1 raeburn 16676: if (keys(%changes) > 0) {
16677: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16678: if ($changes{'run'}) {
1.1 raeburn 16679: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16680: }
16681: if ($changes{'sender'}) {
1.17 raeburn 16682: if ($sender_uname eq '' || $sender_domain eq '') {
16683: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16684: } else {
16685: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16686: }
1.1 raeburn 16687: }
1.129 raeburn 16688: if ($changes{'coowners'}) {
16689: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16690: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16691: if (ref($lastactref) eq 'HASH') {
16692: $lastactref->{'domainconfig'} = 1;
16693: }
1.129 raeburn 16694: }
1.274 raeburn 16695: if ($changes{'autofailsafe'}) {
1.399 raeburn 16696: if ($autofailsafe ne '') {
16697: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16698: } else {
1.399 raeburn 16699: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16700: }
1.399 raeburn 16701: }
16702: if ($changes{'failsafe'}) {
16703: if ($failsafe eq 'off') {
16704: unless ($changes{'autofailsafe'}) {
16705: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16706: }
16707: } elsif ($failsafe eq 'zero') {
16708: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16709: } else {
16710: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16711: }
16712: }
16713: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16714: &Apache::lonnet::get_domain_defaults($dom,1);
16715: if (ref($lastactref) eq 'HASH') {
16716: $lastactref->{'domdefaults'} = 1;
16717: }
16718: }
1.1 raeburn 16719: $resulttext .= '</ul>';
16720: } else {
16721: $resulttext = &mt('No changes made to auto-enrollment settings');
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:
16730: sub modify_autoupdate {
1.3 raeburn 16731: my ($dom,%domconfig) = @_;
1.1 raeburn 16732: my ($resulttext,%currautoupdate,%fields,%changes);
16733: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16734: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16735: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16736: }
16737: }
16738: my @offon = ('off','on');
16739: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16740: run => 'Auto-update:',
16741: classlists => 'Updates to user information in classlists?',
16742: unexpired => 'Skip updates for users without active or future roles?',
16743: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16744: );
1.44 raeburn 16745: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16746: my %fieldtitles = &Apache::lonlocal::texthash (
16747: id => 'Student/Employee ID',
1.20 raeburn 16748: permanentemail => 'E-mail address',
1.1 raeburn 16749: lastname => 'Last Name',
16750: firstname => 'First Name',
16751: middlename => 'Middle Name',
1.132 raeburn 16752: generation => 'Generation',
1.1 raeburn 16753: );
1.142 raeburn 16754: $othertitle = &mt('All users');
1.1 raeburn 16755: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16756: $othertitle = &mt('Other users');
1.1 raeburn 16757: }
16758: foreach my $key (keys(%env)) {
16759: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16760: my ($usertype,$item) = ($1,$2);
16761: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16762: if ($usertype eq 'default') {
16763: push(@{$fields{$1}},$2);
16764: } elsif (ref($types) eq 'ARRAY') {
16765: if (grep(/^\Q$usertype\E$/,@{$types})) {
16766: push(@{$fields{$1}},$2);
16767: }
16768: }
16769: }
1.1 raeburn 16770: }
16771: }
1.131 raeburn 16772: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16773: @lockablenames = sort(@lockablenames);
16774: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16775: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16776: if (@changed) {
16777: $changes{'lockablenames'} = 1;
16778: }
16779: } else {
16780: if (@lockablenames) {
16781: $changes{'lockablenames'} = 1;
16782: }
16783: }
1.1 raeburn 16784: my %updatehash = (
16785: autoupdate => { run => $env{'form.autoupdate_run'},
16786: classlists => $env{'form.classlists'},
1.385 raeburn 16787: unexpired => $env{'form.unexpired'},
1.1 raeburn 16788: fields => {%fields},
1.131 raeburn 16789: lockablenames => \@lockablenames,
1.1 raeburn 16790: }
16791: );
1.385 raeburn 16792: my $lastactivedays;
16793: if ($env{'form.lastactive'}) {
16794: $lastactivedays = $env{'form.lastactivedays'};
16795: $lastactivedays =~ s/^\s+|\s+$//g;
16796: unless ($lastactivedays =~ /^\d+$/) {
16797: undef($lastactivedays);
16798: $env{'form.lastactive'} = 0;
16799: }
16800: }
16801: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16802: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16803: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16804: if (exists($updatehash{autoupdate}{$key})) {
16805: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16806: $changes{$key} = 1;
16807: }
16808: }
16809: } elsif ($key eq 'fields') {
16810: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16811: foreach my $item (@{$types},'default') {
1.1 raeburn 16812: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16813: my $change = 0;
16814: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16815: if (!exists($fields{$item})) {
16816: $change = 1;
1.132 raeburn 16817: last;
1.1 raeburn 16818: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16819: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16820: $change = 1;
1.132 raeburn 16821: last;
1.1 raeburn 16822: }
16823: }
16824: }
16825: if ($change) {
16826: push(@{$changes{$key}},$item);
16827: }
1.26 raeburn 16828: }
1.1 raeburn 16829: }
16830: }
1.131 raeburn 16831: } elsif ($key eq 'lockablenames') {
16832: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16833: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16834: if (@changed) {
16835: $changes{'lockablenames'} = 1;
16836: }
16837: } else {
16838: if (@lockablenames) {
16839: $changes{'lockablenames'} = 1;
16840: }
16841: }
16842: }
16843: }
16844: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16845: if (@lockablenames) {
16846: $changes{'lockablenames'} = 1;
1.1 raeburn 16847: }
16848: }
1.385 raeburn 16849: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16850: if ($updatehash{'autoupdate'}{'unexpired'}) {
16851: $changes{'unexpired'} = 1;
16852: }
16853: }
16854: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16855: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16856: $changes{'lastactive'} = 1;
16857: }
16858: }
1.26 raeburn 16859: foreach my $item (@{$types},'default') {
16860: if (defined($fields{$item})) {
16861: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16862: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16863: my $change = 0;
16864: if (ref($fields{$item}) eq 'ARRAY') {
16865: foreach my $type (@{$fields{$item}}) {
16866: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16867: $change = 1;
16868: last;
16869: }
16870: }
16871: }
16872: if ($change) {
16873: push(@{$changes{'fields'}},$item);
16874: }
16875: } else {
1.26 raeburn 16876: push(@{$changes{'fields'}},$item);
16877: }
16878: } else {
16879: push(@{$changes{'fields'}},$item);
1.1 raeburn 16880: }
16881: }
16882: }
16883: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16884: $dom);
16885: if ($putresult eq 'ok') {
16886: if (keys(%changes) > 0) {
16887: $resulttext = &mt('Changes made:').'<ul>';
16888: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16889: if ($key eq 'lockablenames') {
16890: $resulttext .= '<li>';
16891: if (@lockablenames) {
16892: $usertypes->{'default'} = $othertitle;
16893: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16894: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16895: } else {
16896: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16897: }
16898: $resulttext .= '</li>';
16899: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16900: foreach my $item (@{$changes{$key}}) {
16901: my @newvalues;
16902: foreach my $type (@{$fields{$item}}) {
16903: push(@newvalues,$fieldtitles{$type});
16904: }
1.3 raeburn 16905: my $newvaluestr;
16906: if (@newvalues > 0) {
16907: $newvaluestr = join(', ',@newvalues);
16908: } else {
16909: $newvaluestr = &mt('none');
1.6 raeburn 16910: }
1.1 raeburn 16911: if ($item eq 'default') {
1.26 raeburn 16912: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16913: } else {
1.26 raeburn 16914: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16915: }
16916: }
16917: } else {
16918: my $newvalue;
16919: if ($key eq 'run') {
16920: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16921: } elsif ($key eq 'lastactive') {
16922: $newvalue = $offon[$env{'form.lastactive'}];
16923: unless ($lastactivedays eq '') {
16924: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16925: }
1.1 raeburn 16926: } else {
16927: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16928: }
1.1 raeburn 16929: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16930: }
16931: }
16932: $resulttext .= '</ul>';
16933: } else {
1.3 raeburn 16934: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16935: }
16936: } else {
1.11 albertel 16937: $resulttext = '<span class="LC_error">'.
16938: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16939: }
1.3 raeburn 16940: return $resulttext;
1.1 raeburn 16941: }
16942:
1.125 raeburn 16943: sub modify_autocreate {
16944: my ($dom,%domconfig) = @_;
16945: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
16946: if (ref($domconfig{'autocreate'}) eq 'HASH') {
16947: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
16948: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
16949: }
16950: }
16951: my %title= ( xml => 'Auto-creation of courses in XML course description files',
16952: req => 'Auto-creation of validated requests for official courses',
16953: xmldc => 'Identity of course creator of courses from XML files',
16954: );
16955: my @types = ('xml','req');
16956: foreach my $item (@types) {
16957: $newvals{$item} = $env{'form.autocreate_'.$item};
16958: $newvals{$item} =~ s/\D//g;
16959: $newvals{$item} = 0 if ($newvals{$item} eq '');
16960: }
16961: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 16962: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 16963: unless (exists($domcoords{$newvals{'xmldc'}})) {
16964: $newvals{'xmldc'} = '';
16965: }
16966: %autocreatehash = (
16967: autocreate => { xml => $newvals{'xml'},
16968: req => $newvals{'req'},
16969: }
16970: );
16971: if ($newvals{'xmldc'} ne '') {
16972: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
16973: }
16974: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
16975: $dom);
16976: if ($putresult eq 'ok') {
16977: my @items = @types;
16978: if ($newvals{'xml'}) {
16979: push(@items,'xmldc');
16980: }
16981: foreach my $item (@items) {
16982: if (exists($currautocreate{$item})) {
16983: if ($currautocreate{$item} ne $newvals{$item}) {
16984: $changes{$item} = 1;
16985: }
16986: } elsif ($newvals{$item}) {
16987: $changes{$item} = 1;
16988: }
16989: }
16990: if (keys(%changes) > 0) {
16991: my @offon = ('off','on');
16992: $resulttext = &mt('Changes made:').'<ul>';
16993: foreach my $item (@types) {
16994: if ($changes{$item}) {
16995: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 16996: $resulttext .= '<li>'.
16997: &mt("$title{$item} set to [_1]$newtxt [_2]",
16998: '<b>','</b>').
16999: '</li>';
1.125 raeburn 17000: }
17001: }
17002: if ($changes{'xmldc'}) {
17003: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
17004: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 17005: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 17006: }
17007: $resulttext .= '</ul>';
17008: } else {
17009: $resulttext = &mt('No changes made to auto-creation settings');
17010: }
17011: } else {
17012: $resulttext = '<span class="LC_error">'.
17013: &mt('An error occurred: [_1]',$putresult).'</span>';
17014: }
17015: return $resulttext;
17016: }
17017:
1.23 raeburn 17018: sub modify_directorysrch {
1.295 raeburn 17019: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 17020: my ($resulttext,%changes);
17021: my %currdirsrch;
17022: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
17023: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
17024: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
17025: }
17026: }
1.277 raeburn 17027: my %title = ( available => 'Institutional directory search available',
17028: localonly => 'Other domains can search institution',
17029: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 17030: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 17031: searchby => 'Search types',
17032: searchtypes => 'Search latitude');
17033: my @offon = ('off','on');
1.24 raeburn 17034: my @otherdoms = ('Yes','No');
1.23 raeburn 17035:
1.25 raeburn 17036: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 17037: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
17038: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
17039:
1.44 raeburn 17040: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 17041: if (keys(%{$usertypes}) == 0) {
17042: @cansearch = ('default');
17043: } else {
17044: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
17045: foreach my $type (@{$currdirsrch{'cansearch'}}) {
17046: if (!grep(/^\Q$type\E$/,@cansearch)) {
17047: push(@{$changes{'cansearch'}},$type);
17048: }
1.23 raeburn 17049: }
1.26 raeburn 17050: foreach my $type (@cansearch) {
17051: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
17052: push(@{$changes{'cansearch'}},$type);
17053: }
1.23 raeburn 17054: }
1.26 raeburn 17055: } else {
17056: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 17057: }
17058: }
17059:
17060: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
17061: foreach my $by (@{$currdirsrch{'searchby'}}) {
17062: if (!grep(/^\Q$by\E$/,@searchby)) {
17063: push(@{$changes{'searchby'}},$by);
17064: }
17065: }
17066: foreach my $by (@searchby) {
17067: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
17068: push(@{$changes{'searchby'}},$by);
17069: }
17070: }
17071: } else {
17072: push(@{$changes{'searchby'}},@searchby);
17073: }
1.25 raeburn 17074:
17075: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
17076: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
17077: if (!grep(/^\Q$type\E$/,@searchtypes)) {
17078: push(@{$changes{'searchtypes'}},$type);
17079: }
17080: }
17081: foreach my $type (@searchtypes) {
17082: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
17083: push(@{$changes{'searchtypes'}},$type);
17084: }
17085: }
17086: } else {
17087: if (exists($currdirsrch{'searchtypes'})) {
17088: foreach my $type (@searchtypes) {
17089: if ($type ne $currdirsrch{'searchtypes'}) {
17090: push(@{$changes{'searchtypes'}},$type);
17091: }
17092: }
17093: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
17094: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
17095: }
17096: } else {
17097: push(@{$changes{'searchtypes'}},@searchtypes);
17098: }
17099: }
17100:
1.23 raeburn 17101: my %dirsrch_hash = (
17102: directorysrch => { available => $env{'form.dirsrch_available'},
17103: cansearch => \@cansearch,
1.277 raeburn 17104: localonly => $env{'form.dirsrch_instlocalonly'},
17105: lclocalonly => $env{'form.dirsrch_domlocalonly'},
17106: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 17107: searchby => \@searchby,
1.25 raeburn 17108: searchtypes => \@searchtypes,
1.23 raeburn 17109: }
17110: );
17111: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
17112: $dom);
17113: if ($putresult eq 'ok') {
17114: if (exists($currdirsrch{'available'})) {
17115: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
17116: $changes{'available'} = 1;
17117: }
17118: } else {
17119: if ($env{'form.dirsrch_available'} eq '1') {
17120: $changes{'available'} = 1;
17121: }
17122: }
1.277 raeburn 17123: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 17124: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
17125: $changes{'lcavailable'} = 1;
17126: }
1.277 raeburn 17127: } else {
17128: if ($env{'form.dirsrch_lcavailable'} eq '1') {
17129: $changes{'lcavailable'} = 1;
17130: }
17131: }
1.24 raeburn 17132: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 17133: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
17134: $changes{'localonly'} = 1;
17135: }
1.24 raeburn 17136: } else {
1.277 raeburn 17137: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 17138: $changes{'localonly'} = 1;
17139: }
17140: }
1.277 raeburn 17141: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 17142: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
17143: $changes{'lclocalonly'} = 1;
17144: }
1.277 raeburn 17145: } else {
17146: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
17147: $changes{'lclocalonly'} = 1;
17148: }
17149: }
1.23 raeburn 17150: if (keys(%changes) > 0) {
17151: $resulttext = &mt('Changes made:').'<ul>';
17152: if ($changes{'available'}) {
17153: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
17154: }
1.277 raeburn 17155: if ($changes{'lcavailable'}) {
17156: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
17157: }
1.24 raeburn 17158: if ($changes{'localonly'}) {
1.277 raeburn 17159: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 17160: }
1.277 raeburn 17161: if ($changes{'lclocalonly'}) {
17162: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 17163: }
1.23 raeburn 17164: if (ref($changes{'cansearch'}) eq 'ARRAY') {
17165: my $chgtext;
1.26 raeburn 17166: if (ref($usertypes) eq 'HASH') {
17167: if (keys(%{$usertypes}) > 0) {
17168: foreach my $type (@{$types}) {
17169: if (grep(/^\Q$type\E$/,@cansearch)) {
17170: $chgtext .= $usertypes->{$type}.'; ';
17171: }
17172: }
17173: if (grep(/^default$/,@cansearch)) {
17174: $chgtext .= $othertitle;
17175: } else {
17176: $chgtext =~ s/\; $//;
17177: }
1.210 raeburn 17178: $resulttext .=
1.178 raeburn 17179: '<li>'.
17180: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17181: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17182: '</li>';
1.23 raeburn 17183: }
17184: }
17185: }
17186: if (ref($changes{'searchby'}) eq 'ARRAY') {
17187: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17188: my $chgtext;
17189: foreach my $type (@{$titleorder}) {
17190: if (grep(/^\Q$type\E$/,@searchby)) {
17191: if (defined($searchtitles->{$type})) {
17192: $chgtext .= $searchtitles->{$type}.'; ';
17193: }
17194: }
17195: }
17196: $chgtext =~ s/\; $//;
17197: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17198: }
1.25 raeburn 17199: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17200: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17201: my $chgtext;
17202: foreach my $type (@{$srchtypeorder}) {
17203: if (grep(/^\Q$type\E$/,@searchtypes)) {
17204: if (defined($srchtypes_desc->{$type})) {
17205: $chgtext .= $srchtypes_desc->{$type}.'; ';
17206: }
17207: }
17208: }
17209: $chgtext =~ s/\; $//;
1.178 raeburn 17210: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17211: }
17212: $resulttext .= '</ul>';
1.295 raeburn 17213: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17214: if (ref($lastactref) eq 'HASH') {
17215: $lastactref->{'directorysrch'} = 1;
17216: }
1.23 raeburn 17217: } else {
1.277 raeburn 17218: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17219: }
17220: } else {
17221: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17222: &mt('An error occurred: [_1]',$putresult).'</span>';
17223: }
17224: return $resulttext;
17225: }
17226:
1.28 raeburn 17227: sub modify_contacts {
1.205 raeburn 17228: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17229: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17230: if (ref($domconfig{'contacts'}) eq 'HASH') {
17231: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17232: $currsetting{$key} = $domconfig{'contacts'}{$key};
17233: }
17234: }
1.286 raeburn 17235: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17236: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17237: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17238: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17239: my @toggles = ('reporterrors','reportupdates','reportstatus');
17240: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17241: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17242: foreach my $type (@mailings) {
17243: @{$newsetting{$type}} =
17244: &Apache::loncommon::get_env_multiple('form.'.$type);
17245: foreach my $item (@contacts) {
17246: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17247: $contacts_hash{contacts}{$type}{$item} = 1;
17248: } else {
17249: $contacts_hash{contacts}{$type}{$item} = 0;
17250: }
1.289 raeburn 17251: }
1.28 raeburn 17252: $others{$type} = $env{'form.'.$type.'_others'};
17253: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17254: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17255: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17256: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17257: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17258: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17259: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17260: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17261: }
1.134 raeburn 17262: }
1.28 raeburn 17263: }
17264: foreach my $item (@contacts) {
17265: $to{$item} = $env{'form.'.$item};
17266: $contacts_hash{'contacts'}{$item} = $to{$item};
17267: }
1.203 raeburn 17268: foreach my $item (@toggles) {
17269: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17270: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17271: }
17272: }
1.340 raeburn 17273: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17274: foreach my $item (@lonstatus) {
17275: if ($item eq 'excluded') {
17276: my (%serverhomes,@excluded);
17277: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17278: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17279: if (@possexcluded) {
17280: foreach my $id (sort(@possexcluded)) {
17281: if ($serverhomes{$id}) {
17282: push(@excluded,$id);
17283: }
17284: }
17285: }
17286: if (@excluded) {
17287: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17288: }
17289: } elsif ($item eq 'weights') {
1.377 raeburn 17290: foreach my $type ('E','W','N','U') {
1.340 raeburn 17291: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17292: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17293: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17294: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17295: $env{'form.error'.$item.'_'.$type};
17296: }
17297: }
17298: }
17299: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17300: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17301: if ($env{'form.error'.$item} =~ /^\d+$/) {
17302: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17303: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17304: }
17305: }
17306: }
17307: }
1.286 raeburn 17308: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17309: foreach my $field (@{$fields}) {
17310: if (ref($possoptions->{$field}) eq 'ARRAY') {
17311: my $value = $env{'form.helpform_'.$field};
17312: $value =~ s/^\s+|\s+$//g;
17313: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17314: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17315: if ($field eq 'screenshot') {
17316: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17317: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17318: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17319: }
17320: }
17321: }
17322: }
17323: }
17324: }
1.315 raeburn 17325: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17326: my (@statuses,%usertypeshash,@overrides);
17327: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17328: @statuses = @{$types};
17329: if (ref($usertypes) eq 'HASH') {
17330: %usertypeshash = %{$usertypes};
17331: }
17332: }
17333: if (@statuses) {
17334: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17335: foreach my $type (@possoverrides) {
17336: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17337: push(@overrides,$type);
17338: }
17339: }
17340: if (@overrides) {
17341: foreach my $type (@overrides) {
17342: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17343: foreach my $item (@contacts) {
17344: if (grep(/^\Q$item\E$/,@standard)) {
17345: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17346: $newsetting{'override_'.$type}{$item} = 1;
17347: } else {
17348: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17349: $newsetting{'override_'.$type}{$item} = 0;
17350: }
17351: }
17352: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17353: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17354: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17355: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17356: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17357: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17358: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17359: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17360: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17361: }
1.425 raeburn 17362: }
1.315 raeburn 17363: }
17364: }
1.28 raeburn 17365: if (keys(%currsetting) > 0) {
17366: foreach my $item (@contacts) {
17367: if ($to{$item} ne $currsetting{$item}) {
17368: $changes{$item} = 1;
17369: }
17370: }
17371: foreach my $type (@mailings) {
17372: foreach my $item (@contacts) {
17373: if (ref($currsetting{$type}) eq 'HASH') {
17374: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17375: push(@{$changes{$type}},$item);
17376: }
17377: } else {
17378: push(@{$changes{$type}},@{$newsetting{$type}});
17379: }
17380: }
17381: if ($others{$type} ne $currsetting{$type}{'others'}) {
17382: push(@{$changes{$type}},'others');
17383: }
1.289 raeburn 17384: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17385: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17386: push(@{$changes{$type}},'bcc');
17387: }
1.286 raeburn 17388: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17389: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17390: push(@{$changes{$type}},'include');
17391: }
17392: }
17393: }
17394: if (ref($fields) eq 'ARRAY') {
17395: if (ref($currsetting{'helpform'}) eq 'HASH') {
17396: foreach my $field (@{$fields}) {
17397: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17398: push(@{$changes{'helpform'}},$field);
17399: }
17400: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17401: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17402: push(@{$changes{'helpform'}},'maxsize');
17403: }
17404: }
17405: }
17406: } else {
17407: foreach my $field (@{$fields}) {
17408: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17409: push(@{$changes{'helpform'}},$field);
17410: }
17411: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17412: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17413: push(@{$changes{'helpform'}},'maxsize');
17414: }
17415: }
17416: }
1.134 raeburn 17417: }
1.28 raeburn 17418: }
1.315 raeburn 17419: if (@statuses) {
1.425 raeburn 17420: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17421: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17422: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17423: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17424: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17425: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17426: push(@{$changes{'overrides'}},$key);
17427: last;
17428: }
17429: }
17430: } else {
17431: push(@{$changes{'overrides'}},$key);
17432: }
17433: }
17434: }
17435: foreach my $key (@overrides) {
17436: unless (exists($currsetting{'overrides'}{$key})) {
17437: push(@{$changes{'overrides'}},$key);
17438: }
17439: }
17440: } else {
17441: foreach my $key (@overrides) {
1.425 raeburn 17442: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17443: }
17444: }
17445: }
1.340 raeburn 17446: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17447: foreach my $key ('excluded','weights','threshold','sysmail') {
17448: if ($key eq 'excluded') {
17449: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17450: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17451: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17452: (@{$currsetting{'lonstatus'}{$key}})) {
17453: my @diffs =
17454: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17455: $currsetting{'lonstatus'}{$key});
17456: if (@diffs) {
17457: push(@{$changes{'lonstatus'}},$key);
17458: }
17459: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17460: push(@{$changes{'lonstatus'}},$key);
17461: }
17462: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17463: (@{$currsetting{'lonstatus'}{$key}})) {
17464: push(@{$changes{'lonstatus'}},$key);
17465: }
17466: } elsif ($key eq 'weights') {
17467: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17468: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17469: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17470: foreach my $type ('E','W','N','U') {
1.340 raeburn 17471: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17472: $currsetting{'lonstatus'}{$key}{$type}) {
17473: push(@{$changes{'lonstatus'}},$key);
17474: last;
17475: }
17476: }
17477: } else {
1.341 raeburn 17478: foreach my $type ('E','W','N','U') {
1.340 raeburn 17479: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17480: push(@{$changes{'lonstatus'}},$key);
17481: last;
17482: }
17483: }
17484: }
17485: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17486: foreach my $type ('E','W','N','U') {
1.340 raeburn 17487: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17488: push(@{$changes{'lonstatus'}},$key);
17489: last;
17490: }
17491: }
17492: }
17493: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17494: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17495: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17496: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17497: push(@{$changes{'lonstatus'}},$key);
17498: }
17499: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17500: push(@{$changes{'lonstatus'}},$key);
17501: }
17502: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17503: push(@{$changes{'lonstatus'}},$key);
17504: }
17505: }
17506: }
17507: } else {
17508: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17509: foreach my $key ('excluded','weights','threshold','sysmail') {
17510: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17511: push(@{$changes{'lonstatus'}},$key);
17512: }
17513: }
17514: }
17515: }
1.28 raeburn 17516: } else {
17517: my %default;
17518: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17519: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17520: $default{'errormail'} = 'adminemail';
17521: $default{'packagesmail'} = 'adminemail';
17522: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17523: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17524: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17525: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17526: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17527: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17528: foreach my $item (@contacts) {
17529: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17530: $changes{$item} = 1;
1.203 raeburn 17531: }
1.28 raeburn 17532: }
17533: foreach my $type (@mailings) {
17534: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17535: push(@{$changes{$type}},@{$newsetting{$type}});
17536: }
17537: if ($others{$type} ne '') {
17538: push(@{$changes{$type}},'others');
1.134 raeburn 17539: }
1.286 raeburn 17540: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17541: if ($bcc{$type} ne '') {
17542: push(@{$changes{$type}},'bcc');
17543: }
1.286 raeburn 17544: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17545: push(@{$changes{$type}},'include');
17546: }
1.134 raeburn 17547: }
1.28 raeburn 17548: }
1.286 raeburn 17549: if (ref($fields) eq 'ARRAY') {
17550: foreach my $field (@{$fields}) {
17551: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17552: push(@{$changes{'helpform'}},$field);
17553: }
17554: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17555: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17556: push(@{$changes{'helpform'}},'maxsize');
17557: }
17558: }
17559: }
1.289 raeburn 17560: }
1.340 raeburn 17561: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17562: foreach my $key ('excluded','weights','threshold','sysmail') {
17563: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17564: push(@{$changes{'lonstatus'}},$key);
17565: }
17566: }
17567: }
1.28 raeburn 17568: }
1.203 raeburn 17569: foreach my $item (@toggles) {
17570: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17571: $changes{$item} = 1;
17572: } elsif ((!$env{'form.'.$item}) &&
17573: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17574: $changes{$item} = 1;
17575: }
17576: }
1.28 raeburn 17577: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17578: $dom);
17579: if ($putresult eq 'ok') {
17580: if (keys(%changes) > 0) {
1.205 raeburn 17581: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17582: if (ref($lastactref) eq 'HASH') {
17583: $lastactref->{'domainconfig'} = 1;
17584: }
1.28 raeburn 17585: my ($titles,$short_titles) = &contact_titles();
17586: $resulttext = &mt('Changes made:').'<ul>';
17587: foreach my $item (@contacts) {
17588: if ($changes{$item}) {
17589: $resulttext .= '<li>'.$titles->{$item}.
17590: &mt(' set to: ').
17591: '<span class="LC_cusr_emph">'.
17592: $to{$item}.'</span></li>';
17593: }
17594: }
17595: foreach my $type (@mailings) {
17596: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17597: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17598: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17599: } else {
17600: $resulttext .= '<li>'.$titles->{$type}.': ';
17601: }
1.28 raeburn 17602: my @text;
17603: foreach my $item (@{$newsetting{$type}}) {
17604: push(@text,$short_titles->{$item});
17605: }
17606: if ($others{$type} ne '') {
17607: push(@text,$others{$type});
17608: }
1.286 raeburn 17609: if (@text) {
17610: $resulttext .= '<span class="LC_cusr_emph">'.
17611: join(', ',@text).'</span>';
17612: }
17613: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17614: if ($bcc{$type} ne '') {
1.286 raeburn 17615: my $bcctext;
17616: if (@text) {
1.289 raeburn 17617: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17618: } else {
17619: $bcctext = '(Bcc)';
17620: }
17621: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17622: } elsif (!@text) {
17623: $resulttext .= &mt('No one');
1.425 raeburn 17624: }
1.289 raeburn 17625: if ($includestr{$type} ne '') {
1.286 raeburn 17626: if ($includeloc{$type} eq 'b') {
17627: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17628: } elsif ($includeloc{$type} eq 's') {
17629: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17630: }
1.134 raeburn 17631: }
1.286 raeburn 17632: } elsif (!@text) {
17633: $resulttext .= &mt('No recipients');
1.134 raeburn 17634: }
17635: $resulttext .= '</li>';
1.28 raeburn 17636: }
17637: }
1.315 raeburn 17638: if (ref($changes{'overrides'}) eq 'ARRAY') {
17639: my @deletions;
17640: foreach my $type (@{$changes{'overrides'}}) {
17641: if ($usertypeshash{$type}) {
17642: if (grep(/^\Q$type\E/,@overrides)) {
17643: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17644: $usertypeshash{$type}).'<ul><li>';
17645: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17646: my @text;
17647: foreach my $item (@contacts) {
1.425 raeburn 17648: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17649: push(@text,$short_titles->{$item});
17650: }
17651: }
17652: if ($newsetting{'override_'.$type}{'others'} ne '') {
17653: push(@text,$newsetting{'override_'.$type}{'others'});
17654: }
1.425 raeburn 17655:
1.315 raeburn 17656: if (@text) {
17657: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17658: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17659: }
17660: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17661: my $bcctext;
17662: if (@text) {
17663: $bcctext = ' '.&mt('with Bcc to');
17664: } else {
17665: $bcctext = '(Bcc)';
17666: }
17667: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17668: } elsif (!@text) {
17669: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17670: }
17671: $resulttext .= '</li>';
17672: if ($newsetting{'override_'.$type}{'include'} ne '') {
17673: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17674: if ($loc eq 'b') {
17675: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17676: } elsif ($loc eq 's') {
17677: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17678: }
17679: }
17680: }
17681: $resulttext .= '</li></ul></li>';
17682: } else {
17683: push(@deletions,$usertypeshash{$type});
17684: }
17685: }
17686: }
17687: if (@deletions) {
17688: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17689: join(', ',@deletions)).'</li>';
17690: }
17691: }
1.203 raeburn 17692: my @offon = ('off','on');
1.340 raeburn 17693: my $corelink = &core_link_msu();
1.203 raeburn 17694: if ($changes{'reporterrors'}) {
17695: $resulttext .= '<li>'.
17696: &mt('E-mail error reports to [_1] set to "'.
17697: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17698: $corelink).
1.203 raeburn 17699: '</li>';
17700: }
17701: if ($changes{'reportupdates'}) {
17702: $resulttext .= '<li>'.
17703: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17704: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17705: $corelink).
1.203 raeburn 17706: '</li>';
17707: }
1.340 raeburn 17708: if ($changes{'reportstatus'}) {
17709: $resulttext .= '<li>'.
17710: &mt('E-mail status if errors above threshold to [_1] set to "'.
17711: $offon[$env{'form.reportstatus'}].'".',
17712: $corelink).
17713: '</li>';
17714: }
17715: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17716: $resulttext .= '<li>'.
17717: &mt('Nightly status check e-mail settings').':<ul>';
17718: my (%defval,%use_def,%shown);
17719: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17720: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17721: $defval{'weights'} =
1.341 raeburn 17722: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17723: $defval{'excluded'} = &mt('None');
17724: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17725: foreach my $item ('threshold','sysmail','weights','excluded') {
17726: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17727: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17728: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17729: } elsif ($item eq 'weights') {
17730: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17731: foreach my $type ('E','W','N','U') {
1.340 raeburn 17732: $shown{$item} .= $lonstatus_names->{$type}.'=';
17733: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17734: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17735: } else {
17736: $shown{$item} .= $lonstatus_defs->{$type};
17737: }
17738: $shown{$item} .= ', ';
17739: }
17740: $shown{$item} =~ s/, $//;
17741: } else {
17742: $shown{$item} = $defval{$item};
17743: }
17744: } elsif ($item eq 'excluded') {
17745: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17746: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17747: } else {
17748: $shown{$item} = $defval{$item};
17749: }
17750: }
17751: } else {
17752: $shown{$item} = $defval{$item};
17753: }
17754: }
17755: } else {
17756: foreach my $item ('threshold','weights','excluded','sysmail') {
17757: $shown{$item} = $defval{$item};
17758: }
17759: }
17760: foreach my $item ('threshold','weights','excluded','sysmail') {
17761: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17762: $shown{$item}).'</li>';
17763: }
17764: $resulttext .= '</ul></li>';
17765: }
1.286 raeburn 17766: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17767: my (@optional,@required,@unused,$maxsizechg);
17768: foreach my $field (@{$changes{'helpform'}}) {
17769: if ($field eq 'maxsize') {
17770: $maxsizechg = 1;
17771: next;
17772: }
17773: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17774: push(@optional,$field);
1.286 raeburn 17775: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17776: push(@unused,$field);
17777: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17778: push(@required,$field);
1.286 raeburn 17779: }
17780: }
17781: if (@optional) {
17782: $resulttext .= '<li>'.
17783: &mt('Help form fields changed to "Optional": [_1].',
17784: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17785: '</li>';
17786: }
17787: if (@required) {
17788: $resulttext .= '<li>'.
17789: &mt('Help form fields changed to "Required": [_1].',
17790: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17791: '</li>';
17792: }
17793: if (@unused) {
17794: $resulttext .= '<li>'.
17795: &mt('Help form fields changed to "Not shown": [_1].',
17796: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17797: '</li>';
17798: }
17799: if ($maxsizechg) {
17800: $resulttext .= '<li>'.
17801: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17802: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17803: '</li>';
17804: }
17805: }
1.28 raeburn 17806: $resulttext .= '</ul>';
17807: } else {
1.288 raeburn 17808: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17809: }
17810: } else {
17811: $resulttext = '<span class="LC_error">'.
17812: &mt('An error occurred: [_1].',$putresult).'</span>';
17813: }
17814: return $resulttext;
17815: }
17816:
1.357 raeburn 17817: sub modify_privacy {
1.427 raeburn 17818: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17819: my ($resulttext,%current,%changes);
17820: if (ref($domconfig{'privacy'}) eq 'HASH') {
17821: %current = %{$domconfig{'privacy'}};
17822: }
17823: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17824: my @items = ('domain','author','course','community');
17825: my %names = &Apache::lonlocal::texthash (
17826: domain => 'Assigned domain role(s)',
17827: author => 'Assigned co-author role(s)',
17828: course => 'Assigned course role(s)',
1.416 raeburn 17829: community => 'Assigned community role(s)',
1.357 raeburn 17830: );
17831: my %roles = &Apache::lonlocal::texthash (
17832: domain => 'Domain role',
17833: author => 'Co-author role',
17834: course => 'Course role',
17835: community => 'Community role',
17836: );
17837: my %titles = &Apache::lonlocal::texthash (
17838: approval => 'Approval for role in different domain',
17839: othdom => 'User information available in other domain',
17840: priv => 'Information viewable by privileged user in same domain',
17841: unpriv => 'Information viewable by unprivileged user in same domain',
17842: instdom => 'Other domain shares institution/provider',
17843: extdom => 'Other domain has different institution/provider',
17844: none => 'Not allowed',
17845: user => 'User authorizes',
17846: domain => 'Domain Coordinator authorizes',
17847: auto => 'Unrestricted',
1.418 raeburn 17848: notify => 'Notify when role needs authorization',
1.357 raeburn 17849: );
17850: my %fieldnames = &Apache::lonlocal::texthash (
17851: id => 'Student/Employee ID',
17852: permanentemail => 'E-mail address',
17853: lastname => 'Last Name',
17854: firstname => 'First Name',
17855: middlename => 'Middle Name',
17856: generation => 'Generation',
17857: );
17858: my ($othertitle,$usertypes,$types) =
17859: &Apache::loncommon::sorted_inst_types($dom);
17860: my (%by_ip,%by_location,@intdoms,@instdoms);
17861: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17862:
17863: my %privacyhash = (
17864: 'approval' => {
17865: instdom => {},
17866: extdom => {},
17867: },
17868: 'othdom' => {},
17869: );
17870: foreach my $item (@items) {
17871: if (@instdoms > 1) {
1.416 raeburn 17872: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17873: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17874: }
17875: if (ref($current{'approval'}) eq 'HASH') {
17876: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17877: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17878: $changes{'approval'} = 1;
17879: }
17880: }
17881: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17882: $changes{'approval'} = 1;
17883: }
17884: }
17885: if (keys(%by_location) > 0) {
17886: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17887: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17888: }
17889: if (ref($current{'approval'}) eq 'HASH') {
17890: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17891: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17892: $changes{'approval'} = 1;
17893: }
17894: }
17895: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17896: $changes{'approval'} = 1;
17897: }
17898: }
17899: }
17900: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17901: my @statuses;
17902: if (ref($types) eq 'ARRAY') {
17903: @statuses = @{$types};
17904: }
17905: foreach my $type (@statuses,'default') {
17906: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17907: my @newvalues;
17908: foreach my $field (sort(@possfields)) {
17909: if (grep(/^\Q$field\E$/,@fields)) {
17910: $privacyhash{'othdom'}{$type}{$field} = 1;
17911: push(@newvalues,$field);
17912: }
17913: }
17914: @newvalues = sort(@newvalues);
17915: if (ref($current{'othdom'}) eq 'HASH') {
17916: if (ref($current{'othdom'}{$type}) eq 'HASH') {
17917: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
17918: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17919: if (@diffs > 0) {
17920: $changes{'othdom'} = 1;
17921: }
1.447.2.3 raeburn 17922: } elsif (@newvalues > 0) {
17923: $changes{'othdom'} = 1;
1.357 raeburn 17924: }
17925: } else {
17926: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
17927: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17928: if (@diffs > 0) {
17929: $changes{'othdom'} = 1;
17930: }
17931: }
17932: }
1.417 raeburn 17933: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
17934: my %notify;
17935: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
17936: if (exists($domcoords{$possdc})) {
17937: $notify{$possdc} = 1;
17938: }
17939: }
17940: my $notify = join(',',sort(keys(%notify)));
17941: if ($current{'notify'} ne $notify) {
17942: $changes{'notify'} = 1;
17943: }
17944: $privacyhash{'notify'} = $notify;
1.357 raeburn 17945: }
17946: my %confighash = (
17947: privacy => \%privacyhash,
17948: );
17949: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17950: if ($putresult eq 'ok') {
17951: if (keys(%changes) > 0) {
17952: $resulttext = &mt('Changes made: ').'<ul>';
1.447.2.4 raeburn 17953: foreach my $key ('approval','notify','othdom') {
1.357 raeburn 17954: if ($changes{$key}) {
17955: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17956: if ($key eq 'approval') {
17957: if (keys(%{$privacyhash{$key}{instdom}})) {
17958: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
17959: foreach my $item (@items) {
17960: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
17961: }
17962: $resulttext .= '</ul></li>';
17963: }
17964: if (keys(%{$privacyhash{$key}{extdom}})) {
17965: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
17966: foreach my $item (@items) {
17967: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
17968: }
17969: $resulttext .= '</ul></li>';
17970: }
1.417 raeburn 17971: } elsif ($key eq 'notify') {
17972: if ($privacyhash{$key}) {
17973: foreach my $dc (split(/,/,$privacyhash{$key})) {
17974: my ($dcname,$dcdom) = split(/:/,$dc);
17975: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
17976: }
17977: } else {
17978: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
17979: }
1.357 raeburn 17980: } elsif ($key eq 'othdom') {
17981: my @statuses;
17982: if (ref($types) eq 'ARRAY') {
17983: @statuses = @{$types};
17984: }
17985: if (ref($privacyhash{$key}) eq 'HASH') {
17986: foreach my $status (@statuses,'default') {
17987: if ($status eq 'default') {
17988: $resulttext .= '<li>'.$othertitle.': ';
17989: } elsif (ref($usertypes) eq 'HASH') {
17990: $resulttext .= '<li>'.$usertypes->{$status}.': ';
17991: } else {
17992: next;
17993: }
17994: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
17995: if (keys(%{$privacyhash{$key}{$status}})) {
17996: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
17997: } else {
17998: $resulttext .= &mt('none');
17999: }
18000: }
18001: $resulttext .= '</li>';
18002: }
18003: }
18004: }
18005: $resulttext .= '</ul></li>';
18006: }
18007: }
1.421 raeburn 18008: $resulttext .= '</ul>';
1.427 raeburn 18009: if ($changes{'approval'}) {
18010: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18011: delete($domdefaults{'userapprovals'});
18012: if (ref($privacyhash{'approval'}) eq 'HASH') {
18013: foreach my $domtype ('instdom','extdom') {
18014: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
18015: foreach my $roletype ('domain','author','course','community') {
18016: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
18017: $domdefaults{'userapprovals'} = 1;
18018: last;
18019: }
18020: }
18021: }
18022: last if ($domdefaults{'userapprovals'});
18023: }
18024: }
18025: my $cachetime = 24*60*60;
18026: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18027: if (ref($lastactref) eq 'HASH') {
18028: $lastactref->{'domdefaults'} = 1;
18029: }
18030: }
1.357 raeburn 18031: } else {
18032: $resulttext = &mt('No changes made to user information settings');
18033: }
18034: } else {
18035: $resulttext = '<span class="LC_error">'.
18036: &mt('An error occurred: [_1]',$putresult).'</span>';
18037: }
18038: return $resulttext;
18039: }
18040:
1.354 raeburn 18041: sub modify_passwords {
18042: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18043: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18044: $updatedefaults,$updateconf);
1.354 raeburn 18045: my $customfn = 'resetpw.html';
18046: if (ref($domconfig{'passwords'}) eq 'HASH') {
18047: %current = %{$domconfig{'passwords'}};
18048: }
18049: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18050: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18051: if (ref($types) eq 'ARRAY') {
18052: @oktypes = @{$types};
18053: }
18054: push(@oktypes,'default');
18055:
18056: my %titles = &Apache::lonlocal::texthash (
18057: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18058: intauth_check => 'Check bcrypt cost if authenticated',
18059: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18060: permanent => 'Permanent e-mail address',
18061: critical => 'Critical notification address',
18062: notify => 'Notification address',
18063: min => 'Minimum password length',
18064: max => 'Maximum password length',
18065: chars => 'Required characters',
1.356 raeburn 18066: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18067: reset => 'Resetting Forgotten Password',
18068: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18069: rules => 'Rules for LON-CAPA Passwords',
18070: crsownerchg => 'Course Owner Changing Student Passwords',
18071: username => 'Username',
18072: email => 'E-mail address',
18073: );
18074:
18075: #
18076: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18077: #
18078: my (%curr_defaults,%save_defaults);
18079: if (ref($domconfig{'defaults'}) eq 'HASH') {
18080: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18081: if ($key =~ /^intauth_(cost|check|switch)$/) {
18082: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18083: } else {
18084: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18085: }
18086: }
18087: }
18088: my %staticdefaults = (
18089: 'resetlink' => 2,
18090: 'resetcase' => \@oktypes,
18091: 'resetprelink' => 'both',
18092: 'resetemail' => ['critical','notify','permanent'],
18093: 'intauth_cost' => 10,
18094: 'intauth_check' => 0,
18095: 'intauth_switch' => 0,
18096: );
1.365 raeburn 18097: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18098: foreach my $type (@oktypes) {
18099: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18100: }
18101: my $linklife = $env{'form.passwords_link'};
18102: $linklife =~ s/^\s+|\s+$//g;
18103: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18104: $newvalues{'resetlink'} = $linklife;
18105: if ($current{'resetlink'}) {
18106: if ($current{'resetlink'} ne $linklife) {
18107: $changes{'reset'} = 1;
18108: }
1.368 raeburn 18109: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18110: if ($staticdefaults{'resetlink'} ne $linklife) {
18111: $changes{'reset'} = 1;
18112: }
18113: }
18114: } elsif ($current{'resetlink'}) {
18115: $changes{'reset'} = 1;
18116: }
18117: my @casesens;
18118: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18119: foreach my $case (sort(@posscase)) {
18120: if (grep(/^\Q$case\E$/,@oktypes)) {
18121: push(@casesens,$case);
18122: }
18123: }
18124: $newvalues{'resetcase'} = \@casesens;
18125: if (ref($current{'resetcase'}) eq 'ARRAY') {
18126: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18127: if (@diffs > 0) {
18128: $changes{'reset'} = 1;
18129: }
1.368 raeburn 18130: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18131: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18132: if (@diffs > 0) {
18133: $changes{'reset'} = 1;
18134: }
18135: }
18136: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18137: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18138: if (exists($current{'resetprelink'})) {
18139: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18140: $changes{'reset'} = 1;
18141: }
1.368 raeburn 18142: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18143: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18144: $changes{'reset'} = 1;
18145: }
18146: }
18147: } elsif ($current{'resetprelink'}) {
18148: $changes{'reset'} = 1;
18149: }
18150: foreach my $type (@oktypes) {
18151: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18152: my @postlink;
18153: foreach my $item (sort(@possplink)) {
18154: if ($item =~ /^(email|username)$/) {
18155: push(@postlink,$item);
18156: }
18157: }
18158: $newvalues{'resetpostlink'}{$type} = \@postlink;
18159: unless ($changes{'reset'}) {
18160: if (ref($current{'resetpostlink'}) eq 'HASH') {
18161: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18162: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18163: if (@diffs > 0) {
18164: $changes{'reset'} = 1;
18165: }
18166: } else {
18167: $changes{'reset'} = 1;
18168: }
1.368 raeburn 18169: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18170: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18171: if (@diffs > 0) {
18172: $changes{'reset'} = 1;
18173: }
18174: }
18175: }
18176: }
18177: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18178: my @resetemail;
18179: foreach my $item (sort(@possemailsrc)) {
18180: if ($item =~ /^(permanent|critical|notify)$/) {
18181: push(@resetemail,$item);
18182: }
18183: }
18184: $newvalues{'resetemail'} = \@resetemail;
18185: unless ($changes{'reset'}) {
18186: if (ref($current{'resetemail'}) eq 'ARRAY') {
18187: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18188: if (@diffs > 0) {
18189: $changes{'reset'} = 1;
18190: }
1.368 raeburn 18191: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18192: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18193: if (@diffs > 0) {
18194: $changes{'reset'} = 1;
18195: }
18196: }
18197: }
18198: if ($env{'form.passwords_stdtext'} == 0) {
18199: $newvalues{'resetremove'} = 1;
18200: unless ($current{'resetremove'}) {
18201: $changes{'reset'} = 1;
18202: }
18203: } elsif ($current{'resetremove'}) {
18204: $changes{'reset'} = 1;
18205: }
18206: if ($env{'form.passwords_customfile.filename'} ne '') {
18207: my $servadm = $r->dir_config('lonAdmEMail');
18208: my ($configuserok,$author_ok,$switchserver) =
18209: &config_check($dom,$confname,$servadm);
18210: my $error;
18211: if ($configuserok eq 'ok') {
18212: if ($switchserver) {
18213: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18214: } else {
18215: if ($author_ok eq 'ok') {
1.421 raeburn 18216: my $modified = [];
1.354 raeburn 18217: my ($result,$customurl) =
1.421 raeburn 18218: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18219: $confname,'customtext/resetpw','','',$customfn,
18220: $modified);
1.354 raeburn 18221: if ($result eq 'ok') {
18222: $newvalues{'resetcustom'} = $customurl;
18223: $changes{'reset'} = 1;
1.421 raeburn 18224: &update_modify_urls($r,$modified);
1.354 raeburn 18225: } else {
18226: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18227: }
18228: } else {
18229: $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);
18230: }
18231: }
18232: } else {
18233: $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);
18234: }
18235: if ($error) {
18236: &Apache::lonnet::logthis($error);
18237: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18238: }
18239: } elsif ($current{'resetcustom'}) {
18240: if ($env{'form.passwords_custom_del'}) {
18241: $changes{'reset'} = 1;
18242: } else {
18243: $newvalues{'resetcustom'} = $current{'resetcustom'};
18244: }
18245: }
18246: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18247: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18248: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18249: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18250: $changes{'intauth'} = 1;
18251: }
18252: } else {
18253: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18254: }
18255: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18256: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18257: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18258: $changes{'intauth'} = 1;
18259: }
18260: } else {
18261: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18262: }
18263: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18264: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18265: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18266: $changes{'intauth'} = 1;
18267: }
18268: } else {
18269: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18270: }
18271: foreach my $item ('cost','check','switch') {
18272: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18273: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18274: $updatedefaults = 1;
18275: }
18276: }
1.405 raeburn 18277: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18278: my %crsownerchg = (
18279: by => [],
18280: for => [],
18281: );
18282: foreach my $item ('by','for') {
18283: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18284: foreach my $type (sort(@posstypes)) {
18285: if (grep(/^\Q$type\E$/,@oktypes)) {
18286: push(@{$crsownerchg{$item}},$type);
18287: }
18288: }
18289: }
18290: $newvalues{'crsownerchg'} = \%crsownerchg;
18291: if (ref($current{'crsownerchg'}) eq 'HASH') {
18292: foreach my $item ('by','for') {
18293: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18294: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18295: if (@diffs > 0) {
18296: $changes{'crsownerchg'} = 1;
18297: last;
18298: }
18299: }
18300: }
1.368 raeburn 18301: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18302: foreach my $item ('by','for') {
18303: if (@{$crsownerchg{$item}} > 0) {
18304: $changes{'crsownerchg'} = 1;
18305: last;
18306: }
1.354 raeburn 18307: }
18308: }
18309:
18310: my %confighash = (
18311: defaults => \%save_defaults,
18312: passwords => \%newvalues,
18313: );
18314: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18315:
18316: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18317: if ($putresult eq 'ok') {
18318: if (keys(%changes) > 0) {
18319: $resulttext = &mt('Changes made: ').'<ul>';
18320: foreach my $key ('reset','intauth','rules','crsownerchg') {
18321: if ($changes{$key}) {
1.355 raeburn 18322: unless ($key eq 'intauth') {
18323: $updateconf = 1;
18324: }
1.354 raeburn 18325: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18326: if ($key eq 'reset') {
18327: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18328: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18329: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18330: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18331: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18332: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18333: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18334: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18335: }
1.354 raeburn 18336: } else {
18337: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18338: }
18339: if ($confighash{'passwords'}{'resetlink'}) {
18340: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18341: } else {
18342: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18343: &mt('Will default to 2 hours').'</li>';
18344: }
18345: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18346: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18347: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18348: } else {
18349: my $casesens;
18350: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18351: if ($type eq 'default') {
18352: $casesens .= $othertitle.', ';
18353: } elsif ($usertypes->{$type} ne '') {
18354: $casesens .= $usertypes->{$type}.', ';
18355: }
18356: }
18357: $casesens =~ s/\Q, \E$//;
18358: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18359: }
18360: } else {
18361: $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>';
18362: }
18363: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18364: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18365: } else {
18366: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18367: }
18368: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18369: my $output;
18370: if (ref($types) eq 'ARRAY') {
18371: foreach my $type (@{$types}) {
18372: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18373: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18374: $output .= $usertypes->{$type}.' -- '.&mt('none');
18375: } else {
18376: $output .= $usertypes->{$type}.' -- '.
18377: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18378: }
18379: }
18380: }
18381: }
18382: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18383: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18384: $output .= $othertitle.' -- '.&mt('none');
18385: } else {
18386: $output .= $othertitle.' -- '.
18387: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18388: }
18389: }
18390: if ($output) {
18391: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18392: } else {
18393: $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>';
18394: }
18395: } else {
18396: $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>';
18397: }
18398: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18399: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18400: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18401: } else {
18402: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18403: }
18404: } else {
1.379 raeburn 18405: $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 18406: }
18407: if ($confighash{'passwords'}{'resetremove'}) {
18408: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18409: } else {
18410: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18411: }
18412: if ($confighash{'passwords'}{'resetcustom'}) {
18413: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18414: &mt('custom text'),600,500,undef,undef,
18415: undef,undef,'background-color:#ffffff');
18416: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18417: } else {
18418: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18419: }
18420: } elsif ($key eq 'intauth') {
18421: foreach my $item ('cost','switch','check') {
18422: my $value = $save_defaults{$key.'_'.$item};
18423: if ($item eq 'switch') {
18424: my %optiondesc = &Apache::lonlocal::texthash (
18425: 0 => 'No',
18426: 1 => 'Yes',
18427: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18428: );
18429: if ($value =~ /^(0|1|2)$/) {
18430: $value = $optiondesc{$value};
18431: } else {
18432: $value = &mt('none -- defaults to No');
18433: }
18434: } elsif ($item eq 'check') {
18435: my %optiondesc = &Apache::lonlocal::texthash (
18436: 0 => 'No',
18437: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18438: 2 => 'Yes, disallow login if stored cost is less than domain default',
18439: );
18440: if ($value =~ /^(0|1|2)$/) {
18441: $value = $optiondesc{$value};
18442: } else {
18443: $value = &mt('none -- defaults to No');
18444: }
18445: }
18446: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18447: }
18448: } elsif ($key eq 'rules') {
1.447.2.5! raeburn 18449: foreach my $rule ('min','max','numsaved') {
1.354 raeburn 18450: if ($confighash{'passwords'}{$rule} eq '') {
18451: if ($rule eq 'min') {
1.356 raeburn 18452: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18453: ' '.&mt('Default of [_1] will be used',
18454: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18455: } else {
18456: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18457: }
18458: } else {
18459: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18460: }
18461: }
1.370 raeburn 18462: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18463: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18464: my %rulenames = &Apache::lonlocal::texthash(
18465: uc => 'At least one upper case letter',
18466: lc => 'At least one lower case letter',
18467: num => 'At least one number',
18468: spec => 'At least one non-alphanumeric',
18469: );
18470: my $needed = '<ul><li>'.
18471: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18472: '</li></ul>';
1.370 raeburn 18473: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18474: } else {
18475: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18476: }
18477: } else {
18478: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18479: }
1.354 raeburn 18480: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18481: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18482: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18483: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18484: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18485: } else {
18486: my %crsownerstr;
18487: foreach my $item ('by','for') {
18488: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18489: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18490: if ($type eq 'default') {
18491: $crsownerstr{$item} .= $othertitle.', ';
18492: } elsif ($usertypes->{$type} ne '') {
18493: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18494: }
18495: }
18496: $crsownerstr{$item} =~ s/\Q, \E$//;
18497: }
18498: }
18499: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18500: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18501: }
1.354 raeburn 18502: } else {
1.359 raeburn 18503: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18504: }
18505: }
18506: $resulttext .= '</ul></li>';
18507: }
18508: }
18509: $resulttext .= '</ul>';
18510: } else {
18511: $resulttext = &mt('No changes made to password settings');
18512: }
1.355 raeburn 18513: my $cachetime = 24*60*60;
1.354 raeburn 18514: if ($updatedefaults) {
18515: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18516: if (ref($lastactref) eq 'HASH') {
18517: $lastactref->{'domdefaults'} = 1;
18518: }
18519: }
1.355 raeburn 18520: if ($updateconf) {
18521: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18522: if (ref($lastactref) eq 'HASH') {
18523: $lastactref->{'passwdconf'} = 1;
18524: }
18525: }
1.354 raeburn 18526: } else {
18527: $resulttext = '<span class="LC_error">'.
18528: &mt('An error occurred: [_1]',$putresult).'</span>';
18529: }
18530: if ($errors) {
18531: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18532: $errors.'</ul></p>';
18533: }
18534: return $resulttext;
18535: }
18536:
1.405 raeburn 18537: sub password_rule_changes {
18538: my ($prefix,$newvalues,$current,$changes) = @_;
18539: return unless ((ref($newvalues) eq 'HASH') &&
18540: (ref($current) eq 'HASH') &&
18541: (ref($changes) eq 'HASH'));
18542: my (@rules,%staticdefaults);
18543: if ($prefix eq 'passwords') {
1.447.2.5! raeburn 18544: @rules = ('min','max','numsaved');
1.421 raeburn 18545: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18546: @rules = ('min','max');
18547: }
18548: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18549: foreach my $rule (@rules) {
18550: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18551: my $ruleok;
1.447.2.5! raeburn 18552: if ($rule eq 'min') {
1.405 raeburn 18553: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18554: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18555: $ruleok = 1;
18556: }
18557: }
18558: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18559: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18560: $ruleok = 1;
18561: }
18562: if ($ruleok) {
18563: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18564: if (exists($current->{$rule})) {
18565: if ($newvalues->{$rule} ne $current->{$rule}) {
18566: $changes->{'rules'} = 1;
18567: }
18568: } elsif ($rule eq 'min') {
18569: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18570: $changes->{'rules'} = 1;
18571: }
18572: } else {
18573: $changes->{'rules'} = 1;
18574: }
18575: } elsif (exists($current->{$rule})) {
18576: $changes->{'rules'} = 1;
18577: }
18578: }
18579: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18580: my @chars;
18581: foreach my $item (sort(@posschars)) {
18582: if ($item =~ /^(uc|lc|num|spec)$/) {
18583: push(@chars,$item);
18584: }
18585: }
18586: $newvalues->{'chars'} = \@chars;
18587: unless ($changes->{'rules'}) {
18588: if (ref($current->{'chars'}) eq 'ARRAY') {
18589: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18590: if (@diffs > 0) {
18591: $changes->{'rules'} = 1;
18592: }
18593: } else {
18594: if (@chars > 0) {
18595: $changes->{'rules'} = 1;
18596: }
18597: }
18598: }
18599: return;
18600: }
18601:
1.28 raeburn 18602: sub modify_usercreation {
1.27 raeburn 18603: my ($dom,%domconfig) = @_;
1.224 raeburn 18604: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18605: my $warningmsg;
1.27 raeburn 18606: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18607: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18608: if ($key eq 'cancreate') {
18609: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18610: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18611: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18612: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18613: } else {
1.224 raeburn 18614: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18615: }
18616: }
18617: }
18618: } elsif ($key eq 'email_rule') {
18619: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18620: } else {
18621: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18622: }
1.27 raeburn 18623: }
18624: }
18625: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18626: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18627: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18628: foreach my $item(@contexts) {
1.224 raeburn 18629: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18630: }
1.34 raeburn 18631: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18632: foreach my $item (@contexts) {
1.224 raeburn 18633: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18634: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18635: }
1.27 raeburn 18636: }
1.34 raeburn 18637: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18638: foreach my $item (@contexts) {
1.43 raeburn 18639: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18640: if ($cancreate{$item} ne 'any') {
18641: push(@{$changes{'cancreate'}},$item);
18642: }
18643: } else {
18644: if ($cancreate{$item} ne 'none') {
18645: push(@{$changes{'cancreate'}},$item);
18646: }
1.27 raeburn 18647: }
18648: }
18649: } else {
1.43 raeburn 18650: foreach my $item (@contexts) {
1.34 raeburn 18651: push(@{$changes{'cancreate'}},$item);
18652: }
1.27 raeburn 18653: }
1.34 raeburn 18654:
1.27 raeburn 18655: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18656: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18657: if (!grep(/^\Q$type\E$/,@username_rule)) {
18658: push(@{$changes{'username_rule'}},$type);
18659: }
18660: }
18661: foreach my $type (@username_rule) {
18662: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18663: push(@{$changes{'username_rule'}},$type);
18664: }
18665: }
18666: } else {
18667: push(@{$changes{'username_rule'}},@username_rule);
18668: }
18669:
1.32 raeburn 18670: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18671: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18672: if (!grep(/^\Q$type\E$/,@id_rule)) {
18673: push(@{$changes{'id_rule'}},$type);
18674: }
18675: }
18676: foreach my $type (@id_rule) {
18677: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18678: push(@{$changes{'id_rule'}},$type);
18679: }
18680: }
18681: } else {
18682: push(@{$changes{'id_rule'}},@id_rule);
18683: }
18684:
1.43 raeburn 18685: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18686: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18687: my %authhash;
1.43 raeburn 18688: foreach my $item (@authen_contexts) {
1.28 raeburn 18689: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18690: foreach my $auth (@authtypes) {
18691: if (grep(/^\Q$auth\E$/,@authallowed)) {
18692: $authhash{$item}{$auth} = 1;
18693: } else {
18694: $authhash{$item}{$auth} = 0;
18695: }
18696: }
18697: }
18698: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18699: foreach my $item (@authen_contexts) {
1.28 raeburn 18700: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18701: foreach my $auth (@authtypes) {
18702: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18703: push(@{$changes{'authtypes'}},$item);
18704: last;
18705: }
18706: }
18707: }
18708: }
18709: } else {
1.43 raeburn 18710: foreach my $item (@authen_contexts) {
1.28 raeburn 18711: push(@{$changes{'authtypes'}},$item);
18712: }
18713: }
18714:
1.224 raeburn 18715: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18716: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18717: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18718: $save_usercreate{'id_rule'} = \@id_rule;
18719: $save_usercreate{'username_rule'} = \@username_rule,
18720: $save_usercreate{'authtypes'} = \%authhash;
18721:
1.27 raeburn 18722: my %usercreation_hash = (
1.224 raeburn 18723: usercreation => \%save_usercreate,
18724: );
1.27 raeburn 18725:
18726: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18727: $dom);
1.50 raeburn 18728:
1.224 raeburn 18729: if ($putresult eq 'ok') {
18730: if (keys(%changes) > 0) {
18731: $resulttext = &mt('Changes made:').'<ul>';
18732: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18733: my %lt = &usercreation_types();
18734: foreach my $type (@{$changes{'cancreate'}}) {
18735: my $chgtext = $lt{$type}.', ';
18736: if ($cancreate{$type} eq 'none') {
18737: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18738: } elsif ($cancreate{$type} eq 'any') {
18739: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18740: } elsif ($cancreate{$type} eq 'official') {
18741: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18742: } elsif ($cancreate{$type} eq 'unofficial') {
18743: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18744: }
18745: $resulttext .= '<li>'.$chgtext.'</li>';
18746: }
18747: }
18748: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18749: my ($rules,$ruleorder) =
18750: &Apache::lonnet::inst_userrules($dom,'username');
18751: my $chgtext = '<ul>';
18752: foreach my $type (@username_rule) {
18753: if (ref($rules->{$type}) eq 'HASH') {
18754: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18755: }
18756: }
18757: $chgtext .= '</ul>';
18758: if (@username_rule > 0) {
18759: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18760: } else {
18761: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18762: }
18763: }
18764: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18765: my ($idrules,$idruleorder) =
18766: &Apache::lonnet::inst_userrules($dom,'id');
18767: my $chgtext = '<ul>';
18768: foreach my $type (@id_rule) {
18769: if (ref($idrules->{$type}) eq 'HASH') {
18770: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18771: }
18772: }
18773: $chgtext .= '</ul>';
18774: if (@id_rule > 0) {
18775: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18776: } else {
18777: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18778: }
18779: }
18780: my %authname = &authtype_names();
18781: my %context_title = &context_names();
18782: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18783: my $chgtext = '<ul>';
18784: foreach my $type (@{$changes{'authtypes'}}) {
18785: my @allowed;
18786: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18787: foreach my $auth (@authtypes) {
18788: if ($authhash{$type}{$auth}) {
18789: push(@allowed,$authname{$auth});
18790: }
18791: }
18792: if (@allowed > 0) {
18793: $chgtext .= join(', ',@allowed).'</li>';
18794: } else {
18795: $chgtext .= &mt('none').'</li>';
18796: }
18797: }
18798: $chgtext .= '</ul>';
18799: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18800: $resulttext .= '</li>';
18801: }
18802: $resulttext .= '</ul>';
18803: } else {
18804: $resulttext = &mt('No changes made to user creation settings');
18805: }
18806: } else {
18807: $resulttext = '<span class="LC_error">'.
18808: &mt('An error occurred: [_1]',$putresult).'</span>';
18809: }
18810: if ($warningmsg ne '') {
18811: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18812: }
18813: return $resulttext;
18814: }
18815:
18816: sub modify_selfcreation {
1.305 raeburn 18817: my ($dom,$lastactref,%domconfig) = @_;
18818: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18819: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18820: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18821: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18822: if (ref($typesref) eq 'ARRAY') {
18823: @types = @{$typesref};
18824: }
18825: if (ref($usertypesref) eq 'HASH') {
18826: %usertypes = %{$usertypesref};
1.228 raeburn 18827: }
1.303 raeburn 18828: $usertypes{'default'} = $othertitle;
1.224 raeburn 18829: #
18830: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18831: #
18832: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18833: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18834: if ($key eq 'cancreate') {
18835: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18836: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18837: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18838: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18839: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18840: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18841: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18842: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18843: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18844: } else {
18845: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18846: }
18847: }
18848: }
18849: } elsif ($key eq 'email_rule') {
18850: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18851: } else {
18852: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18853: }
18854: }
18855: }
18856: #
18857: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18858: #
18859: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18860: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18861: if ($key eq 'selfcreate') {
18862: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18863: } else {
18864: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18865: }
18866: }
18867: }
1.305 raeburn 18868: #
18869: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18870: #
18871: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18872: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18873: if ($key eq 'inststatusguest') {
18874: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18875: } else {
18876: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18877: }
18878: }
18879: }
1.224 raeburn 18880:
18881: my @contexts = ('selfcreate');
18882: @{$cancreate{'selfcreate'}} = ();
18883: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18884: if (@types) {
18885: @{$cancreate{'statustocreate'}} = ();
18886: }
1.236 raeburn 18887: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18888: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18889: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18890: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18891: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18892: my %selfcreatetypes = (
18893: sso => 'users authenticated by institutional single sign on',
18894: login => 'users authenticated by institutional log-in',
1.303 raeburn 18895: email => 'users verified by e-mail',
1.50 raeburn 18896: );
1.224 raeburn 18897: #
18898: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18899: # is permitted.
18900: #
1.305 raeburn 18901: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 18902:
1.305 raeburn 18903: my (@statuses,%email_rule);
1.228 raeburn 18904: foreach my $item ('login','sso','email') {
1.224 raeburn 18905: if ($item eq 'email') {
1.236 raeburn 18906: if ($env{'form.cancreate_email'}) {
1.305 raeburn 18907: if (@types) {
18908: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
18909: foreach my $status (@poss_statuses) {
18910: if (grep(/^\Q$status\E$/,(@types,'default'))) {
18911: push(@statuses,$status);
18912: }
18913: }
18914: $save_inststatus{'inststatusguest'} = \@statuses;
18915: } else {
18916: push(@statuses,'default');
18917: }
18918: if (@statuses) {
18919: my %curr_rule;
18920: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
18921: foreach my $type (@statuses) {
18922: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 18923: }
1.305 raeburn 18924: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
18925: foreach my $type (@statuses) {
18926: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
18927: }
18928: }
18929: push(@{$cancreate{'selfcreate'}},'email');
18930: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
18931: my %curremaildom;
18932: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
18933: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
18934: }
18935: foreach my $type (@statuses) {
18936: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
18937: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
18938: }
18939: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
18940: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
18941: }
18942: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
18943: #
18944: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
18945: #
18946: my $chosen = $1;
18947: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
18948: my $emaildom;
18949: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 18950: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 18951: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
18952: if (ref($curremaildom{$type}) eq 'HASH') {
18953: if (exists($curremaildom{$type}{$chosen})) {
18954: if ($curremaildom{$type}{$chosen} ne $emaildom) {
18955: push(@{$changes{'cancreate'}},'emaildomain');
18956: }
18957: } elsif ($emaildom ne '') {
18958: push(@{$changes{'cancreate'}},'emaildomain');
18959: }
18960: } elsif ($emaildom ne '') {
18961: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 18962: }
1.305 raeburn 18963: }
18964: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18965: } elsif ($chosen eq 'custom') {
18966: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
18967: $email_rule{$type} = [];
18968: if (ref($emailrules) eq 'HASH') {
18969: foreach my $rule (@possemail_rules) {
18970: if (exists($emailrules->{$rule})) {
18971: push(@{$email_rule{$type}},$rule);
18972: }
18973: }
18974: }
18975: if (@{$email_rule{$type}}) {
18976: $cancreate{'emailoptions'}{$type} = 'custom';
18977: if (ref($curr_rule{$type}) eq 'ARRAY') {
18978: if (@{$curr_rule{$type}} > 0) {
18979: foreach my $rule (@{$curr_rule{$type}}) {
18980: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
18981: push(@{$changes{'email_rule'}},$type);
18982: }
18983: }
18984: }
18985: foreach my $type (@{$email_rule{$type}}) {
18986: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
18987: push(@{$changes{'email_rule'}},$type);
18988: }
18989: }
18990: } else {
18991: push(@{$changes{'email_rule'}},$type);
18992: }
18993: }
18994: } else {
18995: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18996: }
18997: }
18998: }
18999: if (@types) {
19000: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19001: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
19002: if (@changed) {
19003: push(@{$changes{'inststatus'}},'inststatusguest');
19004: }
19005: } else {
19006: push(@{$changes{'inststatus'}},'inststatusguest');
19007: }
19008: }
19009: } else {
19010: delete($env{'form.cancreate_email'});
19011: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19012: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19013: push(@{$changes{'inststatus'}},'inststatusguest');
19014: }
19015: }
19016: }
19017: } else {
19018: $save_inststatus{'inststatusguest'} = [];
19019: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19020: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19021: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 19022: }
19023: }
1.224 raeburn 19024: }
19025: } else {
19026: if ($env{'form.cancreate_'.$item}) {
19027: push(@{$cancreate{'selfcreate'}},$item);
19028: }
19029: }
19030: }
1.305 raeburn 19031: my (%userinfo,%savecaptcha);
1.224 raeburn 19032: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
19033: #
1.228 raeburn 19034: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
19035: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19036: #
1.236 raeburn 19037:
1.244 raeburn 19038: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19039: push(@contexts,'emailusername');
1.305 raeburn 19040: if (@statuses) {
19041: foreach my $type (@statuses) {
1.228 raeburn 19042: if (ref($infofields) eq 'ARRAY') {
19043: foreach my $field (@{$infofields}) {
19044: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19045: $cancreate{'emailusername'}{$type}{$field} = $1;
19046: }
19047: }
1.224 raeburn 19048: }
19049: }
19050: }
19051: #
19052: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19053: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19054: #
19055:
19056: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19057: @approvalnotify = sort(@approvalnotify);
19058: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19059: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19060: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19061: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19062: push(@{$changes{'cancreate'}},'notify');
19063: }
19064: } else {
19065: if ($cancreate{'notify'}{'approval'}) {
19066: push(@{$changes{'cancreate'}},'notify');
19067: }
19068: }
19069: } elsif ($cancreate{'notify'}{'approval'}) {
19070: push(@{$changes{'cancreate'}},'notify');
19071: }
19072:
19073: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19074: }
19075: #
1.236 raeburn 19076: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19077: # institutional log-in.
19078: #
19079: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19080: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19081: ($domdefaults{'auth_def'} eq 'localauth'))) {
19082: $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.').' '.
19083: &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.');
19084: }
19085: }
19086: my @fields = ('lastname','firstname','middlename','generation',
19087: 'permanentemail','id');
1.240 raeburn 19088: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19089: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19090: #
19091: # Where usernames may created for institutional log-in and/or institutional single sign on:
19092: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19093: # may self-create accounts
19094: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19095: # which the user may supply, if institutional data is unavailable.
19096: #
19097: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19098: if (@types) {
1.305 raeburn 19099: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19100: push(@contexts,'statustocreate');
1.303 raeburn 19101: foreach my $type (@types) {
1.224 raeburn 19102: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19103: foreach my $field (@fields) {
19104: if (grep(/^\Q$field\E$/,@modifiable)) {
19105: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19106: } else {
19107: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19108: }
19109: }
19110: }
19111: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19112: foreach my $type (@types) {
1.224 raeburn 19113: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19114: foreach my $field (@fields) {
19115: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19116: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19117: push(@{$changes{'selfcreate'}},$type);
19118: last;
19119: }
19120: }
19121: }
19122: }
19123: } else {
1.303 raeburn 19124: foreach my $type (@types) {
1.224 raeburn 19125: push(@{$changes{'selfcreate'}},$type);
19126: }
19127: }
19128: }
1.240 raeburn 19129: foreach my $field (@shibfields) {
19130: if ($env{'form.shibenv_'.$field} ne '') {
19131: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19132: }
19133: }
19134: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19135: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19136: foreach my $field (@shibfields) {
19137: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19138: push(@{$changes{'cancreate'}},'shibenv');
19139: }
19140: }
19141: } else {
19142: foreach my $field (@shibfields) {
19143: if ($env{'form.shibenv_'.$field}) {
19144: push(@{$changes{'cancreate'}},'shibenv');
19145: last;
19146: }
19147: }
19148: }
19149: }
1.224 raeburn 19150: }
19151: foreach my $item (@contexts) {
19152: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19153: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19154: if (ref($cancreate{$item}) eq 'ARRAY') {
19155: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19156: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19157: push(@{$changes{'cancreate'}},$item);
19158: }
19159: }
19160: }
19161: }
19162: if (ref($cancreate{$item}) eq 'ARRAY') {
19163: foreach my $type (@{$cancreate{$item}}) {
19164: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19165: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19166: push(@{$changes{'cancreate'}},$item);
19167: }
19168: }
19169: }
19170: }
19171: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19172: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19173: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19174: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19175: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19176: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19177: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19178: push(@{$changes{'cancreate'}},$item);
19179: }
19180: }
19181: }
1.305 raeburn 19182: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19183: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19184: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19185: push(@{$changes{'cancreate'}},$item);
19186: }
1.224 raeburn 19187: }
19188: }
19189: }
1.305 raeburn 19190: foreach my $type (keys(%{$cancreate{$item}})) {
19191: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19192: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19193: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19194: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19195: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19196: push(@{$changes{'cancreate'}},$item);
19197: }
19198: }
19199: } else {
19200: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19201: push(@{$changes{'cancreate'}},$item);
19202: }
19203: }
19204: }
1.305 raeburn 19205: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19206: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19207: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19208: push(@{$changes{'cancreate'}},$item);
19209: }
1.224 raeburn 19210: }
19211: }
19212: }
19213: }
19214: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19215: if (ref($cancreate{$item}) eq 'ARRAY') {
19216: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19217: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19218: push(@{$changes{'cancreate'}},$item);
19219: }
19220: }
1.305 raeburn 19221: }
19222: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19223: if (ref($cancreate{$item}) eq 'HASH') {
19224: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19225: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19226: }
19227: }
19228: } elsif ($item eq 'emailusername') {
1.228 raeburn 19229: if (ref($cancreate{$item}) eq 'HASH') {
19230: foreach my $type (keys(%{$cancreate{$item}})) {
19231: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19232: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19233: if ($cancreate{$item}{$type}{$field}) {
19234: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19235: push(@{$changes{'cancreate'}},$item);
19236: }
19237: last;
19238: }
19239: }
19240: }
19241: }
1.224 raeburn 19242: }
19243: }
19244: }
19245: #
19246: # Populate %save_usercreate hash with updates to self-creation configuration.
19247: #
19248: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19249: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19250: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19251: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19252: if (ref($cancreate{'notify'}) eq 'HASH') {
19253: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19254: }
1.236 raeburn 19255: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19256: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19257: }
1.303 raeburn 19258: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19259: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19260: }
1.305 raeburn 19261: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19262: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19263: }
1.303 raeburn 19264: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19265: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19266: }
1.224 raeburn 19267: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19268: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19269: }
1.240 raeburn 19270: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19271: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19272: }
1.224 raeburn 19273: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19274: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19275:
19276: my %userconfig_hash = (
19277: usercreation => \%save_usercreate,
19278: usermodification => \%save_usermodify,
1.305 raeburn 19279: inststatus => \%save_inststatus,
1.224 raeburn 19280: );
1.305 raeburn 19281:
1.224 raeburn 19282: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19283: $dom);
19284: #
1.305 raeburn 19285: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19286: #
1.27 raeburn 19287: if ($putresult eq 'ok') {
19288: if (keys(%changes) > 0) {
19289: $resulttext = &mt('Changes made:').'<ul>';
19290: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19291: my %lt = &selfcreation_types();
1.34 raeburn 19292: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19293: my $chgtext = '';
1.45 raeburn 19294: if ($type eq 'selfcreate') {
1.50 raeburn 19295: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19296: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19297: } else {
1.224 raeburn 19298: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19299: '<ul>';
1.50 raeburn 19300: foreach my $case (@{$cancreate{$type}}) {
19301: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19302: }
19303: $chgtext .= '</ul>';
1.100 raeburn 19304: if (ref($cancreate{$type}) eq 'ARRAY') {
19305: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19306: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19307: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19308: $chgtext .= '<span class="LC_warning">'.
19309: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19310: '</span><br />';
19311: }
19312: }
19313: }
19314: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19315: if (!@statuses) {
19316: $chgtext .= '<span class="LC_warning">'.
19317: &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.").
19318: '</span><br />';
1.303 raeburn 19319:
1.100 raeburn 19320: }
19321: }
19322: }
1.43 raeburn 19323: }
1.240 raeburn 19324: } elsif ($type eq 'shibenv') {
19325: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19326: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19327: } else {
19328: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19329: '<ul>';
19330: foreach my $field (@shibfields) {
19331: next if ($cancreate{$type}{$field} eq '');
19332: if ($field eq 'inststatus') {
19333: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19334: } else {
19335: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19336: }
19337: }
19338: $chgtext .= '</ul>';
1.303 raeburn 19339: }
1.93 raeburn 19340: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19341: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19342: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19343: if (@{$cancreate{'selfcreate'}} > 0) {
19344: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19345: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19346: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19347: $chgtext .= '<br />'.
19348: '<span class="LC_warning">'.
19349: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19350: '</span>';
19351: }
1.303 raeburn 19352: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19353: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19354: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19355: } else {
19356: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19357: }
19358: $chgtext .= '<ul>';
19359: foreach my $case (@{$cancreate{$type}}) {
19360: if ($case eq 'default') {
19361: $chgtext .= '<li>'.$othertitle.'</li>';
19362: } else {
1.303 raeburn 19363: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19364: }
19365: }
1.100 raeburn 19366: $chgtext .= '</ul>';
19367: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19368: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19369: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19370: '</span>';
1.100 raeburn 19371: }
19372: }
19373: } else {
19374: if (@{$cancreate{$type}} == 0) {
19375: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19376: } else {
19377: $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 19378: }
19379: }
1.303 raeburn 19380: $chgtext .= '<br />';
1.93 raeburn 19381: }
1.236 raeburn 19382: } elsif ($type eq 'selfcreateprocessing') {
19383: my %choices = &Apache::lonlocal::texthash (
19384: automatic => 'Automatic approval',
19385: approval => 'Queued for approval',
19386: );
1.305 raeburn 19387: if (@types) {
19388: if (@statuses) {
1.425 raeburn 19389: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19390: '<ul>';
1.305 raeburn 19391: foreach my $status (@statuses) {
19392: if ($status eq 'default') {
19393: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19394: } else {
1.305 raeburn 19395: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19396: }
19397: }
19398: $chgtext .= '</ul>';
19399: }
19400: } else {
19401: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19402: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19403: }
19404: } elsif ($type eq 'emailverified') {
19405: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19406: all => 'Same as e-mail',
19407: first => 'Omit @domain',
19408: free => 'Free to choose',
1.303 raeburn 19409: );
1.305 raeburn 19410: if (@types) {
19411: if (@statuses) {
1.303 raeburn 19412: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19413: '<ul>';
1.305 raeburn 19414: foreach my $status (@statuses) {
1.362 raeburn 19415: if ($status eq 'default') {
1.305 raeburn 19416: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19417: } else {
1.305 raeburn 19418: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19419: }
19420: }
19421: $chgtext .= '</ul>';
19422: }
19423: } else {
1.305 raeburn 19424: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19425: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19426: }
1.305 raeburn 19427: } elsif ($type eq 'emailoptions') {
19428: my %options = &Apache::lonlocal::texthash (
19429: any => 'Any e-mail',
19430: inst => 'Institutional only',
19431: noninst => 'Non-institutional only',
19432: custom => 'Custom restrictions',
19433: );
19434: if (@types) {
19435: if (@statuses) {
19436: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19437: '<ul>';
19438: foreach my $status (@statuses) {
19439: if ($type eq 'default') {
19440: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19441: } else {
19442: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19443: }
19444: }
1.305 raeburn 19445: $chgtext .= '</ul>';
19446: }
19447: } else {
19448: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19449: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19450: } else {
19451: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19452: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19453: }
1.305 raeburn 19454: }
19455: } elsif ($type eq 'emaildomain') {
19456: my $output;
19457: if (@statuses) {
19458: foreach my $type (@statuses) {
19459: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19460: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19461: if ($type eq 'default') {
19462: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19463: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19464: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19465: } else {
19466: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19467: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19468: }
1.303 raeburn 19469: } else {
1.305 raeburn 19470: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19471: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19472: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19473: } else {
19474: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19475: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19476: }
1.303 raeburn 19477: }
1.305 raeburn 19478: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19479: if ($type eq 'default') {
19480: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19481: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19482: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19483: } else {
19484: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19485: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19486: }
1.303 raeburn 19487: } else {
1.305 raeburn 19488: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19489: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19490: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19491: } else {
19492: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19493: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19494: }
1.303 raeburn 19495: }
19496: }
19497: }
19498: }
1.305 raeburn 19499: }
19500: if ($output ne '') {
19501: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19502: '<ul>'.$output.'</ul>';
1.236 raeburn 19503: }
1.165 raeburn 19504: } elsif ($type eq 'captcha') {
1.224 raeburn 19505: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19506: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19507: } else {
19508: my %captchas = &captcha_phrases();
1.224 raeburn 19509: if ($captchas{$savecaptcha{$type}}) {
19510: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19511: } else {
1.210 raeburn 19512: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19513: }
19514: }
19515: } elsif ($type eq 'recaptchakeys') {
19516: my ($privkey,$pubkey);
1.224 raeburn 19517: if (ref($savecaptcha{$type}) eq 'HASH') {
19518: $pubkey = $savecaptcha{$type}{'public'};
19519: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19520: }
19521: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19522: if (!$pubkey) {
19523: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19524: } else {
19525: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19526: }
19527: if (!$privkey) {
19528: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19529: } else {
19530: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19531: }
19532: $chgtext .= '</ul>';
1.269 raeburn 19533: } elsif ($type eq 'recaptchaversion') {
19534: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19535: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19536: }
1.224 raeburn 19537: } elsif ($type eq 'emailusername') {
19538: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19539: if (@statuses) {
19540: foreach my $type (@statuses) {
1.228 raeburn 19541: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19542: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19543: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19544: '<ul>';
19545: foreach my $field (@{$infofields}) {
19546: if ($cancreate{'emailusername'}{$type}{$field}) {
19547: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19548: }
19549: }
1.245 raeburn 19550: $chgtext .= '</ul>';
19551: } else {
1.303 raeburn 19552: $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 19553: }
19554: } else {
1.303 raeburn 19555: $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 19556: }
19557: }
19558: }
19559: }
19560: } elsif ($type eq 'notify') {
1.303 raeburn 19561: my $numapprove = 0;
1.224 raeburn 19562: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19563: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19564: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19565: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19566: $numapprove ++;
1.224 raeburn 19567: }
19568: }
1.43 raeburn 19569: }
1.303 raeburn 19570: unless ($numapprove) {
19571: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19572: }
1.34 raeburn 19573: }
1.224 raeburn 19574: if ($chgtext) {
19575: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19576: }
19577: }
19578: }
1.305 raeburn 19579: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19580: my ($emailrules,$emailruleorder) =
19581: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19582: foreach my $type (@{$changes{'email_rule'}}) {
19583: if (ref($email_rule{$type}) eq 'ARRAY') {
19584: my $chgtext = '<ul>';
19585: foreach my $rule (@{$email_rule{$type}}) {
19586: if (ref($emailrules->{$rule}) eq 'HASH') {
19587: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19588: }
19589: }
19590: $chgtext .= '</ul>';
1.310 raeburn 19591: my $typename;
1.305 raeburn 19592: if (@types) {
19593: if ($type eq 'default') {
19594: $typename = $othertitle;
19595: } else {
19596: $typename = $usertypes{$type};
1.425 raeburn 19597: }
1.305 raeburn 19598: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19599: }
19600: if (@{$email_rule{$type}} > 0) {
19601: $resulttext .= '<li>'.
19602: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19603: $usertypes{$type}).
19604: $chgtext.
19605: '</li>';
19606: } else {
19607: $resulttext .= '<li>'.
1.310 raeburn 19608: &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 19609: '</li>'.
1.310 raeburn 19610: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19611: }
1.43 raeburn 19612: }
19613: }
1.305 raeburn 19614: }
19615: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19616: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19617: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19618: my $chgtext = '<ul>';
19619: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19620: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19621: }
19622: $chgtext .= '</ul>';
19623: $resulttext .= '<li>'.
19624: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19625: $chgtext.
19626: '</li>';
19627: } else {
19628: $resulttext .= '<li>'.
19629: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19630: '</li>';
19631: }
1.43 raeburn 19632: }
19633: }
1.224 raeburn 19634: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19635: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19636: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19637: foreach my $type (@{$changes{'selfcreate'}}) {
19638: my $typename = $type;
1.303 raeburn 19639: if (keys(%usertypes) > 0) {
19640: if ($usertypes{$type} ne '') {
19641: $typename = $usertypes{$type};
1.224 raeburn 19642: }
19643: }
19644: my @modifiable;
19645: $resulttext .= '<li>'.
19646: &mt('Self-creation of account by users with status: [_1]',
19647: '<span class="LC_cusr_emph">'.$typename.'</span>').
19648: ' - '.&mt('modifiable fields (if institutional data blank): ');
19649: foreach my $field (@fields) {
19650: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19651: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19652: }
19653: }
1.224 raeburn 19654: if (@modifiable > 0) {
19655: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19656: } else {
1.224 raeburn 19657: $resulttext .= &mt('none');
1.43 raeburn 19658: }
1.224 raeburn 19659: $resulttext .= '</li>';
1.28 raeburn 19660: }
1.224 raeburn 19661: $resulttext .= '</ul></li>';
1.28 raeburn 19662: }
1.27 raeburn 19663: $resulttext .= '</ul>';
1.305 raeburn 19664: my $cachetime = 24*60*60;
19665: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19666: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19667: if (ref($lastactref) eq 'HASH') {
19668: $lastactref->{'domdefaults'} = 1;
19669: }
1.27 raeburn 19670: } else {
1.224 raeburn 19671: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19672: }
19673: } else {
19674: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19675: &mt('An error occurred: [_1]',$putresult).'</span>';
19676: }
1.43 raeburn 19677: if ($warningmsg ne '') {
19678: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19679: }
1.23 raeburn 19680: return $resulttext;
19681: }
19682:
1.165 raeburn 19683: sub process_captcha {
1.369 raeburn 19684: my ($container,$changes,$newsettings,$currsettings) = @_;
19685: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19686: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19687: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19688: $newsettings->{'captcha'} = 'original';
19689: }
1.369 raeburn 19690: my %current;
19691: if (ref($currsettings) eq 'HASH') {
19692: %current = %{$currsettings};
19693: }
19694: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19695: if ($container eq 'cancreate') {
1.169 raeburn 19696: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19697: push(@{$changes->{'cancreate'}},'captcha');
19698: } elsif (!defined($changes->{'cancreate'})) {
19699: $changes->{'cancreate'} = ['captcha'];
19700: }
1.368 raeburn 19701: } elsif ($container eq 'passwords') {
19702: $changes->{'reset'} = 1;
1.169 raeburn 19703: } else {
19704: $changes->{'captcha'} = 1;
1.165 raeburn 19705: }
19706: }
1.269 raeburn 19707: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19708: if ($newsettings->{'captcha'} eq 'recaptcha') {
19709: $newpub = $env{'form.'.$container.'_recaptchapub'};
19710: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19711: $newpub =~ s/[^\w\-]//g;
19712: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19713: $newsettings->{'recaptchakeys'} = {
19714: public => $newpub,
19715: private => $newpriv,
19716: };
1.269 raeburn 19717: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19718: $newversion =~ s/\D//g;
19719: if ($newversion ne '2') {
19720: $newversion = 1;
19721: }
19722: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19723: }
1.369 raeburn 19724: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19725: $currpub = $current{'recaptchakeys'}{'public'};
19726: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19727: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19728: $newsettings->{'recaptchakeys'} = {
19729: public => '',
19730: private => '',
19731: }
19732: }
1.165 raeburn 19733: }
1.369 raeburn 19734: if ($current{'captcha'} eq 'recaptcha') {
19735: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19736: if ($currversion ne '2') {
19737: $currversion = 1;
19738: }
19739: }
19740: if ($currversion ne $newversion) {
19741: if ($container eq 'cancreate') {
19742: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19743: push(@{$changes->{'cancreate'}},'recaptchaversion');
19744: } elsif (!defined($changes->{'cancreate'})) {
19745: $changes->{'cancreate'} = ['recaptchaversion'];
19746: }
1.368 raeburn 19747: } elsif ($container eq 'passwords') {
19748: $changes->{'reset'} = 1;
1.269 raeburn 19749: } else {
19750: $changes->{'recaptchaversion'} = 1;
19751: }
19752: }
1.165 raeburn 19753: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19754: if ($container eq 'cancreate') {
19755: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19756: push(@{$changes->{'cancreate'}},'recaptchakeys');
19757: } elsif (!defined($changes->{'cancreate'})) {
19758: $changes->{'cancreate'} = ['recaptchakeys'];
19759: }
1.368 raeburn 19760: } elsif ($container eq 'passwords') {
19761: $changes->{'reset'} = 1;
1.169 raeburn 19762: } else {
1.210 raeburn 19763: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19764: }
19765: }
19766: return;
19767: }
19768:
1.33 raeburn 19769: sub modify_usermodification {
19770: my ($dom,%domconfig) = @_;
1.224 raeburn 19771: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19772: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19773: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19774: if ($key eq 'selfcreate') {
19775: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19776: } else {
19777: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19778: }
1.33 raeburn 19779: }
19780: }
1.443 raeburn 19781: my @contexts = ('author','coauthor','course');
1.33 raeburn 19782: my %context_title = (
19783: author => 'In author context',
1.443 raeburn 19784: coauthor => 'As co-author manager',
1.33 raeburn 19785: course => 'In course context',
19786: );
19787: my @fields = ('lastname','firstname','middlename','generation',
19788: 'permanentemail','id');
19789: my %roles = (
19790: author => ['ca','aa'],
1.443 raeburn 19791: coauthor => ['ca','aa'],
1.33 raeburn 19792: course => ['st','ep','ta','in','cr'],
19793: );
19794: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19795: foreach my $context (@contexts) {
1.443 raeburn 19796: my $prefix = 'canmodify';
19797: if ($context eq 'coauthor') {
19798: $prefix = 'cacanmodify';
19799: }
1.33 raeburn 19800: foreach my $role (@{$roles{$context}}) {
1.443 raeburn 19801: my @modifiable = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$role);
1.33 raeburn 19802: foreach my $item (@fields) {
19803: if (grep(/^\Q$item\E$/,@modifiable)) {
19804: $modifyhash{$context}{$role}{$item} = 1;
19805: } else {
19806: $modifyhash{$context}{$role}{$item} = 0;
19807: }
19808: }
19809: }
19810: if (ref($curr_usermodification{$context}) eq 'HASH') {
19811: foreach my $role (@{$roles{$context}}) {
19812: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19813: foreach my $field (@fields) {
19814: if ($modifyhash{$context}{$role}{$field} ne
19815: $curr_usermodification{$context}{$role}{$field}) {
19816: push(@{$changes{$context}},$role);
19817: last;
19818: }
19819: }
19820: }
19821: }
19822: } else {
19823: foreach my $context (@contexts) {
19824: foreach my $role (@{$roles{$context}}) {
19825: push(@{$changes{$context}},$role);
19826: }
19827: }
19828: }
19829: }
19830: my %usermodification_hash = (
19831: usermodification => \%modifyhash,
19832: );
19833: my $putresult = &Apache::lonnet::put_dom('configuration',
19834: \%usermodification_hash,$dom);
19835: if ($putresult eq 'ok') {
19836: if (keys(%changes) > 0) {
19837: $resulttext = &mt('Changes made: ').'<ul>';
19838: foreach my $context (@contexts) {
19839: if (ref($changes{$context}) eq 'ARRAY') {
19840: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19841: if (ref($changes{$context}) eq 'ARRAY') {
19842: foreach my $role (@{$changes{$context}}) {
19843: my $rolename;
1.224 raeburn 19844: if ($role eq 'cr') {
19845: $rolename = &mt('Custom');
1.33 raeburn 19846: } else {
1.224 raeburn 19847: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19848: }
19849: my @modifiable;
1.224 raeburn 19850: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19851: foreach my $field (@fields) {
19852: if ($modifyhash{$context}{$role}{$field}) {
19853: push(@modifiable,$fieldtitles{$field});
19854: }
19855: }
19856: if (@modifiable > 0) {
19857: $resulttext .= join(', ',@modifiable);
19858: } else {
19859: $resulttext .= &mt('none');
19860: }
19861: $resulttext .= '</li>';
19862: }
19863: $resulttext .= '</ul></li>';
19864: }
19865: }
19866: }
19867: $resulttext .= '</ul>';
19868: } else {
19869: $resulttext = &mt('No changes made to user modification settings');
19870: }
19871: } else {
19872: $resulttext = '<span class="LC_error">'.
19873: &mt('An error occurred: [_1]',$putresult).'</span>';
19874: }
19875: return $resulttext;
19876: }
19877:
1.43 raeburn 19878: sub modify_defaults {
1.212 raeburn 19879: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19880: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19881: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19882: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19883: 'portal_def');
1.325 raeburn 19884: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19885: foreach my $item (@items) {
19886: $newvalues{$item} = $env{'form.'.$item};
19887: if ($item eq 'auth_def') {
19888: if ($newvalues{$item} ne '') {
19889: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19890: push(@errors,$item);
19891: }
19892: }
19893: } elsif ($item eq 'lang_def') {
19894: if ($newvalues{$item} ne '') {
19895: if ($newvalues{$item} =~ /^(\w+)/) {
19896: my $langcode = $1;
1.103 raeburn 19897: if ($langcode ne 'x_chef') {
19898: if (code2language($langcode) eq '') {
19899: push(@errors,$item);
19900: }
1.43 raeburn 19901: }
19902: } else {
19903: push(@errors,$item);
19904: }
19905: }
1.54 raeburn 19906: } elsif ($item eq 'timezone_def') {
19907: if ($newvalues{$item} ne '') {
1.62 raeburn 19908: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 19909: push(@errors,$item);
19910: }
19911: }
1.68 raeburn 19912: } elsif ($item eq 'datelocale_def') {
19913: if ($newvalues{$item} ne '') {
19914: my @datelocale_ids = DateTime::Locale->ids();
19915: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
19916: push(@errors,$item);
19917: }
19918: }
1.141 raeburn 19919: } elsif ($item eq 'portal_def') {
19920: if ($newvalues{$item} ne '') {
1.414 raeburn 19921: 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])\/?$/) {
19922: foreach my $field ('email','web') {
19923: if ($env{'form.'.$item.'_'.$field}) {
19924: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
19925: }
19926: }
19927: } else {
1.141 raeburn 19928: push(@errors,$item);
19929: }
19930: }
1.43 raeburn 19931: }
19932: if (grep(/^\Q$item\E$/,@errors)) {
19933: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 19934: if ($item eq 'portal_def') {
19935: if ($domdefaults{$item}) {
19936: foreach my $field ('email','web') {
19937: if (exists($domdefaults{$item.'_'.$field})) {
19938: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
19939: }
19940: }
19941: }
19942: }
1.43 raeburn 19943: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
19944: $changes{$item} = 1;
19945: }
1.414 raeburn 19946: if ($item eq 'portal_def') {
19947: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 19948: if ($newvalues{$item} eq '') {
1.414 raeburn 19949: foreach my $field ('email','web') {
19950: if (exists($domdefaults{$item.'_'.$field})) {
19951: delete($domdefaults{$item.'_'.$field});
19952: }
19953: }
19954: } else {
19955: unless ($changes{$item}) {
19956: foreach my $field ('email','web') {
19957: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
19958: $changes{$item} = 1;
19959: last;
19960: }
19961: }
19962: }
19963: foreach my $field ('email','web') {
19964: if ($newvalues{$item.'_'.$field}) {
19965: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
19966: } elsif (exists($domdefaults{$item.'_'.$field})) {
19967: delete($domdefaults{$item.'_'.$field});
19968: }
19969: }
19970: }
19971: }
19972: }
1.72 raeburn 19973: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 19974: }
1.354 raeburn 19975: my %staticdefaults = (
19976: 'intauth_cost' => 10,
19977: 'intauth_check' => 0,
19978: 'intauth_switch' => 0,
19979: );
19980: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
19981: if (exists($domdefaults{$item})) {
19982: $newvalues{$item} = $domdefaults{$item};
19983: } else {
19984: $newvalues{$item} = $staticdefaults{$item};
19985: }
19986: }
1.409 raeburn 19987: my ($unamemaprules,$ruleorder);
19988: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
19989: if (@possunamemaprules) {
19990: ($unamemaprules,$ruleorder) =
19991: &Apache::lonnet::inst_userrules($dom,'unamemap');
19992: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
19993: if (@{$ruleorder} > 0) {
19994: my %possrules;
19995: map { $possrules{$_} = 1; } @possunamemaprules;
19996: foreach my $rule (@{$ruleorder}) {
19997: if ($possrules{$rule}) {
19998: push(@{$newvalues{'unamemap_rule'}},$rule);
19999: }
20000: }
20001: }
20002: }
20003: }
20004: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
20005: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20006: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
20007: $newvalues{'unamemap_rule'});
20008: if (@rulediffs) {
20009: $changes{'unamemap_rule'} = 1;
20010: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20011: }
20012: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
20013: $changes{'unamemap_rule'} = 1;
20014: delete($domdefaults{'unamemap_rule'});
20015: }
20016: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20017: if (@{$newvalues{'unamemap_rule'}} > 0) {
20018: $changes{'unamemap_rule'} = 1;
20019: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20020: }
20021: }
1.43 raeburn 20022: my %defaults_hash = (
1.72 raeburn 20023: defaults => \%newvalues,
20024: );
1.43 raeburn 20025: my $title = &defaults_titles();
1.236 raeburn 20026:
20027: my $currinststatus;
20028: if (ref($domconfig{'inststatus'}) eq 'HASH') {
20029: $currinststatus = $domconfig{'inststatus'};
20030: } else {
20031: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
20032: $currinststatus = {
20033: inststatustypes => $usertypes,
20034: inststatusorder => $types,
20035: inststatusguest => [],
20036: };
20037: }
20038: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20039: my @allpos;
20040: my %alltypes;
1.305 raeburn 20041: my @inststatusguest;
20042: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20043: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20044: unless (grep(/^\Q$type\E$/,@todelete)) {
20045: push(@inststatusguest,$type);
20046: }
20047: }
20048: }
20049: my ($currtitles,$currorder);
1.236 raeburn 20050: if (ref($currinststatus) eq 'HASH') {
20051: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20052: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20053: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20054: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20055: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20056: }
20057: }
20058: unless (grep(/^\Q$type\E$/,@todelete)) {
20059: my $position = $env{'form.inststatus_pos_'.$type};
20060: $position =~ s/\D+//g;
20061: $allpos[$position] = $type;
20062: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20063: $alltypes{$type} =~ s/`//g;
20064: }
20065: }
20066: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20067: $currtitles =~ s/,$//;
20068: }
20069: }
20070: if ($env{'form.addinststatus'}) {
20071: my $newtype = $env{'form.addinststatus'};
20072: $newtype =~ s/\W//g;
20073: unless (exists($alltypes{$newtype})) {
20074: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20075: $alltypes{$newtype} =~ s/`//g;
20076: my $position = $env{'form.addinststatus_pos'};
20077: $position =~ s/\D+//g;
20078: if ($position ne '') {
20079: $allpos[$position] = $newtype;
20080: }
20081: }
20082: }
1.305 raeburn 20083: my @orderedstatus;
1.236 raeburn 20084: foreach my $type (@allpos) {
20085: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20086: push(@orderedstatus,$type);
20087: }
20088: }
20089: foreach my $type (keys(%alltypes)) {
20090: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20091: delete($alltypes{$type});
20092: }
20093: }
20094: $defaults_hash{'inststatus'} = {
20095: inststatustypes => \%alltypes,
20096: inststatusorder => \@orderedstatus,
1.305 raeburn 20097: inststatusguest => \@inststatusguest,
1.236 raeburn 20098: };
20099: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20100: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20101: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20102: }
20103: }
20104: if ($currorder ne join(',',@orderedstatus)) {
20105: $changes{'inststatus'}{'inststatusorder'} = 1;
20106: }
20107: my $newtitles;
20108: foreach my $item (@orderedstatus) {
20109: $newtitles .= $alltypes{$item}.',';
20110: }
20111: $newtitles =~ s/,$//;
20112: if ($currtitles ne $newtitles) {
20113: $changes{'inststatus'}{'inststatustypes'} = 1;
20114: }
1.43 raeburn 20115: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20116: $dom);
20117: if ($putresult eq 'ok') {
20118: if (keys(%changes) > 0) {
20119: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20120: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20121: 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";
20122: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20123: if ($item eq 'inststatus') {
20124: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20125: if (@orderedstatus) {
1.236 raeburn 20126: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20127: foreach my $type (@orderedstatus) {
20128: $resulttext .= $alltypes{$type}.', ';
20129: }
20130: $resulttext =~ s/, $//;
20131: $resulttext .= '</li>';
1.305 raeburn 20132: } else {
1.425 raeburn 20133: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20134: }
20135: }
1.409 raeburn 20136: } elsif ($item eq 'unamemap_rule') {
20137: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20138: my @rulenames;
20139: if (ref($unamemaprules) eq 'HASH') {
20140: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20141: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20142: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20143: }
20144: }
20145: }
20146: if (@rulenames) {
20147: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20148: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20149: '</li>';
20150: } else {
20151: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20152: }
20153: } else {
20154: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20155: }
1.236 raeburn 20156: } else {
20157: my $value = $env{'form.'.$item};
20158: if ($value eq '') {
20159: $value = &mt('none');
20160: } elsif ($item eq 'auth_def') {
20161: my %authnames = &authtype_names();
20162: my %shortauth = (
20163: internal => 'int',
20164: krb4 => 'krb4',
20165: krb5 => 'krb5',
20166: localauth => 'loc',
1.325 raeburn 20167: lti => 'lti',
1.236 raeburn 20168: );
20169: $value = $authnames{$shortauth{$value}};
20170: }
20171: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20172: $mailmsgtext .= "$title->{$item} set to $value\n";
20173: if ($item eq 'portal_def') {
20174: if ($env{'form.'.$item} ne '') {
20175: foreach my $field ('email','web') {
20176: $value = $env{'form.'.$item.'_'.$field};
20177: if ($value) {
20178: $value = &mt('Yes');
20179: } else {
20180: $value = &mt('No');
20181: }
20182: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20183: }
20184: }
20185: }
1.43 raeburn 20186: }
20187: }
20188: $resulttext .= '</ul>';
20189: $mailmsgtext .= "\n";
20190: my $cachetime = 24*60*60;
1.72 raeburn 20191: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20192: if (ref($lastactref) eq 'HASH') {
20193: $lastactref->{'domdefaults'} = 1;
20194: }
1.68 raeburn 20195: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20196: my $notify = 1;
20197: if (ref($domconfig{'contacts'}) eq 'HASH') {
20198: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20199: $notify = 0;
20200: }
20201: }
20202: if ($notify) {
20203: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20204: "LON-CAPA Domain Settings Change - $dom",
20205: $mailmsgtext);
20206: }
1.54 raeburn 20207: }
1.43 raeburn 20208: } else {
1.54 raeburn 20209: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20210: }
20211: } else {
20212: $resulttext = '<span class="LC_error">'.
20213: &mt('An error occurred: [_1]',$putresult).'</span>';
20214: }
20215: if (@errors > 0) {
20216: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20217: foreach my $item (@errors) {
20218: $resulttext .= ' "'.$title->{$item}.'",';
20219: }
20220: $resulttext =~ s/,$//;
20221: }
20222: return $resulttext;
20223: }
20224:
1.46 raeburn 20225: sub modify_scantron {
1.205 raeburn 20226: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20227: my ($resulttext,%confhash,%changes,$errors);
20228: my $custom = 'custom.tab';
20229: my $default = 'default.tab';
20230: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20231: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20232: &config_check($dom,$confname,$servadm);
20233: if ($env{'form.scantronformat.filename'} ne '') {
20234: my $error;
20235: if ($configuserok eq 'ok') {
20236: if ($switchserver) {
1.130 raeburn 20237: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20238: } else {
20239: if ($author_ok eq 'ok') {
1.421 raeburn 20240: my $modified = [];
1.46 raeburn 20241: my ($result,$scantronurl) =
1.421 raeburn 20242: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20243: $confname,'scantron','','',$custom,
20244: $modified);
1.46 raeburn 20245: if ($result eq 'ok') {
20246: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20247: $changes{'scantronformat'} = 1;
1.421 raeburn 20248: &update_modify_urls($r,$modified);
1.46 raeburn 20249: } else {
20250: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20251: }
20252: } else {
20253: $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);
20254: }
20255: }
20256: } else {
20257: $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);
20258: }
20259: if ($error) {
20260: &Apache::lonnet::logthis($error);
20261: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20262: }
20263: }
1.48 raeburn 20264: if (ref($domconfig{'scantron'}) eq 'HASH') {
20265: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20266: if ($env{'form.scantronformat_del'}) {
20267: $confhash{'scantron'}{'scantronformat'} = '';
20268: $changes{'scantronformat'} = 1;
1.347 raeburn 20269: } else {
20270: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20271: }
20272: }
20273: }
1.347 raeburn 20274: my @options = ('hdr','pad','rem');
1.346 raeburn 20275: my @fields = &scantroncsv_fields();
20276: my %titles = &scantronconfig_titles();
1.347 raeburn 20277: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20278: my ($newdat,$currdat,%newcol,%currcol);
20279: if (grep(/^dat$/,@formats)) {
20280: $confhash{'scantron'}{config}{dat} = 1;
20281: $newdat = 1;
20282: } else {
20283: $newdat = 0;
20284: }
20285: if (grep(/^csv$/,@formats)) {
20286: my %bynum;
20287: foreach my $field (@fields) {
20288: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20289: my $posscol = $1;
20290: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20291: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20292: $bynum{$posscol} = $field;
20293: $newcol{$field} = $posscol;
20294: }
20295: }
20296: }
1.347 raeburn 20297: if (keys(%newcol)) {
20298: foreach my $option (@options) {
20299: if ($env{'form.scantroncsv_'.$option}) {
20300: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20301: }
20302: }
20303: }
1.346 raeburn 20304: }
20305: $currdat = 1;
20306: if (ref($domconfig{'scantron'}) eq 'HASH') {
20307: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20308: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20309: $currdat = 0;
20310: }
20311: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20312: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20313: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20314: }
1.346 raeburn 20315: }
20316: }
20317: }
20318: if ($currdat != $newdat) {
20319: $changes{'config'} = 1;
20320: } else {
20321: foreach my $field (@fields) {
20322: if ($currcol{$field} ne '') {
20323: if ($currcol{$field} ne $newcol{$field}) {
20324: $changes{'config'} = 1;
20325: last;
1.347 raeburn 20326: }
1.346 raeburn 20327: } elsif ($newcol{$field} ne '') {
20328: $changes{'config'} = 1;
20329: last;
20330: }
20331: }
20332: }
1.46 raeburn 20333: if (keys(%confhash) > 0) {
20334: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20335: $dom);
20336: if ($putresult eq 'ok') {
20337: if (keys(%changes) > 0) {
1.48 raeburn 20338: if (ref($confhash{'scantron'}) eq 'HASH') {
20339: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20340: if ($changes{'scantronformat'}) {
20341: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20342: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20343: } else {
20344: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20345: }
20346: }
1.347 raeburn 20347: if ($changes{'config'}) {
1.346 raeburn 20348: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20349: if ($confhash{'scantron'}{'config'}{'dat'}) {
20350: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20351: }
20352: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20353: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20354: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20355: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20356: foreach my $field (@fields) {
20357: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20358: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20359: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20360: }
20361: }
20362: $resulttext .= '</ul></li>';
20363: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20364: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20365: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20366: foreach my $option (@options) {
20367: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20368: $resulttext .= '<li>'.$titles{$option}.'</li>';
20369: }
20370: }
20371: $resulttext .= '</ul></li>';
20372: }
1.346 raeburn 20373: }
20374: }
20375: }
20376: }
20377: } else {
20378: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20379: }
1.46 raeburn 20380: }
1.48 raeburn 20381: $resulttext .= '</ul>';
20382: } else {
1.130 raeburn 20383: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20384: }
20385: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20386: if (ref($lastactref) eq 'HASH') {
20387: $lastactref->{'domainconfig'} = 1;
20388: }
1.46 raeburn 20389: } else {
1.346 raeburn 20390: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20391: }
20392: } else {
20393: $resulttext = '<span class="LC_error">'.
20394: &mt('An error occurred: [_1]',$putresult).'</span>';
20395: }
20396: } else {
1.130 raeburn 20397: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20398: }
20399: if ($errors) {
1.353 raeburn 20400: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20401: $errors.'</ul></p>';
1.46 raeburn 20402: }
20403: return $resulttext;
20404: }
20405:
1.48 raeburn 20406: sub modify_coursecategories {
1.239 raeburn 20407: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20408: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20409: $cathash);
1.48 raeburn 20410: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20411: my @catitems = ('unauth','auth');
20412: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20413: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20414: $cathash = $domconfig{'coursecategories'}{'cats'};
20415: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20416: $changes{'togglecats'} = 1;
20417: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20418: }
20419: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20420: $changes{'categorize'} = 1;
20421: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20422: }
1.120 raeburn 20423: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20424: $changes{'togglecatscomm'} = 1;
20425: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20426: }
20427: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20428: $changes{'categorizecomm'} = 1;
20429: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20430:
20431: }
20432: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20433: $changes{'togglecatsplace'} = 1;
20434: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20435: }
20436: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20437: $changes{'categorizeplace'} = 1;
20438: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20439: }
1.238 raeburn 20440: foreach my $item (@catitems) {
20441: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20442: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20443: $changes{$item} = 1;
20444: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20445: }
20446: }
20447: }
1.57 raeburn 20448: } else {
20449: $changes{'togglecats'} = 1;
20450: $changes{'categorize'} = 1;
1.124 raeburn 20451: $changes{'togglecatscomm'} = 1;
20452: $changes{'categorizecomm'} = 1;
1.272 raeburn 20453: $changes{'togglecatsplace'} = 1;
20454: $changes{'categorizeplace'} = 1;
1.87 raeburn 20455: $domconfig{'coursecategories'} = {
20456: togglecats => $env{'form.togglecats'},
20457: categorize => $env{'form.categorize'},
1.124 raeburn 20458: togglecatscomm => $env{'form.togglecatscomm'},
20459: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20460: togglecatsplace => $env{'form.togglecatsplace'},
20461: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20462: };
1.238 raeburn 20463: foreach my $item (@catitems) {
20464: if ($env{'form.coursecat_'.$item} ne 'std') {
20465: $changes{$item} = 1;
20466: }
20467: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20468: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20469: }
20470: }
1.57 raeburn 20471: }
20472: if (ref($cathash) eq 'HASH') {
20473: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20474: push (@deletecategory,'instcode::0');
20475: }
1.120 raeburn 20476: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20477: push(@deletecategory,'communities::0');
20478: }
1.272 raeburn 20479: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20480: push(@deletecategory,'placement::0');
20481: }
1.48 raeburn 20482: }
1.57 raeburn 20483: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20484: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20485: if (@deletecategory > 0) {
20486: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20487: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20488: foreach my $item (@deletecategory) {
1.57 raeburn 20489: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20490: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20491: $deletions{$item} = 1;
1.57 raeburn 20492: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20493: }
20494: }
20495: }
1.57 raeburn 20496: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20497: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20498: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20499: $reorderings{$item} = 1;
1.57 raeburn 20500: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20501: }
20502: if ($env{'form.addcategory_name_'.$item} ne '') {
20503: my $newcat = $env{'form.addcategory_name_'.$item};
20504: my $newdepth = $depth+1;
20505: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20506: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20507: $adds{$newitem} = 1;
20508: }
20509: if ($env{'form.subcat_'.$item} ne '') {
20510: my $newcat = $env{'form.subcat_'.$item};
20511: my $newdepth = $depth+1;
20512: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20513: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20514: $adds{$newitem} = 1;
20515: }
20516: }
20517: }
20518: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20519: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20520: my $newitem = 'instcode::0';
1.57 raeburn 20521: if ($cathash->{$newitem} eq '') {
20522: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20523: $adds{$newitem} = 1;
20524: }
20525: } else {
20526: my $newitem = 'instcode::0';
1.57 raeburn 20527: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20528: $adds{$newitem} = 1;
20529: }
20530: }
1.120 raeburn 20531: if ($env{'form.communities'} eq '1') {
20532: if (ref($cathash) eq 'HASH') {
20533: my $newitem = 'communities::0';
20534: if ($cathash->{$newitem} eq '') {
20535: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20536: $adds{$newitem} = 1;
20537: }
20538: } else {
20539: my $newitem = 'communities::0';
20540: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20541: $adds{$newitem} = 1;
20542: }
20543: }
1.272 raeburn 20544: if ($env{'form.placement'} eq '1') {
20545: if (ref($cathash) eq 'HASH') {
20546: my $newitem = 'placement::0';
20547: if ($cathash->{$newitem} eq '') {
20548: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20549: $adds{$newitem} = 1;
20550: }
20551: } else {
20552: my $newitem = 'placement::0';
20553: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20554: $adds{$newitem} = 1;
20555: }
20556: }
1.48 raeburn 20557: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20558: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20559: ($env{'form.addcategory_name'} ne 'communities') &&
20560: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20561: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20562: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20563: $adds{$newitem} = 1;
20564: }
1.48 raeburn 20565: }
1.57 raeburn 20566: my $putresult;
1.48 raeburn 20567: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20568: if (keys(%deletions) > 0) {
20569: foreach my $key (keys(%deletions)) {
20570: if ($predelallitems{$key} ne '') {
20571: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20572: }
20573: }
20574: }
20575: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20576: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20577: if (ref($chkcats[0]) eq 'ARRAY') {
20578: my $depth = 0;
20579: my $chg = 0;
20580: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20581: my $name = $chkcats[0][$i];
20582: my $item;
20583: if ($name eq '') {
20584: $chg ++;
20585: } else {
20586: $item = &escape($name).'::0';
20587: if ($chg) {
1.57 raeburn 20588: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20589: }
20590: $depth ++;
1.57 raeburn 20591: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20592: $depth --;
20593: }
20594: }
20595: }
1.57 raeburn 20596: }
20597: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20598: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20599: if ($putresult eq 'ok') {
1.57 raeburn 20600: my %title = (
1.120 raeburn 20601: togglecats => 'Show/Hide a course in catalog',
20602: categorize => 'Assign a category to a course',
20603: togglecatscomm => 'Show/Hide a community in catalog',
20604: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20605: );
20606: my %level = (
1.120 raeburn 20607: dom => 'set in Domain ("Modify Course/Community")',
20608: crs => 'set in Course ("Course Configuration")',
20609: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20610: none => 'No catalog',
20611: std => 'Standard catalog',
20612: domonly => 'Domain-only catalog',
20613: codesrch => 'Code search form',
1.57 raeburn 20614: );
1.48 raeburn 20615: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20616: if ($changes{'togglecats'}) {
20617: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20618: }
20619: if ($changes{'categorize'}) {
20620: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20621: }
1.120 raeburn 20622: if ($changes{'togglecatscomm'}) {
20623: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20624: }
20625: if ($changes{'categorizecomm'}) {
20626: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20627: }
1.238 raeburn 20628: if ($changes{'unauth'}) {
20629: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20630: }
20631: if ($changes{'auth'}) {
20632: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20633: }
1.57 raeburn 20634: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20635: my $cathash;
20636: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20637: $cathash = $domconfig{'coursecategories'}{'cats'};
20638: } else {
20639: $cathash = {};
20640: }
20641: my (@cats,@trails,%allitems);
20642: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20643: if (keys(%deletions) > 0) {
20644: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20645: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20646: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20647: }
20648: $resulttext .= '</ul></li>';
20649: }
20650: if (keys(%reorderings) > 0) {
20651: my %sort_by_trail;
20652: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20653: foreach my $key (keys(%reorderings)) {
20654: if ($allitems{$key} ne '') {
20655: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20656: }
1.48 raeburn 20657: }
1.57 raeburn 20658: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20659: $resulttext .= '<li>'.$trails[$trail].'</li>';
20660: }
20661: $resulttext .= '</ul></li>';
1.48 raeburn 20662: }
1.57 raeburn 20663: if (keys(%adds) > 0) {
20664: my %sort_by_trail;
20665: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20666: foreach my $key (keys(%adds)) {
20667: if ($allitems{$key} ne '') {
20668: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20669: }
20670: }
20671: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20672: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20673: }
1.57 raeburn 20674: $resulttext .= '</ul></li>';
1.48 raeburn 20675: }
1.364 raeburn 20676: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20677: if (ref($lastactref) eq 'HASH') {
20678: $lastactref->{'cats'} = 1;
20679: }
1.48 raeburn 20680: }
20681: $resulttext .= '</ul>';
1.239 raeburn 20682: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20683: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20684: if ($changes{'auth'}) {
20685: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20686: }
20687: if ($changes{'unauth'}) {
20688: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20689: }
20690: my $cachetime = 24*60*60;
20691: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20692: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20693: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20694: }
20695: }
1.48 raeburn 20696: } else {
20697: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20698: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20699: }
20700: } else {
1.120 raeburn 20701: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20702: }
20703: return $resulttext;
20704: }
20705:
1.69 raeburn 20706: sub modify_serverstatuses {
20707: my ($dom,%domconfig) = @_;
20708: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20709: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20710: %currserverstatus = %{$domconfig{'serverstatuses'}};
20711: }
20712: my @pages = &serverstatus_pages();
20713: foreach my $type (@pages) {
20714: $newserverstatus{$type}{'namedusers'} = '';
20715: $newserverstatus{$type}{'machines'} = '';
20716: if (defined($env{'form.'.$type.'_namedusers'})) {
20717: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20718: my @okusers;
20719: foreach my $user (@users) {
20720: my ($uname,$udom) = split(/:/,$user);
20721: if (($udom =~ /^$match_domain$/) &&
20722: (&Apache::lonnet::domain($udom)) &&
20723: ($uname =~ /^$match_username$/)) {
20724: if (!grep(/^\Q$user\E/,@okusers)) {
20725: push(@okusers,$user);
20726: }
20727: }
20728: }
20729: if (@okusers > 0) {
20730: @okusers = sort(@okusers);
20731: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20732: }
20733: }
20734: if (defined($env{'form.'.$type.'_machines'})) {
20735: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20736: my @okmachines;
20737: foreach my $ip (@machines) {
20738: my @parts = split(/\./,$ip);
20739: next if (@parts < 4);
20740: my $badip = 0;
20741: for (my $i=0; $i<4; $i++) {
20742: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20743: $badip = 1;
20744: last;
20745: }
20746: }
20747: if (!$badip) {
20748: push(@okmachines,$ip);
20749: }
20750: }
20751: @okmachines = sort(@okmachines);
20752: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20753: }
20754: }
20755: my %serverstatushash = (
20756: serverstatuses => \%newserverstatus,
20757: );
20758: foreach my $type (@pages) {
1.83 raeburn 20759: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20760: my (@current,@new);
1.83 raeburn 20761: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20762: if ($currserverstatus{$type}{$setting} ne '') {
20763: @current = split(/,/,$currserverstatus{$type}{$setting});
20764: }
20765: }
20766: if ($newserverstatus{$type}{$setting} ne '') {
20767: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20768: }
20769: if (@current > 0) {
20770: if (@new > 0) {
20771: foreach my $item (@current) {
20772: if (!grep(/^\Q$item\E$/,@new)) {
20773: $changes{$type}{$setting} = 1;
1.82 raeburn 20774: last;
20775: }
20776: }
1.84 raeburn 20777: foreach my $item (@new) {
20778: if (!grep(/^\Q$item\E$/,@current)) {
20779: $changes{$type}{$setting} = 1;
20780: last;
1.82 raeburn 20781: }
20782: }
20783: } else {
1.83 raeburn 20784: $changes{$type}{$setting} = 1;
1.69 raeburn 20785: }
1.83 raeburn 20786: } elsif (@new > 0) {
20787: $changes{$type}{$setting} = 1;
1.69 raeburn 20788: }
20789: }
20790: }
20791: if (keys(%changes) > 0) {
1.81 raeburn 20792: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20793: my $putresult = &Apache::lonnet::put_dom('configuration',
20794: \%serverstatushash,$dom);
20795: if ($putresult eq 'ok') {
20796: $resulttext .= &mt('Changes made:').'<ul>';
20797: foreach my $type (@pages) {
1.84 raeburn 20798: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20799: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20800: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20801: if ($newserverstatus{$type}{'namedusers'} eq '') {
20802: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20803: } else {
20804: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20805: }
1.84 raeburn 20806: }
20807: if ($changes{$type}{'machines'}) {
1.69 raeburn 20808: if ($newserverstatus{$type}{'machines'} eq '') {
20809: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20810: } else {
20811: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20812: }
20813:
20814: }
20815: $resulttext .= '</ul></li>';
20816: }
20817: }
20818: $resulttext .= '</ul>';
20819: } else {
20820: $resulttext = '<span class="LC_error">'.
20821: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20822:
20823: }
20824: } else {
20825: $resulttext = &mt('No changes made to access to server status pages');
20826: }
20827: return $resulttext;
20828: }
20829:
1.118 jms 20830: sub modify_helpsettings {
1.285 raeburn 20831: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20832: my ($resulttext,$errors,%changes,%helphash);
20833: my %defaultchecked = ('submitbugs' => 'on');
20834: my @offon = ('off','on');
1.118 jms 20835: my @toggles = ('submitbugs');
1.285 raeburn 20836: my %current = ('submitbugs' => '',
20837: 'adhoc' => {},
20838: );
1.118 jms 20839: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20840: %current = %{$domconfig{'helpsettings'}};
20841: }
1.285 raeburn 20842: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20843: foreach my $item (@toggles) {
20844: if ($defaultchecked{$item} eq 'on') {
20845: if ($current{$item} eq '') {
20846: if ($env{'form.'.$item} eq '0') {
20847: $changes{$item} = 1;
20848: }
20849: } elsif ($current{$item} ne $env{'form.'.$item}) {
20850: $changes{$item} = 1;
20851: }
20852: } elsif ($defaultchecked{$item} eq 'off') {
20853: if ($current{$item} eq '') {
20854: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20855: $changes{$item} = 1;
20856: }
1.282 raeburn 20857: } elsif ($current{$item} ne $env{'form.'.$item}) {
20858: $changes{$item} = 1;
20859: }
20860: }
20861: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20862: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20863: }
20864: }
1.285 raeburn 20865: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20866: my $confname = $dom.'-domainconfig';
20867: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20868: my (@allpos,%newsettings,%changedprivs,$newrole);
20869: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20870: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20871: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20872: my %lt = &Apache::lonlocal::texthash(
20873: s => 'system',
20874: d => 'domain',
20875: order => 'Display order',
20876: access => 'Role usage',
1.291 raeburn 20877: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20878: dh => 'All with domain helpdesk role',
20879: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20880: none => 'None',
20881: status => 'Determined based on institutional status',
20882: inc => 'Include all, but exclude specific personnel',
20883: exc => 'Exclude all, but include specific personnel',
20884: );
20885: for (my $num=0; $num<=$maxnum; $num++) {
20886: my ($prefix,$identifier,$rolename,%curr);
20887: if ($num == $maxnum) {
20888: next unless ($env{'form.newcusthelp'} == $maxnum);
20889: $identifier = 'custhelp'.$num;
20890: $prefix = 'helproles_'.$num;
20891: $rolename = $env{'form.custhelpname'.$num};
20892: $rolename=~s/[^A-Za-z0-9]//gs;
20893: next if ($rolename eq '');
20894: next if (exists($existing{'rolesdef_'.$rolename}));
20895: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20896: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20897: $newprivs{'c'},$confname,$dom);
20898: if ($result ne 'ok') {
20899: $errors .= '<li><span class="LC_error">'.
20900: &mt('An error occurred storing the new custom role: [_1]',
20901: $result).'</span></li>';
20902: next;
20903: } else {
20904: $changedprivs{$rolename} = \%newprivs;
20905: $newrole = $rolename;
20906: }
20907: } else {
20908: $prefix = 'helproles_'.$num;
20909: $rolename = $env{'form.'.$prefix};
20910: next if ($rolename eq '');
20911: next unless (exists($existing{'rolesdef_'.$rolename}));
20912: $identifier = 'custhelp'.$num;
20913: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20914: my %currprivs;
1.289 raeburn 20915: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 20916: split(/\_/,$existing{'rolesdef_'.$rolename});
20917: foreach my $level ('c','d','s') {
20918: if ($newprivs{$level} ne $currprivs{$level}) {
20919: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20920: $newprivs{'c'},$confname,$dom);
20921: if ($result ne 'ok') {
20922: $errors .= '<li><span class="LC_error">'.
20923: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
20924: $rolename,$result).'</span></li>';
20925: } else {
20926: $changedprivs{$rolename} = \%newprivs;
20927: }
20928: last;
20929: }
20930: }
20931: if (ref($current{'adhoc'}) eq 'HASH') {
20932: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20933: %curr = %{$current{'adhoc'}{$rolename}};
20934: }
20935: }
20936: }
20937: my $newpos = $env{'form.'.$prefix.'_pos'};
20938: $newpos =~ s/\D+//g;
20939: $allpos[$newpos] = $rolename;
20940: my $newdesc = $env{'form.'.$prefix.'_desc'};
20941: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
20942: if ($curr{'desc'}) {
20943: if ($curr{'desc'} ne $newdesc) {
20944: $changes{'customrole'}{$rolename}{'desc'} = 1;
20945: $newsettings{$rolename}{'desc'} = $newdesc;
20946: }
20947: } elsif ($newdesc ne '') {
20948: $changes{'customrole'}{$rolename}{'desc'} = 1;
20949: $newsettings{$rolename}{'desc'} = $newdesc;
20950: }
20951: my $access = $env{'form.'.$prefix.'_access'};
20952: if (grep(/^\Q$access\E$/,@accesstypes)) {
20953: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
20954: if ($access eq 'status') {
20955: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
20956: if (scalar(@statuses) == 0) {
1.289 raeburn 20957: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 20958: } else {
20959: my (@shownstatus,$numtypes);
20960: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20961: if (ref($types) eq 'ARRAY') {
20962: $numtypes = scalar(@{$types});
20963: foreach my $type (sort(@statuses)) {
20964: if ($type eq 'default') {
20965: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20966: } elsif (grep(/^\Q$type\E$/,@{$types})) {
20967: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20968: push(@shownstatus,$usertypes->{$type});
20969: }
20970: }
20971: }
20972: if (grep(/^default$/,@statuses)) {
20973: push(@shownstatus,$othertitle);
20974: }
20975: if (scalar(@shownstatus) == 1+$numtypes) {
20976: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
20977: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
20978: } else {
20979: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
20980: if (ref($curr{'status'}) eq 'ARRAY') {
20981: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20982: if (@diffs) {
20983: $changes{'customrole'}{$rolename}{$access} = 1;
20984: }
20985: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20986: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 20987: }
1.166 raeburn 20988: }
20989: }
1.285 raeburn 20990: } elsif (($access eq 'inc') || ($access eq 'exc')) {
20991: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
20992: my @newspecstaff;
20993: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20994: foreach my $person (sort(@personnel)) {
20995: if ($domhelpdesk{$person}) {
20996: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
20997: }
20998: }
20999: if (ref($curr{$access}) eq 'ARRAY') {
21000: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21001: if (@diffs) {
21002: $changes{'customrole'}{$rolename}{$access} = 1;
21003: }
21004: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21005: $changes{'customrole'}{$rolename}{$access} = 1;
21006: }
21007: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21008: my ($uname,$udom) = split(/:/,$person);
21009: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
21010: }
21011: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 21012: }
1.285 raeburn 21013: } else {
21014: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
21015: }
21016: unless ($curr{'access'} eq $access) {
21017: $changes{'customrole'}{$rolename}{'access'} = 1;
21018: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 21019: }
21020: }
1.285 raeburn 21021: if (@allpos > 0) {
21022: my $idx = 0;
21023: foreach my $rolename (@allpos) {
21024: if ($rolename ne '') {
21025: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
21026: if (ref($current{'adhoc'}) eq 'HASH') {
21027: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21028: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
21029: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 21030: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 21031: }
21032: }
1.282 raeburn 21033: }
1.285 raeburn 21034: $idx ++;
1.166 raeburn 21035: }
21036: }
1.118 jms 21037: }
1.123 jms 21038: my $putresult;
21039: if (keys(%changes) > 0) {
1.166 raeburn 21040: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21041: if ($putresult eq 'ok') {
1.285 raeburn 21042: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21043: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21044: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21045: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21046: }
21047: }
21048: my $cachetime = 24*60*60;
21049: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21050: if (ref($lastactref) eq 'HASH') {
21051: $lastactref->{'domdefaults'} = 1;
21052: }
21053: } else {
21054: $errors .= '<li><span class="LC_error">'.
21055: &mt('An error occurred storing the settings: [_1]',
21056: $putresult).'</span></li>';
21057: }
21058: }
21059: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21060: $resulttext = &mt('Changes made:').'<ul>';
21061: my (%shownprivs,@levelorder);
21062: @levelorder = ('c','d','s');
21063: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21064: foreach my $item (sort(keys(%changes))) {
21065: if ($item eq 'submitbugs') {
21066: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21067: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21068: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21069: } elsif ($item eq 'customrole') {
21070: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21071: my @keyorder = ('order','desc','access','status','exc','inc');
21072: my %keytext = &Apache::lonlocal::texthash(
21073: order => 'Order',
21074: desc => 'Role description',
21075: access => 'Role usage',
1.300 droeschl 21076: status => 'Allowed institutional types',
1.285 raeburn 21077: exc => 'Allowed personnel',
21078: inc => 'Disallowed personnel',
21079: );
1.282 raeburn 21080: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21081: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21082: if ($role eq $newrole) {
21083: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21084: $role).'<ul>';
21085: } else {
21086: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21087: $role).'<ul>';
21088: }
21089: foreach my $key (@keyorder) {
21090: if ($changes{'customrole'}{$role}{$key}) {
21091: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21092: $keytext{$key},$newsettings{$role}{$key}).
21093: '</li>';
21094: }
21095: }
21096: if (ref($changedprivs{$role}) eq 'HASH') {
21097: $shownprivs{$role} = 1;
21098: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21099: foreach my $level (@levelorder) {
21100: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21101: next if ($item eq '');
21102: my ($priv) = split(/\&/,$item,2);
21103: if (&Apache::lonnet::plaintext($priv)) {
21104: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21105: unless ($level eq 'c') {
21106: $resulttext .= ' ('.$lt{$level}.')';
21107: }
21108: $resulttext .= '</li>';
21109: }
21110: }
21111: }
21112: $resulttext .= '</ul>';
21113: }
21114: $resulttext .= '</ul></li>';
21115: }
21116: }
21117: }
21118: }
21119: }
21120: }
21121: if (keys(%changedprivs)) {
21122: foreach my $role (sort(keys(%changedprivs))) {
21123: unless ($shownprivs{$role}) {
21124: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21125: $role).'<ul>'.
21126: '<li>'.&mt('Privileges set to :').'<ul>';
21127: foreach my $level (@levelorder) {
21128: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21129: next if ($item eq '');
21130: my ($priv) = split(/\&/,$item,2);
21131: if (&Apache::lonnet::plaintext($priv)) {
21132: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21133: unless ($level eq 'c') {
21134: $resulttext .= ' ('.$lt{$level}.')';
21135: }
21136: $resulttext .= '</li>';
21137: }
1.282 raeburn 21138: }
21139: }
1.285 raeburn 21140: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21141: }
21142: }
21143: }
1.285 raeburn 21144: $resulttext .= '</ul>';
21145: } else {
21146: $resulttext = &mt('No changes made to help settings');
1.118 jms 21147: }
21148: if ($errors) {
1.168 raeburn 21149: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21150: $errors.'</ul>';
1.118 jms 21151: }
21152: return $resulttext;
21153: }
21154:
1.121 raeburn 21155: sub modify_coursedefaults {
1.212 raeburn 21156: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21157: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21158: my %defaultchecked = (
21159: 'canuse_pdfforms' => 'off',
21160: 'uselcmath' => 'on',
1.398 raeburn 21161: 'usejsme' => 'on',
21162: 'inline_chem' => 'on',
1.404 raeburn 21163: 'ltiauth' => 'off',
1.257 raeburn 21164: );
1.404 raeburn 21165: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21166: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21167: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21168: 'coursequota_official','coursequota_unofficial','coursequota_community',
21169: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21170: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21171: 'mysqltables_placement');
1.271 raeburn 21172: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21173: my %staticdefaults = (
21174: anonsurvey_threshold => 10,
21175: uploadquota => 500,
1.428 raeburn 21176: coursequota => 20,
1.257 raeburn 21177: postsubmit => 60,
1.276 raeburn 21178: mysqltables => 172800,
1.422 raeburn 21179: domexttool => 1,
1.432 raeburn 21180: crsauthor => 1,
1.438 raeburn 21181: crseditors => ['edit','xml'],
1.198 raeburn 21182: );
1.314 raeburn 21183: my %texoptions = (
21184: MathJax => 'MathJax',
21185: mimetex => &mt('Convert to Images'),
21186: tth => &mt('TeX to HTML'),
21187: );
1.438 raeburn 21188:
21189: my @editors = ('edit','xml','daxe');
21190: my %editornames = &crseditor_titles();
21191:
1.121 raeburn 21192: $defaultshash{'coursedefaults'} = {};
21193:
21194: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21195: if ($domconfig{'coursedefaults'} eq '') {
21196: $domconfig{'coursedefaults'} = {};
21197: }
21198: }
21199:
21200: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21201: foreach my $item (@toggles) {
21202: if ($defaultchecked{$item} eq 'on') {
21203: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21204: ($env{'form.'.$item} eq '0')) {
21205: $changes{$item} = 1;
1.192 raeburn 21206: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21207: $changes{$item} = 1;
21208: }
21209: } elsif ($defaultchecked{$item} eq 'off') {
21210: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21211: ($env{'form.'.$item} eq '1')) {
21212: $changes{$item} = 1;
21213: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21214: $changes{$item} = 1;
21215: }
21216: }
21217: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21218: }
1.198 raeburn 21219: foreach my $item (@numbers) {
21220: my ($currdef,$newdef);
1.208 raeburn 21221: $newdef = $env{'form.'.$item};
1.198 raeburn 21222: if ($item eq 'anonsurvey_threshold') {
21223: $currdef = $domconfig{'coursedefaults'}{$item};
21224: $newdef =~ s/\D//g;
21225: if ($newdef eq '' || $newdef < 1) {
21226: $newdef = 1;
21227: }
21228: $defaultshash{'coursedefaults'}{$item} = $newdef;
21229: } else {
1.428 raeburn 21230: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21231: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21232: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21233: }
21234: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21235: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21236: }
21237: if ($currdef ne $newdef) {
21238: if ($item eq 'anonsurvey_threshold') {
21239: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21240: $changes{$item} = 1;
21241: }
1.428 raeburn 21242: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21243: my $setting = $1;
1.276 raeburn 21244: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21245: $changes{$setting} = 1;
1.198 raeburn 21246: }
21247: }
1.139 raeburn 21248: }
21249: }
1.314 raeburn 21250: my $texengine;
21251: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21252: $texengine = $env{'form.texengine'};
1.349 raeburn 21253: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21254: if ($currdef eq '') {
21255: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21256: $changes{'texengine'} = 1;
21257: }
1.349 raeburn 21258: } elsif ($currdef ne $texengine) {
1.314 raeburn 21259: $changes{'texengine'} = 1;
21260: }
21261: }
21262: if ($texengine ne '') {
21263: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21264: }
1.264 raeburn 21265: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21266: my @currclonecode;
21267: if (ref($currclone) eq 'HASH') {
21268: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21269: @currclonecode = @{$currclone->{'instcode'}};
21270: }
21271: }
21272: my $newclone;
1.289 raeburn 21273: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21274: $newclone = $env{'form.canclone'};
21275: }
21276: if ($newclone eq 'instcode') {
21277: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21278: my (%codedefaults,@code_order,@clonecode);
21279: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21280: \@code_order);
21281: foreach my $item (@code_order) {
21282: if (grep(/^\Q$item\E$/,@newcodes)) {
21283: push(@clonecode,$item);
21284: }
21285: }
21286: if (@clonecode) {
21287: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21288: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21289: if (@diffs) {
21290: $changes{'canclone'} = 1;
21291: }
21292: } else {
21293: $newclone eq '';
21294: }
21295: } elsif ($newclone ne '') {
1.289 raeburn 21296: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21297: }
1.264 raeburn 21298: if ($newclone ne $currclone) {
21299: $changes{'canclone'} = 1;
21300: }
1.257 raeburn 21301: my %credits;
21302: foreach my $type (@types) {
21303: unless ($type eq 'community') {
21304: $credits{$type} = $env{'form.'.$type.'_credits'};
21305: $credits{$type} =~ s/[^\d.]+//g;
21306: }
21307: }
21308: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21309: ($env{'form.coursecredits'} eq '1')) {
21310: $changes{'coursecredits'} = 1;
21311: foreach my $type (keys(%credits)) {
21312: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21313: }
21314: } else {
1.289 raeburn 21315: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21316: foreach my $type (@types) {
21317: unless ($type eq 'community') {
1.289 raeburn 21318: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21319: $changes{'coursecredits'} = 1;
21320: }
21321: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21322: }
21323: }
21324: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21325: foreach my $type (@types) {
21326: unless ($type eq 'community') {
21327: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21328: $changes{'coursecredits'} = 1;
21329: last;
21330: }
21331: }
21332: }
21333: }
21334: }
21335: if ($env{'form.postsubmit'} eq '1') {
21336: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21337: my %currtimeout;
21338: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21339: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21340: $changes{'postsubmit'} = 1;
21341: }
21342: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21343: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21344: }
21345: } else {
21346: $changes{'postsubmit'} = 1;
21347: }
21348: foreach my $type (@types) {
21349: my $timeout = $env{'form.'.$type.'_timeout'};
21350: $timeout =~ s/\D//g;
21351: if ($timeout == $staticdefaults{'postsubmit'}) {
21352: $timeout = '';
21353: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21354: $timeout = '0';
21355: }
21356: unless ($timeout eq '') {
21357: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21358: }
21359: if (exists($currtimeout{$type})) {
21360: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21361: $changes{'postsubmit'} = 1;
1.257 raeburn 21362: }
21363: } elsif ($timeout ne '') {
21364: $changes{'postsubmit'} = 1;
21365: }
21366: }
21367: } else {
21368: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21369: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21370: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21371: $changes{'postsubmit'} = 1;
21372: }
21373: } else {
21374: $changes{'postsubmit'} = 1;
21375: }
1.192 raeburn 21376: }
1.438 raeburn 21377: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor,
21378: %posscrseditors);
1.422 raeburn 21379: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21380: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 raeburn 21381: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.438 raeburn 21382: map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
1.422 raeburn 21383: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21384: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21385: } else {
21386: foreach my $type (@types) {
21387: if ($staticdefaults{'domexttool'}) {
21388: $olddomexttool{$type} = 1;
21389: } else {
21390: $olddomexttool{$type} = 0;
21391: }
21392: }
21393: }
21394: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21395: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21396: } else {
21397: foreach my $type (@types) {
21398: if ($staticdefaults{'exttool'}) {
21399: $oldexttool{$type} = 1;
21400: } else {
21401: $oldexttool{$type} = 0;
21402: }
21403: }
21404: }
1.432 raeburn 21405: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21406: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
21407: } else {
21408: foreach my $type (@types) {
21409: if ($staticdefaults{'crsauthor'}) {
21410: $oldcrsauthor{$type} = 1;
21411: } else {
21412: $oldcrsauthor{$type} = 0;
21413: }
21414: }
21415: }
1.438 raeburn 21416: my @newcrseditors = ();
21417: foreach my $editor (@editors) {
21418: if ($posscrseditors{$editor}) {
21419: push(@newcrseditors,$editor);
21420: }
21421: }
21422: if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21423: my @diffs =
21424: &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
21425: \@newcrseditors);
21426: if (@diffs) {
21427: $changes{'crseditors'} = 1;
21428: }
21429: } else {
21430: my @diffs =
21431: &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
21432: \@newcrseditors);
21433: unless (@diffs == 0) {
21434: $changes{'crseditors'} = 1;
21435: }
21436: }
1.422 raeburn 21437: foreach my $type (@types) {
21438: unless ($newdomexttool{$type}) {
21439: $newdomexttool{$type} = 0;
21440: }
21441: unless ($newexttool{$type}) {
21442: $newexttool{$type} = 0;
21443: }
1.432 raeburn 21444: unless ($newcrsauthor{$type}) {
21445: $newcrsauthor{$type} = 0;
21446: }
1.422 raeburn 21447: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21448: $changes{'domexttool'} = 1;
21449: }
21450: if ($newexttool{$type} != $oldexttool{$type}) {
21451: $changes{'exttool'} = 1;
21452: }
1.432 raeburn 21453: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
21454: $changes{'crsauthor'} = 1;
21455: }
1.422 raeburn 21456: }
21457: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21458: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 raeburn 21459: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.438 raeburn 21460: $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 21461: }
21462: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21463: $dom);
21464: if ($putresult eq 'ok') {
21465: if (keys(%changes) > 0) {
1.213 raeburn 21466: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21467: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21468: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21469: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21470: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 raeburn 21471: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21472: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21473: 'ltiauth') {
1.257 raeburn 21474: if ($changes{$item}) {
21475: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21476: }
1.289 raeburn 21477: }
1.192 raeburn 21478: if ($changes{'coursecredits'}) {
21479: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21480: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21481: $domdefaults{$type.'credits'} =
21482: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21483: }
21484: }
21485: }
21486: if ($changes{'postsubmit'}) {
21487: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21488: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21489: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21490: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21491: $domdefaults{$type.'postsubtimeout'} =
21492: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21493: }
21494: }
1.192 raeburn 21495: }
21496: }
1.198 raeburn 21497: if ($changes{'uploadquota'}) {
21498: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21499: foreach my $type (@types) {
21500: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21501: }
21502: }
21503: }
1.428 raeburn 21504: if ($changes{'coursequota'}) {
21505: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21506: foreach my $type (@types) {
21507: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21508: }
21509: }
21510: }
1.264 raeburn 21511: if ($changes{'canclone'}) {
21512: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21513: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21514: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21515: if (@clonecodes) {
21516: $domdefaults{'canclone'} = join('+',@clonecodes);
21517: }
21518: }
21519: } else {
21520: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21521: }
21522: }
1.422 raeburn 21523: if ($changes{'domexttool'}) {
21524: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21525: foreach my $type (@types) {
21526: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21527: }
21528: }
21529: }
21530: if ($changes{'exttool'}) {
21531: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21532: foreach my $type (@types) {
21533: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21534: }
21535: }
21536: }
1.432 raeburn 21537: if ($changes{'crsauthor'}) {
21538: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21539: foreach my $type (@types) {
21540: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
21541: }
21542: }
21543: }
1.438 raeburn 21544: if ($changes{'crseditors'}) {
21545: if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21546: $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
21547: }
21548: }
1.121 raeburn 21549: my $cachetime = 24*60*60;
21550: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21551: if (ref($lastactref) eq 'HASH') {
21552: $lastactref->{'domdefaults'} = 1;
21553: }
1.121 raeburn 21554: }
21555: $resulttext = &mt('Changes made:').'<ul>';
21556: foreach my $item (sort(keys(%changes))) {
21557: if ($item eq 'canuse_pdfforms') {
21558: if ($env{'form.'.$item} eq '1') {
21559: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21560: } else {
21561: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21562: }
1.257 raeburn 21563: } elsif ($item eq 'uselcmath') {
21564: if ($env{'form.'.$item} eq '1') {
21565: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21566: } else {
21567: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21568: }
21569: } elsif ($item eq 'usejsme') {
21570: if ($env{'form.'.$item} eq '1') {
21571: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21572: } else {
1.289 raeburn 21573: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21574: }
1.398 raeburn 21575: } elsif ($item eq 'inline_chem') {
21576: if ($env{'form.'.$item} eq '1') {
21577: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21578: } else {
21579: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21580: }
1.314 raeburn 21581: } elsif ($item eq 'texengine') {
21582: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21583: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21584: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21585: }
1.139 raeburn 21586: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21587: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21588: } elsif ($item eq 'uploadquota') {
21589: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21590: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21591: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21592: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21593: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21594: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21595: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21596: '</ul>'.
21597: '</li>';
21598: } else {
21599: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21600: }
1.428 raeburn 21601: } elsif ($item eq 'coursequota') {
21602: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21603: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21604: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21605: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21606: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21607: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21608: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21609: '</ul>'.
21610: '</li>';
21611: } else {
21612: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21613: }
1.276 raeburn 21614: } elsif ($item eq 'mysqltables') {
21615: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21616: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21617: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21618: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21619: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21620: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21621: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21622: '</ul>'.
21623: '</li>';
21624: } else {
21625: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21626: }
1.257 raeburn 21627: } elsif ($item eq 'postsubmit') {
21628: if ($domdefaults{'postsubmit'} eq 'off') {
21629: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21630: } else {
21631: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21632: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21633: $resulttext .= &mt('durations:').'<ul>';
21634: foreach my $type (@types) {
21635: $resulttext .= '<li>';
21636: my $timeout;
21637: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21638: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21639: }
21640: my $display;
21641: if ($timeout eq '0') {
21642: $display = &mt('unlimited');
21643: } elsif ($timeout eq '') {
21644: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21645: } else {
21646: $display = &mt('[quant,_1,second]',$timeout);
21647: }
21648: if ($type eq 'community') {
21649: $resulttext .= &mt('Communities');
21650: } elsif ($type eq 'official') {
21651: $resulttext .= &mt('Official courses');
21652: } elsif ($type eq 'unofficial') {
21653: $resulttext .= &mt('Unofficial courses');
21654: } elsif ($type eq 'textbook') {
21655: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21656: } elsif ($type eq 'placement') {
21657: $resulttext .= &mt('Placement tests');
1.257 raeburn 21658: }
21659: $resulttext .= ' -- '.$display.'</li>';
21660: }
21661: $resulttext .= '</ul>';
21662: }
1.289 raeburn 21663: $resulttext .= '</li>';
1.257 raeburn 21664: }
1.192 raeburn 21665: } elsif ($item eq 'coursecredits') {
21666: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21667: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21668: ($domdefaults{'unofficialcredits'} eq '') &&
21669: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21670: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21671: } else {
21672: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21673: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21674: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21675: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21676: '</ul>'.
21677: '</li>';
21678: }
21679: } else {
21680: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21681: }
1.264 raeburn 21682: } elsif ($item eq 'canclone') {
21683: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21684: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21685: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21686: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21687: }
21688: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21689: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21690: } else {
1.289 raeburn 21691: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21692: }
1.404 raeburn 21693: } elsif ($item eq 'ltiauth') {
21694: if ($env{'form.'.$item} eq '1') {
21695: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21696: } else {
21697: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21698: }
1.432 raeburn 21699: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21700: my @noyes = (&mt('no'),&mt('yes'));
1.432 raeburn 21701: my %status = (
21702: domexttool => {
21703: ishash => &mt('External Tools defined in the domain may be used as follows:'),
21704: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
21705: },
21706: exttool => {
21707: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
21708: default => &mt('External Tools can not be defined in any course types, by default'),
21709: },
21710: crsauthor => {
21711: ishash => &mt('Standard Problems can be created within course containers as follows:'),
21712: default => &mt('Standard Problems can be created within any course type, by default'),
21713: },
21714: );
21715:
21716: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
21717: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
21718: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
21719: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
21720: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
21721: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
21722: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21723: '</ul>'.
21724: '</li>';
21725: } else {
1.432 raeburn 21726: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21727: }
1.438 raeburn 21728: } elsif ($item eq 'crseditors') {
21729: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
21730: my $shown;
21731: if (@{$defaultshash{'coursedefaults'}{$item}}) {
21732: $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
21733: } else {
21734: $shown = &mt('None');
21735: }
21736: $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
21737: }
1.140 raeburn 21738: }
1.121 raeburn 21739: }
21740: $resulttext .= '</ul>';
21741: } else {
21742: $resulttext = &mt('No changes made to course defaults');
21743: }
21744: } else {
21745: $resulttext = '<span class="LC_error">'.
21746: &mt('An error occurred: [_1]',$putresult).'</span>';
21747: }
21748: return $resulttext;
21749: }
21750:
1.231 raeburn 21751: sub modify_selfenrollment {
21752: my ($dom,$lastactref,%domconfig) = @_;
21753: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21754: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21755: my %titles = &tool_titles();
1.232 raeburn 21756: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21757: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21758: $ordered{'default'} = ['types','registered','approval','limit'];
21759:
21760: my (%roles,%shown,%toplevel);
21761: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21762:
21763: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21764: if ($domconfig{'selfenrollment'} eq '') {
21765: $domconfig{'selfenrollment'} = {};
21766: }
21767: }
21768: %toplevel = (
21769: admin => 'Configuration Rights',
21770: default => 'Default settings',
21771: validation => 'Validation of self-enrollment requests',
21772: );
1.233 raeburn 21773: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21774:
21775: if (ref($ordered{'admin'}) eq 'ARRAY') {
21776: foreach my $item (@{$ordered{'admin'}}) {
21777: foreach my $type (@types) {
21778: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21779: $selfenrollhash{'admin'}{$type}{$item} = 1;
21780: } else {
21781: $selfenrollhash{'admin'}{$type}{$item} = 0;
21782: }
21783: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21784: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21785: if ($selfenrollhash{'admin'}{$type}{$item} ne
21786: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21787: push(@{$changes{'admin'}{$type}},$item);
21788: }
21789: } else {
21790: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21791: push(@{$changes{'admin'}{$type}},$item);
21792: }
21793: }
21794: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21795: push(@{$changes{'admin'}{$type}},$item);
21796: }
21797: }
21798: }
21799: }
21800:
21801: foreach my $item (@{$ordered{'default'}}) {
21802: foreach my $type (@types) {
21803: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21804: if ($item eq 'types') {
21805: unless (($value eq 'all') || ($value eq 'dom')) {
21806: $value = '';
21807: }
21808: } elsif ($item eq 'registered') {
21809: unless ($value eq '1') {
21810: $value = 0;
21811: }
21812: } elsif ($item eq 'approval') {
21813: unless ($value =~ /^[012]$/) {
21814: $value = 0;
21815: }
21816: } else {
21817: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21818: $value = 'none';
21819: }
21820: }
21821: $selfenrollhash{'default'}{$type}{$item} = $value;
21822: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21823: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21824: if ($selfenrollhash{'default'}{$type}{$item} ne
21825: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21826: push(@{$changes{'default'}{$type}},$item);
21827: }
21828: } else {
21829: push(@{$changes{'default'}{$type}},$item);
21830: }
21831: } else {
21832: push(@{$changes{'default'}{$type}},$item);
21833: }
21834: if ($item eq 'limit') {
21835: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21836: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21837: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21838: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21839: }
21840: } else {
21841: $selfenrollhash{'default'}{$type}{'cap'} = '';
21842: }
21843: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21844: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21845: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21846: push(@{$changes{'default'}{$type}},'cap');
21847: }
21848: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21849: push(@{$changes{'default'}{$type}},'cap');
21850: }
21851: }
21852: }
21853: }
21854:
21855: foreach my $item (@{$itemsref}) {
21856: if ($item eq 'fields') {
21857: my @changed;
21858: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21859: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21860: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21861: }
21862: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21863: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21864: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21865: $domconfig{'selfenrollment'}{'validation'}{$item});
21866: } else {
21867: @changed = @{$selfenrollhash{'validation'}{$item}};
21868: }
21869: } else {
21870: @changed = @{$selfenrollhash{'validation'}{$item}};
21871: }
21872: if (@changed) {
21873: if ($selfenrollhash{'validation'}{$item}) {
21874: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21875: } else {
21876: $changes{'validation'}{$item} = &mt('None');
21877: }
21878: }
21879: } else {
21880: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21881: if ($item eq 'markup') {
21882: if ($env{'form.selfenroll_validation_'.$item}) {
21883: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21884: }
21885: }
21886: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21887: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21888: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21889: }
21890: }
21891: }
21892: }
21893:
21894: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21895: $dom);
21896: if ($putresult eq 'ok') {
21897: if (keys(%changes) > 0) {
21898: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21899: $resulttext = &mt('Changes made:').'<ul>';
21900: foreach my $key ('admin','default','validation') {
21901: if (ref($changes{$key}) eq 'HASH') {
21902: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
21903: if ($key eq 'validation') {
21904: foreach my $item (@{$itemsref}) {
21905: if (exists($changes{$key}{$item})) {
21906: if ($item eq 'markup') {
21907: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21908: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
21909: } else {
21910: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21911: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
21912: }
21913: }
21914: }
21915: } else {
21916: foreach my $type (@types) {
21917: if ($type eq 'community') {
21918: $roles{'1'} = &mt('Community personnel');
21919: } else {
21920: $roles{'1'} = &mt('Course personnel');
21921: }
21922: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 21923: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21924: if ($key eq 'admin') {
21925: my @mgrdc = ();
21926: if (ref($ordered{$key}) eq 'ARRAY') {
21927: foreach my $item (@{$ordered{'admin'}}) {
21928: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21929: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
21930: push(@mgrdc,$item);
21931: }
21932: }
21933: }
21934: if (@mgrdc) {
21935: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
21936: } else {
21937: delete($domdefaults{$type.'selfenrolladmdc'});
21938: }
21939: }
21940: } else {
21941: if (ref($ordered{$key}) eq 'ARRAY') {
21942: foreach my $item (@{$ordered{$key}}) {
21943: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21944: $domdefaults{$type.'selfenroll'.$item} =
21945: $selfenrollhash{$key}{$type}{$item};
21946: }
21947: }
21948: }
21949: }
21950: }
1.231 raeburn 21951: $resulttext .= '<li>'.$titles{$type}.'<ul>';
21952: foreach my $item (@{$ordered{$key}}) {
21953: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21954: $resulttext .= '<li>';
21955: if ($key eq 'admin') {
21956: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
21957: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
21958: } else {
21959: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
21960: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
21961: }
21962: $resulttext .= '</li>';
21963: }
21964: }
21965: $resulttext .= '</ul></li>';
21966: }
21967: }
21968: $resulttext .= '</ul></li>';
21969: }
21970: }
1.305 raeburn 21971: }
21972: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
21973: my $cachetime = 24*60*60;
21974: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21975: if (ref($lastactref) eq 'HASH') {
21976: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 21977: }
1.231 raeburn 21978: }
21979: $resulttext .= '</ul>';
21980: } else {
21981: $resulttext = &mt('No changes made to self-enrollment settings');
21982: }
21983: } else {
21984: $resulttext = '<span class="LC_error">'.
21985: &mt('An error occurred: [_1]',$putresult).'</span>';
21986: }
21987: return $resulttext;
21988: }
21989:
1.373 raeburn 21990: sub modify_wafproxy {
21991: my ($dom,$action,$lastactref,%domconfig) = @_;
21992: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 21993: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
21994: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 21995: foreach my $server (sort(keys(%servers))) {
21996: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21997: if ($serverhome eq $server) {
21998: my $serverdom = &Apache::lonnet::host_domain($server);
21999: if ($serverdom eq $dom) {
22000: $canset{$server} = 1;
22001: }
22002: }
22003: }
1.381 raeburn 22004: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
22005: %{$values{$dom}} = ();
22006: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
22007: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
22008: }
1.388 raeburn 22009: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
22010: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
22011: }
1.382 raeburn 22012: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 22013: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
22014: }
22015: }
1.373 raeburn 22016: my $output;
22017: if (keys(%canset)) {
22018: %{$wafproxy{'alias'}} = ();
1.388 raeburn 22019: %{$wafproxy{'saml'}} = ();
1.373 raeburn 22020: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 22021: if ($env{'form.wafproxy_'.$dom}) {
22022: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
22023: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
22024: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
22025: $changes{'alias'} = 1;
22026: }
1.388 raeburn 22027: if ($env{'form.wafproxy_alias_saml_'.$key}) {
22028: $wafproxy{'saml'}{$key} = 1;
22029: }
22030: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
22031: $changes{'saml'} = 1;
22032: }
1.381 raeburn 22033: } else {
22034: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 22035: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 22036: if ($curralias{$key}) {
22037: $changes{'alias'} = 1;
22038: }
1.388 raeburn 22039: if ($currsaml{$key}) {
22040: $changes{'saml'} = 1;
22041: }
1.373 raeburn 22042: }
22043: if ($wafproxy{'alias'}{$key} eq '') {
22044: if ($curralias{$key}) {
22045: $expirecache{$key} = 1;
22046: }
22047: delete($wafproxy{'alias'}{$key});
22048: }
1.388 raeburn 22049: if ($wafproxy{'saml'}{$key} eq '') {
22050: if ($currsaml{$key}) {
22051: $expiresaml{$key} = 1;
22052: }
22053: delete($wafproxy{'saml'}{$key});
22054: }
1.373 raeburn 22055: }
22056: unless (keys(%{$wafproxy{'alias'}})) {
22057: delete($wafproxy{'alias'});
22058: }
1.388 raeburn 22059: unless (keys(%{$wafproxy{'saml'}})) {
22060: delete($wafproxy{'saml'});
22061: }
22062: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 22063: my %warn = (
22064: trusted => 'trusted IP range(s)',
1.381 raeburn 22065: vpnint => 'internal IP range(s) for VPN sessions(s)',
22066: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 22067: );
1.382 raeburn 22068: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22069: my $possible = $env{'form.wafproxy_'.$item};
22070: $possible =~ s/^\s+|\s+$//g;
22071: if ($possible ne '') {
1.381 raeburn 22072: if ($item eq 'remoteip') {
22073: if ($possible =~ /^[mhn]$/) {
22074: $wafproxy{$item} = $possible;
22075: }
22076: } elsif ($item eq 'ipheader') {
22077: if ($wafproxy{'remoteip'} eq 'h') {
22078: $wafproxy{$item} = $possible;
22079: }
1.382 raeburn 22080: } elsif ($item eq 'sslopt') {
22081: if ($possible =~ /^0|1$/) {
22082: $wafproxy{$item} = $possible;
22083: }
1.373 raeburn 22084: } else {
22085: my (@ok,$count);
1.381 raeburn 22086: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
22087: unless ($env{'form.wafproxy_vpnaccess'}) {
22088: $possible = '';
22089: }
22090: } elsif ($item eq 'trusted') {
22091: unless ($wafproxy{'remoteip'} eq 'h') {
22092: $possible = '';
22093: }
22094: }
22095: unless ($possible eq '') {
22096: $possible =~ s/[\r\n]+/\s/g;
22097: $possible =~ s/\s*-\s*/-/g;
22098: $possible =~ s/\s+/,/g;
1.393 raeburn 22099: $possible =~ s/,+/,/g;
1.381 raeburn 22100: }
1.373 raeburn 22101: $count = 0;
1.381 raeburn 22102: if ($possible ne '') {
1.373 raeburn 22103: foreach my $poss (split(/\,/,$possible)) {
22104: $count ++;
1.393 raeburn 22105: $poss = &validate_ip_pattern($poss);
22106: if ($poss ne '') {
1.373 raeburn 22107: push(@ok,$poss);
22108: }
22109: }
22110: my $diff = $count - scalar(@ok);
22111: if ($diff) {
22112: push(@warnings,'<li>'.
22113: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
22114: $diff,$warn{$item}).
22115: '</li>');
22116: }
1.393 raeburn 22117: if (@ok) {
22118: my @cidr_list;
22119: foreach my $item (@ok) {
22120: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
22121: }
22122: $wafproxy{$item} = join(',',@cidr_list);
22123: }
1.373 raeburn 22124: }
22125: }
1.381 raeburn 22126: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 22127: $changes{$item} = 1;
22128: }
1.381 raeburn 22129: } elsif ($currvalue{$item}) {
22130: $changes{$item} = 1;
1.425 raeburn 22131: }
1.381 raeburn 22132: }
22133: } else {
22134: if (keys(%curralias)) {
22135: $changes{'alias'} = 1;
1.388 raeburn 22136: }
22137: if (keys(%currsaml)) {
22138: $changes{'saml'} = 1;
1.425 raeburn 22139: }
1.381 raeburn 22140: if (keys(%currvalue)) {
22141: foreach my $key (keys(%currvalue)) {
22142: $changes{$key} = 1;
1.373 raeburn 22143: }
22144: }
22145: }
22146: if (keys(%changes)) {
22147: my %defaultshash = (
22148: wafproxy => \%wafproxy,
1.425 raeburn 22149: );
1.373 raeburn 22150: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22151: $dom);
22152: if ($putresult eq 'ok') {
22153: my $cachetime = 24*60*60;
22154: my (%domdefaults,$updatedomdefs);
1.382 raeburn 22155: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22156: if ($changes{$item}) {
22157: unless ($updatedomdefs) {
22158: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
22159: $updatedomdefs = 1;
22160: }
22161: if ($wafproxy{$item}) {
22162: $domdefaults{'waf_'.$item} = $wafproxy{$item};
22163: } elsif (exists($domdefaults{'waf_'.$item})) {
22164: delete($domdefaults{'waf_'.$item});
1.425 raeburn 22165: }
1.373 raeburn 22166: }
22167: }
22168: if ($updatedomdefs) {
22169: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22170: if (ref($lastactref) eq 'HASH') {
22171: $lastactref->{'domdefaults'} = 1;
22172: }
22173: }
22174: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22175: my %updates = %expirecache;
22176: foreach my $key (keys(%expirecache)) {
22177: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22178: }
22179: if (ref($wafproxy{'alias'}) eq 'HASH') {
22180: my $cachetime = 24*60*60;
22181: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22182: $updates{$key} = 1;
22183: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22184: $cachetime);
22185: }
22186: }
22187: if (ref($lastactref) eq 'HASH') {
22188: $lastactref->{'proxyalias'} = \%updates;
22189: }
22190: }
1.388 raeburn 22191: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22192: my %samlupdates = %expiresaml;
22193: foreach my $key (keys(%expiresaml)) {
22194: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22195: }
22196: if (ref($wafproxy{'saml'}) eq 'HASH') {
22197: my $cachetime = 24*60*60;
22198: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22199: $samlupdates{$key} = 1;
22200: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22201: $cachetime);
22202: }
22203: }
22204: if (ref($lastactref) eq 'HASH') {
22205: $lastactref->{'proxysaml'} = \%samlupdates;
22206: }
22207: }
1.373 raeburn 22208: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22209: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22210: if ($changes{$item}) {
22211: if ($item eq 'alias') {
22212: my $numaliased = 0;
22213: if (ref($wafproxy{'alias'}) eq 'HASH') {
22214: my $shown;
22215: if (keys(%{$wafproxy{'alias'}})) {
22216: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22217: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22218: &Apache::lonnet::hostname($server),
22219: $wafproxy{'alias'}{$server}).'</li>';
22220: $numaliased ++;
22221: }
22222: if ($numaliased) {
22223: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22224: '<ul>'.$shown.'</ul>').'</li>';
22225: }
22226: }
22227: }
22228: unless ($numaliased) {
22229: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22230: }
1.388 raeburn 22231: } elsif ($item eq 'saml') {
1.425 raeburn 22232: my $shown;
1.388 raeburn 22233: if (ref($wafproxy{'saml'}) eq 'HASH') {
22234: if (keys(%{$wafproxy{'saml'}})) {
22235: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22236: }
22237: }
22238: if ($shown) {
1.396 raeburn 22239: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22240: $shown).'</li>';
22241: } else {
1.396 raeburn 22242: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22243: }
1.373 raeburn 22244: } else {
1.381 raeburn 22245: if ($item eq 'remoteip') {
22246: my %ip_methods = &remoteip_methods();
22247: if ($wafproxy{$item} =~ /^[mh]$/) {
22248: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22249: $ip_methods{$wafproxy{$item}}).'</li>';
22250: } else {
22251: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22252: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22253: '</li>';
22254: } else {
22255: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22256: }
22257: }
22258: } elsif ($item eq 'ipheader') {
1.373 raeburn 22259: if ($wafproxy{$item}) {
1.381 raeburn 22260: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22261: $wafproxy{$item}).'</li>';
22262: } else {
1.381 raeburn 22263: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22264: }
22265: } elsif ($item eq 'trusted') {
22266: if ($wafproxy{$item}) {
1.381 raeburn 22267: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22268: $wafproxy{$item}).'</li>';
22269: } else {
22270: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22271: }
1.381 raeburn 22272: } elsif ($item eq 'vpnint') {
22273: if ($wafproxy{$item}) {
22274: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22275: $wafproxy{$item}).'</li>';
22276: } else {
22277: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22278: }
22279: } elsif ($item eq 'vpnext') {
1.373 raeburn 22280: if ($wafproxy{$item}) {
1.381 raeburn 22281: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22282: $wafproxy{$item}).'</li>';
22283: } else {
1.381 raeburn 22284: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22285: }
1.382 raeburn 22286: } elsif ($item eq 'sslopt') {
22287: if ($wafproxy{$item}) {
22288: $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>';
22289: } else {
22290: $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>';
22291: }
1.373 raeburn 22292: }
22293: }
22294: }
22295: }
1.420 raeburn 22296: $output .= '</ul>';
1.373 raeburn 22297: } else {
22298: $output = '<span class="LC_error">'.
22299: &mt('An error occurred: [_1]',$putresult).'</span>';
22300: }
22301: } elsif (keys(%canset)) {
22302: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22303: }
22304: if (@warnings) {
22305: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22306: join("\n",@warnings).'</ul>';
22307: }
22308: return $output;
22309: }
22310:
22311: sub validate_ip_pattern {
22312: my ($pattern) = @_;
22313: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22314: my ($start,$end) = ($1,$2);
22315: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22316: if (($start !~ m{/}) && ($end !~ m{/})) {
22317: return $start.'-'.$end;
22318: }
22319: }
22320: } elsif ($pattern ne '') {
22321: $pattern = &Net::CIDR::cidrvalidate($pattern);
22322: if ($pattern ne '') {
22323: return $pattern;
1.373 raeburn 22324: }
22325: }
1.393 raeburn 22326: return;
1.373 raeburn 22327: }
22328:
1.137 raeburn 22329: sub modify_usersessions {
1.212 raeburn 22330: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22331: my @hostingtypes = ('version','excludedomain','includedomain');
22332: my @offloadtypes = ('primary','default');
22333: my %types = (
22334: remote => \@hostingtypes,
22335: hosted => \@hostingtypes,
22336: spares => \@offloadtypes,
22337: );
22338: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22339: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22340: my (%by_ip,%by_location,@intdoms,@instdoms);
22341: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22342: my @locations = sort(keys(%by_location));
1.137 raeburn 22343: my (%defaultshash,%changes);
22344: foreach my $prefix (@prefixes) {
22345: $defaultshash{'usersessions'}{$prefix} = {};
22346: }
1.212 raeburn 22347: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22348: my $resulttext;
1.138 raeburn 22349: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22350: foreach my $prefix (@prefixes) {
1.145 raeburn 22351: next if ($prefix eq 'spares');
22352: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22353: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22354: if ($type eq 'version') {
22355: my $value = $env{'form.'.$prefix.'_'.$type};
22356: my $okvalue;
22357: if ($value ne '') {
22358: if (grep(/^\Q$value\E$/,@lcversions)) {
22359: $okvalue = $value;
22360: }
22361: }
22362: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22363: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22364: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22365: if ($inuse == 0) {
22366: $changes{$prefix}{$type} = 1;
22367: } else {
22368: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22369: $changes{$prefix}{$type} = 1;
22370: }
22371: if ($okvalue ne '') {
22372: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22373: }
22374: }
22375: } else {
22376: if (($inuse == 1) && ($okvalue ne '')) {
22377: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22378: $changes{$prefix}{$type} = 1;
22379: }
22380: }
22381: } else {
22382: if (($inuse == 1) && ($okvalue ne '')) {
22383: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22384: $changes{$prefix}{$type} = 1;
22385: }
22386: }
22387: } else {
22388: if (($inuse == 1) && ($okvalue ne '')) {
22389: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22390: $changes{$prefix}{$type} = 1;
22391: }
22392: }
22393: } else {
22394: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22395: my @okvals;
22396: foreach my $val (@vals) {
1.138 raeburn 22397: if ($val =~ /:/) {
22398: my @items = split(/:/,$val);
22399: foreach my $item (@items) {
22400: if (ref($by_location{$item}) eq 'ARRAY') {
22401: push(@okvals,$item);
22402: }
22403: }
22404: } else {
22405: if (ref($by_location{$val}) eq 'ARRAY') {
22406: push(@okvals,$val);
22407: }
1.137 raeburn 22408: }
22409: }
22410: @okvals = sort(@okvals);
22411: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22412: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22413: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22414: if ($inuse == 0) {
22415: $changes{$prefix}{$type} = 1;
22416: } else {
22417: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22418: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22419: if (@changed > 0) {
22420: $changes{$prefix}{$type} = 1;
22421: }
22422: }
22423: } else {
22424: if ($inuse == 1) {
22425: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22426: $changes{$prefix}{$type} = 1;
22427: }
22428: }
22429: } else {
22430: if ($inuse == 1) {
22431: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22432: $changes{$prefix}{$type} = 1;
22433: }
22434: }
22435: } else {
22436: if ($inuse == 1) {
22437: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22438: $changes{$prefix}{$type} = 1;
22439: }
22440: }
22441: }
22442: }
22443: }
1.145 raeburn 22444:
22445: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22446: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22447: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22448: my $savespares;
22449:
22450: foreach my $lonhost (sort(keys(%servers))) {
22451: my $serverhomeID =
22452: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22453: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22454: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22455: my %spareschg;
22456: foreach my $type (@{$types{'spares'}}) {
22457: my @okspares;
22458: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22459: foreach my $server (@checked) {
1.152 raeburn 22460: if (&Apache::lonnet::hostname($server) ne '') {
22461: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22462: unless (grep(/^\Q$server\E$/,@okspares)) {
22463: push(@okspares,$server);
22464: }
1.145 raeburn 22465: }
22466: }
22467: }
22468: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22469: my $newspare;
1.152 raeburn 22470: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22471: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22472: $newspare = $new;
22473: }
22474: }
1.152 raeburn 22475: my @spares;
22476: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22477: @spares = sort(@okspares,$newspare);
22478: } else {
22479: @spares = sort(@okspares);
22480: }
22481: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22482: if (ref($spareid{$lonhost}) eq 'HASH') {
22483: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22484: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22485: if (@diffs > 0) {
22486: $spareschg{$type} = 1;
22487: }
22488: }
22489: }
22490: }
22491: if (keys(%spareschg) > 0) {
22492: $changes{'spares'}{$lonhost} = \%spareschg;
22493: }
22494: }
1.261 raeburn 22495: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22496: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22497: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22498: my @okoffload;
22499: if (@offloadnow) {
22500: foreach my $server (@offloadnow) {
22501: if (&Apache::lonnet::hostname($server) ne '') {
22502: unless (grep(/^\Q$server\E$/,@okoffload)) {
22503: push(@okoffload,$server);
22504: }
22505: }
22506: }
22507: if (@okoffload) {
22508: foreach my $lonhost (@okoffload) {
22509: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22510: }
22511: }
22512: }
1.371 raeburn 22513: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22514: my @okoffloadoth;
22515: if (@offloadoth) {
22516: foreach my $server (@offloadoth) {
22517: if (&Apache::lonnet::hostname($server) ne '') {
22518: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22519: push(@okoffloadoth,$server);
22520: }
22521: }
22522: }
22523: if (@okoffloadoth) {
22524: foreach my $lonhost (@okoffloadoth) {
22525: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22526: }
22527: }
22528: }
1.145 raeburn 22529: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22530: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22531: if (ref($changes{'spares'}) eq 'HASH') {
22532: if (keys(%{$changes{'spares'}}) > 0) {
22533: $savespares = 1;
22534: }
22535: }
22536: } else {
22537: $savespares = 1;
22538: }
1.371 raeburn 22539: foreach my $offload ('offloadnow','offloadoth') {
22540: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22541: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22542: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22543: $changes{$offload} = 1;
22544: last;
22545: }
1.261 raeburn 22546: }
1.371 raeburn 22547: unless ($changes{$offload}) {
22548: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22549: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22550: $changes{$offload} = 1;
22551: last;
22552: }
1.261 raeburn 22553: }
22554: }
1.371 raeburn 22555: } else {
22556: if (($offload eq 'offloadnow') && (@okoffload)) {
22557: $changes{'offloadnow'} = 1;
22558: }
22559: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22560: $changes{'offloadoth'} = 1;
22561: }
1.425 raeburn 22562: }
1.371 raeburn 22563: }
22564: } else {
22565: if (@okoffload) {
1.261 raeburn 22566: $changes{'offloadnow'} = 1;
22567: }
1.371 raeburn 22568: if (@okoffloadoth) {
22569: $changes{'offloadoth'} = 1;
22570: }
1.145 raeburn 22571: }
1.147 raeburn 22572: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22573: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22574: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22575: $dom);
22576: if ($putresult eq 'ok') {
22577: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22578: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22579: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22580: }
22581: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22582: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22583: }
1.261 raeburn 22584: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22585: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22586: }
1.371 raeburn 22587: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22588: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22589: }
1.137 raeburn 22590: }
22591: my $cachetime = 24*60*60;
22592: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22593: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22594: if (ref($lastactref) eq 'HASH') {
22595: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22596: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22597: }
1.147 raeburn 22598: if (keys(%changes) > 0) {
22599: my %lt = &usersession_titles();
22600: $resulttext = &mt('Changes made:').'<ul>';
22601: foreach my $prefix (@prefixes) {
22602: if (ref($changes{$prefix}) eq 'HASH') {
22603: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22604: if ($prefix eq 'spares') {
22605: if (ref($changes{$prefix}) eq 'HASH') {
22606: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22607: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22608: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22609: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22610: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22611: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22612: foreach my $type (@{$types{$prefix}}) {
22613: if ($changes{$prefix}{$lonhost}{$type}) {
22614: my $offloadto = &mt('None');
22615: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22616: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22617: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22618: }
1.145 raeburn 22619: }
1.147 raeburn 22620: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22621: }
1.137 raeburn 22622: }
22623: }
1.147 raeburn 22624: $resulttext .= '</li>';
1.137 raeburn 22625: }
22626: }
1.147 raeburn 22627: } else {
22628: foreach my $type (@{$types{$prefix}}) {
22629: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22630: my ($newvalue,$notinuse);
1.147 raeburn 22631: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22632: if (ref($defaultshash{'usersessions'}{$prefix})) {
22633: if ($type eq 'version') {
22634: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22635: } else {
22636: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22637: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22638: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22639: }
22640: } else {
22641: $notinuse = 1;
1.147 raeburn 22642: }
1.145 raeburn 22643: }
22644: }
22645: }
1.147 raeburn 22646: if ($newvalue eq '') {
22647: if ($type eq 'version') {
22648: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22649: } elsif ($notinuse) {
22650: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22651: } else {
22652: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22653: }
1.145 raeburn 22654: } else {
1.147 raeburn 22655: if ($type eq 'version') {
1.344 raeburn 22656: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22657: }
22658: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22659: }
1.137 raeburn 22660: }
22661: }
22662: }
1.147 raeburn 22663: $resulttext .= '</ul>';
1.137 raeburn 22664: }
22665: }
1.261 raeburn 22666: if ($changes{'offloadnow'}) {
22667: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22668: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22669: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22670: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22671: $resulttext .= '<li>'.$lonhost.'</li>';
22672: }
22673: $resulttext .= '</ul>';
22674: } else {
1.371 raeburn 22675: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22676: }
22677: } else {
22678: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22679: }
22680: }
22681: if ($changes{'offloadoth'}) {
22682: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22683: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22684: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22685: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22686: $resulttext .= '<li>'.$lonhost.'</li>';
22687: }
22688: $resulttext .= '</ul>';
22689: } else {
22690: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22691: }
22692: } else {
1.371 raeburn 22693: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22694: }
22695: }
1.147 raeburn 22696: $resulttext .= '</ul>';
22697: } else {
22698: $resulttext = $nochgmsg;
1.137 raeburn 22699: }
22700: } else {
22701: $resulttext = '<span class="LC_error">'.
22702: &mt('An error occurred: [_1]',$putresult).'</span>';
22703: }
22704: } else {
1.147 raeburn 22705: $resulttext = $nochgmsg;
1.137 raeburn 22706: }
22707: return $resulttext;
22708: }
22709:
1.275 raeburn 22710: sub modify_ssl {
22711: my ($dom,$lastactref,%domconfig) = @_;
22712: my (%by_ip,%by_location,@intdoms,@instdoms);
22713: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22714: my @locations = sort(keys(%by_location));
22715: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22716: my (%defaultshash,%changes);
22717: my $action = 'ssl';
1.293 raeburn 22718: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22719: foreach my $prefix (@prefixes) {
22720: $defaultshash{$action}{$prefix} = {};
22721: }
22722: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22723: my $resulttext;
22724: my %iphost = &Apache::lonnet::get_iphost();
22725: my @reptypes = ('certreq','nocertreq');
22726: my @connecttypes = ('dom','intdom','other');
22727: my %types = (
1.293 raeburn 22728: connto => \@connecttypes,
22729: connfrom => \@connecttypes,
22730: replication => \@reptypes,
1.275 raeburn 22731: );
22732: foreach my $prefix (sort(keys(%types))) {
22733: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22734: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22735: my $value = 'yes';
22736: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22737: $value = $env{'form.'.$prefix.'_'.$type};
22738: }
1.335 raeburn 22739: if (ref($domconfig{$action}) eq 'HASH') {
22740: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22741: if ($domconfig{$action}{$prefix}{$type} ne '') {
22742: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22743: $changes{$prefix}{$type} = 1;
22744: }
22745: $defaultshash{$action}{$prefix}{$type} = $value;
22746: } else {
22747: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22748: $changes{$prefix}{$type} = 1;
22749: }
22750: } else {
22751: $defaultshash{$action}{$prefix}{$type} = $value;
22752: $changes{$prefix}{$type} = 1;
22753: }
22754: } else {
22755: $defaultshash{$action}{$prefix}{$type} = $value;
22756: $changes{$prefix}{$type} = 1;
22757: }
22758: if (($type eq 'dom') && (keys(%servers) == 1)) {
22759: delete($changes{$prefix}{$type});
22760: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22761: delete($changes{$prefix}{$type});
22762: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22763: delete($changes{$prefix}{$type});
22764: }
22765: } elsif ($prefix eq 'replication') {
22766: if (@locations > 0) {
22767: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22768: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22769: my @okvals;
22770: foreach my $val (@vals) {
22771: if ($val =~ /:/) {
22772: my @items = split(/:/,$val);
22773: foreach my $item (@items) {
22774: if (ref($by_location{$item}) eq 'ARRAY') {
22775: push(@okvals,$item);
22776: }
22777: }
22778: } else {
22779: if (ref($by_location{$val}) eq 'ARRAY') {
22780: push(@okvals,$val);
22781: }
22782: }
22783: }
22784: @okvals = sort(@okvals);
22785: if (ref($domconfig{$action}) eq 'HASH') {
22786: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22787: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22788: if ($inuse == 0) {
22789: $changes{$prefix}{$type} = 1;
22790: } else {
22791: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22792: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22793: if (@changed > 0) {
22794: $changes{$prefix}{$type} = 1;
22795: }
22796: }
22797: } else {
22798: if ($inuse == 1) {
22799: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22800: $changes{$prefix}{$type} = 1;
22801: }
22802: }
22803: } else {
22804: if ($inuse == 1) {
22805: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22806: $changes{$prefix}{$type} = 1;
22807: }
22808: }
22809: } else {
22810: if ($inuse == 1) {
22811: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22812: $changes{$prefix}{$type} = 1;
22813: }
22814: }
22815: }
22816: }
22817: }
22818: }
1.336 raeburn 22819: if (keys(%changes)) {
22820: foreach my $prefix (keys(%changes)) {
22821: if (ref($changes{$prefix}) eq 'HASH') {
22822: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22823: delete($changes{$prefix});
22824: }
22825: } else {
22826: delete($changes{$prefix});
22827: }
22828: }
22829: }
1.275 raeburn 22830: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22831: if (keys(%changes) > 0) {
22832: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22833: $dom);
22834: if ($putresult eq 'ok') {
22835: if (ref($defaultshash{$action}) eq 'HASH') {
22836: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22837: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22838: }
1.293 raeburn 22839: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22840: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22841: }
22842: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22843: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22844: }
22845: }
22846: my $cachetime = 24*60*60;
22847: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22848: if (ref($lastactref) eq 'HASH') {
22849: $lastactref->{'domdefaults'} = 1;
22850: }
22851: if (keys(%changes) > 0) {
22852: my %titles = &ssl_titles();
22853: $resulttext = &mt('Changes made:').'<ul>';
22854: foreach my $prefix (@prefixes) {
22855: if (ref($changes{$prefix}) eq 'HASH') {
22856: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22857: foreach my $type (@{$types{$prefix}}) {
22858: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22859: my ($newvalue,$notinuse);
1.275 raeburn 22860: if (ref($defaultshash{$action}) eq 'HASH') {
22861: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22862: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22863: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22864: } else {
22865: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22866: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22867: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22868: }
22869: } else {
22870: $notinuse = 1;
1.275 raeburn 22871: }
22872: }
22873: }
1.344 raeburn 22874: if ($notinuse) {
22875: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22876: } elsif ($newvalue eq '') {
1.275 raeburn 22877: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22878: } else {
22879: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22880: }
22881: }
22882: }
22883: }
22884: $resulttext .= '</ul>';
22885: }
22886: }
22887: } else {
22888: $resulttext = $nochgmsg;
22889: }
22890: } else {
22891: $resulttext = '<span class="LC_error">'.
22892: &mt('An error occurred: [_1]',$putresult).'</span>';
22893: }
22894: } else {
22895: $resulttext = $nochgmsg;
22896: }
22897: return $resulttext;
22898: }
22899:
1.279 raeburn 22900: sub modify_trust {
22901: my ($dom,$lastactref,%domconfig) = @_;
22902: my (%by_ip,%by_location,@intdoms,@instdoms);
22903: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22904: my @locations = sort(keys(%by_location));
22905: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
22906: my @types = ('exc','inc');
22907: my (%defaultshash,%changes);
22908: foreach my $prefix (@prefixes) {
22909: $defaultshash{'trust'}{$prefix} = {};
22910: }
22911: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22912: my $resulttext;
22913: foreach my $prefix (@prefixes) {
22914: foreach my $type (@types) {
22915: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22916: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22917: my @okvals;
22918: foreach my $val (@vals) {
22919: if ($val =~ /:/) {
22920: my @items = split(/:/,$val);
22921: foreach my $item (@items) {
22922: if (ref($by_location{$item}) eq 'ARRAY') {
22923: push(@okvals,$item);
22924: }
22925: }
22926: } else {
22927: if (ref($by_location{$val}) eq 'ARRAY') {
22928: push(@okvals,$val);
22929: }
22930: }
22931: }
22932: @okvals = sort(@okvals);
22933: if (ref($domconfig{'trust'}) eq 'HASH') {
22934: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
22935: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22936: if ($inuse == 0) {
22937: $changes{$prefix}{$type} = 1;
22938: } else {
22939: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22940: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
22941: if (@changed > 0) {
22942: $changes{$prefix}{$type} = 1;
22943: }
22944: }
22945: } else {
22946: if ($inuse == 1) {
22947: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22948: $changes{$prefix}{$type} = 1;
22949: }
22950: }
22951: } else {
22952: if ($inuse == 1) {
22953: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22954: $changes{$prefix}{$type} = 1;
22955: }
22956: }
22957: } else {
22958: if ($inuse == 1) {
22959: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22960: $changes{$prefix}{$type} = 1;
22961: }
22962: }
22963: }
22964: }
22965: my $nochgmsg = &mt('No changes made to trust settings.');
22966: if (keys(%changes) > 0) {
22967: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22968: $dom);
22969: if ($putresult eq 'ok') {
22970: if (ref($defaultshash{'trust'}) eq 'HASH') {
22971: foreach my $prefix (@prefixes) {
22972: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
22973: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
22974: }
22975: }
22976: }
22977: my $cachetime = 24*60*60;
22978: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 22979: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 22980: if (ref($lastactref) eq 'HASH') {
22981: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 22982: $lastactref->{'trust'} = 1;
1.279 raeburn 22983: }
22984: if (keys(%changes) > 0) {
22985: my %lt = &trust_titles();
22986: $resulttext = &mt('Changes made:').'<ul>';
22987: foreach my $prefix (@prefixes) {
22988: if (ref($changes{$prefix}) eq 'HASH') {
22989: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22990: foreach my $type (@types) {
22991: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22992: my ($newvalue,$notinuse);
1.279 raeburn 22993: if (ref($defaultshash{'trust'}) eq 'HASH') {
22994: if (ref($defaultshash{'trust'}{$prefix})) {
22995: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22996: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
22997: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
22998: }
1.344 raeburn 22999: } else {
23000: $notinuse = 1;
1.279 raeburn 23001: }
23002: }
23003: }
1.344 raeburn 23004: if ($notinuse) {
23005: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
23006: } elsif ($newvalue eq '') {
1.279 raeburn 23007: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
23008: } else {
23009: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
23010: }
23011: }
23012: }
23013: $resulttext .= '</ul>';
23014: }
23015: }
23016: $resulttext .= '</ul>';
23017: } else {
23018: $resulttext = $nochgmsg;
23019: }
23020: } else {
23021: $resulttext = '<span class="LC_error">'.
23022: &mt('An error occurred: [_1]',$putresult).'</span>';
23023: }
23024: } else {
23025: $resulttext = $nochgmsg;
23026: }
23027: return $resulttext;
23028: }
23029:
1.150 raeburn 23030: sub modify_loadbalancing {
23031: my ($dom,%domconfig) = @_;
23032: my $primary_id = &Apache::lonnet::domain($dom,'primary');
23033: my $intdom = &Apache::lonnet::internet_dom($primary_id);
23034: my ($othertitle,$usertypes,$types) =
23035: &Apache::loncommon::sorted_inst_types($dom);
23036: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 23037: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 23038: my @sparestypes = ('primary','default');
23039: my %typetitles = &sparestype_titles();
23040: my $resulttext;
1.342 raeburn 23041: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23042: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23043: %existing = %{$domconfig{'loadbalancing'}};
23044: }
23045: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 23046: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 23047: my ($saveloadbalancing,%defaultshash,%changes);
23048: my ($alltypes,$othertypes,$titles) =
23049: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
23050: my %ruletitles = &offloadtype_text();
23051: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
23052: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
23053: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
23054: if ($balancer eq '') {
23055: next;
23056: }
1.210 raeburn 23057: if (!exists($servers{$balancer})) {
1.171 raeburn 23058: if (exists($currbalancer{$balancer})) {
23059: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 23060: }
1.171 raeburn 23061: next;
23062: }
23063: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
23064: push(@{$changes{'delete'}},$balancer);
23065: next;
23066: }
23067: if (!exists($currbalancer{$balancer})) {
23068: push(@{$changes{'add'}},$balancer);
23069: }
23070: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
23071: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
23072: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
23073: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23074: $saveloadbalancing = 1;
23075: }
23076: foreach my $sparetype (@sparestypes) {
23077: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
23078: my @offloadto;
23079: foreach my $target (@targets) {
23080: if (($servers{$target}) && ($target ne $balancer)) {
23081: if ($sparetype eq 'default') {
23082: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
23083: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 23084: }
23085: }
1.171 raeburn 23086: unless(grep(/^\Q$target\E$/,@offloadto)) {
23087: push(@offloadto,$target);
23088: }
1.150 raeburn 23089: }
23090: }
1.284 raeburn 23091: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
23092: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
23093: push(@offloadto,$balancer);
23094: }
23095: }
23096: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 23097: }
1.342 raeburn 23098: if ($env{'form.loadbalancing_cookie_'.$i}) {
23099: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 23100: if (exists($currbalancer{$balancer})) {
1.342 raeburn 23101: unless ($currcookies{$balancer}) {
23102: $changes{'curr'}{$balancer}{'cookie'} = 1;
23103: }
23104: }
23105: } elsif (exists($currbalancer{$balancer})) {
23106: if ($currcookies{$balancer}) {
23107: $changes{'curr'}{$balancer}{'cookie'} = 1;
23108: }
23109: }
1.171 raeburn 23110: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 23111: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23112: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
23113: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 23114: if (@targetdiffs > 0) {
1.171 raeburn 23115: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23116: }
1.171 raeburn 23117: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23118: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23119: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23120: }
23121: }
23122: }
23123: } else {
1.171 raeburn 23124: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 23125: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23126: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23127: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23128: $changes{'curr'}{$balancer}{'targets'} = 1;
23129: }
1.150 raeburn 23130: }
23131: }
1.210 raeburn 23132: }
1.150 raeburn 23133: }
23134: my $ishomedom;
1.171 raeburn 23135: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
23136: $ishomedom = 1;
1.150 raeburn 23137: }
23138: if (ref($alltypes) eq 'ARRAY') {
23139: foreach my $type (@{$alltypes}) {
23140: my $rule;
1.210 raeburn 23141: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 23142: (!$ishomedom)) {
1.171 raeburn 23143: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
23144: }
23145: if ($rule eq 'specific') {
1.255 raeburn 23146: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 23147: if (exists($servers{$specifiedhost})) {
1.255 raeburn 23148: $rule = $specifiedhost;
23149: }
1.150 raeburn 23150: }
1.171 raeburn 23151: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
23152: if (ref($currrules{$balancer}) eq 'HASH') {
23153: if ($rule ne $currrules{$balancer}{$type}) {
23154: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23155: }
23156: } elsif ($rule ne '') {
1.171 raeburn 23157: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23158: }
23159: }
23160: }
1.171 raeburn 23161: }
23162: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
23163: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
23164: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23165: $defaultshash{'loadbalancing'} = {};
23166: }
23167: my $putresult = &Apache::lonnet::put_dom('configuration',
23168: \%defaultshash,$dom);
23169: if ($putresult eq 'ok') {
23170: if (keys(%changes) > 0) {
1.252 raeburn 23171: my %toupdate;
1.171 raeburn 23172: if (ref($changes{'delete'}) eq 'ARRAY') {
23173: foreach my $balancer (sort(@{$changes{'delete'}})) {
23174: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23175: $toupdate{$balancer} = 1;
1.150 raeburn 23176: }
1.171 raeburn 23177: }
23178: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23179: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23180: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23181: $toupdate{$balancer} = 1;
1.171 raeburn 23182: }
23183: }
23184: if (ref($changes{'curr'}) eq 'HASH') {
23185: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23186: $toupdate{$balancer} = 1;
1.171 raeburn 23187: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23188: if ($changes{'curr'}{$balancer}{'targets'}) {
23189: my %offloadstr;
23190: foreach my $sparetype (@sparestypes) {
23191: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23192: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23193: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23194: }
23195: }
1.150 raeburn 23196: }
1.171 raeburn 23197: if (keys(%offloadstr) == 0) {
23198: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23199: } else {
1.171 raeburn 23200: my $showoffload;
23201: foreach my $sparetype (@sparestypes) {
23202: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23203: if (defined($offloadstr{$sparetype})) {
23204: $showoffload .= $offloadstr{$sparetype};
23205: } else {
23206: $showoffload .= &mt('None');
23207: }
23208: $showoffload .= (' 'x3);
23209: }
23210: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23211: }
23212: }
23213: }
1.171 raeburn 23214: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23215: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23216: foreach my $type (@{$alltypes}) {
23217: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23218: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23219: my $balancetext;
23220: if ($rule eq '') {
23221: $balancetext = $ruletitles{'default'};
1.209 raeburn 23222: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23223: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23224: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23225: foreach my $sparetype (@sparestypes) {
23226: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23227: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23228: }
23229: }
1.253 raeburn 23230: foreach my $item (@{$alltypes}) {
23231: next if ($item =~ /^_LC_ipchange/);
23232: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23233: if ($hasrule eq 'homeserver') {
23234: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23235: } else {
23236: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23237: if ($servers{$hasrule}) {
23238: $toupdate{$hasrule} = 1;
23239: }
23240: }
23241: }
23242: }
1.254 raeburn 23243: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23244: $balancetext = $ruletitles{$rule};
23245: } else {
23246: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23247: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23248: if ($receiver) {
23249: $toupdate{$receiver};
23250: }
23251: }
23252: } else {
23253: $balancetext = $ruletitles{$rule};
1.252 raeburn 23254: }
1.171 raeburn 23255: } else {
23256: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23257: }
1.210 raeburn 23258: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23259: }
23260: }
23261: }
23262: }
1.342 raeburn 23263: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23264: if ($currcookies{$balancer}) {
23265: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23266: $balancer).'</li>';
23267: } else {
23268: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23269: $balancer).'</li>';
23270: }
1.342 raeburn 23271: }
1.375 raeburn 23272: }
23273: }
23274: if (keys(%toupdate)) {
23275: my %thismachine;
23276: my $updatedhere;
23277: my $cachetime = 60*60*24;
23278: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23279: foreach my $lonhost (keys(%toupdate)) {
23280: if ($thismachine{$lonhost}) {
23281: unless ($updatedhere) {
23282: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23283: $defaultshash{'loadbalancing'},
23284: $cachetime);
23285: $updatedhere = 1;
1.252 raeburn 23286: }
1.375 raeburn 23287: } else {
23288: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23289: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23290: }
1.150 raeburn 23291: }
1.171 raeburn 23292: }
23293: if ($resulttext ne '') {
23294: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23295: } else {
23296: $resulttext = $nochgmsg;
23297: }
23298: } else {
1.171 raeburn 23299: $resulttext = $nochgmsg;
1.150 raeburn 23300: }
23301: } else {
1.171 raeburn 23302: $resulttext = '<span class="LC_error">'.
23303: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23304: }
23305: } else {
1.171 raeburn 23306: $resulttext = $nochgmsg;
1.150 raeburn 23307: }
23308: return $resulttext;
23309: }
23310:
1.48 raeburn 23311: sub recurse_check {
23312: my ($chkcats,$categories,$depth,$name) = @_;
23313: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23314: my $chg = 0;
23315: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23316: my $category = $chkcats->[$depth]{$name}[$j];
23317: my $item;
23318: if ($category eq '') {
23319: $chg ++;
23320: } else {
23321: my $deeper = $depth + 1;
23322: $item = &escape($category).':'.&escape($name).':'.$depth;
23323: if ($chg) {
23324: $categories->{$item} -= $chg;
23325: }
23326: &recurse_check($chkcats,$categories,$deeper,$category);
23327: $deeper --;
23328: }
23329: }
23330: }
23331: return;
23332: }
23333:
23334: sub recurse_cat_deletes {
23335: my ($item,$coursecategories,$deletions) = @_;
23336: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23337: my $subdepth = $depth + 1;
23338: if (ref($coursecategories) eq 'HASH') {
23339: foreach my $subitem (keys(%{$coursecategories})) {
23340: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23341: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23342: delete($coursecategories->{$subitem});
23343: $deletions->{$subitem} = 1;
23344: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23345: }
1.48 raeburn 23346: }
23347: }
23348: return;
23349: }
23350:
1.125 raeburn 23351: sub active_dc_picker {
1.191 raeburn 23352: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23353: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23354: my @domcoord = keys(%domcoords);
23355: if (keys(%currhash)) {
23356: foreach my $dc (keys(%currhash)) {
23357: unless (exists($domcoords{$dc})) {
23358: push(@domcoord,$dc);
23359: }
23360: }
23361: }
23362: @domcoord = sort(@domcoord);
1.210 raeburn 23363: my $numdcs = scalar(@domcoord);
1.191 raeburn 23364: my $rows = 0;
23365: my $table;
1.125 raeburn 23366: if ($numdcs > 1) {
1.191 raeburn 23367: $table = '<table>';
23368: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23369: my $rem = $i%($numinrow);
23370: if ($rem == 0) {
23371: if ($i > 0) {
1.191 raeburn 23372: $table .= '</tr>';
1.125 raeburn 23373: }
1.191 raeburn 23374: $table .= '<tr>';
23375: $rows ++;
1.125 raeburn 23376: }
1.191 raeburn 23377: my $check = '';
23378: if ($inputtype eq 'radio') {
23379: if (keys(%currhash) == 0) {
23380: if (!$i) {
23381: $check = ' checked="checked"';
23382: }
23383: } elsif (exists($currhash{$domcoord[$i]})) {
23384: $check = ' checked="checked"';
23385: }
23386: } else {
23387: if (exists($currhash{$domcoord[$i]})) {
23388: $check = ' checked="checked"';
1.125 raeburn 23389: }
23390: }
1.191 raeburn 23391: if ($i == @domcoord - 1) {
1.125 raeburn 23392: my $colsleft = $numinrow - $rem;
23393: if ($colsleft > 1) {
1.191 raeburn 23394: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23395: } else {
1.191 raeburn 23396: $table .= '<td class="LC_left_item">';
1.125 raeburn 23397: }
23398: } else {
1.191 raeburn 23399: $table .= '<td class="LC_left_item">';
23400: }
23401: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23402: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23403: $table .= '<span class="LC_nobreak"><label>'.
23404: '<input type="'.$inputtype.'" name="'.$name.'"'.
23405: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23406: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23407: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23408: }
1.219 raeburn 23409: $table .= '</label></span></td>';
1.191 raeburn 23410: }
23411: $table .= '</tr></table>';
23412: } elsif ($numdcs == 1) {
1.219 raeburn 23413: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23414: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23415: if ($inputtype eq 'radio') {
1.247 raeburn 23416: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23417: if ($user ne $dcname.':'.$dcdom) {
23418: $table .= ' ('.$dcname.':'.$dcdom.')';
23419: }
1.191 raeburn 23420: } else {
23421: my $check;
23422: if (exists($currhash{$domcoord[0]})) {
23423: $check = ' checked="checked"';
1.125 raeburn 23424: }
1.247 raeburn 23425: $table = '<span class="LC_nobreak"><label>'.
23426: '<input type="checkbox" name="'.$name.'" '.
23427: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23428: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23429: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23430: }
1.220 raeburn 23431: $table .= '</label></span>';
1.191 raeburn 23432: $rows ++;
1.125 raeburn 23433: }
23434: }
1.191 raeburn 23435: return ($numdcs,$table,$rows);
1.125 raeburn 23436: }
23437:
1.137 raeburn 23438: sub usersession_titles {
23439: return &Apache::lonlocal::texthash(
23440: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23441: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23442: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23443: version => 'LON-CAPA version requirement',
1.138 raeburn 23444: excludedomain => 'Allow all, but exclude specific domains',
23445: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23446: primary => 'Primary (checked first)',
1.154 raeburn 23447: default => 'Default',
1.137 raeburn 23448: );
23449: }
23450:
1.152 raeburn 23451: sub id_for_thisdom {
23452: my (%servers) = @_;
23453: my %altids;
23454: foreach my $server (keys(%servers)) {
23455: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23456: if ($serverhome ne $server) {
23457: $altids{$serverhome} = $server;
23458: }
23459: }
23460: return %altids;
23461: }
23462:
1.150 raeburn 23463: sub count_servers {
23464: my ($currbalancer,%servers) = @_;
23465: my (@spares,$numspares);
23466: foreach my $lonhost (sort(keys(%servers))) {
23467: next if ($currbalancer eq $lonhost);
23468: push(@spares,$lonhost);
23469: }
23470: if ($currbalancer) {
23471: $numspares = scalar(@spares);
23472: } else {
23473: $numspares = scalar(@spares) - 1;
23474: }
23475: return ($numspares,@spares);
23476: }
23477:
23478: sub lonbalance_targets_js {
1.171 raeburn 23479: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23480: my $select = &mt('Select');
23481: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23482: if (ref($servers) eq 'HASH') {
23483: $alltargets = join("','",sort(keys(%{$servers})));
23484: my @homedoms;
23485: foreach my $server (sort(keys(%{$servers}))) {
23486: if (&Apache::lonnet::host_domain($server) eq $dom) {
23487: push(@homedoms,'1');
23488: } else {
23489: push(@homedoms,'0');
23490: }
23491: }
23492: $allishome = join("','",@homedoms);
23493: }
23494: if (ref($types) eq 'ARRAY') {
23495: if (@{$types} > 0) {
23496: @alltypes = @{$types};
23497: }
23498: }
23499: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23500: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23501: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23502: if (ref($settings) eq 'HASH') {
23503: %existing = %{$settings};
23504: }
23505: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23506: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23507: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23508: return <<"END";
23509:
23510: <script type="text/javascript">
23511: // <![CDATA[
23512:
1.171 raeburn 23513: currBalancers = new Array('$balancers');
23514:
23515: function toggleTargets(balnum) {
23516: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23517: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23518: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23519: var prevbalancer = prevhostitem.value;
23520: var baltotal = document.getElementById('loadbalancing_total').value;
23521: prevhostitem.value = balancer;
23522: if (prevbalancer != '') {
23523: var prevIdx = currBalancers.indexOf(prevbalancer);
23524: if (prevIdx != -1) {
23525: currBalancers.splice(prevIdx,1);
23526: }
23527: }
1.150 raeburn 23528: if (balancer == '') {
1.171 raeburn 23529: hideSpares(balnum);
1.150 raeburn 23530: } else {
1.171 raeburn 23531: var currIdx = currBalancers.indexOf(balancer);
23532: if (currIdx == -1) {
23533: currBalancers.push(balancer);
23534: }
1.150 raeburn 23535: var homedoms = new Array('$allishome');
1.171 raeburn 23536: var ishomedom = homedoms[lonhostitem.selectedIndex];
23537: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23538: }
1.171 raeburn 23539: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23540: return;
23541: }
23542:
1.171 raeburn 23543: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23544: var alltargets = new Array('$alltargets');
23545: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23546: var offloadtypes = new Array('primary','default');
23547:
1.171 raeburn 23548: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23549: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23550:
1.151 raeburn 23551: for (var i=0; i<offloadtypes.length; i++) {
23552: var count = 0;
23553: for (var j=0; j<alltargets.length; j++) {
23554: if (alltargets[j] != balancer) {
1.171 raeburn 23555: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23556: item.value = alltargets[j];
23557: item.style.textAlign='left';
23558: item.style.textFace='normal';
23559: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23560: if (currBalancers.indexOf(alltargets[j]) == -1) {
23561: item.disabled = '';
23562: } else {
23563: item.disabled = 'disabled';
23564: item.checked = false;
23565: }
1.151 raeburn 23566: count ++;
23567: }
1.150 raeburn 23568: }
23569: }
1.151 raeburn 23570: for (var k=0; k<insttypes.length; k++) {
23571: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23572: if (ishomedom == 1) {
1.171 raeburn 23573: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23574: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23575: } else {
1.171 raeburn 23576: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23577: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23578: }
23579: } else {
1.171 raeburn 23580: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23581: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23582: }
1.151 raeburn 23583: if ((insttypes[k] != '_LC_external') &&
23584: ((insttypes[k] != '_LC_internetdom') ||
23585: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23586: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23587: item.options.length = 0;
23588: item.options[0] = new Option("","",true,true);
1.210 raeburn 23589: var idx = 0;
1.151 raeburn 23590: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23591: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23592: idx ++;
23593: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23594: }
23595: }
23596: }
23597: }
23598: return;
23599: }
23600:
1.171 raeburn 23601: function hideSpares(balnum) {
1.150 raeburn 23602: var alltargets = new Array('$alltargets');
23603: var insttypes = new Array('$allinsttypes');
23604: var offloadtypes = new Array('primary','default');
23605:
1.171 raeburn 23606: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23607: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23608:
23609: var total = alltargets.length - 1;
23610: for (var i=0; i<offloadtypes; i++) {
23611: for (var j=0; j<total; j++) {
1.171 raeburn 23612: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23613: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23614: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23615: }
1.150 raeburn 23616: }
23617: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23618: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23619: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23620: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23621: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23622: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23623: }
23624: }
23625: return;
23626: }
23627:
1.171 raeburn 23628: function checkOffloads(item,balnum,type) {
1.150 raeburn 23629: var alltargets = new Array('$alltargets');
23630: var offloadtypes = new Array('primary','default');
23631: if (item.checked) {
23632: var total = alltargets.length - 1;
23633: var other;
23634: if (type == offloadtypes[0]) {
1.151 raeburn 23635: other = offloadtypes[1];
1.150 raeburn 23636: } else {
1.151 raeburn 23637: other = offloadtypes[0];
1.150 raeburn 23638: }
23639: for (var i=0; i<total; i++) {
1.171 raeburn 23640: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23641: if (server == item.value) {
1.171 raeburn 23642: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23643: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23644: }
23645: }
23646: }
23647: }
23648: return;
23649: }
23650:
1.171 raeburn 23651: function singleServerToggle(balnum,type) {
23652: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23653: if (offloadtoSelIdx == 0) {
1.171 raeburn 23654: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23655: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23656:
23657: } else {
1.171 raeburn 23658: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23659: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23660: }
23661: return;
23662: }
23663:
1.171 raeburn 23664: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23665: if (type == '_LC_external') {
1.171 raeburn 23666: return;
1.150 raeburn 23667: }
1.171 raeburn 23668: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23669: for (var i=0; i<typesRules.length; i++) {
23670: if (formname.elements[typesRules[i]].checked) {
23671: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23672: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23673: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23674: } else {
1.171 raeburn 23675: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23676: }
23677: }
23678: }
23679: return;
23680: }
23681:
23682: function balancerDeleteChange(balnum) {
23683: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23684: var baltotal = document.getElementById('loadbalancing_total').value;
23685: var addtarget;
23686: var removetarget;
23687: var action = 'delete';
23688: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23689: var lonhost = hostitem.value;
23690: var currIdx = currBalancers.indexOf(lonhost);
23691: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23692: if (currIdx != -1) {
23693: currBalancers.splice(currIdx,1);
23694: }
23695: addtarget = lonhost;
23696: } else {
23697: if (currIdx == -1) {
23698: currBalancers.push(lonhost);
23699: }
23700: removetarget = lonhost;
23701: action = 'undelete';
23702: }
23703: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23704: }
23705: return;
23706: }
23707:
23708: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23709: if (baltotal > 1) {
23710: var offloadtypes = new Array('primary','default');
23711: var alltargets = new Array('$alltargets');
23712: var insttypes = new Array('$allinsttypes');
23713: for (var i=0; i<baltotal; i++) {
23714: if (i != balnum) {
23715: for (var j=0; j<offloadtypes.length; j++) {
23716: var total = alltargets.length - 1;
23717: for (var k=0; k<total; k++) {
23718: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23719: var server = serveritem.value;
23720: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23721: if (server == addtarget) {
23722: serveritem.disabled = '';
23723: }
23724: }
23725: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23726: if (server == removetarget) {
23727: serveritem.disabled = 'disabled';
23728: serveritem.checked = false;
23729: }
23730: }
23731: }
23732: }
23733: for (var j=0; j<insttypes.length; j++) {
23734: if (insttypes[j] != '_LC_external') {
23735: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23736: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23737: var currSel = singleserver.selectedIndex;
23738: var currVal = singleserver.options[currSel].value;
23739: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23740: var numoptions = singleserver.options.length;
23741: var needsnew = 1;
23742: for (var k=0; k<numoptions; k++) {
23743: if (singleserver.options[k] == addtarget) {
23744: needsnew = 0;
23745: break;
23746: }
23747: }
23748: if (needsnew == 1) {
23749: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23750: }
23751: }
23752: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23753: singleserver.options.length = 0;
23754: if ((currVal) && (currVal != removetarget)) {
23755: singleserver.options[0] = new Option("","",false,false);
23756: } else {
23757: singleserver.options[0] = new Option("","",true,true);
23758: }
23759: var idx = 0;
23760: for (var m=0; m<alltargets.length; m++) {
23761: if (currBalancers.indexOf(alltargets[m]) == -1) {
23762: idx ++;
23763: if (currVal == alltargets[m]) {
23764: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23765: } else {
23766: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23767: }
23768: }
23769: }
23770: }
23771: }
23772: }
23773: }
1.150 raeburn 23774: }
23775: }
23776: }
23777: return;
23778: }
23779:
1.152 raeburn 23780: // ]]>
23781: </script>
23782:
23783: END
23784: }
23785:
23786: sub new_spares_js {
23787: my @sparestypes = ('primary','default');
23788: my $types = join("','",@sparestypes);
23789: my $select = &mt('Select');
23790: return <<"END";
23791:
23792: <script type="text/javascript">
23793: // <![CDATA[
23794:
23795: function updateNewSpares(formname,lonhost) {
23796: var types = new Array('$types');
23797: var include = new Array();
23798: var exclude = new Array();
23799: for (var i=0; i<types.length; i++) {
23800: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23801: for (var j=0; j<spareboxes.length; j++) {
23802: if (formname.elements[spareboxes[j]].checked) {
23803: exclude.push(formname.elements[spareboxes[j]].value);
23804: } else {
23805: include.push(formname.elements[spareboxes[j]].value);
23806: }
23807: }
23808: }
23809: for (var i=0; i<types.length; i++) {
23810: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23811: var selIdx = newSpare.selectedIndex;
23812: var currnew = newSpare.options[selIdx].value;
23813: var okSpares = new Array();
23814: for (var j=0; j<newSpare.options.length; j++) {
23815: var possible = newSpare.options[j].value;
23816: if (possible != '') {
23817: if (exclude.indexOf(possible) == -1) {
23818: okSpares.push(possible);
23819: } else {
23820: if (currnew == possible) {
23821: selIdx = 0;
23822: }
23823: }
23824: }
23825: }
23826: for (var k=0; k<include.length; k++) {
23827: if (okSpares.indexOf(include[k]) == -1) {
23828: okSpares.push(include[k]);
23829: }
23830: }
23831: okSpares.sort();
23832: newSpare.options.length = 0;
23833: if (selIdx == 0) {
23834: newSpare.options[0] = new Option("$select","",true,true);
23835: } else {
23836: newSpare.options[0] = new Option("$select","",false,false);
23837: }
23838: for (var m=0; m<okSpares.length; m++) {
23839: var idx = m+1;
23840: var selThis = 0;
23841: if (selIdx != 0) {
23842: if (okSpares[m] == currnew) {
23843: selThis = 1;
23844: }
23845: }
23846: if (selThis == 1) {
23847: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23848: } else {
23849: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23850: }
23851: }
23852: }
23853: return;
23854: }
23855:
23856: function checkNewSpares(lonhost,type) {
23857: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23858: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23859: if (chosen != '') {
1.152 raeburn 23860: var othertype;
23861: var othernewSpare;
23862: if (type == 'primary') {
23863: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23864: }
23865: if (type == 'default') {
23866: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23867: }
23868: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23869: othernewSpare.selectedIndex = 0;
23870: }
23871: }
23872: return;
23873: }
23874:
23875: // ]]>
23876: </script>
23877:
23878: END
23879:
23880: }
23881:
23882: sub common_domprefs_js {
23883: return <<"END";
23884:
23885: <script type="text/javascript">
23886: // <![CDATA[
23887:
1.150 raeburn 23888: function getIndicesByName(formname,item) {
1.152 raeburn 23889: var group = new Array();
1.150 raeburn 23890: for (var i=0;i<formname.elements.length;i++) {
23891: if (formname.elements[i].name == item) {
1.152 raeburn 23892: group.push(formname.elements[i].id);
1.150 raeburn 23893: }
23894: }
1.152 raeburn 23895: return group;
1.150 raeburn 23896: }
23897:
23898: // ]]>
23899: </script>
23900:
23901: END
1.152 raeburn 23902:
1.150 raeburn 23903: }
23904:
1.165 raeburn 23905: sub recaptcha_js {
23906: my %lt = &captcha_phrases();
23907: return <<"END";
23908:
23909: <script type="text/javascript">
23910: // <![CDATA[
23911:
23912: function updateCaptcha(caller,context) {
23913: var privitem;
23914: var pubitem;
23915: var privtext;
23916: var pubtext;
1.269 raeburn 23917: var versionitem;
23918: var versiontext;
1.165 raeburn 23919: if (document.getElementById(context+'_recaptchapub')) {
23920: pubitem = document.getElementById(context+'_recaptchapub');
23921: } else {
23922: return;
23923: }
23924: if (document.getElementById(context+'_recaptchapriv')) {
23925: privitem = document.getElementById(context+'_recaptchapriv');
23926: } else {
23927: return;
23928: }
23929: if (document.getElementById(context+'_recaptchapubtxt')) {
23930: pubtext = document.getElementById(context+'_recaptchapubtxt');
23931: } else {
23932: return;
23933: }
23934: if (document.getElementById(context+'_recaptchaprivtxt')) {
23935: privtext = document.getElementById(context+'_recaptchaprivtxt');
23936: } else {
23937: return;
23938: }
1.269 raeburn 23939: if (document.getElementById(context+'_recaptchaversion')) {
23940: versionitem = document.getElementById(context+'_recaptchaversion');
23941: } else {
23942: return;
23943: }
23944: if (document.getElementById(context+'_recaptchavertxt')) {
23945: versiontext = document.getElementById(context+'_recaptchavertxt');
23946: } else {
23947: return;
23948: }
1.165 raeburn 23949: if (caller.checked) {
23950: if (caller.value == 'recaptcha') {
23951: pubitem.type = 'text';
23952: privitem.type = 'text';
23953: pubitem.size = '40';
23954: privitem.size = '40';
23955: pubtext.innerHTML = "$lt{'pub'}";
23956: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 23957: versionitem.type = 'text';
23958: versionitem.size = '3';
1.289 raeburn 23959: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 23960: } else {
23961: pubitem.type = 'hidden';
23962: privitem.type = 'hidden';
1.269 raeburn 23963: versionitem.type = 'hidden';
1.165 raeburn 23964: pubtext.innerHTML = '';
23965: privtext.innerHTML = '';
1.269 raeburn 23966: versiontext.innerHTML = '';
1.165 raeburn 23967: }
23968: }
23969: return;
23970: }
23971:
23972: // ]]>
23973: </script>
23974:
23975: END
23976:
23977: }
23978:
1.236 raeburn 23979: sub toggle_display_js {
1.192 raeburn 23980: return <<"END";
23981:
23982: <script type="text/javascript">
23983: // <![CDATA[
23984:
1.236 raeburn 23985: function toggleDisplay(domForm,caller) {
23986: if (document.getElementById(caller)) {
23987: var divitem = document.getElementById(caller);
23988: var optionsElement = domForm.coursecredits;
1.264 raeburn 23989: var checkval = 1;
23990: var dispval = 'block';
1.303 raeburn 23991: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 23992: if (caller == 'emailoptions') {
1.372 raeburn 23993: optionsElement = domForm.cancreate_email;
1.236 raeburn 23994: }
1.257 raeburn 23995: if (caller == 'studentsubmission') {
23996: optionsElement = domForm.postsubmit;
23997: }
1.264 raeburn 23998: if (caller == 'cloneinstcode') {
23999: optionsElement = domForm.canclone;
24000: checkval = 'instcode';
24001: }
1.303 raeburn 24002: if (selfcreateRegExp.test(caller)) {
24003: optionsElement = domForm.elements[caller];
24004: checkval = 'other';
24005: dispval = 'inline'
24006: }
1.236 raeburn 24007: if (optionsElement.length) {
1.192 raeburn 24008: var currval;
1.236 raeburn 24009: for (var i=0; i<optionsElement.length; i++) {
24010: if (optionsElement[i].checked) {
24011: currval = optionsElement[i].value;
1.192 raeburn 24012: }
24013: }
1.264 raeburn 24014: if (currval == checkval) {
24015: divitem.style.display = dispval;
1.192 raeburn 24016: } else {
1.236 raeburn 24017: divitem.style.display = 'none';
1.192 raeburn 24018: }
24019: }
24020: }
24021: return;
24022: }
24023:
24024: // ]]>
24025: </script>
24026:
24027: END
24028:
24029: }
24030:
1.165 raeburn 24031: sub captcha_phrases {
24032: return &Apache::lonlocal::texthash (
24033: priv => 'Private key',
24034: pub => 'Public key',
24035: original => 'original (CAPTCHA)',
24036: recaptcha => 'successor (ReCAPTCHA)',
24037: notused => 'unused',
1.289 raeburn 24038: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 24039: );
24040: }
24041:
1.205 raeburn 24042: sub devalidate_remote_domconfs {
1.212 raeburn 24043: my ($dom,$cachekeys) = @_;
24044: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 24045: my %servers = &Apache::lonnet::internet_dom_servers($dom);
24046: my %thismachine;
24047: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 24048: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 24049: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 24050: 'ipaccess','trust');
1.386 raeburn 24051: my %cache_by_lonhost;
24052: if (exists($cachekeys->{'samllanding'})) {
24053: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
24054: my %landing = %{$cachekeys->{'samllanding'}};
24055: my %domservers = &Apache::lonnet::get_servers($dom);
24056: if (keys(%domservers)) {
24057: foreach my $server (keys(%domservers)) {
24058: my @cached;
24059: next if ($thismachine{$server});
24060: if ($landing{$server}) {
24061: push(@cached,&escape('samllanding').':'.&escape($server));
24062: }
24063: if (@cached) {
24064: $cache_by_lonhost{$server} = \@cached;
24065: }
24066: }
24067: }
24068: }
24069: }
1.260 raeburn 24070: if (keys(%servers)) {
1.205 raeburn 24071: foreach my $server (keys(%servers)) {
24072: next if ($thismachine{$server});
1.212 raeburn 24073: my @cached;
24074: foreach my $name (@posscached) {
24075: if ($cachekeys->{$name}) {
1.388 raeburn 24076: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 24077: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 24078: foreach my $key (keys(%{$cachekeys->{$name}})) {
24079: push(@cached,&escape($name).':'.&escape($key));
24080: }
24081: }
24082: } else {
24083: push(@cached,&escape($name).':'.&escape($dom));
24084: }
1.212 raeburn 24085: }
24086: }
1.386 raeburn 24087: if ((exists($cache_by_lonhost{$server})) &&
24088: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
24089: push(@cached,@{$cache_by_lonhost{$server}});
24090: }
1.212 raeburn 24091: if (@cached) {
24092: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
24093: }
1.205 raeburn 24094: }
24095: }
24096: return;
24097: }
24098:
1.3 raeburn 24099: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>