Annotation of loncom/interface/domainprefs.pm, revision 1.447.2.4
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.447.2.4! raeburn 4: # $Id: domainprefs.pm,v 1.447.2.3 2025/01/14 13:06:01 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',
7940: expire => 'Password expiration (days)',
1.356 raeburn 7941: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7942: );
7943: if ($position eq 'top') {
7944: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7945: my $shownlinklife = 2;
7946: my $prelink = 'both';
7947: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7948: if (ref($settings) eq 'HASH') {
7949: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7950: $shownlinklife = $settings->{resetlink};
7951: }
7952: if (ref($settings->{resetcase}) eq 'ARRAY') {
7953: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7954: }
7955: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7956: $prelink = $settings->{resetprelink};
7957: }
7958: if (ref($settings->{resetpostlink}) eq 'HASH') {
7959: %postlink = %{$settings->{resetpostlink}};
7960: }
7961: if (ref($settings->{resetemail}) eq 'ARRAY') {
7962: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7963: }
7964: if ($settings->{resetremove}) {
7965: $nostdtext = 1;
7966: }
7967: if ($settings->{resetcustom}) {
7968: $customurl = $settings->{resetcustom};
7969: }
7970: } else {
7971: if (ref($types) eq 'ARRAY') {
7972: foreach my $item (@{$types}) {
7973: $casesens{$item} = 1;
7974: $postlink{$item} = ['username','email'];
7975: }
7976: }
7977: $casesens{'default'} = 1;
7978: $postlink{'default'} = ['username','email'];
7979: $prelink = 'both';
7980: %emailsrc = (
7981: permanent => 1,
7982: critical => 1,
7983: notify => 1,
7984: );
7985: }
7986: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7987: $itemcount ++;
7988: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7989: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7990: '<td class="LC_left_item">'.
7991: '<input type="textbox" value="'.$shownlinklife.'" '.
7992: 'name="passwords_link" size="3" /></td></tr>';
7993: $itemcount ++;
7994: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7995: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7996: '<td class="LC_left_item">';
7997: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7998: foreach my $item (@{$types}) {
7999: my $checkedcase;
8000: if ($casesens{$item}) {
8001: $checkedcase = ' checked="checked"';
8002: }
8003: $datatable .= '<span class="LC_nobreak"><label>'.
8004: '<input type="checkbox" name="passwords_case_sensitive" value="'.
8005: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 8006: '</span> ';
1.354 raeburn 8007: }
8008: }
8009: my $checkedcase;
8010: if ($casesens{'default'}) {
8011: $checkedcase = ' checked="checked"';
8012: }
8013: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8014: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
8015: $othertitle.'</label></span></td>';
8016: $itemcount ++;
8017: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8018: my %checkedpre = (
8019: both => ' checked="checked"',
8020: either => '',
8021: );
8022: if ($prelink eq 'either') {
8023: $checkedpre{either} = ' checked="checked"';
8024: $checkedpre{both} = '';
8025: }
8026: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
8027: '<td class="LC_left_item"><span class="LC_nobreak">'.
8028: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
8029: &mt('Both username and e-mail address').'</label></span> '.
8030: '<span class="LC_nobreak"><label>'.
8031: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
8032: &mt('Either username or e-mail address').'</label></span></td></tr>';
8033: $itemcount ++;
8034: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8035: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
8036: '<td class="LC_left_item">';
8037: my %postlinked;
8038: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8039: foreach my $item (@{$types}) {
8040: undef(%postlinked);
8041: $datatable .= '<fieldset style="display: inline-block;">'.
8042: '<legend>'.$usertypes->{$item}.'</legend>';
8043: if (ref($postlink{$item}) eq 'ARRAY') {
8044: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
8045: }
8046: foreach my $field ('email','username') {
8047: my $checked;
8048: if ($postlinked{$field}) {
8049: $checked = ' checked="checked"';
8050: }
8051: $datatable .= '<span class="LC_nobreak"><label>'.
8052: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
8053: $field.'"'.$checked.' />'.$field.'</label>'.
8054: '<span> ';
8055: }
8056: $datatable .= '</fieldset>';
8057: }
8058: }
8059: if (ref($postlink{'default'}) eq 'ARRAY') {
8060: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
8061: }
8062: $datatable .= '<fieldset style="display: inline-block;">'.
8063: '<legend>'.$othertitle.'</legend>';
8064: foreach my $field ('email','username') {
8065: my $checked;
8066: if ($postlinked{$field}) {
8067: $checked = ' checked="checked"';
8068: }
8069: $datatable .= '<span class="LC_nobreak"><label>'.
8070: '<input type="checkbox" name="passwords_postlink_default" value="'.
8071: $field.'"'.$checked.' />'.$field.'</label>'.
8072: '<span> ';
8073: }
8074: $datatable .= '</fieldset></td></tr>';
8075: $itemcount ++;
8076: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8077: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
8078: '<td class="LC_left_item">';
8079: foreach my $type ('permanent','critical','notify') {
8080: my $checkedemail;
8081: if ($emailsrc{$type}) {
8082: $checkedemail = ' checked="checked"';
8083: }
8084: $datatable .= '<span class="LC_nobreak"><label>'.
8085: '<input type="checkbox" name="passwords_emailsrc" value="'.
8086: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8087: '<span> ';
8088: }
8089: $datatable .= '</td></tr>';
8090: $itemcount ++;
8091: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8092: my $switchserver = &check_switchserver($dom,$confname);
8093: my ($showstd,$noshowstd);
8094: if ($nostdtext) {
8095: $noshowstd = ' checked="checked"';
8096: } else {
8097: $showstd = ' checked="checked"';
8098: }
8099: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8100: '<td class="LC_left_item"><span class="LC_nobreak">'.
8101: &mt('Retain standard text:').
8102: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8103: &mt('Yes').'</label>'.' '.
8104: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8105: &mt('No').'</label></span><br />'.
8106: '<span class="LC_fontsize_small">'.
8107: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8108: &mt('Include custom text:');
8109: if ($customurl) {
1.369 raeburn 8110: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8111: undef,undef,undef,undef,'background-color:#ffffff');
8112: $datatable .= '<span class="LC_nobreak"> '.$link.
8113: '<label><input type="checkbox" name="passwords_custom_del"'.
8114: ' value="1" />'.&mt('Delete?').'</label></span>'.
8115: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8116: }
8117: if ($switchserver) {
8118: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8119: } else {
8120: $datatable .='<span class="LC_nobreak"> '.
8121: '<input type="file" name="passwords_customfile" /></span>';
8122: }
8123: $datatable .= '</td></tr>';
8124: } elsif ($position eq 'middle') {
8125: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8126: my @items = ('intauth_cost','intauth_check','intauth_switch');
8127: my %defaults;
8128: if (ref($domconf{'defaults'}) eq 'HASH') {
8129: %defaults = %{$domconf{'defaults'}};
8130: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8131: $defaults{'intauth_cost'} = 10;
8132: }
8133: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8134: $defaults{'intauth_check'} = 0;
8135: }
8136: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8137: $defaults{'intauth_switch'} = 0;
8138: }
8139: } else {
8140: %defaults = (
8141: 'intauth_cost' => 10,
8142: 'intauth_check' => 0,
8143: 'intauth_switch' => 0,
8144: );
8145: }
8146: foreach my $item (@items) {
8147: if ($itemcount%2) {
8148: $css_class = '';
8149: } else {
8150: $css_class = ' class="LC_odd_row" ';
8151: }
8152: $datatable .= '<tr'.$css_class.'>'.
8153: '<td><span class="LC_nobreak">'.$titles{$item}.
8154: '</span></td><td class="LC_left_item" colspan="3">';
8155: if ($item eq 'intauth_switch') {
8156: my @options = (0,1,2);
8157: my %optiondesc = &Apache::lonlocal::texthash (
8158: 0 => 'No',
8159: 1 => 'Yes',
8160: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8161: );
8162: $datatable .= '<table width="100%">';
8163: foreach my $option (@options) {
8164: my $checked = ' ';
8165: if ($defaults{$item} eq $option) {
8166: $checked = ' checked="checked"';
8167: }
8168: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8169: '<label><input type="radio" name="'.$item.
8170: '" value="'.$option.'"'.$checked.' />'.
8171: $optiondesc{$option}.'</label></span></td></tr>';
8172: }
8173: $datatable .= '</table>';
8174: } elsif ($item eq 'intauth_check') {
8175: my @options = (0,1,2);
8176: my %optiondesc = &Apache::lonlocal::texthash (
8177: 0 => 'No',
8178: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8179: 2 => 'Yes, disallow login if stored cost is less than domain default',
8180: );
8181: $datatable .= '<table width="100%">';
8182: foreach my $option (@options) {
8183: my $checked = ' ';
8184: my $onclick;
8185: if ($defaults{$item} eq $option) {
8186: $checked = ' checked="checked"';
8187: }
8188: if ($option == 2) {
8189: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8190: }
8191: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8192: '<label><input type="radio" name="'.$item.
8193: '" value="'.$option.'"'.$checked.$onclick.' />'.
8194: $optiondesc{$option}.'</label></span></td></tr>';
8195: }
8196: $datatable .= '</table>';
8197: } else {
8198: $datatable .= '<input type="text" name="'.$item.'" value="'.
8199: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8200: }
8201: $datatable .= '</td></tr>';
8202: $itemcount ++;
8203: }
8204: } elsif ($position eq 'lower') {
1.405 raeburn 8205: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8206: } else {
1.359 raeburn 8207: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8208: my %ownerchg = (
8209: by => {},
8210: for => {},
8211: );
8212: my %ownertitles = &Apache::lonlocal::texthash (
8213: by => 'Course owner status(es) allowed',
8214: for => 'Student status(es) allowed',
8215: );
1.354 raeburn 8216: if (ref($settings) eq 'HASH') {
1.359 raeburn 8217: if (ref($settings->{crsownerchg}) eq 'HASH') {
8218: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8219: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8220: }
8221: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8222: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8223: }
1.354 raeburn 8224: }
8225: }
8226: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8227: $datatable .= '<tr '.$css_class.'>'.
8228: '<td>'.
8229: &mt('Requirements').'<ul>'.
1.359 raeburn 8230: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8231: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8232: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8233: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8234: '</ul>'.
8235: '</td>'.
1.359 raeburn 8236: '<td class="LC_left_item">';
8237: foreach my $item ('by','for') {
8238: $datatable .= '<fieldset style="display: inline-block;">'.
8239: '<legend>'.$ownertitles{$item}.'</legend>';
8240: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8241: foreach my $type (@{$types}) {
8242: my $checked;
8243: if ($ownerchg{$item}{$type}) {
8244: $checked = ' checked="checked"';
8245: }
8246: $datatable .= '<span class="LC_nobreak"><label>'.
8247: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8248: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8249: '</span> ';
1.359 raeburn 8250: }
8251: }
8252: my $checked;
8253: if ($ownerchg{$item}{'default'}) {
8254: $checked = ' checked="checked"';
8255: }
8256: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8257: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8258: $othertitle.'</label></span></fieldset>';
8259: }
8260: $datatable .= '</td></tr>';
1.354 raeburn 8261: }
8262: return $datatable;
8263: }
8264:
1.405 raeburn 8265: sub password_rules {
8266: my ($prefix,$itemcountref,$settings) = @_;
8267: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8268: my %titles;
8269: if ($prefix eq 'passwords') {
8270: %titles = &Apache::lonlocal::texthash (
8271: min => 'Minimum password length',
8272: max => 'Maximum password length',
8273: chars => 'Required characters',
8274: );
1.421 raeburn 8275: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8276: %titles = &Apache::lonlocal::texthash (
8277: min => 'Minimum secret length',
8278: max => 'Maximum secret length',
8279: chars => 'Required characters',
8280: );
8281: }
8282: $min = $Apache::lonnet::passwdmin;
8283: my $datatable;
8284: my $itemcount;
8285: if (ref($itemcountref)) {
8286: $itemcount = $$itemcountref;
8287: }
8288: if (ref($settings) eq 'HASH') {
8289: if ($settings->{min}) {
8290: $min = $settings->{min};
8291: }
8292: if ($settings->{max}) {
8293: $max = $settings->{max};
8294: }
8295: if (ref($settings->{chars}) eq 'ARRAY') {
8296: map { $chars{$_} = 1; } (@{$settings->{chars}});
8297: }
1.425 raeburn 8298: if ($prefix eq 'passwords') {
1.405 raeburn 8299: if ($settings->{expire}) {
8300: $expire = $settings->{expire};
8301: }
8302: if ($settings->{numsaved}) {
8303: $numsaved = $settings->{numsaved};
8304: }
8305: }
8306: }
8307: my %rulenames = &Apache::lonlocal::texthash(
8308: uc => 'At least one upper case letter',
8309: lc => 'At least one lower case letter',
8310: num => 'At least one number',
8311: spec => 'At least one non-alphanumeric',
8312: );
8313: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8314: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8315: '<td class="LC_left_item"><span class="LC_nobreak">'.
8316: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8317: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8318: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8319: '</span></td></tr>';
8320: $itemcount ++;
8321: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8322: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8323: '<td class="LC_left_item"><span class="LC_nobreak">'.
8324: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8325: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8326: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8327: '</span></td></tr>';
8328: $itemcount ++;
8329: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8330: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8331: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8332: '</span></td>';
8333: my $numinrow = 2;
8334: my @possrules = ('uc','lc','num','spec');
8335: $datatable .= '<td class="LC_left_item"><table>';
8336: for (my $i=0; $i<@possrules; $i++) {
8337: my ($rem,$checked);
8338: if ($chars{$possrules[$i]}) {
8339: $checked = ' checked="checked"';
8340: }
8341: $rem = $i%($numinrow);
8342: if ($rem == 0) {
8343: if ($i > 0) {
8344: $datatable .= '</tr>';
8345: }
8346: $datatable .= '<tr>';
8347: }
8348: $datatable .= '<td><span class="LC_nobreak"><label>'.
8349: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8350: $rulenames{$possrules[$i]}.'</label></span></td>';
8351: }
8352: my $rem = @possrules%($numinrow);
8353: my $colsleft = $numinrow - $rem;
8354: if ($colsleft > 1 ) {
8355: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8356: ' </td>';
8357: } elsif ($colsleft == 1) {
8358: $datatable .= '<td class="LC_left_item"> </td>';
8359: }
8360: $datatable .='</table></td></tr>';
8361: $itemcount ++;
8362: if ($prefix eq 'passwords') {
8363: $titles{'expire'} = &mt('Password expiration (days)');
8364: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8365: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8366: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8367: '<td class="LC_left_item"><span class="LC_nobreak">'.
8368: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8369: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8370: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8371: '</span></td></tr>';
8372: $itemcount ++;
8373: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8374: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8375: '<td class="LC_left_item"><span class="LC_nobreak">'.
8376: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8377: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8378: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8379: '</span></td></tr>';
8380: $itemcount ++;
8381: }
8382: if (ref($itemcountref)) {
8383: $$itemcountref += $itemcount;
8384: }
8385: return $datatable;
8386: }
8387:
1.373 raeburn 8388: sub print_wafproxy {
8389: my ($position,$dom,$settings,$rowtotal) = @_;
8390: my $css_class;
8391: my $itemcount = 0;
8392: my $datatable;
8393: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8394: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8395: my %lt = &wafproxy_titles();
1.373 raeburn 8396: foreach my $server (sort(keys(%servers))) {
8397: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8398: next if ($serverhome eq '');
1.373 raeburn 8399: my $serverdom;
8400: if ($serverhome ne $server) {
8401: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8402: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8403: $othercontrol{$server} = $serverdom;
8404: }
1.373 raeburn 8405: } else {
8406: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8407: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8408: if ($serverdom ne $dom) {
8409: $othercontrol{$server} = $serverdom;
8410: } else {
8411: $setdom = 1;
8412: if (ref($settings) eq 'HASH') {
8413: if (ref($settings->{'alias'}) eq 'HASH') {
8414: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8415: if ($aliases{$dom} ne '') {
8416: $showdom = 1;
8417: }
1.373 raeburn 8418: }
1.388 raeburn 8419: if (ref($settings->{'saml'}) eq 'HASH') {
8420: $saml{$dom} = $settings->{'saml'};
8421: }
1.373 raeburn 8422: }
8423: }
8424: }
8425: }
1.381 raeburn 8426: if ($setdom) {
8427: %{$values{$dom}} = ();
8428: if (ref($settings) eq 'HASH') {
8429: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8430: $values{$dom}{$item} = $settings->{$item};
8431: }
8432: }
8433: }
1.373 raeburn 8434: if (keys(%othercontrol)) {
8435: %otherdoms = reverse(%othercontrol);
8436: foreach my $domain (keys(%otherdoms)) {
8437: %{$values{$domain}} = ();
8438: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8439: if (ref($config{'wafproxy'}) eq 'HASH') {
8440: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8441: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8442: $saml{$domain} = $config{'wafproxy'}{'saml'};
8443: }
1.383 raeburn 8444: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8445: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8446: }
8447: }
8448: }
8449: }
8450: if ($position eq 'top') {
8451: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8452: my %aliasinfo;
1.373 raeburn 8453: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8454: $itemcount ++;
8455: my $dom_in_effect;
8456: my $aliasrows = '<tr>'.
1.383 raeburn 8457: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.433 raeburn 8458: &mt('Hostname').': '.
8459: '<span class="LC_nobreak LC_cusr_emph">'.
8460: &Apache::lonnet::hostname($server).
8461: '</span></td><td> </td>';
1.373 raeburn 8462: if ($othercontrol{$server}) {
1.381 raeburn 8463: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8464: my ($current,$forsaml);
1.383 raeburn 8465: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8466: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8467: }
1.388 raeburn 8468: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8469: if ($saml{$dom_in_effect}{$server}) {
8470: $forsaml = 1;
8471: }
8472: }
1.383 raeburn 8473: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8474: &mt('Alias').': ';
1.373 raeburn 8475: if ($current) {
1.381 raeburn 8476: $aliasrows .= $current;
1.388 raeburn 8477: if ($forsaml) {
1.396 raeburn 8478: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8479: }
1.373 raeburn 8480: } else {
1.383 raeburn 8481: $aliasrows .= &mt('None');
1.373 raeburn 8482: }
1.383 raeburn 8483: $aliasrows .= ' <span class="LC_small">('.
8484: &mt('controlled by domain: [_1]',
8485: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8486: } else {
1.381 raeburn 8487: $dom_in_effect = $dom;
1.388 raeburn 8488: my ($current,$samlon,$samloff);
8489: $samloff = ' checked="checked"';
1.373 raeburn 8490: if (ref($aliases{$dom}) eq 'HASH') {
8491: if ($aliases{$dom}{$server}) {
8492: $current = $aliases{$dom}{$server};
8493: }
8494: }
1.388 raeburn 8495: if (ref($saml{$dom}) eq 'HASH') {
8496: if ($saml{$dom}{$server}) {
8497: $samlon = $samloff;
8498: undef($samloff);
8499: }
8500: }
1.383 raeburn 8501: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8502: &mt('Alias').': '.
1.381 raeburn 8503: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8504: 'value="'.$current.'" size="30" />'.
8505: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8506: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8507: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8508: &mt('No').'</label> <label>'.
1.388 raeburn 8509: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8510: &mt('Yes').'</label></span>'.
1.425 raeburn 8511: '</td>';
1.381 raeburn 8512: }
8513: $aliasrows .= '</tr>';
8514: $aliasinfo{$dom_in_effect} .= $aliasrows;
8515: }
8516: if ($aliasinfo{$dom}) {
8517: my ($onclick,$wafon,$wafoff,$showtable);
8518: $onclick = ' onclick="javascript:toggleWAF();"';
8519: $wafoff = ' checked="checked"';
8520: $showtable = ' style="display:none";';
8521: if ($showdom) {
8522: $wafon = $wafoff;
8523: $wafoff = '';
8524: $showtable = ' style="display:inline;"';
8525: }
8526: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8527: $datatable = '<tr'.$css_class.'>'.
8528: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8529: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8530: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8531: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8532: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8533: &mt('No').'</label></span></td>'.
8534: '<td class="LC_left_item">'.
8535: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8536: '</table></td></tr>';
8537: $itemcount++;
8538: }
1.383 raeburn 8539: if (keys(%otherdoms)) {
8540: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8541: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8542: $datatable .= '<tr'.$css_class.'>'.
8543: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8544: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8545: '</table></td></tr>';
1.381 raeburn 8546: $itemcount++;
1.373 raeburn 8547: }
8548: }
8549: } else {
1.383 raeburn 8550: my %ip_methods = &remoteip_methods();
1.373 raeburn 8551: if ($setdom) {
8552: $itemcount ++;
8553: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8554: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8555: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8556: $wafstyle = ' style="display:none;"';
8557: $nowafstyle = ' style="display:table-row;"';
8558: $currwafdisplay = ' style="display: none"';
8559: $wafrangestyle = ' style="display: none"';
8560: $curr_remotip = 'n';
1.382 raeburn 8561: $ssltossl = ' checked="checked"';
1.381 raeburn 8562: if ($showdom) {
8563: $wafstyle = ' style="display:table-row;"';
8564: $nowafstyle = ' style="display:none;"';
8565: if (keys(%{$values{$dom}})) {
8566: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8567: $curr_remotip = $values{$dom}{remoteip};
8568: }
8569: if ($curr_remotip eq 'h') {
8570: $currwafdisplay = ' style="display:table-row"';
8571: $wafrangestyle = ' style="display:inline-block;"';
8572: }
1.382 raeburn 8573: if ($values{$dom}{'sslopt'}) {
8574: $alltossl = ' checked="checked"';
8575: $ssltossl = '';
8576: }
1.381 raeburn 8577: }
8578: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8579: $vpndircheck = ' checked="checked"';
8580: $currwafvpn = ' style="display:table-row;"';
8581: $wafrangestyle = ' style="display:inline-block;"';
8582: } else {
8583: $vpnaliascheck = ' checked="checked"';
8584: $currwafvpn = ' style="display:none;"';
8585: }
8586: }
8587: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8588: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8589: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8590: '</tr>'.
8591: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8592: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8593: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8594: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8595: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8596: '<td class="LC_left_item"><table>'.
8597: '<tr>'.
8598: '<td valign="top">'.$lt{'remoteip'}.': '.
8599: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8600: foreach my $option ('m','h','n') {
8601: my $sel;
8602: if ($option eq $curr_remotip) {
8603: $sel = ' selected="selected"';
8604: }
8605: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8606: $ip_methods{$option}.'</option>';
8607: }
8608: $datatable .= '</select></td></tr>'."\n".
8609: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8610: $lt{'ipheader'}.': '.
8611: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8612: 'name="wafproxy_ipheader" />'.
8613: '</td></tr>'."\n".
8614: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8615: $lt{'trusted'}.':<br />'.
1.381 raeburn 8616: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8617: $values{$dom}{'trusted'}.'</textarea>'.
8618: '</td></tr>'."\n".
8619: '<tr><td><hr /></td></tr>'."\n".
8620: '<tr>'.
8621: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8622: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8623: $lt{'vpndirect'}.'</label>'.(' 'x2).
8624: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8625: $lt{'vpnaliased'}.'</label></span></td></tr>';
8626: foreach my $item ('vpnint','vpnext') {
8627: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8628: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8629: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8630: $values{$dom}{$item}.'</textarea>'.
8631: '</td></tr>'."\n";
1.373 raeburn 8632: }
1.382 raeburn 8633: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8634: '<tr>'.
8635: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8636: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8637: $lt{'alltossl'}.'</label>'.(' 'x2).
8638: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8639: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8640: '</table></td></tr>';
1.373 raeburn 8641: }
8642: if (keys(%otherdoms)) {
8643: foreach my $domain (sort(keys(%otherdoms))) {
8644: $itemcount ++;
8645: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8646: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8647: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8648: '<td class="LC_left_item"><table>';
1.382 raeburn 8649: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8650: my $showval = &mt('None');
1.382 raeburn 8651: if ($item eq 'ssl') {
8652: $showval = $lt{'ssltossl'};
8653: }
1.373 raeburn 8654: if ($values{$domain}{$item}) {
1.381 raeburn 8655: $showval = $values{$domain}{$item};
1.382 raeburn 8656: if ($item eq 'ssl') {
8657: $showval = $lt{'alltossl'};
1.383 raeburn 8658: } elsif ($item eq 'remoteip') {
8659: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8660: }
1.373 raeburn 8661: }
8662: $datatable .= '<tr>'.
8663: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8664: }
1.381 raeburn 8665: $datatable .= '</table></td></tr>';
1.373 raeburn 8666: }
8667: }
8668: }
8669: $$rowtotal += $itemcount;
8670: return $datatable;
8671: }
8672:
8673: sub wafproxy_titles {
8674: return &Apache::lonlocal::texthash(
1.381 raeburn 8675: remoteip => "Method for determining user's IP",
8676: ipheader => 'Request header containing remote IP',
8677: trusted => 'Trusted IP range(s)',
8678: vpnaccess => 'Access from institutional VPN',
8679: vpndirect => 'via regular hostname (no WAF)',
8680: vpnaliased => 'via aliased hostname (WAF)',
8681: vpnint => 'Internal IP Range(s) for VPN sessions',
8682: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8683: sslopt => 'Forwarding http/https',
1.381 raeburn 8684: alltossl => 'WAF forwards both http and https requests to https',
8685: ssltossl => 'WAF forwards http requests to http and https to https',
8686: );
8687: }
8688:
8689: sub remoteip_methods {
8690: return &Apache::lonlocal::texthash(
8691: m => 'Use Apache mod_remoteip',
8692: h => 'Use headers parsed by LON-CAPA',
8693: n => 'Not in use',
1.373 raeburn 8694: );
8695: }
8696:
1.137 raeburn 8697: sub print_usersessions {
8698: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8699: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8700: my (%by_ip,%by_location,@intdoms,@instdoms);
8701: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8702:
8703: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8704: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8705: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8706: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8707: if ($position eq 'top') {
1.152 raeburn 8708: if (keys(%serverhomes) > 1) {
1.145 raeburn 8709: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8710: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8711: if (ref($settings) eq 'HASH') {
8712: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8713: $curroffloadnow = $settings->{'offloadnow'};
8714: }
1.371 raeburn 8715: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8716: $curroffloadoth = $settings->{'offloadoth'};
8717: }
1.261 raeburn 8718: }
1.371 raeburn 8719: my $other_insts = scalar(keys(%by_location));
8720: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8721: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8722: } else {
1.140 raeburn 8723: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8724: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8725: '</td></tr>';
1.140 raeburn 8726: }
1.137 raeburn 8727: } else {
1.279 raeburn 8728: my %titles = &usersession_titles();
8729: my ($prefix,@types);
8730: if ($position eq 'bottom') {
8731: $prefix = 'remote';
8732: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8733: } else {
1.279 raeburn 8734: $prefix = 'hosted';
8735: @types = ('excludedomain','includedomain');
8736: }
8737: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8738: }
8739: $$rowtotal += $itemcount;
8740: return $datatable;
8741: }
8742:
8743: sub rules_by_location {
8744: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8745: my ($datatable,$itemcount,$css_class);
8746: if (keys(%{$by_location}) == 0) {
8747: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8748: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8749: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8750: '</td></tr>';
8751: $itemcount = 1;
8752: } else {
8753: $itemcount = 0;
8754: my $numinrow = 5;
8755: my (%current,%checkedon,%checkedoff);
8756: my @locations = sort(keys(%{$by_location}));
8757: foreach my $type (@{$types}) {
8758: $checkedon{$type} = '';
8759: $checkedoff{$type} = ' checked="checked"';
8760: }
8761: if (ref($settings) eq 'HASH') {
8762: if (ref($settings->{$prefix}) eq 'HASH') {
8763: foreach my $key (keys(%{$settings->{$prefix}})) {
8764: $current{$key} = $settings->{$prefix}{$key};
8765: if ($key eq 'version') {
8766: if ($current{$key} ne '') {
1.145 raeburn 8767: $checkedon{$key} = ' checked="checked"';
8768: $checkedoff{$key} = '';
8769: }
1.279 raeburn 8770: } elsif (ref($current{$key}) eq 'ARRAY') {
8771: $checkedon{$key} = ' checked="checked"';
8772: $checkedoff{$key} = '';
1.137 raeburn 8773: }
8774: }
8775: }
1.279 raeburn 8776: }
8777: foreach my $type (@{$types}) {
8778: next if ($type ne 'version' && !@locations);
8779: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8780: $datatable .= '<tr'.$css_class.'>
8781: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8782: <span class="LC_nobreak">
8783: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8784: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8785: if ($type eq 'version') {
8786: my @lcversions = &Apache::lonnet::all_loncaparevs();
8787: my $selector = '<select name="'.$prefix.'_version">';
8788: foreach my $version (@lcversions) {
8789: my $selected = '';
8790: if ($current{'version'} eq $version) {
8791: $selected = ' selected="selected"';
1.145 raeburn 8792: }
1.279 raeburn 8793: $selector .= ' <option value="'.$version.'"'.
8794: $selected.'>'.$version.'</option>';
8795: }
8796: $selector .= '</select> ';
8797: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8798: } else {
8799: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8800: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8801: ' />'.(' 'x2).
8802: '<input type="button" value="'.&mt('uncheck all').'" '.
8803: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8804: "\n".
8805: '</div><div><table>';
8806: my $rem;
8807: for (my $i=0; $i<@locations; $i++) {
8808: my ($showloc,$value,$checkedtype);
8809: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8810: my $ip = $by_location->{$locations[$i]}->[0];
8811: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8812: $value = join(':',@{$by_ip->{$ip}});
8813: $showloc = join(', ',@{$by_ip->{$ip}});
8814: if (ref($current{$type}) eq 'ARRAY') {
8815: foreach my $loc (@{$by_ip->{$ip}}) {
8816: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8817: $checkedtype = ' checked="checked"';
8818: last;
1.145 raeburn 8819: }
1.138 raeburn 8820: }
8821: }
8822: }
1.137 raeburn 8823: }
1.279 raeburn 8824: $rem = $i%($numinrow);
8825: if ($rem == 0) {
8826: if ($i > 0) {
8827: $datatable .= '</tr>';
8828: }
8829: $datatable .= '<tr>';
8830: }
8831: $datatable .= '<td class="LC_left_item">'.
8832: '<span class="LC_nobreak"><label>'.
8833: '<input type="checkbox" name="'.$prefix.'_'.$type.
8834: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8835: '</label></span></td>';
8836: }
8837: $rem = @locations%($numinrow);
8838: my $colsleft = $numinrow - $rem;
8839: if ($colsleft > 1 ) {
8840: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8841: ' </td>';
8842: } elsif ($colsleft == 1) {
8843: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8844: }
1.279 raeburn 8845: $datatable .= '</tr></table>';
1.137 raeburn 8846: }
1.279 raeburn 8847: $datatable .= '</td></tr>';
8848: $itemcount ++;
1.137 raeburn 8849: }
8850: }
1.279 raeburn 8851: return ($datatable,$itemcount);
1.137 raeburn 8852: }
8853:
1.275 raeburn 8854: sub print_ssl {
8855: my ($position,$dom,$settings,$rowtotal) = @_;
8856: my ($css_class,$datatable);
8857: my $itemcount = 1;
8858: if ($position eq 'top') {
1.281 raeburn 8859: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8860: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8861: my $same_institution;
8862: if ($intdom ne '') {
8863: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8864: if (ref($internet_names) eq 'ARRAY') {
8865: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8866: $same_institution = 1;
8867: }
8868: }
8869: }
1.275 raeburn 8870: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8871: $datatable = '<tr'.$css_class.'><td colspan="2">';
8872: if ($same_institution) {
8873: my %domservers = &Apache::lonnet::get_servers($dom);
8874: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8875: } else {
8876: $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.");
8877: }
8878: $datatable .= '</td></tr>';
1.275 raeburn 8879: $itemcount ++;
8880: } else {
8881: my %titles = &ssl_titles();
8882: my (%by_ip,%by_location,@intdoms,@instdoms);
8883: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8884: my @alldoms = &Apache::lonnet::all_domains();
8885: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8886: my @domservers = &Apache::lonnet::get_servers($dom);
8887: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8888: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8889: if (($position eq 'connto') || ($position eq 'connfrom')) {
8890: my $legacy;
8891: unless (ref($settings) eq 'HASH') {
8892: my $name;
8893: if ($position eq 'connto') {
8894: $name = 'loncAllowInsecure';
8895: } else {
8896: $name = 'londAllowInsecure';
8897: }
8898: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8899: my @ids=&Apache::lonnet::current_machine_ids();
8900: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8901: my %what = (
8902: $name => 1,
8903: );
8904: my ($result,$returnhash) =
8905: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8906: if ($result eq 'ok') {
8907: if (ref($returnhash) eq 'HASH') {
8908: $legacy = $returnhash->{$name};
8909: }
8910: }
8911: } else {
8912: $legacy = $Apache::lonnet::perlvar{$name};
8913: }
8914: }
1.275 raeburn 8915: foreach my $type ('dom','intdom','other') {
8916: my %checked;
8917: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8918: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8919: '<td class="LC_right_item">';
8920: my $skip;
8921: if ($type eq 'dom') {
8922: unless (keys(%servers) > 1) {
8923: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8924: $skip = 1;
8925: }
8926: }
8927: if ($type eq 'intdom') {
8928: unless (@instdoms > 1) {
8929: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8930: $skip = 1;
8931: }
8932: } elsif ($type eq 'other') {
8933: if (keys(%by_location) == 0) {
8934: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8935: $skip = 1;
8936: }
8937: }
8938: unless ($skip) {
8939: $checked{'yes'} = ' checked="checked"';
8940: if (ref($settings) eq 'HASH') {
1.293 raeburn 8941: if (ref($settings->{$position}) eq 'HASH') {
8942: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8943: $checked{$1} = $checked{'yes'};
8944: delete($checked{'yes'});
8945: }
8946: }
1.293 raeburn 8947: } else {
8948: if ($legacy == 0) {
8949: $checked{'req'} = $checked{'yes'};
8950: delete($checked{'yes'});
8951: }
1.275 raeburn 8952: }
8953: foreach my $option ('no','yes','req') {
8954: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8955: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8956: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8957: '</label></span>'.(' 'x2);
8958: }
8959: }
8960: $datatable .= '</td></tr>';
8961: $itemcount ++;
8962: }
8963: } else {
8964: my $prefix = 'replication';
8965: my @types = ('certreq','nocertreq');
1.279 raeburn 8966: if (keys(%by_location) == 0) {
8967: $datatable .= '<tr'.$css_class.'><td>'.
8968: &mt('Nothing to set here, as there are no other institutions').
8969: '</td></tr>';
8970: $itemcount ++;
1.275 raeburn 8971: } else {
1.279 raeburn 8972: ($datatable,$itemcount) =
8973: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8974: }
8975: }
8976: }
8977: $$rowtotal += $itemcount;
8978: return $datatable;
8979: }
8980:
8981: sub ssl_titles {
8982: return &Apache::lonlocal::texthash (
8983: dom => 'LON-CAPA servers/VMs from same domain',
8984: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8985: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8986: connto => 'Connections to other servers',
8987: connfrom => 'Connections from other servers',
1.275 raeburn 8988: replication => 'Replicating content to other institutions',
8989: certreq => 'Client certificate required, but specific domains exempt',
8990: nocertreq => 'No client certificate required, except for specific domains',
8991: no => 'SSL not used',
8992: yes => 'SSL Optional (used if available)',
8993: req => 'SSL Required',
8994: );
1.279 raeburn 8995: }
8996:
8997: sub print_trust {
8998: my ($prefix,$dom,$settings,$rowtotal) = @_;
8999: my ($css_class,$datatable,%checked,%choices);
9000: my (%by_ip,%by_location,@intdoms,@instdoms);
9001: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
9002: my $itemcount = 1;
9003: my %titles = &trust_titles();
9004: my @types = ('exc','inc');
9005: if ($prefix eq 'top') {
9006: $prefix = 'content';
9007: } elsif ($prefix eq 'bottom') {
9008: $prefix = 'msg';
9009: }
9010: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
9011: $$rowtotal += $itemcount;
9012: return $datatable;
9013: }
9014:
9015: sub trust_titles {
9016: return &Apache::lonlocal::texthash(
9017: content => "Access to this domain's content by others",
9018: shared => "Access to other domain's content by this domain",
9019: enroll => "Enrollment in this domain's courses by others",
9020: othcoau => "Co-author roles in this domain for others",
9021: coaurem => "Co-author roles for this domain's users elsewhere",
9022: domroles => "Domain roles in this domain assignable to others",
9023: catalog => "Course Catalog for this domain displayed elsewhere",
9024: reqcrs => "Requests for creation of courses in this domain by others",
9025: msg => "Users in other domains can send messages to this domain",
9026: exc => "Allow all, but exclude specific domains",
9027: inc => "Deny all, but include specific domains",
9028: );
1.275 raeburn 9029: }
9030:
1.138 raeburn 9031: sub build_location_hashes {
1.275 raeburn 9032: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 9033: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 9034: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 9035: my %iphost = &Apache::lonnet::get_iphost();
9036: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
9037: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
9038: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
9039: foreach my $id (@{$iphost{$primary_ip}}) {
9040: my $intdom = &Apache::lonnet::internet_dom($id);
9041: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
9042: push(@{$intdoms},$intdom);
9043: }
9044: }
9045: }
9046: foreach my $ip (keys(%iphost)) {
9047: if (ref($iphost{$ip}) eq 'ARRAY') {
9048: foreach my $id (@{$iphost{$ip}}) {
9049: my $location = &Apache::lonnet::internet_dom($id);
9050: if ($location) {
1.275 raeburn 9051: if (grep(/^\Q$location\E$/,@{$intdoms})) {
9052: my $dom = &Apache::lonnet::host_domain($id);
9053: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
9054: push(@{$instdoms},$dom);
9055: }
9056: next;
9057: }
1.138 raeburn 9058: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9059: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
9060: push(@{$by_ip->{$ip}},$location);
9061: }
9062: } else {
9063: $by_ip->{$ip} = [$location];
9064: }
9065: }
9066: }
9067: }
9068: }
9069: foreach my $ip (sort(keys(%{$by_ip}))) {
9070: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9071: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
9072: my $first = $by_ip->{$ip}->[0];
9073: if (ref($by_location->{$first}) eq 'ARRAY') {
9074: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
9075: push(@{$by_location->{$first}},$ip);
9076: }
9077: } else {
9078: $by_location->{$first} = [$ip];
9079: }
9080: }
9081: }
9082: return;
9083: }
9084:
1.145 raeburn 9085: sub current_offloads_to {
9086: my ($dom,$settings,$servers) = @_;
9087: my (%spareid,%otherdomconfigs);
1.152 raeburn 9088: if (ref($servers) eq 'HASH') {
1.145 raeburn 9089: foreach my $lonhost (sort(keys(%{$servers}))) {
9090: my $gotspares;
1.152 raeburn 9091: if (ref($settings) eq 'HASH') {
9092: if (ref($settings->{'spares'}) eq 'HASH') {
9093: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9094: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9095: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9096: $gotspares = 1;
9097: }
1.145 raeburn 9098: }
9099: }
9100: unless ($gotspares) {
9101: my $gotspares;
9102: my $serverhomeID =
9103: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9104: my $serverhomedom =
9105: &Apache::lonnet::host_domain($serverhomeID);
9106: if ($serverhomedom ne $dom) {
9107: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9108: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9109: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9110: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9111: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9112: $gotspares = 1;
9113: }
9114: }
9115: } else {
9116: $otherdomconfigs{$serverhomedom} =
9117: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9118: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9119: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9120: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9121: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9122: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9123: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9124: $gotspares = 1;
9125: }
9126: }
9127: }
9128: }
9129: }
9130: }
9131: }
9132: unless ($gotspares) {
9133: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9134: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9135: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9136: } else {
9137: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9138: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9139: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9140: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9141: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9142: } else {
1.150 raeburn 9143: my %what = (
9144: spareid => 1,
9145: );
9146: my ($result,$returnhash) =
9147: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9148: if ($result eq 'ok') {
9149: if (ref($returnhash) eq 'HASH') {
9150: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9151: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9152: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9153: }
9154: }
1.145 raeburn 9155: }
9156: }
9157: }
9158: }
9159: }
9160: }
9161: return %spareid;
9162: }
9163:
9164: sub spares_row {
1.371 raeburn 9165: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9166: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9167: my $css_class;
9168: my $numinrow = 4;
9169: my $itemcount = 1;
9170: my $datatable;
1.152 raeburn 9171: my %typetitles = &sparestype_titles();
9172: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9173: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9174: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9175: my ($othercontrol,$serverdom);
9176: if ($serverhome ne $server) {
9177: $serverdom = &Apache::lonnet::host_domain($serverhome);
9178: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9179: } else {
9180: $serverdom = &Apache::lonnet::host_domain($server);
9181: if ($serverdom ne $dom) {
9182: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9183: }
9184: }
9185: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9186: my ($checkednow,$checkedoth);
1.261 raeburn 9187: if (ref($curroffloadnow) eq 'HASH') {
9188: if ($curroffloadnow->{$server}) {
9189: $checkednow = ' checked="checked"';
9190: }
9191: }
1.371 raeburn 9192: if (ref($curroffloadoth) eq 'HASH') {
9193: if ($curroffloadoth->{$server}) {
9194: $checkedoth = ' checked="checked"';
9195: }
9196: }
1.145 raeburn 9197: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9198: $datatable .= '<tr'.$css_class.'>
9199: <td rowspan="2">
1.183 bisitz 9200: <span class="LC_nobreak">'.
9201: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9202: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9203: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9204: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9205: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9206: "\n";
1.371 raeburn 9207: if ($other_insts) {
9208: $datatable .= '<br />'.
9209: '<span class="LC_nobreak">'."\n".
9210: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9211: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9212: "\n";
9213: }
1.145 raeburn 9214: my (%current,%canselect);
1.152 raeburn 9215: my @choices =
9216: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9217: foreach my $type ('primary','default') {
9218: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9219: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9220: my @spares = @{$spareid->{$server}{$type}};
9221: if (@spares > 0) {
1.152 raeburn 9222: if ($othercontrol) {
9223: $current{$type} = join(', ',@spares);
9224: } else {
9225: $current{$type} .= '<table>';
9226: my $numspares = scalar(@spares);
9227: for (my $i=0; $i<@spares; $i++) {
9228: my $rem = $i%($numinrow);
9229: if ($rem == 0) {
9230: if ($i > 0) {
9231: $current{$type} .= '</tr>';
9232: }
9233: $current{$type} .= '<tr>';
1.145 raeburn 9234: }
1.152 raeburn 9235: $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'".');" /> '.
9236: $spareid->{$server}{$type}[$i].
9237: '</label></td>'."\n";
9238: }
9239: my $rem = @spares%($numinrow);
9240: my $colsleft = $numinrow - $rem;
9241: if ($colsleft > 1 ) {
9242: $current{$type} .= '<td colspan="'.$colsleft.
9243: '" class="LC_left_item">'.
9244: ' </td>';
9245: } elsif ($colsleft == 1) {
9246: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9247: }
1.152 raeburn 9248: $current{$type} .= '</tr></table>';
1.150 raeburn 9249: }
1.145 raeburn 9250: }
9251: }
9252: if ($current{$type} eq '') {
9253: $current{$type} = &mt('None specified');
9254: }
1.152 raeburn 9255: if ($othercontrol) {
9256: if ($type eq 'primary') {
9257: $canselect{$type} = $othercontrol;
9258: }
9259: } else {
9260: $canselect{$type} =
9261: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9262: '<select name="newspare_'.$type.'_'.$server.'" '.
9263: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9264: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9265: if (@choices > 0) {
9266: foreach my $lonhost (@choices) {
9267: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9268: }
9269: }
9270: $canselect{$type} .= '</select>'."\n";
9271: }
9272: } else {
9273: $current{$type} = &mt('Could not be determined');
9274: if ($type eq 'primary') {
9275: $canselect{$type} = $othercontrol;
9276: }
1.145 raeburn 9277: }
1.152 raeburn 9278: if ($type eq 'default') {
9279: $datatable .= '<tr'.$css_class.'>';
9280: }
9281: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9282: '<td>'.$current{$type}.'</td>'."\n".
9283: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9284: }
9285: $itemcount ++;
9286: }
9287: }
9288: $$rowtotal += $itemcount;
9289: return $datatable;
9290: }
9291:
1.152 raeburn 9292: sub possible_newspares {
9293: my ($server,$currspares,$serverhomes,$altids) = @_;
9294: my $serverhostname = &Apache::lonnet::hostname($server);
9295: my %excluded;
9296: if ($serverhostname ne '') {
9297: %excluded = (
9298: $serverhostname => 1,
9299: );
9300: }
9301: if (ref($currspares) eq 'HASH') {
9302: foreach my $type (keys(%{$currspares})) {
9303: if (ref($currspares->{$type}) eq 'ARRAY') {
9304: if (@{$currspares->{$type}} > 0) {
9305: foreach my $curr (@{$currspares->{$type}}) {
9306: my $hostname = &Apache::lonnet::hostname($curr);
9307: $excluded{$hostname} = 1;
9308: }
9309: }
9310: }
9311: }
9312: }
9313: my @choices;
9314: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9315: if (keys(%{$serverhomes}) > 1) {
9316: foreach my $name (sort(keys(%{$serverhomes}))) {
9317: unless ($excluded{$name}) {
9318: if (exists($altids->{$serverhomes->{$name}})) {
9319: push(@choices,$altids->{$serverhomes->{$name}});
9320: } else {
9321: push(@choices,$serverhomes->{$name});
1.145 raeburn 9322: }
9323: }
9324: }
9325: }
9326: }
1.152 raeburn 9327: return sort(@choices);
1.145 raeburn 9328: }
9329:
1.150 raeburn 9330: sub print_loadbalancing {
9331: my ($dom,$settings,$rowtotal) = @_;
9332: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9333: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9334: my $numinrow = 1;
9335: my $datatable;
9336: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9337: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9338: if (ref($settings) eq 'HASH') {
9339: %existing = %{$settings};
9340: }
9341: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9342: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9343: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9344: } else {
9345: return;
9346: }
9347: my ($othertitle,$usertypes,$types) =
9348: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9349: my $rownum = 8;
1.150 raeburn 9350: if (ref($types) eq 'ARRAY') {
9351: $rownum += scalar(@{$types});
9352: }
1.171 raeburn 9353: my @css_class = ('LC_odd_row','LC_even_row');
9354: my $balnum = 0;
9355: my $islast;
9356: my (@toshow,$disabledtext);
9357: if (keys(%currbalancer) > 0) {
9358: @toshow = sort(keys(%currbalancer));
9359: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9360: push(@toshow,'');
9361: }
9362: } else {
9363: @toshow = ('');
9364: $disabledtext = &mt('No existing load balancer');
9365: }
9366: foreach my $lonhost (@toshow) {
9367: if ($balnum == scalar(@toshow)-1) {
9368: $islast = 1;
9369: } else {
9370: $islast = 0;
9371: }
9372: my $cssidx = $balnum%2;
9373: my $targets_div_style = 'display: none';
9374: my $disabled_div_style = 'display: block';
9375: my $homedom_div_style = 'display: none';
9376: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9377: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9378: '<p>';
9379: if ($lonhost eq '') {
1.210 raeburn 9380: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9381: if (keys(%currbalancer) > 0) {
9382: $datatable .= &mt('Add balancer:');
9383: } else {
9384: $datatable .= &mt('Enable balancer:');
9385: }
9386: $datatable .= ' '.
9387: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9388: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9389: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9390: '<option value="" selected="selected">'.&mt('None').
9391: '</option>'."\n";
9392: foreach my $server (sort(keys(%servers))) {
9393: next if ($currbalancer{$server});
9394: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9395: }
1.210 raeburn 9396: $datatable .=
1.171 raeburn 9397: '</select>'."\n".
9398: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9399: } else {
9400: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9401: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9402: &mt('Stop balancing').'</label>'.
9403: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9404: $targets_div_style = 'display: block';
9405: $disabled_div_style = 'display: none';
9406: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9407: $homedom_div_style = 'display: block';
9408: }
9409: }
1.306 raeburn 9410: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9411: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9412: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9413: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9414: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9415: my @sparestypes = ('primary','default');
9416: my %typetitles = &sparestype_titles();
1.284 raeburn 9417: my %hostherechecked = (
9418: no => ' checked="checked"',
9419: );
1.342 raeburn 9420: my %balcookiechecked = (
1.425 raeburn 9421: no => ' checked="checked"',
1.342 raeburn 9422: );
1.171 raeburn 9423: foreach my $sparetype (@sparestypes) {
9424: my $targettable;
9425: for (my $i=0; $i<$numspares; $i++) {
9426: my $checked;
9427: if (ref($currtargets{$lonhost}) eq 'HASH') {
9428: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9429: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9430: $checked = ' checked="checked"';
9431: }
9432: }
9433: }
9434: my ($chkboxval,$disabled);
9435: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9436: $chkboxval = $spares[$i];
9437: }
9438: if (exists($currbalancer{$spares[$i]})) {
9439: $disabled = ' disabled="disabled"';
9440: }
1.210 raeburn 9441: $targettable .=
1.253 raeburn 9442: '<td><span class="LC_nobreak"><label>'.
9443: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9444: $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 9445: '</span></label></span></td>';
1.171 raeburn 9446: my $rem = $i%($numinrow);
9447: if ($rem == 0) {
9448: if (($i > 0) && ($i < $numspares-1)) {
9449: $targettable .= '</tr>';
9450: }
9451: if ($i < $numspares-1) {
9452: $targettable .= '<tr>';
1.150 raeburn 9453: }
9454: }
9455: }
1.171 raeburn 9456: if ($targettable ne '') {
9457: my $rem = $numspares%($numinrow);
9458: my $colsleft = $numinrow - $rem;
9459: if ($colsleft > 1 ) {
9460: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9461: ' </td>';
9462: } elsif ($colsleft == 1) {
9463: $targettable .= '<td class="LC_left_item"> </td>';
9464: }
9465: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9466: '<table><tr>'.$targettable.'</tr></table><br />';
9467: }
1.284 raeburn 9468: $hostherechecked{$sparetype} = '';
9469: if (ref($currtargets{$lonhost}) eq 'HASH') {
9470: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9471: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9472: $hostherechecked{$sparetype} = ' checked="checked"';
9473: $hostherechecked{'no'} = '';
9474: }
9475: }
9476: }
9477: }
1.342 raeburn 9478: if ($currcookies{$lonhost}) {
9479: %balcookiechecked = (
9480: yes => ' checked="checked"',
9481: );
9482: }
1.284 raeburn 9483: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9484: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9485: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9486: foreach my $sparetype (@sparestypes) {
9487: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9488: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9489: '</i></label><br />';
1.171 raeburn 9490: }
1.342 raeburn 9491: $datatable .= &mt('Use balancer cookie').'<br />'.
9492: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9493: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9494: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9495: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9496: '</div></td></tr>'.
1.171 raeburn 9497: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9498: $othertitle,$usertypes,$types,\%servers,
9499: \%currbalancer,$lonhost,
9500: $targets_div_style,$homedom_div_style,
9501: $css_class[$cssidx],$balnum,$islast);
9502: $$rowtotal += $rownum;
9503: $balnum ++;
9504: }
9505: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9506: return $datatable;
9507: }
9508:
9509: sub get_loadbalancers_config {
1.342 raeburn 9510: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9511: return unless ((ref($servers) eq 'HASH') &&
9512: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9513: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9514: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9515: if (keys(%{$existing}) > 0) {
9516: my $oldlonhost;
9517: foreach my $key (sort(keys(%{$existing}))) {
9518: if ($key eq 'lonhost') {
9519: $oldlonhost = $existing->{'lonhost'};
9520: $currbalancer->{$oldlonhost} = 1;
9521: } elsif ($key eq 'targets') {
9522: if ($oldlonhost) {
9523: $currtargets->{$oldlonhost} = $existing->{'targets'};
9524: }
9525: } elsif ($key eq 'rules') {
9526: if ($oldlonhost) {
9527: $currrules->{$oldlonhost} = $existing->{'rules'};
9528: }
9529: } elsif (ref($existing->{$key}) eq 'HASH') {
9530: $currbalancer->{$key} = 1;
9531: $currtargets->{$key} = $existing->{$key}{'targets'};
9532: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9533: if ($existing->{$key}{'cookie'}) {
9534: $currcookies->{$key} = 1;
9535: }
1.150 raeburn 9536: }
9537: }
1.171 raeburn 9538: } else {
9539: my ($balancerref,$targetsref) =
9540: &Apache::lonnet::get_lonbalancer_config($servers);
9541: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9542: foreach my $server (sort(keys(%{$balancerref}))) {
9543: $currbalancer->{$server} = 1;
9544: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9545: }
9546: }
9547: }
1.171 raeburn 9548: return;
1.150 raeburn 9549: }
9550:
9551: sub loadbalancing_rules {
9552: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9553: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9554: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9555: my $output;
1.171 raeburn 9556: my $num = 0;
1.210 raeburn 9557: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9558: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9559: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9560: foreach my $type (@{$alltypes}) {
1.171 raeburn 9561: $num ++;
1.150 raeburn 9562: my $current;
9563: if (ref($currrules) eq 'HASH') {
9564: $current = $currrules->{$type};
9565: }
1.253 raeburn 9566: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9567: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9568: $current = '';
9569: }
9570: }
9571: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9572: $servers,$currbalancer,$lonhost,$dom,
9573: $targets_div_style,$homedom_div_style,
9574: $css_class,$balnum,$num,$islast);
1.150 raeburn 9575: }
9576: }
9577: return $output;
9578: }
9579:
9580: sub loadbalancing_titles {
9581: my ($dom,$intdom,$usertypes,$types) = @_;
9582: my %othertypes = (
9583: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9584: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9585: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9586: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9587: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9588: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9589: );
1.209 raeburn 9590: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9591: my @available;
1.150 raeburn 9592: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9593: @available = @{$types};
1.150 raeburn 9594: }
1.302 raeburn 9595: unless (grep(/^default$/,@available)) {
9596: push(@available,'default');
9597: }
9598: unshift(@alltypes,@available);
1.150 raeburn 9599: my %titles;
9600: foreach my $type (@alltypes) {
9601: if ($type =~ /^_LC_/) {
9602: $titles{$type} = $othertypes{$type};
9603: } elsif ($type eq 'default') {
9604: $titles{$type} = &mt('All users from [_1]',$dom);
9605: if (ref($types) eq 'ARRAY') {
9606: if (@{$types} > 0) {
9607: $titles{$type} = &mt('Other users from [_1]',$dom);
9608: }
9609: }
9610: } elsif (ref($usertypes) eq 'HASH') {
9611: $titles{$type} = $usertypes->{$type};
9612: }
9613: }
9614: return (\@alltypes,\%othertypes,\%titles);
9615: }
9616:
9617: sub loadbalance_rule_row {
1.171 raeburn 9618: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9619: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9620: my @rulenames;
1.150 raeburn 9621: my %ruletitles = &offloadtype_text();
1.209 raeburn 9622: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9623: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9624: } else {
1.209 raeburn 9625: @rulenames = ('default','homeserver');
9626: if ($type eq '_LC_external') {
9627: push(@rulenames,'externalbalancer');
9628: } else {
9629: push(@rulenames,'specific');
9630: }
9631: push(@rulenames,'none');
1.150 raeburn 9632: }
9633: my $style = $targets_div_style;
1.253 raeburn 9634: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9635: $style = $homedom_div_style;
9636: }
1.171 raeburn 9637: my $space;
9638: if ($islast && $num == 1) {
1.317 raeburn 9639: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9640: }
1.210 raeburn 9641: my $output =
1.306 raeburn 9642: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9643: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9644: '<td valaign="top">'.$space.
9645: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9646: for (my $i=0; $i<@rulenames; $i++) {
9647: my $rule = $rulenames[$i];
9648: my ($checked,$extra);
9649: if ($rulenames[$i] eq 'default') {
9650: $rule = '';
9651: }
9652: if ($rulenames[$i] eq 'specific') {
9653: if (ref($servers) eq 'HASH') {
9654: my $default;
9655: if (($current ne '') && (exists($servers->{$current}))) {
9656: $checked = ' checked="checked"';
9657: }
9658: unless ($checked) {
9659: $default = ' selected="selected"';
9660: }
1.210 raeburn 9661: $extra =
1.171 raeburn 9662: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9663: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9664: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9665: '<option value=""'.$default.'></option>'."\n";
9666: foreach my $server (sort(keys(%{$servers}))) {
9667: if (ref($currbalancer) eq 'HASH') {
9668: next if (exists($currbalancer->{$server}));
9669: }
1.150 raeburn 9670: my $selected;
1.171 raeburn 9671: if ($server eq $current) {
1.150 raeburn 9672: $selected = ' selected="selected"';
9673: }
1.171 raeburn 9674: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9675: }
9676: $extra .= '</select>';
9677: }
9678: } elsif ($rule eq $current) {
9679: $checked = ' checked="checked"';
9680: }
9681: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9682: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9683: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9684: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9685: ')"'.$checked.' /> ';
9686: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9687: $output .= $ruletitles{'particular'};
9688: } else {
9689: $output .= $ruletitles{$rulenames[$i]};
9690: }
9691: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9692: }
9693: $output .= '</div></td></tr>'."\n";
9694: return $output;
9695: }
9696:
9697: sub offloadtype_text {
9698: my %ruletitles = &Apache::lonlocal::texthash (
9699: 'default' => 'Offloads to default destinations',
9700: 'homeserver' => "Offloads to user's home server",
9701: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9702: 'specific' => 'Offloads to specific server',
1.161 raeburn 9703: 'none' => 'No offload',
1.209 raeburn 9704: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9705: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9706: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9707: );
9708: return %ruletitles;
9709: }
9710:
9711: sub sparestype_titles {
9712: my %typestitles = &Apache::lonlocal::texthash (
9713: 'primary' => 'primary',
9714: 'default' => 'default',
9715: );
9716: return %typestitles;
9717: }
9718:
1.28 raeburn 9719: sub contact_titles {
9720: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9721: 'supportemail' => 'Support E-mail address',
9722: 'adminemail' => 'Default Server Admin E-mail address',
9723: 'errormail' => 'Error reports to be e-mailed to',
9724: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9725: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9726: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9727: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9728: 'requestsmail' => 'E-mail from course requests requiring approval',
9729: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9730: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9731: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9732: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9733: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9734: 'errorweights' => 'Weights used to compute error count',
9735: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9736: );
9737: my %short_titles = &Apache::lonlocal::texthash (
9738: adminemail => 'Admin E-mail address',
9739: supportemail => 'Support E-mail',
9740: );
9741: return (\%titles,\%short_titles);
9742: }
9743:
1.286 raeburn 9744: sub helpform_fields {
9745: my %titles = &Apache::lonlocal::texthash (
9746: 'username' => 'Name',
9747: 'user' => 'Username/domain',
9748: 'phone' => 'Phone',
9749: 'cc' => 'Cc e-mail',
9750: 'course' => 'Course Details',
9751: 'section' => 'Sections',
1.289 raeburn 9752: 'screenshot' => 'File upload',
1.286 raeburn 9753: );
9754: my @fields = ('username','phone','user','course','section','cc','screenshot');
9755: my %possoptions = (
9756: username => ['yes','no','req'],
1.289 raeburn 9757: phone => ['yes','no','req'],
1.286 raeburn 9758: user => ['yes','no'],
1.289 raeburn 9759: cc => ['yes','no'],
1.286 raeburn 9760: course => ['yes','no'],
9761: section => ['yes','no'],
9762: screenshot => ['yes','no'],
9763: );
9764: my %fieldoptions = &Apache::lonlocal::texthash (
9765: 'yes' => 'Optional',
9766: 'req' => 'Required',
9767: 'no' => "Not shown",
9768: );
9769: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9770: }
9771:
1.72 raeburn 9772: sub tool_titles {
9773: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9774: aboutme => 'Personal web page',
1.86 raeburn 9775: blog => 'Blog',
9776: portfolio => 'Portfolio',
1.430 raeburn 9777: portaccess => 'Share portfolio files',
1.413 raeburn 9778: timezone => 'Can set time zone',
1.88 bisitz 9779: official => 'Official courses (with institutional codes)',
9780: unofficial => 'Unofficial courses',
1.98 raeburn 9781: community => 'Communities',
1.216 raeburn 9782: textbook => 'Textbook courses',
1.271 raeburn 9783: placement => 'Placement tests',
1.86 raeburn 9784: );
1.72 raeburn 9785: return %titles;
9786: }
9787:
1.101 raeburn 9788: sub courserequest_titles {
9789: my %titles = &Apache::lonlocal::texthash (
9790: official => 'Official',
9791: unofficial => 'Unofficial',
9792: community => 'Communities',
1.216 raeburn 9793: textbook => 'Textbook',
1.271 raeburn 9794: placement => 'Placement tests',
1.325 raeburn 9795: lti => 'LTI Provider',
1.101 raeburn 9796: norequest => 'Not allowed',
1.325 raeburn 9797: approval => 'Approval by DC',
1.101 raeburn 9798: validate => 'With validation',
9799: autolimit => 'Numerical limit',
1.103 raeburn 9800: unlimited => '(blank for unlimited)',
1.101 raeburn 9801: );
9802: return %titles;
9803: }
9804:
1.163 raeburn 9805: sub authorrequest_titles {
9806: my %titles = &Apache::lonlocal::texthash (
9807: norequest => 'Not allowed',
9808: approval => 'Approval by Dom. Coord.',
9809: automatic => 'Automatic approval',
9810: );
9811: return %titles;
1.210 raeburn 9812: }
1.163 raeburn 9813:
1.101 raeburn 9814: sub courserequest_conditions {
9815: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9816: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9817: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9818: );
9819: return %conditions;
9820: }
9821:
9822:
1.27 raeburn 9823: sub print_usercreation {
1.30 raeburn 9824: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9825: my $numinrow = 4;
1.28 raeburn 9826: my $datatable;
9827: if ($position eq 'top') {
1.30 raeburn 9828: $$rowtotal ++;
1.34 raeburn 9829: my $rowcount = 0;
1.32 raeburn 9830: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9831: if (ref($rules) eq 'HASH') {
9832: if (keys(%{$rules}) > 0) {
1.32 raeburn 9833: $datatable .= &user_formats_row('username',$settings,$rules,
9834: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9835: $$rowtotal ++;
1.32 raeburn 9836: $rowcount ++;
9837: }
9838: }
9839: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9840: if (ref($idrules) eq 'HASH') {
9841: if (keys(%{$idrules}) > 0) {
9842: $datatable .= &user_formats_row('id',$settings,$idrules,
9843: $idruleorder,$numinrow,$rowcount);
9844: $$rowtotal ++;
9845: $rowcount ++;
1.28 raeburn 9846: }
9847: }
1.39 raeburn 9848: if ($rowcount == 0) {
9849: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9850: $$rowtotal ++;
9851: $rowcount ++;
9852: }
1.34 raeburn 9853: } elsif ($position eq 'middle') {
1.224 raeburn 9854: my @creators = ('author','course','requestcrs');
1.37 raeburn 9855: my ($rules,$ruleorder) =
9856: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9857: my %lt = &usercreation_types();
9858: my %checked;
9859: if (ref($settings) eq 'HASH') {
9860: if (ref($settings->{'cancreate'}) eq 'HASH') {
9861: foreach my $item (@creators) {
9862: $checked{$item} = $settings->{'cancreate'}{$item};
9863: }
9864: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9865: foreach my $item (@creators) {
9866: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9867: $checked{$item} = 'none';
9868: }
9869: }
9870: }
9871: }
9872: my $rownum = 0;
9873: foreach my $item (@creators) {
9874: $rownum ++;
1.224 raeburn 9875: if ($checked{$item} eq '') {
9876: $checked{$item} = 'any';
1.34 raeburn 9877: }
9878: my $css_class;
9879: if ($rownum%2) {
9880: $css_class = '';
9881: } else {
9882: $css_class = ' class="LC_odd_row" ';
9883: }
9884: $datatable .= '<tr'.$css_class.'>'.
9885: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9886: '</span></td><td style="text-align: right">';
1.224 raeburn 9887: my @options = ('any');
9888: if (ref($rules) eq 'HASH') {
9889: if (keys(%{$rules}) > 0) {
9890: push(@options,('official','unofficial'));
1.37 raeburn 9891: }
9892: }
1.224 raeburn 9893: push(@options,'none');
1.37 raeburn 9894: foreach my $option (@options) {
1.50 raeburn 9895: my $type = 'radio';
1.34 raeburn 9896: my $check = ' ';
1.224 raeburn 9897: if ($checked{$item} eq $option) {
9898: $check = ' checked="checked" ';
1.34 raeburn 9899: }
9900: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9901: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9902: $item.'" value="'.$option.'"'.$check.'/> '.
9903: $lt{$option}.'</label> </span>';
9904: }
9905: $datatable .= '</td></tr>';
9906: }
1.28 raeburn 9907: } else {
9908: my @contexts = ('author','course','domain');
1.325 raeburn 9909: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9910: my %checked;
9911: if (ref($settings) eq 'HASH') {
9912: if (ref($settings->{'authtypes'}) eq 'HASH') {
9913: foreach my $item (@contexts) {
9914: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9915: foreach my $auth (@authtypes) {
9916: if ($settings->{'authtypes'}{$item}{$auth}) {
9917: $checked{$item}{$auth} = ' checked="checked" ';
9918: }
9919: }
9920: }
9921: }
1.27 raeburn 9922: }
1.35 raeburn 9923: } else {
9924: foreach my $item (@contexts) {
1.36 raeburn 9925: foreach my $auth (@authtypes) {
1.35 raeburn 9926: $checked{$item}{$auth} = ' checked="checked" ';
9927: }
9928: }
1.27 raeburn 9929: }
1.28 raeburn 9930: my %title = &context_names();
9931: my %authname = &authtype_names();
9932: my $rownum = 0;
9933: my $css_class;
9934: foreach my $item (@contexts) {
9935: if ($rownum%2) {
9936: $css_class = '';
9937: } else {
9938: $css_class = ' class="LC_odd_row" ';
9939: }
1.30 raeburn 9940: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9941: '<td>'.$title{$item}.
9942: '</td><td class="LC_left_item">'.
9943: '<span class="LC_nobreak">';
9944: foreach my $auth (@authtypes) {
9945: $datatable .= '<label>'.
9946: '<input type="checkbox" name="'.$item.'_auth" '.
9947: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9948: $authname{$auth}.'</label> ';
9949: }
9950: $datatable .= '</span></td></tr>';
9951: $rownum ++;
1.27 raeburn 9952: }
1.30 raeburn 9953: $$rowtotal += $rownum;
1.27 raeburn 9954: }
9955: return $datatable;
9956: }
9957:
1.224 raeburn 9958: sub print_selfcreation {
9959: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9960: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9961: $emaildomain,$datatable);
1.224 raeburn 9962: if (ref($settings) eq 'HASH') {
9963: if (ref($settings->{'cancreate'}) eq 'HASH') {
9964: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9965: if (ref($createsettings) eq 'HASH') {
9966: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9967: @selfcreate = @{$createsettings->{'selfcreate'}};
9968: } elsif ($createsettings->{'selfcreate'} ne '') {
9969: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9970: @selfcreate = ('email','login','sso');
9971: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9972: @selfcreate = ($createsettings->{'selfcreate'});
9973: }
9974: }
9975: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9976: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9977: }
1.305 raeburn 9978: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9979: $emailoptions = $createsettings->{'emailoptions'};
9980: }
1.303 raeburn 9981: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9982: $emailverified = $createsettings->{'emailverified'};
9983: }
9984: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9985: $emaildomain = $createsettings->{'emaildomain'};
9986: }
1.224 raeburn 9987: }
9988: }
9989: }
9990: my %radiohash;
9991: my $numinrow = 4;
9992: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9993: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9994: if ($position eq 'top') {
9995: my %choices = &Apache::lonlocal::texthash (
9996: cancreate_login => 'Institutional Login',
9997: cancreate_sso => 'Institutional Single Sign On',
9998: );
9999: my @toggles = sort(keys(%choices));
10000: my %defaultchecked = (
10001: 'cancreate_login' => 'off',
10002: 'cancreate_sso' => 'off',
10003: );
1.228 raeburn 10004: my ($onclick,$itemcount);
1.224 raeburn 10005: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10006: \%choices,$itemcount,$onclick);
1.228 raeburn 10007: $$rowtotal += $itemcount;
1.425 raeburn 10008:
1.224 raeburn 10009: if (ref($usertypes) eq 'HASH') {
10010: if (keys(%{$usertypes}) > 0) {
10011: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
10012: $dom,$numinrow,$othertitle,
1.305 raeburn 10013: 'statustocreate',$rowtotal);
1.224 raeburn 10014: $$rowtotal ++;
10015: }
10016: }
1.240 raeburn 10017: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
10018: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10019: $fieldtitles{'inststatus'} = &mt('Institutional status');
10020: my $rem;
10021: my $numperrow = 2;
10022: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
10023: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 10024: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 10025: '<td class="LC_left_item">'."\n".
1.334 raeburn 10026: '<table>'."\n";
1.240 raeburn 10027: for (my $i=0; $i<@fields; $i++) {
10028: $rem = $i%($numperrow);
10029: if ($rem == 0) {
10030: if ($i > 0) {
10031: $datatable .= '</tr>';
10032: }
10033: $datatable .= '<tr>';
10034: }
10035: my $currval;
1.248 raeburn 10036: if (ref($createsettings) eq 'HASH') {
10037: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
10038: $currval = $createsettings->{'shibenv'}{$fields[$i]};
10039: }
1.240 raeburn 10040: }
10041: $datatable .= '<td class="LC_left_item">'.
10042: '<span class="LC_nobreak">'.
10043: '<input type="text" name="shibenv_'.$fields[$i].'" '.
10044: 'value="'.$currval.'" size="10" /> '.
10045: $fieldtitles{$fields[$i]}.'</span></td>';
10046: }
10047: my $colsleft = $numperrow - $rem;
10048: if ($colsleft > 1 ) {
10049: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10050: ' </td>';
10051: } elsif ($colsleft == 1) {
10052: $datatable .= '<td class="LC_left_item"> </td>';
10053: }
10054: $datatable .= '</tr></table></td></tr>';
10055: $$rowtotal ++;
1.224 raeburn 10056: } elsif ($position eq 'middle') {
10057: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 10058: my @posstypes;
1.224 raeburn 10059: if (ref($types) eq 'ARRAY') {
1.302 raeburn 10060: @posstypes = @{$types};
10061: }
10062: unless (grep(/^default$/,@posstypes)) {
10063: push(@posstypes,'default');
10064: }
10065: my %usertypeshash;
10066: if (ref($usertypes) eq 'HASH') {
10067: %usertypeshash = %{$usertypes};
10068: }
10069: $usertypeshash{'default'} = $othertitle;
10070: foreach my $status (@posstypes) {
10071: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
10072: $numinrow,$$rowtotal,\%usertypeshash);
10073: $$rowtotal ++;
1.224 raeburn 10074: }
10075: } else {
1.236 raeburn 10076: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 10077: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 10078: );
10079: my @toggles = sort(keys(%choices));
10080: my %defaultchecked = (
10081: 'cancreate_email' => 'off',
10082: );
1.305 raeburn 10083: my $customclass = 'LC_selfcreate_email';
10084: my $classprefix = 'LC_canmodify_emailusername_';
10085: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10086: my $display = 'none';
1.305 raeburn 10087: my $rowstyle = 'display:none';
1.236 raeburn 10088: if (grep(/^\Qemail\E$/,@selfcreate)) {
10089: $display = 'block';
1.305 raeburn 10090: $rowstyle = 'display:table-row';
1.236 raeburn 10091: }
1.305 raeburn 10092: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10093: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10094: \%choices,$$rowtotal,$onclick);
10095: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10096: $rowstyle);
10097: $$rowtotal ++;
10098: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10099: $rowstyle);
10100: $$rowtotal ++;
10101: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10102: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10103: my ($emailrules,$emailruleorder) =
10104: &Apache::lonnet::inst_userrules($dom,'email');
10105: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10106: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10107: if (ref($types) eq 'ARRAY') {
10108: @posstypes = @{$types};
10109: }
10110: if (@posstypes) {
10111: unless (grep(/^default$/,@posstypes)) {
10112: push(@posstypes,'default');
1.302 raeburn 10113: }
10114: if (ref($usertypes) eq 'HASH') {
10115: %usertypeshash = %{$usertypes};
10116: }
1.305 raeburn 10117: my $currassign;
10118: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10119: $currassign = {
10120: selfassign => $domdefaults{'inststatusguest'},
10121: };
10122: @ordered = @{$domdefaults{'inststatusguest'}};
10123: } else {
10124: $currassign = { selfassign => [] };
10125: }
10126: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10127: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10128: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10129: $numinrow,$othertitle,'selfassign',
10130: $rowtotal,$onclicktypes,$customclass,
10131: $rowstyle);
10132: $$rowtotal ++;
1.302 raeburn 10133: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10134: foreach my $status (@posstypes) {
10135: my $css_class;
10136: if ($$rowtotal%2) {
10137: $css_class = 'LC_odd_row ';
10138: }
10139: $css_class .= $customclass;
10140: my $rowid = $optionsprefix.$status;
10141: my $hidden = 1;
10142: my $currstyle = 'display:none';
10143: if (grep(/^\Q$status\E$/,@ordered)) {
10144: $currstyle = $rowstyle;
1.425 raeburn 10145: $hidden = 0;
1.305 raeburn 10146: }
10147: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10148: $emailrules,$emailruleorder,$settings,$status,$rowid,
10149: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10150: unless ($hidden) {
10151: $$rowtotal ++;
10152: }
1.224 raeburn 10153: }
1.302 raeburn 10154: } else {
1.305 raeburn 10155: my $css_class;
10156: if ($$rowtotal%2) {
10157: $css_class = 'LC_odd_row ';
10158: }
10159: $css_class .= $customclass;
1.302 raeburn 10160: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10161: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10162: $emailrules,$emailruleorder,$settings,'default','',
10163: $othertitle,$css_class,$rowstyle,$intdom);
10164: $$rowtotal ++;
1.224 raeburn 10165: }
10166: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10167: $numinrow = 1;
1.305 raeburn 10168: if (@posstypes) {
10169: foreach my $status (@posstypes) {
10170: my $rowid = $classprefix.$status;
10171: my $datarowstyle = 'display:none';
1.425 raeburn 10172: if (grep(/^\Q$status\E$/,@ordered)) {
10173: $datarowstyle = $rowstyle;
1.305 raeburn 10174: }
10175: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10176: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10177: $infotitles,$rowid,$customclass,$datarowstyle);
10178: unless ($datarowstyle eq 'display:none') {
10179: $$rowtotal ++;
10180: }
1.224 raeburn 10181: }
1.305 raeburn 10182: } else {
10183: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10184: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10185: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10186: }
10187: }
10188: return $datatable;
10189: }
10190:
1.305 raeburn 10191: sub selfcreate_javascript {
10192: return <<"ENDSCRIPT";
10193:
10194: <script type="text/javascript">
10195: // <![CDATA[
10196:
10197: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10198: var x = document.getElementsByClassName(target);
10199: var insttypes = 0;
10200: var insttypeRegExp = new RegExp(prefix);
10201: if ((x.length != undefined) && (x.length > 0)) {
10202: if (form.elements[radio].length != undefined) {
10203: for (var i=0; i<form.elements[radio].length; i++) {
10204: if (form.elements[radio][i].checked) {
10205: if (form.elements[radio][i].value == 1) {
10206: for (var j=0; j<x.length; j++) {
10207: if (x[j].id == 'undefined') {
10208: x[j].style.display = 'table-row';
10209: } else if (insttypeRegExp.test(x[j].id)) {
10210: insttypes ++;
10211: } else {
10212: x[j].style.display = 'table-row';
10213: }
10214: }
10215: } else {
10216: for (var j=0; j<x.length; j++) {
10217: x[j].style.display = 'none';
10218: }
1.236 raeburn 10219: }
1.305 raeburn 10220: break;
10221: }
10222: }
10223: if (insttypes > 0) {
10224: toggleDataRow(form,checkbox,target,altprefix);
10225: toggleDataRow(form,checkbox,target,prefix,1);
10226: }
10227: }
10228: }
10229: return;
10230: }
10231:
10232: function toggleDataRow(form,checkbox,target,prefix,docount) {
10233: if (form.elements[checkbox].length != undefined) {
10234: var count = 0;
10235: if (docount) {
10236: for (var i=0; i<form.elements[checkbox].length; i++) {
10237: if (form.elements[checkbox][i].checked) {
10238: count ++;
1.236 raeburn 10239: }
1.305 raeburn 10240: }
10241: }
10242: for (var i=0; i<form.elements[checkbox].length; i++) {
10243: var type = form.elements[checkbox][i].value;
10244: if (document.getElementById(prefix+type)) {
10245: if (form.elements[checkbox][i].checked) {
10246: document.getElementById(prefix+type).style.display = 'table-row';
10247: if (count % 2 == 1) {
10248: document.getElementById(prefix+type).className = target+' LC_odd_row';
10249: } else {
10250: document.getElementById(prefix+type).className = target;
1.236 raeburn 10251: }
1.305 raeburn 10252: count ++;
1.236 raeburn 10253: } else {
1.305 raeburn 10254: document.getElementById(prefix+type).style.display = 'none';
10255: }
10256: }
10257: }
10258: }
10259: return;
10260: }
10261:
10262: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10263: var caller = radio+'_'+status;
10264: if (form.elements[caller].length != undefined) {
10265: for (var i=0; i<form.elements[caller].length; i++) {
10266: if (form.elements[caller][i].checked) {
10267: if (document.getElementById(altprefix+'_inst_'+status)) {
10268: var curr = form.elements[caller][i].value;
10269: if (prefix) {
10270: document.getElementById(prefix+'_'+status).style.display = 'none';
10271: }
10272: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10273: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10274: if (curr == 'custom') {
1.425 raeburn 10275: if (prefix) {
1.305 raeburn 10276: document.getElementById(prefix+'_'+status).style.display = 'inline';
10277: }
10278: } else if (curr == 'inst') {
10279: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10280: } else if (curr == 'noninst') {
10281: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10282: }
1.305 raeburn 10283: break;
1.236 raeburn 10284: }
10285: }
10286: }
10287: }
10288: }
10289:
1.305 raeburn 10290: // ]]>
10291: </script>
10292:
10293: ENDSCRIPT
10294: }
10295:
10296: sub noninst_users {
10297: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10298: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10299: my $class = 'LC_left_item';
10300: if ($css_class) {
1.425 raeburn 10301: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10302: }
10303: if ($rowid) {
10304: $rowid = ' id="'.$rowid.'"';
10305: }
10306: if ($rowstyle) {
10307: $rowstyle = ' style="'.$rowstyle.'"';
10308: }
10309: my ($output,$description);
10310: if ($type eq 'default') {
10311: $description = &mt('Requests for: [_1]',$typetitle);
10312: } else {
10313: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10314: }
10315: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10316: "<td>$description</td>\n".
1.305 raeburn 10317: '<td class="'.$class.'" colspan="2">'.
10318: '<table><tr>';
1.425 raeburn 10319: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10320: approve => 'Processing',
10321: email => 'E-mail',
10322: username => 'Username',
10323: );
10324: foreach my $item ('approve','email','username') {
10325: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10326: }
1.305 raeburn 10327: $output .= '</tr><tr>';
10328: foreach my $item ('approve','email','username') {
1.306 raeburn 10329: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10330: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10331: if ($item eq 'approve') {
10332: %choices = &Apache::lonlocal::texthash (
10333: automatic => 'Automatically approved',
10334: approval => 'Queued for approval',
10335: );
10336: @options = ('automatic','approval');
10337: $hashref = $processing;
10338: $defoption = 'automatic';
10339: $name = 'cancreate_emailprocess_'.$type;
10340: } elsif ($item eq 'email') {
10341: %choices = &Apache::lonlocal::texthash (
10342: any => 'Any e-mail',
10343: inst => 'Institutional only',
10344: noninst => 'Non-institutional only',
10345: custom => 'Custom restrictions',
10346: );
10347: @options = ('any','inst','noninst');
10348: my $showcustom;
10349: if (ref($emailrules) eq 'HASH') {
10350: if (keys(%{$emailrules}) > 0) {
10351: push(@options,'custom');
10352: $showcustom = 'cancreate_emailrule';
10353: if (ref($settings) eq 'HASH') {
10354: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10355: foreach my $rule (@{$settings->{'email_rule'}}) {
10356: if (exists($emailrules->{$rule})) {
10357: $hascustom ++;
10358: }
10359: }
10360: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10361: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10362: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10363: if (exists($emailrules->{$rule})) {
10364: $hascustom ++;
10365: }
10366: }
10367: }
10368: }
10369: }
10370: }
10371: }
10372: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10373: "'cancreate_emaildomain','$type'".');"';
10374: $hashref = $emailoptions;
10375: $defoption = 'any';
10376: $name = 'cancreate_emailoptions_'.$type;
10377: } elsif ($item eq 'username') {
10378: %choices = &Apache::lonlocal::texthash (
10379: all => 'Same as e-mail',
10380: first => 'Omit @domain',
10381: free => 'Free to choose',
10382: );
10383: @options = ('all','first','free');
10384: $hashref = $emailverified;
10385: $defoption = 'all';
10386: $name = 'cancreate_usernameoptions_'.$type;
10387: }
10388: foreach my $option (@options) {
10389: my $checked;
10390: if (ref($hashref) eq 'HASH') {
10391: if ($type eq '') {
10392: if (!exists($hashref->{'default'})) {
10393: if ($option eq $defoption) {
10394: $checked = ' checked="checked"';
10395: }
10396: } else {
10397: if ($hashref->{'default'} eq $option) {
10398: $checked = ' checked="checked"';
10399: }
1.303 raeburn 10400: }
10401: } else {
1.305 raeburn 10402: if (!exists($hashref->{$type})) {
10403: if ($option eq $defoption) {
10404: $checked = ' checked="checked"';
10405: }
10406: } else {
10407: if ($hashref->{$type} eq $option) {
10408: $checked = ' checked="checked"';
10409: }
1.303 raeburn 10410: }
10411: }
1.305 raeburn 10412: } elsif (($item eq 'email') && ($hascustom)) {
10413: if ($option eq 'custom') {
10414: $checked = ' checked="checked"';
10415: }
10416: } elsif ($option eq $defoption) {
10417: $checked = ' checked="checked"';
10418: }
10419: $output .= '<span class="LC_nobreak"><label>'.
10420: '<input type="radio" name="'.$name.'"'.
10421: $checked.' value="'.$option.'"'.$onclick.' />'.
10422: $choices{$option}.'</label></span><br />';
10423: if ($item eq 'email') {
10424: if ($option eq 'custom') {
10425: my $id = 'cancreate_emailrule_'.$type;
10426: my $display = 'none';
10427: if ($checked) {
10428: $display = 'inline';
1.303 raeburn 10429: }
1.305 raeburn 10430: my $numinrow = 2;
10431: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10432: '<legend>'.&mt('Disallow').'</legend><table>'.
10433: &user_formats_row('email',$settings,$emailrules,
10434: $emailruleorder,$numinrow,'',$type);
10435: '</table></fieldset>';
10436: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10437: my %text = &Apache::lonlocal::texthash (
10438: inst => 'must end:',
10439: noninst => 'cannot end:',
10440: );
10441: my $value;
10442: if (ref($emaildomain) eq 'HASH') {
10443: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10444: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10445: }
10446: }
1.305 raeburn 10447: if ($value eq '') {
10448: $value = '@'.$intdom;
10449: }
10450: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10451: my $display = 'none';
10452: if ($checked) {
10453: $display = 'inline';
10454: }
10455: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10456: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10457: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10458: '</div>';
1.303 raeburn 10459: }
10460: }
10461: }
1.305 raeburn 10462: $output .= '</td>'."\n";
1.303 raeburn 10463: }
1.305 raeburn 10464: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10465: return $output;
10466: }
10467:
1.165 raeburn 10468: sub captcha_choice {
1.305 raeburn 10469: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10470: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10471: $vertext,$currver);
1.165 raeburn 10472: my %lt = &captcha_phrases();
10473: $keyentry = 'hidden';
1.354 raeburn 10474: my $colspan=2;
1.165 raeburn 10475: if ($context eq 'cancreate') {
1.224 raeburn 10476: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10477: } elsif ($context eq 'login') {
10478: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10479: } elsif ($context eq 'passwords') {
10480: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10481: $colspan=1;
1.165 raeburn 10482: }
10483: if (ref($settings) eq 'HASH') {
10484: if ($settings->{'captcha'}) {
10485: $checked{$settings->{'captcha'}} = ' checked="checked"';
10486: } else {
10487: $checked{'original'} = ' checked="checked"';
10488: }
10489: if ($settings->{'captcha'} eq 'recaptcha') {
10490: $pubtext = $lt{'pub'};
10491: $privtext = $lt{'priv'};
10492: $keyentry = 'text';
1.269 raeburn 10493: $vertext = $lt{'ver'};
10494: $currver = $settings->{'recaptchaversion'};
10495: if ($currver ne '2') {
10496: $currver = 1;
10497: }
1.165 raeburn 10498: }
10499: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10500: $currpub = $settings->{'recaptchakeys'}{'public'};
10501: $currpriv = $settings->{'recaptchakeys'}{'private'};
10502: }
10503: } else {
10504: $checked{'original'} = ' checked="checked"';
10505: }
1.305 raeburn 10506: my $css_class;
10507: if ($itemcount%2) {
10508: $css_class = 'LC_odd_row';
10509: }
10510: if ($customcss) {
10511: $css_class .= " $customcss";
10512: }
10513: $css_class =~ s/^\s+//;
10514: if ($css_class) {
10515: $css_class = ' class="'.$css_class.'"';
10516: }
10517: if ($rowstyle) {
10518: $css_class .= ' style="'.$rowstyle.'"';
10519: }
1.169 raeburn 10520: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10521: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10522: '<table><tr><td>'."\n";
10523: foreach my $option ('original','recaptcha','notused') {
10524: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10525: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10526: $lt{$option}.'</label></span>';
10527: unless ($option eq 'notused') {
10528: $output .= (' 'x2)."\n";
10529: }
10530: }
10531: #
10532: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10533: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10534: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10535: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10536: #
1.165 raeburn 10537: $output .= '</td></tr>'."\n".
1.305 raeburn 10538: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10539: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10540: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10541: $currpub.'" size="40" /></span><br />'."\n".
10542: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10543: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10544: $currpriv.'" size="40" /></span><br />'.
10545: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10546: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10547: $currver.'" size="3" /></span><br />'.
10548: '</td></tr></table>'."\n".
1.165 raeburn 10549: '</td></tr>';
10550: return $output;
10551: }
10552:
1.32 raeburn 10553: sub user_formats_row {
1.305 raeburn 10554: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10555: my $output;
10556: my %text = (
10557: 'username' => 'new usernames',
10558: 'id' => 'IDs',
10559: );
1.409 raeburn 10560: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10561: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10562: $output = '<tr '.$css_class.'>'.
10563: '<td><span class="LC_nobreak">'.
10564: &mt("Format rules to check for $text{$type}: ").
10565: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10566: }
1.27 raeburn 10567: my $rem;
10568: if (ref($ruleorder) eq 'ARRAY') {
10569: for (my $i=0; $i<@{$ruleorder}; $i++) {
10570: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10571: my $rem = $i%($numinrow);
10572: if ($rem == 0) {
10573: if ($i > 0) {
10574: $output .= '</tr>';
10575: }
10576: $output .= '<tr>';
10577: }
10578: my $check = ' ';
1.39 raeburn 10579: if (ref($settings) eq 'HASH') {
10580: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10581: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10582: $check = ' checked="checked" ';
10583: }
1.305 raeburn 10584: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10585: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10586: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10587: $check = ' checked="checked" ';
10588: }
10589: }
1.27 raeburn 10590: }
10591: }
1.305 raeburn 10592: my $name = $type.'_rule';
10593: if ($type eq 'email') {
10594: $name .= '_'.$status;
10595: }
1.27 raeburn 10596: $output .= '<td class="LC_left_item">'.
10597: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10598: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10599: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10600: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10601: }
10602: }
10603: $rem = @{$ruleorder}%($numinrow);
10604: }
1.305 raeburn 10605: my $colsleft;
10606: if ($rem) {
10607: $colsleft = $numinrow - $rem;
10608: }
1.27 raeburn 10609: if ($colsleft > 1 ) {
10610: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10611: ' </td>';
10612: } elsif ($colsleft == 1) {
10613: $output .= '<td class="LC_left_item"> </td>';
10614: }
1.409 raeburn 10615: $output .= '</tr>';
10616: unless (($type eq 'email') || ($type eq 'unamemap')) {
10617: $output .= '</table></td></tr>';
1.305 raeburn 10618: }
1.27 raeburn 10619: return $output;
10620: }
10621:
1.34 raeburn 10622: sub usercreation_types {
10623: my %lt = &Apache::lonlocal::texthash (
10624: author => 'When adding a co-author',
10625: course => 'When adding a user to a course',
1.100 raeburn 10626: requestcrs => 'When requesting a course',
1.34 raeburn 10627: any => 'Any',
10628: official => 'Institutional only ',
10629: unofficial => 'Non-institutional only',
10630: none => 'None',
10631: );
10632: return %lt;
1.48 raeburn 10633: }
1.34 raeburn 10634:
1.224 raeburn 10635: sub selfcreation_types {
10636: my %lt = &Apache::lonlocal::texthash (
10637: selfcreate => 'User creates own account',
10638: any => 'Any',
10639: official => 'Institutional only ',
10640: unofficial => 'Non-institutional only',
10641: email => 'E-mail address',
10642: login => 'Institutional Login',
10643: sso => 'SSO',
10644: );
10645: }
10646:
1.28 raeburn 10647: sub authtype_names {
10648: my %lt = &Apache::lonlocal::texthash(
10649: int => 'Internal',
10650: krb4 => 'Kerberos 4',
10651: krb5 => 'Kerberos 5',
10652: loc => 'Local',
1.325 raeburn 10653: lti => 'LTI',
1.28 raeburn 10654: );
10655: return %lt;
10656: }
10657:
10658: sub context_names {
10659: my %context_title = &Apache::lonlocal::texthash(
10660: author => 'Creating users when an Author',
10661: course => 'Creating users when in a course',
10662: domain => 'Creating users when a Domain Coordinator',
10663: );
10664: return %context_title;
10665: }
10666:
1.33 raeburn 10667: sub print_usermodification {
10668: my ($position,$dom,$settings,$rowtotal) = @_;
10669: my $numinrow = 4;
10670: my ($context,$datatable,$rowcount);
10671: if ($position eq 'top') {
10672: $rowcount = 0;
10673: $context = 'author';
10674: foreach my $role ('ca','aa') {
10675: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10676: $numinrow,$rowcount);
10677: $$rowtotal ++;
10678: $rowcount ++;
10679: }
1.443 raeburn 10680: } elsif ($position eq 'middle') {
10681: $rowcount = 0;
10682: $context = 'coauthor';
10683: foreach my $role ('ca','aa') {
10684: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10685: $numinrow,$rowcount);
10686: $$rowtotal ++;
10687: $rowcount ++;
10688: }
1.230 raeburn 10689: } elsif ($position eq 'bottom') {
1.33 raeburn 10690: $context = 'course';
10691: $rowcount = 0;
10692: foreach my $role ('st','ep','ta','in','cr') {
10693: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10694: $numinrow,$rowcount);
10695: $$rowtotal ++;
10696: $rowcount ++;
10697: }
10698: }
10699: return $datatable;
10700: }
10701:
1.43 raeburn 10702: sub print_defaults {
1.236 raeburn 10703: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10704: my $rownum = 0;
1.294 raeburn 10705: my ($datatable,$css_class,$titles);
10706: unless ($position eq 'bottom') {
10707: $titles = &defaults_titles($dom);
10708: }
1.236 raeburn 10709: if ($position eq 'top') {
10710: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10711: 'datelocale_def','portal_def');
10712: my %defaults;
10713: if (ref($settings) eq 'HASH') {
10714: %defaults = %{$settings};
1.43 raeburn 10715: } else {
1.236 raeburn 10716: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10717: foreach my $item (@items) {
10718: $defaults{$item} = $domdefaults{$item};
10719: }
1.43 raeburn 10720: }
1.236 raeburn 10721: foreach my $item (@items) {
10722: if ($rownum%2) {
10723: $css_class = '';
10724: } else {
10725: $css_class = ' class="LC_odd_row" ';
10726: }
10727: $datatable .= '<tr'.$css_class.'>'.
10728: '<td><span class="LC_nobreak">'.$titles->{$item}.
10729: '</span></td><td class="LC_right_item" colspan="3">';
10730: if ($item eq 'auth_def') {
1.325 raeburn 10731: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10732: my %shortauth = (
10733: internal => 'int',
10734: krb4 => 'krb4',
10735: krb5 => 'krb5',
1.325 raeburn 10736: localauth => 'loc',
10737: lti => 'lti',
1.236 raeburn 10738: );
10739: my %authnames = &authtype_names();
10740: foreach my $auth (@authtypes) {
10741: my $checked = ' ';
10742: if ($defaults{$item} eq $auth) {
10743: $checked = ' checked="checked" ';
10744: }
10745: $datatable .= '<label><input type="radio" name="'.$item.
10746: '" value="'.$auth.'"'.$checked.'/>'.
10747: $authnames{$shortauth{$auth}}.'</label> ';
10748: }
10749: } elsif ($item eq 'timezone_def') {
10750: my $includeempty = 1;
10751: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10752: } elsif ($item eq 'datelocale_def') {
10753: my $includeempty = 1;
10754: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10755: } elsif ($item eq 'lang_def') {
1.263 raeburn 10756: my $includeempty = 1;
10757: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10758: } elsif ($item eq 'portal_def') {
10759: $datatable .= '<input type="text" name="'.$item.'" value="'.
10760: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10761: my $portalsty = 'none';
10762: if ($defaults{$item}) {
10763: $portalsty = 'block';
10764: }
10765: foreach my $field ('email','web') {
10766: my $checkedoff = ' checked="checked"';
10767: my $checkedon;
10768: if ($defaults{$item.'_'.$field}) {
10769: $checkedon = $checkedoff;
10770: $checkedoff = '';
1.425 raeburn 10771: }
1.414 raeburn 10772: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10773: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10774: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10775: (' 'x2).
10776: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10777: '</div>';
10778: }
1.236 raeburn 10779: } else {
1.414 raeburn 10780: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10781: }
1.236 raeburn 10782: $datatable .= '</td></tr>';
10783: $rownum ++;
10784: }
1.409 raeburn 10785: } elsif ($position eq 'middle') {
1.294 raeburn 10786: my %defaults;
10787: if (ref($settings) eq 'HASH') {
1.354 raeburn 10788: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10789: my $maxnum = @{$settings->{'inststatusorder'}};
10790: for (my $i=0; $i<$maxnum; $i++) {
10791: $css_class = $rownum%2?' class="LC_odd_row"':'';
10792: my $item = $settings->{'inststatusorder'}->[$i];
10793: my $title = $settings->{'inststatustypes'}->{$item};
10794: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10795: $datatable .= '<tr'.$css_class.'>'.
10796: '<td><span class="LC_nobreak">'.
10797: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10798: for (my $k=0; $k<=$maxnum; $k++) {
10799: my $vpos = $k+1;
10800: my $selstr;
10801: if ($k == $i) {
10802: $selstr = ' selected="selected" ';
10803: }
10804: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10805: }
10806: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10807: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10808: &mt('delete').'</span></td>'.
1.380 raeburn 10809: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10810: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10811: '</span></td></tr>';
10812: }
10813: $css_class = $rownum%2?' class="LC_odd_row"':'';
10814: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10815: $datatable .= '<tr '.$css_class.'>'.
10816: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10817: for (my $k=0; $k<=$maxnum; $k++) {
10818: my $vpos = $k+1;
10819: my $selstr;
10820: if ($k == $maxnum) {
10821: $selstr = ' selected="selected" ';
10822: }
10823: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10824: }
10825: $datatable .= '</select> '.&mt('Internal ID:').
10826: '<input type="text" size="10" name="addinststatus" value="" />'.
10827: ' '.&mt('(new)').
10828: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10829: &mt('Name displayed').':'.
1.354 raeburn 10830: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10831: '</tr>'."\n";
10832: $rownum ++;
1.294 raeburn 10833: }
1.354 raeburn 10834: }
1.409 raeburn 10835: } else {
10836: my ($unamemaprules,$ruleorder) =
10837: &Apache::lonnet::inst_userrules($dom,'unamemap');
10838: $css_class = $rownum%2?' class="LC_odd_row"':'';
10839: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10840: my $numinrow = 2;
10841: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10842: &user_formats_row('unamemap',$settings,$unamemaprules,
10843: $ruleorder,$numinrow).
10844: '</table></td></tr>';
10845: }
10846: if ($datatable eq '') {
10847: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10848: &mt('No rules set for domain in customized localenroll.pm').
10849: '</td></tr>';
10850: }
1.354 raeburn 10851: }
10852: $$rowtotal += $rownum;
1.43 raeburn 10853: return $datatable;
10854: }
10855:
1.168 raeburn 10856: sub get_languages_hash {
10857: my %langchoices;
10858: foreach my $id (&Apache::loncommon::languageids()) {
10859: my $code = &Apache::loncommon::supportedlanguagecode($id);
10860: if ($code ne '') {
10861: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10862: }
10863: }
10864: return %langchoices;
10865: }
10866:
1.43 raeburn 10867: sub defaults_titles {
1.141 raeburn 10868: my ($dom) = @_;
1.43 raeburn 10869: my %titles = &Apache::lonlocal::texthash (
10870: 'auth_def' => 'Default authentication type',
10871: 'auth_arg_def' => 'Default authentication argument',
10872: 'lang_def' => 'Default language',
1.54 raeburn 10873: 'timezone_def' => 'Default timezone',
1.68 raeburn 10874: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10875: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10876: 'email' => 'Email links use portal URL',
10877: 'web' => 'Public web links use portal URL',
1.294 raeburn 10878: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10879: 'intauth_check' => 'Check bcrypt cost if authenticated',
10880: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10881: );
1.141 raeburn 10882: if ($dom) {
10883: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10884: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10885: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10886: $protocol = 'http' if ($protocol ne 'https');
10887: if ($uint_dom) {
10888: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10889: $uint_dom);
10890: }
10891: }
1.43 raeburn 10892: return (\%titles);
10893: }
10894:
1.346 raeburn 10895: sub print_scantron {
10896: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10897: if ($position eq 'top') {
10898: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10899: } else {
10900: return &print_scantronconfig($dom,$settings,\$rowtotal);
10901: }
10902: }
10903:
10904: sub scantron_javascript {
10905: return <<"ENDSCRIPT";
10906:
10907: <script type="text/javascript">
10908: // <![CDATA[
10909:
10910: function toggleScantron(form) {
1.347 raeburn 10911: var csvfieldset = new Array();
1.346 raeburn 10912: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10913: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10914: }
10915: if (document.getElementById('scantroncsv_options')) {
10916: csvfieldset.push(document.getElementById('scantroncsv_options'));
10917: }
10918: if (csvfieldset.length) {
1.346 raeburn 10919: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10920: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10921: if (scantroncsv.checked) {
1.347 raeburn 10922: for (var i=0; i<csvfieldset.length; i++) {
10923: csvfieldset[i].style.display = 'block';
10924: }
1.346 raeburn 10925: } else {
1.347 raeburn 10926: for (var i=0; i<csvfieldset.length; i++) {
10927: csvfieldset[i].style.display = 'none';
10928: }
1.346 raeburn 10929: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10930: if (csvselects.length) {
10931: for (var j=0; j<csvselects.length; j++) {
10932: csvselects[j].selectedIndex = 0;
10933: }
10934: }
10935: }
10936: }
10937: }
10938: return;
10939: }
10940: // ]]>
10941: </script>
10942:
10943: ENDSCRIPT
10944:
10945: }
10946:
1.46 raeburn 10947: sub print_scantronformat {
10948: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10949: my $itemcount = 1;
1.60 raeburn 10950: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10951: %confhash);
1.46 raeburn 10952: my $switchserver = &check_switchserver($dom,$confname);
10953: my %lt = &Apache::lonlocal::texthash (
1.95 www 10954: default => 'Default bubblesheet format file error',
10955: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10956: );
10957: my %scantronfiles = (
10958: default => 'default.tab',
10959: custom => 'custom.tab',
10960: );
10961: foreach my $key (keys(%scantronfiles)) {
10962: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10963: .$scantronfiles{$key};
10964: }
10965: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10966: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10967: if (!$switchserver) {
10968: my $servadm = $r->dir_config('lonAdmEMail');
10969: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10970: if ($configuserok eq 'ok') {
10971: if ($author_ok eq 'ok') {
10972: my %legacyfile = (
1.346 raeburn 10973: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10974: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10975: );
10976: my %md5chk;
10977: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10978: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10979: chomp($md5chk{$type});
1.46 raeburn 10980: }
10981: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10982: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10983: ($scantronurls{$type},my $error) =
1.46 raeburn 10984: &legacy_scantronformat($r,$dom,$confname,
10985: $type,$legacyfile{$type},
10986: $scantronurls{$type},
10987: $scantronfiles{$type});
1.60 raeburn 10988: if ($error ne '') {
10989: $error{$type} = $error;
10990: }
10991: }
10992: if (keys(%error) == 0) {
10993: $is_custom = 1;
1.346 raeburn 10994: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10995: $scantronurls{'custom'};
1.346 raeburn 10996: my $putresult =
1.60 raeburn 10997: &Apache::lonnet::put_dom('configuration',
10998: \%confhash,$dom);
10999: if ($putresult ne 'ok') {
1.346 raeburn 11000: $error{'custom'} =
1.60 raeburn 11001: '<span class="LC_error">'.
11002: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11003: }
1.46 raeburn 11004: }
11005: } else {
1.60 raeburn 11006: ($scantronurls{'default'},my $error) =
1.46 raeburn 11007: &legacy_scantronformat($r,$dom,$confname,
11008: 'default',$legacyfile{'default'},
11009: $scantronurls{'default'},
11010: $scantronfiles{'default'});
1.60 raeburn 11011: if ($error eq '') {
11012: $confhash{'scantron'}{'scantronformat'} = '';
11013: my $putresult =
11014: &Apache::lonnet::put_dom('configuration',
11015: \%confhash,$dom);
11016: if ($putresult ne 'ok') {
11017: $error{'default'} =
11018: '<span class="LC_error">'.
11019: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11020: }
11021: } else {
11022: $error{'default'} = $error;
11023: }
1.46 raeburn 11024: }
11025: }
11026: }
11027: } else {
1.95 www 11028: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 11029: }
11030: }
11031: if (ref($settings) eq 'HASH') {
11032: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
11033: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
11034: if ((!@info) || ($info[0] eq 'no_such_dir')) {
11035: $scantronurl = '';
11036: } else {
11037: $scantronurl = $settings->{'scantronformat'};
11038: }
11039: $is_custom = 1;
11040: } else {
11041: $scantronurl = $scantronurls{'default'};
11042: }
11043: } else {
1.60 raeburn 11044: if ($is_custom) {
11045: $scantronurl = $scantronurls{'custom'};
11046: } else {
11047: $scantronurl = $scantronurls{'default'};
11048: }
1.46 raeburn 11049: }
11050: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11051: $datatable .= '<tr'.$css_class.'>';
11052: if (!$is_custom) {
1.65 raeburn 11053: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
11054: '<span class="LC_nobreak">';
1.46 raeburn 11055: if ($scantronurl) {
1.199 raeburn 11056: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
11057: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 11058: } else {
11059: $datatable = &mt('File unavailable for display');
11060: }
1.65 raeburn 11061: $datatable .= '</span></td>';
1.60 raeburn 11062: if (keys(%error) == 0) {
1.306 raeburn 11063: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 11064: if (!$switchserver) {
11065: $datatable .= &mt('Upload:').'<br />';
11066: }
11067: } else {
11068: my $errorstr;
11069: foreach my $key (sort(keys(%error))) {
11070: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11071: }
11072: $datatable .= '<td>'.$errorstr;
11073: }
1.46 raeburn 11074: } else {
11075: if (keys(%error) > 0) {
11076: my $errorstr;
11077: foreach my $key (sort(keys(%error))) {
11078: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11079: }
1.60 raeburn 11080: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 11081: } elsif ($scantronurl) {
1.199 raeburn 11082: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
11083: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 11084: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 11085: $link.
11086: '<label><input type="checkbox" name="scantronformat_del"'.
11087: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 11088: '<td><span class="LC_nobreak"> '.
11089: &mt('Replace:').'</span><br />';
1.46 raeburn 11090: }
11091: }
11092: if (keys(%error) == 0) {
11093: if ($switchserver) {
11094: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
11095: } else {
1.65 raeburn 11096: $datatable .='<span class="LC_nobreak"> '.
11097: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11098: }
11099: }
11100: $datatable .= '</td></tr>';
11101: $$rowtotal ++;
11102: return $datatable;
11103: }
11104:
11105: sub legacy_scantronformat {
11106: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11107: my ($url,$error);
11108: my @statinfo = &Apache::lonnet::stat_file($newurl);
11109: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 11110: my $modified = [];
1.46 raeburn 11111: (my $result,$url) =
1.421 raeburn 11112: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
11113: 'scantron','','',$newfile,$modified);
11114: if ($result eq 'ok') {
11115: &update_modify_urls($r,$modified);
11116: } else {
1.130 raeburn 11117: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11118: }
11119: }
11120: return ($url,$error);
11121: }
1.43 raeburn 11122:
1.346 raeburn 11123: sub print_scantronconfig {
11124: my ($dom,$settings,$rowtotal) = @_;
11125: my $itemcount = 2;
11126: my $is_checked = ' checked="checked"';
1.347 raeburn 11127: my %optionson = (
11128: hdr => ' checked="checked"',
11129: pad => ' checked="checked"',
11130: rem => ' checked="checked"',
11131: );
11132: my %optionsoff = (
11133: hdr => '',
11134: pad => '',
11135: rem => '',
11136: );
1.346 raeburn 11137: my $currcsvsty = 'none';
1.347 raeburn 11138: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11139: my @fields = &scantroncsv_fields();
11140: my %titles = &scantronconfig_titles();
11141: if (ref($settings) eq 'HASH') {
11142: if (ref($settings->{config}) eq 'HASH') {
11143: if ($settings->{config}->{dat}) {
11144: $checked{'dat'} = $is_checked;
11145: }
11146: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11147: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11148: %csvfields = %{$settings->{config}->{csv}->{fields}};
11149: if (keys(%csvfields) > 0) {
11150: $checked{'csv'} = $is_checked;
11151: $currcsvsty = 'block';
11152: }
11153: }
11154: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11155: %csvoptions = %{$settings->{config}->{csv}->{options}};
11156: foreach my $option (keys(%optionson)) {
11157: unless ($csvoptions{$option}) {
11158: $optionsoff{$option} = $optionson{$option};
11159: $optionson{$option} = '';
11160: }
11161: }
1.346 raeburn 11162: }
11163: }
11164: } else {
11165: $checked{'dat'} = $is_checked;
11166: }
11167: } else {
11168: $checked{'dat'} = $is_checked;
11169: }
11170: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11171: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11172: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11173: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11174: foreach my $item ('dat','csv') {
11175: my $id;
11176: if ($item eq 'csv') {
11177: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11178: }
1.346 raeburn 11179: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11180: $titles{$item}.'</label>'.(' 'x3);
11181: if ($item eq 'csv') {
11182: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11183: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11184: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11185: foreach my $col (@fields) {
11186: my $selnone;
11187: if ($csvfields{$col} eq '') {
11188: $selnone = ' selected="selected"';
11189: }
11190: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11191: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11192: '<option value=""'.$selnone.'></option>';
11193: for (my $i=0; $i<20; $i++) {
11194: my $shown = $i+1;
11195: my $sel;
11196: unless ($selnone) {
11197: if (exists($csvfields{$col})) {
11198: if ($csvfields{$col} == $i) {
11199: $sel = ' selected="selected"';
11200: }
11201: }
11202: }
11203: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11204: }
11205: $datatable .= '</select></td></tr>';
11206: }
1.347 raeburn 11207: $datatable .= '</table></fieldset>'.
11208: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11209: '<legend>'.&mt('CSV Options').'</legend>';
11210: foreach my $option ('hdr','pad','rem') {
11211: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11212: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11213: &mt('Yes').'</label>'.(' 'x2)."\n".
11214: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11215: }
11216: $datatable .= '</fieldset>';
1.346 raeburn 11217: $itemcount ++;
11218: }
11219: }
11220: $datatable .= '</td></tr>';
11221: $$rowtotal ++;
11222: return $datatable;
11223: }
11224:
11225: sub scantronconfig_titles {
11226: return &Apache::lonlocal::texthash(
11227: dat => 'Standard format (.dat)',
11228: csv => 'Comma separated values (.csv)',
1.347 raeburn 11229: hdr => 'Remove first line in file (contains column titles)',
11230: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11231: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11232: CODE => 'CODE',
11233: ID => 'Student ID',
11234: PaperID => 'Paper ID',
11235: FirstName => 'First Name',
11236: LastName => 'Last Name',
11237: FirstQuestion => 'First Question Response',
11238: Section => 'Section',
11239: );
11240: }
11241:
11242: sub scantroncsv_fields {
11243: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11244: }
11245:
1.49 raeburn 11246: sub print_coursecategories {
1.57 raeburn 11247: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11248: my $datatable;
11249: if ($position eq 'top') {
1.238 raeburn 11250: my (%checked);
11251: my @catitems = ('unauth','auth');
11252: my @cattypes = ('std','domonly','codesrch','none');
11253: $checked{'unauth'} = 'std';
11254: $checked{'auth'} = 'std';
11255: if (ref($settings) eq 'HASH') {
11256: foreach my $type (@cattypes) {
11257: if ($type eq $settings->{'unauth'}) {
11258: $checked{'unauth'} = $type;
11259: }
11260: if ($type eq $settings->{'auth'}) {
11261: $checked{'auth'} = $type;
11262: }
11263: }
11264: }
11265: my %lt = &Apache::lonlocal::texthash (
11266: unauth => 'Catalog type for unauthenticated users',
11267: auth => 'Catalog type for authenticated users',
11268: none => 'No catalog',
11269: std => 'Standard catalog',
11270: domonly => 'Domain-only catalog',
11271: codesrch => "Code search form",
11272: );
11273: my $itemcount = 0;
11274: foreach my $item (@catitems) {
11275: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11276: $datatable .= '<tr '.$css_class.'>'.
11277: '<td>'.$lt{$item}.'</td>'.
11278: '<td class="LC_right_item"><span class="LC_nobreak">';
11279: foreach my $type (@cattypes) {
11280: my $ischecked;
11281: if ($checked{$item} eq $type) {
11282: $ischecked=' checked="checked"';
11283: }
11284: $datatable .= '<label>'.
11285: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11286: ' />'.$lt{$type}.'</label> ';
11287: }
1.327 raeburn 11288: $datatable .= '</span></td></tr>';
1.238 raeburn 11289: $itemcount ++;
11290: }
11291: $$rowtotal += $itemcount;
11292: } elsif ($position eq 'middle') {
1.57 raeburn 11293: my $toggle_cats_crs = ' ';
11294: my $toggle_cats_dom = ' checked="checked" ';
11295: my $can_cat_crs = ' ';
11296: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11297: my $toggle_catscomm_comm = ' ';
11298: my $toggle_catscomm_dom = ' checked="checked" ';
11299: my $can_catcomm_comm = ' ';
11300: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11301: my $toggle_catsplace_place = ' ';
11302: my $toggle_catsplace_dom = ' checked="checked" ';
11303: my $can_catplace_place = ' ';
11304: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11305:
1.57 raeburn 11306: if (ref($settings) eq 'HASH') {
11307: if ($settings->{'togglecats'} eq 'crs') {
11308: $toggle_cats_crs = $toggle_cats_dom;
11309: $toggle_cats_dom = ' ';
11310: }
11311: if ($settings->{'categorize'} eq 'crs') {
11312: $can_cat_crs = $can_cat_dom;
11313: $can_cat_dom = ' ';
11314: }
1.120 raeburn 11315: if ($settings->{'togglecatscomm'} eq 'comm') {
11316: $toggle_catscomm_comm = $toggle_catscomm_dom;
11317: $toggle_catscomm_dom = ' ';
11318: }
11319: if ($settings->{'categorizecomm'} eq 'comm') {
11320: $can_catcomm_comm = $can_catcomm_dom;
11321: $can_catcomm_dom = ' ';
11322: }
1.272 raeburn 11323: if ($settings->{'togglecatsplace'} eq 'place') {
11324: $toggle_catsplace_place = $toggle_catsplace_dom;
11325: $toggle_catsplace_dom = ' ';
11326: }
11327: if ($settings->{'categorizeplace'} eq 'place') {
11328: $can_catplace_place = $can_catplace_dom;
11329: $can_catplace_dom = ' ';
11330: }
1.57 raeburn 11331: }
11332: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11333: togglecats => 'Show/Hide a course in catalog',
11334: togglecatscomm => 'Show/Hide a community in catalog',
11335: togglecatsplace => 'Show/Hide a placement test in catalog',
11336: categorize => 'Assign a category to a course',
11337: categorizecomm => 'Assign a category to a community',
11338: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11339: );
11340: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11341: dom => 'Set in Domain',
11342: crs => 'Set in Course',
11343: comm => 'Set in Community',
11344: place => 'Set in Placement Test',
1.57 raeburn 11345: );
11346: $datatable = '<tr class="LC_odd_row">'.
11347: '<td>'.$title{'togglecats'}.'</td>'.
11348: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11349: '<input type="radio" name="togglecats"'.
11350: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11351: '<label><input type="radio" name="togglecats"'.
11352: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11353: '</tr><tr>'.
11354: '<td>'.$title{'categorize'}.'</td>'.
11355: '<td class="LC_right_item"><span class="LC_nobreak">'.
11356: '<label><input type="radio" name="categorize"'.
11357: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11358: '<label><input type="radio" name="categorize"'.
11359: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11360: '</tr><tr class="LC_odd_row">'.
11361: '<td>'.$title{'togglecatscomm'}.'</td>'.
11362: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11363: '<input type="radio" name="togglecatscomm"'.
11364: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11365: '<label><input type="radio" name="togglecatscomm"'.
11366: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11367: '</tr><tr>'.
11368: '<td>'.$title{'categorizecomm'}.'</td>'.
11369: '<td class="LC_right_item"><span class="LC_nobreak">'.
11370: '<label><input type="radio" name="categorizecomm"'.
11371: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11372: '<label><input type="radio" name="categorizecomm"'.
11373: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11374: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11375: '<td>'.$title{'togglecatsplace'}.'</td>'.
11376: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11377: '<input type="radio" name="togglecatsplace"'.
11378: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11379: '<label><input type="radio" name="togglecatscomm"'.
11380: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11381: '</tr><tr>'.
11382: '<td>'.$title{'categorizeplace'}.'</td>'.
11383: '<td class="LC_right_item"><span class="LC_nobreak">'.
11384: '<label><input type="radio" name="categorizeplace"'.
11385: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11386: '<label><input type="radio" name="categorizeplace"'.
11387: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11388: '</tr>';
1.272 raeburn 11389: $$rowtotal += 6;
1.57 raeburn 11390: } else {
11391: my $css_class;
11392: my $itemcount = 1;
11393: my $cathash;
11394: if (ref($settings) eq 'HASH') {
11395: $cathash = $settings->{'cats'};
11396: }
11397: if (ref($cathash) eq 'HASH') {
11398: my (@cats,@trails,%allitems,%idx,@jsarray);
11399: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11400: \%allitems,\%idx,\@jsarray);
11401: my $maxdepth = scalar(@cats);
11402: my $colattrib = '';
11403: if ($maxdepth > 2) {
11404: $colattrib = ' colspan="2" ';
11405: }
11406: my @path;
11407: if (@cats > 0) {
11408: if (ref($cats[0]) eq 'ARRAY') {
11409: my $numtop = @{$cats[0]};
11410: my $maxnum = $numtop;
1.120 raeburn 11411: my %default_names = (
11412: instcode => &mt('Official courses'),
11413: communities => &mt('Communities'),
1.272 raeburn 11414: placement => &mt('Placement Tests'),
1.120 raeburn 11415: );
11416:
11417: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11418: ($cathash->{'instcode::0'} eq '') ||
11419: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11420: ($cathash->{'communities::0'} eq '') ||
11421: (!grep(/^placement$/,@{$cats[0]})) ||
11422: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11423: $maxnum ++;
11424: }
11425: my $lastidx;
11426: for (my $i=0; $i<$numtop; $i++) {
11427: my $parent = $cats[0][$i];
11428: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11429: my $item = &escape($parent).'::0';
11430: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11431: $lastidx = $idx{$item};
11432: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11433: .'<select name="'.$item.'"'.$chgstr.'>';
11434: for (my $k=0; $k<=$maxnum; $k++) {
11435: my $vpos = $k+1;
11436: my $selstr;
11437: if ($k == $i) {
11438: $selstr = ' selected="selected" ';
11439: }
11440: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11441: }
1.214 raeburn 11442: $datatable .= '</select></span></td><td>';
1.272 raeburn 11443: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11444: $datatable .= '<span class="LC_nobreak">'
11445: .$default_names{$parent}.'</span>';
11446: if ($parent eq 'instcode') {
11447: $datatable .= '<br /><span class="LC_nobreak">('
11448: .&mt('with institutional codes')
11449: .')</span></td><td'.$colattrib.'>';
11450: } else {
11451: $datatable .= '<table><tr><td>';
11452: }
11453: $datatable .= '<span class="LC_nobreak">'
11454: .'<label><input type="radio" name="'
11455: .$parent.'" value="1" checked="checked" />'
11456: .&mt('Display').'</label>';
11457: if ($parent eq 'instcode') {
11458: $datatable .= ' ';
11459: } else {
11460: $datatable .= '</span></td></tr><tr><td>'
11461: .'<span class="LC_nobreak">';
11462: }
11463: $datatable .= '<label><input type="radio" name="'
11464: .$parent.'" value="0" />'
11465: .&mt('Do not display').'</label></span>';
1.272 raeburn 11466: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11467: $datatable .= '</td></tr></table>';
11468: }
11469: $datatable .= '</td>';
1.57 raeburn 11470: } else {
11471: $datatable .= $parent
1.214 raeburn 11472: .' <span class="LC_nobreak"><label>'
11473: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11474: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11475: }
11476: my $depth = 1;
11477: push(@path,$parent);
11478: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11479: pop(@path);
11480: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11481: $itemcount ++;
11482: }
1.48 raeburn 11483: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11484: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11485: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11486: for (my $k=0; $k<=$maxnum; $k++) {
11487: my $vpos = $k+1;
11488: my $selstr;
1.57 raeburn 11489: if ($k == $numtop) {
1.48 raeburn 11490: $selstr = ' selected="selected" ';
11491: }
11492: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11493: }
1.59 bisitz 11494: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11495: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11496: .'</tr>'."\n";
1.48 raeburn 11497: $itemcount ++;
1.272 raeburn 11498: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11499: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11500: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11501: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11502: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11503: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11504: for (my $k=0; $k<=$maxnum; $k++) {
11505: my $vpos = $k+1;
11506: my $selstr;
11507: if ($k == $maxnum) {
11508: $selstr = ' selected="selected" ';
11509: }
11510: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11511: }
1.120 raeburn 11512: $datatable .= '</select></span></td>'.
11513: '<td><span class="LC_nobreak">'.
11514: $default_names{$default}.'</span>';
11515: if ($default eq 'instcode') {
11516: $datatable .= '<br /><span class="LC_nobreak">('
11517: .&mt('with institutional codes').')</span>';
11518: }
11519: $datatable .= '</td>'
11520: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11521: .&mt('Display').'</label> '
11522: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11523: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11524: }
11525: }
11526: }
1.57 raeburn 11527: } else {
11528: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11529: }
11530: } else {
1.327 raeburn 11531: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11532: .&initialize_categories($itemcount);
1.48 raeburn 11533: }
1.57 raeburn 11534: $$rowtotal += $itemcount;
1.48 raeburn 11535: }
11536: return $datatable;
11537: }
11538:
1.69 raeburn 11539: sub print_serverstatuses {
11540: my ($dom,$settings,$rowtotal) = @_;
11541: my $datatable;
11542: my @pages = &serverstatus_pages();
11543: my (%namedaccess,%machineaccess);
11544: foreach my $type (@pages) {
11545: $namedaccess{$type} = '';
11546: $machineaccess{$type}= '';
11547: }
11548: if (ref($settings) eq 'HASH') {
11549: foreach my $type (@pages) {
11550: if (exists($settings->{$type})) {
11551: if (ref($settings->{$type}) eq 'HASH') {
11552: foreach my $key (keys(%{$settings->{$type}})) {
11553: if ($key eq 'namedusers') {
11554: $namedaccess{$type} = $settings->{$type}->{$key};
11555: } elsif ($key eq 'machines') {
11556: $machineaccess{$type} = $settings->{$type}->{$key};
11557: }
11558: }
11559: }
11560: }
11561: }
11562: }
1.81 raeburn 11563: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11564: my $rownum = 0;
11565: my $css_class;
11566: foreach my $type (@pages) {
11567: $rownum ++;
11568: $css_class = $rownum%2?' class="LC_odd_row"':'';
11569: $datatable .= '<tr'.$css_class.'>'.
11570: '<td><span class="LC_nobreak">'.
11571: $titles->{$type}.'</span></td>'.
11572: '<td class="LC_left_item">'.
11573: '<input type="text" name="'.$type.'_namedusers" '.
11574: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11575: '<td class="LC_right_item">'.
11576: '<span class="LC_nobreak">'.
11577: '<input type="text" name="'.$type.'_machines" '.
11578: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11579: '</span></td></tr>'."\n";
1.69 raeburn 11580: }
11581: $$rowtotal += $rownum;
11582: return $datatable;
11583: }
11584:
11585: sub serverstatus_pages {
11586: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11587: 'checksums','clusterstatus','certstatus','metadata_keywords',
11588: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11589: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11590: }
11591:
1.236 raeburn 11592: sub defaults_javascript {
11593: my ($settings) = @_;
1.354 raeburn 11594: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11595: my $portal_js = <<"ENDPORTAL";
11596:
11597: function portalExtras(caller) {
11598: var x = caller.value;
11599: var y = new Array('email','web');
1.425 raeburn 11600: for (var i=0; i<y.length; i++) {
1.414 raeburn 11601: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11602: var z = document.getElementById('portal_def_'+y[i]+'_div');
11603: if (x.length > 0) {
11604: z.style.display = 'block';
11605: } else {
11606: z.style.display = 'none';
11607: }
11608: }
11609: }
11610: }
11611: ENDPORTAL
1.236 raeburn 11612: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11613: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11614: if ($maxnum eq '') {
11615: $maxnum = 0;
11616: }
11617: $maxnum ++;
1.249 raeburn 11618: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11619: return <<"ENDSCRIPT";
11620: <script type="text/javascript">
11621: // <![CDATA[
11622: function reorderTypes(form,caller) {
11623: var changedVal;
11624: $jstext
11625: var newpos = 'addinststatus_pos';
11626: var current = new Array;
11627: var maxh = $maxnum;
11628: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11629: var oldVal;
11630: if (caller == newpos) {
11631: changedVal = newitemVal;
11632: } else {
11633: var curritem = 'inststatus_pos_'+caller;
11634: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11635: current[newitemVal] = newpos;
11636: }
11637: for (var i=0; i<inststatuses.length; i++) {
11638: if (inststatuses[i] != caller) {
11639: var elementName = 'inststatus_pos_'+inststatuses[i];
11640: if (form.elements[elementName]) {
11641: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11642: current[currVal] = elementName;
11643: }
11644: }
11645: }
11646: for (var j=0; j<maxh; j++) {
11647: if (current[j] == undefined) {
11648: oldVal = j;
11649: }
11650: }
11651: if (oldVal < changedVal) {
11652: for (var k=oldVal+1; k<=changedVal ; k++) {
11653: var elementName = current[k];
11654: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11655: }
11656: } else {
11657: for (var k=changedVal; k<oldVal; k++) {
11658: var elementName = current[k];
11659: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11660: }
11661: }
11662: return;
11663: }
11664:
1.414 raeburn 11665: $portal_js
11666:
11667: // ]]>
11668: </script>
11669:
11670: ENDSCRIPT
11671: } else {
11672: return <<"ENDSCRIPT";
11673: <script type="text/javascript">
11674: // <![CDATA[
11675: $portal_js
1.236 raeburn 11676: // ]]>
11677: </script>
11678:
11679: ENDSCRIPT
11680: }
1.354 raeburn 11681: return;
11682: }
11683:
11684: sub passwords_javascript {
1.405 raeburn 11685: my ($prefix) = @_;
11686: my %intalert;
11687: if ($prefix eq 'passwords') {
11688: %intalert = &Apache::lonlocal::texthash (
11689: 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.',
11690: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11691: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11692: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11693: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11694: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11695: );
1.421 raeburn 11696: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11697: %intalert = &Apache::lonlocal::texthash (
11698: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11699: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11700: );
11701: }
1.365 raeburn 11702: &js_escape(\%intalert);
11703: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11704: my $intauthjs;
1.405 raeburn 11705: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11706:
11707: function warnIntAuth(field) {
11708: if (field.name == 'intauth_check') {
11709: if (field.value == '2') {
1.365 raeburn 11710: alert('$intalert{authcheck}');
1.354 raeburn 11711: }
11712: }
11713: if (field.name == 'intauth_cost') {
11714: field.value.replace(/\s/g,'');
11715: if (field.value != '') {
11716: var regexdigit=/^\\d+\$/;
11717: if (!regexdigit.test(field.value)) {
1.365 raeburn 11718: alert('$intalert{authcost}');
11719: }
11720: }
11721: }
11722: return;
11723: }
11724:
1.405 raeburn 11725: ENDSCRIPT
11726:
11727: }
11728:
11729: $intauthjs .= <<"ENDSCRIPT";
11730:
11731: function warnInt$prefix(field) {
1.365 raeburn 11732: field.value.replace(/^\s+/,'');
11733: field.value.replace(/\s+\$/,'');
11734: var regexdigit=/^\\d+\$/;
1.408 raeburn 11735: if (field.name == '${prefix}_min') {
1.365 raeburn 11736: if (field.value == '') {
11737: alert('$intalert{passmin}');
11738: field.value = '$defmin';
11739: } else {
11740: if (!regexdigit.test(field.value)) {
11741: alert('$intalert{passmin}');
11742: field.value = '$defmin';
11743: }
1.366 raeburn 11744: var minval = parseInt(field.value,10);
1.365 raeburn 11745: if (minval < $defmin) {
11746: alert('$intalert{passmin}');
11747: field.value = '$defmin';
11748: }
11749: }
11750: } else {
11751: if (field.value == '0') {
11752: field.value = '';
11753: }
11754: if (field.value != '') {
1.408 raeburn 11755: if (field.name == '${prefix}_expire') {
1.365 raeburn 11756: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11757: if (!regexpposnum.test(field.value)) {
11758: alert('$intalert{passexp}');
11759: field.value = '';
11760: } else {
11761: var expval = parseFloat(field.value);
11762: if (expval == 0) {
11763: alert('$intalert{passexp}');
11764: field.value = '';
11765: }
11766: }
11767: } else {
11768: if (!regexdigit.test(field.value)) {
1.408 raeburn 11769: if (field.name == '${prefix}_max') {
1.365 raeburn 11770: alert('$intalert{passmax}');
11771: } else {
1.408 raeburn 11772: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11773: alert('$intalert{passnum}');
11774: }
11775: }
1.370 raeburn 11776: field.value = '';
1.365 raeburn 11777: }
1.354 raeburn 11778: }
11779: }
11780: }
11781: return;
11782: }
11783:
11784: ENDSCRIPT
11785: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11786: }
11787:
1.49 raeburn 11788: sub coursecategories_javascript {
11789: my ($settings) = @_;
1.57 raeburn 11790: my ($output,$jstext,$cathash);
1.49 raeburn 11791: if (ref($settings) eq 'HASH') {
1.57 raeburn 11792: $cathash = $settings->{'cats'};
11793: }
11794: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11795: my (@cats,@jsarray,%idx);
1.57 raeburn 11796: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11797: if (@jsarray > 0) {
11798: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11799: for (my $i=0; $i<@jsarray; $i++) {
11800: if (ref($jsarray[$i]) eq 'ARRAY') {
11801: my $catstr = join('","',@{$jsarray[$i]});
11802: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11803: }
11804: }
11805: }
11806: } else {
11807: $jstext = ' var categories = Array(1);'."\n".
11808: ' categories[0] = Array("instcode_pos");'."\n";
11809: }
1.237 bisitz 11810: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11811: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11812: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11813: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11814: &js_escape(\$instcode_reserved);
11815: &js_escape(\$communities_reserved);
1.272 raeburn 11816: &js_escape(\$placement_reserved);
1.265 damieng 11817: &js_escape(\$choose_again);
1.49 raeburn 11818: $output = <<"ENDSCRIPT";
11819: <script type="text/javascript">
1.109 raeburn 11820: // <![CDATA[
1.49 raeburn 11821: function reorderCats(form,parent,item,idx) {
11822: var changedVal;
11823: $jstext
11824: var newpos = 'addcategory_pos';
11825: if (parent == '') {
11826: var has_instcode = 0;
11827: var maxtop = categories[idx].length;
11828: for (var j=0; j<maxtop; j++) {
11829: if (categories[idx][j] == 'instcode::0') {
11830: has_instcode == 1;
11831: }
11832: }
11833: if (has_instcode == 0) {
11834: categories[idx][maxtop] = 'instcode_pos';
11835: }
11836: } else {
11837: newpos += '_'+parent;
11838: }
11839: var maxh = 1 + categories[idx].length;
11840: var current = new Array;
11841: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11842: if (item == newpos) {
11843: changedVal = newitemVal;
11844: } else {
11845: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11846: current[newitemVal] = newpos;
11847: }
11848: for (var i=0; i<categories[idx].length; i++) {
11849: var elementName = categories[idx][i];
11850: if (elementName != item) {
11851: if (form.elements[elementName]) {
11852: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11853: current[currVal] = elementName;
11854: }
11855: }
11856: }
11857: var oldVal;
11858: for (var j=0; j<maxh; j++) {
11859: if (current[j] == undefined) {
11860: oldVal = j;
11861: }
11862: }
11863: if (oldVal < changedVal) {
11864: for (var k=oldVal+1; k<=changedVal ; k++) {
11865: var elementName = current[k];
11866: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11867: }
11868: } else {
11869: for (var k=changedVal; k<oldVal; k++) {
11870: var elementName = current[k];
11871: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11872: }
11873: }
11874: return;
11875: }
1.120 raeburn 11876:
11877: function categoryCheck(form) {
11878: if (form.elements['addcategory_name'].value == 'instcode') {
11879: alert('$instcode_reserved\\n$choose_again');
11880: return false;
11881: }
11882: if (form.elements['addcategory_name'].value == 'communities') {
11883: alert('$communities_reserved\\n$choose_again');
11884: return false;
11885: }
1.272 raeburn 11886: if (form.elements['addcategory_name'].value == 'placement') {
11887: alert('$placement_reserved\\n$choose_again');
11888: return false;
11889: }
1.120 raeburn 11890: return true;
11891: }
11892:
1.109 raeburn 11893: // ]]>
1.49 raeburn 11894: </script>
11895:
11896: ENDSCRIPT
11897: return $output;
11898: }
11899:
1.48 raeburn 11900: sub initialize_categories {
11901: my ($itemcount) = @_;
1.120 raeburn 11902: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11903: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11904: instcode => 'Official courses (with institutional codes)',
11905: communities => 'Communities',
1.272 raeburn 11906: placement => 'Placement Tests',
1.120 raeburn 11907: );
1.328 raeburn 11908: my %selnum = (
11909: instcode => '0',
11910: communities => '1',
11911: placement => '2',
11912: );
11913: my %selected;
1.272 raeburn 11914: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11915: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11916: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11917: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11918: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11919: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11920: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11921: .'<option value="0"'.$selected{'0'}.'>1</option>'
11922: .'<option value="1"'.$selected{'1'}.'>2</option>'
11923: .'<option value="2"'.$selected{'2'}.'>3</option>'
11924: .'<option value="3">4</option></select> '
1.120 raeburn 11925: .$default_names{$default}
11926: .'</span></td><td><span class="LC_nobreak">'
11927: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11928: .&mt('Display').'</label> <label>'
11929: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11930: .'</label></span></td></tr>';
1.120 raeburn 11931: $itemcount ++;
11932: }
1.48 raeburn 11933: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11934: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11935: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11936: .'<select name="addcategory_pos"'.$chgstr.'>'
11937: .'<option value="0">1</option>'
11938: .'<option value="1">2</option>'
1.328 raeburn 11939: .'<option value="2">3</option>'
11940: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11941: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11942: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11943: .'</td></tr>';
1.48 raeburn 11944: return $datatable;
11945: }
11946:
11947: sub build_category_rows {
1.49 raeburn 11948: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11949: my ($text,$name,$item,$chgstr);
1.48 raeburn 11950: if (ref($cats) eq 'ARRAY') {
11951: my $maxdepth = scalar(@{$cats});
11952: if (ref($cats->[$depth]) eq 'HASH') {
11953: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11954: my $numchildren = @{$cats->[$depth]{$parent}};
11955: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11956: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11957: my ($idxnum,$parent_name,$parent_item);
11958: my $higher = $depth - 1;
11959: if ($higher == 0) {
11960: $parent_name = &escape($parent).'::'.$higher;
11961: } else {
11962: if (ref($path) eq 'ARRAY') {
11963: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11964: }
11965: }
11966: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11967: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11968: if ($j < $numchildren) {
1.48 raeburn 11969: $name = $cats->[$depth]{$parent}[$j];
11970: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11971: $idxnum = $idx->{$item};
11972: } else {
11973: $name = $parent_name;
11974: $item = $parent_item;
1.48 raeburn 11975: }
1.49 raeburn 11976: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11977: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11978: for (my $i=0; $i<=$numchildren; $i++) {
11979: my $vpos = $i+1;
11980: my $selstr;
11981: if ($j == $i) {
11982: $selstr = ' selected="selected" ';
11983: }
11984: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11985: }
11986: $text .= '</select> ';
11987: if ($j < $numchildren) {
11988: my $deeper = $depth+1;
11989: $text .= $name.' '
11990: .'<label><input type="checkbox" name="deletecategory" value="'
11991: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11992: if(ref($path) eq 'ARRAY') {
11993: push(@{$path},$name);
1.49 raeburn 11994: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11995: pop(@{$path});
11996: }
11997: } else {
1.330 raeburn 11998: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11999: if ($j == $numchildren) {
12000: $text .= $name;
12001: } else {
12002: $text .= $item;
12003: }
12004: $text .= '" value="" />';
12005: }
12006: $text .= '</td></tr>';
12007: }
12008: $text .= '</table></td>';
12009: } else {
12010: my $higher = $depth-1;
12011: if ($higher == 0) {
12012: $name = &escape($parent).'::'.$higher;
12013: } else {
12014: if (ref($path) eq 'ARRAY') {
12015: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12016: }
12017: }
12018: my $colspan;
12019: if ($parent ne 'instcode') {
12020: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 12021: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 12022: }
12023: }
12024: }
12025: }
12026: return $text;
12027: }
12028:
1.33 raeburn 12029: sub modifiable_userdata_row {
1.305 raeburn 12030: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 12031: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 12032: my ($role,$rolename,$statustype);
12033: $role = $item;
1.224 raeburn 12034: if ($context eq 'cancreate') {
1.305 raeburn 12035: if ($item =~ /^(emailusername)_(.+)$/) {
12036: $role = $1;
12037: $statustype = $2;
1.228 raeburn 12038: if (ref($usertypes) eq 'HASH') {
12039: if ($usertypes->{$statustype}) {
12040: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
12041: } else {
12042: $rolename = &mt('Data provided by user');
12043: }
12044: }
1.224 raeburn 12045: }
12046: } elsif ($context eq 'selfcreate') {
1.63 raeburn 12047: if (ref($usertypes) eq 'HASH') {
12048: $rolename = $usertypes->{$role};
12049: } else {
12050: $rolename = $role;
12051: }
1.325 raeburn 12052: } elsif ($context eq 'lti') {
12053: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 12054: } elsif ($context eq 'privacy') {
12055: $rolename = $itemdesc;
1.33 raeburn 12056: } else {
1.63 raeburn 12057: if ($role eq 'cr') {
12058: $rolename = &mt('Custom role');
12059: } else {
12060: $rolename = &Apache::lonnet::plaintext($role);
12061: }
1.33 raeburn 12062: }
1.224 raeburn 12063: my (@fields,%fieldtitles);
12064: if (ref($fieldsref) eq 'ARRAY') {
12065: @fields = @{$fieldsref};
12066: } else {
12067: @fields = ('lastname','firstname','middlename','generation',
12068: 'permanentemail','id');
12069: }
12070: if ((ref($titlesref) eq 'HASH')) {
12071: %fieldtitles = %{$titlesref};
12072: } else {
12073: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12074: }
1.33 raeburn 12075: my $output;
1.305 raeburn 12076: my $css_class;
12077: if ($rowcount%2) {
12078: $css_class = 'LC_odd_row';
12079: }
12080: if ($customcss) {
12081: $css_class .= " $customcss";
12082: }
12083: $css_class =~ s/^\s+//;
12084: if ($css_class) {
12085: $css_class = ' class="'.$css_class.'"';
12086: }
12087: if ($rowstyle) {
12088: $css_class .= ' style="'.$rowstyle.'"';
12089: }
12090: if ($rowid) {
12091: $rowid = ' id="'.$rowid.'"';
12092: }
12093: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 12094: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
12095: '<td class="LC_left_item" colspan="2"><table>';
12096: my $rem;
12097: my %checks;
12098: if (ref($settings) eq 'HASH') {
1.325 raeburn 12099: my $hashref;
12100: if ($context eq 'lti') {
12101: if (ref($settings) eq 'HASH') {
1.447.2.2 raeburn 12102: my %instdata;
12103: if (ref($settings->{'instdata'}) eq 'ARRAY') {
12104: map { $instdata{$_} = 1; } @{$settings->{'instdata'}};
12105: }
12106: $hashref = \%instdata;
1.325 raeburn 12107: }
1.357 raeburn 12108: } elsif ($context eq 'privacy') {
12109: my ($key,$inner) = split(/_/,$role);
12110: if (ref($settings) eq 'HASH') {
12111: if (ref($settings->{$key}) eq 'HASH') {
12112: $hashref = $settings->{$key}->{$inner};
12113: }
12114: }
1.325 raeburn 12115: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12116: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.447.2.2 raeburn 12117: $hashref = $settings->{$context}->{$role};
1.325 raeburn 12118: }
12119: if ($role eq 'emailusername') {
12120: if ($statustype) {
12121: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12122: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12123: }
1.325 raeburn 12124: }
12125: }
12126: }
1.425 raeburn 12127: if (ref($hashref) eq 'HASH') {
1.325 raeburn 12128: foreach my $field (@fields) {
12129: if ($hashref->{$field}) {
12130: if ($role eq 'emailusername') {
12131: $checks{$field} = $hashref->{$field};
12132: } else {
12133: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12134: }
12135: }
12136: }
12137: }
12138: }
1.305 raeburn 12139: my $total = scalar(@fields);
12140: for (my $i=0; $i<$total; $i++) {
12141: $rem = $i%($numinrow);
1.33 raeburn 12142: if ($rem == 0) {
12143: if ($i > 0) {
12144: $output .= '</tr>';
12145: }
12146: $output .= '<tr>';
12147: }
12148: my $check = ' ';
1.228 raeburn 12149: unless ($role eq 'emailusername') {
12150: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12151: $check = $checks{$fields[$i]};
1.357 raeburn 12152: } elsif ($context eq 'privacy') {
12153: if ($role =~ /^priv_(domain|course)$/) {
12154: if (ref($settings) ne 'HASH') {
12155: $check = ' checked="checked" ';
12156: }
12157: } elsif ($role =~ /^priv_(author|community)$/) {
12158: if (ref($settings) ne 'HASH') {
12159: unless ($fields[$i] eq 'id') {
12160: $check = ' checked="checked" ';
12161: }
12162: }
12163: } elsif ($role =~ /^(unpriv|othdom)_/) {
12164: if (ref($settings) ne 'HASH') {
12165: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12166: $check = ' checked="checked" ';
12167: }
12168: }
12169: }
1.325 raeburn 12170: } elsif ($context ne 'lti') {
1.228 raeburn 12171: if ($role eq 'st') {
12172: if (ref($settings) ne 'HASH') {
12173: $check = ' checked="checked" ';
12174: }
1.33 raeburn 12175: }
12176: }
12177: }
12178: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12179: '<span class="LC_nobreak">';
1.325 raeburn 12180: my $prefix = 'canmodify';
1.228 raeburn 12181: if ($role eq 'emailusername') {
12182: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12183: $checks{$fields[$i]} = 'omit';
12184: }
12185: foreach my $option ('required','optional','omit') {
12186: my $checked='';
12187: if ($checks{$fields[$i]} eq $option) {
12188: $checked='checked="checked" ';
12189: }
12190: $output .= '<label>'.
1.325 raeburn 12191: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12192: &mt($option).'</label>'.(' ' x2);
12193: }
12194: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12195: } else {
1.325 raeburn 12196: if ($context eq 'lti') {
12197: $prefix = 'lti';
1.443 raeburn 12198: } elsif ($context eq 'coauthor') {
12199: $prefix = 'cacanmodify';
1.357 raeburn 12200: } elsif ($context eq 'privacy') {
12201: $prefix = 'privacy';
1.325 raeburn 12202: }
1.228 raeburn 12203: $output .= '<label>'.
1.325 raeburn 12204: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12205: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12206: '</label>';
12207: }
12208: $output .= '</span></td>';
1.33 raeburn 12209: }
1.305 raeburn 12210: $rem = $total%$numinrow;
12211: my $colsleft;
12212: if ($rem) {
12213: $colsleft = $numinrow - $rem;
12214: }
12215: if ($colsleft > 1) {
1.33 raeburn 12216: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12217: ' </td>';
12218: } elsif ($colsleft == 1) {
12219: $output .= '<td class="LC_left_item"> </td>';
12220: }
12221: $output .= '</tr></table></td></tr>';
12222: return $output;
12223: }
1.28 raeburn 12224:
1.93 raeburn 12225: sub insttypes_row {
1.305 raeburn 12226: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12227: $customcss,$rowstyle) = @_;
1.93 raeburn 12228: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12229: cansearch => 'Users allowed to search',
1.93 raeburn 12230: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12231: lockablenames => 'User preference to lock name',
12232: selfassign => 'Self-reportable affiliations',
12233: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12234: webdav => 'WebDAV access available',
12235: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12236: );
1.429 raeburn 12237: my ($showdom,$defaultquota);
1.93 raeburn 12238: if ($context eq 'cansearch') {
12239: $showdom = ' ('.$dom.')';
1.429 raeburn 12240: } elsif ($context eq 'authorquota') {
12241: $defaultquota = 500;
1.93 raeburn 12242: }
1.165 raeburn 12243: my $class = 'LC_left_item';
12244: if ($context eq 'statustocreate') {
12245: $class = 'LC_right_item';
12246: }
1.305 raeburn 12247: my $css_class;
12248: if ($$rowtotal%2) {
12249: $css_class = 'LC_odd_row';
12250: }
12251: if ($customcss) {
12252: $css_class .= ' '.$customcss;
12253: }
12254: $css_class =~ s/^\s+//;
12255: if ($css_class) {
12256: $css_class = ' class="'.$css_class.'"';
12257: }
12258: if ($rowstyle) {
12259: $css_class .= ' style="'.$rowstyle.'"';
12260: }
12261: if ($onclick) {
12262: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12263: }
12264: my $output = '<tr'.$css_class.'>'.
12265: '<td>'.$lt{$context}.$showdom.
12266: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12267: my $rem;
12268: if (ref($types) eq 'ARRAY') {
12269: for (my $i=0; $i<@{$types}; $i++) {
12270: if (defined($usertypes->{$types->[$i]})) {
12271: my $rem = $i%($numinrow);
12272: if ($rem == 0) {
12273: if ($i > 0) {
12274: $output .= '</tr>';
12275: }
12276: $output .= '<tr>';
1.23 raeburn 12277: }
1.429 raeburn 12278: if ($context eq 'authorquota') {
12279: my $currquota;
12280: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12281: $currquota = $settings->{$context}->{$types->[$i]};
12282: } else {
12283: $currquota = $defaultquota;
12284: }
12285: $output .= '<td class="LC_left_item">'."\n".
12286: '<label><span class="LC_nobreak">'."\n".
12287: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12288: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12289: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12290: '</label></td>';
12291: } else {
12292: my $check = ' ';
12293: if (ref($settings) eq 'HASH') {
12294: if (ref($settings->{$context}) eq 'ARRAY') {
12295: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12296: $check = ' checked="checked" ';
12297: }
12298: } elsif (ref($settings->{$context}) eq 'HASH') {
12299: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12300: $check = ' checked="checked" ';
12301: } elsif ($context eq 'webdav') {
12302: if ($settings->{$context}->{$types->[$i]}) {
12303: $check = ' checked="checked" ';
12304: }
12305: }
12306: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12307: $check = ' checked="checked" ';
12308: }
1.26 raeburn 12309: }
1.429 raeburn 12310: $output .= '<td class="LC_left_item">'.
12311: '<span class="LC_nobreak"><label>'.
12312: '<input type="checkbox" name="'.$context.'" '.
12313: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12314: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12315: }
12316: }
12317: }
1.26 raeburn 12318: $rem = @{$types}%($numinrow);
1.23 raeburn 12319: }
12320: my $colsleft = $numinrow - $rem;
1.315 raeburn 12321: if ($context eq 'overrides') {
12322: if ($colsleft > 1) {
12323: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12324: } else {
12325: $output .= '<td class="LC_left_item">';
12326: }
1.425 raeburn 12327: $output .= ' ';
1.23 raeburn 12328: } else {
1.334 raeburn 12329: if ($rem == 0) {
1.315 raeburn 12330: $output .= '<tr>';
12331: }
12332: if ($colsleft > 1) {
12333: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12334: } else {
12335: $output .= '<td class="LC_left_item">';
12336: }
1.429 raeburn 12337: if ($context eq 'authorquota') {
12338: my $currquota = 500;
12339: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12340: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12341: $currquota = $settings->{$context}{'default'};
12342: }
12343: }
12344: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12345: '<input type="text" name="'.$context.'_default" '.
12346: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12347: '</label>';
12348: } else {
12349: my $defcheck = ' ';
12350: if (ref($settings) eq 'HASH') {
12351: if (ref($settings->{$context}) eq 'ARRAY') {
12352: if (grep(/^default$/,@{$settings->{$context}})) {
12353: $defcheck = ' checked="checked" ';
12354: }
12355: } elsif (ref($settings->{$context}) eq 'HASH') {
12356: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12357: $defcheck = ' checked="checked" ';
12358: } elsif ($context eq 'webdav') {
12359: if ($settings->{$context}->{'default'}) {
12360: $defcheck = ' checked="checked" ';
12361: }
12362: }
12363: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12364: $defcheck = ' checked="checked" ';
12365: }
1.99 raeburn 12366: }
1.429 raeburn 12367: $output .= '<span class="LC_nobreak"><label>'.
12368: '<input type="checkbox" name="'.$context.'" '.
12369: 'value="default"'.$defcheck.$onclick.'/>'.
12370: $othertitle.'</label></span>';
1.26 raeburn 12371: }
1.23 raeburn 12372: }
1.315 raeburn 12373: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12374: return $output;
1.23 raeburn 12375: }
12376:
12377: sub sorted_searchtitles {
12378: my %searchtitles = &Apache::lonlocal::texthash(
12379: 'uname' => 'username',
12380: 'lastname' => 'last name',
12381: 'lastfirst' => 'last name, first name',
12382: );
12383: my @titleorder = ('uname','lastname','lastfirst');
12384: return (\%searchtitles,\@titleorder);
12385: }
12386:
1.25 raeburn 12387: sub sorted_searchtypes {
12388: my %srchtypes_desc = (
12389: exact => 'is exact match',
12390: contains => 'contains ..',
12391: begins => 'begins with ..',
12392: );
12393: my @srchtypeorder = ('exact','begins','contains');
12394: return (\%srchtypes_desc,\@srchtypeorder);
12395: }
12396:
1.3 raeburn 12397: sub usertype_update_row {
12398: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12399: my $datatable;
12400: my $numinrow = 4;
12401: foreach my $type (@{$types}) {
12402: if (defined($usertypes->{$type})) {
12403: $$rownums ++;
12404: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12405: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12406: '</td><td class="LC_left_item"><table>';
12407: for (my $i=0; $i<@{$fields}; $i++) {
12408: my $rem = $i%($numinrow);
12409: if ($rem == 0) {
12410: if ($i > 0) {
12411: $datatable .= '</tr>';
12412: }
12413: $datatable .= '<tr>';
12414: }
12415: my $check = ' ';
1.39 raeburn 12416: if (ref($settings) eq 'HASH') {
12417: if (ref($settings->{'fields'}) eq 'HASH') {
12418: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12419: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12420: $check = ' checked="checked" ';
12421: }
1.3 raeburn 12422: }
12423: }
12424: }
12425:
12426: if ($i == @{$fields}-1) {
12427: my $colsleft = $numinrow - $rem;
12428: if ($colsleft > 1) {
12429: $datatable .= '<td colspan="'.$colsleft.'">';
12430: } else {
12431: $datatable .= '<td>';
12432: }
12433: } else {
12434: $datatable .= '<td>';
12435: }
1.8 raeburn 12436: $datatable .= '<span class="LC_nobreak"><label>'.
12437: '<input type="checkbox" name="updateable_'.$type.
12438: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12439: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12440: }
12441: $datatable .= '</tr></table></td></tr>';
12442: }
12443: }
12444: return $datatable;
1.1 raeburn 12445: }
12446:
12447: sub modify_login {
1.205 raeburn 12448: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12449: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12450: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12451: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12452: %title = ( coursecatalog => 'Display course catalog',
12453: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12454: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12455: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12456: loginheader => 'Log-in box header',
12457: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12458: @offon = ('off','on');
1.112 raeburn 12459: if (ref($domconfig{login}) eq 'HASH') {
12460: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12461: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12462: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12463: }
12464: }
1.386 raeburn 12465: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12466: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12467: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12468: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12469: $saml{$lonhost} = 1;
12470: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12471: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12472: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12473: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12474: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12475: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12476: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12477: }
12478: }
12479: }
1.112 raeburn 12480: }
1.9 raeburn 12481: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12482: \%domconfig,\%loginhash);
1.188 raeburn 12483: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12484: foreach my $item (@toggles) {
12485: $loginhash{login}{$item} = $env{'form.'.$item};
12486: }
1.41 raeburn 12487: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12488: if (ref($colchanges{'login'}) eq 'HASH') {
12489: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12490: \%loginhash);
12491: }
1.110 raeburn 12492:
1.149 raeburn 12493: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12494: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12495: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12496: if (keys(%servers) > 1) {
12497: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12498: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12499: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12500: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12501: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12502: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12503: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12504: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12505: $changes{'loginvia'}{$lonhost} = 1;
12506: } else {
12507: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12508: $changes{'loginvia'}{$lonhost} = 1;
12509: }
12510: } else {
12511: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12512: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12513: $changes{'loginvia'}{$lonhost} = 1;
12514: }
12515: }
12516: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12517: foreach my $item (@loginvia_attribs) {
12518: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12519: }
12520: } else {
12521: foreach my $item (@loginvia_attribs) {
12522: my $new = $env{'form.'.$lonhost.'_'.$item};
12523: if (($item eq 'serverpath') && ($new eq 'custom')) {
12524: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12525: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12526: $new = '/';
12527: }
12528: }
12529: if (($item eq 'custompath') &&
12530: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12531: $new = '';
12532: }
12533: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12534: $changes{'loginvia'}{$lonhost} = 1;
12535: }
12536: if ($item eq 'exempt') {
1.256 raeburn 12537: $new = &check_exempt_addresses($new);
1.128 raeburn 12538: }
12539: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12540: }
12541: }
1.112 raeburn 12542: } else {
1.128 raeburn 12543: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12544: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12545: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12546: foreach my $item (@loginvia_attribs) {
12547: my $new = $env{'form.'.$lonhost.'_'.$item};
12548: if (($item eq 'serverpath') && ($new eq 'custom')) {
12549: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12550: $new = '/';
12551: }
12552: }
12553: if (($item eq 'custompath') &&
12554: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12555: $new = '';
12556: }
12557: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12558: }
1.110 raeburn 12559: }
12560: }
12561: }
12562: }
1.119 raeburn 12563:
1.168 raeburn 12564: my $servadm = $r->dir_config('lonAdmEMail');
12565: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12566: if (ref($domconfig{'login'}) eq 'HASH') {
12567: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12568: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12569: if ($lang eq 'nolang') {
12570: push(@currlangs,$lang);
12571: } elsif (defined($langchoices{$lang})) {
12572: push(@currlangs,$lang);
12573: } else {
12574: next;
12575: }
12576: }
12577: }
12578: }
12579: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12580: if (@currlangs > 0) {
12581: foreach my $lang (@currlangs) {
12582: if (grep(/^\Q$lang\E$/,@delurls)) {
12583: $changes{'helpurl'}{$lang} = 1;
12584: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12585: $changes{'helpurl'}{$lang} = 1;
12586: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12587: push(@newlangs,$lang);
12588: } else {
12589: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12590: }
12591: }
12592: }
12593: unless (grep(/^nolang$/,@currlangs)) {
12594: if ($env{'form.loginhelpurl_nolang.filename'}) {
12595: $changes{'helpurl'}{'nolang'} = 1;
12596: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12597: push(@newlangs,'nolang');
12598: }
12599: }
12600: if ($env{'form.loginhelpurl_add_lang'}) {
12601: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12602: ($env{'form.loginhelpurl_add_file.filename'})) {
12603: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12604: $addedfile = $env{'form.loginhelpurl_add_lang'};
12605: }
12606: }
12607: if ((@newlangs > 0) || ($addedfile)) {
12608: my $error;
12609: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12610: if ($configuserok eq 'ok') {
12611: if ($switchserver) {
12612: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12613: } elsif ($author_ok eq 'ok') {
12614: my @allnew = @newlangs;
12615: if ($addedfile ne '') {
12616: push(@allnew,$addedfile);
12617: }
1.421 raeburn 12618: my $modified = [];
1.168 raeburn 12619: foreach my $lang (@allnew) {
12620: my $formelem = 'loginhelpurl_'.$lang;
12621: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12622: $formelem = 'loginhelpurl_add_file';
12623: }
1.425 raeburn 12624: (my $result,$newurl{$lang}) =
1.421 raeburn 12625: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12626: "help/$lang",'','',$newfile{$lang},
12627: $modified);
1.168 raeburn 12628: if ($result eq 'ok') {
12629: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12630: $changes{'helpurl'}{$lang} = 1;
12631: } else {
12632: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12633: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12634: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12635: (!grep(/^\Q$lang\E$/,@delurls))) {
12636: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12637: }
12638: }
12639: }
1.421 raeburn 12640: &update_modify_urls($r,$modified);
1.168 raeburn 12641: } else {
12642: $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);
12643: }
12644: } else {
12645: $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);
12646: }
12647: if ($error) {
12648: &Apache::lonnet::logthis($error);
12649: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12650: }
12651: }
1.256 raeburn 12652:
12653: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12654: if (ref($domconfig{'login'}) eq 'HASH') {
12655: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12656: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12657: if ($domservers{$lonhost}) {
12658: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12659: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12660: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12661: }
12662: }
12663: }
12664: }
12665: }
12666: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12667: foreach my $lonhost (sort(keys(%domservers))) {
12668: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12669: $changes{'headtag'}{$lonhost} = 1;
12670: } else {
12671: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12672: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12673: }
12674: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12675: push(@newhosts,$lonhost);
12676: } elsif ($currheadtagurls{$lonhost}) {
12677: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12678: if ($currexempt{$lonhost}) {
1.289 raeburn 12679: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12680: $changes{'headtag'}{$lonhost} = 1;
12681: }
12682: } elsif ($possexempt{$lonhost}) {
12683: $changes{'headtag'}{$lonhost} = 1;
12684: }
12685: if ($possexempt{$lonhost}) {
12686: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12687: }
12688: }
12689: }
12690: }
12691: if (@newhosts) {
12692: my $error;
12693: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12694: if ($configuserok eq 'ok') {
12695: if ($switchserver) {
12696: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12697: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12698: my $modified = [];
1.256 raeburn 12699: foreach my $lonhost (@newhosts) {
12700: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12701: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12702: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12703: "login/headtag/$lonhost",'','',
12704: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12705: $modified);
1.256 raeburn 12706: if ($result eq 'ok') {
12707: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12708: $changes{'headtag'}{$lonhost} = 1;
12709: if ($possexempt{$lonhost}) {
12710: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12711: }
12712: } else {
12713: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12714: $newheadtagurls{$lonhost},$result);
12715: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12716: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12717: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12718: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12719: }
12720: }
12721: }
1.421 raeburn 12722: &update_modify_urls($r,$modified);
1.256 raeburn 12723: } else {
12724: $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);
12725: }
12726: } else {
12727: $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);
12728: }
12729: if ($error) {
12730: &Apache::lonnet::logthis($error);
12731: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12732: }
12733: }
1.386 raeburn 12734: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12735: my @newsamlimgs;
12736: foreach my $lonhost (keys(%domservers)) {
12737: if ($env{'form.saml_'.$lonhost}) {
12738: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12739: push(@newsamlimgs,$lonhost);
12740: }
1.412 raeburn 12741: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12742: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12743: }
12744: if ($saml{$lonhost}) {
1.412 raeburn 12745: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12746: $env{'form.saml_window_'.$lonhost} = '';
12747: }
1.386 raeburn 12748: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12749: #FIXME Need to obsolete published image
12750: delete($currsaml{$lonhost}{'img'});
12751: $changes{'saml'}{$lonhost} = 1;
12752: }
12753: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12754: $changes{'saml'}{$lonhost} = 1;
12755: }
12756: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12757: $changes{'saml'}{$lonhost} = 1;
12758: }
12759: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12760: $changes{'saml'}{$lonhost} = 1;
12761: }
12762: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12763: $changes{'saml'}{$lonhost} = 1;
12764: }
1.412 raeburn 12765: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12766: $changes{'saml'}{$lonhost} = 1;
12767: }
1.386 raeburn 12768: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12769: $changes{'saml'}{$lonhost} = 1;
12770: }
12771: } else {
12772: $changes{'saml'}{$lonhost} = 1;
12773: }
1.412 raeburn 12774: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12775: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12776: }
12777: } else {
1.425 raeburn 12778: if ($saml{$lonhost}) {
1.389 raeburn 12779: $changes{'saml'}{$lonhost} = 1;
12780: delete($currsaml{$lonhost});
12781: }
1.386 raeburn 12782: }
12783: }
12784: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12785: unless (exists($domservers{$posshost})) {
12786: delete($currsaml{$posshost});
1.386 raeburn 12787: }
12788: }
12789: %{$loginhash{'login'}{'saml'}} = %currsaml;
12790: if (@newsamlimgs) {
12791: my $error;
12792: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12793: if ($configuserok eq 'ok') {
12794: if ($switchserver) {
12795: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12796: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12797: my $modified = [];
1.386 raeburn 12798: foreach my $lonhost (@newsamlimgs) {
12799: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12800: my ($result,$imgurl) =
1.421 raeburn 12801: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12802: "login/saml/$lonhost",'','',
12803: $env{'form.saml_img_'.$lonhost.'.filename'},
12804: $modified);
1.386 raeburn 12805: if ($result eq 'ok') {
12806: $currsaml{$lonhost}{'img'} = $imgurl;
12807: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12808: $changes{'saml'}{$lonhost} = 1;
12809: } else {
12810: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12811: $lonhost,$result);
12812: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12813: }
12814: }
1.421 raeburn 12815: &update_modify_urls($r,$modified);
1.386 raeburn 12816: } else {
12817: $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);
12818: }
12819: } else {
12820: $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);
12821: }
12822: if ($error) {
12823: &Apache::lonnet::logthis($error);
12824: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12825: }
12826: }
1.169 raeburn 12827: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12828:
12829: my $defaulthelpfile = '/adm/loginproblems.html';
12830: my $defaulttext = &mt('Default in use');
12831:
1.1 raeburn 12832: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12833: $dom);
12834: if ($putresult eq 'ok') {
1.188 raeburn 12835: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12836: my %defaultchecked = (
12837: 'coursecatalog' => 'on',
1.188 raeburn 12838: 'helpdesk' => 'on',
1.42 raeburn 12839: 'adminmail' => 'off',
1.43 raeburn 12840: 'newuser' => 'off',
1.42 raeburn 12841: );
1.55 raeburn 12842: if (ref($domconfig{'login'}) eq 'HASH') {
12843: foreach my $item (@toggles) {
12844: if ($defaultchecked{$item} eq 'on') {
12845: if (($domconfig{'login'}{$item} eq '0') &&
12846: ($env{'form.'.$item} eq '1')) {
12847: $changes{$item} = 1;
12848: } elsif (($domconfig{'login'}{$item} eq '' ||
12849: $domconfig{'login'}{$item} eq '1') &&
12850: ($env{'form.'.$item} eq '0')) {
12851: $changes{$item} = 1;
12852: }
12853: } elsif ($defaultchecked{$item} eq 'off') {
12854: if (($domconfig{'login'}{$item} eq '1') &&
12855: ($env{'form.'.$item} eq '0')) {
12856: $changes{$item} = 1;
12857: } elsif (($domconfig{'login'}{$item} eq '' ||
12858: $domconfig{'login'}{$item} eq '0') &&
12859: ($env{'form.'.$item} eq '1')) {
12860: $changes{$item} = 1;
12861: }
1.42 raeburn 12862: }
12863: }
1.41 raeburn 12864: }
1.6 raeburn 12865: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12866: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12867: if (exists($changes{'saml'})) {
12868: my $hostid_in_use;
12869: my @hosts = &Apache::lonnet::current_machine_ids();
12870: if (@hosts > 1) {
12871: foreach my $hostid (@hosts) {
12872: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12873: $hostid_in_use = $hostid;
12874: last;
12875: }
12876: }
12877: } else {
12878: $hostid_in_use = $r->dir_config('lonHostID');
12879: }
12880: if (($hostid_in_use) &&
12881: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12882: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12883: }
12884: if (ref($lastactref) eq 'HASH') {
12885: if (ref($changes{'saml'}) eq 'HASH') {
12886: my %updates;
12887: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12888: $lastactref->{'samllanding'} = \%updates;
12889: }
12890: }
12891: }
1.212 raeburn 12892: if (ref($lastactref) eq 'HASH') {
12893: $lastactref->{'domainconfig'} = 1;
12894: }
1.1 raeburn 12895: $resulttext = &mt('Changes made:').'<ul>';
12896: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12897: if ($item eq 'loginvia') {
1.112 raeburn 12898: if (ref($changes{$item}) eq 'HASH') {
12899: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12900: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12901: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12902: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12903: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12904: $protocol = 'http' if ($protocol ne 'https');
12905: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12906:
12907: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12908: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12909: } else {
12910: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12911: }
12912: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12913: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12914: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12915: }
12916: $resulttext .= '</li>';
12917: } else {
12918: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12919: }
1.112 raeburn 12920: } else {
1.128 raeburn 12921: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12922: }
12923: }
1.128 raeburn 12924: $resulttext .= '</ul></li>';
1.112 raeburn 12925: }
1.168 raeburn 12926: } elsif ($item eq 'helpurl') {
12927: if (ref($changes{$item}) eq 'HASH') {
12928: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12929: if (grep(/^\Q$lang\E$/,@delurls)) {
12930: my ($chg,$link);
12931: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12932: if ($lang eq 'nolang') {
12933: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12934: } else {
12935: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12936: }
12937: $resulttext .= '<li>'.$chg.'</li>';
12938: } else {
12939: my $chg;
12940: if ($lang eq 'nolang') {
12941: $chg = &mt('custom log-in help file for no preferred language');
12942: } else {
12943: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12944: }
12945: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12946: $loginhash{'login'}{'helpurl'}{$lang}.
12947: '?inhibitmenu=yes',$chg,600,500).
12948: '</li>';
12949: }
12950: }
12951: }
1.256 raeburn 12952: } elsif ($item eq 'headtag') {
12953: if (ref($changes{$item}) eq 'HASH') {
12954: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12955: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12956: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12957: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12958: $resulttext .= '<li><a href="'.
12959: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12960: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12961: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12962: if ($possexempt{$lonhost}) {
12963: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12964: } else {
12965: $resulttext .= &mt('included for any client IP');
12966: }
12967: $resulttext .= '</li>';
12968: }
12969: }
12970: }
1.386 raeburn 12971: } elsif ($item eq 'saml') {
12972: if (ref($changes{$item}) eq 'HASH') {
12973: my %notlt = (
12974: text => 'Text for log-in by SSO',
12975: img => 'SSO button image',
12976: alt => 'Alt text for button image',
12977: url => 'SSO URL',
12978: title => 'Tooltip for SSO link',
1.412 raeburn 12979: window => 'Pop-up window if iframe',
1.386 raeburn 12980: notsso => 'Text for non-SSO log-in',
12981: );
12982: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12983: if (ref($currsaml{$lonhost}) eq 'HASH') {
12984: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12985: '<ul>';
1.412 raeburn 12986: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 12987: if ($currsaml{$lonhost}{$key} eq '') {
12988: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12989: } else {
12990: my $value = "'$currsaml{$lonhost}{$key}'";
12991: if ($key eq 'img') {
12992: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 12993: } elsif ($key eq 'window') {
12994: $value = 'On';
1.386 raeburn 12995: }
12996: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12997: $value).'</li>';
12998: }
12999: }
13000: $resulttext .= '</ul></li>';
13001: } else {
13002: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
13003: }
13004: }
13005: }
1.169 raeburn 13006: } elsif ($item eq 'captcha') {
13007: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 13008: my $chgtxt;
1.169 raeburn 13009: if ($loginhash{'login'}{$item} eq 'notused') {
13010: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
13011: } else {
13012: my %captchas = &captcha_phrases();
13013: if ($captchas{$loginhash{'login'}{$item}}) {
13014: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
13015: } else {
13016: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
13017: }
13018: }
13019: $resulttext .= '<li>'.$chgtxt.'</li>';
13020: }
13021: } elsif ($item eq 'recaptchakeys') {
13022: if (ref($loginhash{'login'}) eq 'HASH') {
13023: my ($privkey,$pubkey);
13024: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
13025: $pubkey = $loginhash{'login'}{$item}{'public'};
13026: $privkey = $loginhash{'login'}{$item}{'private'};
13027: }
13028: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
13029: if (!$pubkey) {
13030: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
13031: } else {
13032: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13033: }
13034: if (!$privkey) {
13035: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
13036: } else {
1.251 raeburn 13037: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 13038: }
13039: $chgtxt .= '</ul>';
13040: $resulttext .= '<li>'.$chgtxt.'</li>';
13041: }
1.269 raeburn 13042: } elsif ($item eq 'recaptchaversion') {
13043: if (ref($loginhash{'login'}) eq 'HASH') {
13044: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 13045: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 13046: '</li>';
13047: }
13048: }
1.41 raeburn 13049: } else {
13050: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
13051: }
1.1 raeburn 13052: }
1.6 raeburn 13053: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 13054: } else {
13055: $resulttext = &mt('No changes made to log-in page settings');
13056: }
13057: } else {
1.11 albertel 13058: $resulttext = '<span class="LC_error">'.
13059: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13060: }
1.6 raeburn 13061: if ($errors) {
1.9 raeburn 13062: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 13063: $errors.'</ul>';
13064: }
13065: return $resulttext;
13066: }
13067:
1.256 raeburn 13068: sub check_exempt_addresses {
13069: my ($iplist) = @_;
13070: $iplist =~ s/^\s+//;
13071: $iplist =~ s/\s+$//;
13072: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
13073: my (@okips,$new);
13074: foreach my $ip (@poss_ips) {
13075: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
13076: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
13077: push(@okips,$ip);
13078: }
13079: }
13080: }
13081: if (@okips > 0) {
13082: $new = join(',',@okips);
13083: } else {
13084: $new = '';
13085: }
13086: return $new;
13087: }
13088:
1.6 raeburn 13089: sub color_font_choices {
13090: my %choices =
13091: &Apache::lonlocal::texthash (
13092: bgs => "Background colors",
13093: links => "Link colors",
1.55 raeburn 13094: images => "Images",
1.6 raeburn 13095: font => "Font color",
1.201 raeburn 13096: fontmenu => "Font menu",
1.76 raeburn 13097: pgbg => "Page",
1.6 raeburn 13098: tabbg => "Header",
13099: sidebg => "Border",
13100: link => "Link",
13101: alink => "Active link",
13102: vlink => "Visited link",
13103: );
13104: return %choices;
13105: }
13106:
1.394 raeburn 13107: sub modify_ipaccess {
13108: my ($dom,$lastactref,%domconfig) = @_;
13109: my (@allpos,%changes,%confhash,$errors,$resulttext);
13110: my (@items,%deletions,%itemids,@warnings);
13111: my ($typeorder,$types) = &commblocktype_text();
13112: if ($env{'form.ipaccess_add'}) {
13113: my $name = $env{'form.ipaccess_name_add'};
13114: my ($newid,$error) = &get_ipaccess_id($dom,$name);
13115: if ($newid) {
13116: $itemids{'add'} = $newid;
13117: push(@items,'add');
13118: $changes{$newid} = 1;
13119: } else {
13120: $error = &mt('Failed to acquire unique ID for new IP access control item');
13121: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13122: }
13123: }
13124: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13125: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13126: if (@todelete) {
13127: map { $deletions{$_} = 1; } @todelete;
13128: }
13129: my $maxnum = $env{'form.ipaccess_maxnum'};
13130: for (my $i=0; $i<$maxnum; $i++) {
13131: my $itemid = $env{'form.ipaccess_id_'.$i};
13132: $itemid =~ s/\D+//g;
13133: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13134: if ($deletions{$itemid}) {
13135: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13136: } else {
13137: push(@items,$i);
13138: $itemids{$i} = $itemid;
13139: }
13140: }
13141: }
13142: }
13143: foreach my $idx (@items) {
13144: my $itemid = $itemids{$idx};
13145: next unless ($itemid);
1.446 raeburn 13146: my ($position,%current);
13147: if ($idx eq 'add') {
13148: $position = $env{'form.ipaccess_pos_add'};
13149: } else {
13150: $position = $env{'form.ipaccess_pos_'.$itemid};
1.394 raeburn 13151: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13152: %current = %{$domconfig{'ipaccess'}{$itemid}};
13153: }
13154: }
13155: $position =~ s/\D+//g;
13156: if ($position ne '') {
13157: $allpos[$position] = $itemid;
13158: }
13159: my $name = $env{'form.ipaccess_name_'.$idx};
13160: $name =~ s/^\s+|\s+$//g;
13161: $confhash{$itemid}{'name'} = $name;
13162: my $possrange = $env{'form.ipaccess_range_'.$idx};
13163: $possrange =~ s/^\s+|\s+$//g;
13164: unless ($possrange eq '') {
13165: $possrange =~ s/[\r\n]+/\s/g;
13166: $possrange =~ s/\s*-\s*/-/g;
13167: $possrange =~ s/\s+/,/g;
13168: $possrange =~ s/,+/,/g;
13169: if ($possrange ne '') {
13170: my (@ok,$count);
1.425 raeburn 13171: $count = 0;
1.394 raeburn 13172: foreach my $poss (split(/\,/,$possrange)) {
13173: $count ++;
13174: $poss = &validate_ip_pattern($poss);
13175: if ($poss ne '') {
13176: push(@ok,$poss);
13177: }
13178: }
13179: my $diff = $count - scalar(@ok);
13180: if ($diff) {
13181: $errors .= '<li><span class="LC_error">'.
13182: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13183: $diff,$name).
13184: '</span></li>';
13185: }
13186: if (@ok) {
13187: my @cidr_list;
13188: foreach my $item (@ok) {
13189: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13190: }
13191: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13192: }
13193: }
13194: }
13195: foreach my $field ('name','ip') {
13196: unless (($idx eq 'add') || ($changes{$itemid})) {
13197: if ($current{$field} ne $confhash{$itemid}{$field}) {
13198: $changes{$itemid} = 1;
13199: last;
13200: }
13201: }
13202: }
13203: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13204:
1.394 raeburn 13205: my %commblocks;
1.425 raeburn 13206: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13207: foreach my $type (@{$typeorder}) {
13208: if ($commblocks{$type}) {
13209: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13210: }
13211: unless (($idx eq 'add') || ($changes{$itemid})) {
13212: if (ref($current{'commblocks'}) eq 'HASH') {
13213: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13214: $changes{$itemid} = 1;
13215: }
13216: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13217: $changes{$itemid} = 1;
13218: }
13219: }
13220: }
13221: $confhash{$itemid}{'courses'} = {};
13222: my %crsdeletions;
13223: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13224: if (@delcrs) {
13225: map { $crsdeletions{$_} = 1; } @delcrs;
13226: }
13227: if (ref($current{'courses'}) eq 'HASH') {
13228: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13229: if ($crsdeletions{$cid}) {
13230: $changes{$itemid} = 1;
13231: } else {
13232: $confhash{$itemid}{'courses'}{$cid} = 1;
13233: }
13234: }
13235: }
13236: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13237: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13238: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13239: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13240: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13241: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13242: $errors .= '<li><span class="LC_error">'.
13243: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13244: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13245: '</span></li>';
13246: } else {
13247: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13248: $changes{$itemid} = 1;
13249: }
13250: }
13251: }
13252: if (@allpos > 0) {
13253: my $idx = 0;
13254: foreach my $itemid (@allpos) {
13255: if ($itemid ne '') {
13256: $confhash{$itemid}{'order'} = $idx;
13257: unless ($changes{$itemid}) {
13258: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13259: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13260: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13261: $changes{$itemid} = 1;
13262: }
13263: }
13264: }
13265: }
13266: $idx ++;
13267: }
13268: }
13269: }
13270: if (keys(%changes)) {
13271: my %defaultshash = (
13272: ipaccess => \%confhash,
13273: );
13274: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13275: $dom);
13276: if ($putresult eq 'ok') {
13277: my $cachetime = 1800;
13278: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13279: if (ref($lastactref) eq 'HASH') {
13280: $lastactref->{'ipaccess'} = 1;
13281: }
13282: $resulttext = &mt('Changes made:').'<ul>';
13283: my %bynum;
13284: foreach my $itemid (sort(keys(%changes))) {
13285: if (ref($confhash{$itemid}) eq 'HASH') {
13286: my $position = $confhash{$itemid}{'order'};
13287: if ($position =~ /^\d+$/) {
13288: $bynum{$position} = $itemid;
13289: }
13290: }
13291: }
13292: if (keys(%deletions)) {
13293: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13294: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13295: }
13296: }
13297: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13298: my $itemid = $bynum{$pos};
13299: if (ref($confhash{$itemid}) eq 'HASH') {
13300: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13301: my $position = $pos + 1;
13302: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13303: if ($confhash{$itemid}{'ip'} eq '') {
13304: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13305: } else {
13306: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13307: }
13308: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13309: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13310: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13311: '</li>';
13312: } else {
13313: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13314: }
13315: if (keys(%{$confhash{$itemid}{'courses'}})) {
13316: my @courses;
13317: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13318: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13319: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13320: }
13321: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13322: join('</li><li>',@courses).'</li></ul>';
13323: } else {
13324: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13325: }
1.395 raeburn 13326: $resulttext .= '</ul></li>';
1.394 raeburn 13327: }
13328: }
1.395 raeburn 13329: $resulttext .= '</ul>';
1.394 raeburn 13330: } else {
13331: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13332: }
13333: } else {
13334: $resulttext = &mt('No changes made');
13335: }
13336: if ($errors) {
13337: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13338: $errors.'</ul></p>';
13339: }
13340: return $resulttext;
13341: }
13342:
13343: sub get_ipaccess_id {
13344: my ($domain,$location) = @_;
13345: # get lock on ipaccess db
13346: my $lockhash = {
13347: lock => $env{'user.name'}.
13348: ':'.$env{'user.domain'},
13349: };
13350: my $tries = 0;
13351: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13352: my ($id,$error);
13353:
13354: while (($gotlock ne 'ok') && ($tries<10)) {
13355: $tries ++;
13356: sleep (0.1);
13357: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13358: }
13359: if ($gotlock eq 'ok') {
13360: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13361: if ($currids{'lock'}) {
13362: delete($currids{'lock'});
13363: if (keys(%currids)) {
13364: my @curr = sort { $a <=> $b } keys(%currids);
13365: if ($curr[-1] =~ /^\d+$/) {
13366: $id = 1 + $curr[-1];
13367: }
13368: } else {
13369: $id = 1;
13370: }
13371: if ($id) {
13372: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13373: $error = 'nostore';
13374: }
13375: } else {
13376: $error = 'nonumber';
13377: }
13378: }
13379: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13380: } else {
13381: $error = 'nolock';
13382: }
13383: return ($id,$error);
13384: }
13385:
1.429 raeburn 13386: sub modify_authordefaults {
13387: my ($dom,$lastactref,%domconfig) = @_;
13388: #
13389: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13390: #
13391: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13392: if (ref($domconfig{'quotas'}) eq 'HASH') {
13393: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13394: if ($key =~ /^webdav|authorquota$/) {
13395: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13396: } else {
13397: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13398: }
13399: }
13400: }
13401: my %staticdefaults = (
13402: 'copyright' => 'default',
13403: 'sourceavail' => 'closed',
13404: 'nocodemirror' => 'off',
1.437 raeburn 13405: 'daxecollapse' => 'off',
1.429 raeburn 13406: 'domcoordacc' => 'on',
1.439 raeburn 13407: 'editors' => ['edit','xml'],
1.429 raeburn 13408: 'authorquota' => 500,
13409: 'webdav' => 0,
1.440 raeburn 13410: 'archive' => 'off',
1.429 raeburn 13411: );
13412: my %titles = &authordefaults_titles();
1.440 raeburn 13413: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.429 raeburn 13414: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13415: $confhash{$item} = $env{'form.'.$item};
13416: }
13417: }
13418: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13419: $confhash{'copyright'} = $1;
13420: }
13421: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13422: $confhash{'sourceavail'} = $1;
13423: }
13424: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13425: my @okeditors = ('edit','xml','daxe');
13426: my @editors;
13427: foreach my $item (@posseditors) {
13428: if (grep(/^\Q$item\E$/,@okeditors)) {
13429: push(@editors,$item);
13430: }
13431: }
13432: $confhash{'editors'} = \@editors;
1.436 raeburn 13433:
1.429 raeburn 13434: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13435: my @insttypes;
13436: if (ref($types) eq 'ARRAY') {
13437: @insttypes = @{$types};
13438: }
13439: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13440: my %webdav;
13441: map { $webdav{$_} = 1; } @webdavon;
13442: foreach my $type (@insttypes,'default') {
13443: my $possquota = $env{'form.authorquota_'.$type};
13444: if ($possquota =~ /^\d+$/) {
13445: $save_quotas{'authorquota'}{$type} = $possquota;
13446: }
13447: if ($webdav{$type}) {
13448: $save_quotas{'webdav'}{$type} = 1;
13449: } else {
13450: $save_quotas{'webdav'}{$type} = 0;
13451: }
13452: }
13453: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13454: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13455: }
13456: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
1.440 raeburn 13457: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail','archive') {
1.429 raeburn 13458: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13459: $changes{$item} = 1;
13460: }
13461: }
13462: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
1.436 raeburn 13463: my @diffs =
1.429 raeburn 13464: &Apache::loncommon::compare_arrays($confhash{'editors'},
13465: $domconfig{'authordefaults'}{'editors'});
13466: unless (@diffs == 0) {
13467: $changes{'editors'} = 1;
13468: }
13469: } else {
13470: my @diffs =
13471: &Apache::loncommon::compare_arrays($confhash{'editors'},
13472: $staticdefaults{'editors'});
13473: unless (@diffs == 0) {
13474: $changes{'editors'} = 1;
13475: }
13476: }
13477: } else {
13478: my @offon = ('off','on');
1.440 raeburn 13479: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.436 raeburn 13480: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
1.429 raeburn 13481: $changes{$item} = 1;
13482: }
13483: }
13484: foreach my $item ('copyright','sourceavail') {
13485: if ($confhash{$item} ne $staticdefaults{$item}) {
13486: $changes{$item} = 1;
13487: }
13488: }
1.439 raeburn 13489: my @diffs =
13490: &Apache::loncommon::compare_arrays($confhash{'editors'},
13491: $staticdefaults{'editors'});
13492: unless (@diffs == 0) {
13493: $changes{'editors'} = 1;
13494: }
1.429 raeburn 13495: }
13496: foreach my $key ('authorquota','webdav') {
13497: if (ref($curr_quotas{$key}) eq 'HASH') {
13498: foreach my $type (@insttypes,'default') {
13499: if (exists($save_quotas{$key}{$type})) {
13500: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13501: $changes{$key}{$type} = 1;
13502: }
13503: } elsif (exists($curr_quotas{$key}{$type})) {
13504: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13505: } else {
13506: $save_quotas{$key}{$type} = $staticdefaults{$key};
13507: }
13508: }
13509: } else {
13510: foreach my $type (@insttypes,'default') {
13511: if (exists($save_quotas{$key}{$type})) {
13512: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13513: $changes{$key}{$type} = 1;
13514: }
13515: } else {
13516: $save_quotas{$key}{$type} = $staticdefaults{$key};
13517: }
13518: }
13519: }
13520: }
13521: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13522: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
1.436 raeburn 13523: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
1.429 raeburn 13524: $changes{'webdav_LC_adv'} = 1;
13525: }
13526: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13527: $changes{'webdav_LC_adv'} = 1;
13528: }
13529: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13530: $changes{'webdav_LC_adv'} = 1;
13531: }
13532: my %confighash = (
13533: quotas => \%save_quotas,
13534: authordefaults => \%confhash,
13535: );
13536: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13537: $dom);
13538: my $resulttext;
13539: if ($putresult eq 'ok') {
13540: if (keys(%changes)) {
1.431 raeburn 13541: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13542: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
1.436 raeburn 13543: ($changes{'webdav_LC_adv'})) {
1.429 raeburn 13544: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13545: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13546: }
13547: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13548: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13549: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13550: }
13551: }
13552: $resulttext = &mt('Changes made:').'<ul>';
13553: my $authoroverride;
1.437 raeburn 13554: foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
1.429 raeburn 13555: if (exists($changes{$key})) {
1.431 raeburn 13556: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13557: my $shown;
13558: unless ($authoroverride) {
13559: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13560: $authoroverride = 1;
13561: }
1.437 raeburn 13562: if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
1.429 raeburn 13563: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13564: } elsif ($key eq 'copyright') {
13565: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13566: } elsif ($key eq 'sourceavail') {
13567: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13568: }
1.436 raeburn 13569: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.429 raeburn 13570: }
13571: }
13572: if ($authoroverride) {
13573: $resulttext .= '</ul></li>';
13574: }
13575: my $domcoordoverride;
1.440 raeburn 13576: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv','archive') {
1.429 raeburn 13577: if (exists($changes{$key})) {
13578: my $shown;
13579: unless ($domcoordoverride) {
13580: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13581: $domcoordoverride = 1;
13582: }
13583: if ($key eq 'editors') {
1.431 raeburn 13584: if (ref($confhash{'editors'}) eq 'ARRAY') {
13585: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
13586: if (@{$confhash{'editors'}}) {
13587: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
13588: } else {
13589: $shown = &mt('None');
13590: }
1.429 raeburn 13591: }
13592: } elsif ($key eq 'authorquota') {
13593: foreach my $type (@insttypes) {
13594: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13595: }
13596: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13597: } elsif ($key eq 'webdav') {
13598: foreach my $type (@insttypes) {
13599: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13600: }
13601: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13602: } elsif ($key eq 'webdav_LC_adv') {
13603: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13604: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13605: } else {
13606: $shown = $titles{'none'};
13607: }
1.440 raeburn 13608: } elsif ($key eq 'archive') {
1.441 raeburn 13609: $domdefaults{$key} = $confhash{$key};
1.440 raeburn 13610: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
1.429 raeburn 13611: }
13612: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.436 raeburn 13613: }
1.429 raeburn 13614: }
13615: if ($domcoordoverride) {
13616: $resulttext .= '</ul></li>';
13617: }
1.439 raeburn 13618: $resulttext .= '</ul>';
1.431 raeburn 13619: my $cachetime = 24*60*60;
13620: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13621: if (ref($lastactref) eq 'HASH') {
13622: $lastactref->{'domdefaults'} = 1;
13623: }
1.429 raeburn 13624: } else {
13625: $resulttext = &mt('No changes made to Authoring Space defaults');
13626: }
13627: }
13628: return $resulttext;
13629: }
13630:
1.6 raeburn 13631: sub modify_rolecolors {
1.205 raeburn 13632: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13633: my ($resulttext,%rolehash);
13634: $rolehash{'rolecolors'} = {};
1.55 raeburn 13635: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13636: if ($domconfig{'rolecolors'} eq '') {
13637: $domconfig{'rolecolors'} = {};
13638: }
13639: }
1.9 raeburn 13640: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13641: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13642: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13643: $dom);
13644: if ($putresult eq 'ok') {
13645: if (keys(%changes) > 0) {
1.41 raeburn 13646: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13647: if (ref($lastactref) eq 'HASH') {
13648: $lastactref->{'domainconfig'} = 1;
13649: }
1.6 raeburn 13650: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13651: $rolehash{'rolecolors'});
13652: } else {
13653: $resulttext = &mt('No changes made to default color schemes');
13654: }
13655: } else {
1.11 albertel 13656: $resulttext = '<span class="LC_error">'.
13657: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13658: }
13659: if ($errors) {
13660: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13661: $errors.'</ul>';
13662: }
13663: return $resulttext;
13664: }
13665:
13666: sub modify_colors {
1.9 raeburn 13667: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13668: my (%changes,%choices);
1.51 raeburn 13669: my @bgs;
1.6 raeburn 13670: my @links = ('link','alink','vlink');
1.41 raeburn 13671: my @logintext;
1.6 raeburn 13672: my @images;
13673: my $servadm = $r->dir_config('lonAdmEMail');
13674: my $errors;
1.200 raeburn 13675: my %defaults;
1.6 raeburn 13676: foreach my $role (@{$roles}) {
13677: if ($role eq 'login') {
1.12 raeburn 13678: %choices = &login_choices();
1.41 raeburn 13679: @logintext = ('textcol','bgcol');
1.12 raeburn 13680: } else {
13681: %choices = &color_font_choices();
13682: }
13683: if ($role eq 'login') {
1.41 raeburn 13684: @images = ('img','logo','domlogo','login');
1.51 raeburn 13685: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13686: } else {
1.445 raeburn 13687: @images = ();
1.200 raeburn 13688: @bgs = ('pgbg','tabbg','sidebg');
13689: }
13690: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
1.444 raeburn 13691: $env{'form.'.$role.'_font'} = lc($env{'form.'.$role.'_font'});
13692: if ($env{'form.'.$role.'_font'} =~ /^\w+/) {
13693: $env{'form.'.$role.'_font'} = '#'.$env{'form.'.$role.'_font'};
13694: }
13695: unless ($env{'form.'.$role.'_font'} eq lc($defaults{'font'})) {
1.200 raeburn 13696: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13697: }
13698: if ($role eq 'login') {
13699: foreach my $item (@logintext) {
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{'logintext'}{$item})) {
1.200 raeburn 13705: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13706: }
13707: }
13708: } else {
1.234 raeburn 13709: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13710: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13711: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13712: }
1.445 raeburn 13713: unless ($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13714: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13715: }
1.6 raeburn 13716: }
1.200 raeburn 13717: foreach my $item (@bgs) {
1.234 raeburn 13718: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13719: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13720: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13721: }
13722: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13723: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13724: }
13725: }
13726: foreach my $item (@links) {
1.234 raeburn 13727: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13728: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13729: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13730: }
13731: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13732: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13733: }
1.6 raeburn 13734: }
1.46 raeburn 13735: my ($configuserok,$author_ok,$switchserver) =
13736: &config_check($dom,$confname,$servadm);
1.9 raeburn 13737: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13738: if (ref($domconfig->{$role}) ne 'HASH') {
13739: $domconfig->{$role} = {};
13740: }
1.8 raeburn 13741: foreach my $img (@images) {
1.402 raeburn 13742: if ($role eq 'login') {
13743: if (($img eq 'img') || ($img eq 'logo')) {
13744: if (defined($env{'form.login_showlogo_'.$img})) {
13745: $confhash->{$role}{'showlogo'}{$img} = 1;
13746: } else {
13747: $confhash->{$role}{'showlogo'}{$img} = 0;
13748: }
13749: }
13750: if ($env{'form.login_alt_'.$img} ne '') {
13751: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13752: }
1.402 raeburn 13753: }
1.18 albertel 13754: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13755: && !defined($domconfig->{$role}{$img})
13756: && !$env{'form.'.$role.'_del_'.$img}
13757: && $env{'form.'.$role.'_import_'.$img}) {
13758: # import the old configured image from the .tab setting
13759: # if they haven't provided a new one
13760: $domconfig->{$role}{$img} =
13761: $env{'form.'.$role.'_import_'.$img};
13762: }
1.6 raeburn 13763: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13764: my $error;
1.6 raeburn 13765: if ($configuserok eq 'ok') {
1.9 raeburn 13766: if ($switchserver) {
1.12 raeburn 13767: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13768: } else {
13769: if ($author_ok eq 'ok') {
1.421 raeburn 13770: my $modified = [];
1.9 raeburn 13771: my ($result,$logourl) =
1.421 raeburn 13772: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13773: $dom,$confname,$img,$width,$height,
13774: '',$modified);
1.9 raeburn 13775: if ($result eq 'ok') {
13776: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13777: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13778: &update_modify_urls($r,$modified);
1.9 raeburn 13779: } else {
1.12 raeburn 13780: $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 13781: }
13782: } else {
1.46 raeburn 13783: $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 13784: }
13785: }
13786: } else {
1.46 raeburn 13787: $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 13788: }
13789: if ($error) {
1.8 raeburn 13790: &Apache::lonnet::logthis($error);
1.11 albertel 13791: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13792: }
13793: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13794: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13795: my $error;
13796: if ($configuserok eq 'ok') {
13797: # is confname an author?
13798: if ($switchserver eq '') {
13799: if ($author_ok eq 'ok') {
1.421 raeburn 13800: my $modified = [];
1.9 raeburn 13801: my ($result,$logourl) =
1.421 raeburn 13802: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13803: $dom,$confname,$img,$width,$height,
13804: '',$modified);
1.9 raeburn 13805: if ($result eq 'ok') {
13806: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13807: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13808: &update_modify_urls($r,$modified);
1.9 raeburn 13809: }
13810: }
13811: }
13812: }
1.6 raeburn 13813: }
13814: }
13815: }
13816: if (ref($domconfig) eq 'HASH') {
13817: if (ref($domconfig->{$role}) eq 'HASH') {
13818: foreach my $img (@images) {
13819: if ($domconfig->{$role}{$img} ne '') {
13820: if ($env{'form.'.$role.'_del_'.$img}) {
13821: $confhash->{$role}{$img} = '';
1.12 raeburn 13822: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13823: } else {
1.9 raeburn 13824: if ($confhash->{$role}{$img} eq '') {
13825: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13826: }
1.6 raeburn 13827: }
13828: } else {
13829: if ($env{'form.'.$role.'_del_'.$img}) {
13830: $confhash->{$role}{$img} = '';
1.12 raeburn 13831: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13832: }
13833: }
1.402 raeburn 13834: if ($role eq 'login') {
13835: if (($img eq 'logo') || ($img eq 'img')) {
13836: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13837: if ($confhash->{$role}{'showlogo'}{$img} ne
13838: $domconfig->{$role}{'showlogo'}{$img}) {
13839: $changes{$role}{'showlogo'}{$img} = 1;
13840: }
13841: } else {
13842: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13843: $changes{$role}{'showlogo'}{$img} = 1;
13844: }
1.70 raeburn 13845: }
1.402 raeburn 13846: }
13847: if ($img ne 'login') {
13848: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13849: if ($confhash->{$role}{'alttext'}{$img} ne
13850: $domconfig->{$role}{'alttext'}{$img}) {
13851: $changes{$role}{'alttext'}{$img} = 1;
13852: }
13853: } else {
13854: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13855: $changes{$role}{'alttext'}{$img} = 1;
13856: }
1.70 raeburn 13857: }
13858: }
13859: }
13860: }
1.6 raeburn 13861: if ($domconfig->{$role}{'font'} ne '') {
13862: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13863: $changes{$role}{'font'} = 1;
13864: }
13865: } else {
13866: if ($confhash->{$role}{'font'}) {
13867: $changes{$role}{'font'} = 1;
13868: }
13869: }
1.107 raeburn 13870: if ($role ne 'login') {
13871: if ($domconfig->{$role}{'fontmenu'} ne '') {
13872: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13873: $changes{$role}{'fontmenu'} = 1;
13874: }
13875: } else {
13876: if ($confhash->{$role}{'fontmenu'}) {
13877: $changes{$role}{'fontmenu'} = 1;
13878: }
1.97 tempelho 13879: }
13880: }
1.6 raeburn 13881: foreach my $item (@bgs) {
13882: if ($domconfig->{$role}{$item} ne '') {
13883: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13884: $changes{$role}{'bgs'}{$item} = 1;
13885: }
13886: } else {
13887: if ($confhash->{$role}{$item}) {
13888: $changes{$role}{'bgs'}{$item} = 1;
13889: }
13890: }
13891: }
13892: foreach my $item (@links) {
13893: if ($domconfig->{$role}{$item} ne '') {
13894: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13895: $changes{$role}{'links'}{$item} = 1;
13896: }
13897: } else {
13898: if ($confhash->{$role}{$item}) {
13899: $changes{$role}{'links'}{$item} = 1;
13900: }
13901: }
13902: }
1.41 raeburn 13903: foreach my $item (@logintext) {
13904: if ($domconfig->{$role}{$item} ne '') {
13905: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13906: $changes{$role}{'logintext'}{$item} = 1;
13907: }
13908: } else {
13909: if ($confhash->{$role}{$item}) {
13910: $changes{$role}{'logintext'}{$item} = 1;
13911: }
13912: }
13913: }
1.6 raeburn 13914: } else {
13915: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13916: \@logintext,$confhash,\%changes);
1.6 raeburn 13917: }
13918: } else {
13919: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13920: \@logintext,$confhash,\%changes);
1.6 raeburn 13921: }
13922: }
13923: return ($errors,%changes);
13924: }
13925:
1.46 raeburn 13926: sub config_check {
13927: my ($dom,$confname,$servadm) = @_;
13928: my ($configuserok,$author_ok,$switchserver,%currroles);
13929: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13930: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13931: $confname,$servadm);
13932: if ($configuserok eq 'ok') {
13933: $switchserver = &check_switchserver($dom,$confname);
13934: if ($switchserver eq '') {
13935: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13936: }
13937: }
13938: return ($configuserok,$author_ok,$switchserver);
13939: }
13940:
1.6 raeburn 13941: sub default_change_checker {
1.41 raeburn 13942: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13943: foreach my $item (@{$links}) {
13944: if ($confhash->{$role}{$item}) {
13945: $changes->{$role}{'links'}{$item} = 1;
13946: }
13947: }
13948: foreach my $item (@{$bgs}) {
13949: if ($confhash->{$role}{$item}) {
13950: $changes->{$role}{'bgs'}{$item} = 1;
13951: }
13952: }
1.41 raeburn 13953: foreach my $item (@{$logintext}) {
13954: if ($confhash->{$role}{$item}) {
13955: $changes->{$role}{'logintext'}{$item} = 1;
13956: }
13957: }
1.6 raeburn 13958: foreach my $img (@{$images}) {
13959: if ($env{'form.'.$role.'_del_'.$img}) {
13960: $confhash->{$role}{$img} = '';
1.12 raeburn 13961: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13962: }
1.70 raeburn 13963: if ($role eq 'login') {
13964: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13965: $changes->{$role}{'showlogo'}{$img} = 1;
13966: }
1.402 raeburn 13967: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13968: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13969: $changes->{$role}{'alttext'}{$img} = 1;
13970: }
13971: }
1.70 raeburn 13972: }
1.6 raeburn 13973: }
13974: if ($confhash->{$role}{'font'}) {
13975: $changes->{$role}{'font'} = 1;
13976: }
1.48 raeburn 13977: }
1.6 raeburn 13978:
13979: sub display_colorchgs {
13980: my ($dom,$changes,$roles,$confhash) = @_;
13981: my (%choices,$resulttext);
13982: if (!grep(/^login$/,@{$roles})) {
13983: $resulttext = &mt('Changes made:').'<br />';
13984: }
13985: foreach my $role (@{$roles}) {
13986: if ($role eq 'login') {
13987: %choices = &login_choices();
13988: } else {
13989: %choices = &color_font_choices();
13990: }
13991: if (ref($changes->{$role}) eq 'HASH') {
13992: if ($role ne 'login') {
13993: $resulttext .= '<h4>'.&mt($role).'</h4>';
13994: }
13995: foreach my $key (sort(keys(%{$changes->{$role}}))) {
13996: if ($role ne 'login') {
13997: $resulttext .= '<ul>';
13998: }
13999: if (ref($changes->{$role}{$key}) eq 'HASH') {
14000: if ($role ne 'login') {
14001: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
14002: }
14003: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 14004: if (($role eq 'login') && ($key eq 'showlogo')) {
14005: if ($confhash->{$role}{$key}{$item}) {
14006: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
14007: } else {
14008: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
14009: }
1.402 raeburn 14010: } elsif (($role eq 'login') && ($key eq 'alttext')) {
14011: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 14012: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 14013: $confhash->{$role}{$key}{$item}).'</li>';
14014: } else {
14015: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
14016: }
1.70 raeburn 14017: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 14018: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
14019: } else {
1.12 raeburn 14020: my $newitem = $confhash->{$role}{$item};
14021: if ($key eq 'images') {
1.306 raeburn 14022: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 14023: }
14024: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 14025: }
14026: }
14027: if ($role ne 'login') {
14028: $resulttext .= '</ul></li>';
14029: }
14030: } else {
14031: if ($confhash->{$role}{$key} eq '') {
14032: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
14033: } else {
14034: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
14035: }
14036: }
14037: if ($role ne 'login') {
14038: $resulttext .= '</ul>';
14039: }
14040: }
14041: }
14042: }
1.3 raeburn 14043: return $resulttext;
1.1 raeburn 14044: }
14045:
1.9 raeburn 14046: sub thumb_dimensions {
14047: return ('200','50');
14048: }
14049:
1.16 raeburn 14050: sub check_dimensions {
14051: my ($inputfile) = @_;
14052: my ($fullwidth,$fullheight);
14053: if ($inputfile =~ m|^[/\w.\-]+$|) {
14054: if (open(PIPE,"identify $inputfile 2>&1 |")) {
14055: my $imageinfo = <PIPE>;
14056: if (!close(PIPE)) {
14057: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
14058: }
14059: chomp($imageinfo);
14060: my ($fullsize) =
1.21 raeburn 14061: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 14062: if ($fullsize) {
14063: ($fullwidth,$fullheight) = split(/x/,$fullsize);
14064: }
14065: }
14066: }
14067: return ($fullwidth,$fullheight);
14068: }
14069:
1.9 raeburn 14070: sub check_configuser {
14071: my ($uhome,$dom,$confname,$servadm) = @_;
14072: my ($configuserok,%currroles);
14073: if ($uhome eq 'no_host') {
14074: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 14075: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 14076: $configuserok =
14077: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
14078: $configpass,'','','','','',undef,$servadm);
14079: } else {
14080: $configuserok = 'ok';
14081: %currroles =
14082: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
14083: }
14084: return ($configuserok,%currroles);
14085: }
14086:
14087: sub check_authorstatus {
14088: my ($dom,$confname,%currroles) = @_;
14089: my $author_ok;
1.40 raeburn 14090: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 14091: my $start = time;
14092: my $end = 0;
14093: $author_ok =
14094: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 14095: 'au',$end,$start,'','','domconfig');
1.9 raeburn 14096: } else {
14097: $author_ok = 'ok';
14098: }
14099: return $author_ok;
14100: }
14101:
1.421 raeburn 14102: sub update_modify_urls {
14103: my ($r,$modified) = @_;
14104: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
14105: push(@{$modified_urls},$modified);
14106: unless ($registered_cleanup) {
14107: my $handlers = $r->get_handlers('PerlCleanupHandler');
14108: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
14109: $registered_cleanup=1;
1.9 raeburn 14110: }
14111: }
1.155 raeburn 14112: }
14113:
14114: sub notifysubscribed {
14115: foreach my $targetsource (@{$modified_urls}){
14116: next unless (ref($targetsource) eq 'ARRAY');
14117: my ($target,$source)=@{$targetsource};
14118: if ($source ne '') {
1.316 raeburn 14119: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 14120: print $logfh "\nCleanup phase: Notifications\n";
14121: my @subscribed=&subscribed_hosts($target);
14122: foreach my $subhost (@subscribed) {
14123: print $logfh "\nNotifying host ".$subhost.':';
14124: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
14125: print $logfh $reply;
14126: }
14127: my @subscribedmeta=&subscribed_hosts("$target.meta");
14128: foreach my $subhost (@subscribedmeta) {
14129: print $logfh "\nNotifying host for metadata only ".$subhost.':';
14130: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
14131: $subhost);
14132: print $logfh $reply;
14133: }
14134: print $logfh "\n============ Done ============\n";
1.160 raeburn 14135: close($logfh);
1.155 raeburn 14136: }
14137: }
14138: }
14139: return OK;
14140: }
14141:
14142: sub subscribed_hosts {
14143: my ($target) = @_;
14144: my @subscribed;
1.316 raeburn 14145: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 14146: while (my $subline=<$fh>) {
14147: if ($subline =~ /^($match_lonid):/) {
14148: my $host = $1;
14149: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
14150: unless (grep(/^\Q$host\E$/,@subscribed)) {
14151: push(@subscribed,$host);
14152: }
14153: }
14154: }
14155: }
14156: }
14157: return @subscribed;
1.9 raeburn 14158: }
14159:
14160: sub check_switchserver {
14161: my ($dom,$confname) = @_;
1.424 raeburn 14162: my ($allowed,$switchserver,$home);
14163: if ($confname eq '') {
1.9 raeburn 14164: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14165: } else {
14166: $home = &Apache::lonnet::homeserver($confname,$dom);
14167: if ($home eq 'no_host') {
14168: $home = &Apache::lonnet::domain($dom,'primary');
14169: }
1.9 raeburn 14170: }
14171: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14172: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14173: if (!$allowed) {
1.426 raeburn 14174: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14175: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14176: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14177: }
14178: return $switchserver;
14179: }
14180:
1.1 raeburn 14181: sub modify_quotas {
1.216 raeburn 14182: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14183: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14184: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14185: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14186: $validationfieldsref);
1.86 raeburn 14187: if ($action eq 'quotas') {
1.429 raeburn 14188: $context = 'tools';
1.163 raeburn 14189: } else {
1.86 raeburn 14190: $context = $action;
14191: }
14192: if ($context eq 'requestcourses') {
1.325 raeburn 14193: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14194: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14195: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14196: %titles = &courserequest_titles();
14197: $toolregexp = join('|',@usertools);
14198: %conditions = &courserequest_conditions();
1.216 raeburn 14199: $confname = $dom.'-domainconfig';
14200: my $servadm = $r->dir_config('lonAdmEMail');
14201: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14202: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14203: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14204: } elsif ($context eq 'requestauthor') {
14205: @usertools = ('author');
14206: %titles = &authorrequest_titles();
1.86 raeburn 14207: } else {
1.430 raeburn 14208: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14209: %titles = &tool_titles();
1.86 raeburn 14210: }
1.212 raeburn 14211: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14212: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14213: foreach my $key (keys(%env)) {
1.101 raeburn 14214: if ($context eq 'requestcourses') {
14215: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14216: my $item = $1;
14217: my $type = $2;
14218: if ($type =~ /^limit_(.+)/) {
14219: $limithash{$item}{$1} = $env{$key};
14220: } else {
14221: $confhash{$item}{$type} = $env{$key};
14222: }
14223: }
1.163 raeburn 14224: } elsif ($context eq 'requestauthor') {
14225: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14226: $confhash{$1} = $env{$key};
14227: }
1.101 raeburn 14228: } else {
1.86 raeburn 14229: if ($key =~ /^form\.quota_(.+)$/) {
14230: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14231: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14232: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14233: }
1.72 raeburn 14234: }
14235: }
1.163 raeburn 14236: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14237: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14238: @approvalnotify = sort(@approvalnotify);
14239: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14240: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14241: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14242: foreach my $type (@hasuniquecode) {
14243: if (grep(/^\Q$type\E$/,@crstypes)) {
14244: $confhash{'uniquecode'}{$type} = 1;
14245: }
1.216 raeburn 14246: }
1.242 raeburn 14247: my (%newbook,%allpos);
1.216 raeburn 14248: if ($context eq 'requestcourses') {
1.242 raeburn 14249: foreach my $type ('textbooks','templates') {
14250: @{$allpos{$type}} = ();
14251: my $invalid;
14252: if ($type eq 'textbooks') {
14253: $invalid = &mt('Invalid LON-CAPA course for textbook');
14254: } else {
14255: $invalid = &mt('Invalid LON-CAPA course for template');
14256: }
14257: if ($env{'form.'.$type.'_addbook'}) {
14258: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14259: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14260: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14261: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14262: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14263: } else {
14264: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14265: my $position = $env{'form.'.$type.'_addbook_pos'};
14266: $position =~ s/\D+//g;
14267: if ($position ne '') {
14268: $allpos{$type}[$position] = $newbook{$type};
14269: }
1.216 raeburn 14270: }
1.242 raeburn 14271: } else {
14272: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14273: }
14274: }
1.242 raeburn 14275: }
1.216 raeburn 14276: }
1.102 raeburn 14277: if (ref($domconfig{$action}) eq 'HASH') {
14278: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14279: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14280: $changes{'notify'}{'approval'} = 1;
14281: }
14282: } else {
1.144 raeburn 14283: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14284: $changes{'notify'}{'approval'} = 1;
14285: }
14286: }
1.218 raeburn 14287: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14288: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14289: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14290: unless ($confhash{'uniquecode'}{$crstype}) {
14291: $changes{'uniquecode'} = 1;
14292: }
14293: }
14294: unless ($changes{'uniquecode'}) {
14295: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14296: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14297: $changes{'uniquecode'} = 1;
14298: }
14299: }
14300: }
14301: } else {
14302: $changes{'uniquecode'} = 1;
14303: }
14304: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14305: $changes{'uniquecode'} = 1;
1.216 raeburn 14306: }
14307: if ($context eq 'requestcourses') {
1.242 raeburn 14308: foreach my $type ('textbooks','templates') {
14309: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14310: my %deletions;
14311: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14312: if (@todelete) {
14313: map { $deletions{$_} = 1; } @todelete;
14314: }
14315: my %imgdeletions;
14316: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14317: if (@todeleteimages) {
14318: map { $imgdeletions{$_} = 1; } @todeleteimages;
14319: }
14320: my $maxnum = $env{'form.'.$type.'_maxnum'};
14321: for (my $i=0; $i<=$maxnum; $i++) {
14322: my $itemid = $env{'form.'.$type.'_id_'.$i};
14323: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14324: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14325: if ($deletions{$key}) {
14326: if ($domconfig{$action}{$type}{$key}{'image'}) {
14327: #FIXME need to obsolete item in RES space
14328: }
14329: next;
14330: } else {
14331: my $newpos = $env{'form.'.$itemid};
14332: $newpos =~ s/\D+//g;
1.243 raeburn 14333: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14334: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14335: ($type eq 'templates'));
1.242 raeburn 14336: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14337: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14338: $changes{$type}{$key} = 1;
14339: }
14340: }
14341: $allpos{$type}[$newpos] = $key;
14342: }
14343: if ($imgdeletions{$key}) {
14344: $changes{$type}{$key} = 1;
1.216 raeburn 14345: #FIXME need to obsolete item in RES space
1.242 raeburn 14346: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14347: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14348: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14349: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14350: } else {
14351: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14352: $cdom,$cnum,$type,$configuserok,
14353: $switchserver,$author_ok);
14354: if ($imgurl) {
14355: $confhash{$type}{$key}{'image'} = $imgurl;
14356: $changes{$type}{$key} = 1;
14357: }
14358: if ($error) {
14359: &Apache::lonnet::logthis($error);
14360: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14361: }
14362: }
1.242 raeburn 14363: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14364: $confhash{$type}{$key}{'image'} =
14365: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14366: }
14367: }
14368: }
14369: }
14370: }
14371: }
1.102 raeburn 14372: } else {
1.144 raeburn 14373: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14374: $changes{'notify'}{'approval'} = 1;
14375: }
1.218 raeburn 14376: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14377: $changes{'uniquecode'} = 1;
14378: }
14379: }
14380: if ($context eq 'requestcourses') {
1.242 raeburn 14381: foreach my $type ('textbooks','templates') {
14382: if ($newbook{$type}) {
14383: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14384: foreach my $item ('subject','title','publisher','author') {
14385: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14386: ($type eq 'template'));
1.242 raeburn 14387: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14388: if ($env{'form.'.$type.'_addbook_'.$item}) {
14389: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14390: }
14391: }
14392: if ($type eq 'textbooks') {
14393: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14394: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14395: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14396: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14397: } else {
14398: my ($imageurl,$error) =
14399: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14400: $configuserok,$switchserver,$author_ok);
14401: if ($imageurl) {
14402: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14403: }
14404: if ($error) {
14405: &Apache::lonnet::logthis($error);
14406: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14407: }
1.242 raeburn 14408: }
14409: }
1.216 raeburn 14410: }
14411: }
1.242 raeburn 14412: if (@{$allpos{$type}} > 0) {
14413: my $idx = 0;
14414: foreach my $item (@{$allpos{$type}}) {
14415: if ($item ne '') {
14416: $confhash{$type}{$item}{'order'} = $idx;
14417: if (ref($domconfig{$action}) eq 'HASH') {
14418: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14419: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14420: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14421: $changes{$type}{$item} = 1;
14422: }
1.216 raeburn 14423: }
14424: }
14425: }
1.242 raeburn 14426: $idx ++;
1.216 raeburn 14427: }
14428: }
14429: }
14430: }
1.235 raeburn 14431: if (ref($validationitemsref) eq 'ARRAY') {
14432: foreach my $item (@{$validationitemsref}) {
14433: if ($item eq 'fields') {
14434: my @changed;
14435: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14436: if (@{$confhash{'validation'}{$item}} > 0) {
14437: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14438: }
1.266 raeburn 14439: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14440: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14441: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14442: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14443: $domconfig{'requestcourses'}{'validation'}{$item});
14444: } else {
14445: @changed = @{$confhash{'validation'}{$item}};
14446: }
1.235 raeburn 14447: } else {
14448: @changed = @{$confhash{'validation'}{$item}};
14449: }
14450: } else {
14451: @changed = @{$confhash{'validation'}{$item}};
14452: }
14453: if (@changed) {
14454: if ($confhash{'validation'}{$item}) {
14455: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14456: } else {
14457: $changes{'validation'}{$item} = &mt('None');
14458: }
14459: }
14460: } else {
14461: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14462: if ($item eq 'markup') {
14463: if ($env{'form.requestcourses_validation_'.$item}) {
14464: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14465: }
14466: }
1.266 raeburn 14467: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14468: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14469: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14470: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14471: }
14472: } else {
14473: if ($confhash{'validation'}{$item} ne '') {
14474: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14475: }
1.235 raeburn 14476: }
14477: } else {
14478: if ($confhash{'validation'}{$item} ne '') {
14479: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14480: }
14481: }
14482: }
14483: }
14484: }
14485: if ($env{'form.validationdc'}) {
14486: my $newval = $env{'form.validationdc'};
1.285 raeburn 14487: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14488: if (exists($domcoords{$newval})) {
14489: $confhash{'validation'}{'dc'} = $newval;
14490: }
14491: }
14492: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14493: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14494: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14495: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14496: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14497: if ($confhash{'validation'}{'dc'} eq '') {
14498: $changes{'validation'}{'dc'} = &mt('None');
14499: } else {
14500: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14501: }
1.235 raeburn 14502: }
1.266 raeburn 14503: } elsif ($confhash{'validation'}{'dc'} ne '') {
14504: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14505: }
14506: } elsif ($confhash{'validation'}{'dc'} ne '') {
14507: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14508: }
14509: } elsif ($confhash{'validation'}{'dc'} ne '') {
14510: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14511: }
1.266 raeburn 14512: } else {
14513: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14514: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14515: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14516: $changes{'validation'}{'dc'} = &mt('None');
14517: }
14518: }
1.235 raeburn 14519: }
14520: }
1.102 raeburn 14521: }
14522: } else {
1.86 raeburn 14523: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14524: }
1.72 raeburn 14525: foreach my $item (@usertools) {
14526: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14527: my $unset;
1.101 raeburn 14528: if ($context eq 'requestcourses') {
1.104 raeburn 14529: $unset = '0';
14530: if ($type eq '_LC_adv') {
14531: $unset = '';
14532: }
1.101 raeburn 14533: if ($confhash{$item}{$type} eq 'autolimit') {
14534: $confhash{$item}{$type} .= '=';
14535: unless ($limithash{$item}{$type} =~ /\D/) {
14536: $confhash{$item}{$type} .= $limithash{$item}{$type};
14537: }
14538: }
1.163 raeburn 14539: } elsif ($context eq 'requestauthor') {
14540: $unset = '0';
14541: if ($type eq '_LC_adv') {
14542: $unset = '';
14543: }
1.72 raeburn 14544: } else {
1.101 raeburn 14545: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14546: $confhash{$item}{$type} = 1;
14547: } else {
14548: $confhash{$item}{$type} = 0;
14549: }
1.72 raeburn 14550: }
1.86 raeburn 14551: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14552: if ($action eq 'requestauthor') {
14553: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14554: $changes{$type} = 1;
14555: }
14556: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14557: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14558: $changes{$item}{$type} = 1;
14559: }
14560: } else {
14561: if ($context eq 'requestcourses') {
1.104 raeburn 14562: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14563: $changes{$item}{$type} = 1;
14564: }
14565: } else {
14566: if (!$confhash{$item}{$type}) {
14567: $changes{$item}{$type} = 1;
14568: }
14569: }
14570: }
14571: } else {
14572: if ($context eq 'requestcourses') {
1.104 raeburn 14573: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14574: $changes{$item}{$type} = 1;
14575: }
1.163 raeburn 14576: } elsif ($context eq 'requestauthor') {
14577: if ($confhash{$type} ne $unset) {
14578: $changes{$type} = 1;
14579: }
1.72 raeburn 14580: } else {
14581: if (!$confhash{$item}{$type}) {
14582: $changes{$item}{$type} = 1;
14583: }
14584: }
14585: }
1.1 raeburn 14586: }
14587: }
1.163 raeburn 14588: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14589: if (ref($domconfig{'quotas'}) eq 'HASH') {
14590: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14591: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14592: if (exists($confhash{'defaultquota'}{$key})) {
14593: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14594: $changes{'defaultquota'}{$key} = 1;
14595: }
14596: } else {
14597: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14598: }
14599: }
1.86 raeburn 14600: } else {
14601: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14602: if (exists($confhash{'defaultquota'}{$key})) {
14603: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14604: $changes{'defaultquota'}{$key} = 1;
14605: }
14606: } else {
14607: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14608: }
1.1 raeburn 14609: }
14610: }
1.197 raeburn 14611: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14612: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14613: }
14614: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14615: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14616: }
1.1 raeburn 14617: }
1.86 raeburn 14618: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14619: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14620: if (ref($domconfig{'quotas'}) eq 'HASH') {
14621: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14622: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14623: $changes{'defaultquota'}{$key} = 1;
14624: }
14625: } else {
14626: if (!exists($domconfig{'quotas'}{$key})) {
14627: $changes{'defaultquota'}{$key} = 1;
14628: }
1.72 raeburn 14629: }
14630: } else {
1.86 raeburn 14631: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14632: }
1.1 raeburn 14633: }
14634: }
14635: }
1.72 raeburn 14636:
1.163 raeburn 14637: if ($context eq 'requestauthor') {
14638: $domdefaults{'requestauthor'} = \%confhash;
14639: } else {
14640: foreach my $key (keys(%confhash)) {
1.242 raeburn 14641: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14642: $domdefaults{$key} = $confhash{$key};
14643: }
1.163 raeburn 14644: }
1.72 raeburn 14645: }
1.163 raeburn 14646:
1.1 raeburn 14647: my %quotahash = (
1.86 raeburn 14648: $action => { %confhash }
1.1 raeburn 14649: );
14650: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14651: $dom);
14652: if ($putresult eq 'ok') {
14653: if (keys(%changes) > 0) {
1.72 raeburn 14654: my $cachetime = 24*60*60;
14655: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14656: if (ref($lastactref) eq 'HASH') {
14657: $lastactref->{'domdefaults'} = 1;
14658: }
1.1 raeburn 14659: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14660: unless (($context eq 'requestcourses') ||
1.163 raeburn 14661: ($context eq 'requestauthor')) {
1.86 raeburn 14662: if (ref($changes{'defaultquota'}) eq 'HASH') {
14663: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14664: foreach my $type (@{$types},'default') {
14665: if (defined($changes{'defaultquota'}{$type})) {
14666: my $typetitle = $usertypes->{$type};
14667: if ($type eq 'default') {
14668: $typetitle = $othertitle;
14669: }
1.213 raeburn 14670: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14671: }
14672: }
1.86 raeburn 14673: $resulttext .= '</ul></li>';
1.72 raeburn 14674: }
14675: }
1.80 raeburn 14676: my %newenv;
1.72 raeburn 14677: foreach my $item (@usertools) {
1.163 raeburn 14678: my (%haschgs,%inconf);
14679: if ($context eq 'requestauthor') {
14680: %haschgs = %changes;
1.210 raeburn 14681: %inconf = %confhash;
1.163 raeburn 14682: } else {
14683: if (ref($changes{$item}) eq 'HASH') {
14684: %haschgs = %{$changes{$item}};
14685: }
14686: if (ref($confhash{$item}) eq 'HASH') {
14687: %inconf = %{$confhash{$item}};
14688: }
14689: }
14690: if (keys(%haschgs) > 0) {
1.80 raeburn 14691: my $newacc =
14692: &Apache::lonnet::usertools_access($env{'user.name'},
14693: $env{'user.domain'},
1.86 raeburn 14694: $item,'reload',$context);
1.210 raeburn 14695: if (($context eq 'requestcourses') ||
1.163 raeburn 14696: ($context eq 'requestauthor')) {
1.108 raeburn 14697: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14698: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14699: }
14700: } else {
14701: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14702: $newenv{'environment.availabletools.'.$item} = $newacc;
14703: }
1.80 raeburn 14704: }
1.163 raeburn 14705: unless ($context eq 'requestauthor') {
14706: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14707: }
1.72 raeburn 14708: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14709: if ($haschgs{$type}) {
1.72 raeburn 14710: my $typetitle = $usertypes->{$type};
14711: if ($type eq 'default') {
14712: $typetitle = $othertitle;
14713: } elsif ($type eq '_LC_adv') {
14714: $typetitle = 'LON-CAPA Advanced Users';
14715: }
1.163 raeburn 14716: if ($inconf{$type}) {
1.101 raeburn 14717: if ($context eq 'requestcourses') {
14718: my $cond;
1.163 raeburn 14719: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14720: if ($1 eq '') {
14721: $cond = &mt('(Automatic processing of any request).');
14722: } else {
14723: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14724: }
14725: } else {
1.163 raeburn 14726: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14727: }
14728: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14729: } elsif ($context eq 'requestauthor') {
14730: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14731: $titles{$inconf{$type}},$typetitle);
14732:
1.101 raeburn 14733: } else {
14734: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14735: }
1.72 raeburn 14736: } else {
1.104 raeburn 14737: if ($type eq '_LC_adv') {
1.163 raeburn 14738: if ($inconf{$type} eq '0') {
1.104 raeburn 14739: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14740: } else {
14741: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14742: }
14743: } else {
14744: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14745: }
1.72 raeburn 14746: }
14747: }
1.26 raeburn 14748: }
1.163 raeburn 14749: unless ($context eq 'requestauthor') {
14750: $resulttext .= '</ul></li>';
14751: }
1.26 raeburn 14752: }
1.1 raeburn 14753: }
1.163 raeburn 14754: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14755: if (ref($changes{'notify'}) eq 'HASH') {
14756: if ($changes{'notify'}{'approval'}) {
14757: if (ref($confhash{'notify'}) eq 'HASH') {
14758: if ($confhash{'notify'}{'approval'}) {
14759: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14760: } else {
1.163 raeburn 14761: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14762: }
14763: }
14764: }
14765: }
14766: }
1.216 raeburn 14767: if ($action eq 'requestcourses') {
14768: my @offon = ('off','on');
14769: if ($changes{'uniquecode'}) {
1.218 raeburn 14770: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14771: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14772: $resulttext .= '<li>'.
14773: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14774: '</li>';
14775: } else {
14776: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14777: '</li>';
14778: }
1.216 raeburn 14779: }
1.242 raeburn 14780: foreach my $type ('textbooks','templates') {
14781: if (ref($changes{$type}) eq 'HASH') {
14782: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14783: foreach my $key (sort(keys(%{$changes{$type}}))) {
14784: my %coursehash = &Apache::lonnet::coursedescription($key);
14785: my $coursetitle = $coursehash{'description'};
14786: my $position = $confhash{$type}{$key}{'order'} + 1;
14787: $resulttext .= '<li>';
1.243 raeburn 14788: foreach my $item ('subject','title','publisher','author') {
14789: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14790: ($type eq 'templates'));
1.242 raeburn 14791: my $name = $item.':';
14792: $name =~ s/^(\w)/\U$1/;
14793: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14794: }
14795: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14796: if ($type eq 'textbooks') {
14797: if ($confhash{$type}{$key}{'image'}) {
14798: $resulttext .= ' '.&mt('Image: [_1]',
14799: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14800: ' alt="Textbook cover" />').'<br />';
14801: }
14802: }
14803: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14804: }
1.242 raeburn 14805: $resulttext .= '</ul></li>';
1.216 raeburn 14806: }
14807: }
1.235 raeburn 14808: if (ref($changes{'validation'}) eq 'HASH') {
14809: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14810: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14811: foreach my $item (@{$validationitemsref}) {
14812: if (exists($changes{'validation'}{$item})) {
14813: if ($item eq 'markup') {
14814: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14815: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14816: } else {
14817: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14818: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14819: }
14820: }
14821: }
14822: if (exists($changes{'validation'}{'dc'})) {
14823: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14824: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14825: }
1.442 raeburn 14826: $resulttext .= '</ul></li>';
1.235 raeburn 14827: }
14828: }
1.216 raeburn 14829: }
1.1 raeburn 14830: $resulttext .= '</ul>';
1.80 raeburn 14831: if (keys(%newenv)) {
14832: &Apache::lonnet::appenv(\%newenv);
14833: }
1.1 raeburn 14834: } else {
1.86 raeburn 14835: if ($context eq 'requestcourses') {
14836: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14837: } elsif ($context eq 'requestauthor') {
14838: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14839: } else {
1.90 weissno 14840: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14841: }
1.1 raeburn 14842: }
14843: } else {
1.11 albertel 14844: $resulttext = '<span class="LC_error">'.
14845: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14846: }
1.216 raeburn 14847: if ($errors) {
14848: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14849: '<ul>'.$errors.'</ul></p>';
14850: }
1.3 raeburn 14851: return $resulttext;
1.1 raeburn 14852: }
14853:
1.216 raeburn 14854: sub process_textbook_image {
1.242 raeburn 14855: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14856: my $filename = $env{'form.'.$caller.'.filename'};
14857: my ($error,$url);
14858: my ($width,$height) = (50,50);
14859: if ($configuserok eq 'ok') {
14860: if ($switchserver) {
14861: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14862: $switchserver);
14863: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14864: my $modified = [];
1.216 raeburn 14865: my ($result,$imageurl) =
1.421 raeburn 14866: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14867: "$type/$cdom/$cnum/cover",$width,$height,
14868: '',$modified);
1.216 raeburn 14869: if ($result eq 'ok') {
14870: $url = $imageurl;
1.421 raeburn 14871: &update_modify_urls($r,$modified);
1.216 raeburn 14872: } else {
14873: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14874: }
14875: } else {
14876: $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);
14877: }
14878: } else {
14879: $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);
14880: }
14881: return ($url,$error);
14882: }
14883:
1.267 raeburn 14884: sub modify_ltitools {
14885: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14886: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14887: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14888:
1.267 raeburn 14889: my $confname = $dom.'-domainconfig';
14890: my $servadm = $r->dir_config('lonAdmEMail');
14891: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14892:
14893: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14894: my $toolserror =
14895: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14896: $lastactref,$configuserok,$switchserver,$author_ok);
14897:
14898: my $home = &Apache::lonnet::domain($dom,'primary');
14899: unless (($home eq 'no_host') || ($home eq '')) {
14900: my @ids=&Apache::lonnet::current_machine_ids();
14901: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14902: }
14903:
14904: if (keys(%ltitoolschg)) {
14905: foreach my $id (keys(%ltitoolschg)) {
14906: if (ref($ltitoolschg{$id}) eq 'HASH') {
14907: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14908: if (($inner eq 'secret') || ($inner eq 'key')) {
14909: if ($is_home) {
14910: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14911: }
14912: }
14913: }
1.267 raeburn 14914: }
1.421 raeburn 14915: }
14916: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14917: if (keys(%ltitoolschg)) {
14918: %newltitools = %ltitoolschg;
14919: }
14920: }
14921: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14922: foreach my $id (%{$domconfig{'ltitools'}}) {
14923: next if ($id !~ /^\d+$/);
14924: unless (exists($ltitoolschg{$id})) {
14925: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14926: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14927: if (($inner eq 'secret') || ($inner eq 'key')) {
14928: if ($is_home) {
14929: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14930: }
14931: } else {
14932: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14933: }
14934: }
14935: } else {
14936: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14937: }
1.421 raeburn 14938: }
14939: }
14940: }
14941: if ($toolserror) {
14942: $errors = '<li>'.$toolserror.'</li>';
14943: }
14944: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14945: $resulttext = &mt('No changes made.');
14946: if ($errors) {
14947: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14948: $errors.'</ul>';
14949: }
14950: return $resulttext;
14951: }
14952: my %ltitoolshash = (
14953: $action => { %newltitools }
14954: );
14955: if (keys(%secchanges)) {
14956: $ltitoolshash{'toolsec'} = \%newtoolsec;
14957: }
14958: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14959: if ($putresult eq 'ok') {
14960: my %keystore;
14961: if ($is_home) {
14962: my %toolsenchash = (
14963: $action => { %newtoolsenc }
14964: );
14965: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 14966: my $cachetime = 24*60*60;
14967: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 14968: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
14969: }
14970: $resulttext = &mt('Changes made:').'<ul>';
14971: if (keys(%secchanges) > 0) {
1.423 raeburn 14972: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 14973: }
14974: if (keys(%ltitoolschg) > 0) {
14975: $resulttext .= $ltitoolsoutput;
14976: }
1.423 raeburn 14977: my $cachetime = 24*60*60;
14978: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
14979: if (ref($lastactref) eq 'HASH') {
14980: $lastactref->{'ltitools'} = 1;
14981: }
1.421 raeburn 14982: } else {
14983: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14984: }
14985: if ($errors) {
14986: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14987: $errors.'</ul></p>';
14988: }
14989: return $resulttext;
14990: }
14991:
14992: sub fetch_secrets {
14993: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
14994: my %keyset;
14995: %{$currsec} = ();
14996: $newsec->{'private'}{'keys'} = [];
14997: $newsec->{'encrypt'} = {};
14998: $newsec->{'rules'} = {};
14999: if ($context eq 'ltisec') {
15000: $newsec->{'linkprot'} = {};
15001: }
15002: if (ref($domconfig->{$context}) eq 'HASH') {
15003: %{$currsec} = %{$domconfig->{$context}};
15004: if ($context eq 'ltisec') {
15005: if (ref($currsec->{'linkprot'}) eq 'HASH') {
15006: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
15007: unless ($id =~ /^\d+$/) {
15008: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 15009: }
1.267 raeburn 15010: }
15011: }
1.421 raeburn 15012: }
15013: if (ref($currsec->{'private'}) eq 'HASH') {
15014: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
15015: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
15016: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 15017: }
1.421 raeburn 15018: }
15019: }
15020: my @items= ('crs','dom');
15021: if ($context eq 'ltisec') {
15022: push(@items,'consumers');
15023: }
15024: foreach my $item (@items) {
15025: my $formelement;
15026: if (($context eq 'toolsec') || ($item eq 'consumers')) {
15027: $formelement = 'form.'.$context.'_'.$item;
15028: } else {
15029: $formelement = 'form.'.$context.'_'.$item.'linkprot';
15030: }
15031: if ($env{$formelement}) {
15032: $newsec->{'encrypt'}{$item} = 1;
15033: if (ref($currsec->{'encrypt'}) eq 'HASH') {
15034: unless ($currsec->{'encrypt'}{$item}) {
15035: $secchanges->{'encrypt'} = 1;
15036: }
15037: } else {
15038: $secchanges->{'encrypt'} = 1;
1.267 raeburn 15039: }
1.421 raeburn 15040: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
15041: if ($currsec->{'encrypt'}{$item}) {
15042: $secchanges->{'encrypt'} = 1;
1.323 raeburn 15043: }
1.421 raeburn 15044: }
15045: }
15046: my $secrets;
15047: if ($context eq 'ltisec') {
15048: $secrets = 'ltisecrets';
15049: } else {
15050: $secrets = 'toolsecrets';
15051: }
15052: unless (exists($currsec->{'rules'})) {
15053: $currsec->{'rules'} = {};
15054: }
15055: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
15056:
15057: my @ids=&Apache::lonnet::current_machine_ids();
15058: my %servers = &Apache::lonnet::get_servers($dom,'library');
15059:
15060: foreach my $hostid (keys(%servers)) {
15061: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
15062: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
15063: if (exists($env{$keyitem})) {
15064: $env{$keyitem} =~ s/(`)/'/g;
15065: if ($keyset{$hostid}) {
15066: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
15067: if ($env{$keyitem} ne '') {
15068: $secchanges->{'private'} = 1;
15069: $newkeyset->{$hostid} = $env{$keyitem};
15070: }
1.296 raeburn 15071: }
1.421 raeburn 15072: } elsif ($env{$keyitem} ne '') {
15073: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
15074: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 15075: }
1.421 raeburn 15076: $secchanges->{'private'} = 1;
15077: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 15078: }
15079: }
1.421 raeburn 15080: }
15081: }
15082: }
15083:
15084: sub store_security {
1.424 raeburn 15085: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 15086: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
15087: (ref($keystore) eq 'HASH'));
15088: if (keys(%{$secchanges})) {
15089: if ($secchanges->{'private'}) {
15090: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
15091: foreach my $hostid (keys(%{$newkeyset})) {
15092: my $storehash = {
15093: key => $newkeyset->{$hostid},
15094: who => $env{'user.name'}.':'.$env{'user.domain'},
15095: };
15096: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
15097: $dom,$hostid);
15098: }
15099: }
15100: }
15101: }
15102:
15103: sub lti_security_results {
1.423 raeburn 15104: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 15105: my $output;
1.423 raeburn 15106: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15107: my $needs_update;
1.421 raeburn 15108: foreach my $item (keys(%{$secchanges})) {
15109: if ($item eq 'encrypt') {
1.423 raeburn 15110: $needs_update = 1;
1.421 raeburn 15111: my %encrypted;
15112: if ($context eq 'lti') {
15113: %encrypted = (
15114: crs => {
15115: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
15116: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
15117: },
15118: dom => {
15119: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
15120: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
15121: },
15122: consumers => {
15123: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
15124: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
15125: },
15126: );
1.267 raeburn 15127: } else {
1.421 raeburn 15128: %encrypted = (
15129: crs => {
15130: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
15131: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
15132: },
15133: dom => {
15134: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
15135: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
15136: },
15137: );
15138: }
15139: my @types= ('crs','dom');
15140: if ($context eq 'lti') {
1.423 raeburn 15141: foreach my $type (@types) {
15142: undef($domdefaults{'linkprotenc_'.$type});
15143: }
1.421 raeburn 15144: push(@types,'consumers');
1.423 raeburn 15145: undef($domdefaults{'ltienc_consumers'});
15146: } elsif ($context eq 'ltitools') {
15147: foreach my $type (@types) {
15148: undef($domdefaults{'toolenc_'.$type});
15149: }
1.267 raeburn 15150: }
1.421 raeburn 15151: foreach my $type (@types) {
15152: my $shown = $encrypted{$type}{'off'};
15153: if (ref($newsec->{$item}) eq 'HASH') {
15154: if ($newsec->{$item}{$type}) {
1.423 raeburn 15155: if ($context eq 'lti') {
15156: if ($type eq 'consumers') {
15157: $domdefaults{'ltienc_consumers'} = 1;
15158: } else {
15159: $domdefaults{'linkprotenc_'.$type} = 1;
15160: }
15161: } elsif ($context eq 'ltitools') {
15162: $domdefaults{'toolenc_'.$type} = 1;
15163: }
1.421 raeburn 15164: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15165: }
1.267 raeburn 15166: }
1.421 raeburn 15167: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15168: }
1.421 raeburn 15169: } elsif ($item eq 'rules') {
15170: my %titles = &Apache::lonlocal::texthash(
15171: min => 'Minimum password length',
15172: max => 'Maximum password length',
15173: chars => 'Required characters',
15174: );
15175: foreach my $rule ('min','max') {
15176: if ($newsec->{rules}{$rule} eq '') {
15177: if ($rule eq 'min') {
15178: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15179: ' '.&mt('Default of [_1] will be used',
15180: $Apache::lonnet::passwdmin).'</li>';
15181: } else {
15182: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15183: }
15184: } else {
15185: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15186: }
15187: }
15188: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15189: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15190: my %rulenames = &Apache::lonlocal::texthash(
15191: uc => 'At least one upper case letter',
15192: lc => 'At least one lower case letter',
15193: num => 'At least one number',
15194: spec => 'At least one non-alphanumeric',
15195: );
15196: my $needed = '<ul><li>'.
15197: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15198: '</li></ul>';
15199: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15200: } else {
15201: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15202: }
1.421 raeburn 15203: } else {
15204: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15205: }
1.421 raeburn 15206: } elsif ($item eq 'private') {
1.423 raeburn 15207: $needs_update = 1;
15208: if ($context eq 'lti') {
15209: undef($domdefaults{'ltiprivhosts'});
15210: } elsif ($context eq 'ltitools') {
15211: undef($domdefaults{'toolprivhosts'});
15212: }
1.421 raeburn 15213: if (keys(%{$newkeyset})) {
1.423 raeburn 15214: my @privhosts;
1.421 raeburn 15215: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15216: if ($keystore->{$hostid} eq 'ok') {
15217: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15218: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15219: push(@privhosts,$hostid);
15220: }
15221: }
15222: }
15223: if (@privhosts) {
15224: if ($context eq 'lti') {
15225: $domdefaults{'ltiprivhosts'} = \@privhosts;
15226: } elsif ($context eq 'ltitools') {
15227: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15228: }
15229: }
15230: }
1.421 raeburn 15231: } elsif ($item eq 'linkprot') {
15232: next;
1.434 raeburn 15233: } elsif ($item eq 'suggested') {
15234: if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
15235: (ref($newsec->{'suggested'}) eq 'HASH')) {
15236: my $suggestions;
15237: foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
15238: if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
15239: my $name = $newsec->{'suggested'}->{$id}->{'name'};
15240: my $info = $newsec->{'suggested'}->{$id}->{'info'};
15241: $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
15242: &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
15243: '</li>';
15244: } else {
15245: $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
15246: $newsec->{'suggested'}->{$id}).'</li>';
15247: }
15248: }
15249: if ($suggestions) {
15250: $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
15251: '<ul>'.$suggestions.'</ul>'.
15252: '</li>';
15253: }
15254: }
1.267 raeburn 15255: }
15256: }
1.423 raeburn 15257: if ($needs_update) {
15258: my $cachetime = 24*60*60;
15259: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15260: }
1.421 raeburn 15261: return $output;
15262: }
15263:
15264: sub modify_proctoring {
15265: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15266: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15267: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15268: my $confname = $dom.'-domainconfig';
15269: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15270: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15271: my %providernames = &proctoring_providernames();
15272: my $maxnum = scalar(keys(%providernames));
15273:
15274: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15275: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15276: if (ref($requref) eq 'HASH') {
15277: %requserfields = %{$requref};
15278: }
15279: if (ref($opturef) eq 'HASH') {
15280: %optuserfields = %{$opturef};
15281: }
15282: if (ref($defref) eq 'HASH') {
15283: %defaults = %{$defref};
15284: }
15285: if (ref($extref) eq 'HASH') {
15286: %extended = %{$extref};
15287: }
15288: if (ref($crsref) eq 'HASH') {
15289: %crsconf = %{$crsref};
15290: }
15291: if (ref($rolesref) eq 'ARRAY') {
15292: @courseroles = @{$rolesref};
15293: }
15294: if (ref($ltiref) eq 'ARRAY') {
15295: @ltiroles = @{$ltiref};
15296: }
15297:
15298: if (ref($domconfig{$action}) eq 'HASH') {
15299: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15300: if (@todeleteimages) {
15301: map { $imgdeletions{$_} = 1; } @todeleteimages;
15302: }
15303: }
15304: my %customadds;
15305: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15306: if (@newcustom) {
15307: map { $customadds{$_} = 1; } @newcustom;
15308: }
15309: foreach my $provider (sort(keys(%providernames))) {
15310: $confhash{$provider} = {};
15311: my $pos = $env{'form.proctoring_pos_'.$provider};
15312: $pos =~ s/\D+//g;
15313: $allpos[$pos] = $provider;
15314: my (%current,%currentenc);
15315: my $showroles = 0;
15316: if (ref($domconfig{$action}) eq 'HASH') {
15317: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15318: %current = %{$domconfig{$action}{$provider}};
15319: foreach my $item ('key','secret') {
15320: $currentenc{$item} = $current{$item};
15321: delete($current{$item});
15322: }
15323: }
15324: }
15325: if ($env{'form.proctoring_available_'.$provider}) {
15326: $confhash{$provider}{'available'} = 1;
15327: unless ($current{'available'}) {
15328: $changes{$provider} = 1;
15329: }
15330: } else {
15331: %{$confhash{$provider}} = %current;
15332: %{$encconfhash{$provider}} = %currentenc;
15333: $confhash{$provider}{'available'} = 0;
15334: if ($current{'available'}) {
15335: $changes{$provider} = 1;
15336: }
15337: }
15338: if ($confhash{$provider}{'available'}) {
15339: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15340: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15341: if ($field eq 'lifetime') {
15342: if ($possval =~ /^\d+$/) {
15343: $confhash{$provider}{$field} = $possval;
15344: }
15345: } elsif ($field eq 'version') {
15346: if ($possval =~ /^\d+\.\d+$/) {
15347: $confhash{$provider}{$field} = $possval;
15348: }
15349: } elsif ($field eq 'sigmethod') {
15350: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15351: $confhash{$provider}{$field} = $possval;
15352: }
15353: } elsif ($field eq 'url') {
15354: $confhash{$provider}{$field} = $possval;
15355: } elsif (($field eq 'key') || ($field eq 'secret')) {
15356: $encconfhash{$provider}{$field} = $possval;
15357: unless ($currentenc{$field} eq $possval) {
15358: $changes{$provider} = 1;
15359: }
15360: }
15361: unless (($field eq 'key') || ($field eq 'secret')) {
15362: unless ($current{$field} eq $confhash{$provider}{$field}) {
15363: $changes{$provider} = 1;
15364: }
15365: }
15366: }
15367: if ($imgdeletions{$provider}) {
15368: $changes{$provider} = 1;
15369: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15370: my ($imageurl,$error) =
15371: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15372: $configuserok,$switchserver,$author_ok);
15373: if ($imageurl) {
15374: $confhash{$provider}{'image'} = $imageurl;
15375: $changes{$provider} = 1;
15376: }
15377: if ($error) {
15378: &Apache::lonnet::logthis($error);
15379: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15380: }
15381: } elsif (exists($current{'image'})) {
15382: $confhash{$provider}{'image'} = $current{'image'};
15383: }
15384: if (ref($requserfields{$provider}) eq 'ARRAY') {
15385: if (@{$requserfields{$provider}} > 0) {
15386: if (grep(/^user$/,@{$requserfields{$provider}})) {
15387: if ($env{'form.proctoring_userincdom_'.$provider}) {
15388: $confhash{$provider}{'incdom'} = 1;
15389: }
15390: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15391: $changes{$provider} = 1;
15392: }
15393: }
15394: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15395: $showroles = 1;
15396: }
15397: }
15398: }
15399: $confhash{$provider}{'fields'} = [];
15400: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15401: if (@{$optuserfields{$provider}} > 0) {
15402: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15403: foreach my $field (@{$optuserfields{$provider}}) {
15404: if (grep(/^\Q$field\E$/,@optfields)) {
15405: push(@{$confhash{$provider}{'fields'}},$field);
15406: }
15407: }
15408: }
15409: if (ref($current{'fields'}) eq 'ARRAY') {
15410: unless ($changes{$provider}) {
15411: my @new = sort(@{$confhash{$provider}{'fields'}});
15412: my @old = sort(@{$current{'fields'}});
15413: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15414: if (@diffs) {
15415: $changes{$provider} = 1;
15416: }
15417: }
15418: } elsif (@{$confhash{$provider}{'fields'}}) {
15419: $changes{$provider} = 1;
15420: }
15421: }
15422: if (ref($defaults{$provider}) eq 'ARRAY') {
15423: if (@{$defaults{$provider}} > 0) {
15424: my %options;
15425: if (ref($extended{$provider}) eq 'HASH') {
15426: %options = %{$extended{$provider}};
15427: }
15428: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15429: foreach my $field (@{$defaults{$provider}}) {
15430: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15431: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15432: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15433: push(@{$confhash{$provider}{'defaults'}},$poss);
15434: }
15435: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15436: foreach my $inner (keys(%{$options{$field}})) {
15437: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15438: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15439: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15440: $confhash{$provider}{'defaults'}{$inner} = $poss;
15441: }
15442: } else {
15443: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15444: }
15445: }
15446: } else {
15447: if (grep(/^\Q$field\E$/,@checked)) {
15448: push(@{$confhash{$provider}{'defaults'}},$field);
15449: }
15450: }
15451: }
15452: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15453: if (ref($current{'defaults'}) eq 'ARRAY') {
15454: unless ($changes{$provider}) {
15455: my @new = sort(@{$confhash{$provider}{'defaults'}});
15456: my @old = sort(@{$current{'defaults'}});
15457: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15458: if (@diffs) {
15459: $changes{$provider} = 1;
15460: }
15461: }
15462: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15463: if (@{$current{'defaults'}}) {
15464: $changes{$provider} = 1;
15465: }
15466: }
15467: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15468: if (ref($current{'defaults'}) eq 'HASH') {
15469: unless ($changes{$provider}) {
15470: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15471: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15472: $changes{$provider} = 1;
15473: last;
15474: }
15475: }
15476: }
15477: unless ($changes{$provider}) {
15478: foreach my $key (keys(%{$current{'defaults'}})) {
15479: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15480: $changes{$provider} = 1;
15481: last;
15482: }
15483: }
15484: }
15485: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15486: $changes{$provider} = 1;
15487: }
15488: }
15489: }
15490: }
15491: if (ref($crsconf{$provider}) eq 'ARRAY') {
15492: if (@{$crsconf{$provider}} > 0) {
15493: $confhash{$provider}{'crsconf'} = [];
15494: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15495: foreach my $crsfield (@{$crsconf{$provider}}) {
15496: if (grep(/^\Q$crsfield\E$/,@checked)) {
15497: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15498: }
15499: }
15500: if (ref($current{'crsconf'}) eq 'ARRAY') {
15501: unless ($changes{$provider}) {
15502: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15503: my @old = sort(@{$current{'crsconf'}});
15504: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15505: if (@diffs) {
15506: $changes{$provider} = 1;
15507: }
15508: }
15509: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15510: $changes{$provider} = 1;
15511: }
15512: }
15513: }
15514: if ($showroles) {
15515: $confhash{$provider}{'roles'} = {};
15516: foreach my $role (@courseroles) {
15517: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15518: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15519: $confhash{$provider}{'roles'}{$role} = $poss;
15520: }
15521: }
15522: unless ($changes{$provider}) {
15523: if (ref($current{'roles'}) eq 'HASH') {
15524: foreach my $role (keys(%{$current{'roles'}})) {
15525: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15526: $changes{$provider} = 1;
15527: last
15528: }
15529: }
15530: unless ($changes{$provider}) {
15531: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15532: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15533: $changes{$provider} = 1;
15534: last;
15535: }
15536: }
15537: }
15538: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15539: $changes{$provider} = 1;
15540: }
15541: }
15542: }
15543: if (ref($current{'custom'}) eq 'HASH') {
15544: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15545: foreach my $key (keys(%{$current{'custom'}})) {
15546: if (grep(/^\Q$key\E$/,@customdels)) {
15547: $changes{$provider} = 1;
15548: } else {
15549: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15550: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15551: $changes{$provider} = 1;
15552: }
15553: }
15554: }
15555: }
15556: if ($customadds{$provider}) {
15557: my $name = $env{'form.proctoring_custom_name_'.$provider};
15558: $name =~ s/(`)/'/g;
15559: $name =~ s/^\s+//;
15560: $name =~ s/\s+$//;
15561: my $value = $env{'form.proctoring_custom_value_'.$provider};
15562: $value =~ s/(`)/'/g;
15563: $value =~ s/^\s+//;
15564: $value =~ s/\s+$//;
15565: if ($name ne '') {
15566: $confhash{$provider}{'custom'}{$name} = $value;
15567: $changes{$provider} = 1;
15568: }
15569: }
15570: }
15571: }
15572: if (@allpos > 0) {
15573: my $idx = 0;
15574: foreach my $provider (@allpos) {
15575: if ($provider ne '') {
15576: $confhash{$provider}{'order'} = $idx;
15577: unless ($changes{$provider}) {
15578: if (ref($domconfig{$action}) eq 'HASH') {
15579: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15580: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15581: $changes{$provider} = 1;
15582: }
15583: }
15584: }
15585: }
15586: $idx ++;
15587: }
15588: }
15589: }
15590: my %proc_hash = (
15591: $action => { %confhash }
15592: );
15593: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15594: $dom);
15595: if ($putresult eq 'ok') {
15596: my %proc_enchash = (
15597: $action => { %encconfhash }
15598: );
1.384 raeburn 15599: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15600: if (keys(%changes) > 0) {
15601: my $cachetime = 24*60*60;
15602: my %procall = %confhash;
15603: foreach my $provider (keys(%procall)) {
15604: if (ref($encconfhash{$provider}) eq 'HASH') {
15605: foreach my $key ('key','secret') {
15606: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15607: }
15608: }
15609: }
15610: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15611: if (ref($lastactref) eq 'HASH') {
15612: $lastactref->{'proctoring'} = 1;
15613: }
15614: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15615: my %bynum;
15616: foreach my $provider (sort(keys(%changes))) {
15617: my $position = $confhash{$provider}{'order'};
15618: $bynum{$position} = $provider;
15619: }
15620: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15621: my $provider = $bynum{$pos};
15622: my %lt = &proctoring_titles($provider);
15623: my %fieldtitles = &proctoring_fieldtitles($provider);
15624: if (!$confhash{$provider}{'available'}) {
15625: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15626: } else {
15627: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15628: if ($confhash{$provider}{'image'}) {
15629: $resulttext .= ' '.
15630: '<img src="'.$confhash{$provider}{'image'}.'"'.
15631: ' alt="'.&mt('Proctoring icon').'" />';
15632: }
15633: $resulttext .= '<ul>';
15634: my $position = $pos + 1;
15635: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15636: foreach my $key ('version','sigmethod','url','lifetime') {
15637: if ($confhash{$provider}{$key} ne '') {
15638: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15639: }
15640: }
15641: if ($encconfhash{$provider}{'key'} ne '') {
15642: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15643: }
15644: if ($encconfhash{$provider}{'secret'} ne '') {
15645: $resulttext .= '<li>'.$lt{'secret'}.': ';
15646: my $num = length($encconfhash{$provider}{'secret'});
15647: $resulttext .= ('*'x$num).'</li>';
15648: }
15649: my (@fields,$showroles);
15650: if (ref($requserfields{$provider}) eq 'ARRAY') {
15651: push(@fields,@{$requserfields{$provider}});
15652: }
15653: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15654: push(@fields,@{$confhash{$provider}{'fields'}});
15655: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15656: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15657: }
15658: if (@fields) {
15659: if (grep(/^roles$/,@fields)) {
15660: $showroles = 1;
15661: }
15662: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15663: join('", "', map { $lt{$_}; } @fields).'"</li>';
15664: }
15665: if (ref($requserfields{$provider}) eq 'ARRAY') {
15666: if (grep(/^user$/,@{$requserfields{$provider}})) {
15667: if ($confhash{$provider}{'incdom'}) {
15668: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15669: } else {
15670: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15671: }
15672: }
15673: }
15674: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15675: if (@{$confhash{$provider}{'defaults'}} > 0) {
15676: $resulttext .= '<li>'.$lt{'defa'};
15677: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15678: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15679: }
15680: $resulttext =~ s/,$//;
15681: $resulttext .= '</li>';
15682: }
15683: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15684: if (keys(%{$confhash{$provider}{'defaults'}})) {
15685: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15686: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15687: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15688: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15689: }
15690: }
15691: $resulttext .= '</ul></li>';
15692: }
15693: }
15694: if (ref($crsconf{$provider}) eq 'ARRAY') {
15695: if (@{$crsconf{$provider}} > 0) {
15696: $resulttext .= '<li>'.&mt('Configurable in course:');
15697: my $numconfig = 0;
15698: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15699: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15700: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15701: $numconfig ++;
15702: if ($provider eq 'examity') {
15703: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15704: } else {
15705: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15706: }
15707: }
15708: $resulttext =~ s/,$//;
15709: }
15710: }
15711: if (!$numconfig) {
15712: $resulttext .= ' '.&mt('None');
15713: }
15714: $resulttext .= '</li>';
15715: }
15716: }
15717: if ($showroles) {
15718: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15719: my $rolemaps;
15720: foreach my $role (@courseroles) {
15721: if ($confhash{$provider}{'roles'}{$role}) {
15722: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15723: $confhash{$provider}{'roles'}{$role}.',';
15724: }
15725: }
15726: if ($rolemaps) {
15727: $rolemaps =~ s/,$//;
15728: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15729: }
15730: }
15731: }
15732: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15733: my $customlist;
15734: if (keys(%{$confhash{$provider}{'custom'}})) {
15735: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15736: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15737: }
15738: $customlist =~ s/,$//;
15739: }
15740: if ($customlist) {
15741: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15742: }
15743: }
15744: $resulttext .= '</ul></li>';
15745: }
15746: }
15747: $resulttext .= '</ul>';
15748: } else {
15749: $resulttext = &mt('No changes made.');
15750: }
15751: } else {
15752: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15753: }
15754: if ($errors) {
15755: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15756: $errors.'</ul>';
15757: }
15758: return $resulttext;
15759: }
15760:
15761: sub process_proctoring_image {
15762: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15763: my $filename = $env{'form.'.$caller.'.filename'};
15764: my ($error,$url);
15765: my ($width,$height) = (21,21);
15766: if ($configuserok eq 'ok') {
15767: if ($switchserver) {
15768: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15769: $switchserver);
15770: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15771: my $modified = [];
1.372 raeburn 15772: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15773: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15774: "proctoring/$provider/icon",$width,$height,
15775: '',$modified);
1.372 raeburn 15776: if ($result eq 'ok') {
15777: if ($madethumb) {
15778: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15779: my $imagethumb = "$path/tn-".$imagefile;
15780: $url = $imagethumb;
15781: } else {
15782: $url = $imageurl;
15783: }
1.421 raeburn 15784: &update_modify_urls($r,$modified);
1.372 raeburn 15785: } else {
15786: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15787: }
15788: } else {
15789: $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);
15790: }
15791: } else {
15792: $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);
15793: }
15794: return ($url,$error);
15795: }
15796:
1.320 raeburn 15797: sub modify_lti {
15798: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15799: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15800: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15801: my (%posslti,%posslticrs,%posscrstype);
15802: my @courseroles = ('cc','in','ta','ep','st');
15803: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15804: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15805: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15806: my %coursetypetitles = &Apache::lonlocal::texthash (
15807: official => 'Official',
15808: unofficial => 'Unofficial',
15809: community => 'Community',
15810: textbook => 'Textbook',
15811: placement => 'Placement Test',
1.392 raeburn 15812: lti => 'LTI Provider',
1.320 raeburn 15813: );
1.325 raeburn 15814: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15815: my %lt = <i_names();
15816: map { $posslti{$_} = 1; } @ltiroles;
15817: map { $posslticrs{$_} = 1; } @lticourseroles;
15818: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15819:
1.326 raeburn 15820: my %menutitles = <imenu_titles();
1.421 raeburn 15821: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15822:
1.421 raeburn 15823: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15824:
1.406 raeburn 15825: my (%linkprotchg,$linkprotoutput,$is_home);
15826: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15827: \%linkprotchg,'domain');
15828: my $home = &Apache::lonnet::domain($dom,'primary');
15829: unless (($home eq 'no_host') || ($home eq '')) {
15830: my @ids=&Apache::lonnet::current_machine_ids();
15831: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15832: }
15833:
15834: if (keys(%linkprotchg)) {
15835: $secchanges{'linkprot'} = 1;
15836: my %oldlinkprot;
15837: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15838: %oldlinkprot = %{$currltisec{'linkprot'}};
15839: }
15840: foreach my $id (keys(%linkprotchg)) {
15841: if (ref($linkprotchg{$id}) eq 'HASH') {
15842: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15843: if (($inner eq 'secret') || ($inner eq 'key')) {
15844: if ($is_home) {
15845: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15846: }
15847: }
15848: }
15849: } else {
15850: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15851: }
15852: }
15853: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15854: if (keys(%linkprotchg)) {
15855: %{$newltisec{'linkprot'}} = %linkprotchg;
15856: }
15857: }
15858: if (ref($currltisec{'linkprot'}) eq 'HASH') {
1.434 raeburn 15859: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
1.406 raeburn 15860: next if ($id !~ /^\d+$/);
15861: unless (exists($linkprotchg{$id})) {
15862: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15863: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15864: if (($inner eq 'secret') || ($inner eq 'key')) {
15865: if ($is_home) {
15866: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15867: }
15868: } else {
15869: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15870: }
15871: }
15872: } else {
15873: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15874: }
15875: }
15876: }
15877: }
15878: if ($proterror) {
15879: $errors .= '<li>'.$proterror.'</li>';
15880: }
1.434 raeburn 15881:
15882: my (%delsuggested,%suggids,@suggested);;
15883: if (ref($currltisec{'suggested'}) eq 'HASH') {
15884: my $maxnum = $env{'form.linkprot_suggested_maxnum'};
15885: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
15886: for (my $i=0; $i<$maxnum; $i++) {
15887: my $itemid = $env{'form.linkprot_suggested_id_'.$i};
15888: $itemid =~ s/\D+//g;
15889: if ($itemid) {
15890: if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
15891: push(@suggested,$i);
15892: $suggids{$i} = $itemid;
15893: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
15894: if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
15895: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15896: }
15897: } else {
15898: if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
15899: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15900: } else {
15901: $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
15902: $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
15903: $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
15904: $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
15905: if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
15906: ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
15907: $secchanges{'suggested'}{$itemid} = 1;
15908: }
15909: }
15910: }
15911: }
15912: }
15913: }
15914: }
15915: foreach my $key (keys(%delsuggested)) {
15916: $newltisec{'suggested'}{$key} = $delsuggested{$key};
15917: $secchanges{'suggested'}{$key} = 1;
15918: }
15919: if (($env{'form.linkprot_suggested_add'}) &&
15920: ($env{'form.linkprot_suggested_name_add'} ne '')) {
15921: $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
15922: $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
15923: my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
15924: if ($newsuggid) {
15925: $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
15926: $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
15927: $secchanges{'suggested'}{$newsuggid} = 1;
15928: } else {
15929: my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
15930: if ($errormsg) {
15931: $error .= ' ('.$errormsg.')';
15932: }
15933: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15934: }
15935: }
1.320 raeburn 15936: my (@items,%deletions,%itemids);
15937: if ($env{'form.lti_add'}) {
15938: my $consumer = $env{'form.lti_consumer_add'};
15939: $consumer =~ s/(`)/'/g;
1.434 raeburn 15940: ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
1.320 raeburn 15941: if ($newid) {
15942: $itemids{'add'} = $newid;
15943: push(@items,'add');
15944: $changes{$newid} = 1;
15945: } else {
15946: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
1.434 raeburn 15947: if ($errormsg) {
15948: $error .= ' ('.$errormsg.')';
15949: }
1.320 raeburn 15950: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15951: }
15952: }
15953: if (ref($domconfig{$action}) eq 'HASH') {
15954: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15955: if (@todelete) {
15956: map { $deletions{$_} = 1; } @todelete;
15957: }
15958: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15959: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15960: my $itemid = $env{'form.lti_id_'.$i};
15961: $itemid =~ s/\D+//g;
15962: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15963: if ($deletions{$itemid}) {
15964: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15965: } else {
1.390 raeburn 15966: push(@items,$i);
15967: $itemids{$i} = $itemid;
1.320 raeburn 15968: }
15969: }
15970: }
15971: }
1.424 raeburn 15972: my (%keystore,$secstored);
15973: if ($is_home) {
15974: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
15975: }
15976:
15977: my ($cipher,$privnum);
15978: if ((@items > 0) && ($is_home)) {
15979: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
15980: $newltisec{'encrypt'},$keystore{$home});
15981: }
1.320 raeburn 15982: foreach my $idx (@items) {
15983: my $itemid = $itemids{$idx};
15984: next unless ($itemid);
1.424 raeburn 15985: my %currlti;
15986: unless ($idx eq 'add') {
15987: if (ref($domconfig{$action}) eq 'HASH') {
15988: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15989: %currlti = %{$domconfig{$action}{$itemid}};
15990: }
15991: }
15992: }
1.390 raeburn 15993: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 15994: $position =~ s/\D+//g;
15995: if ($position ne '') {
15996: $allpos[$position] = $itemid;
15997: }
1.424 raeburn 15998: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 15999: my $formitem = 'form.lti_'.$item.'_'.$idx;
16000: $env{$formitem} =~ s/(`)/'/g;
16001: if ($item eq 'lifetime') {
16002: $env{$formitem} =~ s/[^\d.]//g;
16003: }
16004: if ($env{$formitem} ne '') {
1.424 raeburn 16005: $confhash{$itemid}{$item} = $env{$formitem};
16006: unless (($idx eq 'add') || ($changes{$itemid})) {
16007: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
16008: $changes{$itemid} = 1;
1.320 raeburn 16009: }
16010: }
16011: }
16012: }
16013: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
16014: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
16015: }
1.345 raeburn 16016: if ($confhash{$itemid}{'requser'}) {
16017: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 16018: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 16019: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
16020: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
16021: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
16022: my $mapuser = $env{'form.lti_customuser_'.$idx};
16023: $mapuser =~ s/(`)/'/g;
1.405 raeburn 16024: $mapuser =~ s/^\s+|\s+$//g;
16025: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 16026: }
16027: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
16028: my @makeuser;
16029: foreach my $ltirole (sort(@possmakeuser)) {
16030: if ($posslti{$ltirole}) {
16031: push(@makeuser,$ltirole);
16032: }
16033: }
16034: $confhash{$itemid}{'makeuser'} = \@makeuser;
16035: if (@makeuser) {
16036: my $lcauth = $env{'form.lti_lcauth_'.$idx};
16037: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
16038: $confhash{$itemid}{'lcauth'} = $lcauth;
16039: if ($lcauth ne 'internal') {
16040: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
16041: $lcauthparm =~ s/^(\s+|\s+)$//g;
16042: $lcauthparm =~ s/`//g;
16043: if ($lcauthparm ne '') {
16044: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
16045: }
16046: }
16047: } else {
16048: $confhash{$itemid}{'lcauth'} = 'lti';
16049: }
1.320 raeburn 16050: }
1.345 raeburn 16051: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
16052: if (@possinstdata) {
1.447.2.2 raeburn 16053: foreach my $field (sort(@possinstdata)) {
1.345 raeburn 16054: if (exists($fieldtitles{$field})) {
1.447.2.2 raeburn 16055: push(@{$confhash{$itemid}{'instdata'}},$field);
1.325 raeburn 16056: }
16057: }
16058: }
1.363 raeburn 16059: if ($env{'form.lti_callback_'.$idx}) {
16060: if ($env{'form.lti_callbackparam_'.$idx}) {
16061: my $callback = $env{'form.lti_callbackparam_'.$idx};
16062: $callback =~ s/^\s+|\s+$//g;
16063: $confhash{$itemid}{'callback'} = $callback;
16064: }
16065: }
1.391 raeburn 16066: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 16067: if ($env{'form.lti_'.$field.'_'.$idx}) {
16068: $confhash{$itemid}{$field} = 1;
16069: }
1.320 raeburn 16070: }
1.345 raeburn 16071: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
16072: $confhash{$itemid}{lcmenu} = [];
16073: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
16074: foreach my $field (@possmenu) {
16075: if (exists($menutitles{$field})) {
16076: if ($field eq 'grades') {
16077: next unless ($env{'form.lti_inlinemenu_'.$idx});
16078: }
16079: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 16080: }
16081: }
16082: }
1.391 raeburn 16083: if ($confhash{$itemid}{'crsinc'}) {
16084: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
16085: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
16086: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
16087: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
16088: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
16089: $mapcrs =~ s/(`)/'/g;
16090: $mapcrs =~ s/^\s+|\s+$//g;
16091: $confhash{$itemid}{'mapcrs'} = $mapcrs;
16092: }
16093: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
16094: my @crstypes;
16095: foreach my $type (sort(@posstypes)) {
16096: if ($posscrstype{$type}) {
16097: push(@crstypes,$type);
16098: }
16099: }
16100: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 16101: if ($env{'form.lti_storecrs_'.$idx}) {
16102: $confhash{$itemid}{'storecrs'} = 1;
16103: }
1.391 raeburn 16104: if ($env{'form.lti_makecrs_'.$idx}) {
16105: $confhash{$itemid}{'makecrs'} = 1;
16106: }
16107: foreach my $ltirole (@lticourseroles) {
16108: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
16109: if (grep(/^\Q$possrole\E$/,@courseroles)) {
16110: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
16111: }
16112: }
16113: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
16114: my @selfenroll;
16115: foreach my $type (sort(@possenroll)) {
16116: if ($posslticrs{$type}) {
16117: push(@selfenroll,$type);
16118: }
16119: }
16120: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
16121: if ($env{'form.lti_crssec_'.$idx}) {
16122: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
16123: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
16124: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
16125: my $section = $env{'form.lti_customsection_'.$idx};
16126: $section =~ s/(`)/'/g;
16127: $section =~ s/^\s+|\s+$//g;
16128: if ($section ne '') {
16129: $confhash{$itemid}{'section'} = $section;
16130: }
16131: }
16132: }
16133: foreach my $field ('passback','roster') {
16134: if ($env{'form.lti_'.$field.'_'.$idx}) {
16135: $confhash{$itemid}{$field} = 1;
16136: }
16137: }
16138: if ($env{'form.lti_passback_'.$idx}) {
16139: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
16140: $confhash{$itemid}{'passbackformat'} = '1.0';
16141: } else {
16142: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 16143: }
16144: }
1.391 raeburn 16145: }
16146: unless (($idx eq 'add') || ($changes{$itemid})) {
16147: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 16148: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 16149: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 16150: $changes{$itemid} = 1;
16151: }
1.345 raeburn 16152: }
16153: unless ($changes{$itemid}) {
1.424 raeburn 16154: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
16155: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 16156: $changes{$itemid} = 1;
16157: }
16158: }
1.345 raeburn 16159: }
1.391 raeburn 16160: foreach my $field ('mapcrstype','selfenroll') {
16161: unless ($changes{$itemid}) {
1.424 raeburn 16162: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16163: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16164: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16165: $confhash{$itemid}{$field});
16166: if (@diffs) {
16167: $changes{$itemid} = 1;
16168: }
1.424 raeburn 16169: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16170: $changes{$itemid} = 1;
16171: }
16172: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16173: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 16174: $changes{$itemid} = 1;
16175: }
16176: }
1.391 raeburn 16177: }
16178: }
16179: unless ($changes{$itemid}) {
1.424 raeburn 16180: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 16181: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 16182: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
16183: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 16184: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 16185: $changes{$itemid} = 1;
16186: last;
16187: }
16188: }
1.391 raeburn 16189: unless ($changes{$itemid}) {
16190: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
16191: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 16192: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 16193: $changes{$itemid} = 1;
16194: last;
16195: }
16196: }
16197: }
1.424 raeburn 16198: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 16199: $changes{$itemid} = 1;
1.345 raeburn 16200: }
1.391 raeburn 16201: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16202: unless ($changes{$itemid}) {
16203: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16204: $changes{$itemid} = 1;
16205: }
16206: }
16207: }
16208: }
16209: }
16210: unless ($changes{$itemid}) {
16211: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 16212: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16213: $changes{$itemid} = 1;
1.320 raeburn 16214: }
1.391 raeburn 16215: }
16216: unless ($changes{$itemid}) {
1.447.2.2 raeburn 16217: foreach my $field ('makeuser','lcmenu','instdata') {
1.424 raeburn 16218: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16219: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16220: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16221: $confhash{$itemid}{$field});
16222: if (@diffs) {
16223: $changes{$itemid} = 1;
16224: }
1.424 raeburn 16225: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16226: $changes{$itemid} = 1;
16227: }
16228: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16229: if (@{$confhash{$itemid}{$field}} > 0) {
16230: $changes{$itemid} = 1;
16231: }
1.345 raeburn 16232: }
1.320 raeburn 16233: }
16234: }
16235: }
16236: }
16237: }
1.424 raeburn 16238: if ($is_home) {
16239: my $keyitem = 'form.lti_key_'.$idx;
16240: $env{$keyitem} =~ s/(`)/'/g;
16241: if ($env{$keyitem} ne '') {
16242: $ltienc{$itemid}{'key'} = $env{$keyitem};
16243: unless ($changes{$itemid}) {
16244: if ($currlti{'key'} ne $env{$keyitem}) {
16245: $changes{$itemid} = 1;
16246: }
16247: }
16248: }
16249: my $secretitem = 'form.lti_secret_'.$idx;
16250: $env{$secretitem} =~ s/(`)/'/g;
16251: if ($currlti{'usable'}) {
16252: if ($env{'form.lti_changesecret_'.$idx}) {
16253: if ($env{$secretitem} ne '') {
16254: if ($privnum && $cipher) {
16255: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16256: $confhash{$itemid}{'cipher'} = $privnum;
16257: } else {
16258: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16259: }
16260: $changes{$itemid} = 1;
16261: }
16262: } else {
16263: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16264: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16265: }
16266: if (ref($ltienc{$itemid}) eq 'HASH') {
16267: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16268: $confhash{$itemid}{'usable'} = 1;
16269: }
16270: }
16271: } elsif ($env{$secretitem} ne '') {
16272: if ($privnum && $cipher) {
16273: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16274: $confhash{$itemid}{'cipher'} = $privnum;
16275: } else {
16276: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16277: }
16278: if (ref($ltienc{$itemid}) eq 'HASH') {
16279: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16280: $confhash{$itemid}{'usable'} = 1;
16281: }
16282: }
16283: $changes{$itemid} = 1;
16284: }
16285: }
16286: unless ($changes{$itemid}) {
16287: foreach my $key (keys(%currlti)) {
16288: if (ref($currlti{$key}) eq 'HASH') {
16289: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16290: foreach my $innerkey (keys(%{$currlti{$key}})) {
16291: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16292: $changes{$itemid} = 1;
16293: last;
16294: }
16295: }
16296: } elsif (keys(%{$currlti{$key}}) > 0) {
16297: $changes{$itemid} = 1;
16298: }
16299: }
16300: last if ($changes{$itemid});
16301: }
16302: }
1.320 raeburn 16303: }
16304: if (@allpos > 0) {
16305: my $idx = 0;
16306: foreach my $itemid (@allpos) {
16307: if ($itemid ne '') {
16308: $confhash{$itemid}{'order'} = $idx;
16309: if (ref($domconfig{$action}) eq 'HASH') {
16310: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16311: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16312: $changes{$itemid} = 1;
16313: }
16314: }
16315: }
16316: $idx ++;
16317: }
16318: }
16319: }
1.424 raeburn 16320:
16321: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16322: return &mt('No changes made.');
16323: }
16324:
1.320 raeburn 16325: my %ltihash = (
1.405 raeburn 16326: $action => { %confhash }
16327: );
1.424 raeburn 16328: my %ltienchash;
16329:
16330: if ($is_home) {
16331: %ltienchash = (
16332: $action => { %ltienc }
16333: );
16334: }
1.405 raeburn 16335: if (keys(%secchanges)) {
16336: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16337: if ($secchanges{'linkprot'}) {
16338: if ($is_home) {
16339: $ltienchash{'linkprot'} = \%newltienc;
16340: }
16341: }
1.405 raeburn 16342: }
16343: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16344: if ($putresult eq 'ok') {
1.424 raeburn 16345: if (keys(%ltienchash)) {
16346: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16347: }
16348: $resulttext = &mt('Changes made:').'<ul>';
16349: if (keys(%secchanges) > 0) {
1.423 raeburn 16350: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16351: if (exists($secchanges{'linkprot'})) {
16352: $resulttext .= $linkprotoutput;
1.405 raeburn 16353: }
16354: }
1.320 raeburn 16355: if (keys(%changes) > 0) {
16356: my $cachetime = 24*60*60;
1.424 raeburn 16357: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16358: if (ref($lastactref) eq 'HASH') {
16359: $lastactref->{'lti'} = 1;
16360: }
16361: my %bynum;
16362: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16363: if (ref($confhash{$itemid}) eq 'HASH') {
16364: my $position = $confhash{$itemid}{'order'};
16365: $bynum{$position} = $itemid;
16366: }
1.320 raeburn 16367: }
16368: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16369: my $itemid = $bynum{$pos};
1.424 raeburn 16370: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16371: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16372: my $position = $pos + 1;
16373: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16374: foreach my $item ('version','lifetime') {
16375: if ($confhash{$itemid}{$item} ne '') {
16376: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16377: }
16378: }
1.424 raeburn 16379: if ($ltienc{$itemid}{'key'} ne '') {
16380: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16381: }
1.424 raeburn 16382: if ($ltienc{$itemid}{'secret'} ne '') {
16383: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16384: }
1.345 raeburn 16385: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16386: if ($confhash{$itemid}{'callback'}) {
16387: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16388: } else {
1.392 raeburn 16389: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16390: }
1.345 raeburn 16391: if ($confhash{$itemid}{'mapuser'}) {
16392: my $shownmapuser;
16393: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16394: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16395: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16396: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16397: } else {
16398: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16399: }
1.345 raeburn 16400: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16401: }
1.345 raeburn 16402: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16403: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16404: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16405: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16406: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16407: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16408: } else {
16409: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16410: $confhash{$itemid}{'lcauth'});
16411: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16412: $resulttext .= '; '.&mt('a randomly generated password will be created');
16413: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16414: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16415: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16416: }
16417: } else {
16418: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16419: }
16420: }
16421: $resulttext .= '</li>';
16422: } else {
16423: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16424: }
1.320 raeburn 16425: }
1.345 raeburn 16426: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16427: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16428: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16429: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16430: } else {
1.447.2.2 raeburn 16431: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user').'</li>';
1.325 raeburn 16432: }
1.447.2.2 raeburn 16433: } else {
16434: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user').'</li>';
1.320 raeburn 16435: }
1.391 raeburn 16436: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16437: $resulttext .= '<li>'.$lt{$item}.': ';
16438: if ($confhash{$itemid}{$item}) {
16439: $resulttext .= &mt('Yes');
16440: } else {
16441: $resulttext .= &mt('No');
1.337 raeburn 16442: }
1.345 raeburn 16443: $resulttext .= '</li>';
1.320 raeburn 16444: }
1.345 raeburn 16445: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16446: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16447: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16448: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16449: } else {
16450: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16451: }
16452: }
16453: if ($confhash{$itemid}{'crsinc'}) {
16454: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16455: my $rolemaps;
16456: foreach my $role (@ltiroles) {
16457: if ($confhash{$itemid}{'maproles'}{$role}) {
16458: $rolemaps .= (' 'x2).$role.'='.
16459: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16460: 'Course').',';
16461: }
16462: }
16463: if ($rolemaps) {
16464: $rolemaps =~ s/,$//;
16465: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16466: }
16467: }
16468: if ($confhash{$itemid}{'mapcrs'}) {
16469: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16470: }
16471: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16472: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16473: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16474: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16475: '</li>';
16476: } else {
16477: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16478: }
16479: }
1.392 raeburn 16480: if ($confhash{$itemid}{'storecrs'}) {
16481: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16482: }
1.391 raeburn 16483: if ($confhash{$itemid}{'makecrs'}) {
16484: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16485: } else {
16486: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16487: }
16488: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16489: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16490: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16491: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16492: '</li>';
16493: } else {
16494: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16495: }
16496: }
16497: if ($confhash{$itemid}{'section'}) {
16498: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16499: $resulttext .= '<li>'.&mt('User section from standard field:').
16500: ' (course_section_sourcedid)'.'</li>';
16501: } else {
16502: $resulttext .= '<li>'.&mt('User section from:').' '.
16503: $confhash{$itemid}{'section'}.'</li>';
16504: }
1.345 raeburn 16505: } else {
1.391 raeburn 16506: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16507: }
16508: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16509: $resulttext .= '<li>'.$lt{$item}.': ';
16510: if ($confhash{$itemid}{$item}) {
16511: $resulttext .= &mt('Yes');
16512: if ($item eq 'passback') {
16513: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16514: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16515: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16516: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16517: }
16518: }
16519: } else {
16520: $resulttext .= &mt('No');
16521: }
16522: $resulttext .= '</li>';
16523: }
16524: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16525: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16526: $resulttext .= '<li>'.&mt('Menu items:').' '.
16527: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16528: } else {
16529: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16530: }
1.345 raeburn 16531: }
1.326 raeburn 16532: }
16533: }
1.320 raeburn 16534: $resulttext .= '</ul></li>';
16535: }
16536: }
1.424 raeburn 16537: if (keys(%deletions)) {
16538: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16539: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16540: }
16541: }
1.320 raeburn 16542: }
1.405 raeburn 16543: $resulttext .= '</ul>';
1.424 raeburn 16544: if (ref($lastactref) eq 'HASH') {
1.434 raeburn 16545: if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
16546: &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 16547: $lastactref->{'domdefaults'} = 1;
16548: }
16549: }
1.320 raeburn 16550: } else {
16551: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16552: }
16553: if ($errors) {
16554: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16555: $errors.'</ul>';
16556: }
16557: return $resulttext;
16558: }
16559:
1.424 raeburn 16560: sub get_priv_creds {
16561: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16562: my ($needenc,$cipher,$privnum);
16563: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16564: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16565: $needenc = $encrypt->{'consumers'}
16566: } else {
16567: $needenc = $domdefs{'ltienc_consumers'};
16568: }
16569: if ($needenc) {
16570: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16571: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16572: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16573: my $privkey = $privhash{'key'};
16574: $privnum = $privhash{'version'};
16575: if (($privnum) && ($privkey ne '')) {
16576: $cipher = Crypt::CBC->new({'key' => $privkey,
16577: 'cipher' => 'DES'});
16578: }
16579: }
16580: }
16581: return ($cipher,$privnum);
16582: }
16583:
1.320 raeburn 16584: sub get_lti_id {
1.434 raeburn 16585: my ($domain,$consumer,$dbname) = @_;
16586: unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
16587: return ('','invalid db');
16588: }
16589: # get lock on db
1.320 raeburn 16590: my $lockhash = {
16591: lock => $env{'user.name'}.
16592: ':'.$env{'user.domain'},
16593: };
16594: my $tries = 0;
1.434 raeburn 16595: my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16596: my ($id,$error);
16597:
16598: while (($gotlock ne 'ok') && ($tries<10)) {
16599: $tries ++;
16600: sleep (0.1);
1.434 raeburn 16601: $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16602: }
16603: if ($gotlock eq 'ok') {
1.434 raeburn 16604: my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1.320 raeburn 16605: if ($currids{'lock'}) {
16606: delete($currids{'lock'});
16607: if (keys(%currids)) {
16608: my @curr = sort { $a <=> $b } keys(%currids);
16609: if ($curr[-1] =~ /^\d+$/) {
16610: $id = 1 + $curr[-1];
16611: }
16612: } else {
16613: $id = 1;
16614: }
16615: if ($id) {
1.434 raeburn 16616: unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1.320 raeburn 16617: $error = 'nostore';
16618: }
16619: } else {
16620: $error = 'nonumber';
16621: }
16622: }
1.434 raeburn 16623: my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1.320 raeburn 16624: } else {
16625: $error = 'nolock';
16626: }
16627: return ($id,$error);
16628: }
16629:
1.3 raeburn 16630: sub modify_autoenroll {
1.205 raeburn 16631: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16632: my ($resulttext,%changes);
16633: my %currautoenroll;
16634: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16635: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16636: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16637: }
16638: }
16639: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16640: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16641: sender => 'Sender for notification messages',
1.274 raeburn 16642: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16643: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16644: my @offon = ('off','on');
1.17 raeburn 16645: my $sender_uname = $env{'form.sender_uname'};
16646: my $sender_domain = $env{'form.sender_domain'};
16647: if ($sender_domain eq '') {
16648: $sender_uname = '';
16649: } elsif ($sender_uname eq '') {
16650: $sender_domain = '';
16651: }
1.129 raeburn 16652: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16653: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16654: $autofailsafe =~ s{^\s+|\s+$}{}g;
16655: if ($autofailsafe =~ /\D/) {
16656: undef($autofailsafe);
16657: }
1.274 raeburn 16658: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16659: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16660: $failsafe = 'off';
1.400 raeburn 16661: undef($autofailsafe);
1.274 raeburn 16662: }
1.1 raeburn 16663: my %autoenrollhash = (
1.129 raeburn 16664: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16665: 'sender_uname' => $sender_uname,
16666: 'sender_domain' => $sender_domain,
16667: 'co-owners' => $coowners,
1.399 raeburn 16668: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16669: 'failsafe' => $failsafe,
1.1 raeburn 16670: }
16671: );
1.4 raeburn 16672: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16673: $dom);
1.1 raeburn 16674: if ($putresult eq 'ok') {
16675: if (exists($currautoenroll{'run'})) {
16676: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16677: $changes{'run'} = 1;
16678: }
16679: } elsif ($autorun) {
16680: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16681: $changes{'run'} = 1;
1.1 raeburn 16682: }
16683: }
1.17 raeburn 16684: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16685: $changes{'sender'} = 1;
16686: }
1.17 raeburn 16687: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16688: $changes{'sender'} = 1;
16689: }
1.129 raeburn 16690: if ($currautoenroll{'co-owners'} ne '') {
16691: if ($currautoenroll{'co-owners'} ne $coowners) {
16692: $changes{'coowners'} = 1;
16693: }
16694: } elsif ($coowners) {
16695: $changes{'coowners'} = 1;
1.274 raeburn 16696: }
1.399 raeburn 16697: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16698: $changes{'autofailsafe'} = 1;
16699: }
1.399 raeburn 16700: if ($currautoenroll{'failsafe'} ne $failsafe) {
16701: $changes{'failsafe'} = 1;
16702: }
1.1 raeburn 16703: if (keys(%changes) > 0) {
16704: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16705: if ($changes{'run'}) {
1.1 raeburn 16706: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16707: }
16708: if ($changes{'sender'}) {
1.17 raeburn 16709: if ($sender_uname eq '' || $sender_domain eq '') {
16710: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16711: } else {
16712: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16713: }
1.1 raeburn 16714: }
1.129 raeburn 16715: if ($changes{'coowners'}) {
16716: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16717: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16718: if (ref($lastactref) eq 'HASH') {
16719: $lastactref->{'domainconfig'} = 1;
16720: }
1.129 raeburn 16721: }
1.274 raeburn 16722: if ($changes{'autofailsafe'}) {
1.399 raeburn 16723: if ($autofailsafe ne '') {
16724: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16725: } else {
1.399 raeburn 16726: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16727: }
1.399 raeburn 16728: }
16729: if ($changes{'failsafe'}) {
16730: if ($failsafe eq 'off') {
16731: unless ($changes{'autofailsafe'}) {
16732: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16733: }
16734: } elsif ($failsafe eq 'zero') {
16735: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16736: } else {
16737: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16738: }
16739: }
16740: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16741: &Apache::lonnet::get_domain_defaults($dom,1);
16742: if (ref($lastactref) eq 'HASH') {
16743: $lastactref->{'domdefaults'} = 1;
16744: }
16745: }
1.1 raeburn 16746: $resulttext .= '</ul>';
16747: } else {
16748: $resulttext = &mt('No changes made to auto-enrollment settings');
16749: }
16750: } else {
1.11 albertel 16751: $resulttext = '<span class="LC_error">'.
16752: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16753: }
1.3 raeburn 16754: return $resulttext;
1.1 raeburn 16755: }
16756:
16757: sub modify_autoupdate {
1.3 raeburn 16758: my ($dom,%domconfig) = @_;
1.1 raeburn 16759: my ($resulttext,%currautoupdate,%fields,%changes);
16760: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16761: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16762: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16763: }
16764: }
16765: my @offon = ('off','on');
16766: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16767: run => 'Auto-update:',
16768: classlists => 'Updates to user information in classlists?',
16769: unexpired => 'Skip updates for users without active or future roles?',
16770: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16771: );
1.44 raeburn 16772: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16773: my %fieldtitles = &Apache::lonlocal::texthash (
16774: id => 'Student/Employee ID',
1.20 raeburn 16775: permanentemail => 'E-mail address',
1.1 raeburn 16776: lastname => 'Last Name',
16777: firstname => 'First Name',
16778: middlename => 'Middle Name',
1.132 raeburn 16779: generation => 'Generation',
1.1 raeburn 16780: );
1.142 raeburn 16781: $othertitle = &mt('All users');
1.1 raeburn 16782: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16783: $othertitle = &mt('Other users');
1.1 raeburn 16784: }
16785: foreach my $key (keys(%env)) {
16786: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16787: my ($usertype,$item) = ($1,$2);
16788: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16789: if ($usertype eq 'default') {
16790: push(@{$fields{$1}},$2);
16791: } elsif (ref($types) eq 'ARRAY') {
16792: if (grep(/^\Q$usertype\E$/,@{$types})) {
16793: push(@{$fields{$1}},$2);
16794: }
16795: }
16796: }
1.1 raeburn 16797: }
16798: }
1.131 raeburn 16799: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16800: @lockablenames = sort(@lockablenames);
16801: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16802: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16803: if (@changed) {
16804: $changes{'lockablenames'} = 1;
16805: }
16806: } else {
16807: if (@lockablenames) {
16808: $changes{'lockablenames'} = 1;
16809: }
16810: }
1.1 raeburn 16811: my %updatehash = (
16812: autoupdate => { run => $env{'form.autoupdate_run'},
16813: classlists => $env{'form.classlists'},
1.385 raeburn 16814: unexpired => $env{'form.unexpired'},
1.1 raeburn 16815: fields => {%fields},
1.131 raeburn 16816: lockablenames => \@lockablenames,
1.1 raeburn 16817: }
16818: );
1.385 raeburn 16819: my $lastactivedays;
16820: if ($env{'form.lastactive'}) {
16821: $lastactivedays = $env{'form.lastactivedays'};
16822: $lastactivedays =~ s/^\s+|\s+$//g;
16823: unless ($lastactivedays =~ /^\d+$/) {
16824: undef($lastactivedays);
16825: $env{'form.lastactive'} = 0;
16826: }
16827: }
16828: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16829: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16830: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16831: if (exists($updatehash{autoupdate}{$key})) {
16832: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16833: $changes{$key} = 1;
16834: }
16835: }
16836: } elsif ($key eq 'fields') {
16837: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16838: foreach my $item (@{$types},'default') {
1.1 raeburn 16839: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16840: my $change = 0;
16841: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16842: if (!exists($fields{$item})) {
16843: $change = 1;
1.132 raeburn 16844: last;
1.1 raeburn 16845: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16846: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16847: $change = 1;
1.132 raeburn 16848: last;
1.1 raeburn 16849: }
16850: }
16851: }
16852: if ($change) {
16853: push(@{$changes{$key}},$item);
16854: }
1.26 raeburn 16855: }
1.1 raeburn 16856: }
16857: }
1.131 raeburn 16858: } elsif ($key eq 'lockablenames') {
16859: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16860: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16861: if (@changed) {
16862: $changes{'lockablenames'} = 1;
16863: }
16864: } else {
16865: if (@lockablenames) {
16866: $changes{'lockablenames'} = 1;
16867: }
16868: }
16869: }
16870: }
16871: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16872: if (@lockablenames) {
16873: $changes{'lockablenames'} = 1;
1.1 raeburn 16874: }
16875: }
1.385 raeburn 16876: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16877: if ($updatehash{'autoupdate'}{'unexpired'}) {
16878: $changes{'unexpired'} = 1;
16879: }
16880: }
16881: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16882: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16883: $changes{'lastactive'} = 1;
16884: }
16885: }
1.26 raeburn 16886: foreach my $item (@{$types},'default') {
16887: if (defined($fields{$item})) {
16888: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16889: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16890: my $change = 0;
16891: if (ref($fields{$item}) eq 'ARRAY') {
16892: foreach my $type (@{$fields{$item}}) {
16893: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16894: $change = 1;
16895: last;
16896: }
16897: }
16898: }
16899: if ($change) {
16900: push(@{$changes{'fields'}},$item);
16901: }
16902: } else {
1.26 raeburn 16903: push(@{$changes{'fields'}},$item);
16904: }
16905: } else {
16906: push(@{$changes{'fields'}},$item);
1.1 raeburn 16907: }
16908: }
16909: }
16910: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16911: $dom);
16912: if ($putresult eq 'ok') {
16913: if (keys(%changes) > 0) {
16914: $resulttext = &mt('Changes made:').'<ul>';
16915: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16916: if ($key eq 'lockablenames') {
16917: $resulttext .= '<li>';
16918: if (@lockablenames) {
16919: $usertypes->{'default'} = $othertitle;
16920: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16921: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16922: } else {
16923: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16924: }
16925: $resulttext .= '</li>';
16926: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16927: foreach my $item (@{$changes{$key}}) {
16928: my @newvalues;
16929: foreach my $type (@{$fields{$item}}) {
16930: push(@newvalues,$fieldtitles{$type});
16931: }
1.3 raeburn 16932: my $newvaluestr;
16933: if (@newvalues > 0) {
16934: $newvaluestr = join(', ',@newvalues);
16935: } else {
16936: $newvaluestr = &mt('none');
1.6 raeburn 16937: }
1.1 raeburn 16938: if ($item eq 'default') {
1.26 raeburn 16939: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16940: } else {
1.26 raeburn 16941: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16942: }
16943: }
16944: } else {
16945: my $newvalue;
16946: if ($key eq 'run') {
16947: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16948: } elsif ($key eq 'lastactive') {
16949: $newvalue = $offon[$env{'form.lastactive'}];
16950: unless ($lastactivedays eq '') {
16951: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16952: }
1.1 raeburn 16953: } else {
16954: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16955: }
1.1 raeburn 16956: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16957: }
16958: }
16959: $resulttext .= '</ul>';
16960: } else {
1.3 raeburn 16961: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16962: }
16963: } else {
1.11 albertel 16964: $resulttext = '<span class="LC_error">'.
16965: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16966: }
1.3 raeburn 16967: return $resulttext;
1.1 raeburn 16968: }
16969:
1.125 raeburn 16970: sub modify_autocreate {
16971: my ($dom,%domconfig) = @_;
16972: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
16973: if (ref($domconfig{'autocreate'}) eq 'HASH') {
16974: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
16975: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
16976: }
16977: }
16978: my %title= ( xml => 'Auto-creation of courses in XML course description files',
16979: req => 'Auto-creation of validated requests for official courses',
16980: xmldc => 'Identity of course creator of courses from XML files',
16981: );
16982: my @types = ('xml','req');
16983: foreach my $item (@types) {
16984: $newvals{$item} = $env{'form.autocreate_'.$item};
16985: $newvals{$item} =~ s/\D//g;
16986: $newvals{$item} = 0 if ($newvals{$item} eq '');
16987: }
16988: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 16989: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 16990: unless (exists($domcoords{$newvals{'xmldc'}})) {
16991: $newvals{'xmldc'} = '';
16992: }
16993: %autocreatehash = (
16994: autocreate => { xml => $newvals{'xml'},
16995: req => $newvals{'req'},
16996: }
16997: );
16998: if ($newvals{'xmldc'} ne '') {
16999: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
17000: }
17001: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
17002: $dom);
17003: if ($putresult eq 'ok') {
17004: my @items = @types;
17005: if ($newvals{'xml'}) {
17006: push(@items,'xmldc');
17007: }
17008: foreach my $item (@items) {
17009: if (exists($currautocreate{$item})) {
17010: if ($currautocreate{$item} ne $newvals{$item}) {
17011: $changes{$item} = 1;
17012: }
17013: } elsif ($newvals{$item}) {
17014: $changes{$item} = 1;
17015: }
17016: }
17017: if (keys(%changes) > 0) {
17018: my @offon = ('off','on');
17019: $resulttext = &mt('Changes made:').'<ul>';
17020: foreach my $item (@types) {
17021: if ($changes{$item}) {
17022: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 17023: $resulttext .= '<li>'.
17024: &mt("$title{$item} set to [_1]$newtxt [_2]",
17025: '<b>','</b>').
17026: '</li>';
1.125 raeburn 17027: }
17028: }
17029: if ($changes{'xmldc'}) {
17030: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
17031: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 17032: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 17033: }
17034: $resulttext .= '</ul>';
17035: } else {
17036: $resulttext = &mt('No changes made to auto-creation settings');
17037: }
17038: } else {
17039: $resulttext = '<span class="LC_error">'.
17040: &mt('An error occurred: [_1]',$putresult).'</span>';
17041: }
17042: return $resulttext;
17043: }
17044:
1.23 raeburn 17045: sub modify_directorysrch {
1.295 raeburn 17046: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 17047: my ($resulttext,%changes);
17048: my %currdirsrch;
17049: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
17050: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
17051: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
17052: }
17053: }
1.277 raeburn 17054: my %title = ( available => 'Institutional directory search available',
17055: localonly => 'Other domains can search institution',
17056: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 17057: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 17058: searchby => 'Search types',
17059: searchtypes => 'Search latitude');
17060: my @offon = ('off','on');
1.24 raeburn 17061: my @otherdoms = ('Yes','No');
1.23 raeburn 17062:
1.25 raeburn 17063: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 17064: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
17065: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
17066:
1.44 raeburn 17067: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 17068: if (keys(%{$usertypes}) == 0) {
17069: @cansearch = ('default');
17070: } else {
17071: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
17072: foreach my $type (@{$currdirsrch{'cansearch'}}) {
17073: if (!grep(/^\Q$type\E$/,@cansearch)) {
17074: push(@{$changes{'cansearch'}},$type);
17075: }
1.23 raeburn 17076: }
1.26 raeburn 17077: foreach my $type (@cansearch) {
17078: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
17079: push(@{$changes{'cansearch'}},$type);
17080: }
1.23 raeburn 17081: }
1.26 raeburn 17082: } else {
17083: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 17084: }
17085: }
17086:
17087: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
17088: foreach my $by (@{$currdirsrch{'searchby'}}) {
17089: if (!grep(/^\Q$by\E$/,@searchby)) {
17090: push(@{$changes{'searchby'}},$by);
17091: }
17092: }
17093: foreach my $by (@searchby) {
17094: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
17095: push(@{$changes{'searchby'}},$by);
17096: }
17097: }
17098: } else {
17099: push(@{$changes{'searchby'}},@searchby);
17100: }
1.25 raeburn 17101:
17102: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
17103: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
17104: if (!grep(/^\Q$type\E$/,@searchtypes)) {
17105: push(@{$changes{'searchtypes'}},$type);
17106: }
17107: }
17108: foreach my $type (@searchtypes) {
17109: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
17110: push(@{$changes{'searchtypes'}},$type);
17111: }
17112: }
17113: } else {
17114: if (exists($currdirsrch{'searchtypes'})) {
17115: foreach my $type (@searchtypes) {
17116: if ($type ne $currdirsrch{'searchtypes'}) {
17117: push(@{$changes{'searchtypes'}},$type);
17118: }
17119: }
17120: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
17121: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
17122: }
17123: } else {
17124: push(@{$changes{'searchtypes'}},@searchtypes);
17125: }
17126: }
17127:
1.23 raeburn 17128: my %dirsrch_hash = (
17129: directorysrch => { available => $env{'form.dirsrch_available'},
17130: cansearch => \@cansearch,
1.277 raeburn 17131: localonly => $env{'form.dirsrch_instlocalonly'},
17132: lclocalonly => $env{'form.dirsrch_domlocalonly'},
17133: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 17134: searchby => \@searchby,
1.25 raeburn 17135: searchtypes => \@searchtypes,
1.23 raeburn 17136: }
17137: );
17138: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
17139: $dom);
17140: if ($putresult eq 'ok') {
17141: if (exists($currdirsrch{'available'})) {
17142: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
17143: $changes{'available'} = 1;
17144: }
17145: } else {
17146: if ($env{'form.dirsrch_available'} eq '1') {
17147: $changes{'available'} = 1;
17148: }
17149: }
1.277 raeburn 17150: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 17151: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
17152: $changes{'lcavailable'} = 1;
17153: }
1.277 raeburn 17154: } else {
17155: if ($env{'form.dirsrch_lcavailable'} eq '1') {
17156: $changes{'lcavailable'} = 1;
17157: }
17158: }
1.24 raeburn 17159: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 17160: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
17161: $changes{'localonly'} = 1;
17162: }
1.24 raeburn 17163: } else {
1.277 raeburn 17164: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 17165: $changes{'localonly'} = 1;
17166: }
17167: }
1.277 raeburn 17168: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 17169: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
17170: $changes{'lclocalonly'} = 1;
17171: }
1.277 raeburn 17172: } else {
17173: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
17174: $changes{'lclocalonly'} = 1;
17175: }
17176: }
1.23 raeburn 17177: if (keys(%changes) > 0) {
17178: $resulttext = &mt('Changes made:').'<ul>';
17179: if ($changes{'available'}) {
17180: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
17181: }
1.277 raeburn 17182: if ($changes{'lcavailable'}) {
17183: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
17184: }
1.24 raeburn 17185: if ($changes{'localonly'}) {
1.277 raeburn 17186: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 17187: }
1.277 raeburn 17188: if ($changes{'lclocalonly'}) {
17189: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 17190: }
1.23 raeburn 17191: if (ref($changes{'cansearch'}) eq 'ARRAY') {
17192: my $chgtext;
1.26 raeburn 17193: if (ref($usertypes) eq 'HASH') {
17194: if (keys(%{$usertypes}) > 0) {
17195: foreach my $type (@{$types}) {
17196: if (grep(/^\Q$type\E$/,@cansearch)) {
17197: $chgtext .= $usertypes->{$type}.'; ';
17198: }
17199: }
17200: if (grep(/^default$/,@cansearch)) {
17201: $chgtext .= $othertitle;
17202: } else {
17203: $chgtext =~ s/\; $//;
17204: }
1.210 raeburn 17205: $resulttext .=
1.178 raeburn 17206: '<li>'.
17207: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17208: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17209: '</li>';
1.23 raeburn 17210: }
17211: }
17212: }
17213: if (ref($changes{'searchby'}) eq 'ARRAY') {
17214: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17215: my $chgtext;
17216: foreach my $type (@{$titleorder}) {
17217: if (grep(/^\Q$type\E$/,@searchby)) {
17218: if (defined($searchtitles->{$type})) {
17219: $chgtext .= $searchtitles->{$type}.'; ';
17220: }
17221: }
17222: }
17223: $chgtext =~ s/\; $//;
17224: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17225: }
1.25 raeburn 17226: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17227: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17228: my $chgtext;
17229: foreach my $type (@{$srchtypeorder}) {
17230: if (grep(/^\Q$type\E$/,@searchtypes)) {
17231: if (defined($srchtypes_desc->{$type})) {
17232: $chgtext .= $srchtypes_desc->{$type}.'; ';
17233: }
17234: }
17235: }
17236: $chgtext =~ s/\; $//;
1.178 raeburn 17237: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17238: }
17239: $resulttext .= '</ul>';
1.295 raeburn 17240: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17241: if (ref($lastactref) eq 'HASH') {
17242: $lastactref->{'directorysrch'} = 1;
17243: }
1.23 raeburn 17244: } else {
1.277 raeburn 17245: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17246: }
17247: } else {
17248: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17249: &mt('An error occurred: [_1]',$putresult).'</span>';
17250: }
17251: return $resulttext;
17252: }
17253:
1.28 raeburn 17254: sub modify_contacts {
1.205 raeburn 17255: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17256: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17257: if (ref($domconfig{'contacts'}) eq 'HASH') {
17258: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17259: $currsetting{$key} = $domconfig{'contacts'}{$key};
17260: }
17261: }
1.286 raeburn 17262: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17263: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17264: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17265: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17266: my @toggles = ('reporterrors','reportupdates','reportstatus');
17267: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17268: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17269: foreach my $type (@mailings) {
17270: @{$newsetting{$type}} =
17271: &Apache::loncommon::get_env_multiple('form.'.$type);
17272: foreach my $item (@contacts) {
17273: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17274: $contacts_hash{contacts}{$type}{$item} = 1;
17275: } else {
17276: $contacts_hash{contacts}{$type}{$item} = 0;
17277: }
1.289 raeburn 17278: }
1.28 raeburn 17279: $others{$type} = $env{'form.'.$type.'_others'};
17280: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17281: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17282: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17283: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17284: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17285: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17286: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17287: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17288: }
1.134 raeburn 17289: }
1.28 raeburn 17290: }
17291: foreach my $item (@contacts) {
17292: $to{$item} = $env{'form.'.$item};
17293: $contacts_hash{'contacts'}{$item} = $to{$item};
17294: }
1.203 raeburn 17295: foreach my $item (@toggles) {
17296: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17297: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17298: }
17299: }
1.340 raeburn 17300: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17301: foreach my $item (@lonstatus) {
17302: if ($item eq 'excluded') {
17303: my (%serverhomes,@excluded);
17304: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17305: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17306: if (@possexcluded) {
17307: foreach my $id (sort(@possexcluded)) {
17308: if ($serverhomes{$id}) {
17309: push(@excluded,$id);
17310: }
17311: }
17312: }
17313: if (@excluded) {
17314: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17315: }
17316: } elsif ($item eq 'weights') {
1.377 raeburn 17317: foreach my $type ('E','W','N','U') {
1.340 raeburn 17318: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17319: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17320: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17321: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17322: $env{'form.error'.$item.'_'.$type};
17323: }
17324: }
17325: }
17326: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17327: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17328: if ($env{'form.error'.$item} =~ /^\d+$/) {
17329: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17330: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17331: }
17332: }
17333: }
17334: }
1.286 raeburn 17335: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17336: foreach my $field (@{$fields}) {
17337: if (ref($possoptions->{$field}) eq 'ARRAY') {
17338: my $value = $env{'form.helpform_'.$field};
17339: $value =~ s/^\s+|\s+$//g;
17340: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17341: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17342: if ($field eq 'screenshot') {
17343: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17344: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17345: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17346: }
17347: }
17348: }
17349: }
17350: }
17351: }
1.315 raeburn 17352: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17353: my (@statuses,%usertypeshash,@overrides);
17354: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17355: @statuses = @{$types};
17356: if (ref($usertypes) eq 'HASH') {
17357: %usertypeshash = %{$usertypes};
17358: }
17359: }
17360: if (@statuses) {
17361: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17362: foreach my $type (@possoverrides) {
17363: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17364: push(@overrides,$type);
17365: }
17366: }
17367: if (@overrides) {
17368: foreach my $type (@overrides) {
17369: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17370: foreach my $item (@contacts) {
17371: if (grep(/^\Q$item\E$/,@standard)) {
17372: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17373: $newsetting{'override_'.$type}{$item} = 1;
17374: } else {
17375: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17376: $newsetting{'override_'.$type}{$item} = 0;
17377: }
17378: }
17379: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17380: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17381: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17382: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17383: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17384: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17385: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17386: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17387: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17388: }
1.425 raeburn 17389: }
1.315 raeburn 17390: }
17391: }
1.28 raeburn 17392: if (keys(%currsetting) > 0) {
17393: foreach my $item (@contacts) {
17394: if ($to{$item} ne $currsetting{$item}) {
17395: $changes{$item} = 1;
17396: }
17397: }
17398: foreach my $type (@mailings) {
17399: foreach my $item (@contacts) {
17400: if (ref($currsetting{$type}) eq 'HASH') {
17401: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17402: push(@{$changes{$type}},$item);
17403: }
17404: } else {
17405: push(@{$changes{$type}},@{$newsetting{$type}});
17406: }
17407: }
17408: if ($others{$type} ne $currsetting{$type}{'others'}) {
17409: push(@{$changes{$type}},'others');
17410: }
1.289 raeburn 17411: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17412: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17413: push(@{$changes{$type}},'bcc');
17414: }
1.286 raeburn 17415: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17416: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17417: push(@{$changes{$type}},'include');
17418: }
17419: }
17420: }
17421: if (ref($fields) eq 'ARRAY') {
17422: if (ref($currsetting{'helpform'}) eq 'HASH') {
17423: foreach my $field (@{$fields}) {
17424: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17425: push(@{$changes{'helpform'}},$field);
17426: }
17427: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17428: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17429: push(@{$changes{'helpform'}},'maxsize');
17430: }
17431: }
17432: }
17433: } else {
17434: foreach my $field (@{$fields}) {
17435: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17436: push(@{$changes{'helpform'}},$field);
17437: }
17438: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17439: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17440: push(@{$changes{'helpform'}},'maxsize');
17441: }
17442: }
17443: }
1.134 raeburn 17444: }
1.28 raeburn 17445: }
1.315 raeburn 17446: if (@statuses) {
1.425 raeburn 17447: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17448: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17449: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17450: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17451: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17452: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17453: push(@{$changes{'overrides'}},$key);
17454: last;
17455: }
17456: }
17457: } else {
17458: push(@{$changes{'overrides'}},$key);
17459: }
17460: }
17461: }
17462: foreach my $key (@overrides) {
17463: unless (exists($currsetting{'overrides'}{$key})) {
17464: push(@{$changes{'overrides'}},$key);
17465: }
17466: }
17467: } else {
17468: foreach my $key (@overrides) {
1.425 raeburn 17469: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17470: }
17471: }
17472: }
1.340 raeburn 17473: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17474: foreach my $key ('excluded','weights','threshold','sysmail') {
17475: if ($key eq 'excluded') {
17476: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17477: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17478: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17479: (@{$currsetting{'lonstatus'}{$key}})) {
17480: my @diffs =
17481: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17482: $currsetting{'lonstatus'}{$key});
17483: if (@diffs) {
17484: push(@{$changes{'lonstatus'}},$key);
17485: }
17486: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17487: push(@{$changes{'lonstatus'}},$key);
17488: }
17489: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17490: (@{$currsetting{'lonstatus'}{$key}})) {
17491: push(@{$changes{'lonstatus'}},$key);
17492: }
17493: } elsif ($key eq 'weights') {
17494: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17495: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17496: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17497: foreach my $type ('E','W','N','U') {
1.340 raeburn 17498: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17499: $currsetting{'lonstatus'}{$key}{$type}) {
17500: push(@{$changes{'lonstatus'}},$key);
17501: last;
17502: }
17503: }
17504: } else {
1.341 raeburn 17505: foreach my $type ('E','W','N','U') {
1.340 raeburn 17506: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17507: push(@{$changes{'lonstatus'}},$key);
17508: last;
17509: }
17510: }
17511: }
17512: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17513: foreach my $type ('E','W','N','U') {
1.340 raeburn 17514: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17515: push(@{$changes{'lonstatus'}},$key);
17516: last;
17517: }
17518: }
17519: }
17520: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17521: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17522: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17523: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17524: push(@{$changes{'lonstatus'}},$key);
17525: }
17526: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17527: push(@{$changes{'lonstatus'}},$key);
17528: }
17529: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17530: push(@{$changes{'lonstatus'}},$key);
17531: }
17532: }
17533: }
17534: } else {
17535: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17536: foreach my $key ('excluded','weights','threshold','sysmail') {
17537: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17538: push(@{$changes{'lonstatus'}},$key);
17539: }
17540: }
17541: }
17542: }
1.28 raeburn 17543: } else {
17544: my %default;
17545: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17546: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17547: $default{'errormail'} = 'adminemail';
17548: $default{'packagesmail'} = 'adminemail';
17549: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17550: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17551: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17552: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17553: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17554: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17555: foreach my $item (@contacts) {
17556: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17557: $changes{$item} = 1;
1.203 raeburn 17558: }
1.28 raeburn 17559: }
17560: foreach my $type (@mailings) {
17561: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17562: push(@{$changes{$type}},@{$newsetting{$type}});
17563: }
17564: if ($others{$type} ne '') {
17565: push(@{$changes{$type}},'others');
1.134 raeburn 17566: }
1.286 raeburn 17567: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17568: if ($bcc{$type} ne '') {
17569: push(@{$changes{$type}},'bcc');
17570: }
1.286 raeburn 17571: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17572: push(@{$changes{$type}},'include');
17573: }
1.134 raeburn 17574: }
1.28 raeburn 17575: }
1.286 raeburn 17576: if (ref($fields) eq 'ARRAY') {
17577: foreach my $field (@{$fields}) {
17578: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17579: push(@{$changes{'helpform'}},$field);
17580: }
17581: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17582: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17583: push(@{$changes{'helpform'}},'maxsize');
17584: }
17585: }
17586: }
1.289 raeburn 17587: }
1.340 raeburn 17588: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17589: foreach my $key ('excluded','weights','threshold','sysmail') {
17590: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17591: push(@{$changes{'lonstatus'}},$key);
17592: }
17593: }
17594: }
1.28 raeburn 17595: }
1.203 raeburn 17596: foreach my $item (@toggles) {
17597: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17598: $changes{$item} = 1;
17599: } elsif ((!$env{'form.'.$item}) &&
17600: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17601: $changes{$item} = 1;
17602: }
17603: }
1.28 raeburn 17604: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17605: $dom);
17606: if ($putresult eq 'ok') {
17607: if (keys(%changes) > 0) {
1.205 raeburn 17608: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17609: if (ref($lastactref) eq 'HASH') {
17610: $lastactref->{'domainconfig'} = 1;
17611: }
1.28 raeburn 17612: my ($titles,$short_titles) = &contact_titles();
17613: $resulttext = &mt('Changes made:').'<ul>';
17614: foreach my $item (@contacts) {
17615: if ($changes{$item}) {
17616: $resulttext .= '<li>'.$titles->{$item}.
17617: &mt(' set to: ').
17618: '<span class="LC_cusr_emph">'.
17619: $to{$item}.'</span></li>';
17620: }
17621: }
17622: foreach my $type (@mailings) {
17623: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17624: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17625: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17626: } else {
17627: $resulttext .= '<li>'.$titles->{$type}.': ';
17628: }
1.28 raeburn 17629: my @text;
17630: foreach my $item (@{$newsetting{$type}}) {
17631: push(@text,$short_titles->{$item});
17632: }
17633: if ($others{$type} ne '') {
17634: push(@text,$others{$type});
17635: }
1.286 raeburn 17636: if (@text) {
17637: $resulttext .= '<span class="LC_cusr_emph">'.
17638: join(', ',@text).'</span>';
17639: }
17640: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17641: if ($bcc{$type} ne '') {
1.286 raeburn 17642: my $bcctext;
17643: if (@text) {
1.289 raeburn 17644: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17645: } else {
17646: $bcctext = '(Bcc)';
17647: }
17648: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17649: } elsif (!@text) {
17650: $resulttext .= &mt('No one');
1.425 raeburn 17651: }
1.289 raeburn 17652: if ($includestr{$type} ne '') {
1.286 raeburn 17653: if ($includeloc{$type} eq 'b') {
17654: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17655: } elsif ($includeloc{$type} eq 's') {
17656: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17657: }
1.134 raeburn 17658: }
1.286 raeburn 17659: } elsif (!@text) {
17660: $resulttext .= &mt('No recipients');
1.134 raeburn 17661: }
17662: $resulttext .= '</li>';
1.28 raeburn 17663: }
17664: }
1.315 raeburn 17665: if (ref($changes{'overrides'}) eq 'ARRAY') {
17666: my @deletions;
17667: foreach my $type (@{$changes{'overrides'}}) {
17668: if ($usertypeshash{$type}) {
17669: if (grep(/^\Q$type\E/,@overrides)) {
17670: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17671: $usertypeshash{$type}).'<ul><li>';
17672: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17673: my @text;
17674: foreach my $item (@contacts) {
1.425 raeburn 17675: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17676: push(@text,$short_titles->{$item});
17677: }
17678: }
17679: if ($newsetting{'override_'.$type}{'others'} ne '') {
17680: push(@text,$newsetting{'override_'.$type}{'others'});
17681: }
1.425 raeburn 17682:
1.315 raeburn 17683: if (@text) {
17684: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17685: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17686: }
17687: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17688: my $bcctext;
17689: if (@text) {
17690: $bcctext = ' '.&mt('with Bcc to');
17691: } else {
17692: $bcctext = '(Bcc)';
17693: }
17694: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17695: } elsif (!@text) {
17696: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17697: }
17698: $resulttext .= '</li>';
17699: if ($newsetting{'override_'.$type}{'include'} ne '') {
17700: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17701: if ($loc eq 'b') {
17702: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17703: } elsif ($loc eq 's') {
17704: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17705: }
17706: }
17707: }
17708: $resulttext .= '</li></ul></li>';
17709: } else {
17710: push(@deletions,$usertypeshash{$type});
17711: }
17712: }
17713: }
17714: if (@deletions) {
17715: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17716: join(', ',@deletions)).'</li>';
17717: }
17718: }
1.203 raeburn 17719: my @offon = ('off','on');
1.340 raeburn 17720: my $corelink = &core_link_msu();
1.203 raeburn 17721: if ($changes{'reporterrors'}) {
17722: $resulttext .= '<li>'.
17723: &mt('E-mail error reports to [_1] set to "'.
17724: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17725: $corelink).
1.203 raeburn 17726: '</li>';
17727: }
17728: if ($changes{'reportupdates'}) {
17729: $resulttext .= '<li>'.
17730: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17731: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17732: $corelink).
1.203 raeburn 17733: '</li>';
17734: }
1.340 raeburn 17735: if ($changes{'reportstatus'}) {
17736: $resulttext .= '<li>'.
17737: &mt('E-mail status if errors above threshold to [_1] set to "'.
17738: $offon[$env{'form.reportstatus'}].'".',
17739: $corelink).
17740: '</li>';
17741: }
17742: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17743: $resulttext .= '<li>'.
17744: &mt('Nightly status check e-mail settings').':<ul>';
17745: my (%defval,%use_def,%shown);
17746: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17747: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17748: $defval{'weights'} =
1.341 raeburn 17749: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17750: $defval{'excluded'} = &mt('None');
17751: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17752: foreach my $item ('threshold','sysmail','weights','excluded') {
17753: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17754: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17755: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17756: } elsif ($item eq 'weights') {
17757: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17758: foreach my $type ('E','W','N','U') {
1.340 raeburn 17759: $shown{$item} .= $lonstatus_names->{$type}.'=';
17760: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17761: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17762: } else {
17763: $shown{$item} .= $lonstatus_defs->{$type};
17764: }
17765: $shown{$item} .= ', ';
17766: }
17767: $shown{$item} =~ s/, $//;
17768: } else {
17769: $shown{$item} = $defval{$item};
17770: }
17771: } elsif ($item eq 'excluded') {
17772: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17773: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17774: } else {
17775: $shown{$item} = $defval{$item};
17776: }
17777: }
17778: } else {
17779: $shown{$item} = $defval{$item};
17780: }
17781: }
17782: } else {
17783: foreach my $item ('threshold','weights','excluded','sysmail') {
17784: $shown{$item} = $defval{$item};
17785: }
17786: }
17787: foreach my $item ('threshold','weights','excluded','sysmail') {
17788: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17789: $shown{$item}).'</li>';
17790: }
17791: $resulttext .= '</ul></li>';
17792: }
1.286 raeburn 17793: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17794: my (@optional,@required,@unused,$maxsizechg);
17795: foreach my $field (@{$changes{'helpform'}}) {
17796: if ($field eq 'maxsize') {
17797: $maxsizechg = 1;
17798: next;
17799: }
17800: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17801: push(@optional,$field);
1.286 raeburn 17802: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17803: push(@unused,$field);
17804: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17805: push(@required,$field);
1.286 raeburn 17806: }
17807: }
17808: if (@optional) {
17809: $resulttext .= '<li>'.
17810: &mt('Help form fields changed to "Optional": [_1].',
17811: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17812: '</li>';
17813: }
17814: if (@required) {
17815: $resulttext .= '<li>'.
17816: &mt('Help form fields changed to "Required": [_1].',
17817: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17818: '</li>';
17819: }
17820: if (@unused) {
17821: $resulttext .= '<li>'.
17822: &mt('Help form fields changed to "Not shown": [_1].',
17823: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17824: '</li>';
17825: }
17826: if ($maxsizechg) {
17827: $resulttext .= '<li>'.
17828: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17829: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17830: '</li>';
17831: }
17832: }
1.28 raeburn 17833: $resulttext .= '</ul>';
17834: } else {
1.288 raeburn 17835: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17836: }
17837: } else {
17838: $resulttext = '<span class="LC_error">'.
17839: &mt('An error occurred: [_1].',$putresult).'</span>';
17840: }
17841: return $resulttext;
17842: }
17843:
1.357 raeburn 17844: sub modify_privacy {
1.427 raeburn 17845: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17846: my ($resulttext,%current,%changes);
17847: if (ref($domconfig{'privacy'}) eq 'HASH') {
17848: %current = %{$domconfig{'privacy'}};
17849: }
17850: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17851: my @items = ('domain','author','course','community');
17852: my %names = &Apache::lonlocal::texthash (
17853: domain => 'Assigned domain role(s)',
17854: author => 'Assigned co-author role(s)',
17855: course => 'Assigned course role(s)',
1.416 raeburn 17856: community => 'Assigned community role(s)',
1.357 raeburn 17857: );
17858: my %roles = &Apache::lonlocal::texthash (
17859: domain => 'Domain role',
17860: author => 'Co-author role',
17861: course => 'Course role',
17862: community => 'Community role',
17863: );
17864: my %titles = &Apache::lonlocal::texthash (
17865: approval => 'Approval for role in different domain',
17866: othdom => 'User information available in other domain',
17867: priv => 'Information viewable by privileged user in same domain',
17868: unpriv => 'Information viewable by unprivileged user in same domain',
17869: instdom => 'Other domain shares institution/provider',
17870: extdom => 'Other domain has different institution/provider',
17871: none => 'Not allowed',
17872: user => 'User authorizes',
17873: domain => 'Domain Coordinator authorizes',
17874: auto => 'Unrestricted',
1.418 raeburn 17875: notify => 'Notify when role needs authorization',
1.357 raeburn 17876: );
17877: my %fieldnames = &Apache::lonlocal::texthash (
17878: id => 'Student/Employee ID',
17879: permanentemail => 'E-mail address',
17880: lastname => 'Last Name',
17881: firstname => 'First Name',
17882: middlename => 'Middle Name',
17883: generation => 'Generation',
17884: );
17885: my ($othertitle,$usertypes,$types) =
17886: &Apache::loncommon::sorted_inst_types($dom);
17887: my (%by_ip,%by_location,@intdoms,@instdoms);
17888: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17889:
17890: my %privacyhash = (
17891: 'approval' => {
17892: instdom => {},
17893: extdom => {},
17894: },
17895: 'othdom' => {},
17896: );
17897: foreach my $item (@items) {
17898: if (@instdoms > 1) {
1.416 raeburn 17899: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17900: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17901: }
17902: if (ref($current{'approval'}) eq 'HASH') {
17903: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17904: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17905: $changes{'approval'} = 1;
17906: }
17907: }
17908: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17909: $changes{'approval'} = 1;
17910: }
17911: }
17912: if (keys(%by_location) > 0) {
17913: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17914: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17915: }
17916: if (ref($current{'approval'}) eq 'HASH') {
17917: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17918: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17919: $changes{'approval'} = 1;
17920: }
17921: }
17922: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17923: $changes{'approval'} = 1;
17924: }
17925: }
17926: }
17927: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17928: my @statuses;
17929: if (ref($types) eq 'ARRAY') {
17930: @statuses = @{$types};
17931: }
17932: foreach my $type (@statuses,'default') {
17933: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17934: my @newvalues;
17935: foreach my $field (sort(@possfields)) {
17936: if (grep(/^\Q$field\E$/,@fields)) {
17937: $privacyhash{'othdom'}{$type}{$field} = 1;
17938: push(@newvalues,$field);
17939: }
17940: }
17941: @newvalues = sort(@newvalues);
17942: if (ref($current{'othdom'}) eq 'HASH') {
17943: if (ref($current{'othdom'}{$type}) eq 'HASH') {
17944: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
17945: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17946: if (@diffs > 0) {
17947: $changes{'othdom'} = 1;
17948: }
1.447.2.3 raeburn 17949: } elsif (@newvalues > 0) {
17950: $changes{'othdom'} = 1;
1.357 raeburn 17951: }
17952: } else {
17953: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
17954: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17955: if (@diffs > 0) {
17956: $changes{'othdom'} = 1;
17957: }
17958: }
17959: }
1.417 raeburn 17960: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
17961: my %notify;
17962: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
17963: if (exists($domcoords{$possdc})) {
17964: $notify{$possdc} = 1;
17965: }
17966: }
17967: my $notify = join(',',sort(keys(%notify)));
17968: if ($current{'notify'} ne $notify) {
17969: $changes{'notify'} = 1;
17970: }
17971: $privacyhash{'notify'} = $notify;
1.357 raeburn 17972: }
17973: my %confighash = (
17974: privacy => \%privacyhash,
17975: );
17976: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17977: if ($putresult eq 'ok') {
17978: if (keys(%changes) > 0) {
17979: $resulttext = &mt('Changes made: ').'<ul>';
1.447.2.4! raeburn 17980: foreach my $key ('approval','notify','othdom') {
1.357 raeburn 17981: if ($changes{$key}) {
17982: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17983: if ($key eq 'approval') {
17984: if (keys(%{$privacyhash{$key}{instdom}})) {
17985: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
17986: foreach my $item (@items) {
17987: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
17988: }
17989: $resulttext .= '</ul></li>';
17990: }
17991: if (keys(%{$privacyhash{$key}{extdom}})) {
17992: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
17993: foreach my $item (@items) {
17994: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
17995: }
17996: $resulttext .= '</ul></li>';
17997: }
1.417 raeburn 17998: } elsif ($key eq 'notify') {
17999: if ($privacyhash{$key}) {
18000: foreach my $dc (split(/,/,$privacyhash{$key})) {
18001: my ($dcname,$dcdom) = split(/:/,$dc);
18002: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
18003: }
18004: } else {
18005: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
18006: }
1.357 raeburn 18007: } elsif ($key eq 'othdom') {
18008: my @statuses;
18009: if (ref($types) eq 'ARRAY') {
18010: @statuses = @{$types};
18011: }
18012: if (ref($privacyhash{$key}) eq 'HASH') {
18013: foreach my $status (@statuses,'default') {
18014: if ($status eq 'default') {
18015: $resulttext .= '<li>'.$othertitle.': ';
18016: } elsif (ref($usertypes) eq 'HASH') {
18017: $resulttext .= '<li>'.$usertypes->{$status}.': ';
18018: } else {
18019: next;
18020: }
18021: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
18022: if (keys(%{$privacyhash{$key}{$status}})) {
18023: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
18024: } else {
18025: $resulttext .= &mt('none');
18026: }
18027: }
18028: $resulttext .= '</li>';
18029: }
18030: }
18031: }
18032: $resulttext .= '</ul></li>';
18033: }
18034: }
1.421 raeburn 18035: $resulttext .= '</ul>';
1.427 raeburn 18036: if ($changes{'approval'}) {
18037: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18038: delete($domdefaults{'userapprovals'});
18039: if (ref($privacyhash{'approval'}) eq 'HASH') {
18040: foreach my $domtype ('instdom','extdom') {
18041: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
18042: foreach my $roletype ('domain','author','course','community') {
18043: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
18044: $domdefaults{'userapprovals'} = 1;
18045: last;
18046: }
18047: }
18048: }
18049: last if ($domdefaults{'userapprovals'});
18050: }
18051: }
18052: my $cachetime = 24*60*60;
18053: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18054: if (ref($lastactref) eq 'HASH') {
18055: $lastactref->{'domdefaults'} = 1;
18056: }
18057: }
1.357 raeburn 18058: } else {
18059: $resulttext = &mt('No changes made to user information settings');
18060: }
18061: } else {
18062: $resulttext = '<span class="LC_error">'.
18063: &mt('An error occurred: [_1]',$putresult).'</span>';
18064: }
18065: return $resulttext;
18066: }
18067:
1.354 raeburn 18068: sub modify_passwords {
18069: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18070: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18071: $updatedefaults,$updateconf);
1.354 raeburn 18072: my $customfn = 'resetpw.html';
18073: if (ref($domconfig{'passwords'}) eq 'HASH') {
18074: %current = %{$domconfig{'passwords'}};
18075: }
18076: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18077: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18078: if (ref($types) eq 'ARRAY') {
18079: @oktypes = @{$types};
18080: }
18081: push(@oktypes,'default');
18082:
18083: my %titles = &Apache::lonlocal::texthash (
18084: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18085: intauth_check => 'Check bcrypt cost if authenticated',
18086: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18087: permanent => 'Permanent e-mail address',
18088: critical => 'Critical notification address',
18089: notify => 'Notification address',
18090: min => 'Minimum password length',
18091: max => 'Maximum password length',
18092: chars => 'Required characters',
18093: expire => 'Password expiration (days)',
1.356 raeburn 18094: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18095: reset => 'Resetting Forgotten Password',
18096: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18097: rules => 'Rules for LON-CAPA Passwords',
18098: crsownerchg => 'Course Owner Changing Student Passwords',
18099: username => 'Username',
18100: email => 'E-mail address',
18101: );
18102:
18103: #
18104: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18105: #
18106: my (%curr_defaults,%save_defaults);
18107: if (ref($domconfig{'defaults'}) eq 'HASH') {
18108: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18109: if ($key =~ /^intauth_(cost|check|switch)$/) {
18110: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18111: } else {
18112: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18113: }
18114: }
18115: }
18116: my %staticdefaults = (
18117: 'resetlink' => 2,
18118: 'resetcase' => \@oktypes,
18119: 'resetprelink' => 'both',
18120: 'resetemail' => ['critical','notify','permanent'],
18121: 'intauth_cost' => 10,
18122: 'intauth_check' => 0,
18123: 'intauth_switch' => 0,
18124: );
1.365 raeburn 18125: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18126: foreach my $type (@oktypes) {
18127: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18128: }
18129: my $linklife = $env{'form.passwords_link'};
18130: $linklife =~ s/^\s+|\s+$//g;
18131: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18132: $newvalues{'resetlink'} = $linklife;
18133: if ($current{'resetlink'}) {
18134: if ($current{'resetlink'} ne $linklife) {
18135: $changes{'reset'} = 1;
18136: }
1.368 raeburn 18137: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18138: if ($staticdefaults{'resetlink'} ne $linklife) {
18139: $changes{'reset'} = 1;
18140: }
18141: }
18142: } elsif ($current{'resetlink'}) {
18143: $changes{'reset'} = 1;
18144: }
18145: my @casesens;
18146: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18147: foreach my $case (sort(@posscase)) {
18148: if (grep(/^\Q$case\E$/,@oktypes)) {
18149: push(@casesens,$case);
18150: }
18151: }
18152: $newvalues{'resetcase'} = \@casesens;
18153: if (ref($current{'resetcase'}) eq 'ARRAY') {
18154: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18155: if (@diffs > 0) {
18156: $changes{'reset'} = 1;
18157: }
1.368 raeburn 18158: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18159: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18160: if (@diffs > 0) {
18161: $changes{'reset'} = 1;
18162: }
18163: }
18164: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18165: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18166: if (exists($current{'resetprelink'})) {
18167: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18168: $changes{'reset'} = 1;
18169: }
1.368 raeburn 18170: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18171: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18172: $changes{'reset'} = 1;
18173: }
18174: }
18175: } elsif ($current{'resetprelink'}) {
18176: $changes{'reset'} = 1;
18177: }
18178: foreach my $type (@oktypes) {
18179: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18180: my @postlink;
18181: foreach my $item (sort(@possplink)) {
18182: if ($item =~ /^(email|username)$/) {
18183: push(@postlink,$item);
18184: }
18185: }
18186: $newvalues{'resetpostlink'}{$type} = \@postlink;
18187: unless ($changes{'reset'}) {
18188: if (ref($current{'resetpostlink'}) eq 'HASH') {
18189: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18190: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18191: if (@diffs > 0) {
18192: $changes{'reset'} = 1;
18193: }
18194: } else {
18195: $changes{'reset'} = 1;
18196: }
1.368 raeburn 18197: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18198: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18199: if (@diffs > 0) {
18200: $changes{'reset'} = 1;
18201: }
18202: }
18203: }
18204: }
18205: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18206: my @resetemail;
18207: foreach my $item (sort(@possemailsrc)) {
18208: if ($item =~ /^(permanent|critical|notify)$/) {
18209: push(@resetemail,$item);
18210: }
18211: }
18212: $newvalues{'resetemail'} = \@resetemail;
18213: unless ($changes{'reset'}) {
18214: if (ref($current{'resetemail'}) eq 'ARRAY') {
18215: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18216: if (@diffs > 0) {
18217: $changes{'reset'} = 1;
18218: }
1.368 raeburn 18219: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18220: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18221: if (@diffs > 0) {
18222: $changes{'reset'} = 1;
18223: }
18224: }
18225: }
18226: if ($env{'form.passwords_stdtext'} == 0) {
18227: $newvalues{'resetremove'} = 1;
18228: unless ($current{'resetremove'}) {
18229: $changes{'reset'} = 1;
18230: }
18231: } elsif ($current{'resetremove'}) {
18232: $changes{'reset'} = 1;
18233: }
18234: if ($env{'form.passwords_customfile.filename'} ne '') {
18235: my $servadm = $r->dir_config('lonAdmEMail');
18236: my ($configuserok,$author_ok,$switchserver) =
18237: &config_check($dom,$confname,$servadm);
18238: my $error;
18239: if ($configuserok eq 'ok') {
18240: if ($switchserver) {
18241: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18242: } else {
18243: if ($author_ok eq 'ok') {
1.421 raeburn 18244: my $modified = [];
1.354 raeburn 18245: my ($result,$customurl) =
1.421 raeburn 18246: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18247: $confname,'customtext/resetpw','','',$customfn,
18248: $modified);
1.354 raeburn 18249: if ($result eq 'ok') {
18250: $newvalues{'resetcustom'} = $customurl;
18251: $changes{'reset'} = 1;
1.421 raeburn 18252: &update_modify_urls($r,$modified);
1.354 raeburn 18253: } else {
18254: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18255: }
18256: } else {
18257: $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);
18258: }
18259: }
18260: } else {
18261: $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);
18262: }
18263: if ($error) {
18264: &Apache::lonnet::logthis($error);
18265: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18266: }
18267: } elsif ($current{'resetcustom'}) {
18268: if ($env{'form.passwords_custom_del'}) {
18269: $changes{'reset'} = 1;
18270: } else {
18271: $newvalues{'resetcustom'} = $current{'resetcustom'};
18272: }
18273: }
18274: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18275: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18276: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18277: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18278: $changes{'intauth'} = 1;
18279: }
18280: } else {
18281: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18282: }
18283: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18284: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18285: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18286: $changes{'intauth'} = 1;
18287: }
18288: } else {
18289: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18290: }
18291: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18292: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18293: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18294: $changes{'intauth'} = 1;
18295: }
18296: } else {
18297: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18298: }
18299: foreach my $item ('cost','check','switch') {
18300: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18301: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18302: $updatedefaults = 1;
18303: }
18304: }
1.405 raeburn 18305: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18306: my %crsownerchg = (
18307: by => [],
18308: for => [],
18309: );
18310: foreach my $item ('by','for') {
18311: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18312: foreach my $type (sort(@posstypes)) {
18313: if (grep(/^\Q$type\E$/,@oktypes)) {
18314: push(@{$crsownerchg{$item}},$type);
18315: }
18316: }
18317: }
18318: $newvalues{'crsownerchg'} = \%crsownerchg;
18319: if (ref($current{'crsownerchg'}) eq 'HASH') {
18320: foreach my $item ('by','for') {
18321: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18322: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18323: if (@diffs > 0) {
18324: $changes{'crsownerchg'} = 1;
18325: last;
18326: }
18327: }
18328: }
1.368 raeburn 18329: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18330: foreach my $item ('by','for') {
18331: if (@{$crsownerchg{$item}} > 0) {
18332: $changes{'crsownerchg'} = 1;
18333: last;
18334: }
1.354 raeburn 18335: }
18336: }
18337:
18338: my %confighash = (
18339: defaults => \%save_defaults,
18340: passwords => \%newvalues,
18341: );
18342: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18343:
18344: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18345: if ($putresult eq 'ok') {
18346: if (keys(%changes) > 0) {
18347: $resulttext = &mt('Changes made: ').'<ul>';
18348: foreach my $key ('reset','intauth','rules','crsownerchg') {
18349: if ($changes{$key}) {
1.355 raeburn 18350: unless ($key eq 'intauth') {
18351: $updateconf = 1;
18352: }
1.354 raeburn 18353: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18354: if ($key eq 'reset') {
18355: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18356: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18357: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18358: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18359: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18360: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18361: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18362: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18363: }
1.354 raeburn 18364: } else {
18365: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18366: }
18367: if ($confighash{'passwords'}{'resetlink'}) {
18368: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18369: } else {
18370: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18371: &mt('Will default to 2 hours').'</li>';
18372: }
18373: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18374: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18375: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18376: } else {
18377: my $casesens;
18378: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18379: if ($type eq 'default') {
18380: $casesens .= $othertitle.', ';
18381: } elsif ($usertypes->{$type} ne '') {
18382: $casesens .= $usertypes->{$type}.', ';
18383: }
18384: }
18385: $casesens =~ s/\Q, \E$//;
18386: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18387: }
18388: } else {
18389: $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>';
18390: }
18391: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18392: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18393: } else {
18394: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18395: }
18396: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18397: my $output;
18398: if (ref($types) eq 'ARRAY') {
18399: foreach my $type (@{$types}) {
18400: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18401: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18402: $output .= $usertypes->{$type}.' -- '.&mt('none');
18403: } else {
18404: $output .= $usertypes->{$type}.' -- '.
18405: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18406: }
18407: }
18408: }
18409: }
18410: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18411: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18412: $output .= $othertitle.' -- '.&mt('none');
18413: } else {
18414: $output .= $othertitle.' -- '.
18415: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18416: }
18417: }
18418: if ($output) {
18419: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18420: } else {
18421: $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>';
18422: }
18423: } else {
18424: $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>';
18425: }
18426: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18427: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18428: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18429: } else {
18430: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18431: }
18432: } else {
1.379 raeburn 18433: $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 18434: }
18435: if ($confighash{'passwords'}{'resetremove'}) {
18436: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18437: } else {
18438: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18439: }
18440: if ($confighash{'passwords'}{'resetcustom'}) {
18441: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18442: &mt('custom text'),600,500,undef,undef,
18443: undef,undef,'background-color:#ffffff');
18444: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18445: } else {
18446: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18447: }
18448: } elsif ($key eq 'intauth') {
18449: foreach my $item ('cost','switch','check') {
18450: my $value = $save_defaults{$key.'_'.$item};
18451: if ($item eq 'switch') {
18452: my %optiondesc = &Apache::lonlocal::texthash (
18453: 0 => 'No',
18454: 1 => 'Yes',
18455: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18456: );
18457: if ($value =~ /^(0|1|2)$/) {
18458: $value = $optiondesc{$value};
18459: } else {
18460: $value = &mt('none -- defaults to No');
18461: }
18462: } elsif ($item eq 'check') {
18463: my %optiondesc = &Apache::lonlocal::texthash (
18464: 0 => 'No',
18465: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18466: 2 => 'Yes, disallow login if stored cost is less than domain default',
18467: );
18468: if ($value =~ /^(0|1|2)$/) {
18469: $value = $optiondesc{$value};
18470: } else {
18471: $value = &mt('none -- defaults to No');
18472: }
18473: }
18474: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18475: }
18476: } elsif ($key eq 'rules') {
1.356 raeburn 18477: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18478: if ($confighash{'passwords'}{$rule} eq '') {
18479: if ($rule eq 'min') {
1.356 raeburn 18480: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18481: ' '.&mt('Default of [_1] will be used',
18482: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18483: } else {
18484: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18485: }
18486: } else {
18487: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18488: }
18489: }
1.370 raeburn 18490: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18491: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18492: my %rulenames = &Apache::lonlocal::texthash(
18493: uc => 'At least one upper case letter',
18494: lc => 'At least one lower case letter',
18495: num => 'At least one number',
18496: spec => 'At least one non-alphanumeric',
18497: );
18498: my $needed = '<ul><li>'.
18499: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18500: '</li></ul>';
1.370 raeburn 18501: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18502: } else {
18503: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18504: }
18505: } else {
18506: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18507: }
1.354 raeburn 18508: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18509: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18510: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18511: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18512: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18513: } else {
18514: my %crsownerstr;
18515: foreach my $item ('by','for') {
18516: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18517: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18518: if ($type eq 'default') {
18519: $crsownerstr{$item} .= $othertitle.', ';
18520: } elsif ($usertypes->{$type} ne '') {
18521: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18522: }
18523: }
18524: $crsownerstr{$item} =~ s/\Q, \E$//;
18525: }
18526: }
18527: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18528: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18529: }
1.354 raeburn 18530: } else {
1.359 raeburn 18531: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18532: }
18533: }
18534: $resulttext .= '</ul></li>';
18535: }
18536: }
18537: $resulttext .= '</ul>';
18538: } else {
18539: $resulttext = &mt('No changes made to password settings');
18540: }
1.355 raeburn 18541: my $cachetime = 24*60*60;
1.354 raeburn 18542: if ($updatedefaults) {
18543: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18544: if (ref($lastactref) eq 'HASH') {
18545: $lastactref->{'domdefaults'} = 1;
18546: }
18547: }
1.355 raeburn 18548: if ($updateconf) {
18549: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18550: if (ref($lastactref) eq 'HASH') {
18551: $lastactref->{'passwdconf'} = 1;
18552: }
18553: }
1.354 raeburn 18554: } else {
18555: $resulttext = '<span class="LC_error">'.
18556: &mt('An error occurred: [_1]',$putresult).'</span>';
18557: }
18558: if ($errors) {
18559: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18560: $errors.'</ul></p>';
18561: }
18562: return $resulttext;
18563: }
18564:
1.405 raeburn 18565: sub password_rule_changes {
18566: my ($prefix,$newvalues,$current,$changes) = @_;
18567: return unless ((ref($newvalues) eq 'HASH') &&
18568: (ref($current) eq 'HASH') &&
18569: (ref($changes) eq 'HASH'));
18570: my (@rules,%staticdefaults);
18571: if ($prefix eq 'passwords') {
18572: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18573: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18574: @rules = ('min','max');
18575: }
18576: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18577: foreach my $rule (@rules) {
18578: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18579: my $ruleok;
18580: if ($rule eq 'expire') {
18581: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18582: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18583: $ruleok = 1;
18584: }
18585: } elsif ($rule eq 'min') {
18586: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18587: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18588: $ruleok = 1;
18589: }
18590: }
18591: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18592: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18593: $ruleok = 1;
18594: }
18595: if ($ruleok) {
18596: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18597: if (exists($current->{$rule})) {
18598: if ($newvalues->{$rule} ne $current->{$rule}) {
18599: $changes->{'rules'} = 1;
18600: }
18601: } elsif ($rule eq 'min') {
18602: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18603: $changes->{'rules'} = 1;
18604: }
18605: } else {
18606: $changes->{'rules'} = 1;
18607: }
18608: } elsif (exists($current->{$rule})) {
18609: $changes->{'rules'} = 1;
18610: }
18611: }
18612: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18613: my @chars;
18614: foreach my $item (sort(@posschars)) {
18615: if ($item =~ /^(uc|lc|num|spec)$/) {
18616: push(@chars,$item);
18617: }
18618: }
18619: $newvalues->{'chars'} = \@chars;
18620: unless ($changes->{'rules'}) {
18621: if (ref($current->{'chars'}) eq 'ARRAY') {
18622: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18623: if (@diffs > 0) {
18624: $changes->{'rules'} = 1;
18625: }
18626: } else {
18627: if (@chars > 0) {
18628: $changes->{'rules'} = 1;
18629: }
18630: }
18631: }
18632: return;
18633: }
18634:
1.28 raeburn 18635: sub modify_usercreation {
1.27 raeburn 18636: my ($dom,%domconfig) = @_;
1.224 raeburn 18637: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18638: my $warningmsg;
1.27 raeburn 18639: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18640: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18641: if ($key eq 'cancreate') {
18642: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18643: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18644: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18645: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18646: } else {
1.224 raeburn 18647: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18648: }
18649: }
18650: }
18651: } elsif ($key eq 'email_rule') {
18652: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18653: } else {
18654: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18655: }
1.27 raeburn 18656: }
18657: }
18658: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18659: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18660: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18661: foreach my $item(@contexts) {
1.224 raeburn 18662: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18663: }
1.34 raeburn 18664: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18665: foreach my $item (@contexts) {
1.224 raeburn 18666: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18667: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18668: }
1.27 raeburn 18669: }
1.34 raeburn 18670: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18671: foreach my $item (@contexts) {
1.43 raeburn 18672: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18673: if ($cancreate{$item} ne 'any') {
18674: push(@{$changes{'cancreate'}},$item);
18675: }
18676: } else {
18677: if ($cancreate{$item} ne 'none') {
18678: push(@{$changes{'cancreate'}},$item);
18679: }
1.27 raeburn 18680: }
18681: }
18682: } else {
1.43 raeburn 18683: foreach my $item (@contexts) {
1.34 raeburn 18684: push(@{$changes{'cancreate'}},$item);
18685: }
1.27 raeburn 18686: }
1.34 raeburn 18687:
1.27 raeburn 18688: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18689: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18690: if (!grep(/^\Q$type\E$/,@username_rule)) {
18691: push(@{$changes{'username_rule'}},$type);
18692: }
18693: }
18694: foreach my $type (@username_rule) {
18695: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18696: push(@{$changes{'username_rule'}},$type);
18697: }
18698: }
18699: } else {
18700: push(@{$changes{'username_rule'}},@username_rule);
18701: }
18702:
1.32 raeburn 18703: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18704: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18705: if (!grep(/^\Q$type\E$/,@id_rule)) {
18706: push(@{$changes{'id_rule'}},$type);
18707: }
18708: }
18709: foreach my $type (@id_rule) {
18710: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18711: push(@{$changes{'id_rule'}},$type);
18712: }
18713: }
18714: } else {
18715: push(@{$changes{'id_rule'}},@id_rule);
18716: }
18717:
1.43 raeburn 18718: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18719: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18720: my %authhash;
1.43 raeburn 18721: foreach my $item (@authen_contexts) {
1.28 raeburn 18722: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18723: foreach my $auth (@authtypes) {
18724: if (grep(/^\Q$auth\E$/,@authallowed)) {
18725: $authhash{$item}{$auth} = 1;
18726: } else {
18727: $authhash{$item}{$auth} = 0;
18728: }
18729: }
18730: }
18731: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18732: foreach my $item (@authen_contexts) {
1.28 raeburn 18733: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18734: foreach my $auth (@authtypes) {
18735: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18736: push(@{$changes{'authtypes'}},$item);
18737: last;
18738: }
18739: }
18740: }
18741: }
18742: } else {
1.43 raeburn 18743: foreach my $item (@authen_contexts) {
1.28 raeburn 18744: push(@{$changes{'authtypes'}},$item);
18745: }
18746: }
18747:
1.224 raeburn 18748: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18749: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18750: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18751: $save_usercreate{'id_rule'} = \@id_rule;
18752: $save_usercreate{'username_rule'} = \@username_rule,
18753: $save_usercreate{'authtypes'} = \%authhash;
18754:
1.27 raeburn 18755: my %usercreation_hash = (
1.224 raeburn 18756: usercreation => \%save_usercreate,
18757: );
1.27 raeburn 18758:
18759: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18760: $dom);
1.50 raeburn 18761:
1.224 raeburn 18762: if ($putresult eq 'ok') {
18763: if (keys(%changes) > 0) {
18764: $resulttext = &mt('Changes made:').'<ul>';
18765: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18766: my %lt = &usercreation_types();
18767: foreach my $type (@{$changes{'cancreate'}}) {
18768: my $chgtext = $lt{$type}.', ';
18769: if ($cancreate{$type} eq 'none') {
18770: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18771: } elsif ($cancreate{$type} eq 'any') {
18772: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18773: } elsif ($cancreate{$type} eq 'official') {
18774: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18775: } elsif ($cancreate{$type} eq 'unofficial') {
18776: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18777: }
18778: $resulttext .= '<li>'.$chgtext.'</li>';
18779: }
18780: }
18781: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18782: my ($rules,$ruleorder) =
18783: &Apache::lonnet::inst_userrules($dom,'username');
18784: my $chgtext = '<ul>';
18785: foreach my $type (@username_rule) {
18786: if (ref($rules->{$type}) eq 'HASH') {
18787: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18788: }
18789: }
18790: $chgtext .= '</ul>';
18791: if (@username_rule > 0) {
18792: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18793: } else {
18794: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18795: }
18796: }
18797: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18798: my ($idrules,$idruleorder) =
18799: &Apache::lonnet::inst_userrules($dom,'id');
18800: my $chgtext = '<ul>';
18801: foreach my $type (@id_rule) {
18802: if (ref($idrules->{$type}) eq 'HASH') {
18803: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18804: }
18805: }
18806: $chgtext .= '</ul>';
18807: if (@id_rule > 0) {
18808: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18809: } else {
18810: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18811: }
18812: }
18813: my %authname = &authtype_names();
18814: my %context_title = &context_names();
18815: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18816: my $chgtext = '<ul>';
18817: foreach my $type (@{$changes{'authtypes'}}) {
18818: my @allowed;
18819: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18820: foreach my $auth (@authtypes) {
18821: if ($authhash{$type}{$auth}) {
18822: push(@allowed,$authname{$auth});
18823: }
18824: }
18825: if (@allowed > 0) {
18826: $chgtext .= join(', ',@allowed).'</li>';
18827: } else {
18828: $chgtext .= &mt('none').'</li>';
18829: }
18830: }
18831: $chgtext .= '</ul>';
18832: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18833: $resulttext .= '</li>';
18834: }
18835: $resulttext .= '</ul>';
18836: } else {
18837: $resulttext = &mt('No changes made to user creation settings');
18838: }
18839: } else {
18840: $resulttext = '<span class="LC_error">'.
18841: &mt('An error occurred: [_1]',$putresult).'</span>';
18842: }
18843: if ($warningmsg ne '') {
18844: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18845: }
18846: return $resulttext;
18847: }
18848:
18849: sub modify_selfcreation {
1.305 raeburn 18850: my ($dom,$lastactref,%domconfig) = @_;
18851: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18852: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18853: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18854: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18855: if (ref($typesref) eq 'ARRAY') {
18856: @types = @{$typesref};
18857: }
18858: if (ref($usertypesref) eq 'HASH') {
18859: %usertypes = %{$usertypesref};
1.228 raeburn 18860: }
1.303 raeburn 18861: $usertypes{'default'} = $othertitle;
1.224 raeburn 18862: #
18863: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18864: #
18865: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18866: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18867: if ($key eq 'cancreate') {
18868: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18869: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18870: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18871: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18872: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18873: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18874: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18875: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18876: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18877: } else {
18878: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18879: }
18880: }
18881: }
18882: } elsif ($key eq 'email_rule') {
18883: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18884: } else {
18885: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18886: }
18887: }
18888: }
18889: #
18890: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18891: #
18892: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18893: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18894: if ($key eq 'selfcreate') {
18895: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18896: } else {
18897: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18898: }
18899: }
18900: }
1.305 raeburn 18901: #
18902: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18903: #
18904: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18905: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18906: if ($key eq 'inststatusguest') {
18907: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18908: } else {
18909: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18910: }
18911: }
18912: }
1.224 raeburn 18913:
18914: my @contexts = ('selfcreate');
18915: @{$cancreate{'selfcreate'}} = ();
18916: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18917: if (@types) {
18918: @{$cancreate{'statustocreate'}} = ();
18919: }
1.236 raeburn 18920: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18921: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18922: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18923: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18924: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18925: my %selfcreatetypes = (
18926: sso => 'users authenticated by institutional single sign on',
18927: login => 'users authenticated by institutional log-in',
1.303 raeburn 18928: email => 'users verified by e-mail',
1.50 raeburn 18929: );
1.224 raeburn 18930: #
18931: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18932: # is permitted.
18933: #
1.305 raeburn 18934: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 18935:
1.305 raeburn 18936: my (@statuses,%email_rule);
1.228 raeburn 18937: foreach my $item ('login','sso','email') {
1.224 raeburn 18938: if ($item eq 'email') {
1.236 raeburn 18939: if ($env{'form.cancreate_email'}) {
1.305 raeburn 18940: if (@types) {
18941: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
18942: foreach my $status (@poss_statuses) {
18943: if (grep(/^\Q$status\E$/,(@types,'default'))) {
18944: push(@statuses,$status);
18945: }
18946: }
18947: $save_inststatus{'inststatusguest'} = \@statuses;
18948: } else {
18949: push(@statuses,'default');
18950: }
18951: if (@statuses) {
18952: my %curr_rule;
18953: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
18954: foreach my $type (@statuses) {
18955: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 18956: }
1.305 raeburn 18957: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
18958: foreach my $type (@statuses) {
18959: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
18960: }
18961: }
18962: push(@{$cancreate{'selfcreate'}},'email');
18963: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
18964: my %curremaildom;
18965: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
18966: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
18967: }
18968: foreach my $type (@statuses) {
18969: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
18970: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
18971: }
18972: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
18973: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
18974: }
18975: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
18976: #
18977: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
18978: #
18979: my $chosen = $1;
18980: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
18981: my $emaildom;
18982: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 18983: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 18984: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
18985: if (ref($curremaildom{$type}) eq 'HASH') {
18986: if (exists($curremaildom{$type}{$chosen})) {
18987: if ($curremaildom{$type}{$chosen} ne $emaildom) {
18988: push(@{$changes{'cancreate'}},'emaildomain');
18989: }
18990: } elsif ($emaildom ne '') {
18991: push(@{$changes{'cancreate'}},'emaildomain');
18992: }
18993: } elsif ($emaildom ne '') {
18994: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 18995: }
1.305 raeburn 18996: }
18997: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18998: } elsif ($chosen eq 'custom') {
18999: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
19000: $email_rule{$type} = [];
19001: if (ref($emailrules) eq 'HASH') {
19002: foreach my $rule (@possemail_rules) {
19003: if (exists($emailrules->{$rule})) {
19004: push(@{$email_rule{$type}},$rule);
19005: }
19006: }
19007: }
19008: if (@{$email_rule{$type}}) {
19009: $cancreate{'emailoptions'}{$type} = 'custom';
19010: if (ref($curr_rule{$type}) eq 'ARRAY') {
19011: if (@{$curr_rule{$type}} > 0) {
19012: foreach my $rule (@{$curr_rule{$type}}) {
19013: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
19014: push(@{$changes{'email_rule'}},$type);
19015: }
19016: }
19017: }
19018: foreach my $type (@{$email_rule{$type}}) {
19019: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
19020: push(@{$changes{'email_rule'}},$type);
19021: }
19022: }
19023: } else {
19024: push(@{$changes{'email_rule'}},$type);
19025: }
19026: }
19027: } else {
19028: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19029: }
19030: }
19031: }
19032: if (@types) {
19033: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19034: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
19035: if (@changed) {
19036: push(@{$changes{'inststatus'}},'inststatusguest');
19037: }
19038: } else {
19039: push(@{$changes{'inststatus'}},'inststatusguest');
19040: }
19041: }
19042: } else {
19043: delete($env{'form.cancreate_email'});
19044: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19045: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19046: push(@{$changes{'inststatus'}},'inststatusguest');
19047: }
19048: }
19049: }
19050: } else {
19051: $save_inststatus{'inststatusguest'} = [];
19052: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19053: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19054: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 19055: }
19056: }
1.224 raeburn 19057: }
19058: } else {
19059: if ($env{'form.cancreate_'.$item}) {
19060: push(@{$cancreate{'selfcreate'}},$item);
19061: }
19062: }
19063: }
1.305 raeburn 19064: my (%userinfo,%savecaptcha);
1.224 raeburn 19065: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
19066: #
1.228 raeburn 19067: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
19068: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19069: #
1.236 raeburn 19070:
1.244 raeburn 19071: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19072: push(@contexts,'emailusername');
1.305 raeburn 19073: if (@statuses) {
19074: foreach my $type (@statuses) {
1.228 raeburn 19075: if (ref($infofields) eq 'ARRAY') {
19076: foreach my $field (@{$infofields}) {
19077: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19078: $cancreate{'emailusername'}{$type}{$field} = $1;
19079: }
19080: }
1.224 raeburn 19081: }
19082: }
19083: }
19084: #
19085: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19086: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19087: #
19088:
19089: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19090: @approvalnotify = sort(@approvalnotify);
19091: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19092: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19093: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19094: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19095: push(@{$changes{'cancreate'}},'notify');
19096: }
19097: } else {
19098: if ($cancreate{'notify'}{'approval'}) {
19099: push(@{$changes{'cancreate'}},'notify');
19100: }
19101: }
19102: } elsif ($cancreate{'notify'}{'approval'}) {
19103: push(@{$changes{'cancreate'}},'notify');
19104: }
19105:
19106: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19107: }
19108: #
1.236 raeburn 19109: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19110: # institutional log-in.
19111: #
19112: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19113: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19114: ($domdefaults{'auth_def'} eq 'localauth'))) {
19115: $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.').' '.
19116: &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.');
19117: }
19118: }
19119: my @fields = ('lastname','firstname','middlename','generation',
19120: 'permanentemail','id');
1.240 raeburn 19121: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19122: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19123: #
19124: # Where usernames may created for institutional log-in and/or institutional single sign on:
19125: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19126: # may self-create accounts
19127: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19128: # which the user may supply, if institutional data is unavailable.
19129: #
19130: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19131: if (@types) {
1.305 raeburn 19132: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19133: push(@contexts,'statustocreate');
1.303 raeburn 19134: foreach my $type (@types) {
1.224 raeburn 19135: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19136: foreach my $field (@fields) {
19137: if (grep(/^\Q$field\E$/,@modifiable)) {
19138: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19139: } else {
19140: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19141: }
19142: }
19143: }
19144: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19145: foreach my $type (@types) {
1.224 raeburn 19146: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19147: foreach my $field (@fields) {
19148: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19149: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19150: push(@{$changes{'selfcreate'}},$type);
19151: last;
19152: }
19153: }
19154: }
19155: }
19156: } else {
1.303 raeburn 19157: foreach my $type (@types) {
1.224 raeburn 19158: push(@{$changes{'selfcreate'}},$type);
19159: }
19160: }
19161: }
1.240 raeburn 19162: foreach my $field (@shibfields) {
19163: if ($env{'form.shibenv_'.$field} ne '') {
19164: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19165: }
19166: }
19167: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19168: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19169: foreach my $field (@shibfields) {
19170: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19171: push(@{$changes{'cancreate'}},'shibenv');
19172: }
19173: }
19174: } else {
19175: foreach my $field (@shibfields) {
19176: if ($env{'form.shibenv_'.$field}) {
19177: push(@{$changes{'cancreate'}},'shibenv');
19178: last;
19179: }
19180: }
19181: }
19182: }
1.224 raeburn 19183: }
19184: foreach my $item (@contexts) {
19185: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19186: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19187: if (ref($cancreate{$item}) eq 'ARRAY') {
19188: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19189: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19190: push(@{$changes{'cancreate'}},$item);
19191: }
19192: }
19193: }
19194: }
19195: if (ref($cancreate{$item}) eq 'ARRAY') {
19196: foreach my $type (@{$cancreate{$item}}) {
19197: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19198: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19199: push(@{$changes{'cancreate'}},$item);
19200: }
19201: }
19202: }
19203: }
19204: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19205: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19206: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19207: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19208: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19209: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19210: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19211: push(@{$changes{'cancreate'}},$item);
19212: }
19213: }
19214: }
1.305 raeburn 19215: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19216: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19217: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19218: push(@{$changes{'cancreate'}},$item);
19219: }
1.224 raeburn 19220: }
19221: }
19222: }
1.305 raeburn 19223: foreach my $type (keys(%{$cancreate{$item}})) {
19224: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19225: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19226: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19227: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19228: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19229: push(@{$changes{'cancreate'}},$item);
19230: }
19231: }
19232: } else {
19233: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19234: push(@{$changes{'cancreate'}},$item);
19235: }
19236: }
19237: }
1.305 raeburn 19238: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19239: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19240: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19241: push(@{$changes{'cancreate'}},$item);
19242: }
1.224 raeburn 19243: }
19244: }
19245: }
19246: }
19247: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19248: if (ref($cancreate{$item}) eq 'ARRAY') {
19249: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19250: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19251: push(@{$changes{'cancreate'}},$item);
19252: }
19253: }
1.305 raeburn 19254: }
19255: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19256: if (ref($cancreate{$item}) eq 'HASH') {
19257: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19258: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19259: }
19260: }
19261: } elsif ($item eq 'emailusername') {
1.228 raeburn 19262: if (ref($cancreate{$item}) eq 'HASH') {
19263: foreach my $type (keys(%{$cancreate{$item}})) {
19264: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19265: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19266: if ($cancreate{$item}{$type}{$field}) {
19267: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19268: push(@{$changes{'cancreate'}},$item);
19269: }
19270: last;
19271: }
19272: }
19273: }
19274: }
1.224 raeburn 19275: }
19276: }
19277: }
19278: #
19279: # Populate %save_usercreate hash with updates to self-creation configuration.
19280: #
19281: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19282: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19283: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19284: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19285: if (ref($cancreate{'notify'}) eq 'HASH') {
19286: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19287: }
1.236 raeburn 19288: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19289: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19290: }
1.303 raeburn 19291: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19292: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19293: }
1.305 raeburn 19294: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19295: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19296: }
1.303 raeburn 19297: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19298: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19299: }
1.224 raeburn 19300: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19301: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19302: }
1.240 raeburn 19303: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19304: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19305: }
1.224 raeburn 19306: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19307: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19308:
19309: my %userconfig_hash = (
19310: usercreation => \%save_usercreate,
19311: usermodification => \%save_usermodify,
1.305 raeburn 19312: inststatus => \%save_inststatus,
1.224 raeburn 19313: );
1.305 raeburn 19314:
1.224 raeburn 19315: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19316: $dom);
19317: #
1.305 raeburn 19318: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19319: #
1.27 raeburn 19320: if ($putresult eq 'ok') {
19321: if (keys(%changes) > 0) {
19322: $resulttext = &mt('Changes made:').'<ul>';
19323: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19324: my %lt = &selfcreation_types();
1.34 raeburn 19325: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19326: my $chgtext = '';
1.45 raeburn 19327: if ($type eq 'selfcreate') {
1.50 raeburn 19328: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19329: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19330: } else {
1.224 raeburn 19331: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19332: '<ul>';
1.50 raeburn 19333: foreach my $case (@{$cancreate{$type}}) {
19334: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19335: }
19336: $chgtext .= '</ul>';
1.100 raeburn 19337: if (ref($cancreate{$type}) eq 'ARRAY') {
19338: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19339: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19340: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19341: $chgtext .= '<span class="LC_warning">'.
19342: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19343: '</span><br />';
19344: }
19345: }
19346: }
19347: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19348: if (!@statuses) {
19349: $chgtext .= '<span class="LC_warning">'.
19350: &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.").
19351: '</span><br />';
1.303 raeburn 19352:
1.100 raeburn 19353: }
19354: }
19355: }
1.43 raeburn 19356: }
1.240 raeburn 19357: } elsif ($type eq 'shibenv') {
19358: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19359: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19360: } else {
19361: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19362: '<ul>';
19363: foreach my $field (@shibfields) {
19364: next if ($cancreate{$type}{$field} eq '');
19365: if ($field eq 'inststatus') {
19366: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19367: } else {
19368: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19369: }
19370: }
19371: $chgtext .= '</ul>';
1.303 raeburn 19372: }
1.93 raeburn 19373: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19374: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19375: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19376: if (@{$cancreate{'selfcreate'}} > 0) {
19377: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19378: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19379: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19380: $chgtext .= '<br />'.
19381: '<span class="LC_warning">'.
19382: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19383: '</span>';
19384: }
1.303 raeburn 19385: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19386: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19387: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19388: } else {
19389: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19390: }
19391: $chgtext .= '<ul>';
19392: foreach my $case (@{$cancreate{$type}}) {
19393: if ($case eq 'default') {
19394: $chgtext .= '<li>'.$othertitle.'</li>';
19395: } else {
1.303 raeburn 19396: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19397: }
19398: }
1.100 raeburn 19399: $chgtext .= '</ul>';
19400: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19401: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19402: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19403: '</span>';
1.100 raeburn 19404: }
19405: }
19406: } else {
19407: if (@{$cancreate{$type}} == 0) {
19408: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19409: } else {
19410: $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 19411: }
19412: }
1.303 raeburn 19413: $chgtext .= '<br />';
1.93 raeburn 19414: }
1.236 raeburn 19415: } elsif ($type eq 'selfcreateprocessing') {
19416: my %choices = &Apache::lonlocal::texthash (
19417: automatic => 'Automatic approval',
19418: approval => 'Queued for approval',
19419: );
1.305 raeburn 19420: if (@types) {
19421: if (@statuses) {
1.425 raeburn 19422: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19423: '<ul>';
1.305 raeburn 19424: foreach my $status (@statuses) {
19425: if ($status eq 'default') {
19426: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19427: } else {
1.305 raeburn 19428: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19429: }
19430: }
19431: $chgtext .= '</ul>';
19432: }
19433: } else {
19434: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19435: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19436: }
19437: } elsif ($type eq 'emailverified') {
19438: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19439: all => 'Same as e-mail',
19440: first => 'Omit @domain',
19441: free => 'Free to choose',
1.303 raeburn 19442: );
1.305 raeburn 19443: if (@types) {
19444: if (@statuses) {
1.303 raeburn 19445: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19446: '<ul>';
1.305 raeburn 19447: foreach my $status (@statuses) {
1.362 raeburn 19448: if ($status eq 'default') {
1.305 raeburn 19449: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19450: } else {
1.305 raeburn 19451: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19452: }
19453: }
19454: $chgtext .= '</ul>';
19455: }
19456: } else {
1.305 raeburn 19457: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19458: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19459: }
1.305 raeburn 19460: } elsif ($type eq 'emailoptions') {
19461: my %options = &Apache::lonlocal::texthash (
19462: any => 'Any e-mail',
19463: inst => 'Institutional only',
19464: noninst => 'Non-institutional only',
19465: custom => 'Custom restrictions',
19466: );
19467: if (@types) {
19468: if (@statuses) {
19469: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19470: '<ul>';
19471: foreach my $status (@statuses) {
19472: if ($type eq 'default') {
19473: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19474: } else {
19475: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19476: }
19477: }
1.305 raeburn 19478: $chgtext .= '</ul>';
19479: }
19480: } else {
19481: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19482: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19483: } else {
19484: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19485: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19486: }
1.305 raeburn 19487: }
19488: } elsif ($type eq 'emaildomain') {
19489: my $output;
19490: if (@statuses) {
19491: foreach my $type (@statuses) {
19492: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19493: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19494: if ($type eq 'default') {
19495: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19496: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19497: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19498: } else {
19499: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19500: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19501: }
1.303 raeburn 19502: } else {
1.305 raeburn 19503: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19504: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19505: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19506: } else {
19507: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19508: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19509: }
1.303 raeburn 19510: }
1.305 raeburn 19511: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19512: if ($type eq 'default') {
19513: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19514: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19515: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19516: } else {
19517: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19518: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19519: }
1.303 raeburn 19520: } else {
1.305 raeburn 19521: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19522: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19523: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19524: } else {
19525: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19526: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19527: }
1.303 raeburn 19528: }
19529: }
19530: }
19531: }
1.305 raeburn 19532: }
19533: if ($output ne '') {
19534: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19535: '<ul>'.$output.'</ul>';
1.236 raeburn 19536: }
1.165 raeburn 19537: } elsif ($type eq 'captcha') {
1.224 raeburn 19538: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19539: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19540: } else {
19541: my %captchas = &captcha_phrases();
1.224 raeburn 19542: if ($captchas{$savecaptcha{$type}}) {
19543: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19544: } else {
1.210 raeburn 19545: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19546: }
19547: }
19548: } elsif ($type eq 'recaptchakeys') {
19549: my ($privkey,$pubkey);
1.224 raeburn 19550: if (ref($savecaptcha{$type}) eq 'HASH') {
19551: $pubkey = $savecaptcha{$type}{'public'};
19552: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19553: }
19554: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19555: if (!$pubkey) {
19556: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19557: } else {
19558: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19559: }
19560: if (!$privkey) {
19561: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19562: } else {
19563: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19564: }
19565: $chgtext .= '</ul>';
1.269 raeburn 19566: } elsif ($type eq 'recaptchaversion') {
19567: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19568: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19569: }
1.224 raeburn 19570: } elsif ($type eq 'emailusername') {
19571: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19572: if (@statuses) {
19573: foreach my $type (@statuses) {
1.228 raeburn 19574: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19575: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19576: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19577: '<ul>';
19578: foreach my $field (@{$infofields}) {
19579: if ($cancreate{'emailusername'}{$type}{$field}) {
19580: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19581: }
19582: }
1.245 raeburn 19583: $chgtext .= '</ul>';
19584: } else {
1.303 raeburn 19585: $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 19586: }
19587: } else {
1.303 raeburn 19588: $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 19589: }
19590: }
19591: }
19592: }
19593: } elsif ($type eq 'notify') {
1.303 raeburn 19594: my $numapprove = 0;
1.224 raeburn 19595: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19596: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19597: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19598: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19599: $numapprove ++;
1.224 raeburn 19600: }
19601: }
1.43 raeburn 19602: }
1.303 raeburn 19603: unless ($numapprove) {
19604: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19605: }
1.34 raeburn 19606: }
1.224 raeburn 19607: if ($chgtext) {
19608: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19609: }
19610: }
19611: }
1.305 raeburn 19612: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19613: my ($emailrules,$emailruleorder) =
19614: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19615: foreach my $type (@{$changes{'email_rule'}}) {
19616: if (ref($email_rule{$type}) eq 'ARRAY') {
19617: my $chgtext = '<ul>';
19618: foreach my $rule (@{$email_rule{$type}}) {
19619: if (ref($emailrules->{$rule}) eq 'HASH') {
19620: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19621: }
19622: }
19623: $chgtext .= '</ul>';
1.310 raeburn 19624: my $typename;
1.305 raeburn 19625: if (@types) {
19626: if ($type eq 'default') {
19627: $typename = $othertitle;
19628: } else {
19629: $typename = $usertypes{$type};
1.425 raeburn 19630: }
1.305 raeburn 19631: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19632: }
19633: if (@{$email_rule{$type}} > 0) {
19634: $resulttext .= '<li>'.
19635: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19636: $usertypes{$type}).
19637: $chgtext.
19638: '</li>';
19639: } else {
19640: $resulttext .= '<li>'.
1.310 raeburn 19641: &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 19642: '</li>'.
1.310 raeburn 19643: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19644: }
1.43 raeburn 19645: }
19646: }
1.305 raeburn 19647: }
19648: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19649: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19650: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19651: my $chgtext = '<ul>';
19652: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19653: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19654: }
19655: $chgtext .= '</ul>';
19656: $resulttext .= '<li>'.
19657: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19658: $chgtext.
19659: '</li>';
19660: } else {
19661: $resulttext .= '<li>'.
19662: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19663: '</li>';
19664: }
1.43 raeburn 19665: }
19666: }
1.224 raeburn 19667: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19668: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19669: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19670: foreach my $type (@{$changes{'selfcreate'}}) {
19671: my $typename = $type;
1.303 raeburn 19672: if (keys(%usertypes) > 0) {
19673: if ($usertypes{$type} ne '') {
19674: $typename = $usertypes{$type};
1.224 raeburn 19675: }
19676: }
19677: my @modifiable;
19678: $resulttext .= '<li>'.
19679: &mt('Self-creation of account by users with status: [_1]',
19680: '<span class="LC_cusr_emph">'.$typename.'</span>').
19681: ' - '.&mt('modifiable fields (if institutional data blank): ');
19682: foreach my $field (@fields) {
19683: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19684: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19685: }
19686: }
1.224 raeburn 19687: if (@modifiable > 0) {
19688: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19689: } else {
1.224 raeburn 19690: $resulttext .= &mt('none');
1.43 raeburn 19691: }
1.224 raeburn 19692: $resulttext .= '</li>';
1.28 raeburn 19693: }
1.224 raeburn 19694: $resulttext .= '</ul></li>';
1.28 raeburn 19695: }
1.27 raeburn 19696: $resulttext .= '</ul>';
1.305 raeburn 19697: my $cachetime = 24*60*60;
19698: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19699: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19700: if (ref($lastactref) eq 'HASH') {
19701: $lastactref->{'domdefaults'} = 1;
19702: }
1.27 raeburn 19703: } else {
1.224 raeburn 19704: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19705: }
19706: } else {
19707: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19708: &mt('An error occurred: [_1]',$putresult).'</span>';
19709: }
1.43 raeburn 19710: if ($warningmsg ne '') {
19711: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19712: }
1.23 raeburn 19713: return $resulttext;
19714: }
19715:
1.165 raeburn 19716: sub process_captcha {
1.369 raeburn 19717: my ($container,$changes,$newsettings,$currsettings) = @_;
19718: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19719: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19720: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19721: $newsettings->{'captcha'} = 'original';
19722: }
1.369 raeburn 19723: my %current;
19724: if (ref($currsettings) eq 'HASH') {
19725: %current = %{$currsettings};
19726: }
19727: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19728: if ($container eq 'cancreate') {
1.169 raeburn 19729: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19730: push(@{$changes->{'cancreate'}},'captcha');
19731: } elsif (!defined($changes->{'cancreate'})) {
19732: $changes->{'cancreate'} = ['captcha'];
19733: }
1.368 raeburn 19734: } elsif ($container eq 'passwords') {
19735: $changes->{'reset'} = 1;
1.169 raeburn 19736: } else {
19737: $changes->{'captcha'} = 1;
1.165 raeburn 19738: }
19739: }
1.269 raeburn 19740: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19741: if ($newsettings->{'captcha'} eq 'recaptcha') {
19742: $newpub = $env{'form.'.$container.'_recaptchapub'};
19743: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19744: $newpub =~ s/[^\w\-]//g;
19745: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19746: $newsettings->{'recaptchakeys'} = {
19747: public => $newpub,
19748: private => $newpriv,
19749: };
1.269 raeburn 19750: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19751: $newversion =~ s/\D//g;
19752: if ($newversion ne '2') {
19753: $newversion = 1;
19754: }
19755: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19756: }
1.369 raeburn 19757: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19758: $currpub = $current{'recaptchakeys'}{'public'};
19759: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19760: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19761: $newsettings->{'recaptchakeys'} = {
19762: public => '',
19763: private => '',
19764: }
19765: }
1.165 raeburn 19766: }
1.369 raeburn 19767: if ($current{'captcha'} eq 'recaptcha') {
19768: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19769: if ($currversion ne '2') {
19770: $currversion = 1;
19771: }
19772: }
19773: if ($currversion ne $newversion) {
19774: if ($container eq 'cancreate') {
19775: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19776: push(@{$changes->{'cancreate'}},'recaptchaversion');
19777: } elsif (!defined($changes->{'cancreate'})) {
19778: $changes->{'cancreate'} = ['recaptchaversion'];
19779: }
1.368 raeburn 19780: } elsif ($container eq 'passwords') {
19781: $changes->{'reset'} = 1;
1.269 raeburn 19782: } else {
19783: $changes->{'recaptchaversion'} = 1;
19784: }
19785: }
1.165 raeburn 19786: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19787: if ($container eq 'cancreate') {
19788: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19789: push(@{$changes->{'cancreate'}},'recaptchakeys');
19790: } elsif (!defined($changes->{'cancreate'})) {
19791: $changes->{'cancreate'} = ['recaptchakeys'];
19792: }
1.368 raeburn 19793: } elsif ($container eq 'passwords') {
19794: $changes->{'reset'} = 1;
1.169 raeburn 19795: } else {
1.210 raeburn 19796: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19797: }
19798: }
19799: return;
19800: }
19801:
1.33 raeburn 19802: sub modify_usermodification {
19803: my ($dom,%domconfig) = @_;
1.224 raeburn 19804: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19805: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19806: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19807: if ($key eq 'selfcreate') {
19808: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19809: } else {
19810: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19811: }
1.33 raeburn 19812: }
19813: }
1.443 raeburn 19814: my @contexts = ('author','coauthor','course');
1.33 raeburn 19815: my %context_title = (
19816: author => 'In author context',
1.443 raeburn 19817: coauthor => 'As co-author manager',
1.33 raeburn 19818: course => 'In course context',
19819: );
19820: my @fields = ('lastname','firstname','middlename','generation',
19821: 'permanentemail','id');
19822: my %roles = (
19823: author => ['ca','aa'],
1.443 raeburn 19824: coauthor => ['ca','aa'],
1.33 raeburn 19825: course => ['st','ep','ta','in','cr'],
19826: );
19827: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19828: foreach my $context (@contexts) {
1.443 raeburn 19829: my $prefix = 'canmodify';
19830: if ($context eq 'coauthor') {
19831: $prefix = 'cacanmodify';
19832: }
1.33 raeburn 19833: foreach my $role (@{$roles{$context}}) {
1.443 raeburn 19834: my @modifiable = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$role);
1.33 raeburn 19835: foreach my $item (@fields) {
19836: if (grep(/^\Q$item\E$/,@modifiable)) {
19837: $modifyhash{$context}{$role}{$item} = 1;
19838: } else {
19839: $modifyhash{$context}{$role}{$item} = 0;
19840: }
19841: }
19842: }
19843: if (ref($curr_usermodification{$context}) eq 'HASH') {
19844: foreach my $role (@{$roles{$context}}) {
19845: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19846: foreach my $field (@fields) {
19847: if ($modifyhash{$context}{$role}{$field} ne
19848: $curr_usermodification{$context}{$role}{$field}) {
19849: push(@{$changes{$context}},$role);
19850: last;
19851: }
19852: }
19853: }
19854: }
19855: } else {
19856: foreach my $context (@contexts) {
19857: foreach my $role (@{$roles{$context}}) {
19858: push(@{$changes{$context}},$role);
19859: }
19860: }
19861: }
19862: }
19863: my %usermodification_hash = (
19864: usermodification => \%modifyhash,
19865: );
19866: my $putresult = &Apache::lonnet::put_dom('configuration',
19867: \%usermodification_hash,$dom);
19868: if ($putresult eq 'ok') {
19869: if (keys(%changes) > 0) {
19870: $resulttext = &mt('Changes made: ').'<ul>';
19871: foreach my $context (@contexts) {
19872: if (ref($changes{$context}) eq 'ARRAY') {
19873: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19874: if (ref($changes{$context}) eq 'ARRAY') {
19875: foreach my $role (@{$changes{$context}}) {
19876: my $rolename;
1.224 raeburn 19877: if ($role eq 'cr') {
19878: $rolename = &mt('Custom');
1.33 raeburn 19879: } else {
1.224 raeburn 19880: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19881: }
19882: my @modifiable;
1.224 raeburn 19883: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19884: foreach my $field (@fields) {
19885: if ($modifyhash{$context}{$role}{$field}) {
19886: push(@modifiable,$fieldtitles{$field});
19887: }
19888: }
19889: if (@modifiable > 0) {
19890: $resulttext .= join(', ',@modifiable);
19891: } else {
19892: $resulttext .= &mt('none');
19893: }
19894: $resulttext .= '</li>';
19895: }
19896: $resulttext .= '</ul></li>';
19897: }
19898: }
19899: }
19900: $resulttext .= '</ul>';
19901: } else {
19902: $resulttext = &mt('No changes made to user modification settings');
19903: }
19904: } else {
19905: $resulttext = '<span class="LC_error">'.
19906: &mt('An error occurred: [_1]',$putresult).'</span>';
19907: }
19908: return $resulttext;
19909: }
19910:
1.43 raeburn 19911: sub modify_defaults {
1.212 raeburn 19912: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19913: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19914: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19915: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19916: 'portal_def');
1.325 raeburn 19917: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19918: foreach my $item (@items) {
19919: $newvalues{$item} = $env{'form.'.$item};
19920: if ($item eq 'auth_def') {
19921: if ($newvalues{$item} ne '') {
19922: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19923: push(@errors,$item);
19924: }
19925: }
19926: } elsif ($item eq 'lang_def') {
19927: if ($newvalues{$item} ne '') {
19928: if ($newvalues{$item} =~ /^(\w+)/) {
19929: my $langcode = $1;
1.103 raeburn 19930: if ($langcode ne 'x_chef') {
19931: if (code2language($langcode) eq '') {
19932: push(@errors,$item);
19933: }
1.43 raeburn 19934: }
19935: } else {
19936: push(@errors,$item);
19937: }
19938: }
1.54 raeburn 19939: } elsif ($item eq 'timezone_def') {
19940: if ($newvalues{$item} ne '') {
1.62 raeburn 19941: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 19942: push(@errors,$item);
19943: }
19944: }
1.68 raeburn 19945: } elsif ($item eq 'datelocale_def') {
19946: if ($newvalues{$item} ne '') {
19947: my @datelocale_ids = DateTime::Locale->ids();
19948: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
19949: push(@errors,$item);
19950: }
19951: }
1.141 raeburn 19952: } elsif ($item eq 'portal_def') {
19953: if ($newvalues{$item} ne '') {
1.414 raeburn 19954: 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])\/?$/) {
19955: foreach my $field ('email','web') {
19956: if ($env{'form.'.$item.'_'.$field}) {
19957: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
19958: }
19959: }
19960: } else {
1.141 raeburn 19961: push(@errors,$item);
19962: }
19963: }
1.43 raeburn 19964: }
19965: if (grep(/^\Q$item\E$/,@errors)) {
19966: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 19967: if ($item eq 'portal_def') {
19968: if ($domdefaults{$item}) {
19969: foreach my $field ('email','web') {
19970: if (exists($domdefaults{$item.'_'.$field})) {
19971: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
19972: }
19973: }
19974: }
19975: }
1.43 raeburn 19976: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
19977: $changes{$item} = 1;
19978: }
1.414 raeburn 19979: if ($item eq 'portal_def') {
19980: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 19981: if ($newvalues{$item} eq '') {
1.414 raeburn 19982: foreach my $field ('email','web') {
19983: if (exists($domdefaults{$item.'_'.$field})) {
19984: delete($domdefaults{$item.'_'.$field});
19985: }
19986: }
19987: } else {
19988: unless ($changes{$item}) {
19989: foreach my $field ('email','web') {
19990: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
19991: $changes{$item} = 1;
19992: last;
19993: }
19994: }
19995: }
19996: foreach my $field ('email','web') {
19997: if ($newvalues{$item.'_'.$field}) {
19998: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
19999: } elsif (exists($domdefaults{$item.'_'.$field})) {
20000: delete($domdefaults{$item.'_'.$field});
20001: }
20002: }
20003: }
20004: }
20005: }
1.72 raeburn 20006: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 20007: }
1.354 raeburn 20008: my %staticdefaults = (
20009: 'intauth_cost' => 10,
20010: 'intauth_check' => 0,
20011: 'intauth_switch' => 0,
20012: );
20013: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
20014: if (exists($domdefaults{$item})) {
20015: $newvalues{$item} = $domdefaults{$item};
20016: } else {
20017: $newvalues{$item} = $staticdefaults{$item};
20018: }
20019: }
1.409 raeburn 20020: my ($unamemaprules,$ruleorder);
20021: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
20022: if (@possunamemaprules) {
20023: ($unamemaprules,$ruleorder) =
20024: &Apache::lonnet::inst_userrules($dom,'unamemap');
20025: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
20026: if (@{$ruleorder} > 0) {
20027: my %possrules;
20028: map { $possrules{$_} = 1; } @possunamemaprules;
20029: foreach my $rule (@{$ruleorder}) {
20030: if ($possrules{$rule}) {
20031: push(@{$newvalues{'unamemap_rule'}},$rule);
20032: }
20033: }
20034: }
20035: }
20036: }
20037: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
20038: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20039: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
20040: $newvalues{'unamemap_rule'});
20041: if (@rulediffs) {
20042: $changes{'unamemap_rule'} = 1;
20043: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20044: }
20045: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
20046: $changes{'unamemap_rule'} = 1;
20047: delete($domdefaults{'unamemap_rule'});
20048: }
20049: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20050: if (@{$newvalues{'unamemap_rule'}} > 0) {
20051: $changes{'unamemap_rule'} = 1;
20052: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20053: }
20054: }
1.43 raeburn 20055: my %defaults_hash = (
1.72 raeburn 20056: defaults => \%newvalues,
20057: );
1.43 raeburn 20058: my $title = &defaults_titles();
1.236 raeburn 20059:
20060: my $currinststatus;
20061: if (ref($domconfig{'inststatus'}) eq 'HASH') {
20062: $currinststatus = $domconfig{'inststatus'};
20063: } else {
20064: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
20065: $currinststatus = {
20066: inststatustypes => $usertypes,
20067: inststatusorder => $types,
20068: inststatusguest => [],
20069: };
20070: }
20071: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20072: my @allpos;
20073: my %alltypes;
1.305 raeburn 20074: my @inststatusguest;
20075: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20076: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20077: unless (grep(/^\Q$type\E$/,@todelete)) {
20078: push(@inststatusguest,$type);
20079: }
20080: }
20081: }
20082: my ($currtitles,$currorder);
1.236 raeburn 20083: if (ref($currinststatus) eq 'HASH') {
20084: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20085: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20086: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20087: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20088: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20089: }
20090: }
20091: unless (grep(/^\Q$type\E$/,@todelete)) {
20092: my $position = $env{'form.inststatus_pos_'.$type};
20093: $position =~ s/\D+//g;
20094: $allpos[$position] = $type;
20095: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20096: $alltypes{$type} =~ s/`//g;
20097: }
20098: }
20099: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20100: $currtitles =~ s/,$//;
20101: }
20102: }
20103: if ($env{'form.addinststatus'}) {
20104: my $newtype = $env{'form.addinststatus'};
20105: $newtype =~ s/\W//g;
20106: unless (exists($alltypes{$newtype})) {
20107: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20108: $alltypes{$newtype} =~ s/`//g;
20109: my $position = $env{'form.addinststatus_pos'};
20110: $position =~ s/\D+//g;
20111: if ($position ne '') {
20112: $allpos[$position] = $newtype;
20113: }
20114: }
20115: }
1.305 raeburn 20116: my @orderedstatus;
1.236 raeburn 20117: foreach my $type (@allpos) {
20118: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20119: push(@orderedstatus,$type);
20120: }
20121: }
20122: foreach my $type (keys(%alltypes)) {
20123: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20124: delete($alltypes{$type});
20125: }
20126: }
20127: $defaults_hash{'inststatus'} = {
20128: inststatustypes => \%alltypes,
20129: inststatusorder => \@orderedstatus,
1.305 raeburn 20130: inststatusguest => \@inststatusguest,
1.236 raeburn 20131: };
20132: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20133: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20134: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20135: }
20136: }
20137: if ($currorder ne join(',',@orderedstatus)) {
20138: $changes{'inststatus'}{'inststatusorder'} = 1;
20139: }
20140: my $newtitles;
20141: foreach my $item (@orderedstatus) {
20142: $newtitles .= $alltypes{$item}.',';
20143: }
20144: $newtitles =~ s/,$//;
20145: if ($currtitles ne $newtitles) {
20146: $changes{'inststatus'}{'inststatustypes'} = 1;
20147: }
1.43 raeburn 20148: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20149: $dom);
20150: if ($putresult eq 'ok') {
20151: if (keys(%changes) > 0) {
20152: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20153: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20154: 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";
20155: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20156: if ($item eq 'inststatus') {
20157: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20158: if (@orderedstatus) {
1.236 raeburn 20159: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20160: foreach my $type (@orderedstatus) {
20161: $resulttext .= $alltypes{$type}.', ';
20162: }
20163: $resulttext =~ s/, $//;
20164: $resulttext .= '</li>';
1.305 raeburn 20165: } else {
1.425 raeburn 20166: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20167: }
20168: }
1.409 raeburn 20169: } elsif ($item eq 'unamemap_rule') {
20170: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20171: my @rulenames;
20172: if (ref($unamemaprules) eq 'HASH') {
20173: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20174: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20175: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20176: }
20177: }
20178: }
20179: if (@rulenames) {
20180: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20181: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20182: '</li>';
20183: } else {
20184: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20185: }
20186: } else {
20187: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20188: }
1.236 raeburn 20189: } else {
20190: my $value = $env{'form.'.$item};
20191: if ($value eq '') {
20192: $value = &mt('none');
20193: } elsif ($item eq 'auth_def') {
20194: my %authnames = &authtype_names();
20195: my %shortauth = (
20196: internal => 'int',
20197: krb4 => 'krb4',
20198: krb5 => 'krb5',
20199: localauth => 'loc',
1.325 raeburn 20200: lti => 'lti',
1.236 raeburn 20201: );
20202: $value = $authnames{$shortauth{$value}};
20203: }
20204: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20205: $mailmsgtext .= "$title->{$item} set to $value\n";
20206: if ($item eq 'portal_def') {
20207: if ($env{'form.'.$item} ne '') {
20208: foreach my $field ('email','web') {
20209: $value = $env{'form.'.$item.'_'.$field};
20210: if ($value) {
20211: $value = &mt('Yes');
20212: } else {
20213: $value = &mt('No');
20214: }
20215: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20216: }
20217: }
20218: }
1.43 raeburn 20219: }
20220: }
20221: $resulttext .= '</ul>';
20222: $mailmsgtext .= "\n";
20223: my $cachetime = 24*60*60;
1.72 raeburn 20224: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20225: if (ref($lastactref) eq 'HASH') {
20226: $lastactref->{'domdefaults'} = 1;
20227: }
1.68 raeburn 20228: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20229: my $notify = 1;
20230: if (ref($domconfig{'contacts'}) eq 'HASH') {
20231: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20232: $notify = 0;
20233: }
20234: }
20235: if ($notify) {
20236: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20237: "LON-CAPA Domain Settings Change - $dom",
20238: $mailmsgtext);
20239: }
1.54 raeburn 20240: }
1.43 raeburn 20241: } else {
1.54 raeburn 20242: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20243: }
20244: } else {
20245: $resulttext = '<span class="LC_error">'.
20246: &mt('An error occurred: [_1]',$putresult).'</span>';
20247: }
20248: if (@errors > 0) {
20249: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20250: foreach my $item (@errors) {
20251: $resulttext .= ' "'.$title->{$item}.'",';
20252: }
20253: $resulttext =~ s/,$//;
20254: }
20255: return $resulttext;
20256: }
20257:
1.46 raeburn 20258: sub modify_scantron {
1.205 raeburn 20259: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20260: my ($resulttext,%confhash,%changes,$errors);
20261: my $custom = 'custom.tab';
20262: my $default = 'default.tab';
20263: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20264: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20265: &config_check($dom,$confname,$servadm);
20266: if ($env{'form.scantronformat.filename'} ne '') {
20267: my $error;
20268: if ($configuserok eq 'ok') {
20269: if ($switchserver) {
1.130 raeburn 20270: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20271: } else {
20272: if ($author_ok eq 'ok') {
1.421 raeburn 20273: my $modified = [];
1.46 raeburn 20274: my ($result,$scantronurl) =
1.421 raeburn 20275: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20276: $confname,'scantron','','',$custom,
20277: $modified);
1.46 raeburn 20278: if ($result eq 'ok') {
20279: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20280: $changes{'scantronformat'} = 1;
1.421 raeburn 20281: &update_modify_urls($r,$modified);
1.46 raeburn 20282: } else {
20283: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20284: }
20285: } else {
20286: $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);
20287: }
20288: }
20289: } else {
20290: $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);
20291: }
20292: if ($error) {
20293: &Apache::lonnet::logthis($error);
20294: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20295: }
20296: }
1.48 raeburn 20297: if (ref($domconfig{'scantron'}) eq 'HASH') {
20298: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20299: if ($env{'form.scantronformat_del'}) {
20300: $confhash{'scantron'}{'scantronformat'} = '';
20301: $changes{'scantronformat'} = 1;
1.347 raeburn 20302: } else {
20303: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20304: }
20305: }
20306: }
1.347 raeburn 20307: my @options = ('hdr','pad','rem');
1.346 raeburn 20308: my @fields = &scantroncsv_fields();
20309: my %titles = &scantronconfig_titles();
1.347 raeburn 20310: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20311: my ($newdat,$currdat,%newcol,%currcol);
20312: if (grep(/^dat$/,@formats)) {
20313: $confhash{'scantron'}{config}{dat} = 1;
20314: $newdat = 1;
20315: } else {
20316: $newdat = 0;
20317: }
20318: if (grep(/^csv$/,@formats)) {
20319: my %bynum;
20320: foreach my $field (@fields) {
20321: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20322: my $posscol = $1;
20323: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20324: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20325: $bynum{$posscol} = $field;
20326: $newcol{$field} = $posscol;
20327: }
20328: }
20329: }
1.347 raeburn 20330: if (keys(%newcol)) {
20331: foreach my $option (@options) {
20332: if ($env{'form.scantroncsv_'.$option}) {
20333: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20334: }
20335: }
20336: }
1.346 raeburn 20337: }
20338: $currdat = 1;
20339: if (ref($domconfig{'scantron'}) eq 'HASH') {
20340: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20341: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20342: $currdat = 0;
20343: }
20344: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20345: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20346: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20347: }
1.346 raeburn 20348: }
20349: }
20350: }
20351: if ($currdat != $newdat) {
20352: $changes{'config'} = 1;
20353: } else {
20354: foreach my $field (@fields) {
20355: if ($currcol{$field} ne '') {
20356: if ($currcol{$field} ne $newcol{$field}) {
20357: $changes{'config'} = 1;
20358: last;
1.347 raeburn 20359: }
1.346 raeburn 20360: } elsif ($newcol{$field} ne '') {
20361: $changes{'config'} = 1;
20362: last;
20363: }
20364: }
20365: }
1.46 raeburn 20366: if (keys(%confhash) > 0) {
20367: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20368: $dom);
20369: if ($putresult eq 'ok') {
20370: if (keys(%changes) > 0) {
1.48 raeburn 20371: if (ref($confhash{'scantron'}) eq 'HASH') {
20372: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20373: if ($changes{'scantronformat'}) {
20374: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20375: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20376: } else {
20377: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20378: }
20379: }
1.347 raeburn 20380: if ($changes{'config'}) {
1.346 raeburn 20381: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20382: if ($confhash{'scantron'}{'config'}{'dat'}) {
20383: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20384: }
20385: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20386: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20387: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20388: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20389: foreach my $field (@fields) {
20390: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20391: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20392: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20393: }
20394: }
20395: $resulttext .= '</ul></li>';
20396: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20397: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20398: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20399: foreach my $option (@options) {
20400: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20401: $resulttext .= '<li>'.$titles{$option}.'</li>';
20402: }
20403: }
20404: $resulttext .= '</ul></li>';
20405: }
1.346 raeburn 20406: }
20407: }
20408: }
20409: }
20410: } else {
20411: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20412: }
1.46 raeburn 20413: }
1.48 raeburn 20414: $resulttext .= '</ul>';
20415: } else {
1.130 raeburn 20416: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20417: }
20418: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20419: if (ref($lastactref) eq 'HASH') {
20420: $lastactref->{'domainconfig'} = 1;
20421: }
1.46 raeburn 20422: } else {
1.346 raeburn 20423: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20424: }
20425: } else {
20426: $resulttext = '<span class="LC_error">'.
20427: &mt('An error occurred: [_1]',$putresult).'</span>';
20428: }
20429: } else {
1.130 raeburn 20430: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20431: }
20432: if ($errors) {
1.353 raeburn 20433: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20434: $errors.'</ul></p>';
1.46 raeburn 20435: }
20436: return $resulttext;
20437: }
20438:
1.48 raeburn 20439: sub modify_coursecategories {
1.239 raeburn 20440: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20441: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20442: $cathash);
1.48 raeburn 20443: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20444: my @catitems = ('unauth','auth');
20445: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20446: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20447: $cathash = $domconfig{'coursecategories'}{'cats'};
20448: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20449: $changes{'togglecats'} = 1;
20450: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20451: }
20452: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20453: $changes{'categorize'} = 1;
20454: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20455: }
1.120 raeburn 20456: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20457: $changes{'togglecatscomm'} = 1;
20458: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20459: }
20460: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20461: $changes{'categorizecomm'} = 1;
20462: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20463:
20464: }
20465: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20466: $changes{'togglecatsplace'} = 1;
20467: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20468: }
20469: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20470: $changes{'categorizeplace'} = 1;
20471: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20472: }
1.238 raeburn 20473: foreach my $item (@catitems) {
20474: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20475: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20476: $changes{$item} = 1;
20477: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20478: }
20479: }
20480: }
1.57 raeburn 20481: } else {
20482: $changes{'togglecats'} = 1;
20483: $changes{'categorize'} = 1;
1.124 raeburn 20484: $changes{'togglecatscomm'} = 1;
20485: $changes{'categorizecomm'} = 1;
1.272 raeburn 20486: $changes{'togglecatsplace'} = 1;
20487: $changes{'categorizeplace'} = 1;
1.87 raeburn 20488: $domconfig{'coursecategories'} = {
20489: togglecats => $env{'form.togglecats'},
20490: categorize => $env{'form.categorize'},
1.124 raeburn 20491: togglecatscomm => $env{'form.togglecatscomm'},
20492: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20493: togglecatsplace => $env{'form.togglecatsplace'},
20494: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20495: };
1.238 raeburn 20496: foreach my $item (@catitems) {
20497: if ($env{'form.coursecat_'.$item} ne 'std') {
20498: $changes{$item} = 1;
20499: }
20500: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20501: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20502: }
20503: }
1.57 raeburn 20504: }
20505: if (ref($cathash) eq 'HASH') {
20506: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20507: push (@deletecategory,'instcode::0');
20508: }
1.120 raeburn 20509: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20510: push(@deletecategory,'communities::0');
20511: }
1.272 raeburn 20512: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20513: push(@deletecategory,'placement::0');
20514: }
1.48 raeburn 20515: }
1.57 raeburn 20516: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20517: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20518: if (@deletecategory > 0) {
20519: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20520: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20521: foreach my $item (@deletecategory) {
1.57 raeburn 20522: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20523: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20524: $deletions{$item} = 1;
1.57 raeburn 20525: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20526: }
20527: }
20528: }
1.57 raeburn 20529: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20530: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20531: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20532: $reorderings{$item} = 1;
1.57 raeburn 20533: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20534: }
20535: if ($env{'form.addcategory_name_'.$item} ne '') {
20536: my $newcat = $env{'form.addcategory_name_'.$item};
20537: my $newdepth = $depth+1;
20538: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20539: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20540: $adds{$newitem} = 1;
20541: }
20542: if ($env{'form.subcat_'.$item} ne '') {
20543: my $newcat = $env{'form.subcat_'.$item};
20544: my $newdepth = $depth+1;
20545: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20546: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20547: $adds{$newitem} = 1;
20548: }
20549: }
20550: }
20551: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20552: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20553: my $newitem = 'instcode::0';
1.57 raeburn 20554: if ($cathash->{$newitem} eq '') {
20555: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20556: $adds{$newitem} = 1;
20557: }
20558: } else {
20559: my $newitem = 'instcode::0';
1.57 raeburn 20560: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20561: $adds{$newitem} = 1;
20562: }
20563: }
1.120 raeburn 20564: if ($env{'form.communities'} eq '1') {
20565: if (ref($cathash) eq 'HASH') {
20566: my $newitem = 'communities::0';
20567: if ($cathash->{$newitem} eq '') {
20568: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20569: $adds{$newitem} = 1;
20570: }
20571: } else {
20572: my $newitem = 'communities::0';
20573: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20574: $adds{$newitem} = 1;
20575: }
20576: }
1.272 raeburn 20577: if ($env{'form.placement'} eq '1') {
20578: if (ref($cathash) eq 'HASH') {
20579: my $newitem = 'placement::0';
20580: if ($cathash->{$newitem} eq '') {
20581: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20582: $adds{$newitem} = 1;
20583: }
20584: } else {
20585: my $newitem = 'placement::0';
20586: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20587: $adds{$newitem} = 1;
20588: }
20589: }
1.48 raeburn 20590: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20591: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20592: ($env{'form.addcategory_name'} ne 'communities') &&
20593: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20594: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20595: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20596: $adds{$newitem} = 1;
20597: }
1.48 raeburn 20598: }
1.57 raeburn 20599: my $putresult;
1.48 raeburn 20600: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20601: if (keys(%deletions) > 0) {
20602: foreach my $key (keys(%deletions)) {
20603: if ($predelallitems{$key} ne '') {
20604: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20605: }
20606: }
20607: }
20608: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20609: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20610: if (ref($chkcats[0]) eq 'ARRAY') {
20611: my $depth = 0;
20612: my $chg = 0;
20613: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20614: my $name = $chkcats[0][$i];
20615: my $item;
20616: if ($name eq '') {
20617: $chg ++;
20618: } else {
20619: $item = &escape($name).'::0';
20620: if ($chg) {
1.57 raeburn 20621: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20622: }
20623: $depth ++;
1.57 raeburn 20624: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20625: $depth --;
20626: }
20627: }
20628: }
1.57 raeburn 20629: }
20630: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20631: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20632: if ($putresult eq 'ok') {
1.57 raeburn 20633: my %title = (
1.120 raeburn 20634: togglecats => 'Show/Hide a course in catalog',
20635: categorize => 'Assign a category to a course',
20636: togglecatscomm => 'Show/Hide a community in catalog',
20637: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20638: );
20639: my %level = (
1.120 raeburn 20640: dom => 'set in Domain ("Modify Course/Community")',
20641: crs => 'set in Course ("Course Configuration")',
20642: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20643: none => 'No catalog',
20644: std => 'Standard catalog',
20645: domonly => 'Domain-only catalog',
20646: codesrch => 'Code search form',
1.57 raeburn 20647: );
1.48 raeburn 20648: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20649: if ($changes{'togglecats'}) {
20650: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20651: }
20652: if ($changes{'categorize'}) {
20653: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20654: }
1.120 raeburn 20655: if ($changes{'togglecatscomm'}) {
20656: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20657: }
20658: if ($changes{'categorizecomm'}) {
20659: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20660: }
1.238 raeburn 20661: if ($changes{'unauth'}) {
20662: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20663: }
20664: if ($changes{'auth'}) {
20665: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20666: }
1.57 raeburn 20667: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20668: my $cathash;
20669: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20670: $cathash = $domconfig{'coursecategories'}{'cats'};
20671: } else {
20672: $cathash = {};
20673: }
20674: my (@cats,@trails,%allitems);
20675: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20676: if (keys(%deletions) > 0) {
20677: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20678: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20679: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20680: }
20681: $resulttext .= '</ul></li>';
20682: }
20683: if (keys(%reorderings) > 0) {
20684: my %sort_by_trail;
20685: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20686: foreach my $key (keys(%reorderings)) {
20687: if ($allitems{$key} ne '') {
20688: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20689: }
1.48 raeburn 20690: }
1.57 raeburn 20691: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20692: $resulttext .= '<li>'.$trails[$trail].'</li>';
20693: }
20694: $resulttext .= '</ul></li>';
1.48 raeburn 20695: }
1.57 raeburn 20696: if (keys(%adds) > 0) {
20697: my %sort_by_trail;
20698: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20699: foreach my $key (keys(%adds)) {
20700: if ($allitems{$key} ne '') {
20701: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20702: }
20703: }
20704: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20705: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20706: }
1.57 raeburn 20707: $resulttext .= '</ul></li>';
1.48 raeburn 20708: }
1.364 raeburn 20709: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20710: if (ref($lastactref) eq 'HASH') {
20711: $lastactref->{'cats'} = 1;
20712: }
1.48 raeburn 20713: }
20714: $resulttext .= '</ul>';
1.239 raeburn 20715: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20716: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20717: if ($changes{'auth'}) {
20718: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20719: }
20720: if ($changes{'unauth'}) {
20721: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20722: }
20723: my $cachetime = 24*60*60;
20724: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20725: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20726: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20727: }
20728: }
1.48 raeburn 20729: } else {
20730: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20731: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20732: }
20733: } else {
1.120 raeburn 20734: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20735: }
20736: return $resulttext;
20737: }
20738:
1.69 raeburn 20739: sub modify_serverstatuses {
20740: my ($dom,%domconfig) = @_;
20741: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20742: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20743: %currserverstatus = %{$domconfig{'serverstatuses'}};
20744: }
20745: my @pages = &serverstatus_pages();
20746: foreach my $type (@pages) {
20747: $newserverstatus{$type}{'namedusers'} = '';
20748: $newserverstatus{$type}{'machines'} = '';
20749: if (defined($env{'form.'.$type.'_namedusers'})) {
20750: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20751: my @okusers;
20752: foreach my $user (@users) {
20753: my ($uname,$udom) = split(/:/,$user);
20754: if (($udom =~ /^$match_domain$/) &&
20755: (&Apache::lonnet::domain($udom)) &&
20756: ($uname =~ /^$match_username$/)) {
20757: if (!grep(/^\Q$user\E/,@okusers)) {
20758: push(@okusers,$user);
20759: }
20760: }
20761: }
20762: if (@okusers > 0) {
20763: @okusers = sort(@okusers);
20764: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20765: }
20766: }
20767: if (defined($env{'form.'.$type.'_machines'})) {
20768: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20769: my @okmachines;
20770: foreach my $ip (@machines) {
20771: my @parts = split(/\./,$ip);
20772: next if (@parts < 4);
20773: my $badip = 0;
20774: for (my $i=0; $i<4; $i++) {
20775: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20776: $badip = 1;
20777: last;
20778: }
20779: }
20780: if (!$badip) {
20781: push(@okmachines,$ip);
20782: }
20783: }
20784: @okmachines = sort(@okmachines);
20785: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20786: }
20787: }
20788: my %serverstatushash = (
20789: serverstatuses => \%newserverstatus,
20790: );
20791: foreach my $type (@pages) {
1.83 raeburn 20792: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20793: my (@current,@new);
1.83 raeburn 20794: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20795: if ($currserverstatus{$type}{$setting} ne '') {
20796: @current = split(/,/,$currserverstatus{$type}{$setting});
20797: }
20798: }
20799: if ($newserverstatus{$type}{$setting} ne '') {
20800: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20801: }
20802: if (@current > 0) {
20803: if (@new > 0) {
20804: foreach my $item (@current) {
20805: if (!grep(/^\Q$item\E$/,@new)) {
20806: $changes{$type}{$setting} = 1;
1.82 raeburn 20807: last;
20808: }
20809: }
1.84 raeburn 20810: foreach my $item (@new) {
20811: if (!grep(/^\Q$item\E$/,@current)) {
20812: $changes{$type}{$setting} = 1;
20813: last;
1.82 raeburn 20814: }
20815: }
20816: } else {
1.83 raeburn 20817: $changes{$type}{$setting} = 1;
1.69 raeburn 20818: }
1.83 raeburn 20819: } elsif (@new > 0) {
20820: $changes{$type}{$setting} = 1;
1.69 raeburn 20821: }
20822: }
20823: }
20824: if (keys(%changes) > 0) {
1.81 raeburn 20825: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20826: my $putresult = &Apache::lonnet::put_dom('configuration',
20827: \%serverstatushash,$dom);
20828: if ($putresult eq 'ok') {
20829: $resulttext .= &mt('Changes made:').'<ul>';
20830: foreach my $type (@pages) {
1.84 raeburn 20831: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20832: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20833: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20834: if ($newserverstatus{$type}{'namedusers'} eq '') {
20835: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20836: } else {
20837: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20838: }
1.84 raeburn 20839: }
20840: if ($changes{$type}{'machines'}) {
1.69 raeburn 20841: if ($newserverstatus{$type}{'machines'} eq '') {
20842: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20843: } else {
20844: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20845: }
20846:
20847: }
20848: $resulttext .= '</ul></li>';
20849: }
20850: }
20851: $resulttext .= '</ul>';
20852: } else {
20853: $resulttext = '<span class="LC_error">'.
20854: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20855:
20856: }
20857: } else {
20858: $resulttext = &mt('No changes made to access to server status pages');
20859: }
20860: return $resulttext;
20861: }
20862:
1.118 jms 20863: sub modify_helpsettings {
1.285 raeburn 20864: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20865: my ($resulttext,$errors,%changes,%helphash);
20866: my %defaultchecked = ('submitbugs' => 'on');
20867: my @offon = ('off','on');
1.118 jms 20868: my @toggles = ('submitbugs');
1.285 raeburn 20869: my %current = ('submitbugs' => '',
20870: 'adhoc' => {},
20871: );
1.118 jms 20872: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20873: %current = %{$domconfig{'helpsettings'}};
20874: }
1.285 raeburn 20875: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20876: foreach my $item (@toggles) {
20877: if ($defaultchecked{$item} eq 'on') {
20878: if ($current{$item} eq '') {
20879: if ($env{'form.'.$item} eq '0') {
20880: $changes{$item} = 1;
20881: }
20882: } elsif ($current{$item} ne $env{'form.'.$item}) {
20883: $changes{$item} = 1;
20884: }
20885: } elsif ($defaultchecked{$item} eq 'off') {
20886: if ($current{$item} eq '') {
20887: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20888: $changes{$item} = 1;
20889: }
1.282 raeburn 20890: } elsif ($current{$item} ne $env{'form.'.$item}) {
20891: $changes{$item} = 1;
20892: }
20893: }
20894: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20895: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20896: }
20897: }
1.285 raeburn 20898: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20899: my $confname = $dom.'-domainconfig';
20900: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20901: my (@allpos,%newsettings,%changedprivs,$newrole);
20902: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20903: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20904: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20905: my %lt = &Apache::lonlocal::texthash(
20906: s => 'system',
20907: d => 'domain',
20908: order => 'Display order',
20909: access => 'Role usage',
1.291 raeburn 20910: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20911: dh => 'All with domain helpdesk role',
20912: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20913: none => 'None',
20914: status => 'Determined based on institutional status',
20915: inc => 'Include all, but exclude specific personnel',
20916: exc => 'Exclude all, but include specific personnel',
20917: );
20918: for (my $num=0; $num<=$maxnum; $num++) {
20919: my ($prefix,$identifier,$rolename,%curr);
20920: if ($num == $maxnum) {
20921: next unless ($env{'form.newcusthelp'} == $maxnum);
20922: $identifier = 'custhelp'.$num;
20923: $prefix = 'helproles_'.$num;
20924: $rolename = $env{'form.custhelpname'.$num};
20925: $rolename=~s/[^A-Za-z0-9]//gs;
20926: next if ($rolename eq '');
20927: next if (exists($existing{'rolesdef_'.$rolename}));
20928: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20929: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20930: $newprivs{'c'},$confname,$dom);
20931: if ($result ne 'ok') {
20932: $errors .= '<li><span class="LC_error">'.
20933: &mt('An error occurred storing the new custom role: [_1]',
20934: $result).'</span></li>';
20935: next;
20936: } else {
20937: $changedprivs{$rolename} = \%newprivs;
20938: $newrole = $rolename;
20939: }
20940: } else {
20941: $prefix = 'helproles_'.$num;
20942: $rolename = $env{'form.'.$prefix};
20943: next if ($rolename eq '');
20944: next unless (exists($existing{'rolesdef_'.$rolename}));
20945: $identifier = 'custhelp'.$num;
20946: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20947: my %currprivs;
1.289 raeburn 20948: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 20949: split(/\_/,$existing{'rolesdef_'.$rolename});
20950: foreach my $level ('c','d','s') {
20951: if ($newprivs{$level} ne $currprivs{$level}) {
20952: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20953: $newprivs{'c'},$confname,$dom);
20954: if ($result ne 'ok') {
20955: $errors .= '<li><span class="LC_error">'.
20956: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
20957: $rolename,$result).'</span></li>';
20958: } else {
20959: $changedprivs{$rolename} = \%newprivs;
20960: }
20961: last;
20962: }
20963: }
20964: if (ref($current{'adhoc'}) eq 'HASH') {
20965: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20966: %curr = %{$current{'adhoc'}{$rolename}};
20967: }
20968: }
20969: }
20970: my $newpos = $env{'form.'.$prefix.'_pos'};
20971: $newpos =~ s/\D+//g;
20972: $allpos[$newpos] = $rolename;
20973: my $newdesc = $env{'form.'.$prefix.'_desc'};
20974: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
20975: if ($curr{'desc'}) {
20976: if ($curr{'desc'} ne $newdesc) {
20977: $changes{'customrole'}{$rolename}{'desc'} = 1;
20978: $newsettings{$rolename}{'desc'} = $newdesc;
20979: }
20980: } elsif ($newdesc ne '') {
20981: $changes{'customrole'}{$rolename}{'desc'} = 1;
20982: $newsettings{$rolename}{'desc'} = $newdesc;
20983: }
20984: my $access = $env{'form.'.$prefix.'_access'};
20985: if (grep(/^\Q$access\E$/,@accesstypes)) {
20986: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
20987: if ($access eq 'status') {
20988: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
20989: if (scalar(@statuses) == 0) {
1.289 raeburn 20990: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 20991: } else {
20992: my (@shownstatus,$numtypes);
20993: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20994: if (ref($types) eq 'ARRAY') {
20995: $numtypes = scalar(@{$types});
20996: foreach my $type (sort(@statuses)) {
20997: if ($type eq 'default') {
20998: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20999: } elsif (grep(/^\Q$type\E$/,@{$types})) {
21000: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21001: push(@shownstatus,$usertypes->{$type});
21002: }
21003: }
21004: }
21005: if (grep(/^default$/,@statuses)) {
21006: push(@shownstatus,$othertitle);
21007: }
21008: if (scalar(@shownstatus) == 1+$numtypes) {
21009: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
21010: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
21011: } else {
21012: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
21013: if (ref($curr{'status'}) eq 'ARRAY') {
21014: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21015: if (@diffs) {
21016: $changes{'customrole'}{$rolename}{$access} = 1;
21017: }
21018: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21019: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 21020: }
1.166 raeburn 21021: }
21022: }
1.285 raeburn 21023: } elsif (($access eq 'inc') || ($access eq 'exc')) {
21024: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
21025: my @newspecstaff;
21026: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21027: foreach my $person (sort(@personnel)) {
21028: if ($domhelpdesk{$person}) {
21029: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
21030: }
21031: }
21032: if (ref($curr{$access}) eq 'ARRAY') {
21033: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21034: if (@diffs) {
21035: $changes{'customrole'}{$rolename}{$access} = 1;
21036: }
21037: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21038: $changes{'customrole'}{$rolename}{$access} = 1;
21039: }
21040: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21041: my ($uname,$udom) = split(/:/,$person);
21042: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
21043: }
21044: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 21045: }
1.285 raeburn 21046: } else {
21047: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
21048: }
21049: unless ($curr{'access'} eq $access) {
21050: $changes{'customrole'}{$rolename}{'access'} = 1;
21051: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 21052: }
21053: }
1.285 raeburn 21054: if (@allpos > 0) {
21055: my $idx = 0;
21056: foreach my $rolename (@allpos) {
21057: if ($rolename ne '') {
21058: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
21059: if (ref($current{'adhoc'}) eq 'HASH') {
21060: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21061: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
21062: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 21063: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 21064: }
21065: }
1.282 raeburn 21066: }
1.285 raeburn 21067: $idx ++;
1.166 raeburn 21068: }
21069: }
1.118 jms 21070: }
1.123 jms 21071: my $putresult;
21072: if (keys(%changes) > 0) {
1.166 raeburn 21073: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21074: if ($putresult eq 'ok') {
1.285 raeburn 21075: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21076: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21077: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21078: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21079: }
21080: }
21081: my $cachetime = 24*60*60;
21082: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21083: if (ref($lastactref) eq 'HASH') {
21084: $lastactref->{'domdefaults'} = 1;
21085: }
21086: } else {
21087: $errors .= '<li><span class="LC_error">'.
21088: &mt('An error occurred storing the settings: [_1]',
21089: $putresult).'</span></li>';
21090: }
21091: }
21092: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21093: $resulttext = &mt('Changes made:').'<ul>';
21094: my (%shownprivs,@levelorder);
21095: @levelorder = ('c','d','s');
21096: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21097: foreach my $item (sort(keys(%changes))) {
21098: if ($item eq 'submitbugs') {
21099: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21100: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21101: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21102: } elsif ($item eq 'customrole') {
21103: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21104: my @keyorder = ('order','desc','access','status','exc','inc');
21105: my %keytext = &Apache::lonlocal::texthash(
21106: order => 'Order',
21107: desc => 'Role description',
21108: access => 'Role usage',
1.300 droeschl 21109: status => 'Allowed institutional types',
1.285 raeburn 21110: exc => 'Allowed personnel',
21111: inc => 'Disallowed personnel',
21112: );
1.282 raeburn 21113: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21114: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21115: if ($role eq $newrole) {
21116: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21117: $role).'<ul>';
21118: } else {
21119: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21120: $role).'<ul>';
21121: }
21122: foreach my $key (@keyorder) {
21123: if ($changes{'customrole'}{$role}{$key}) {
21124: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21125: $keytext{$key},$newsettings{$role}{$key}).
21126: '</li>';
21127: }
21128: }
21129: if (ref($changedprivs{$role}) eq 'HASH') {
21130: $shownprivs{$role} = 1;
21131: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21132: foreach my $level (@levelorder) {
21133: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21134: next if ($item eq '');
21135: my ($priv) = split(/\&/,$item,2);
21136: if (&Apache::lonnet::plaintext($priv)) {
21137: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21138: unless ($level eq 'c') {
21139: $resulttext .= ' ('.$lt{$level}.')';
21140: }
21141: $resulttext .= '</li>';
21142: }
21143: }
21144: }
21145: $resulttext .= '</ul>';
21146: }
21147: $resulttext .= '</ul></li>';
21148: }
21149: }
21150: }
21151: }
21152: }
21153: }
21154: if (keys(%changedprivs)) {
21155: foreach my $role (sort(keys(%changedprivs))) {
21156: unless ($shownprivs{$role}) {
21157: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21158: $role).'<ul>'.
21159: '<li>'.&mt('Privileges set to :').'<ul>';
21160: foreach my $level (@levelorder) {
21161: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21162: next if ($item eq '');
21163: my ($priv) = split(/\&/,$item,2);
21164: if (&Apache::lonnet::plaintext($priv)) {
21165: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21166: unless ($level eq 'c') {
21167: $resulttext .= ' ('.$lt{$level}.')';
21168: }
21169: $resulttext .= '</li>';
21170: }
1.282 raeburn 21171: }
21172: }
1.285 raeburn 21173: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21174: }
21175: }
21176: }
1.285 raeburn 21177: $resulttext .= '</ul>';
21178: } else {
21179: $resulttext = &mt('No changes made to help settings');
1.118 jms 21180: }
21181: if ($errors) {
1.168 raeburn 21182: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21183: $errors.'</ul>';
1.118 jms 21184: }
21185: return $resulttext;
21186: }
21187:
1.121 raeburn 21188: sub modify_coursedefaults {
1.212 raeburn 21189: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21190: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21191: my %defaultchecked = (
21192: 'canuse_pdfforms' => 'off',
21193: 'uselcmath' => 'on',
1.398 raeburn 21194: 'usejsme' => 'on',
21195: 'inline_chem' => 'on',
1.404 raeburn 21196: 'ltiauth' => 'off',
1.257 raeburn 21197: );
1.404 raeburn 21198: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21199: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21200: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21201: 'coursequota_official','coursequota_unofficial','coursequota_community',
21202: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21203: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21204: 'mysqltables_placement');
1.271 raeburn 21205: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21206: my %staticdefaults = (
21207: anonsurvey_threshold => 10,
21208: uploadquota => 500,
1.428 raeburn 21209: coursequota => 20,
1.257 raeburn 21210: postsubmit => 60,
1.276 raeburn 21211: mysqltables => 172800,
1.422 raeburn 21212: domexttool => 1,
1.432 raeburn 21213: crsauthor => 1,
1.438 raeburn 21214: crseditors => ['edit','xml'],
1.198 raeburn 21215: );
1.314 raeburn 21216: my %texoptions = (
21217: MathJax => 'MathJax',
21218: mimetex => &mt('Convert to Images'),
21219: tth => &mt('TeX to HTML'),
21220: );
1.438 raeburn 21221:
21222: my @editors = ('edit','xml','daxe');
21223: my %editornames = &crseditor_titles();
21224:
1.121 raeburn 21225: $defaultshash{'coursedefaults'} = {};
21226:
21227: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21228: if ($domconfig{'coursedefaults'} eq '') {
21229: $domconfig{'coursedefaults'} = {};
21230: }
21231: }
21232:
21233: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21234: foreach my $item (@toggles) {
21235: if ($defaultchecked{$item} eq 'on') {
21236: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21237: ($env{'form.'.$item} eq '0')) {
21238: $changes{$item} = 1;
1.192 raeburn 21239: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21240: $changes{$item} = 1;
21241: }
21242: } elsif ($defaultchecked{$item} eq 'off') {
21243: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21244: ($env{'form.'.$item} eq '1')) {
21245: $changes{$item} = 1;
21246: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21247: $changes{$item} = 1;
21248: }
21249: }
21250: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21251: }
1.198 raeburn 21252: foreach my $item (@numbers) {
21253: my ($currdef,$newdef);
1.208 raeburn 21254: $newdef = $env{'form.'.$item};
1.198 raeburn 21255: if ($item eq 'anonsurvey_threshold') {
21256: $currdef = $domconfig{'coursedefaults'}{$item};
21257: $newdef =~ s/\D//g;
21258: if ($newdef eq '' || $newdef < 1) {
21259: $newdef = 1;
21260: }
21261: $defaultshash{'coursedefaults'}{$item} = $newdef;
21262: } else {
1.428 raeburn 21263: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21264: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21265: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21266: }
21267: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21268: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21269: }
21270: if ($currdef ne $newdef) {
21271: if ($item eq 'anonsurvey_threshold') {
21272: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21273: $changes{$item} = 1;
21274: }
1.428 raeburn 21275: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21276: my $setting = $1;
1.276 raeburn 21277: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21278: $changes{$setting} = 1;
1.198 raeburn 21279: }
21280: }
1.139 raeburn 21281: }
21282: }
1.314 raeburn 21283: my $texengine;
21284: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21285: $texengine = $env{'form.texengine'};
1.349 raeburn 21286: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21287: if ($currdef eq '') {
21288: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21289: $changes{'texengine'} = 1;
21290: }
1.349 raeburn 21291: } elsif ($currdef ne $texengine) {
1.314 raeburn 21292: $changes{'texengine'} = 1;
21293: }
21294: }
21295: if ($texengine ne '') {
21296: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21297: }
1.264 raeburn 21298: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21299: my @currclonecode;
21300: if (ref($currclone) eq 'HASH') {
21301: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21302: @currclonecode = @{$currclone->{'instcode'}};
21303: }
21304: }
21305: my $newclone;
1.289 raeburn 21306: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21307: $newclone = $env{'form.canclone'};
21308: }
21309: if ($newclone eq 'instcode') {
21310: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21311: my (%codedefaults,@code_order,@clonecode);
21312: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21313: \@code_order);
21314: foreach my $item (@code_order) {
21315: if (grep(/^\Q$item\E$/,@newcodes)) {
21316: push(@clonecode,$item);
21317: }
21318: }
21319: if (@clonecode) {
21320: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21321: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21322: if (@diffs) {
21323: $changes{'canclone'} = 1;
21324: }
21325: } else {
21326: $newclone eq '';
21327: }
21328: } elsif ($newclone ne '') {
1.289 raeburn 21329: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21330: }
1.264 raeburn 21331: if ($newclone ne $currclone) {
21332: $changes{'canclone'} = 1;
21333: }
1.257 raeburn 21334: my %credits;
21335: foreach my $type (@types) {
21336: unless ($type eq 'community') {
21337: $credits{$type} = $env{'form.'.$type.'_credits'};
21338: $credits{$type} =~ s/[^\d.]+//g;
21339: }
21340: }
21341: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21342: ($env{'form.coursecredits'} eq '1')) {
21343: $changes{'coursecredits'} = 1;
21344: foreach my $type (keys(%credits)) {
21345: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21346: }
21347: } else {
1.289 raeburn 21348: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21349: foreach my $type (@types) {
21350: unless ($type eq 'community') {
1.289 raeburn 21351: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21352: $changes{'coursecredits'} = 1;
21353: }
21354: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21355: }
21356: }
21357: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21358: foreach my $type (@types) {
21359: unless ($type eq 'community') {
21360: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21361: $changes{'coursecredits'} = 1;
21362: last;
21363: }
21364: }
21365: }
21366: }
21367: }
21368: if ($env{'form.postsubmit'} eq '1') {
21369: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21370: my %currtimeout;
21371: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21372: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21373: $changes{'postsubmit'} = 1;
21374: }
21375: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21376: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21377: }
21378: } else {
21379: $changes{'postsubmit'} = 1;
21380: }
21381: foreach my $type (@types) {
21382: my $timeout = $env{'form.'.$type.'_timeout'};
21383: $timeout =~ s/\D//g;
21384: if ($timeout == $staticdefaults{'postsubmit'}) {
21385: $timeout = '';
21386: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21387: $timeout = '0';
21388: }
21389: unless ($timeout eq '') {
21390: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21391: }
21392: if (exists($currtimeout{$type})) {
21393: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21394: $changes{'postsubmit'} = 1;
1.257 raeburn 21395: }
21396: } elsif ($timeout ne '') {
21397: $changes{'postsubmit'} = 1;
21398: }
21399: }
21400: } else {
21401: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21402: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21403: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21404: $changes{'postsubmit'} = 1;
21405: }
21406: } else {
21407: $changes{'postsubmit'} = 1;
21408: }
1.192 raeburn 21409: }
1.438 raeburn 21410: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor,
21411: %posscrseditors);
1.422 raeburn 21412: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21413: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 raeburn 21414: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.438 raeburn 21415: map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
1.422 raeburn 21416: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21417: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21418: } else {
21419: foreach my $type (@types) {
21420: if ($staticdefaults{'domexttool'}) {
21421: $olddomexttool{$type} = 1;
21422: } else {
21423: $olddomexttool{$type} = 0;
21424: }
21425: }
21426: }
21427: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21428: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21429: } else {
21430: foreach my $type (@types) {
21431: if ($staticdefaults{'exttool'}) {
21432: $oldexttool{$type} = 1;
21433: } else {
21434: $oldexttool{$type} = 0;
21435: }
21436: }
21437: }
1.432 raeburn 21438: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21439: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
21440: } else {
21441: foreach my $type (@types) {
21442: if ($staticdefaults{'crsauthor'}) {
21443: $oldcrsauthor{$type} = 1;
21444: } else {
21445: $oldcrsauthor{$type} = 0;
21446: }
21447: }
21448: }
1.438 raeburn 21449: my @newcrseditors = ();
21450: foreach my $editor (@editors) {
21451: if ($posscrseditors{$editor}) {
21452: push(@newcrseditors,$editor);
21453: }
21454: }
21455: if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21456: my @diffs =
21457: &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
21458: \@newcrseditors);
21459: if (@diffs) {
21460: $changes{'crseditors'} = 1;
21461: }
21462: } else {
21463: my @diffs =
21464: &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
21465: \@newcrseditors);
21466: unless (@diffs == 0) {
21467: $changes{'crseditors'} = 1;
21468: }
21469: }
1.422 raeburn 21470: foreach my $type (@types) {
21471: unless ($newdomexttool{$type}) {
21472: $newdomexttool{$type} = 0;
21473: }
21474: unless ($newexttool{$type}) {
21475: $newexttool{$type} = 0;
21476: }
1.432 raeburn 21477: unless ($newcrsauthor{$type}) {
21478: $newcrsauthor{$type} = 0;
21479: }
1.422 raeburn 21480: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21481: $changes{'domexttool'} = 1;
21482: }
21483: if ($newexttool{$type} != $oldexttool{$type}) {
21484: $changes{'exttool'} = 1;
21485: }
1.432 raeburn 21486: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
21487: $changes{'crsauthor'} = 1;
21488: }
1.422 raeburn 21489: }
21490: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21491: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 raeburn 21492: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.438 raeburn 21493: $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 21494: }
21495: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21496: $dom);
21497: if ($putresult eq 'ok') {
21498: if (keys(%changes) > 0) {
1.213 raeburn 21499: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21500: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21501: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21502: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21503: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 raeburn 21504: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21505: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21506: 'ltiauth') {
1.257 raeburn 21507: if ($changes{$item}) {
21508: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21509: }
1.289 raeburn 21510: }
1.192 raeburn 21511: if ($changes{'coursecredits'}) {
21512: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21513: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21514: $domdefaults{$type.'credits'} =
21515: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21516: }
21517: }
21518: }
21519: if ($changes{'postsubmit'}) {
21520: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21521: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21522: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21523: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21524: $domdefaults{$type.'postsubtimeout'} =
21525: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21526: }
21527: }
1.192 raeburn 21528: }
21529: }
1.198 raeburn 21530: if ($changes{'uploadquota'}) {
21531: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21532: foreach my $type (@types) {
21533: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21534: }
21535: }
21536: }
1.428 raeburn 21537: if ($changes{'coursequota'}) {
21538: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21539: foreach my $type (@types) {
21540: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21541: }
21542: }
21543: }
1.264 raeburn 21544: if ($changes{'canclone'}) {
21545: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21546: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21547: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21548: if (@clonecodes) {
21549: $domdefaults{'canclone'} = join('+',@clonecodes);
21550: }
21551: }
21552: } else {
21553: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21554: }
21555: }
1.422 raeburn 21556: if ($changes{'domexttool'}) {
21557: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21558: foreach my $type (@types) {
21559: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21560: }
21561: }
21562: }
21563: if ($changes{'exttool'}) {
21564: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21565: foreach my $type (@types) {
21566: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21567: }
21568: }
21569: }
1.432 raeburn 21570: if ($changes{'crsauthor'}) {
21571: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21572: foreach my $type (@types) {
21573: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
21574: }
21575: }
21576: }
1.438 raeburn 21577: if ($changes{'crseditors'}) {
21578: if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21579: $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
21580: }
21581: }
1.121 raeburn 21582: my $cachetime = 24*60*60;
21583: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21584: if (ref($lastactref) eq 'HASH') {
21585: $lastactref->{'domdefaults'} = 1;
21586: }
1.121 raeburn 21587: }
21588: $resulttext = &mt('Changes made:').'<ul>';
21589: foreach my $item (sort(keys(%changes))) {
21590: if ($item eq 'canuse_pdfforms') {
21591: if ($env{'form.'.$item} eq '1') {
21592: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21593: } else {
21594: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21595: }
1.257 raeburn 21596: } elsif ($item eq 'uselcmath') {
21597: if ($env{'form.'.$item} eq '1') {
21598: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21599: } else {
21600: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21601: }
21602: } elsif ($item eq 'usejsme') {
21603: if ($env{'form.'.$item} eq '1') {
21604: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21605: } else {
1.289 raeburn 21606: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21607: }
1.398 raeburn 21608: } elsif ($item eq 'inline_chem') {
21609: if ($env{'form.'.$item} eq '1') {
21610: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21611: } else {
21612: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21613: }
1.314 raeburn 21614: } elsif ($item eq 'texengine') {
21615: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21616: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21617: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21618: }
1.139 raeburn 21619: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21620: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21621: } elsif ($item eq 'uploadquota') {
21622: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21623: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21624: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21625: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21626: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21627: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21628: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21629: '</ul>'.
21630: '</li>';
21631: } else {
21632: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21633: }
1.428 raeburn 21634: } elsif ($item eq 'coursequota') {
21635: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21636: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21637: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21638: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21639: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21640: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21641: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21642: '</ul>'.
21643: '</li>';
21644: } else {
21645: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21646: }
1.276 raeburn 21647: } elsif ($item eq 'mysqltables') {
21648: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21649: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21650: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21651: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21652: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21653: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21654: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21655: '</ul>'.
21656: '</li>';
21657: } else {
21658: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21659: }
1.257 raeburn 21660: } elsif ($item eq 'postsubmit') {
21661: if ($domdefaults{'postsubmit'} eq 'off') {
21662: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21663: } else {
21664: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21665: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21666: $resulttext .= &mt('durations:').'<ul>';
21667: foreach my $type (@types) {
21668: $resulttext .= '<li>';
21669: my $timeout;
21670: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21671: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21672: }
21673: my $display;
21674: if ($timeout eq '0') {
21675: $display = &mt('unlimited');
21676: } elsif ($timeout eq '') {
21677: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21678: } else {
21679: $display = &mt('[quant,_1,second]',$timeout);
21680: }
21681: if ($type eq 'community') {
21682: $resulttext .= &mt('Communities');
21683: } elsif ($type eq 'official') {
21684: $resulttext .= &mt('Official courses');
21685: } elsif ($type eq 'unofficial') {
21686: $resulttext .= &mt('Unofficial courses');
21687: } elsif ($type eq 'textbook') {
21688: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21689: } elsif ($type eq 'placement') {
21690: $resulttext .= &mt('Placement tests');
1.257 raeburn 21691: }
21692: $resulttext .= ' -- '.$display.'</li>';
21693: }
21694: $resulttext .= '</ul>';
21695: }
1.289 raeburn 21696: $resulttext .= '</li>';
1.257 raeburn 21697: }
1.192 raeburn 21698: } elsif ($item eq 'coursecredits') {
21699: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21700: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21701: ($domdefaults{'unofficialcredits'} eq '') &&
21702: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21703: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21704: } else {
21705: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21706: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21707: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21708: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21709: '</ul>'.
21710: '</li>';
21711: }
21712: } else {
21713: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21714: }
1.264 raeburn 21715: } elsif ($item eq 'canclone') {
21716: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21717: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21718: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21719: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21720: }
21721: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21722: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21723: } else {
1.289 raeburn 21724: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21725: }
1.404 raeburn 21726: } elsif ($item eq 'ltiauth') {
21727: if ($env{'form.'.$item} eq '1') {
21728: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21729: } else {
21730: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21731: }
1.432 raeburn 21732: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21733: my @noyes = (&mt('no'),&mt('yes'));
1.432 raeburn 21734: my %status = (
21735: domexttool => {
21736: ishash => &mt('External Tools defined in the domain may be used as follows:'),
21737: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
21738: },
21739: exttool => {
21740: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
21741: default => &mt('External Tools can not be defined in any course types, by default'),
21742: },
21743: crsauthor => {
21744: ishash => &mt('Standard Problems can be created within course containers as follows:'),
21745: default => &mt('Standard Problems can be created within any course type, by default'),
21746: },
21747: );
21748:
21749: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
21750: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
21751: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
21752: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
21753: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
21754: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
21755: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21756: '</ul>'.
21757: '</li>';
21758: } else {
1.432 raeburn 21759: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21760: }
1.438 raeburn 21761: } elsif ($item eq 'crseditors') {
21762: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
21763: my $shown;
21764: if (@{$defaultshash{'coursedefaults'}{$item}}) {
21765: $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
21766: } else {
21767: $shown = &mt('None');
21768: }
21769: $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
21770: }
1.140 raeburn 21771: }
1.121 raeburn 21772: }
21773: $resulttext .= '</ul>';
21774: } else {
21775: $resulttext = &mt('No changes made to course defaults');
21776: }
21777: } else {
21778: $resulttext = '<span class="LC_error">'.
21779: &mt('An error occurred: [_1]',$putresult).'</span>';
21780: }
21781: return $resulttext;
21782: }
21783:
1.231 raeburn 21784: sub modify_selfenrollment {
21785: my ($dom,$lastactref,%domconfig) = @_;
21786: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21787: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21788: my %titles = &tool_titles();
1.232 raeburn 21789: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21790: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21791: $ordered{'default'} = ['types','registered','approval','limit'];
21792:
21793: my (%roles,%shown,%toplevel);
21794: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21795:
21796: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21797: if ($domconfig{'selfenrollment'} eq '') {
21798: $domconfig{'selfenrollment'} = {};
21799: }
21800: }
21801: %toplevel = (
21802: admin => 'Configuration Rights',
21803: default => 'Default settings',
21804: validation => 'Validation of self-enrollment requests',
21805: );
1.233 raeburn 21806: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21807:
21808: if (ref($ordered{'admin'}) eq 'ARRAY') {
21809: foreach my $item (@{$ordered{'admin'}}) {
21810: foreach my $type (@types) {
21811: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21812: $selfenrollhash{'admin'}{$type}{$item} = 1;
21813: } else {
21814: $selfenrollhash{'admin'}{$type}{$item} = 0;
21815: }
21816: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21817: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21818: if ($selfenrollhash{'admin'}{$type}{$item} ne
21819: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21820: push(@{$changes{'admin'}{$type}},$item);
21821: }
21822: } else {
21823: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21824: push(@{$changes{'admin'}{$type}},$item);
21825: }
21826: }
21827: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21828: push(@{$changes{'admin'}{$type}},$item);
21829: }
21830: }
21831: }
21832: }
21833:
21834: foreach my $item (@{$ordered{'default'}}) {
21835: foreach my $type (@types) {
21836: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21837: if ($item eq 'types') {
21838: unless (($value eq 'all') || ($value eq 'dom')) {
21839: $value = '';
21840: }
21841: } elsif ($item eq 'registered') {
21842: unless ($value eq '1') {
21843: $value = 0;
21844: }
21845: } elsif ($item eq 'approval') {
21846: unless ($value =~ /^[012]$/) {
21847: $value = 0;
21848: }
21849: } else {
21850: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21851: $value = 'none';
21852: }
21853: }
21854: $selfenrollhash{'default'}{$type}{$item} = $value;
21855: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21856: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21857: if ($selfenrollhash{'default'}{$type}{$item} ne
21858: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21859: push(@{$changes{'default'}{$type}},$item);
21860: }
21861: } else {
21862: push(@{$changes{'default'}{$type}},$item);
21863: }
21864: } else {
21865: push(@{$changes{'default'}{$type}},$item);
21866: }
21867: if ($item eq 'limit') {
21868: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21869: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21870: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21871: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21872: }
21873: } else {
21874: $selfenrollhash{'default'}{$type}{'cap'} = '';
21875: }
21876: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21877: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21878: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21879: push(@{$changes{'default'}{$type}},'cap');
21880: }
21881: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21882: push(@{$changes{'default'}{$type}},'cap');
21883: }
21884: }
21885: }
21886: }
21887:
21888: foreach my $item (@{$itemsref}) {
21889: if ($item eq 'fields') {
21890: my @changed;
21891: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21892: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21893: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21894: }
21895: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21896: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21897: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21898: $domconfig{'selfenrollment'}{'validation'}{$item});
21899: } else {
21900: @changed = @{$selfenrollhash{'validation'}{$item}};
21901: }
21902: } else {
21903: @changed = @{$selfenrollhash{'validation'}{$item}};
21904: }
21905: if (@changed) {
21906: if ($selfenrollhash{'validation'}{$item}) {
21907: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21908: } else {
21909: $changes{'validation'}{$item} = &mt('None');
21910: }
21911: }
21912: } else {
21913: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21914: if ($item eq 'markup') {
21915: if ($env{'form.selfenroll_validation_'.$item}) {
21916: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21917: }
21918: }
21919: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21920: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21921: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21922: }
21923: }
21924: }
21925: }
21926:
21927: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21928: $dom);
21929: if ($putresult eq 'ok') {
21930: if (keys(%changes) > 0) {
21931: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21932: $resulttext = &mt('Changes made:').'<ul>';
21933: foreach my $key ('admin','default','validation') {
21934: if (ref($changes{$key}) eq 'HASH') {
21935: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
21936: if ($key eq 'validation') {
21937: foreach my $item (@{$itemsref}) {
21938: if (exists($changes{$key}{$item})) {
21939: if ($item eq 'markup') {
21940: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21941: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
21942: } else {
21943: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21944: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
21945: }
21946: }
21947: }
21948: } else {
21949: foreach my $type (@types) {
21950: if ($type eq 'community') {
21951: $roles{'1'} = &mt('Community personnel');
21952: } else {
21953: $roles{'1'} = &mt('Course personnel');
21954: }
21955: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 21956: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21957: if ($key eq 'admin') {
21958: my @mgrdc = ();
21959: if (ref($ordered{$key}) eq 'ARRAY') {
21960: foreach my $item (@{$ordered{'admin'}}) {
21961: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21962: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
21963: push(@mgrdc,$item);
21964: }
21965: }
21966: }
21967: if (@mgrdc) {
21968: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
21969: } else {
21970: delete($domdefaults{$type.'selfenrolladmdc'});
21971: }
21972: }
21973: } else {
21974: if (ref($ordered{$key}) eq 'ARRAY') {
21975: foreach my $item (@{$ordered{$key}}) {
21976: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21977: $domdefaults{$type.'selfenroll'.$item} =
21978: $selfenrollhash{$key}{$type}{$item};
21979: }
21980: }
21981: }
21982: }
21983: }
1.231 raeburn 21984: $resulttext .= '<li>'.$titles{$type}.'<ul>';
21985: foreach my $item (@{$ordered{$key}}) {
21986: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21987: $resulttext .= '<li>';
21988: if ($key eq 'admin') {
21989: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
21990: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
21991: } else {
21992: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
21993: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
21994: }
21995: $resulttext .= '</li>';
21996: }
21997: }
21998: $resulttext .= '</ul></li>';
21999: }
22000: }
22001: $resulttext .= '</ul></li>';
22002: }
22003: }
1.305 raeburn 22004: }
22005: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
22006: my $cachetime = 24*60*60;
22007: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22008: if (ref($lastactref) eq 'HASH') {
22009: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 22010: }
1.231 raeburn 22011: }
22012: $resulttext .= '</ul>';
22013: } else {
22014: $resulttext = &mt('No changes made to self-enrollment settings');
22015: }
22016: } else {
22017: $resulttext = '<span class="LC_error">'.
22018: &mt('An error occurred: [_1]',$putresult).'</span>';
22019: }
22020: return $resulttext;
22021: }
22022:
1.373 raeburn 22023: sub modify_wafproxy {
22024: my ($dom,$action,$lastactref,%domconfig) = @_;
22025: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 22026: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
22027: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 22028: foreach my $server (sort(keys(%servers))) {
22029: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
22030: if ($serverhome eq $server) {
22031: my $serverdom = &Apache::lonnet::host_domain($server);
22032: if ($serverdom eq $dom) {
22033: $canset{$server} = 1;
22034: }
22035: }
22036: }
1.381 raeburn 22037: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
22038: %{$values{$dom}} = ();
22039: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
22040: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
22041: }
1.388 raeburn 22042: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
22043: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
22044: }
1.382 raeburn 22045: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 22046: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
22047: }
22048: }
1.373 raeburn 22049: my $output;
22050: if (keys(%canset)) {
22051: %{$wafproxy{'alias'}} = ();
1.388 raeburn 22052: %{$wafproxy{'saml'}} = ();
1.373 raeburn 22053: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 22054: if ($env{'form.wafproxy_'.$dom}) {
22055: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
22056: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
22057: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
22058: $changes{'alias'} = 1;
22059: }
1.388 raeburn 22060: if ($env{'form.wafproxy_alias_saml_'.$key}) {
22061: $wafproxy{'saml'}{$key} = 1;
22062: }
22063: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
22064: $changes{'saml'} = 1;
22065: }
1.381 raeburn 22066: } else {
22067: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 22068: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 22069: if ($curralias{$key}) {
22070: $changes{'alias'} = 1;
22071: }
1.388 raeburn 22072: if ($currsaml{$key}) {
22073: $changes{'saml'} = 1;
22074: }
1.373 raeburn 22075: }
22076: if ($wafproxy{'alias'}{$key} eq '') {
22077: if ($curralias{$key}) {
22078: $expirecache{$key} = 1;
22079: }
22080: delete($wafproxy{'alias'}{$key});
22081: }
1.388 raeburn 22082: if ($wafproxy{'saml'}{$key} eq '') {
22083: if ($currsaml{$key}) {
22084: $expiresaml{$key} = 1;
22085: }
22086: delete($wafproxy{'saml'}{$key});
22087: }
1.373 raeburn 22088: }
22089: unless (keys(%{$wafproxy{'alias'}})) {
22090: delete($wafproxy{'alias'});
22091: }
1.388 raeburn 22092: unless (keys(%{$wafproxy{'saml'}})) {
22093: delete($wafproxy{'saml'});
22094: }
22095: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 22096: my %warn = (
22097: trusted => 'trusted IP range(s)',
1.381 raeburn 22098: vpnint => 'internal IP range(s) for VPN sessions(s)',
22099: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 22100: );
1.382 raeburn 22101: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22102: my $possible = $env{'form.wafproxy_'.$item};
22103: $possible =~ s/^\s+|\s+$//g;
22104: if ($possible ne '') {
1.381 raeburn 22105: if ($item eq 'remoteip') {
22106: if ($possible =~ /^[mhn]$/) {
22107: $wafproxy{$item} = $possible;
22108: }
22109: } elsif ($item eq 'ipheader') {
22110: if ($wafproxy{'remoteip'} eq 'h') {
22111: $wafproxy{$item} = $possible;
22112: }
1.382 raeburn 22113: } elsif ($item eq 'sslopt') {
22114: if ($possible =~ /^0|1$/) {
22115: $wafproxy{$item} = $possible;
22116: }
1.373 raeburn 22117: } else {
22118: my (@ok,$count);
1.381 raeburn 22119: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
22120: unless ($env{'form.wafproxy_vpnaccess'}) {
22121: $possible = '';
22122: }
22123: } elsif ($item eq 'trusted') {
22124: unless ($wafproxy{'remoteip'} eq 'h') {
22125: $possible = '';
22126: }
22127: }
22128: unless ($possible eq '') {
22129: $possible =~ s/[\r\n]+/\s/g;
22130: $possible =~ s/\s*-\s*/-/g;
22131: $possible =~ s/\s+/,/g;
1.393 raeburn 22132: $possible =~ s/,+/,/g;
1.381 raeburn 22133: }
1.373 raeburn 22134: $count = 0;
1.381 raeburn 22135: if ($possible ne '') {
1.373 raeburn 22136: foreach my $poss (split(/\,/,$possible)) {
22137: $count ++;
1.393 raeburn 22138: $poss = &validate_ip_pattern($poss);
22139: if ($poss ne '') {
1.373 raeburn 22140: push(@ok,$poss);
22141: }
22142: }
22143: my $diff = $count - scalar(@ok);
22144: if ($diff) {
22145: push(@warnings,'<li>'.
22146: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
22147: $diff,$warn{$item}).
22148: '</li>');
22149: }
1.393 raeburn 22150: if (@ok) {
22151: my @cidr_list;
22152: foreach my $item (@ok) {
22153: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
22154: }
22155: $wafproxy{$item} = join(',',@cidr_list);
22156: }
1.373 raeburn 22157: }
22158: }
1.381 raeburn 22159: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 22160: $changes{$item} = 1;
22161: }
1.381 raeburn 22162: } elsif ($currvalue{$item}) {
22163: $changes{$item} = 1;
1.425 raeburn 22164: }
1.381 raeburn 22165: }
22166: } else {
22167: if (keys(%curralias)) {
22168: $changes{'alias'} = 1;
1.388 raeburn 22169: }
22170: if (keys(%currsaml)) {
22171: $changes{'saml'} = 1;
1.425 raeburn 22172: }
1.381 raeburn 22173: if (keys(%currvalue)) {
22174: foreach my $key (keys(%currvalue)) {
22175: $changes{$key} = 1;
1.373 raeburn 22176: }
22177: }
22178: }
22179: if (keys(%changes)) {
22180: my %defaultshash = (
22181: wafproxy => \%wafproxy,
1.425 raeburn 22182: );
1.373 raeburn 22183: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22184: $dom);
22185: if ($putresult eq 'ok') {
22186: my $cachetime = 24*60*60;
22187: my (%domdefaults,$updatedomdefs);
1.382 raeburn 22188: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22189: if ($changes{$item}) {
22190: unless ($updatedomdefs) {
22191: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
22192: $updatedomdefs = 1;
22193: }
22194: if ($wafproxy{$item}) {
22195: $domdefaults{'waf_'.$item} = $wafproxy{$item};
22196: } elsif (exists($domdefaults{'waf_'.$item})) {
22197: delete($domdefaults{'waf_'.$item});
1.425 raeburn 22198: }
1.373 raeburn 22199: }
22200: }
22201: if ($updatedomdefs) {
22202: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22203: if (ref($lastactref) eq 'HASH') {
22204: $lastactref->{'domdefaults'} = 1;
22205: }
22206: }
22207: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22208: my %updates = %expirecache;
22209: foreach my $key (keys(%expirecache)) {
22210: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22211: }
22212: if (ref($wafproxy{'alias'}) eq 'HASH') {
22213: my $cachetime = 24*60*60;
22214: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22215: $updates{$key} = 1;
22216: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22217: $cachetime);
22218: }
22219: }
22220: if (ref($lastactref) eq 'HASH') {
22221: $lastactref->{'proxyalias'} = \%updates;
22222: }
22223: }
1.388 raeburn 22224: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22225: my %samlupdates = %expiresaml;
22226: foreach my $key (keys(%expiresaml)) {
22227: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22228: }
22229: if (ref($wafproxy{'saml'}) eq 'HASH') {
22230: my $cachetime = 24*60*60;
22231: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22232: $samlupdates{$key} = 1;
22233: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22234: $cachetime);
22235: }
22236: }
22237: if (ref($lastactref) eq 'HASH') {
22238: $lastactref->{'proxysaml'} = \%samlupdates;
22239: }
22240: }
1.373 raeburn 22241: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22242: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22243: if ($changes{$item}) {
22244: if ($item eq 'alias') {
22245: my $numaliased = 0;
22246: if (ref($wafproxy{'alias'}) eq 'HASH') {
22247: my $shown;
22248: if (keys(%{$wafproxy{'alias'}})) {
22249: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22250: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22251: &Apache::lonnet::hostname($server),
22252: $wafproxy{'alias'}{$server}).'</li>';
22253: $numaliased ++;
22254: }
22255: if ($numaliased) {
22256: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22257: '<ul>'.$shown.'</ul>').'</li>';
22258: }
22259: }
22260: }
22261: unless ($numaliased) {
22262: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22263: }
1.388 raeburn 22264: } elsif ($item eq 'saml') {
1.425 raeburn 22265: my $shown;
1.388 raeburn 22266: if (ref($wafproxy{'saml'}) eq 'HASH') {
22267: if (keys(%{$wafproxy{'saml'}})) {
22268: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22269: }
22270: }
22271: if ($shown) {
1.396 raeburn 22272: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22273: $shown).'</li>';
22274: } else {
1.396 raeburn 22275: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22276: }
1.373 raeburn 22277: } else {
1.381 raeburn 22278: if ($item eq 'remoteip') {
22279: my %ip_methods = &remoteip_methods();
22280: if ($wafproxy{$item} =~ /^[mh]$/) {
22281: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22282: $ip_methods{$wafproxy{$item}}).'</li>';
22283: } else {
22284: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22285: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22286: '</li>';
22287: } else {
22288: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22289: }
22290: }
22291: } elsif ($item eq 'ipheader') {
1.373 raeburn 22292: if ($wafproxy{$item}) {
1.381 raeburn 22293: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22294: $wafproxy{$item}).'</li>';
22295: } else {
1.381 raeburn 22296: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22297: }
22298: } elsif ($item eq 'trusted') {
22299: if ($wafproxy{$item}) {
1.381 raeburn 22300: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22301: $wafproxy{$item}).'</li>';
22302: } else {
22303: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22304: }
1.381 raeburn 22305: } elsif ($item eq 'vpnint') {
22306: if ($wafproxy{$item}) {
22307: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22308: $wafproxy{$item}).'</li>';
22309: } else {
22310: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22311: }
22312: } elsif ($item eq 'vpnext') {
1.373 raeburn 22313: if ($wafproxy{$item}) {
1.381 raeburn 22314: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22315: $wafproxy{$item}).'</li>';
22316: } else {
1.381 raeburn 22317: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22318: }
1.382 raeburn 22319: } elsif ($item eq 'sslopt') {
22320: if ($wafproxy{$item}) {
22321: $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>';
22322: } else {
22323: $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>';
22324: }
1.373 raeburn 22325: }
22326: }
22327: }
22328: }
1.420 raeburn 22329: $output .= '</ul>';
1.373 raeburn 22330: } else {
22331: $output = '<span class="LC_error">'.
22332: &mt('An error occurred: [_1]',$putresult).'</span>';
22333: }
22334: } elsif (keys(%canset)) {
22335: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22336: }
22337: if (@warnings) {
22338: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22339: join("\n",@warnings).'</ul>';
22340: }
22341: return $output;
22342: }
22343:
22344: sub validate_ip_pattern {
22345: my ($pattern) = @_;
22346: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22347: my ($start,$end) = ($1,$2);
22348: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22349: if (($start !~ m{/}) && ($end !~ m{/})) {
22350: return $start.'-'.$end;
22351: }
22352: }
22353: } elsif ($pattern ne '') {
22354: $pattern = &Net::CIDR::cidrvalidate($pattern);
22355: if ($pattern ne '') {
22356: return $pattern;
1.373 raeburn 22357: }
22358: }
1.393 raeburn 22359: return;
1.373 raeburn 22360: }
22361:
1.137 raeburn 22362: sub modify_usersessions {
1.212 raeburn 22363: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22364: my @hostingtypes = ('version','excludedomain','includedomain');
22365: my @offloadtypes = ('primary','default');
22366: my %types = (
22367: remote => \@hostingtypes,
22368: hosted => \@hostingtypes,
22369: spares => \@offloadtypes,
22370: );
22371: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22372: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22373: my (%by_ip,%by_location,@intdoms,@instdoms);
22374: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22375: my @locations = sort(keys(%by_location));
1.137 raeburn 22376: my (%defaultshash,%changes);
22377: foreach my $prefix (@prefixes) {
22378: $defaultshash{'usersessions'}{$prefix} = {};
22379: }
1.212 raeburn 22380: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22381: my $resulttext;
1.138 raeburn 22382: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22383: foreach my $prefix (@prefixes) {
1.145 raeburn 22384: next if ($prefix eq 'spares');
22385: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22386: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22387: if ($type eq 'version') {
22388: my $value = $env{'form.'.$prefix.'_'.$type};
22389: my $okvalue;
22390: if ($value ne '') {
22391: if (grep(/^\Q$value\E$/,@lcversions)) {
22392: $okvalue = $value;
22393: }
22394: }
22395: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22396: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22397: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22398: if ($inuse == 0) {
22399: $changes{$prefix}{$type} = 1;
22400: } else {
22401: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22402: $changes{$prefix}{$type} = 1;
22403: }
22404: if ($okvalue ne '') {
22405: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22406: }
22407: }
22408: } else {
22409: if (($inuse == 1) && ($okvalue ne '')) {
22410: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22411: $changes{$prefix}{$type} = 1;
22412: }
22413: }
22414: } else {
22415: if (($inuse == 1) && ($okvalue ne '')) {
22416: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22417: $changes{$prefix}{$type} = 1;
22418: }
22419: }
22420: } else {
22421: if (($inuse == 1) && ($okvalue ne '')) {
22422: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22423: $changes{$prefix}{$type} = 1;
22424: }
22425: }
22426: } else {
22427: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22428: my @okvals;
22429: foreach my $val (@vals) {
1.138 raeburn 22430: if ($val =~ /:/) {
22431: my @items = split(/:/,$val);
22432: foreach my $item (@items) {
22433: if (ref($by_location{$item}) eq 'ARRAY') {
22434: push(@okvals,$item);
22435: }
22436: }
22437: } else {
22438: if (ref($by_location{$val}) eq 'ARRAY') {
22439: push(@okvals,$val);
22440: }
1.137 raeburn 22441: }
22442: }
22443: @okvals = sort(@okvals);
22444: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22445: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22446: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22447: if ($inuse == 0) {
22448: $changes{$prefix}{$type} = 1;
22449: } else {
22450: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22451: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22452: if (@changed > 0) {
22453: $changes{$prefix}{$type} = 1;
22454: }
22455: }
22456: } else {
22457: if ($inuse == 1) {
22458: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22459: $changes{$prefix}{$type} = 1;
22460: }
22461: }
22462: } else {
22463: if ($inuse == 1) {
22464: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22465: $changes{$prefix}{$type} = 1;
22466: }
22467: }
22468: } else {
22469: if ($inuse == 1) {
22470: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22471: $changes{$prefix}{$type} = 1;
22472: }
22473: }
22474: }
22475: }
22476: }
1.145 raeburn 22477:
22478: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22479: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22480: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22481: my $savespares;
22482:
22483: foreach my $lonhost (sort(keys(%servers))) {
22484: my $serverhomeID =
22485: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22486: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22487: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22488: my %spareschg;
22489: foreach my $type (@{$types{'spares'}}) {
22490: my @okspares;
22491: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22492: foreach my $server (@checked) {
1.152 raeburn 22493: if (&Apache::lonnet::hostname($server) ne '') {
22494: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22495: unless (grep(/^\Q$server\E$/,@okspares)) {
22496: push(@okspares,$server);
22497: }
1.145 raeburn 22498: }
22499: }
22500: }
22501: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22502: my $newspare;
1.152 raeburn 22503: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22504: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22505: $newspare = $new;
22506: }
22507: }
1.152 raeburn 22508: my @spares;
22509: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22510: @spares = sort(@okspares,$newspare);
22511: } else {
22512: @spares = sort(@okspares);
22513: }
22514: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22515: if (ref($spareid{$lonhost}) eq 'HASH') {
22516: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22517: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22518: if (@diffs > 0) {
22519: $spareschg{$type} = 1;
22520: }
22521: }
22522: }
22523: }
22524: if (keys(%spareschg) > 0) {
22525: $changes{'spares'}{$lonhost} = \%spareschg;
22526: }
22527: }
1.261 raeburn 22528: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22529: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22530: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22531: my @okoffload;
22532: if (@offloadnow) {
22533: foreach my $server (@offloadnow) {
22534: if (&Apache::lonnet::hostname($server) ne '') {
22535: unless (grep(/^\Q$server\E$/,@okoffload)) {
22536: push(@okoffload,$server);
22537: }
22538: }
22539: }
22540: if (@okoffload) {
22541: foreach my $lonhost (@okoffload) {
22542: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22543: }
22544: }
22545: }
1.371 raeburn 22546: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22547: my @okoffloadoth;
22548: if (@offloadoth) {
22549: foreach my $server (@offloadoth) {
22550: if (&Apache::lonnet::hostname($server) ne '') {
22551: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22552: push(@okoffloadoth,$server);
22553: }
22554: }
22555: }
22556: if (@okoffloadoth) {
22557: foreach my $lonhost (@okoffloadoth) {
22558: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22559: }
22560: }
22561: }
1.145 raeburn 22562: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22563: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22564: if (ref($changes{'spares'}) eq 'HASH') {
22565: if (keys(%{$changes{'spares'}}) > 0) {
22566: $savespares = 1;
22567: }
22568: }
22569: } else {
22570: $savespares = 1;
22571: }
1.371 raeburn 22572: foreach my $offload ('offloadnow','offloadoth') {
22573: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22574: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22575: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22576: $changes{$offload} = 1;
22577: last;
22578: }
1.261 raeburn 22579: }
1.371 raeburn 22580: unless ($changes{$offload}) {
22581: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22582: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22583: $changes{$offload} = 1;
22584: last;
22585: }
1.261 raeburn 22586: }
22587: }
1.371 raeburn 22588: } else {
22589: if (($offload eq 'offloadnow') && (@okoffload)) {
22590: $changes{'offloadnow'} = 1;
22591: }
22592: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22593: $changes{'offloadoth'} = 1;
22594: }
1.425 raeburn 22595: }
1.371 raeburn 22596: }
22597: } else {
22598: if (@okoffload) {
1.261 raeburn 22599: $changes{'offloadnow'} = 1;
22600: }
1.371 raeburn 22601: if (@okoffloadoth) {
22602: $changes{'offloadoth'} = 1;
22603: }
1.145 raeburn 22604: }
1.147 raeburn 22605: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22606: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22607: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22608: $dom);
22609: if ($putresult eq 'ok') {
22610: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22611: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22612: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22613: }
22614: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22615: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22616: }
1.261 raeburn 22617: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22618: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22619: }
1.371 raeburn 22620: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22621: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22622: }
1.137 raeburn 22623: }
22624: my $cachetime = 24*60*60;
22625: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22626: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22627: if (ref($lastactref) eq 'HASH') {
22628: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22629: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22630: }
1.147 raeburn 22631: if (keys(%changes) > 0) {
22632: my %lt = &usersession_titles();
22633: $resulttext = &mt('Changes made:').'<ul>';
22634: foreach my $prefix (@prefixes) {
22635: if (ref($changes{$prefix}) eq 'HASH') {
22636: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22637: if ($prefix eq 'spares') {
22638: if (ref($changes{$prefix}) eq 'HASH') {
22639: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22640: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22641: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22642: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22643: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22644: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22645: foreach my $type (@{$types{$prefix}}) {
22646: if ($changes{$prefix}{$lonhost}{$type}) {
22647: my $offloadto = &mt('None');
22648: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22649: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22650: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22651: }
1.145 raeburn 22652: }
1.147 raeburn 22653: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22654: }
1.137 raeburn 22655: }
22656: }
1.147 raeburn 22657: $resulttext .= '</li>';
1.137 raeburn 22658: }
22659: }
1.147 raeburn 22660: } else {
22661: foreach my $type (@{$types{$prefix}}) {
22662: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22663: my ($newvalue,$notinuse);
1.147 raeburn 22664: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22665: if (ref($defaultshash{'usersessions'}{$prefix})) {
22666: if ($type eq 'version') {
22667: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22668: } else {
22669: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22670: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22671: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22672: }
22673: } else {
22674: $notinuse = 1;
1.147 raeburn 22675: }
1.145 raeburn 22676: }
22677: }
22678: }
1.147 raeburn 22679: if ($newvalue eq '') {
22680: if ($type eq 'version') {
22681: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22682: } elsif ($notinuse) {
22683: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22684: } else {
22685: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22686: }
1.145 raeburn 22687: } else {
1.147 raeburn 22688: if ($type eq 'version') {
1.344 raeburn 22689: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22690: }
22691: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22692: }
1.137 raeburn 22693: }
22694: }
22695: }
1.147 raeburn 22696: $resulttext .= '</ul>';
1.137 raeburn 22697: }
22698: }
1.261 raeburn 22699: if ($changes{'offloadnow'}) {
22700: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22701: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22702: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22703: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22704: $resulttext .= '<li>'.$lonhost.'</li>';
22705: }
22706: $resulttext .= '</ul>';
22707: } else {
1.371 raeburn 22708: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22709: }
22710: } else {
22711: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22712: }
22713: }
22714: if ($changes{'offloadoth'}) {
22715: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22716: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22717: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22718: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22719: $resulttext .= '<li>'.$lonhost.'</li>';
22720: }
22721: $resulttext .= '</ul>';
22722: } else {
22723: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22724: }
22725: } else {
1.371 raeburn 22726: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22727: }
22728: }
1.147 raeburn 22729: $resulttext .= '</ul>';
22730: } else {
22731: $resulttext = $nochgmsg;
1.137 raeburn 22732: }
22733: } else {
22734: $resulttext = '<span class="LC_error">'.
22735: &mt('An error occurred: [_1]',$putresult).'</span>';
22736: }
22737: } else {
1.147 raeburn 22738: $resulttext = $nochgmsg;
1.137 raeburn 22739: }
22740: return $resulttext;
22741: }
22742:
1.275 raeburn 22743: sub modify_ssl {
22744: my ($dom,$lastactref,%domconfig) = @_;
22745: my (%by_ip,%by_location,@intdoms,@instdoms);
22746: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22747: my @locations = sort(keys(%by_location));
22748: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22749: my (%defaultshash,%changes);
22750: my $action = 'ssl';
1.293 raeburn 22751: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22752: foreach my $prefix (@prefixes) {
22753: $defaultshash{$action}{$prefix} = {};
22754: }
22755: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22756: my $resulttext;
22757: my %iphost = &Apache::lonnet::get_iphost();
22758: my @reptypes = ('certreq','nocertreq');
22759: my @connecttypes = ('dom','intdom','other');
22760: my %types = (
1.293 raeburn 22761: connto => \@connecttypes,
22762: connfrom => \@connecttypes,
22763: replication => \@reptypes,
1.275 raeburn 22764: );
22765: foreach my $prefix (sort(keys(%types))) {
22766: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22767: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22768: my $value = 'yes';
22769: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22770: $value = $env{'form.'.$prefix.'_'.$type};
22771: }
1.335 raeburn 22772: if (ref($domconfig{$action}) eq 'HASH') {
22773: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22774: if ($domconfig{$action}{$prefix}{$type} ne '') {
22775: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22776: $changes{$prefix}{$type} = 1;
22777: }
22778: $defaultshash{$action}{$prefix}{$type} = $value;
22779: } else {
22780: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22781: $changes{$prefix}{$type} = 1;
22782: }
22783: } else {
22784: $defaultshash{$action}{$prefix}{$type} = $value;
22785: $changes{$prefix}{$type} = 1;
22786: }
22787: } else {
22788: $defaultshash{$action}{$prefix}{$type} = $value;
22789: $changes{$prefix}{$type} = 1;
22790: }
22791: if (($type eq 'dom') && (keys(%servers) == 1)) {
22792: delete($changes{$prefix}{$type});
22793: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22794: delete($changes{$prefix}{$type});
22795: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22796: delete($changes{$prefix}{$type});
22797: }
22798: } elsif ($prefix eq 'replication') {
22799: if (@locations > 0) {
22800: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22801: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22802: my @okvals;
22803: foreach my $val (@vals) {
22804: if ($val =~ /:/) {
22805: my @items = split(/:/,$val);
22806: foreach my $item (@items) {
22807: if (ref($by_location{$item}) eq 'ARRAY') {
22808: push(@okvals,$item);
22809: }
22810: }
22811: } else {
22812: if (ref($by_location{$val}) eq 'ARRAY') {
22813: push(@okvals,$val);
22814: }
22815: }
22816: }
22817: @okvals = sort(@okvals);
22818: if (ref($domconfig{$action}) eq 'HASH') {
22819: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22820: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22821: if ($inuse == 0) {
22822: $changes{$prefix}{$type} = 1;
22823: } else {
22824: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22825: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22826: if (@changed > 0) {
22827: $changes{$prefix}{$type} = 1;
22828: }
22829: }
22830: } else {
22831: if ($inuse == 1) {
22832: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22833: $changes{$prefix}{$type} = 1;
22834: }
22835: }
22836: } else {
22837: if ($inuse == 1) {
22838: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22839: $changes{$prefix}{$type} = 1;
22840: }
22841: }
22842: } else {
22843: if ($inuse == 1) {
22844: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22845: $changes{$prefix}{$type} = 1;
22846: }
22847: }
22848: }
22849: }
22850: }
22851: }
1.336 raeburn 22852: if (keys(%changes)) {
22853: foreach my $prefix (keys(%changes)) {
22854: if (ref($changes{$prefix}) eq 'HASH') {
22855: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22856: delete($changes{$prefix});
22857: }
22858: } else {
22859: delete($changes{$prefix});
22860: }
22861: }
22862: }
1.275 raeburn 22863: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22864: if (keys(%changes) > 0) {
22865: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22866: $dom);
22867: if ($putresult eq 'ok') {
22868: if (ref($defaultshash{$action}) eq 'HASH') {
22869: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22870: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22871: }
1.293 raeburn 22872: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22873: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22874: }
22875: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22876: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22877: }
22878: }
22879: my $cachetime = 24*60*60;
22880: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22881: if (ref($lastactref) eq 'HASH') {
22882: $lastactref->{'domdefaults'} = 1;
22883: }
22884: if (keys(%changes) > 0) {
22885: my %titles = &ssl_titles();
22886: $resulttext = &mt('Changes made:').'<ul>';
22887: foreach my $prefix (@prefixes) {
22888: if (ref($changes{$prefix}) eq 'HASH') {
22889: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22890: foreach my $type (@{$types{$prefix}}) {
22891: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22892: my ($newvalue,$notinuse);
1.275 raeburn 22893: if (ref($defaultshash{$action}) eq 'HASH') {
22894: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22895: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22896: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22897: } else {
22898: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22899: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22900: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22901: }
22902: } else {
22903: $notinuse = 1;
1.275 raeburn 22904: }
22905: }
22906: }
1.344 raeburn 22907: if ($notinuse) {
22908: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22909: } elsif ($newvalue eq '') {
1.275 raeburn 22910: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22911: } else {
22912: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22913: }
22914: }
22915: }
22916: }
22917: $resulttext .= '</ul>';
22918: }
22919: }
22920: } else {
22921: $resulttext = $nochgmsg;
22922: }
22923: } else {
22924: $resulttext = '<span class="LC_error">'.
22925: &mt('An error occurred: [_1]',$putresult).'</span>';
22926: }
22927: } else {
22928: $resulttext = $nochgmsg;
22929: }
22930: return $resulttext;
22931: }
22932:
1.279 raeburn 22933: sub modify_trust {
22934: my ($dom,$lastactref,%domconfig) = @_;
22935: my (%by_ip,%by_location,@intdoms,@instdoms);
22936: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22937: my @locations = sort(keys(%by_location));
22938: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
22939: my @types = ('exc','inc');
22940: my (%defaultshash,%changes);
22941: foreach my $prefix (@prefixes) {
22942: $defaultshash{'trust'}{$prefix} = {};
22943: }
22944: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22945: my $resulttext;
22946: foreach my $prefix (@prefixes) {
22947: foreach my $type (@types) {
22948: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22949: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22950: my @okvals;
22951: foreach my $val (@vals) {
22952: if ($val =~ /:/) {
22953: my @items = split(/:/,$val);
22954: foreach my $item (@items) {
22955: if (ref($by_location{$item}) eq 'ARRAY') {
22956: push(@okvals,$item);
22957: }
22958: }
22959: } else {
22960: if (ref($by_location{$val}) eq 'ARRAY') {
22961: push(@okvals,$val);
22962: }
22963: }
22964: }
22965: @okvals = sort(@okvals);
22966: if (ref($domconfig{'trust'}) eq 'HASH') {
22967: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
22968: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22969: if ($inuse == 0) {
22970: $changes{$prefix}{$type} = 1;
22971: } else {
22972: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22973: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
22974: if (@changed > 0) {
22975: $changes{$prefix}{$type} = 1;
22976: }
22977: }
22978: } else {
22979: if ($inuse == 1) {
22980: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22981: $changes{$prefix}{$type} = 1;
22982: }
22983: }
22984: } else {
22985: if ($inuse == 1) {
22986: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22987: $changes{$prefix}{$type} = 1;
22988: }
22989: }
22990: } else {
22991: if ($inuse == 1) {
22992: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22993: $changes{$prefix}{$type} = 1;
22994: }
22995: }
22996: }
22997: }
22998: my $nochgmsg = &mt('No changes made to trust settings.');
22999: if (keys(%changes) > 0) {
23000: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
23001: $dom);
23002: if ($putresult eq 'ok') {
23003: if (ref($defaultshash{'trust'}) eq 'HASH') {
23004: foreach my $prefix (@prefixes) {
23005: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
23006: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
23007: }
23008: }
23009: }
23010: my $cachetime = 24*60*60;
23011: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 23012: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 23013: if (ref($lastactref) eq 'HASH') {
23014: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 23015: $lastactref->{'trust'} = 1;
1.279 raeburn 23016: }
23017: if (keys(%changes) > 0) {
23018: my %lt = &trust_titles();
23019: $resulttext = &mt('Changes made:').'<ul>';
23020: foreach my $prefix (@prefixes) {
23021: if (ref($changes{$prefix}) eq 'HASH') {
23022: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
23023: foreach my $type (@types) {
23024: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 23025: my ($newvalue,$notinuse);
1.279 raeburn 23026: if (ref($defaultshash{'trust'}) eq 'HASH') {
23027: if (ref($defaultshash{'trust'}{$prefix})) {
23028: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23029: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
23030: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
23031: }
1.344 raeburn 23032: } else {
23033: $notinuse = 1;
1.279 raeburn 23034: }
23035: }
23036: }
1.344 raeburn 23037: if ($notinuse) {
23038: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
23039: } elsif ($newvalue eq '') {
1.279 raeburn 23040: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
23041: } else {
23042: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
23043: }
23044: }
23045: }
23046: $resulttext .= '</ul>';
23047: }
23048: }
23049: $resulttext .= '</ul>';
23050: } else {
23051: $resulttext = $nochgmsg;
23052: }
23053: } else {
23054: $resulttext = '<span class="LC_error">'.
23055: &mt('An error occurred: [_1]',$putresult).'</span>';
23056: }
23057: } else {
23058: $resulttext = $nochgmsg;
23059: }
23060: return $resulttext;
23061: }
23062:
1.150 raeburn 23063: sub modify_loadbalancing {
23064: my ($dom,%domconfig) = @_;
23065: my $primary_id = &Apache::lonnet::domain($dom,'primary');
23066: my $intdom = &Apache::lonnet::internet_dom($primary_id);
23067: my ($othertitle,$usertypes,$types) =
23068: &Apache::loncommon::sorted_inst_types($dom);
23069: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 23070: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 23071: my @sparestypes = ('primary','default');
23072: my %typetitles = &sparestype_titles();
23073: my $resulttext;
1.342 raeburn 23074: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23075: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23076: %existing = %{$domconfig{'loadbalancing'}};
23077: }
23078: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 23079: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 23080: my ($saveloadbalancing,%defaultshash,%changes);
23081: my ($alltypes,$othertypes,$titles) =
23082: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
23083: my %ruletitles = &offloadtype_text();
23084: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
23085: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
23086: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
23087: if ($balancer eq '') {
23088: next;
23089: }
1.210 raeburn 23090: if (!exists($servers{$balancer})) {
1.171 raeburn 23091: if (exists($currbalancer{$balancer})) {
23092: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 23093: }
1.171 raeburn 23094: next;
23095: }
23096: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
23097: push(@{$changes{'delete'}},$balancer);
23098: next;
23099: }
23100: if (!exists($currbalancer{$balancer})) {
23101: push(@{$changes{'add'}},$balancer);
23102: }
23103: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
23104: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
23105: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
23106: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23107: $saveloadbalancing = 1;
23108: }
23109: foreach my $sparetype (@sparestypes) {
23110: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
23111: my @offloadto;
23112: foreach my $target (@targets) {
23113: if (($servers{$target}) && ($target ne $balancer)) {
23114: if ($sparetype eq 'default') {
23115: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
23116: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 23117: }
23118: }
1.171 raeburn 23119: unless(grep(/^\Q$target\E$/,@offloadto)) {
23120: push(@offloadto,$target);
23121: }
1.150 raeburn 23122: }
23123: }
1.284 raeburn 23124: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
23125: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
23126: push(@offloadto,$balancer);
23127: }
23128: }
23129: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 23130: }
1.342 raeburn 23131: if ($env{'form.loadbalancing_cookie_'.$i}) {
23132: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 23133: if (exists($currbalancer{$balancer})) {
1.342 raeburn 23134: unless ($currcookies{$balancer}) {
23135: $changes{'curr'}{$balancer}{'cookie'} = 1;
23136: }
23137: }
23138: } elsif (exists($currbalancer{$balancer})) {
23139: if ($currcookies{$balancer}) {
23140: $changes{'curr'}{$balancer}{'cookie'} = 1;
23141: }
23142: }
1.171 raeburn 23143: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 23144: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23145: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
23146: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 23147: if (@targetdiffs > 0) {
1.171 raeburn 23148: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23149: }
1.171 raeburn 23150: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23151: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23152: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23153: }
23154: }
23155: }
23156: } else {
1.171 raeburn 23157: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 23158: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23159: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23160: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23161: $changes{'curr'}{$balancer}{'targets'} = 1;
23162: }
1.150 raeburn 23163: }
23164: }
1.210 raeburn 23165: }
1.150 raeburn 23166: }
23167: my $ishomedom;
1.171 raeburn 23168: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
23169: $ishomedom = 1;
1.150 raeburn 23170: }
23171: if (ref($alltypes) eq 'ARRAY') {
23172: foreach my $type (@{$alltypes}) {
23173: my $rule;
1.210 raeburn 23174: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 23175: (!$ishomedom)) {
1.171 raeburn 23176: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
23177: }
23178: if ($rule eq 'specific') {
1.255 raeburn 23179: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 23180: if (exists($servers{$specifiedhost})) {
1.255 raeburn 23181: $rule = $specifiedhost;
23182: }
1.150 raeburn 23183: }
1.171 raeburn 23184: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
23185: if (ref($currrules{$balancer}) eq 'HASH') {
23186: if ($rule ne $currrules{$balancer}{$type}) {
23187: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23188: }
23189: } elsif ($rule ne '') {
1.171 raeburn 23190: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23191: }
23192: }
23193: }
1.171 raeburn 23194: }
23195: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
23196: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
23197: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23198: $defaultshash{'loadbalancing'} = {};
23199: }
23200: my $putresult = &Apache::lonnet::put_dom('configuration',
23201: \%defaultshash,$dom);
23202: if ($putresult eq 'ok') {
23203: if (keys(%changes) > 0) {
1.252 raeburn 23204: my %toupdate;
1.171 raeburn 23205: if (ref($changes{'delete'}) eq 'ARRAY') {
23206: foreach my $balancer (sort(@{$changes{'delete'}})) {
23207: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23208: $toupdate{$balancer} = 1;
1.150 raeburn 23209: }
1.171 raeburn 23210: }
23211: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23212: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23213: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23214: $toupdate{$balancer} = 1;
1.171 raeburn 23215: }
23216: }
23217: if (ref($changes{'curr'}) eq 'HASH') {
23218: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23219: $toupdate{$balancer} = 1;
1.171 raeburn 23220: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23221: if ($changes{'curr'}{$balancer}{'targets'}) {
23222: my %offloadstr;
23223: foreach my $sparetype (@sparestypes) {
23224: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23225: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23226: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23227: }
23228: }
1.150 raeburn 23229: }
1.171 raeburn 23230: if (keys(%offloadstr) == 0) {
23231: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23232: } else {
1.171 raeburn 23233: my $showoffload;
23234: foreach my $sparetype (@sparestypes) {
23235: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23236: if (defined($offloadstr{$sparetype})) {
23237: $showoffload .= $offloadstr{$sparetype};
23238: } else {
23239: $showoffload .= &mt('None');
23240: }
23241: $showoffload .= (' 'x3);
23242: }
23243: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23244: }
23245: }
23246: }
1.171 raeburn 23247: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23248: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23249: foreach my $type (@{$alltypes}) {
23250: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23251: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23252: my $balancetext;
23253: if ($rule eq '') {
23254: $balancetext = $ruletitles{'default'};
1.209 raeburn 23255: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23256: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23257: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23258: foreach my $sparetype (@sparestypes) {
23259: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23260: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23261: }
23262: }
1.253 raeburn 23263: foreach my $item (@{$alltypes}) {
23264: next if ($item =~ /^_LC_ipchange/);
23265: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23266: if ($hasrule eq 'homeserver') {
23267: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23268: } else {
23269: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23270: if ($servers{$hasrule}) {
23271: $toupdate{$hasrule} = 1;
23272: }
23273: }
23274: }
23275: }
1.254 raeburn 23276: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23277: $balancetext = $ruletitles{$rule};
23278: } else {
23279: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23280: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23281: if ($receiver) {
23282: $toupdate{$receiver};
23283: }
23284: }
23285: } else {
23286: $balancetext = $ruletitles{$rule};
1.252 raeburn 23287: }
1.171 raeburn 23288: } else {
23289: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23290: }
1.210 raeburn 23291: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23292: }
23293: }
23294: }
23295: }
1.342 raeburn 23296: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23297: if ($currcookies{$balancer}) {
23298: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23299: $balancer).'</li>';
23300: } else {
23301: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23302: $balancer).'</li>';
23303: }
1.342 raeburn 23304: }
1.375 raeburn 23305: }
23306: }
23307: if (keys(%toupdate)) {
23308: my %thismachine;
23309: my $updatedhere;
23310: my $cachetime = 60*60*24;
23311: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23312: foreach my $lonhost (keys(%toupdate)) {
23313: if ($thismachine{$lonhost}) {
23314: unless ($updatedhere) {
23315: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23316: $defaultshash{'loadbalancing'},
23317: $cachetime);
23318: $updatedhere = 1;
1.252 raeburn 23319: }
1.375 raeburn 23320: } else {
23321: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23322: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23323: }
1.150 raeburn 23324: }
1.171 raeburn 23325: }
23326: if ($resulttext ne '') {
23327: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23328: } else {
23329: $resulttext = $nochgmsg;
23330: }
23331: } else {
1.171 raeburn 23332: $resulttext = $nochgmsg;
1.150 raeburn 23333: }
23334: } else {
1.171 raeburn 23335: $resulttext = '<span class="LC_error">'.
23336: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23337: }
23338: } else {
1.171 raeburn 23339: $resulttext = $nochgmsg;
1.150 raeburn 23340: }
23341: return $resulttext;
23342: }
23343:
1.48 raeburn 23344: sub recurse_check {
23345: my ($chkcats,$categories,$depth,$name) = @_;
23346: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23347: my $chg = 0;
23348: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23349: my $category = $chkcats->[$depth]{$name}[$j];
23350: my $item;
23351: if ($category eq '') {
23352: $chg ++;
23353: } else {
23354: my $deeper = $depth + 1;
23355: $item = &escape($category).':'.&escape($name).':'.$depth;
23356: if ($chg) {
23357: $categories->{$item} -= $chg;
23358: }
23359: &recurse_check($chkcats,$categories,$deeper,$category);
23360: $deeper --;
23361: }
23362: }
23363: }
23364: return;
23365: }
23366:
23367: sub recurse_cat_deletes {
23368: my ($item,$coursecategories,$deletions) = @_;
23369: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23370: my $subdepth = $depth + 1;
23371: if (ref($coursecategories) eq 'HASH') {
23372: foreach my $subitem (keys(%{$coursecategories})) {
23373: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23374: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23375: delete($coursecategories->{$subitem});
23376: $deletions->{$subitem} = 1;
23377: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23378: }
1.48 raeburn 23379: }
23380: }
23381: return;
23382: }
23383:
1.125 raeburn 23384: sub active_dc_picker {
1.191 raeburn 23385: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23386: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23387: my @domcoord = keys(%domcoords);
23388: if (keys(%currhash)) {
23389: foreach my $dc (keys(%currhash)) {
23390: unless (exists($domcoords{$dc})) {
23391: push(@domcoord,$dc);
23392: }
23393: }
23394: }
23395: @domcoord = sort(@domcoord);
1.210 raeburn 23396: my $numdcs = scalar(@domcoord);
1.191 raeburn 23397: my $rows = 0;
23398: my $table;
1.125 raeburn 23399: if ($numdcs > 1) {
1.191 raeburn 23400: $table = '<table>';
23401: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23402: my $rem = $i%($numinrow);
23403: if ($rem == 0) {
23404: if ($i > 0) {
1.191 raeburn 23405: $table .= '</tr>';
1.125 raeburn 23406: }
1.191 raeburn 23407: $table .= '<tr>';
23408: $rows ++;
1.125 raeburn 23409: }
1.191 raeburn 23410: my $check = '';
23411: if ($inputtype eq 'radio') {
23412: if (keys(%currhash) == 0) {
23413: if (!$i) {
23414: $check = ' checked="checked"';
23415: }
23416: } elsif (exists($currhash{$domcoord[$i]})) {
23417: $check = ' checked="checked"';
23418: }
23419: } else {
23420: if (exists($currhash{$domcoord[$i]})) {
23421: $check = ' checked="checked"';
1.125 raeburn 23422: }
23423: }
1.191 raeburn 23424: if ($i == @domcoord - 1) {
1.125 raeburn 23425: my $colsleft = $numinrow - $rem;
23426: if ($colsleft > 1) {
1.191 raeburn 23427: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23428: } else {
1.191 raeburn 23429: $table .= '<td class="LC_left_item">';
1.125 raeburn 23430: }
23431: } else {
1.191 raeburn 23432: $table .= '<td class="LC_left_item">';
23433: }
23434: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23435: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23436: $table .= '<span class="LC_nobreak"><label>'.
23437: '<input type="'.$inputtype.'" name="'.$name.'"'.
23438: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23439: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23440: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23441: }
1.219 raeburn 23442: $table .= '</label></span></td>';
1.191 raeburn 23443: }
23444: $table .= '</tr></table>';
23445: } elsif ($numdcs == 1) {
1.219 raeburn 23446: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23447: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23448: if ($inputtype eq 'radio') {
1.247 raeburn 23449: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23450: if ($user ne $dcname.':'.$dcdom) {
23451: $table .= ' ('.$dcname.':'.$dcdom.')';
23452: }
1.191 raeburn 23453: } else {
23454: my $check;
23455: if (exists($currhash{$domcoord[0]})) {
23456: $check = ' checked="checked"';
1.125 raeburn 23457: }
1.247 raeburn 23458: $table = '<span class="LC_nobreak"><label>'.
23459: '<input type="checkbox" name="'.$name.'" '.
23460: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23461: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23462: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23463: }
1.220 raeburn 23464: $table .= '</label></span>';
1.191 raeburn 23465: $rows ++;
1.125 raeburn 23466: }
23467: }
1.191 raeburn 23468: return ($numdcs,$table,$rows);
1.125 raeburn 23469: }
23470:
1.137 raeburn 23471: sub usersession_titles {
23472: return &Apache::lonlocal::texthash(
23473: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23474: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23475: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23476: version => 'LON-CAPA version requirement',
1.138 raeburn 23477: excludedomain => 'Allow all, but exclude specific domains',
23478: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23479: primary => 'Primary (checked first)',
1.154 raeburn 23480: default => 'Default',
1.137 raeburn 23481: );
23482: }
23483:
1.152 raeburn 23484: sub id_for_thisdom {
23485: my (%servers) = @_;
23486: my %altids;
23487: foreach my $server (keys(%servers)) {
23488: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23489: if ($serverhome ne $server) {
23490: $altids{$serverhome} = $server;
23491: }
23492: }
23493: return %altids;
23494: }
23495:
1.150 raeburn 23496: sub count_servers {
23497: my ($currbalancer,%servers) = @_;
23498: my (@spares,$numspares);
23499: foreach my $lonhost (sort(keys(%servers))) {
23500: next if ($currbalancer eq $lonhost);
23501: push(@spares,$lonhost);
23502: }
23503: if ($currbalancer) {
23504: $numspares = scalar(@spares);
23505: } else {
23506: $numspares = scalar(@spares) - 1;
23507: }
23508: return ($numspares,@spares);
23509: }
23510:
23511: sub lonbalance_targets_js {
1.171 raeburn 23512: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23513: my $select = &mt('Select');
23514: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23515: if (ref($servers) eq 'HASH') {
23516: $alltargets = join("','",sort(keys(%{$servers})));
23517: my @homedoms;
23518: foreach my $server (sort(keys(%{$servers}))) {
23519: if (&Apache::lonnet::host_domain($server) eq $dom) {
23520: push(@homedoms,'1');
23521: } else {
23522: push(@homedoms,'0');
23523: }
23524: }
23525: $allishome = join("','",@homedoms);
23526: }
23527: if (ref($types) eq 'ARRAY') {
23528: if (@{$types} > 0) {
23529: @alltypes = @{$types};
23530: }
23531: }
23532: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23533: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23534: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23535: if (ref($settings) eq 'HASH') {
23536: %existing = %{$settings};
23537: }
23538: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23539: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23540: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23541: return <<"END";
23542:
23543: <script type="text/javascript">
23544: // <![CDATA[
23545:
1.171 raeburn 23546: currBalancers = new Array('$balancers');
23547:
23548: function toggleTargets(balnum) {
23549: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23550: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23551: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23552: var prevbalancer = prevhostitem.value;
23553: var baltotal = document.getElementById('loadbalancing_total').value;
23554: prevhostitem.value = balancer;
23555: if (prevbalancer != '') {
23556: var prevIdx = currBalancers.indexOf(prevbalancer);
23557: if (prevIdx != -1) {
23558: currBalancers.splice(prevIdx,1);
23559: }
23560: }
1.150 raeburn 23561: if (balancer == '') {
1.171 raeburn 23562: hideSpares(balnum);
1.150 raeburn 23563: } else {
1.171 raeburn 23564: var currIdx = currBalancers.indexOf(balancer);
23565: if (currIdx == -1) {
23566: currBalancers.push(balancer);
23567: }
1.150 raeburn 23568: var homedoms = new Array('$allishome');
1.171 raeburn 23569: var ishomedom = homedoms[lonhostitem.selectedIndex];
23570: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23571: }
1.171 raeburn 23572: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23573: return;
23574: }
23575:
1.171 raeburn 23576: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23577: var alltargets = new Array('$alltargets');
23578: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23579: var offloadtypes = new Array('primary','default');
23580:
1.171 raeburn 23581: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23582: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23583:
1.151 raeburn 23584: for (var i=0; i<offloadtypes.length; i++) {
23585: var count = 0;
23586: for (var j=0; j<alltargets.length; j++) {
23587: if (alltargets[j] != balancer) {
1.171 raeburn 23588: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23589: item.value = alltargets[j];
23590: item.style.textAlign='left';
23591: item.style.textFace='normal';
23592: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23593: if (currBalancers.indexOf(alltargets[j]) == -1) {
23594: item.disabled = '';
23595: } else {
23596: item.disabled = 'disabled';
23597: item.checked = false;
23598: }
1.151 raeburn 23599: count ++;
23600: }
1.150 raeburn 23601: }
23602: }
1.151 raeburn 23603: for (var k=0; k<insttypes.length; k++) {
23604: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23605: if (ishomedom == 1) {
1.171 raeburn 23606: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23607: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23608: } else {
1.171 raeburn 23609: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23610: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23611: }
23612: } else {
1.171 raeburn 23613: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23614: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23615: }
1.151 raeburn 23616: if ((insttypes[k] != '_LC_external') &&
23617: ((insttypes[k] != '_LC_internetdom') ||
23618: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23619: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23620: item.options.length = 0;
23621: item.options[0] = new Option("","",true,true);
1.210 raeburn 23622: var idx = 0;
1.151 raeburn 23623: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23624: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23625: idx ++;
23626: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23627: }
23628: }
23629: }
23630: }
23631: return;
23632: }
23633:
1.171 raeburn 23634: function hideSpares(balnum) {
1.150 raeburn 23635: var alltargets = new Array('$alltargets');
23636: var insttypes = new Array('$allinsttypes');
23637: var offloadtypes = new Array('primary','default');
23638:
1.171 raeburn 23639: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23640: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23641:
23642: var total = alltargets.length - 1;
23643: for (var i=0; i<offloadtypes; i++) {
23644: for (var j=0; j<total; j++) {
1.171 raeburn 23645: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23646: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23647: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23648: }
1.150 raeburn 23649: }
23650: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23651: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23652: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23653: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23654: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23655: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23656: }
23657: }
23658: return;
23659: }
23660:
1.171 raeburn 23661: function checkOffloads(item,balnum,type) {
1.150 raeburn 23662: var alltargets = new Array('$alltargets');
23663: var offloadtypes = new Array('primary','default');
23664: if (item.checked) {
23665: var total = alltargets.length - 1;
23666: var other;
23667: if (type == offloadtypes[0]) {
1.151 raeburn 23668: other = offloadtypes[1];
1.150 raeburn 23669: } else {
1.151 raeburn 23670: other = offloadtypes[0];
1.150 raeburn 23671: }
23672: for (var i=0; i<total; i++) {
1.171 raeburn 23673: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23674: if (server == item.value) {
1.171 raeburn 23675: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23676: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23677: }
23678: }
23679: }
23680: }
23681: return;
23682: }
23683:
1.171 raeburn 23684: function singleServerToggle(balnum,type) {
23685: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23686: if (offloadtoSelIdx == 0) {
1.171 raeburn 23687: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23688: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23689:
23690: } else {
1.171 raeburn 23691: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23692: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23693: }
23694: return;
23695: }
23696:
1.171 raeburn 23697: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23698: if (type == '_LC_external') {
1.171 raeburn 23699: return;
1.150 raeburn 23700: }
1.171 raeburn 23701: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23702: for (var i=0; i<typesRules.length; i++) {
23703: if (formname.elements[typesRules[i]].checked) {
23704: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23705: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23706: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23707: } else {
1.171 raeburn 23708: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23709: }
23710: }
23711: }
23712: return;
23713: }
23714:
23715: function balancerDeleteChange(balnum) {
23716: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23717: var baltotal = document.getElementById('loadbalancing_total').value;
23718: var addtarget;
23719: var removetarget;
23720: var action = 'delete';
23721: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23722: var lonhost = hostitem.value;
23723: var currIdx = currBalancers.indexOf(lonhost);
23724: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23725: if (currIdx != -1) {
23726: currBalancers.splice(currIdx,1);
23727: }
23728: addtarget = lonhost;
23729: } else {
23730: if (currIdx == -1) {
23731: currBalancers.push(lonhost);
23732: }
23733: removetarget = lonhost;
23734: action = 'undelete';
23735: }
23736: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23737: }
23738: return;
23739: }
23740:
23741: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23742: if (baltotal > 1) {
23743: var offloadtypes = new Array('primary','default');
23744: var alltargets = new Array('$alltargets');
23745: var insttypes = new Array('$allinsttypes');
23746: for (var i=0; i<baltotal; i++) {
23747: if (i != balnum) {
23748: for (var j=0; j<offloadtypes.length; j++) {
23749: var total = alltargets.length - 1;
23750: for (var k=0; k<total; k++) {
23751: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23752: var server = serveritem.value;
23753: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23754: if (server == addtarget) {
23755: serveritem.disabled = '';
23756: }
23757: }
23758: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23759: if (server == removetarget) {
23760: serveritem.disabled = 'disabled';
23761: serveritem.checked = false;
23762: }
23763: }
23764: }
23765: }
23766: for (var j=0; j<insttypes.length; j++) {
23767: if (insttypes[j] != '_LC_external') {
23768: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23769: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23770: var currSel = singleserver.selectedIndex;
23771: var currVal = singleserver.options[currSel].value;
23772: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23773: var numoptions = singleserver.options.length;
23774: var needsnew = 1;
23775: for (var k=0; k<numoptions; k++) {
23776: if (singleserver.options[k] == addtarget) {
23777: needsnew = 0;
23778: break;
23779: }
23780: }
23781: if (needsnew == 1) {
23782: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23783: }
23784: }
23785: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23786: singleserver.options.length = 0;
23787: if ((currVal) && (currVal != removetarget)) {
23788: singleserver.options[0] = new Option("","",false,false);
23789: } else {
23790: singleserver.options[0] = new Option("","",true,true);
23791: }
23792: var idx = 0;
23793: for (var m=0; m<alltargets.length; m++) {
23794: if (currBalancers.indexOf(alltargets[m]) == -1) {
23795: idx ++;
23796: if (currVal == alltargets[m]) {
23797: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23798: } else {
23799: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23800: }
23801: }
23802: }
23803: }
23804: }
23805: }
23806: }
1.150 raeburn 23807: }
23808: }
23809: }
23810: return;
23811: }
23812:
1.152 raeburn 23813: // ]]>
23814: </script>
23815:
23816: END
23817: }
23818:
23819: sub new_spares_js {
23820: my @sparestypes = ('primary','default');
23821: my $types = join("','",@sparestypes);
23822: my $select = &mt('Select');
23823: return <<"END";
23824:
23825: <script type="text/javascript">
23826: // <![CDATA[
23827:
23828: function updateNewSpares(formname,lonhost) {
23829: var types = new Array('$types');
23830: var include = new Array();
23831: var exclude = new Array();
23832: for (var i=0; i<types.length; i++) {
23833: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23834: for (var j=0; j<spareboxes.length; j++) {
23835: if (formname.elements[spareboxes[j]].checked) {
23836: exclude.push(formname.elements[spareboxes[j]].value);
23837: } else {
23838: include.push(formname.elements[spareboxes[j]].value);
23839: }
23840: }
23841: }
23842: for (var i=0; i<types.length; i++) {
23843: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23844: var selIdx = newSpare.selectedIndex;
23845: var currnew = newSpare.options[selIdx].value;
23846: var okSpares = new Array();
23847: for (var j=0; j<newSpare.options.length; j++) {
23848: var possible = newSpare.options[j].value;
23849: if (possible != '') {
23850: if (exclude.indexOf(possible) == -1) {
23851: okSpares.push(possible);
23852: } else {
23853: if (currnew == possible) {
23854: selIdx = 0;
23855: }
23856: }
23857: }
23858: }
23859: for (var k=0; k<include.length; k++) {
23860: if (okSpares.indexOf(include[k]) == -1) {
23861: okSpares.push(include[k]);
23862: }
23863: }
23864: okSpares.sort();
23865: newSpare.options.length = 0;
23866: if (selIdx == 0) {
23867: newSpare.options[0] = new Option("$select","",true,true);
23868: } else {
23869: newSpare.options[0] = new Option("$select","",false,false);
23870: }
23871: for (var m=0; m<okSpares.length; m++) {
23872: var idx = m+1;
23873: var selThis = 0;
23874: if (selIdx != 0) {
23875: if (okSpares[m] == currnew) {
23876: selThis = 1;
23877: }
23878: }
23879: if (selThis == 1) {
23880: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23881: } else {
23882: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23883: }
23884: }
23885: }
23886: return;
23887: }
23888:
23889: function checkNewSpares(lonhost,type) {
23890: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23891: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23892: if (chosen != '') {
1.152 raeburn 23893: var othertype;
23894: var othernewSpare;
23895: if (type == 'primary') {
23896: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23897: }
23898: if (type == 'default') {
23899: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23900: }
23901: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23902: othernewSpare.selectedIndex = 0;
23903: }
23904: }
23905: return;
23906: }
23907:
23908: // ]]>
23909: </script>
23910:
23911: END
23912:
23913: }
23914:
23915: sub common_domprefs_js {
23916: return <<"END";
23917:
23918: <script type="text/javascript">
23919: // <![CDATA[
23920:
1.150 raeburn 23921: function getIndicesByName(formname,item) {
1.152 raeburn 23922: var group = new Array();
1.150 raeburn 23923: for (var i=0;i<formname.elements.length;i++) {
23924: if (formname.elements[i].name == item) {
1.152 raeburn 23925: group.push(formname.elements[i].id);
1.150 raeburn 23926: }
23927: }
1.152 raeburn 23928: return group;
1.150 raeburn 23929: }
23930:
23931: // ]]>
23932: </script>
23933:
23934: END
1.152 raeburn 23935:
1.150 raeburn 23936: }
23937:
1.165 raeburn 23938: sub recaptcha_js {
23939: my %lt = &captcha_phrases();
23940: return <<"END";
23941:
23942: <script type="text/javascript">
23943: // <![CDATA[
23944:
23945: function updateCaptcha(caller,context) {
23946: var privitem;
23947: var pubitem;
23948: var privtext;
23949: var pubtext;
1.269 raeburn 23950: var versionitem;
23951: var versiontext;
1.165 raeburn 23952: if (document.getElementById(context+'_recaptchapub')) {
23953: pubitem = document.getElementById(context+'_recaptchapub');
23954: } else {
23955: return;
23956: }
23957: if (document.getElementById(context+'_recaptchapriv')) {
23958: privitem = document.getElementById(context+'_recaptchapriv');
23959: } else {
23960: return;
23961: }
23962: if (document.getElementById(context+'_recaptchapubtxt')) {
23963: pubtext = document.getElementById(context+'_recaptchapubtxt');
23964: } else {
23965: return;
23966: }
23967: if (document.getElementById(context+'_recaptchaprivtxt')) {
23968: privtext = document.getElementById(context+'_recaptchaprivtxt');
23969: } else {
23970: return;
23971: }
1.269 raeburn 23972: if (document.getElementById(context+'_recaptchaversion')) {
23973: versionitem = document.getElementById(context+'_recaptchaversion');
23974: } else {
23975: return;
23976: }
23977: if (document.getElementById(context+'_recaptchavertxt')) {
23978: versiontext = document.getElementById(context+'_recaptchavertxt');
23979: } else {
23980: return;
23981: }
1.165 raeburn 23982: if (caller.checked) {
23983: if (caller.value == 'recaptcha') {
23984: pubitem.type = 'text';
23985: privitem.type = 'text';
23986: pubitem.size = '40';
23987: privitem.size = '40';
23988: pubtext.innerHTML = "$lt{'pub'}";
23989: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 23990: versionitem.type = 'text';
23991: versionitem.size = '3';
1.289 raeburn 23992: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 23993: } else {
23994: pubitem.type = 'hidden';
23995: privitem.type = 'hidden';
1.269 raeburn 23996: versionitem.type = 'hidden';
1.165 raeburn 23997: pubtext.innerHTML = '';
23998: privtext.innerHTML = '';
1.269 raeburn 23999: versiontext.innerHTML = '';
1.165 raeburn 24000: }
24001: }
24002: return;
24003: }
24004:
24005: // ]]>
24006: </script>
24007:
24008: END
24009:
24010: }
24011:
1.236 raeburn 24012: sub toggle_display_js {
1.192 raeburn 24013: return <<"END";
24014:
24015: <script type="text/javascript">
24016: // <![CDATA[
24017:
1.236 raeburn 24018: function toggleDisplay(domForm,caller) {
24019: if (document.getElementById(caller)) {
24020: var divitem = document.getElementById(caller);
24021: var optionsElement = domForm.coursecredits;
1.264 raeburn 24022: var checkval = 1;
24023: var dispval = 'block';
1.303 raeburn 24024: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 24025: if (caller == 'emailoptions') {
1.372 raeburn 24026: optionsElement = domForm.cancreate_email;
1.236 raeburn 24027: }
1.257 raeburn 24028: if (caller == 'studentsubmission') {
24029: optionsElement = domForm.postsubmit;
24030: }
1.264 raeburn 24031: if (caller == 'cloneinstcode') {
24032: optionsElement = domForm.canclone;
24033: checkval = 'instcode';
24034: }
1.303 raeburn 24035: if (selfcreateRegExp.test(caller)) {
24036: optionsElement = domForm.elements[caller];
24037: checkval = 'other';
24038: dispval = 'inline'
24039: }
1.236 raeburn 24040: if (optionsElement.length) {
1.192 raeburn 24041: var currval;
1.236 raeburn 24042: for (var i=0; i<optionsElement.length; i++) {
24043: if (optionsElement[i].checked) {
24044: currval = optionsElement[i].value;
1.192 raeburn 24045: }
24046: }
1.264 raeburn 24047: if (currval == checkval) {
24048: divitem.style.display = dispval;
1.192 raeburn 24049: } else {
1.236 raeburn 24050: divitem.style.display = 'none';
1.192 raeburn 24051: }
24052: }
24053: }
24054: return;
24055: }
24056:
24057: // ]]>
24058: </script>
24059:
24060: END
24061:
24062: }
24063:
1.165 raeburn 24064: sub captcha_phrases {
24065: return &Apache::lonlocal::texthash (
24066: priv => 'Private key',
24067: pub => 'Public key',
24068: original => 'original (CAPTCHA)',
24069: recaptcha => 'successor (ReCAPTCHA)',
24070: notused => 'unused',
1.289 raeburn 24071: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 24072: );
24073: }
24074:
1.205 raeburn 24075: sub devalidate_remote_domconfs {
1.212 raeburn 24076: my ($dom,$cachekeys) = @_;
24077: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 24078: my %servers = &Apache::lonnet::internet_dom_servers($dom);
24079: my %thismachine;
24080: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 24081: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 24082: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 24083: 'ipaccess','trust');
1.386 raeburn 24084: my %cache_by_lonhost;
24085: if (exists($cachekeys->{'samllanding'})) {
24086: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
24087: my %landing = %{$cachekeys->{'samllanding'}};
24088: my %domservers = &Apache::lonnet::get_servers($dom);
24089: if (keys(%domservers)) {
24090: foreach my $server (keys(%domservers)) {
24091: my @cached;
24092: next if ($thismachine{$server});
24093: if ($landing{$server}) {
24094: push(@cached,&escape('samllanding').':'.&escape($server));
24095: }
24096: if (@cached) {
24097: $cache_by_lonhost{$server} = \@cached;
24098: }
24099: }
24100: }
24101: }
24102: }
1.260 raeburn 24103: if (keys(%servers)) {
1.205 raeburn 24104: foreach my $server (keys(%servers)) {
24105: next if ($thismachine{$server});
1.212 raeburn 24106: my @cached;
24107: foreach my $name (@posscached) {
24108: if ($cachekeys->{$name}) {
1.388 raeburn 24109: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 24110: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 24111: foreach my $key (keys(%{$cachekeys->{$name}})) {
24112: push(@cached,&escape($name).':'.&escape($key));
24113: }
24114: }
24115: } else {
24116: push(@cached,&escape($name).':'.&escape($dom));
24117: }
1.212 raeburn 24118: }
24119: }
1.386 raeburn 24120: if ((exists($cache_by_lonhost{$server})) &&
24121: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
24122: push(@cached,@{$cache_by_lonhost{$server}});
24123: }
1.212 raeburn 24124: if (@cached) {
24125: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
24126: }
1.205 raeburn 24127: }
24128: }
24129: return;
24130: }
24131:
1.3 raeburn 24132: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>