Annotation of loncom/interface/domainprefs.pm, revision 1.447.2.1
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.447.2.1! raeburn 4: # $Id: domainprefs.pm,v 1.447 2024/12/31 19:28:29 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.429 raeburn 98: used by course owners to request creation of a course.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 106: (official, unofficial, community, textbook, placement, and lti).
1.425 raeburn 107: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.232 raeburn 167: use Apache::lonuserutils();
1.235 raeburn 168: use Apache::loncoursequeueadmin();
1.419 raeburn 169: use Apache::courseprefs();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.373 raeburn 179: use Net::CIDR;
1.424 raeburn 180: use Crypt::CBC;
1.1 raeburn 181:
1.155 raeburn 182: my $registered_cleanup;
183: my $modified_urls;
184:
1.1 raeburn 185: sub handler {
186: my $r=shift;
187: if ($r->header_only) {
188: &Apache::loncommon::content_type($r,'text/html');
189: $r->send_http_header;
190: return OK;
191: }
192:
1.91 raeburn 193: my $context = 'domain';
1.1 raeburn 194: my $dom = $env{'request.role.domain'};
1.5 albertel 195: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 196: if (&Apache::lonnet::allowed('mau',$dom)) {
197: &Apache::loncommon::content_type($r,'text/html');
198: $r->send_http_header;
199: } else {
200: $env{'user.error.msg'}=
201: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
202: return HTTP_NOT_ACCEPTABLE;
203: }
1.155 raeburn 204:
205: $registered_cleanup=0;
206: @{$modified_urls}=();
207:
1.1 raeburn 208: &Apache::lonhtmlcommon::clear_breadcrumbs();
209: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 210: ['phase','actions']);
1.30 raeburn 211: my $phase = 'pickactions';
1.3 raeburn 212: if ( exists($env{'form.phase'}) ) {
213: $phase = $env{'form.phase'};
214: }
1.150 raeburn 215: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 216: my %domconfig =
1.6 raeburn 217: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 218: 'quotas','autoenroll','autoupdate','autocreate',
219: 'directorysrch','usercreation','usermodification',
220: 'contacts','defaults','scantron','coursecategories',
221: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 222: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 223: 'requestauthor','selfenrollment','inststatus',
1.421 raeburn 224: 'ltitools','toolsec','ssl','trust','lti','ltisec',
1.447.2.1! raeburn 225: 'privacy','passwords','wafproxy',
1.429 raeburn 226: 'ipaccess','authordefaults'],$dom);
1.320 raeburn 227: my %encconfig =
1.447.2.1! raeburn 228: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','linkprot'],$dom,undef,1);
1.424 raeburn 229: my ($checked_is_home,$is_home);
1.297 raeburn 230: if (ref($domconfig{'ltitools'}) eq 'HASH') {
231: if (ref($encconfig{'ltitools'}) eq 'HASH') {
1.423 raeburn 232: my $home = &Apache::lonnet::domain($dom,'primary');
233: unless (($home eq 'no_host') || ($home eq '')) {
234: my @ids=&Apache::lonnet::current_machine_ids();
235: if (grep(/^\Q$home\E$/,@ids)) {
236: $is_home = 1;
237: }
238: }
1.425 raeburn 239: $checked_is_home = 1;
1.297 raeburn 240: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 241: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
242: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.421 raeburn 243: $domconfig{'ltitools'}{$id}{'key'} = $encconfig{'ltitools'}{$id}{'key'};
1.423 raeburn 244: if (($is_home) && ($phase eq 'process')) {
245: $domconfig{'ltitools'}{$id}{'secret'} = $encconfig{'ltitools'}{$id}{'secret'};
246: }
1.297 raeburn 247: }
248: }
249: }
250: }
1.320 raeburn 251: if (ref($domconfig{'lti'}) eq 'HASH') {
252: if (ref($encconfig{'lti'}) eq 'HASH') {
1.424 raeburn 253: unless ($checked_is_home) {
254: my $home = &Apache::lonnet::domain($dom,'primary');
255: unless (($home eq 'no_host') || ($home eq '')) {
256: my @ids=&Apache::lonnet::current_machine_ids();
257: if (grep(/^\Q$home\E$/,@ids)) {
258: $is_home = 1;
259: }
260: }
261: $checked_is_home = 1;
262: }
1.320 raeburn 263: foreach my $id (keys(%{$domconfig{'lti'}})) {
264: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
265: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
1.424 raeburn 266: $domconfig{'lti'}{$id}{'key'} = $encconfig{'lti'}{$id}{'key'};
267: if (($is_home) && ($phase eq 'process')) {
268: $domconfig{'lti'}{$id}{'secret'} = $encconfig{'lti'}{$id}{'secret'};
1.320 raeburn 269: }
270: }
271: }
272: }
273: }
1.405 raeburn 274: if (ref($domconfig{'ltisec'}) eq 'HASH') {
1.406 raeburn 275: if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
1.405 raeburn 276: if (ref($encconfig{'linkprot'}) eq 'HASH') {
1.406 raeburn 277: foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
278: unless ($id =~ /^\d+$/) {
279: delete($domconfig{'ltisec'}{'linkprot'}{$id});
280: }
281: if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
1.405 raeburn 282: (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
283: foreach my $item ('key','secret') {
1.406 raeburn 284: $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
1.405 raeburn 285: }
286: }
287: }
288: }
289: }
290: }
1.394 raeburn 291: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
292: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373 raeburn 293: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 294: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 295: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.447.2.1! raeburn 296: 'authordefaults','ltitools','selfenrollment',
1.429 raeburn 297: 'usersessions','ssl','trust','lti');
1.171 raeburn 298: my %existing;
299: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
300: %existing = %{$domconfig{'loadbalancing'}};
301: }
302: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 303: push(@prefs_order,'loadbalancing');
304: }
1.30 raeburn 305: my %prefs = (
306: 'rolecolors' =>
307: { text => 'Default color schemes',
1.67 raeburn 308: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 309: header => [{col1 => 'Student Settings',
310: col2 => '',},
311: {col1 => 'Coordinator Settings',
312: col2 => '',},
313: {col1 => 'Author Settings',
314: col2 => '',},
315: {col1 => 'Administrator Settings',
316: col2 => '',}],
1.230 raeburn 317: print => \&print_rolecolors,
318: modify => \&modify_rolecolors,
1.30 raeburn 319: },
1.110 raeburn 320: 'login' =>
1.30 raeburn 321: { text => 'Log-in page options',
1.67 raeburn 322: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 323: header => [{col1 => 'Log-in Page Items',
324: col2 => '',},
325: {col1 => 'Log-in Help',
1.256 raeburn 326: col2 => 'Value'},
327: {col1 => 'Custom HTML in document head',
1.386 raeburn 328: col2 => 'Value'},
329: {col1 => 'SSO',
330: col2 => 'Dual login: SSO and non-SSO options'},
331: ],
1.230 raeburn 332: print => \&print_login,
333: modify => \&modify_login,
1.30 raeburn 334: },
1.43 raeburn 335: 'defaults' =>
1.236 raeburn 336: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 337: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 338: header => [{col1 => 'Setting',
1.236 raeburn 339: col2 => 'Value'},
340: {col1 => 'Institutional user types',
1.409 raeburn 341: col2 => 'Name displayed'},
342: {col1 => 'Mapping for missing usernames via standard log-in',
343: col2 => 'Rules in use'}],
1.230 raeburn 344: print => \&print_defaults,
345: modify => \&modify_defaults,
1.43 raeburn 346: },
1.381 raeburn 347: 'wafproxy' =>
348: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 349: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 350: header => [{col1 => 'Domain(s)',
351: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 352: },
1.381 raeburn 353: {col1 => 'Domain(s)',
354: col2 => 'WAF Configuration',}],
1.373 raeburn 355: print => \&print_wafproxy,
1.381 raeburn 356: modify => \&modify_wafproxy,
1.373 raeburn 357: },
1.354 raeburn 358: 'passwords' =>
359: { text => 'Passwords (Internal authentication)',
360: help => 'Domain_Configuration_Passwords',
361: header => [{col1 => 'Resetting Forgotten Password',
362: col2 => 'Settings'},
363: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
364: col2 => 'Settings'},
365: {col1 => 'Rules for LON-CAPA Passwords',
366: col2 => 'Settings'},
367: {col1 => 'Course Owner Changing Student Passwords',
368: col2 => 'Settings'}],
369: print => \&print_passwords,
370: modify => \&modify_passwords,
371: },
1.30 raeburn 372: 'quotas' =>
1.429 raeburn 373: { text => 'Blogs, personal pages/timezones, portfolio/quotas',
1.67 raeburn 374: help => 'Domain_Configuration_Quotas',
1.77 raeburn 375: header => [{col1 => 'User affiliation',
1.72 raeburn 376: col2 => 'Available tools',
1.435 raeburn 377: col3 => 'Portfolio quota (MB)',}],
1.230 raeburn 378: print => \&print_quotas,
379: modify => \&modify_quotas,
1.30 raeburn 380: },
381: 'autoenroll' =>
382: { text => 'Auto-enrollment settings',
1.67 raeburn 383: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 384: header => [{col1 => 'Configuration setting',
385: col2 => 'Value(s)'}],
1.230 raeburn 386: print => \&print_autoenroll,
387: modify => \&modify_autoenroll,
1.30 raeburn 388: },
389: 'autoupdate' =>
390: { text => 'Auto-update settings',
1.67 raeburn 391: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 392: header => [{col1 => 'Setting',
393: col2 => 'Value',},
1.131 raeburn 394: {col1 => 'Setting',
395: col2 => 'Affiliation'},
1.43 raeburn 396: {col1 => 'User population',
1.227 bisitz 397: col2 => 'Updatable user data'}],
1.230 raeburn 398: print => \&print_autoupdate,
399: modify => \&modify_autoupdate,
1.30 raeburn 400: },
1.125 raeburn 401: 'autocreate' =>
402: { text => 'Auto-course creation settings',
403: help => 'Domain_Configuration_Auto_Creation',
404: header => [{col1 => 'Configuration Setting',
405: col2 => 'Value',}],
1.230 raeburn 406: print => \&print_autocreate,
407: modify => \&modify_autocreate,
1.125 raeburn 408: },
1.30 raeburn 409: 'directorysrch' =>
1.277 raeburn 410: { text => 'Directory searches',
1.67 raeburn 411: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 412: header => [{col1 => 'Institutional Directory Setting',
413: col2 => 'Value',},
414: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 415: col2 => 'Value',}],
1.230 raeburn 416: print => \&print_directorysrch,
417: modify => \&modify_directorysrch,
1.30 raeburn 418: },
419: 'contacts' =>
1.286 raeburn 420: { text => 'E-mail addresses and helpform',
1.67 raeburn 421: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 422: header => [{col1 => 'Default e-mail addresses',
423: col2 => 'Value',},
424: {col1 => 'Recipient(s) for notifications',
425: col2 => 'Value',},
1.340 raeburn 426: {col1 => 'Nightly status check e-mail',
427: col2 => 'Settings',},
1.286 raeburn 428: {col1 => 'Ask helpdesk form settings',
429: col2 => 'Value',},],
1.230 raeburn 430: print => \&print_contacts,
431: modify => \&modify_contacts,
1.30 raeburn 432: },
433: 'usercreation' =>
434: { text => 'User creation',
1.67 raeburn 435: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 436: header => [{col1 => 'Format rule type',
437: col2 => 'Format rules in force'},
1.34 raeburn 438: {col1 => 'User account creation',
439: col2 => 'Usernames which may be created',},
1.30 raeburn 440: {col1 => 'Context',
1.43 raeburn 441: col2 => 'Assignable authentication types'}],
1.230 raeburn 442: print => \&print_usercreation,
443: modify => \&modify_usercreation,
1.30 raeburn 444: },
1.224 raeburn 445: 'selfcreation' =>
446: { text => 'Users self-creating accounts',
447: help => 'Domain_Configuration_Self_Creation',
448: header => [{col1 => 'Self-creation with institutional username',
449: col2 => 'Enabled?'},
450: {col1 => 'Institutional user type (login/SSO self-creation)',
451: col2 => 'Information user can enter'},
1.303 raeburn 452: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 453: col2 => 'Settings'}],
1.230 raeburn 454: print => \&print_selfcreation,
455: modify => \&modify_selfcreation,
1.224 raeburn 456: },
1.69 raeburn 457: 'usermodification' =>
1.33 raeburn 458: { text => 'User modification',
1.67 raeburn 459: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 460: header => [{col1 => 'Target user has role',
1.227 bisitz 461: col2 => 'User information updatable in author context'},
1.33 raeburn 462: {col1 => 'Target user has role',
1.443 raeburn 463: col2 => 'User information updatable by co-author manager'},
464: {col1 => 'Target user has role',
1.227 bisitz 465: col2 => 'User information updatable in course context'}],
1.230 raeburn 466: print => \&print_usermodification,
467: modify => \&modify_usermodification,
1.33 raeburn 468: },
1.69 raeburn 469: 'scantron' =>
1.346 raeburn 470: { text => 'Bubblesheet format',
1.67 raeburn 471: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 472: header => [ {col1 => 'Bubblesheet format file',
473: col2 => ''},
474: {col1 => 'Bubblesheet data upload formats',
475: col2 => 'Settings'}],
1.230 raeburn 476: print => \&print_scantron,
477: modify => \&modify_scantron,
1.46 raeburn 478: },
1.86 raeburn 479: 'requestcourses' =>
480: {text => 'Request creation of courses',
481: help => 'Domain_Configuration_Request_Courses',
482: header => [{col1 => 'User affiliation',
1.102 raeburn 483: col2 => 'Availability/Processing of requests',},
484: {col1 => 'Setting',
1.216 raeburn 485: col2 => 'Value'},
486: {col1 => 'Available textbooks',
1.235 raeburn 487: col2 => ''},
1.242 raeburn 488: {col1 => 'Available templates',
489: col2 => ''},
1.235 raeburn 490: {col1 => 'Validation (not official courses)',
491: col2 => 'Value'},],
1.230 raeburn 492: print => \&print_quotas,
493: modify => \&modify_quotas,
1.86 raeburn 494: },
1.163 raeburn 495: 'requestauthor' =>
1.223 bisitz 496: {text => 'Request Authoring Space',
1.163 raeburn 497: help => 'Domain_Configuration_Request_Author',
498: header => [{col1 => 'User affiliation',
499: col2 => 'Availability/Processing of requests',},
500: {col1 => 'Setting',
501: col2 => 'Value'}],
1.230 raeburn 502: print => \&print_quotas,
503: modify => \&modify_quotas,
1.163 raeburn 504: },
1.69 raeburn 505: 'coursecategories' =>
1.120 raeburn 506: { text => 'Cataloging of courses/communities',
1.67 raeburn 507: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 508: header => [{col1 => 'Catalog type/availability',
509: col2 => '',},
510: {col1 => 'Category settings for standard catalog',
1.57 raeburn 511: col2 => '',},
512: {col1 => 'Categories',
513: col2 => '',
514: }],
1.230 raeburn 515: print => \&print_coursecategories,
516: modify => \&modify_coursecategories,
1.69 raeburn 517: },
518: 'serverstatuses' =>
1.77 raeburn 519: {text => 'Access to server status pages',
1.69 raeburn 520: help => 'Domain_Configuration_Server_Status',
521: header => [{col1 => 'Status Page',
522: col2 => 'Other named users',
523: col3 => 'Specific IPs',
524: }],
1.230 raeburn 525: print => \&print_serverstatuses,
526: modify => \&modify_serverstatuses,
1.69 raeburn 527: },
1.118 jms 528: 'helpsettings' =>
1.282 raeburn 529: {text => 'Support settings',
1.118 jms 530: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 531: header => [{col1 => 'Help Page Settings (logged-in users)',
532: col2 => 'Value'},
533: {col1 => 'Helpdesk Roles',
534: col2 => 'Settings'},],
1.230 raeburn 535: print => \&print_helpsettings,
536: modify => \&modify_helpsettings,
1.118 jms 537: },
1.121 raeburn 538: 'coursedefaults' =>
539: {text => 'Course/Community defaults',
540: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 541: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
542: col2 => 'Value',},
543: {col1 => 'Defaults which can be overridden for each course by a DC',
544: col2 => 'Value',},],
1.230 raeburn 545: print => \&print_coursedefaults,
546: modify => \&modify_coursedefaults,
1.121 raeburn 547: },
1.231 raeburn 548: 'selfenrollment' =>
549: {text => 'Self-enrollment in Course/Community',
550: help => 'Domain_Configuration_Selfenrollment',
551: header => [{col1 => 'Configuration Rights',
552: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
553: {col1 => 'Defaults',
554: col2 => 'Value'},
555: {col1 => 'Self-enrollment validation (optional)',
556: col2 => 'Value'},],
557: print => \&print_selfenrollment,
558: modify => \&modify_selfenrollment,
559: },
1.120 raeburn 560: 'privacy' =>
1.427 raeburn 561: {text => 'Role assignments and user privacy',
1.120 raeburn 562: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 563: header => [{col1 => 'Role assigned in different domain',
564: col2 => 'Approval options'},
565: {col1 => 'Role assigned in different domain to user of type',
566: col2 => 'User information available in that domain'},
567: {col1 => "Role assigned in user's domain",
568: col2 => 'Information viewable by privileged user'},
569: {col1 => "Role assigned in user's domain",
570: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 571: print => \&print_privacy,
572: modify => \&modify_privacy,
1.120 raeburn 573: },
1.141 raeburn 574: 'usersessions' =>
1.145 raeburn 575: {text => 'User session hosting/offloading',
1.137 raeburn 576: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 577: header => [{col1 => 'Domain server',
578: col2 => 'Servers to offload sessions to when busy'},
579: {col1 => 'Hosting of users from other domains',
1.137 raeburn 580: col2 => 'Rules'},
581: {col1 => "Hosting domain's own users elsewhere",
582: col2 => 'Rules'}],
1.230 raeburn 583: print => \&print_usersessions,
584: modify => \&modify_usersessions,
1.137 raeburn 585: },
1.279 raeburn 586: 'loadbalancing' =>
1.185 raeburn 587: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 588: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 589: header => [{col1 => 'Balancers',
1.150 raeburn 590: col2 => 'Default destinations',
1.183 bisitz 591: col3 => 'User affiliation',
1.150 raeburn 592: col4 => 'Overrides'},
593: ],
1.230 raeburn 594: print => \&print_loadbalancing,
595: modify => \&modify_loadbalancing,
1.150 raeburn 596: },
1.425 raeburn 597: 'ltitools' =>
1.267 raeburn 598: {text => 'External Tools (LTI)',
1.296 raeburn 599: help => 'Domain_Configuration_LTI_Tools',
1.421 raeburn 600: header => [{col1 => 'Encryption of shared secrets',
601: col2 => 'Settings'},
602: {col1 => 'Rules for shared secrets',
603: col2 => 'Settings'},
604: {col1 => 'Providers',
605: col2 => 'Settings',}],
1.267 raeburn 606: print => \&print_ltitools,
607: modify => \&modify_ltitools,
608: },
1.279 raeburn 609: 'ssl' =>
1.275 raeburn 610: {text => 'LON-CAPA Network (SSL)',
611: help => 'Domain_Configuration_Network_SSL',
612: header => [{col1 => 'Server',
613: col2 => 'Certificate Status'},
614: {col1 => 'Connections to other servers',
615: col2 => 'Rules'},
1.293 raeburn 616: {col1 => 'Connections from other servers',
617: col2 => 'Rules'},
1.275 raeburn 618: {col1 => "Replicating domain's published content",
619: col2 => 'Rules'}],
620: print => \&print_ssl,
621: modify => \&modify_ssl,
622: },
1.279 raeburn 623: 'trust' =>
624: {text => 'Trust Settings',
625: help => 'Domain_Configuration_Trust',
626: header => [{col1 => "Access to this domain's content by others",
627: col2 => 'Rules'},
628: {col1 => "Access to other domain's content by this domain",
629: col2 => 'Rules'},
630: {col1 => "Enrollment in this domain's courses by others",
631: col2 => 'Rules',},
632: {col1 => "Co-author roles in this domain for others",
633: col2 => 'Rules',},
634: {col1 => "Co-author roles for this domain's users elsewhere",
635: col2 => 'Rules',},
636: {col1 => "Domain roles in this domain assignable to others",
637: col2 => 'Rules'},
638: {col1 => "Course catalog for this domain displayed elsewhere",
639: col2 => 'Rules'},
640: {col1 => "Requests for creation of courses in this domain by others",
641: col2 => 'Rules'},
642: {col1 => "Users in other domains can send messages to this domain",
643: col2 => 'Rules'},],
644: print => \&print_trust,
645: modify => \&modify_trust,
646: },
1.425 raeburn 647: 'lti' =>
1.405 raeburn 648: {text => 'LTI Link Protection and LTI Consumers',
1.320 raeburn 649: help => 'Domain_Configuration_LTI_Provider',
1.405 raeburn 650: header => [{col1 => 'Encryption of shared secrets',
651: col2 => 'Settings'},
1.425 raeburn 652: {col1 => 'Rules for shared secrets',
1.405 raeburn 653: col2 => 'Settings'},
1.434 raeburn 654: {col1 => 'Link Protectors in Courses',
1.436 raeburn 655: col2 => 'Values'},
1.406 raeburn 656: {col1 => 'Link Protectors',
1.405 raeburn 657: col2 => 'Settings'},
658: {col1 => 'Consumers',
659: col2 => 'Settings'},],
1.320 raeburn 660: print => \&print_lti,
661: modify => \&modify_lti,
662: },
1.425 raeburn 663: 'ipaccess' =>
1.394 raeburn 664: {text => 'IP-based access control',
665: help => 'Domain_Configuration_IP_Access',
666: header => [{col1 => 'Setting',
667: col2 => 'Value'},],
668: print => \&print_ipaccess,
669: modify => \&modify_ipaccess,
670: },
1.436 raeburn 671: 'authordefaults' =>
1.429 raeburn 672: {text => 'Authoring Space defaults',
673: help => 'Domain_Configuration_Author_Defaults',
674: header => [{col1 => 'Defaults which can be overridden by Author',
675: col2 => 'Settings',},
676: {col1 => 'Defaults which can be overridden by a Dom. Coord.',
677: col2 => 'Settings',},],
678: print => \&print_authordefaults,
679: modify => \&modify_authordefaults,
680: },
1.3 raeburn 681: );
1.110 raeburn 682: if (keys(%servers) > 1) {
683: $prefs{'login'} = { text => 'Log-in page options',
684: help => 'Domain_Configuration_Login_Page',
685: header => [{col1 => 'Log-in Service',
686: col2 => 'Server Setting',},
687: {col1 => 'Log-in Page Items',
1.405 raeburn 688: col2 => 'Settings'},
1.168 raeburn 689: {col1 => 'Log-in Help',
1.256 raeburn 690: col2 => 'Value'},
691: {col1 => 'Custom HTML in document head',
1.386 raeburn 692: col2 => 'Value'},
693: {col1 => 'SSO',
694: col2 => 'Dual login: SSO and non-SSO options'},
695: ],
1.230 raeburn 696: print => \&print_login,
697: modify => \&modify_login,
1.110 raeburn 698: };
699: }
1.174 foxr 700:
1.6 raeburn 701: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 702: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 703: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 704: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 705: text=>"Settings to display/modify"});
1.9 raeburn 706: my $confname = $dom.'-domainconfig';
1.174 foxr 707:
1.3 raeburn 708: if ($phase eq 'process') {
1.212 raeburn 709: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
710: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 711: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 712: $r->rflush();
1.212 raeburn 713: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 714: }
1.30 raeburn 715: } elsif ($phase eq 'display') {
1.192 raeburn 716: my $js = &recaptcha_js().
1.236 raeburn 717: &toggle_display_js();
1.171 raeburn 718: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 719: my ($othertitle,$usertypes,$types) =
720: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 721: $js .= &lonbalance_targets_js($dom,$types,\%servers,
722: $domconfig{'loadbalancing'}).
1.170 raeburn 723: &new_spares_js().
724: &common_domprefs_js().
725: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 726: }
1.216 raeburn 727: if (grep(/^requestcourses$/,@actions)) {
728: my $javascript_validations;
729: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
730: $js .= <<END;
731: <script type="text/javascript">
732: $javascript_validations
733: </script>
734: $coursebrowserjs
735: END
1.394 raeburn 736: } elsif (grep(/^ipaccess$/,@actions)) {
737: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 738: }
1.305 raeburn 739: if (grep(/^selfcreation$/,@actions)) {
740: $js .= &selfcreate_javascript();
741: }
1.286 raeburn 742: if (grep(/^contacts$/,@actions)) {
743: $js .= &contacts_javascript();
744: }
1.346 raeburn 745: if (grep(/^scantron$/,@actions)) {
746: $js .= &scantron_javascript();
747: }
1.150 raeburn 748: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 749: } else {
1.180 raeburn 750: # check if domconfig user exists for the domain.
751: my $servadm = $r->dir_config('lonAdmEMail');
752: my ($configuserok,$author_ok,$switchserver) =
753: &config_check($dom,$confname,$servadm);
754: unless ($configuserok eq 'ok') {
1.181 raeburn 755: &Apache::lonconfigsettings::print_header($r,$phase,$context);
756: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 757: $confname).
1.181 raeburn 758: '<br />'
759: );
1.180 raeburn 760: if ($switchserver) {
1.181 raeburn 761: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
762: '<br />'.
763: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
764: '<br />'.
765: &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).
766: '<br />'.
767: &mt('To do that now, use the following link: [_1]',$switchserver)
768: );
769: } else {
770: $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.').
771: '<br />'.
772: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
773: );
1.180 raeburn 774: }
775: $r->print(&Apache::loncommon::end_page());
776: return OK;
777: }
1.21 raeburn 778: if (keys(%domconfig) == 0) {
779: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 780: my @ids=&Apache::lonnet::current_machine_ids();
781: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 782: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 783: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 784: my $custom_img_count = 0;
785: foreach my $img (@loginimages) {
786: if ($designhash{$dom.'.login.'.$img} ne '') {
787: $custom_img_count ++;
788: }
789: }
790: foreach my $role (@roles) {
791: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
792: $custom_img_count ++;
793: }
794: }
795: if ($custom_img_count > 0) {
1.94 raeburn 796: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 797: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 798: $r->print(
799: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
800: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
801: &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 />'.
802: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
803: if ($switch_server) {
1.30 raeburn 804: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 805: }
1.91 raeburn 806: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 807: return OK;
808: }
809: }
810: }
1.91 raeburn 811: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 812: }
813: return OK;
814: }
815:
816: sub process_changes {
1.205 raeburn 817: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 818: my %domconfig;
819: if (ref($values) eq 'HASH') {
820: %domconfig = %{$values};
821: }
1.3 raeburn 822: my $output;
823: if ($action eq 'login') {
1.205 raeburn 824: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 825: } elsif ($action eq 'rolecolors') {
1.9 raeburn 826: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 827: $lastactref,%domconfig);
1.3 raeburn 828: } elsif ($action eq 'quotas') {
1.216 raeburn 829: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 830: } elsif ($action eq 'autoenroll') {
1.205 raeburn 831: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 832: } elsif ($action eq 'autoupdate') {
833: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 834: } elsif ($action eq 'autocreate') {
835: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 836: } elsif ($action eq 'directorysrch') {
1.295 raeburn 837: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 838: } elsif ($action eq 'usercreation') {
1.28 raeburn 839: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 840: } elsif ($action eq 'selfcreation') {
1.305 raeburn 841: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 842: } elsif ($action eq 'usermodification') {
843: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 844: } elsif ($action eq 'contacts') {
1.205 raeburn 845: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 846: } elsif ($action eq 'defaults') {
1.212 raeburn 847: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 848: } elsif ($action eq 'scantron') {
1.205 raeburn 849: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 850: } elsif ($action eq 'coursecategories') {
1.239 raeburn 851: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 852: } elsif ($action eq 'serverstatuses') {
853: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 854: } elsif ($action eq 'requestcourses') {
1.216 raeburn 855: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 856: } elsif ($action eq 'requestauthor') {
1.216 raeburn 857: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 858: } elsif ($action eq 'helpsettings') {
1.285 raeburn 859: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 860: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 861: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 862: } elsif ($action eq 'selfenrollment') {
863: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 864: } elsif ($action eq 'usersessions') {
1.212 raeburn 865: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 866: } elsif ($action eq 'loadbalancing') {
867: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 868: } elsif ($action eq 'ltitools') {
869: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 870: } elsif ($action eq 'ssl') {
871: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 872: } elsif ($action eq 'trust') {
873: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 874: } elsif ($action eq 'lti') {
875: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 876: } elsif ($action eq 'privacy') {
1.427 raeburn 877: $output = &modify_privacy($dom,$lastactref,%domconfig);
1.354 raeburn 878: } elsif ($action eq 'passwords') {
879: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 880: } elsif ($action eq 'wafproxy') {
881: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 882: } elsif ($action eq 'ipaccess') {
883: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.429 raeburn 884: } elsif ($action eq 'authordefaults') {
885: $output = &modify_authordefaults($dom,$lastactref,%domconfig);
1.3 raeburn 886: }
887: return $output;
888: }
889:
890: sub print_config_box {
1.9 raeburn 891: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 892: my $rowtotal = 0;
1.49 raeburn 893: my $output;
894: if ($action eq 'coursecategories') {
895: $output = &coursecategories_javascript($settings);
1.236 raeburn 896: } elsif ($action eq 'defaults') {
897: $output = &defaults_javascript($settings);
1.354 raeburn 898: } elsif ($action eq 'passwords') {
1.405 raeburn 899: $output = &passwords_javascript($action);
1.282 raeburn 900: } elsif ($action eq 'helpsettings') {
901: my (%privs,%levelscurrent);
902: my %full=();
903: my %levels=(
904: course => {},
905: domain => {},
906: system => {},
907: );
908: my $context = 'domain';
909: my $crstype = 'Course';
910: my $formname = 'display';
911: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
912: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
913: $output =
1.425 raeburn 914: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
1.282 raeburn 915: \@templateroles);
1.334 raeburn 916: } elsif ($action eq 'ltitools') {
1.421 raeburn 917: $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
1.334 raeburn 918: } elsif ($action eq 'lti') {
1.421 raeburn 919: $output .= &passwords_javascript('ltisecrets')."\n".
1.405 raeburn 920: <i_javascript($dom,$settings);
1.381 raeburn 921: } elsif ($action eq 'wafproxy') {
922: $output .= &wafproxy_javascript($dom);
1.385 raeburn 923: } elsif ($action eq 'autoupdate') {
924: $output .= &autoupdate_javascript();
1.399 raeburn 925: } elsif ($action eq 'autoenroll') {
926: $output .= &autoenroll_javascript();
1.386 raeburn 927: } elsif ($action eq 'login') {
928: $output .= &saml_javascript();
1.394 raeburn 929: } elsif ($action eq 'ipaccess') {
930: $output .= &ipaccess_javascript($settings);
1.429 raeburn 931: } elsif ($action eq 'authordefaults') {
932: $output .= &authordefaults_javascript();
1.91 raeburn 933: }
1.236 raeburn 934: $output .=
1.30 raeburn 935: '<table class="LC_nested_outer">
1.3 raeburn 936: <tr>
1.306 raeburn 937: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 938: &mt($item->{text}).' '.
939: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
940: '</tr>';
1.30 raeburn 941: $rowtotal ++;
1.110 raeburn 942: my $numheaders = 1;
943: if (ref($item->{'header'}) eq 'ARRAY') {
944: $numheaders = scalar(@{$item->{'header'}});
945: }
946: if ($numheaders > 1) {
1.64 raeburn 947: my $colspan = '';
1.145 raeburn 948: my $rightcolspan = '';
1.369 raeburn 949: my $leftnobr = '';
1.238 raeburn 950: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 951: ($action eq 'directorysrch') ||
1.386 raeburn 952: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 953: $colspan = ' colspan="2"';
954: }
1.145 raeburn 955: if ($action eq 'usersessions') {
956: $rightcolspan = ' colspan="3"';
957: }
1.369 raeburn 958: if ($action eq 'passwords') {
959: $leftnobr = ' LC_nobreak';
960: }
1.30 raeburn 961: $output .= '
1.3 raeburn 962: <tr>
963: <td>
964: <table class="LC_nested">
965: <tr class="LC_info_row">
1.369 raeburn 966: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 967: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 968: </tr>';
1.69 raeburn 969: $rowtotal ++;
1.230 raeburn 970: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 971: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 972: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 973: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.421 raeburn 974: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') ||
1.429 raeburn 975: ($action eq 'lti') || ($action eq 'ltitools') || ($action eq 'authordefaults')) {
1.230 raeburn 976: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 977: } elsif ($action eq 'passwords') {
978: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 979: } elsif ($action eq 'coursecategories') {
1.230 raeburn 980: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 981: } elsif ($action eq 'scantron') {
982: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 983: } elsif ($action eq 'login') {
1.386 raeburn 984: if ($numheaders == 5) {
1.168 raeburn 985: $colspan = ' colspan="2"';
986: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
987: } else {
988: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
989: }
1.230 raeburn 990: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 991: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 992: } elsif ($action eq 'rolecolors') {
1.30 raeburn 993: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 994: }
1.30 raeburn 995: $output .= '
1.6 raeburn 996: </table>
997: </td>
998: </tr>
999: <tr>
1000: <td>
1001: <table class="LC_nested">
1002: <tr class="LC_info_row">
1.230 raeburn 1003: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 1004: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 1005: </tr>';
1006: $rowtotal ++;
1.230 raeburn 1007: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
1008: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 1009: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 1010: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.421 raeburn 1011: ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti') ||
1.443 raeburn 1012: ($action eq 'ltitools') || ($action eq 'usermodification')) {
1.238 raeburn 1013: if ($action eq 'coursecategories') {
1014: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
1015: $colspan = ' colspan="2"';
1.279 raeburn 1016: } elsif ($action eq 'trust') {
1017: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 1018: } elsif ($action eq 'passwords') {
1019: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.434 raeburn 1020: } elsif ($action eq 'lti') {
1021: $output .= $item->{'print'}->('upper',$dom,$settings,\$rowtotal).'
1022: </table>
1023: </td>
1024: </tr>
1025: <tr>
1026: <td>
1027: <table class="LC_nested">
1028: <tr class="LC_info_row">
1029: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1030: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1031: </tr>'."\n".
1032: $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1.238 raeburn 1033: } else {
1034: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1035: }
1.279 raeburn 1036: if ($action eq 'trust') {
1037: $output .= '
1038: </table>
1039: </td>
1040: </tr>';
1041: my @trusthdrs = qw(2 3 4 5 6 7);
1042: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1043: for (my $i=0; $i<@trusthdrs; $i++) {
1044: $output .= '
1045: <tr>
1046: <td>
1047: <table class="LC_nested">
1048: <tr class="LC_info_row">
1049: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1050: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1051: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1052: </table>
1053: </td>
1054: </tr>';
1055: }
1056: $output .= '
1057: <tr>
1058: <td>
1059: <table class="LC_nested">
1060: <tr class="LC_info_row">
1061: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1062: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1063: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1064: } else {
1.434 raeburn 1065: my $hdridx = 2;
1066: if ($action eq 'lti') {
1067: $hdridx = 3;
1068: }
1.279 raeburn 1069: $output .= '
1.63 raeburn 1070: </table>
1071: </td>
1072: </tr>
1073: <tr>
1074: <td>
1075: <table class="LC_nested">
1076: <tr class="LC_info_row">
1.434 raeburn 1077: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1078: <td class="LC_right_item">'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td>
1.238 raeburn 1079: </tr>'."\n";
1.279 raeburn 1080: if ($action eq 'coursecategories') {
1081: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405 raeburn 1082: } elsif (($action eq 'contacts') || ($action eq 'privacy') ||
1083: ($action eq 'passwords') || ($action eq 'lti')) {
1.354 raeburn 1084: if ($action eq 'passwords') {
1085: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1086: } else {
1087: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1088: }
1.434 raeburn 1089: $hdridx ++;
1.354 raeburn 1090: $output .= '
1.340 raeburn 1091: </tr>
1092: </table>
1093: </td>
1094: </tr>
1095: <tr>
1096: <td>
1097: <table class="LC_nested">
1098: <tr class="LC_info_row">
1.434 raeburn 1099: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1100: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td></tr>'."\n";
1.354 raeburn 1101: if ($action eq 'passwords') {
1102: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1103: } else {
1104: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1105: }
1106: $output .= '
1.340 raeburn 1107: </table>
1108: </td>
1109: </tr>
1110: <tr>';
1.279 raeburn 1111: } else {
1112: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1113: }
1.238 raeburn 1114: }
1.63 raeburn 1115: $rowtotal ++;
1.443 raeburn 1116: } elsif (($action eq 'coursedefaults') || ($action eq 'authordefaults') ||
1.409 raeburn 1117: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1.443 raeburn 1118: ($action eq 'wafproxy')) {
1.230 raeburn 1119: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1120: } elsif ($action eq 'scantron') {
1121: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1122: } elsif ($action eq 'ssl') {
1123: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1124: </table>
1125: </td>
1126: </tr>
1127: <tr>
1128: <td>
1129: <table class="LC_nested">
1130: <tr class="LC_info_row">
1131: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1132: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1133: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1134: </table>
1135: </td>
1136: </tr>
1137: <tr>
1138: <td>
1139: <table class="LC_nested">
1140: <tr class="LC_info_row">
1141: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1142: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1143: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1144: } elsif ($action eq 'login') {
1.386 raeburn 1145: if ($numheaders == 5) {
1.168 raeburn 1146: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1147: </table>
1148: </td>
1149: </tr>
1150: <tr>
1151: <td>
1152: <table class="LC_nested">
1153: <tr class="LC_info_row">
1154: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1155: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1156: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1157: $rowtotal ++;
1158: } else {
1159: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1160: }
1.256 raeburn 1161: $output .= '
1162: </table>
1163: </td>
1164: </tr>
1165: <tr>
1166: <td>
1167: <table class="LC_nested">
1168: <tr class="LC_info_row">';
1.386 raeburn 1169: if ($numheaders == 5) {
1.256 raeburn 1170: $output .= '
1171: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1172: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1173: </tr>';
1174: } else {
1175: $output .= '
1176: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1177: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1178: </tr>';
1179: }
1180: $rowtotal ++;
1.386 raeburn 1181: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1182: </table>
1183: </td>
1184: </tr>
1185: <tr>
1186: <td>
1187: <table class="LC_nested">
1188: <tr class="LC_info_row">';
1189: if ($numheaders == 5) {
1190: $output .= '
1191: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1192: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1193: </tr>';
1194: } else {
1195: $output .= '
1196: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1197: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1198: </tr>';
1199: }
1200: $rowtotal ++;
1201: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1202: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1203: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1204: $rowtotal ++;
1205: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1206: </table>
1207: </td>
1208: </tr>
1209: <tr>
1210: <td>
1211: <table class="LC_nested">
1212: <tr class="LC_info_row">
1213: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1214: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1215: &textbookcourses_javascript($settings).
1216: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1217: </table>
1218: </td>
1219: </tr>
1220: <tr>
1221: <td>
1222: <table class="LC_nested">
1223: <tr class="LC_info_row">
1224: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1225: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1226: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1227: </table>
1228: </td>
1229: </tr>
1230: <tr>
1231: <td>
1232: <table class="LC_nested">
1233: <tr class="LC_info_row">
1.306 raeburn 1234: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1235: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1236: </tr>'.
1237: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1238: } elsif ($action eq 'requestauthor') {
1239: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1240: $rowtotal ++;
1.122 jms 1241: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1242: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1243: </table>
1244: </td>
1245: </tr>
1246: <tr>
1247: <td>
1248: <table class="LC_nested">
1249: <tr class="LC_info_row">
1.306 raeburn 1250: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1251: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1252: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1253: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1254: </tr>'.
1.30 raeburn 1255: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1256: </table>
1257: </td>
1258: </tr>
1259: <tr>
1260: <td>
1261: <table class="LC_nested">
1262: <tr class="LC_info_row">
1.59 bisitz 1263: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1264: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1265: </tr>'.
1.30 raeburn 1266: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1267: $rowtotal += 2;
1.6 raeburn 1268: }
1.3 raeburn 1269: } else {
1.30 raeburn 1270: $output .= '
1.3 raeburn 1271: <tr>
1272: <td>
1273: <table class="LC_nested">
1.30 raeburn 1274: <tr class="LC_info_row">';
1.277 raeburn 1275: if ($action eq 'login') {
1.30 raeburn 1276: $output .= '
1.59 bisitz 1277: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1278: } elsif ($action eq 'serverstatuses') {
1279: $output .= '
1.306 raeburn 1280: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1281: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1282:
1.6 raeburn 1283: } else {
1.30 raeburn 1284: $output .= '
1.306 raeburn 1285: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1286: }
1.72 raeburn 1287: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1288: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1289: &mt($item->{'header'}->[0]->{'col2'});
1290: if ($action eq 'serverstatuses') {
1291: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1292: }
1.69 raeburn 1293: } else {
1.306 raeburn 1294: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1295: &mt($item->{'header'}->[0]->{'col2'});
1296: }
1297: $output .= '</td>';
1298: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1299: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1300: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1301: &mt($item->{'header'}->[0]->{'col3'});
1302: } else {
1.306 raeburn 1303: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1304: &mt($item->{'header'}->[0]->{'col3'});
1305: }
1.69 raeburn 1306: if ($action eq 'serverstatuses') {
1307: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1308: }
1309: $output .= '</td>';
1.6 raeburn 1310: }
1.150 raeburn 1311: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1312: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1313: &mt($item->{'header'}->[0]->{'col4'});
1314: }
1.69 raeburn 1315: $output .= '</tr>';
1.48 raeburn 1316: $rowtotal ++;
1.168 raeburn 1317: if ($action eq 'quotas') {
1.86 raeburn 1318: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1319: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1320: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.447.2.1! raeburn 1321: ($action eq 'ipaccess')) {
1.230 raeburn 1322: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1323: }
1.3 raeburn 1324: }
1.30 raeburn 1325: $output .= '
1.3 raeburn 1326: </table>
1327: </td>
1328: </tr>
1.30 raeburn 1329: </table><br />';
1330: return ($output,$rowtotal);
1.1 raeburn 1331: }
1332:
1.3 raeburn 1333: sub print_login {
1.168 raeburn 1334: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1335: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1336: my %choices = &login_choices();
1.386 raeburn 1337: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1338: %lt = &login_file_options();
1339: $switchserver = &check_switchserver($dom,$confname);
1340: }
1.168 raeburn 1341: if ($caller eq 'service') {
1.149 raeburn 1342: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1343: my $choice = $choices{'disallowlogin'};
1344: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1345: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1346: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1347: '<th>'.$choices{'server'}.'</th>'.
1348: '<th>'.$choices{'serverpath'}.'</th>'.
1349: '<th>'.$choices{'custompath'}.'</th>'.
1350: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1351: my %disallowed;
1352: if (ref($settings) eq 'HASH') {
1353: if (ref($settings->{'loginvia'}) eq 'HASH') {
1354: %disallowed = %{$settings->{'loginvia'}};
1355: }
1356: }
1357: foreach my $lonhost (sort(keys(%servers))) {
1358: my $direct = 'selected="selected"';
1.128 raeburn 1359: if (ref($disallowed{$lonhost}) eq 'HASH') {
1360: if ($disallowed{$lonhost}{'server'} ne '') {
1361: $direct = '';
1362: }
1.110 raeburn 1363: }
1.115 raeburn 1364: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1365: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1366: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1367: '</option>';
1.184 raeburn 1368: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1369: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1370: my $selected = '';
1.128 raeburn 1371: if (ref($disallowed{$lonhost}) eq 'HASH') {
1372: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1373: $selected = 'selected="selected"';
1374: }
1.110 raeburn 1375: }
1376: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1377: $servers{$hostid}.'</option>';
1378: }
1.128 raeburn 1379: $datatable .= '</select></td>'.
1380: '<td><select name="'.$lonhost.'_serverpath">';
1381: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1382: my $pathname = $path;
1383: if ($path eq 'custom') {
1384: $pathname = &mt('Custom Path').' ->';
1385: }
1386: my $selected = '';
1387: if (ref($disallowed{$lonhost}) eq 'HASH') {
1388: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1389: $selected = 'selected="selected"';
1390: }
1391: } elsif ($path eq '') {
1392: $selected = 'selected="selected"';
1393: }
1394: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1395: }
1396: $datatable .= '</select></td>';
1397: my ($custom,$exempt);
1398: if (ref($disallowed{$lonhost}) eq 'HASH') {
1399: $custom = $disallowed{$lonhost}{'custompath'};
1400: $exempt = $disallowed{$lonhost}{'exempt'};
1401: }
1402: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1403: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1404: '</tr>';
1.110 raeburn 1405: }
1406: $datatable .= '</table></td></tr>';
1407: return $datatable;
1.168 raeburn 1408: } elsif ($caller eq 'page') {
1409: my %defaultchecked = (
1410: 'coursecatalog' => 'on',
1.188 raeburn 1411: 'helpdesk' => 'on',
1.168 raeburn 1412: 'adminmail' => 'off',
1413: 'newuser' => 'off',
1414: );
1.188 raeburn 1415: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1416: my (%checkedon,%checkedoff);
1.42 raeburn 1417: foreach my $item (@toggles) {
1.168 raeburn 1418: if ($defaultchecked{$item} eq 'on') {
1419: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1420: $checkedoff{$item} = ' ';
1.168 raeburn 1421: } elsif ($defaultchecked{$item} eq 'off') {
1422: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1423: $checkedon{$item} = ' ';
1424: }
1.1 raeburn 1425: }
1.168 raeburn 1426: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1427: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1428: my @logintext = ('textcol','bgcol');
1429: my @bgs = ('pgbg','mainbg','sidebg');
1430: my @links = ('link','alink','vlink');
1431: my %designhash = &Apache::loncommon::get_domainconf($dom);
1432: my %defaultdesign = %Apache::loncommon::defaultdesign;
1433: my (%is_custom,%designs);
1434: my %defaults = (
1435: font => $defaultdesign{'login.font'},
1436: );
1.6 raeburn 1437: foreach my $item (@images) {
1.168 raeburn 1438: $defaults{$item} = $defaultdesign{'login.'.$item};
1439: $defaults{'showlogo'}{$item} = 1;
1440: }
1441: foreach my $item (@bgs) {
1442: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1443: }
1.41 raeburn 1444: foreach my $item (@logintext) {
1.168 raeburn 1445: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1446: }
1.168 raeburn 1447: foreach my $item (@links) {
1448: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1449: }
1.168 raeburn 1450: if (ref($settings) eq 'HASH') {
1451: foreach my $item (@toggles) {
1452: if ($settings->{$item} eq '1') {
1453: $checkedon{$item} = ' checked="checked" ';
1454: $checkedoff{$item} = ' ';
1455: } elsif ($settings->{$item} eq '0') {
1456: $checkedoff{$item} = ' checked="checked" ';
1457: $checkedon{$item} = ' ';
1458: }
1459: }
1460: foreach my $item (@images) {
1461: if (defined($settings->{$item})) {
1462: $designs{$item} = $settings->{$item};
1463: $is_custom{$item} = 1;
1464: }
1465: if (defined($settings->{'showlogo'}{$item})) {
1466: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1467: }
1468: }
1.402 raeburn 1469: foreach my $item (@alttext) {
1470: if (ref($settings->{'alttext'}) eq 'HASH') {
1471: if ($settings->{'alttext'}->{$item} ne '') {
1472: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1473: }
1474: }
1475: }
1.168 raeburn 1476: foreach my $item (@logintext) {
1477: if ($settings->{$item} ne '') {
1478: $designs{'logintext'}{$item} = $settings->{$item};
1479: $is_custom{$item} = 1;
1480: }
1481: }
1482: if ($settings->{'font'} ne '') {
1483: $designs{'font'} = $settings->{'font'};
1484: $is_custom{'font'} = 1;
1485: }
1486: foreach my $item (@bgs) {
1487: if ($settings->{$item} ne '') {
1488: $designs{'bgs'}{$item} = $settings->{$item};
1489: $is_custom{$item} = 1;
1490: }
1491: }
1492: foreach my $item (@links) {
1493: if ($settings->{$item} ne '') {
1494: $designs{'links'}{$item} = $settings->{$item};
1495: $is_custom{$item} = 1;
1496: }
1497: }
1498: } else {
1499: if ($designhash{$dom.'.login.font'} ne '') {
1500: $designs{'font'} = $designhash{$dom.'.login.font'};
1501: $is_custom{'font'} = 1;
1502: }
1503: foreach my $item (@images) {
1504: if ($designhash{$dom.'.login.'.$item} ne '') {
1505: $designs{$item} = $designhash{$dom.'.login.'.$item};
1506: $is_custom{$item} = 1;
1507: }
1508: }
1509: foreach my $item (@bgs) {
1510: if ($designhash{$dom.'.login.'.$item} ne '') {
1511: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1512: $is_custom{$item} = 1;
1513: }
1.6 raeburn 1514: }
1.168 raeburn 1515: foreach my $item (@links) {
1516: if ($designhash{$dom.'.login.'.$item} ne '') {
1517: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1518: $is_custom{$item} = 1;
1519: }
1.6 raeburn 1520: }
1521: }
1.168 raeburn 1522: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1523: logo => 'Institution Logo',
1524: domlogo => 'Domain Logo',
1525: login => 'Login box');
1526: my $itemcount = 1;
1527: foreach my $item (@toggles) {
1528: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1529: $datatable .=
1530: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1531: '</td><td>'.
1532: '<span class="LC_nobreak"><label><input type="radio" name="'.
1533: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1534: '</label> <label><input type="radio" name="'.$item.'"'.
1535: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1536: '</tr>';
1537: $itemcount ++;
1.6 raeburn 1538: }
1.168 raeburn 1539: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1540: $datatable .= '</tr></table></td></tr>';
1541: } elsif ($caller eq 'help') {
1.386 raeburn 1542: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1543: my $itemcount = 1;
1544: $defaulturl = '/adm/loginproblems.html';
1545: $defaulttype = 'default';
1546: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1547: my @currlangs;
1548: if (ref($settings) eq 'HASH') {
1549: if (ref($settings->{'helpurl'}) eq 'HASH') {
1550: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1551: next if ($settings->{'helpurl'}{$key} eq '');
1552: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1553: $type{$key} = 'custom';
1554: unless ($key eq 'nolang') {
1555: push(@currlangs,$key);
1556: }
1557: }
1558: } elsif ($settings->{'helpurl'} ne '') {
1559: $type{'nolang'} = 'custom';
1560: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1561: }
1562: }
1.168 raeburn 1563: foreach my $lang ('nolang',sort(@currlangs)) {
1564: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1565: $datatable .= '<tr'.$css_class.'>';
1566: if ($url{$lang} eq '') {
1567: $url{$lang} = $defaulturl;
1568: }
1569: if ($type{$lang} eq '') {
1570: $type{$lang} = $defaulttype;
1571: }
1572: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1573: if ($lang eq 'nolang') {
1574: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1575: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1576: } else {
1577: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1578: $langchoices{$lang},
1579: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1580: }
1581: $datatable .= '</span></td>'."\n".
1582: '<td class="LC_left_item">';
1583: if ($type{$lang} eq 'custom') {
1584: $datatable .= '<span class="LC_nobreak"><label>'.
1585: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1586: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1587: } else {
1588: $datatable .= $lt{'upl'};
1589: }
1590: $datatable .='<br />';
1591: if ($switchserver) {
1592: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1593: } else {
1594: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1595: }
1.168 raeburn 1596: $datatable .= '</td></tr>';
1597: $itemcount ++;
1.6 raeburn 1598: }
1.168 raeburn 1599: my @addlangs;
1600: foreach my $lang (sort(keys(%langchoices))) {
1601: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1602: push(@addlangs,$lang);
1603: }
1604: if (@addlangs > 0) {
1605: my %toadd;
1606: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1607: $toadd{''} = &mt('Select');
1608: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1609: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1610: &mt('Add log-in help page for a specific language:').' '.
1611: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1612: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1613: if ($switchserver) {
1614: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1615: } else {
1616: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1617: }
1.168 raeburn 1618: $datatable .= '</td></tr>';
1.169 raeburn 1619: $itemcount ++;
1.6 raeburn 1620: }
1.169 raeburn 1621: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1622: } elsif ($caller eq 'headtag') {
1623: my %domservers = &Apache::lonnet::get_servers($dom);
1624: my $choice = $choices{'headtag'};
1625: $css_class = ' class="LC_odd_row"';
1626: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1627: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1628: '<th>'.$choices{'current'}.'</th>'.
1629: '<th>'.$choices{'action'}.'</th>'.
1630: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1631: my (%currurls,%currexempt);
1632: if (ref($settings) eq 'HASH') {
1633: if (ref($settings->{'headtag'}) eq 'HASH') {
1634: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1635: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1636: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1637: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1638: }
1639: }
1640: }
1641: }
1642: foreach my $lonhost (sort(keys(%domservers))) {
1643: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1644: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1645: if ($currurls{$lonhost}) {
1646: $datatable .= '<td class="LC_right_item"><a href="'.
1647: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1648: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1649: '">'.$lt{'curr'}.'</a></td>'.
1650: '<td><span class="LC_nobreak"><label>'.
1651: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1652: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1653: } else {
1654: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1655: }
1656: $datatable .='<br />';
1657: if ($switchserver) {
1658: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1659: } else {
1660: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1661: }
1.330 raeburn 1662: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1663: }
1664: $datatable .= '</table></td></tr>';
1.386 raeburn 1665: } elsif ($caller eq 'saml') {
1666: my %domservers = &Apache::lonnet::get_servers($dom);
1667: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1668: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1669: '<th>'.$choices{'samllanding'}.'</th>'.
1670: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1671: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1672: foreach my $lonhost (keys(%domservers)) {
1673: $samlurl{$lonhost} = '/adm/sso';
1674: $styleon{$lonhost} = 'display:none';
1675: $styleoff{$lonhost} = '';
1676: }
1.411 raeburn 1677: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1678: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1679: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1680: $saml{$lonhost} = 1;
1681: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1682: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1683: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1684: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1685: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1686: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1687: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1688: $styleon{$lonhost} = '';
1689: $styleoff{$lonhost} = 'display:none';
1690: } else {
1691: $styleon{$lonhost} = 'display:none';
1692: $styleoff{$lonhost} = '';
1693: }
1694: }
1695: }
1696: my $itemcount = 1;
1697: foreach my $lonhost (sort(keys(%domservers))) {
1698: my $samlon = ' ';
1699: my $samloff = ' checked="checked" ';
1700: if ($saml{$lonhost}) {
1701: $samlon = $samloff;
1702: $samloff = ' ';
1703: }
1.412 raeburn 1704: my $samlwinon = '';
1705: my $samlwinoff = ' checked="checked"';
1706: if ($samlwindow{$lonhost}) {
1707: $samlwinon = $samlwinoff;
1708: $samlwinoff = '';
1709: }
1.386 raeburn 1710: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1711: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1712: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1713: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1714: &mt('No').'</label>'.(' 'x2).
1715: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1716: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1717: &mt('Yes').'</label></span></td>'.
1718: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1719: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1720: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1721: '<th>'.&mt('Alt Text').'</th></tr>'.
1722: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1723: $samltext{$lonhost}.'" /></td><td>';
1724: if ($samlimg{$lonhost}) {
1725: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1726: '<span class="LC_nobreak"><label>'.
1727: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1728: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1729: } else {
1730: $datatable .= $lt{'upl'};
1731: }
1732: $datatable .='<br />';
1733: if ($switchserver) {
1734: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1735: } else {
1736: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1737: }
1738: $datatable .= '</td>'.
1.412 raeburn 1739: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1740: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1741: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1742: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1743: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1744: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1745: '<tr'.$css_class.'>'.
1746: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1747: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1748: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1749: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1750: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1751: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1752: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1753: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1754: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1755: '</table></td>'.
1756: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1757: $itemcount ++;
1758: }
1759: $datatable .= '</table></td></tr>';
1.1 raeburn 1760: }
1.6 raeburn 1761: return $datatable;
1762: }
1763:
1764: sub login_choices {
1765: my %choices =
1766: &Apache::lonlocal::texthash (
1.116 bisitz 1767: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1768: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1769: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1770: disallowlogin => "Login page requests redirected",
1771: hostid => "Server",
1.128 raeburn 1772: server => "Redirect to:",
1773: serverpath => "Path",
1774: custompath => "Custom",
1775: exempt => "Exempt IP(s)",
1.110 raeburn 1776: directlogin => "No redirect",
1777: newuser => "Link to create a user account",
1778: img => "Header",
1779: logo => "Main Logo",
1780: domlogo => "Domain Logo",
1781: login => "Log-in Header",
1782: textcol => "Text color",
1783: bgcol => "Box color",
1784: bgs => "Background colors",
1785: links => "Link colors",
1786: font => "Font color",
1787: pgbg => "Header",
1788: mainbg => "Page",
1789: sidebg => "Login box",
1790: link => "Link",
1791: alink => "Active link",
1792: vlink => "Visited link",
1.256 raeburn 1793: headtag => "Custom markup",
1794: action => "Action",
1795: current => "Current",
1.386 raeburn 1796: samllanding => "Dual login?",
1797: samloptions => "Options",
1.402 raeburn 1798: alttext => "Alt text",
1.6 raeburn 1799: );
1800: return %choices;
1801: }
1802:
1.386 raeburn 1803: sub login_file_options {
1804: return &Apache::lonlocal::texthash(
1805: del => 'Delete?',
1806: rep => 'Replace:',
1807: upl => 'Upload:',
1808: curr => 'View contents',
1809: default => 'Default',
1810: custom => 'Custom',
1811: none => 'None',
1812: );
1813: }
1814:
1.394 raeburn 1815: sub print_ipaccess {
1816: my ($dom,$settings,$rowtotal) = @_;
1817: my $css_class;
1818: my $itemcount = 0;
1819: my $datatable;
1820: my %ordered;
1821: if (ref($settings) eq 'HASH') {
1822: foreach my $item (keys(%{$settings})) {
1823: if (ref($settings->{$item}) eq 'HASH') {
1824: my $num = $settings->{$item}{'order'};
1825: if ($num eq '') {
1826: $num = scalar(keys(%{$settings}));
1827: }
1828: $ordered{$num} = $item;
1829: }
1830: }
1831: }
1832: my $maxnum = scalar(keys(%ordered));
1833: if (keys(%ordered)) {
1834: my @items = sort { $a <=> $b } keys(%ordered);
1835: for (my $i=0; $i<@items; $i++) {
1836: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1837: my $item = $ordered{$items[$i]};
1838: my ($name,$ipranges,%commblocks,%courses);
1839: if (ref($settings->{$item}) eq 'HASH') {
1840: $name = $settings->{$item}->{'name'};
1841: $ipranges = $settings->{$item}->{'ip'};
1842: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1843: %commblocks = %{$settings->{$item}->{'commblocks'}};
1844: }
1845: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1846: %courses = %{$settings->{$item}->{'courses'}};
1847: }
1848: }
1849: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1850: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1851: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1852: for (my $k=0; $k<=$maxnum; $k++) {
1853: my $vpos = $k+1;
1854: my $selstr;
1855: if ($k == $i) {
1856: $selstr = ' selected="selected" ';
1857: }
1858: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1859: }
1860: $datatable .= '</select>'.(' 'x2).
1861: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1862: &mt('Delete?').'</label></span></td>'.
1863: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1864: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1865: '</td></tr>';
1866: $itemcount ++;
1867: }
1868: }
1869: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1870: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1871: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1872: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1873: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1874: for (my $k=0; $k<$maxnum+1; $k++) {
1875: my $vpos = $k+1;
1876: my $selstr;
1877: if ($k == $maxnum) {
1878: $selstr = ' selected="selected" ';
1879: }
1880: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1881: }
1882: $datatable .= '</select> '."\n".
1883: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1884: '<td colspan="2">'.
1885: &ipaccess_options('add',$itemcount,$dom).
1886: '</td>'."\n".
1887: '</tr>'."\n";
1888: $$rowtotal ++;
1889: return $datatable;
1890: }
1891:
1892: sub ipaccess_options {
1893: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1894: my (%currblocks,%currcourses,$output);
1895: if (ref($blocksref) eq 'HASH') {
1896: %currblocks = %{$blocksref};
1897: }
1898: if (ref($coursesref) eq 'HASH') {
1899: %currcourses = %{$coursesref};
1900: }
1901: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1902: '<span class="LC_nobreak">'.&mt('Name').': '.
1903: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1904: '</span></fieldset>'.
1905: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1906: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1907: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1908: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1909: $ipranges.'</textarea></fieldset>'.
1910: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1911: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1912: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1913: '<table>';
1914: foreach my $cid (sort(keys(%currcourses))) {
1915: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1916: $output .= '<tr><td><span class="LC_nobreak">'.
1917: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1918: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1919: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1920: }
1921: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1922: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1923: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1924: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1925: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1926: '</span></td></tr></table>'."\n".
1927: '</fieldset>';
1928: return $output;
1929: }
1930:
1931: sub blocker_checkboxes {
1932: my ($num,$blocks) = @_;
1933: my ($typeorder,$types) = &commblocktype_text();
1934: my $numinrow = 6;
1935: my $output = '<table>';
1936: for (my $i=0; $i<@{$typeorder}; $i++) {
1937: my $block = $typeorder->[$i];
1938: my $blockstatus;
1939: if (ref($blocks) eq 'HASH') {
1940: if ($blocks->{$block} eq 'on') {
1941: $blockstatus = 'checked="checked"';
1942: }
1943: }
1944: my $rem = $i%($numinrow);
1945: if ($rem == 0) {
1946: if ($i > 0) {
1947: $output .= '</tr>';
1948: }
1949: $output .= '<tr>';
1950: }
1951: if ($i == scalar(@{$typeorder})-1) {
1952: my $colsleft = $numinrow-$rem;
1953: if ($colsleft > 1) {
1954: $output .= '<td colspan="'.$colsleft.'">';
1955: } else {
1956: $output .= '<td>';
1957: }
1958: } else {
1959: $output .= '<td>';
1960: }
1961: my $item = 'ipaccess_block_'.$num;
1962: if ($blockstatus) {
1963: $blockstatus = ' '.$blockstatus;
1964: }
1965: $output .= '<span class="LC_nobreak"><label>'."\n".
1966: '<input type="checkbox" name="'.$item.'"'.
1967: $blockstatus.' value="'.$block.'"'.' />'.
1968: $types->{$block}.'</label></span>'."\n".
1969: '<br /></td>';
1970: }
1971: $output .= '</tr></table>';
1972: return $output;
1973: }
1974:
1975: sub commblocktype_text {
1976: my %types = &Apache::lonlocal::texthash(
1977: 'com' => 'Messaging',
1978: 'chat' => 'Chat Room',
1979: 'boards' => 'Discussion',
1980: 'port' => 'Portfolio',
1981: 'groups' => 'Groups',
1982: 'blogs' => 'Blogs',
1983: 'about' => 'User Information',
1984: 'printout' => 'Printouts',
1985: 'passwd' => 'Change Password',
1986: 'grades' => 'Gradebook',
1.397 raeburn 1987: 'search' => 'Course search',
1.447 raeburn 1988: 'index' => 'Course content index',
1.397 raeburn 1989: 'wishlist' => 'Stored links',
1990: 'annotate' => 'Annotations',
1.394 raeburn 1991: );
1.447 raeburn 1992: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','index','annotate','passwd'];
1.394 raeburn 1993: return ($typeorder,\%types);
1994: }
1995:
1.6 raeburn 1996: sub print_rolecolors {
1.30 raeburn 1997: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1998: my %choices = &color_font_choices();
1999: my @bgs = ('pgbg','tabbg','sidebg');
2000: my @links = ('link','alink','vlink');
1.445 raeburn 2001: my @images = ();
1.6 raeburn 2002: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 2003: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 2004: my %defaultdesign = %Apache::loncommon::defaultdesign;
2005: my (%is_custom,%designs);
1.200 raeburn 2006: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 2007: if (ref($settings) eq 'HASH') {
2008: if (ref($settings->{$role}) eq 'HASH') {
2009: if ($settings->{$role}->{'font'} ne '') {
2010: $designs{'font'} = $settings->{$role}->{'font'};
2011: $is_custom{'font'} = 1;
2012: }
1.97 tempelho 2013: if ($settings->{$role}->{'fontmenu'} ne '') {
2014: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
2015: $is_custom{'fontmenu'} = 1;
2016: }
1.6 raeburn 2017: foreach my $item (@bgs) {
2018: if ($settings->{$role}->{$item} ne '') {
2019: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
2020: $is_custom{$item} = 1;
2021: }
2022: }
2023: foreach my $item (@links) {
2024: if ($settings->{$role}->{$item} ne '') {
2025: $designs{'links'}{$item} = $settings->{$role}->{$item};
2026: $is_custom{$item} = 1;
2027: }
2028: }
2029: }
2030: } else {
1.97 tempelho 2031: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2032: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2033: $is_custom{'fontmenu'} = 1;
2034: }
1.6 raeburn 2035: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2036: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2037: $is_custom{'font'} = 1;
2038: }
2039: foreach my $item (@bgs) {
2040: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2041: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2042: $is_custom{$item} = 1;
2043:
2044: }
2045: }
2046: foreach my $item (@links) {
2047: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2048: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2049: $is_custom{$item} = 1;
2050: }
2051: }
2052: }
2053: my $itemcount = 1;
1.30 raeburn 2054: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2055: $datatable .= '</tr></table></td></tr>';
2056: return $datatable;
2057: }
2058:
1.200 raeburn 2059: sub role_defaults {
2060: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2061: my %defaults;
2062: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2063: return %defaults;
2064: }
2065: my %defaultdesign = %Apache::loncommon::defaultdesign;
2066: if ($role eq 'login') {
2067: %defaults = (
2068: font => $defaultdesign{$role.'.font'},
2069: );
2070: if (ref($logintext) eq 'ARRAY') {
2071: foreach my $item (@{$logintext}) {
2072: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2073: }
2074: }
2075: foreach my $item (@{$images}) {
2076: $defaults{'showlogo'}{$item} = 1;
2077: }
2078: } else {
2079: %defaults = (
2080: font => $defaultdesign{$role.'.font'},
2081: fontmenu => $defaultdesign{$role.'.fontmenu'},
2082: );
2083: }
2084: foreach my $item (@{$bgs}) {
2085: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2086: }
2087: foreach my $item (@{$links}) {
2088: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2089: }
2090: foreach my $item (@{$images}) {
2091: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2092: }
2093: return %defaults;
2094: }
2095:
1.6 raeburn 2096: sub display_color_options {
1.9 raeburn 2097: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2098: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2099: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2100: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2101: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2102: '<td>'.$choices->{'font'}.'</td>';
2103: if (!$is_custom->{'font'}) {
1.329 raeburn 2104: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2105: } else {
2106: $datatable .= '<td> </td>';
2107: }
1.174 foxr 2108: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2109:
1.8 raeburn 2110: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2111: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2112: ' value="'.$current_color.'" /> '.
1.329 raeburn 2113: ' </span></td></tr>';
1.107 raeburn 2114: unless ($role eq 'login') {
2115: $datatable .= '<tr'.$css_class.'>'.
2116: '<td>'.$choices->{'fontmenu'}.'</td>';
2117: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2118: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2119: } else {
2120: $datatable .= '<td> </td>';
2121: }
1.202 raeburn 2122: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2123: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2124: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2125: '<input class="colorchooser" type="text" size="10" name="'
2126: .$role.'_fontmenu"'.
2127: ' value="'.$current_color.'" /> '.
1.329 raeburn 2128: ' </span></td></tr>';
1.97 tempelho 2129: }
1.9 raeburn 2130: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2131: foreach my $img (@{$images}) {
1.18 albertel 2132: $itemcount ++;
1.6 raeburn 2133: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2134: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2135: '<td>'.$choices->{$img};
1.402 raeburn 2136: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2137: if ($role eq 'login') {
2138: if ($img eq 'login') {
2139: $login_hdr_pick =
1.135 bisitz 2140: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2141: $logincolors =
2142: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2143: $designs,$defaults);
1.402 raeburn 2144: } else {
2145: if ($img ne 'domlogo') {
2146: $datatable.= &logo_display_options($img,$defaults,$designs);
2147: }
2148: if (ref($designs->{'alttext'}) eq 'HASH') {
2149: $alttext = $designs->{'alttext'}{$img};
2150: }
1.70 raeburn 2151: }
2152: }
2153: $datatable .= '</td>';
1.6 raeburn 2154: if ($designs->{$img} ne '') {
2155: $imgfile = $designs->{$img};
1.18 albertel 2156: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2157: } else {
2158: $imgfile = $defaults->{$img};
2159: }
2160: if ($imgfile) {
1.9 raeburn 2161: my ($showfile,$fullsize);
2162: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2163: my $urldir = $1;
2164: my $filename = $2;
2165: my @info = &Apache::lonnet::stat_file($designs->{$img});
2166: if (@info) {
2167: my $thumbfile = 'tn-'.$filename;
2168: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2169: if (@thumb) {
2170: $showfile = $urldir.'/'.$thumbfile;
2171: } else {
2172: $showfile = $imgfile;
2173: }
2174: } else {
2175: $showfile = '';
2176: }
2177: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2178: $showfile = $imgfile;
1.6 raeburn 2179: my $imgdir = $1;
2180: my $filename = $2;
1.159 raeburn 2181: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2182: $showfile = "/$imgdir/tn-".$filename;
2183: } else {
1.159 raeburn 2184: my $input = $londocroot.$imgfile;
2185: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2186: if (!-e $output) {
1.9 raeburn 2187: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2188: my ($fullwidth,$fullheight) = &check_dimensions($input);
2189: if ($fullwidth ne '' && $fullheight ne '') {
2190: if ($fullwidth > $width && $fullheight > $height) {
2191: my $size = $width.'x'.$height;
1.316 raeburn 2192: my @args = ('convert','-sample',$size,$input,$output);
2193: system({$args[0]} @args);
1.159 raeburn 2194: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2195: }
2196: }
1.6 raeburn 2197: }
2198: }
1.16 raeburn 2199: }
1.6 raeburn 2200: if ($showfile) {
1.40 raeburn 2201: if ($showfile =~ m{^/(adm|res)/}) {
2202: if ($showfile =~ m{^/res/}) {
2203: my $local_showfile =
2204: &Apache::lonnet::filelocation('',$showfile);
2205: &Apache::lonnet::repcopy($local_showfile);
2206: }
2207: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2208: }
2209: if ($imgfile) {
2210: if ($imgfile =~ m{^/(adm|res)/}) {
2211: if ($imgfile =~ m{^/res/}) {
2212: my $local_imgfile =
2213: &Apache::lonnet::filelocation('',$imgfile);
2214: &Apache::lonnet::repcopy($local_imgfile);
2215: }
2216: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2217: } else {
2218: $fullsize = $imgfile;
2219: }
2220: }
1.41 raeburn 2221: $datatable .= '<td>';
2222: if ($img eq 'login') {
1.135 bisitz 2223: $datatable .= $login_hdr_pick;
2224: }
1.41 raeburn 2225: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2226: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2227: } else {
1.201 raeburn 2228: $datatable .= '<td> </td><td class="LC_left_item">'.
2229: &mt('Upload:').'<br />';
1.6 raeburn 2230: }
2231: } else {
1.201 raeburn 2232: $datatable .= '<td> </td><td class="LC_left_item">'.
2233: &mt('Upload:').'<br />';
1.6 raeburn 2234: }
1.9 raeburn 2235: if ($switchserver) {
2236: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2237: } else {
1.135 bisitz 2238: if ($img ne 'login') { # suppress file selection for Log-in header
2239: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2240: }
1.9 raeburn 2241: }
1.402 raeburn 2242: if (($role eq 'login') && ($img ne 'login')) {
2243: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2244: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2245: '</label></span>';
2246: }
1.9 raeburn 2247: $datatable .= '</td></tr>';
1.6 raeburn 2248: }
2249: $itemcount ++;
2250: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2251: $datatable .= '<tr'.$css_class.'>'.
2252: '<td>'.$choices->{'bgs'}.'</td>';
2253: my $bgs_def;
2254: foreach my $item (@{$bgs}) {
2255: if (!$is_custom->{$item}) {
1.329 raeburn 2256: $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 2257: }
2258: }
2259: if ($bgs_def) {
1.8 raeburn 2260: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2261: } else {
2262: $datatable .= '<td> </td>';
2263: }
2264: $datatable .= '<td class="LC_right_item">'.
2265: '<table border="0"><tr>';
1.174 foxr 2266:
1.6 raeburn 2267: foreach my $item (@{$bgs}) {
1.306 raeburn 2268: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2269: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2270: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2271: $datatable .= ' ';
1.6 raeburn 2272: }
1.174 foxr 2273: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2274: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2275: }
2276: $datatable .= '</tr></table></td></tr>';
2277: $itemcount ++;
2278: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2279: $datatable .= '<tr'.$css_class.'>'.
2280: '<td>'.$choices->{'links'}.'</td>';
2281: my $links_def;
2282: foreach my $item (@{$links}) {
2283: if (!$is_custom->{$item}) {
1.329 raeburn 2284: $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 2285: }
2286: }
2287: if ($links_def) {
1.8 raeburn 2288: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2289: } else {
2290: $datatable .= '<td> </td>';
2291: }
2292: $datatable .= '<td class="LC_right_item">'.
2293: '<table border="0"><tr>';
2294: foreach my $item (@{$links}) {
1.234 raeburn 2295: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2296: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2297: if ($designs->{'links'}{$item}) {
1.174 foxr 2298: $datatable.=' ';
1.6 raeburn 2299: }
1.174 foxr 2300: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2301: '" /></td>';
2302: }
1.30 raeburn 2303: $$rowtotal += $itemcount;
1.3 raeburn 2304: return $datatable;
2305: }
2306:
1.70 raeburn 2307: sub logo_display_options {
2308: my ($img,$defaults,$designs) = @_;
2309: my $checkedon;
2310: if (ref($defaults) eq 'HASH') {
2311: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2312: if ($defaults->{'showlogo'}{$img}) {
2313: $checkedon = 'checked="checked" ';
2314: }
2315: }
2316: }
2317: if (ref($designs) eq 'HASH') {
2318: if (ref($designs->{'showlogo'}) eq 'HASH') {
2319: if (defined($designs->{'showlogo'}{$img})) {
2320: if ($designs->{'showlogo'}{$img} == 0) {
2321: $checkedon = '';
2322: } elsif ($designs->{'showlogo'}{$img} == 1) {
2323: $checkedon = 'checked="checked" ';
2324: }
2325: }
2326: }
2327: }
2328: return '<br /><label> <input type="checkbox" name="'.
2329: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2330: &mt('show').'</label>'."\n";
2331: }
2332:
1.41 raeburn 2333: sub login_header_options {
1.135 bisitz 2334: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2335: my $output = '';
1.41 raeburn 2336: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2337: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2338: if (!$is_custom->{'textcol'}) {
2339: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2340: ' ';
2341: }
2342: if (!$is_custom->{'bgcol'}) {
2343: $output .= $choices->{'bgcol'}.': '.
2344: '<span id="css_'.$role.'_font" style="background-color: '.
2345: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2346: }
2347: $output .= '<br />';
2348: }
2349: $output .='<br />';
2350: return $output;
2351: }
2352:
2353: sub login_text_colors {
1.201 raeburn 2354: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2355: my $color_menu = '<table border="0"><tr>';
2356: foreach my $item (@{$logintext}) {
1.306 raeburn 2357: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2358: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2359: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2360: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2361: }
2362: $color_menu .= '</tr></table><br />';
2363: return $color_menu;
2364: }
2365:
2366: sub image_changes {
2367: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2368: my $output;
1.135 bisitz 2369: if ($img eq 'login') {
1.331 raeburn 2370: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2371: } elsif (!$is_custom) {
1.70 raeburn 2372: if ($img ne 'domlogo') {
1.331 raeburn 2373: $output = &mt('Default image:').'<br />';
1.41 raeburn 2374: } else {
1.331 raeburn 2375: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2376: }
2377: }
1.331 raeburn 2378: if ($img ne 'login') {
1.135 bisitz 2379: if ($img_import) {
2380: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2381: }
2382: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2383: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2384: if ($is_custom) {
2385: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2386: '<input type="checkbox" name="'.
2387: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2388: '</label> '.&mt('Replace:').'</span><br />';
2389: } else {
1.306 raeburn 2390: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2391: }
1.41 raeburn 2392: }
2393: return $output;
2394: }
2395:
1.3 raeburn 2396: sub print_quotas {
1.86 raeburn 2397: my ($dom,$settings,$rowtotal,$action) = @_;
2398: my $context;
2399: if ($action eq 'quotas') {
2400: $context = 'tools';
2401: } else {
2402: $context = $action;
2403: }
1.429 raeburn 2404: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2405: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2406: my $typecount = 0;
1.101 raeburn 2407: my ($css_class,%titles);
1.86 raeburn 2408: if ($context eq 'requestcourses') {
1.325 raeburn 2409: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2410: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2411: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2412: %titles = &courserequest_titles();
1.163 raeburn 2413: } elsif ($context eq 'requestauthor') {
2414: @usertools = ('author');
2415: @options = ('norequest','approval','automatic');
1.210 raeburn 2416: %titles = &authorrequest_titles();
1.86 raeburn 2417: } else {
1.430 raeburn 2418: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 2419: %titles = &tool_titles();
1.86 raeburn 2420: }
1.26 raeburn 2421: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2422: foreach my $type (@{$types}) {
1.429 raeburn 2423: my $currdefquota;
1.163 raeburn 2424: unless (($context eq 'requestcourses') ||
2425: ($context eq 'requestauthor')) {
1.86 raeburn 2426: if (ref($settings) eq 'HASH') {
2427: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2428: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2429: } else {
2430: $currdefquota = $settings->{$type};
2431: }
1.78 raeburn 2432: }
1.72 raeburn 2433: }
1.3 raeburn 2434: if (defined($usertypes->{$type})) {
2435: $typecount ++;
2436: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2437: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2438: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2439: '<td class="LC_left_item">';
1.101 raeburn 2440: if ($context eq 'requestcourses') {
2441: $datatable .= '<table><tr>';
2442: }
2443: my %cell;
1.72 raeburn 2444: foreach my $item (@usertools) {
1.101 raeburn 2445: if ($context eq 'requestcourses') {
2446: my ($curroption,$currlimit);
2447: if (ref($settings) eq 'HASH') {
2448: if (ref($settings->{$item}) eq 'HASH') {
2449: $curroption = $settings->{$item}->{$type};
2450: if ($curroption =~ /^autolimit=(\d*)$/) {
2451: $currlimit = $1;
2452: }
2453: }
2454: }
2455: if (!$curroption) {
2456: $curroption = 'norequest';
2457: }
2458: $datatable .= '<th>'.$titles{$item}.'</th>';
2459: foreach my $option (@options) {
2460: my $val = $option;
2461: if ($option eq 'norequest') {
2462: $val = 0;
2463: }
2464: if ($option eq 'validate') {
2465: my $canvalidate = 0;
2466: if (ref($validations{$item}) eq 'HASH') {
2467: if ($validations{$item}{$type}) {
2468: $canvalidate = 1;
2469: }
2470: }
2471: next if (!$canvalidate);
2472: }
2473: my $checked = '';
2474: if ($option eq $curroption) {
2475: $checked = ' checked="checked"';
2476: } elsif ($option eq 'autolimit') {
2477: if ($curroption =~ /^autolimit/) {
2478: $checked = ' checked="checked"';
2479: }
2480: }
2481: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2482: '<input type="radio" name="crsreq_'.$item.
2483: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2484: $titles{$option}.'</label>';
1.101 raeburn 2485: if ($option eq 'autolimit') {
1.127 raeburn 2486: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2487: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2488: 'value="'.$currlimit.'" />';
1.101 raeburn 2489: }
1.127 raeburn 2490: $cell{$item} .= '</span> ';
1.103 raeburn 2491: if ($option eq 'autolimit') {
1.127 raeburn 2492: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2493: }
1.101 raeburn 2494: }
1.163 raeburn 2495: } elsif ($context eq 'requestauthor') {
2496: my $curroption;
2497: if (ref($settings) eq 'HASH') {
2498: $curroption = $settings->{$type};
2499: }
2500: if (!$curroption) {
2501: $curroption = 'norequest';
2502: }
2503: foreach my $option (@options) {
2504: my $val = $option;
2505: if ($option eq 'norequest') {
2506: $val = 0;
2507: }
2508: my $checked = '';
2509: if ($option eq $curroption) {
2510: $checked = ' checked="checked"';
2511: }
2512: $datatable .= '<span class="LC_nobreak"><label>'.
2513: '<input type="radio" name="authorreq_'.$type.
2514: '" value="'.$val.'"'.$checked.' />'.
2515: $titles{$option}.'</label></span> ';
2516: }
1.101 raeburn 2517: } else {
2518: my $checked = 'checked="checked" ';
1.413 raeburn 2519: if ($item eq 'timezone') {
2520: $checked = '';
2521: }
1.101 raeburn 2522: if (ref($settings) eq 'HASH') {
2523: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2524: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2525: $checked = '';
2526: } elsif ($settings->{$item}->{$type} == 1) {
2527: $checked = 'checked="checked" ';
2528: }
1.78 raeburn 2529: }
1.72 raeburn 2530: }
1.101 raeburn 2531: $datatable .= '<span class="LC_nobreak"><label>'.
2532: '<input type="checkbox" name="'.$context.'_'.$item.
2533: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2534: '</label></span> ';
1.72 raeburn 2535: }
1.101 raeburn 2536: }
2537: if ($context eq 'requestcourses') {
2538: $datatable .= '</tr><tr>';
2539: foreach my $item (@usertools) {
1.106 raeburn 2540: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2541: }
2542: $datatable .= '</tr></table>';
1.72 raeburn 2543: }
1.86 raeburn 2544: $datatable .= '</td>';
1.163 raeburn 2545: unless (($context eq 'requestcourses') ||
2546: ($context eq 'requestauthor')) {
1.86 raeburn 2547: $datatable .=
1.197 raeburn 2548: '<td class="LC_right_item">'.
1.429 raeburn 2549: '<span class="LC_nobreak">'.
1.3 raeburn 2550: '<input type="text" name="quota_'.$type.
1.72 raeburn 2551: '" value="'.$currdefquota.
1.197 raeburn 2552: '" size="5" /></span></td>';
1.86 raeburn 2553: }
2554: $datatable .= '</tr>';
1.3 raeburn 2555: }
2556: }
2557: }
1.163 raeburn 2558: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2559: $defaultquota = '20';
2560: if (ref($settings) eq 'HASH') {
2561: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2562: $defaultquota = $settings->{'defaultquota'}->{'default'};
2563: } elsif (defined($settings->{'default'})) {
2564: $defaultquota = $settings->{'default'};
2565: }
1.3 raeburn 2566: }
2567: }
2568: $typecount ++;
2569: $css_class = $typecount%2?' class="LC_odd_row"':'';
2570: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2571: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2572: '<td class="LC_left_item">';
1.101 raeburn 2573: if ($context eq 'requestcourses') {
2574: $datatable .= '<table><tr>';
2575: }
2576: my %defcell;
1.72 raeburn 2577: foreach my $item (@usertools) {
1.101 raeburn 2578: if ($context eq 'requestcourses') {
2579: my ($curroption,$currlimit);
2580: if (ref($settings) eq 'HASH') {
2581: if (ref($settings->{$item}) eq 'HASH') {
2582: $curroption = $settings->{$item}->{'default'};
2583: if ($curroption =~ /^autolimit=(\d*)$/) {
2584: $currlimit = $1;
2585: }
2586: }
2587: }
2588: if (!$curroption) {
2589: $curroption = 'norequest';
2590: }
2591: $datatable .= '<th>'.$titles{$item}.'</th>';
2592: foreach my $option (@options) {
2593: my $val = $option;
2594: if ($option eq 'norequest') {
2595: $val = 0;
2596: }
2597: if ($option eq 'validate') {
2598: my $canvalidate = 0;
2599: if (ref($validations{$item}) eq 'HASH') {
2600: if ($validations{$item}{'default'}) {
2601: $canvalidate = 1;
2602: }
2603: }
2604: next if (!$canvalidate);
2605: }
2606: my $checked = '';
2607: if ($option eq $curroption) {
2608: $checked = ' checked="checked"';
2609: } elsif ($option eq 'autolimit') {
2610: if ($curroption =~ /^autolimit/) {
2611: $checked = ' checked="checked"';
2612: }
2613: }
2614: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2615: '<input type="radio" name="crsreq_'.$item.
2616: '_default" value="'.$val.'"'.$checked.' />'.
2617: $titles{$option}.'</label>';
2618: if ($option eq 'autolimit') {
1.127 raeburn 2619: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2620: $item.'_limit_default" size="1" '.
2621: 'value="'.$currlimit.'" />';
2622: }
1.127 raeburn 2623: $defcell{$item} .= '</span> ';
1.104 raeburn 2624: if ($option eq 'autolimit') {
1.127 raeburn 2625: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2626: }
1.101 raeburn 2627: }
1.163 raeburn 2628: } elsif ($context eq 'requestauthor') {
2629: my $curroption;
2630: if (ref($settings) eq 'HASH') {
1.172 raeburn 2631: $curroption = $settings->{'default'};
1.163 raeburn 2632: }
2633: if (!$curroption) {
2634: $curroption = 'norequest';
2635: }
2636: foreach my $option (@options) {
2637: my $val = $option;
2638: if ($option eq 'norequest') {
2639: $val = 0;
2640: }
2641: my $checked = '';
2642: if ($option eq $curroption) {
2643: $checked = ' checked="checked"';
2644: }
2645: $datatable .= '<span class="LC_nobreak"><label>'.
2646: '<input type="radio" name="authorreq_default"'.
2647: ' value="'.$val.'"'.$checked.' />'.
2648: $titles{$option}.'</label></span> ';
2649: }
1.101 raeburn 2650: } else {
2651: my $checked = 'checked="checked" ';
2652: if (ref($settings) eq 'HASH') {
2653: if (ref($settings->{$item}) eq 'HASH') {
2654: if ($settings->{$item}->{'default'} == 0) {
2655: $checked = '';
2656: } elsif ($settings->{$item}->{'default'} == 1) {
2657: $checked = 'checked="checked" ';
2658: }
1.78 raeburn 2659: }
1.72 raeburn 2660: }
1.101 raeburn 2661: $datatable .= '<span class="LC_nobreak"><label>'.
2662: '<input type="checkbox" name="'.$context.'_'.$item.
2663: '" value="default" '.$checked.'/>'.$titles{$item}.
2664: '</label></span> ';
2665: }
2666: }
2667: if ($context eq 'requestcourses') {
2668: $datatable .= '</tr><tr>';
2669: foreach my $item (@usertools) {
1.106 raeburn 2670: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2671: }
1.101 raeburn 2672: $datatable .= '</tr></table>';
1.72 raeburn 2673: }
1.86 raeburn 2674: $datatable .= '</td>';
1.163 raeburn 2675: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2676: $datatable .= '<td class="LC_right_item">'.
1.429 raeburn 2677: '<span class="LC_nobreak">'.
1.86 raeburn 2678: '<input type="text" name="defaultquota" value="'.
1.429 raeburn 2679: $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2680: }
2681: $datatable .= '</tr>';
1.72 raeburn 2682: $typecount ++;
2683: $css_class = $typecount%2?' class="LC_odd_row"':'';
2684: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2685: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2686: if ($context eq 'requestcourses') {
1.109 raeburn 2687: $datatable .= &mt('(overrides affiliation, if set)').
2688: '</td>'.
2689: '<td class="LC_left_item">'.
2690: '<table><tr>';
1.101 raeburn 2691: } else {
1.109 raeburn 2692: $datatable .= &mt('(overrides affiliation, if checked)').
2693: '</td>'.
2694: '<td class="LC_left_item" colspan="2">'.
2695: '<br />';
1.101 raeburn 2696: }
2697: my %advcell;
1.72 raeburn 2698: foreach my $item (@usertools) {
1.101 raeburn 2699: if ($context eq 'requestcourses') {
2700: my ($curroption,$currlimit);
2701: if (ref($settings) eq 'HASH') {
2702: if (ref($settings->{$item}) eq 'HASH') {
2703: $curroption = $settings->{$item}->{'_LC_adv'};
2704: if ($curroption =~ /^autolimit=(\d*)$/) {
2705: $currlimit = $1;
2706: }
2707: }
2708: }
2709: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2710: my $checked = '';
2711: if ($curroption eq '') {
2712: $checked = ' checked="checked"';
2713: }
2714: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2715: '<input type="radio" name="crsreq_'.$item.
2716: '__LC_adv" value=""'.$checked.' />'.
2717: &mt('No override set').'</label></span> ';
1.101 raeburn 2718: foreach my $option (@options) {
2719: my $val = $option;
2720: if ($option eq 'norequest') {
2721: $val = 0;
2722: }
2723: if ($option eq 'validate') {
2724: my $canvalidate = 0;
2725: if (ref($validations{$item}) eq 'HASH') {
2726: if ($validations{$item}{'_LC_adv'}) {
2727: $canvalidate = 1;
2728: }
2729: }
2730: next if (!$canvalidate);
2731: }
2732: my $checked = '';
1.104 raeburn 2733: if ($val eq $curroption) {
1.101 raeburn 2734: $checked = ' checked="checked"';
2735: } elsif ($option eq 'autolimit') {
2736: if ($curroption =~ /^autolimit/) {
2737: $checked = ' checked="checked"';
2738: }
2739: }
2740: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2741: '<input type="radio" name="crsreq_'.$item.
2742: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2743: $titles{$option}.'</label>';
2744: if ($option eq 'autolimit') {
1.127 raeburn 2745: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2746: $item.'_limit__LC_adv" size="1" '.
2747: 'value="'.$currlimit.'" />';
2748: }
1.127 raeburn 2749: $advcell{$item} .= '</span> ';
1.104 raeburn 2750: if ($option eq 'autolimit') {
1.127 raeburn 2751: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2752: }
1.101 raeburn 2753: }
1.163 raeburn 2754: } elsif ($context eq 'requestauthor') {
2755: my $curroption;
2756: if (ref($settings) eq 'HASH') {
2757: $curroption = $settings->{'_LC_adv'};
2758: }
2759: my $checked = '';
2760: if ($curroption eq '') {
2761: $checked = ' checked="checked"';
2762: }
2763: $datatable .= '<span class="LC_nobreak"><label>'.
2764: '<input type="radio" name="authorreq__LC_adv"'.
2765: ' value=""'.$checked.' />'.
2766: &mt('No override set').'</label></span> ';
2767: foreach my $option (@options) {
2768: my $val = $option;
2769: if ($option eq 'norequest') {
2770: $val = 0;
2771: }
2772: my $checked = '';
2773: if ($val eq $curroption) {
2774: $checked = ' checked="checked"';
2775: }
2776: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2777: '<input type="radio" name="authorreq__LC_adv"'.
2778: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2779: $titles{$option}.'</label></span> ';
2780: }
1.101 raeburn 2781: } else {
2782: my $checked = 'checked="checked" ';
2783: if (ref($settings) eq 'HASH') {
2784: if (ref($settings->{$item}) eq 'HASH') {
2785: if ($settings->{$item}->{'_LC_adv'} == 0) {
2786: $checked = '';
2787: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2788: $checked = 'checked="checked" ';
2789: }
1.79 raeburn 2790: }
1.72 raeburn 2791: }
1.101 raeburn 2792: $datatable .= '<span class="LC_nobreak"><label>'.
2793: '<input type="checkbox" name="'.$context.'_'.$item.
2794: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2795: '</label></span> ';
2796: }
2797: }
2798: if ($context eq 'requestcourses') {
2799: $datatable .= '</tr><tr>';
2800: foreach my $item (@usertools) {
1.106 raeburn 2801: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2802: }
1.101 raeburn 2803: $datatable .= '</tr></table>';
1.72 raeburn 2804: }
1.98 raeburn 2805: $datatable .= '</td></tr>';
1.30 raeburn 2806: $$rowtotal += $typecount;
1.3 raeburn 2807: return $datatable;
2808: }
2809:
1.163 raeburn 2810: sub print_requestmail {
1.305 raeburn 2811: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2812: my ($now,$datatable,%currapp);
1.102 raeburn 2813: $now = time;
2814: if (ref($settings) eq 'HASH') {
2815: if (ref($settings->{'notify'}) eq 'HASH') {
2816: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2817: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2818: }
2819: }
2820: }
1.191 raeburn 2821: my $numinrow = 2;
1.224 raeburn 2822: my $css_class;
1.305 raeburn 2823: if ($$rowtotal%2) {
2824: $css_class = 'LC_odd_row';
2825: }
2826: if ($customcss) {
2827: $css_class .= " $customcss";
2828: }
2829: $css_class =~ s/^\s+//;
2830: if ($css_class) {
2831: $css_class = ' class="'.$css_class.'"';
2832: }
2833: if ($rowstyle) {
2834: $css_class .= ' style="'.$rowstyle.'"';
2835: }
1.163 raeburn 2836: my $text;
2837: if ($action eq 'requestcourses') {
2838: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2839: } elsif ($action eq 'requestauthor') {
2840: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2841: } else {
1.224 raeburn 2842: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2843: }
1.224 raeburn 2844: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2845: ' <td>'.$text.'</td>'.
1.102 raeburn 2846: ' <td class="LC_left_item">';
1.191 raeburn 2847: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2848: $action.'notifyapproval',%currapp);
1.191 raeburn 2849: if ($numdc > 0) {
2850: $datatable .= $table;
1.102 raeburn 2851: } else {
2852: $datatable .= &mt('There are no active Domain Coordinators');
2853: }
2854: $datatable .='</td></tr>';
2855: return $datatable;
2856: }
2857:
1.216 raeburn 2858: sub print_studentcode {
2859: my ($settings,$rowtotal) = @_;
2860: my $rownum = 0;
1.218 raeburn 2861: my ($output,%current);
1.325 raeburn 2862: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2863: if (ref($settings) eq 'HASH') {
2864: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2865: foreach my $type (@crstypes) {
2866: $current{$type} = $settings->{'uniquecode'}{$type};
2867: }
1.218 raeburn 2868: }
2869: }
2870: $output .= '<tr>'.
2871: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2872: '<td class="LC_left_item">';
2873: foreach my $type (@crstypes) {
2874: my $check = ' ';
2875: if ($current{$type}) {
2876: $check = ' checked="checked" ';
2877: }
2878: $output .= '<span class="LC_nobreak"><label>'.
2879: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2880: &mt($type).'</label></span>'.(' 'x2).' ';
2881: }
2882: $output .= '</td></tr>';
2883: $$rowtotal ++;
2884: return $output;
1.216 raeburn 2885: }
2886:
2887: sub print_textbookcourses {
1.242 raeburn 2888: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2889: my $rownum = 0;
2890: my $css_class;
2891: my $itemcount = 1;
2892: my $maxnum = 0;
2893: my $bookshash;
2894: if (ref($settings) eq 'HASH') {
1.242 raeburn 2895: $bookshash = $settings->{$type};
1.216 raeburn 2896: }
2897: my %ordered;
2898: if (ref($bookshash) eq 'HASH') {
2899: foreach my $item (keys(%{$bookshash})) {
2900: if (ref($bookshash->{$item}) eq 'HASH') {
2901: my $num = $bookshash->{$item}{'order'};
2902: $ordered{$num} = $item;
2903: }
2904: }
2905: }
2906: my $confname = $dom.'-domainconfig';
2907: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2908: my $maxnum = scalar(keys(%ordered));
2909: my $datatable;
1.216 raeburn 2910: if (keys(%ordered)) {
2911: my @items = sort { $a <=> $b } keys(%ordered);
2912: for (my $i=0; $i<@items; $i++) {
2913: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2914: my $key = $ordered{$items[$i]};
2915: my %coursehash=&Apache::lonnet::coursedescription($key);
2916: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2917: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2918: if (ref($bookshash->{$key}) eq 'HASH') {
2919: $subject = $bookshash->{$key}->{'subject'};
2920: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2921: if ($type eq 'textbooks') {
1.243 raeburn 2922: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2923: $author = $bookshash->{$key}->{'author'};
2924: $image = $bookshash->{$key}->{'image'};
2925: if ($image ne '') {
2926: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2927: my $imagethumb = "$path/tn-".$imagefile;
2928: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2929: }
1.216 raeburn 2930: }
2931: }
1.242 raeburn 2932: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2933: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2934: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2935: for (my $k=0; $k<=$maxnum; $k++) {
2936: my $vpos = $k+1;
2937: my $selstr;
2938: if ($k == $i) {
2939: $selstr = ' selected="selected" ';
2940: }
2941: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2942: }
2943: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2944: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2945: &mt('Delete?').'</label></span></td>'.
2946: '<td colspan="2">'.
1.242 raeburn 2947: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2948: (' 'x2).
1.242 raeburn 2949: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2950: if ($type eq 'textbooks') {
2951: $datatable .= (' 'x2).
1.243 raeburn 2952: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2953: (' 'x2).
1.242 raeburn 2954: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2955: (' 'x2).
2956: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2957: if ($image) {
1.267 raeburn 2958: $datatable .= $imgsrc.
1.242 raeburn 2959: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2960: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2961: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2962: }
2963: if ($switchserver) {
2964: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2965: } else {
2966: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2967: }
1.216 raeburn 2968: }
1.242 raeburn 2969: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2970: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2971: $coursetitle.'</span></td></tr>'."\n";
2972: $itemcount ++;
2973: }
2974: }
2975: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2976: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2977: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2978: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2979: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2980: for (my $k=0; $k<$maxnum+1; $k++) {
2981: my $vpos = $k+1;
2982: my $selstr;
2983: if ($k == $maxnum) {
2984: $selstr = ' selected="selected" ';
2985: }
2986: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2987: }
2988: $datatable .= '</select> '."\n".
1.334 raeburn 2989: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2990: '<td colspan="2">'.
1.242 raeburn 2991: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2992: (' 'x2).
1.242 raeburn 2993: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2994: (' 'x2);
2995: if ($type eq 'textbooks') {
1.243 raeburn 2996: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2997: (' 'x2).
2998: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2999: (' 'x2).
3000: '<span class="LC_nobreak">'.&mt('Image:').' ';
3001: if ($switchserver) {
3002: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3003: } else {
3004: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
3005: }
1.334 raeburn 3006: $datatable .= '</span>'."\n";
1.216 raeburn 3007: }
1.334 raeburn 3008: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 3009: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
3010: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 3011: &Apache::loncommon::selectcourse_link
1.334 raeburn 3012: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 3013: '</span></td>'."\n".
3014: '</tr>'."\n";
3015: $itemcount ++;
3016: return $datatable;
3017: }
3018:
1.217 raeburn 3019: sub textbookcourses_javascript {
1.242 raeburn 3020: my ($settings) = @_;
3021: return unless(ref($settings) eq 'HASH');
3022: my (%ordered,%total,%jstext);
3023: foreach my $type ('textbooks','templates') {
3024: $total{$type} = 0;
3025: if (ref($settings->{$type}) eq 'HASH') {
3026: foreach my $item (keys(%{$settings->{$type}})) {
3027: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3028: my $num = $settings->{$type}->{$item}{'order'};
3029: $ordered{$type}{$num} = $item;
3030: }
3031: }
3032: $total{$type} = scalar(keys(%{$settings->{$type}}));
3033: }
3034: my @jsarray = ();
3035: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3036: push(@jsarray,$ordered{$type}{$item});
3037: }
3038: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3039: }
3040: return <<"ENDSCRIPT";
3041: <script type="text/javascript">
3042: // <![CDATA[
1.242 raeburn 3043: function reorderBooks(form,item,caller) {
1.217 raeburn 3044: var changedVal;
1.242 raeburn 3045: $jstext{'textbooks'};
3046: $jstext{'templates'};
3047: var newpos;
3048: var maxh;
3049: if (caller == 'textbooks') {
3050: newpos = 'textbooks_addbook_pos';
3051: maxh = 1 + $total{'textbooks'};
3052: } else {
3053: newpos = 'templates_addbook_pos';
3054: maxh = 1 + $total{'templates'};
3055: }
1.217 raeburn 3056: var current = new Array;
3057: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3058: if (item == newpos) {
3059: changedVal = newitemVal;
3060: } else {
3061: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3062: current[newitemVal] = newpos;
3063: }
1.242 raeburn 3064: if (caller == 'textbooks') {
3065: for (var i=0; i<textbooks.length; i++) {
3066: var elementName = 'textbooks_'+textbooks[i];
3067: if (elementName != item) {
3068: if (form.elements[elementName]) {
3069: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3070: current[currVal] = elementName;
3071: }
3072: }
3073: }
3074: }
3075: if (caller == 'templates') {
3076: for (var i=0; i<templates.length; i++) {
3077: var elementName = 'templates_'+templates[i];
3078: if (elementName != item) {
3079: if (form.elements[elementName]) {
3080: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3081: current[currVal] = elementName;
3082: }
1.217 raeburn 3083: }
3084: }
3085: }
3086: var oldVal;
3087: for (var j=0; j<maxh; j++) {
3088: if (current[j] == undefined) {
3089: oldVal = j;
3090: }
3091: }
3092: if (oldVal < changedVal) {
3093: for (var k=oldVal+1; k<=changedVal ; k++) {
3094: var elementName = current[k];
3095: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3096: }
3097: } else {
3098: for (var k=changedVal; k<oldVal; k++) {
3099: var elementName = current[k];
3100: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3101: }
3102: }
3103: return;
3104: }
3105:
3106: // ]]>
3107: </script>
3108:
3109: ENDSCRIPT
3110: }
3111:
1.267 raeburn 3112: sub ltitools_javascript {
3113: my ($settings) = @_;
1.319 raeburn 3114: my $togglejs = <itools_toggle_js();
3115: unless (ref($settings) eq 'HASH') {
3116: return $togglejs;
3117: }
1.267 raeburn 3118: my (%ordered,$total,%jstext);
3119: $total = 0;
3120: foreach my $item (keys(%{$settings})) {
3121: if (ref($settings->{$item}) eq 'HASH') {
3122: my $num = $settings->{$item}{'order'};
3123: $ordered{$num} = $item;
3124: }
3125: }
3126: $total = scalar(keys(%{$settings}));
3127: my @jsarray = ();
3128: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3129: push(@jsarray,$ordered{$item});
3130: }
3131: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3132: return <<"ENDSCRIPT";
3133: <script type="text/javascript">
3134: // <![CDATA[
1.319 raeburn 3135: function reorderLTITools(form,item) {
1.267 raeburn 3136: var changedVal;
3137: $jstext
3138: var newpos = 'ltitools_add_pos';
3139: var maxh = 1 + $total;
3140: var current = new Array;
3141: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3142: if (item == newpos) {
3143: changedVal = newitemVal;
3144: } else {
3145: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3146: current[newitemVal] = newpos;
3147: }
3148: for (var i=0; i<ltitools.length; i++) {
3149: var elementName = 'ltitools_'+ltitools[i];
3150: if (elementName != item) {
3151: if (form.elements[elementName]) {
3152: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3153: current[currVal] = elementName;
3154: }
3155: }
3156: }
3157: var oldVal;
3158: for (var j=0; j<maxh; j++) {
3159: if (current[j] == undefined) {
3160: oldVal = j;
3161: }
3162: }
3163: if (oldVal < changedVal) {
3164: for (var k=oldVal+1; k<=changedVal ; k++) {
3165: var elementName = current[k];
3166: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3167: }
3168: } else {
3169: for (var k=changedVal; k<oldVal; k++) {
3170: var elementName = current[k];
3171: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3172: }
3173: }
3174: return;
3175: }
3176:
3177: // ]]>
3178: </script>
3179:
1.319 raeburn 3180: $togglejs
3181:
3182: ENDSCRIPT
3183: }
3184:
3185: sub ltitools_toggle_js {
3186: return <<"ENDSCRIPT";
3187: <script type="text/javascript">
3188: // <![CDATA[
3189:
3190: function toggleLTITools(form,setting,item) {
3191: var radioname = '';
3192: var divid = '';
3193: if ((setting == 'passback') || (setting == 'roster')) {
3194: radioname = 'ltitools_'+setting+'_'+item;
3195: divid = 'ltitools_'+setting+'time_'+item;
3196: var num = form.elements[radioname].length;
3197: if (num) {
3198: var setvis = '';
3199: for (var i=0; i<num; i++) {
3200: if (form.elements[radioname][i].checked) {
3201: if (form.elements[radioname][i].value == '1') {
3202: if (document.getElementById(divid)) {
3203: document.getElementById(divid).style.display = 'inline-block';
3204: }
3205: setvis = 1;
3206: }
3207: break;
3208: }
3209: }
3210: }
3211: if (!setvis) {
3212: if (document.getElementById(divid)) {
3213: document.getElementById(divid).style.display = 'none';
3214: }
3215: }
3216: }
1.324 raeburn 3217: if (setting == 'user') {
3218: divid = 'ltitools_'+setting+'_div_'+item;
3219: var checkid = 'ltitools_'+setting+'_field_'+item;
3220: if (document.getElementById(divid)) {
3221: if (document.getElementById(checkid)) {
3222: if (document.getElementById(checkid).checked) {
3223: document.getElementById(divid).style.display = 'inline-block';
3224: } else {
3225: document.getElementById(divid).style.display = 'none';
3226: }
3227: }
3228: }
3229: }
1.319 raeburn 3230: return;
3231: }
3232: // ]]>
3233: </script>
3234:
1.267 raeburn 3235: ENDSCRIPT
3236: }
3237:
1.381 raeburn 3238: sub wafproxy_javascript {
3239: my ($dom) = @_;
3240: return <<"ENDSCRIPT";
3241: <script type="text/javascript">
3242: // <![CDATA[
3243: function updateWAF() {
3244: if (document.getElementById('wafproxy_remoteip')) {
3245: var wafremote = 0;
3246: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3247: wafremote = 1;
3248: }
3249: var fields = new Array('header','trust');
3250: for (var i=0; i<fields.length; i++) {
3251: if (document.getElementById('wafproxy_'+fields[i])) {
3252: if (wafremote == 1) {
3253: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3254: }
3255: else {
3256: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3257: }
3258: }
3259: }
3260: if (document.getElementById('wafproxyranges_$dom')) {
3261: if (wafremote == 1) {
3262: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3263: } else {
3264: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3265: if (document.display.wafproxy_vpnaccess[i].checked) {
3266: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3267: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3268: }
3269: }
3270: }
3271: }
3272: }
3273: }
3274: return;
3275: }
3276:
3277: function checkWAF() {
3278: if (document.getElementById('wafproxy_remoteip')) {
3279: var wafvpn = 0;
3280: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3281: if (document.display.wafproxy_vpnaccess[i].checked) {
3282: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3283: wafvpn = 1;
3284: }
3285: break;
3286: }
3287: }
3288: var vpn = new Array('vpnint','vpnext');
3289: for (var i=0; i<vpn.length; i++) {
3290: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3291: if (wafvpn == 1) {
3292: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3293: }
3294: else {
3295: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3296: }
3297: }
3298: }
3299: if (document.getElementById('wafproxyranges_$dom')) {
3300: if (wafvpn == 1) {
3301: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3302: }
3303: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3304: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3305: }
3306: }
3307: }
3308: return;
3309: }
3310:
3311: function toggleWAF() {
3312: if (document.getElementById('wafproxy_table')) {
3313: var wafproxy = 0;
3314: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3315: if (document.display.wafproxy_${dom}[i].checked) {
3316: if (document.display.wafproxy_${dom}[i].value == 1) {
3317: wafproxy = 1;
3318: break;
3319: }
3320: }
3321: }
3322: if (wafproxy == 1) {
3323: document.getElementById('wafproxy_table').style.display='inline';
3324: }
3325: else {
3326: document.getElementById('wafproxy_table').style.display='none';
3327: }
3328: if (document.getElementById('wafproxyrow_${dom}')) {
3329: if (wafproxy == 1) {
3330: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3331: }
3332: else {
3333: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3334: }
3335: }
3336: if (document.getElementById('nowafproxyrow_$dom')) {
3337: if (wafproxy == 1) {
3338: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3339: }
3340: else {
3341: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3342: }
3343: }
3344: }
3345: return;
3346: }
3347: // ]]>
3348: </script>
3349:
3350: ENDSCRIPT
3351: }
3352:
1.372 raeburn 3353: sub proctoring_javascript {
3354: my ($settings) = @_;
3355: my (%ordered,$total,%jstext);
3356: $total = 0;
3357: if (ref($settings) eq 'HASH') {
3358: foreach my $item (keys(%{$settings})) {
3359: if (ref($settings->{$item}) eq 'HASH') {
3360: my $num = $settings->{$item}{'order'};
3361: $ordered{$num} = $item;
3362: }
3363: }
3364: $total = scalar(keys(%{$settings}));
3365: } else {
3366: %ordered = (
3367: 0 => 'proctorio',
3368: 1 => 'examity',
3369: );
3370: $total = 2;
3371: }
3372: my @jsarray = ();
3373: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3374: push(@jsarray,$ordered{$item});
3375: }
3376: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3377: return <<"ENDSCRIPT";
3378: <script type="text/javascript">
3379: // <![CDATA[
3380: function reorderProctoring(form,item) {
3381: var changedVal;
3382: $jstext
3383: var maxh = $total;
3384: var current = new Array;
3385: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3386: for (var i=0; i<proctors.length; i++) {
3387: var elementName = 'proctoring_pos_'+proctors[i];
3388: if (elementName != item) {
3389: if (form.elements[elementName]) {
3390: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3391: current[currVal] = elementName;
3392: }
3393: }
3394: }
3395: var oldVal;
3396: for (var j=0; j<maxh; j++) {
3397: if (current[j] == undefined) {
3398: oldVal = j;
3399: }
3400: }
3401: if (oldVal < changedVal) {
3402: for (var k=oldVal+1; k<=changedVal ; k++) {
3403: var elementName = current[k];
3404: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3405: }
3406: } else {
3407: for (var k=changedVal; k<oldVal; k++) {
3408: var elementName = current[k];
3409: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3410: }
3411: }
3412: return;
3413: }
3414:
3415: function toggleProctoring(form,item) {
3416: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3417: if (fieldsets.length) {
3418: var radioname = 'proctoring_available_'+item;
3419: var num = form.elements[radioname].length;
3420: if (num) {
3421: var setvis = '';
3422: for (var i=0; i<num; i++) {
3423: if (form.elements[radioname][i].checked) {
3424: if (form.elements[radioname][i].value == '1') {
3425: setvis = 1;
3426: break;
3427: }
3428: }
3429: }
3430: for (var j=0; j<fieldsets.length; j++) {
3431: if (setvis) {
3432: fieldsets[j].style.display = 'block';
3433: } else {
3434: fieldsets[j].style.display = 'none';
3435: }
3436: }
3437: }
3438: }
3439: return;
3440: }
3441:
3442: // ]]>
3443: </script>
3444:
3445: ENDSCRIPT
3446: }
3447:
3448:
1.320 raeburn 3449: sub lti_javascript {
1.405 raeburn 3450: my ($dom,$settings) = @_;
3451: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3452: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3453: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3454: return $togglejs.'
3455: <script type="text/javascript">
3456: // <![CDATA[
3457:
3458: '.$linkprot_js.'
3459:
3460: // ]]>
3461: </script>
3462: ';
1.320 raeburn 3463: }
3464: my (%ordered,$total,%jstext);
1.390 raeburn 3465: $total = scalar(keys(%{$settings}));
1.320 raeburn 3466: foreach my $item (keys(%{$settings})) {
3467: if (ref($settings->{$item}) eq 'HASH') {
3468: my $num = $settings->{$item}{'order'};
1.390 raeburn 3469: if ($num eq '') {
3470: $num = $total - 1;
3471: }
1.320 raeburn 3472: $ordered{$num} = $item;
3473: }
3474: }
3475: my @jsarray = ();
3476: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3477: push(@jsarray,$ordered{$item});
3478: }
3479: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3480: return <<"ENDSCRIPT";
3481: <script type="text/javascript">
3482: // <![CDATA[
3483: function reorderLTI(form,item) {
3484: var changedVal;
3485: $jstext
3486: var newpos = 'lti_pos_add';
3487: var maxh = 1 + $total;
3488: var current = new Array;
3489: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3490: if (item == newpos) {
3491: changedVal = newitemVal;
3492: } else {
3493: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3494: current[newitemVal] = newpos;
3495: }
3496: for (var i=0; i<lti.length; i++) {
3497: var elementName = 'lti_pos_'+lti[i];
3498: if (elementName != item) {
3499: if (form.elements[elementName]) {
3500: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3501: current[currVal] = elementName;
3502: }
3503: }
3504: }
3505: var oldVal;
3506: for (var j=0; j<maxh; j++) {
3507: if (current[j] == undefined) {
3508: oldVal = j;
3509: }
3510: }
3511: if (oldVal < changedVal) {
3512: for (var k=oldVal+1; k<=changedVal ; k++) {
3513: var elementName = current[k];
3514: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3515: }
3516: } else {
3517: for (var k=changedVal; k<oldVal; k++) {
3518: var elementName = current[k];
3519: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3520: }
3521: }
3522: return;
3523: }
1.406 raeburn 3524:
3525: $linkprot_js
3526:
1.320 raeburn 3527: // ]]>
3528: </script>
3529:
3530: $togglejs
3531:
3532: ENDSCRIPT
3533: }
3534:
3535: sub lti_toggle_js {
1.405 raeburn 3536: my ($dom) = @_;
1.325 raeburn 3537: my %lcauthparmtext = &Apache::lonlocal::texthash (
3538: localauth => 'Local auth argument',
3539: krb => 'Kerberos domain',
3540: );
1.391 raeburn 3541: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3542: &js_escape(\$crsincalert);
1.405 raeburn 3543: my %servers = &Apache::lonnet::get_servers($dom,'library');
3544: my $primary = &Apache::lonnet::domain($dom,'primary');
3545: my $course_servers = "'".join("','",keys(%servers))."'";
1.320 raeburn 3546: return <<"ENDSCRIPT";
3547: <script type="text/javascript">
3548: // <![CDATA[
3549:
3550: function toggleLTI(form,setting,item) {
1.391 raeburn 3551: if ((setting == 'requser') || (setting == 'crsinc')) {
3552: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3553: var setvis = '';
3554: var radioname = 'lti_requser_'+item;
3555: var num = form.elements[radioname].length;
3556: if (num) {
3557: for (var i=0; i<num; i++) {
3558: if (form.elements[radioname][i].checked) {
3559: if (form.elements[radioname][i].value == '1') {
3560: setvis = 1;
3561: break;
3562: }
3563: }
3564: }
3565: }
3566: if (usrfieldsets.length) {
3567: for (var j=0; j<usrfieldsets.length; j++) {
3568: if (setvis) {
3569: usrfieldsets[j].style.display = 'block';
3570: } else {
3571: usrfieldsets[j].style.display = 'none';
3572: }
3573: }
3574: }
3575: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3576: if (crsfieldsets.length) {
3577: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3578: var num = form.elements[radioname].length;
3579: if (num) {
1.391 raeburn 3580: var crsvis = '';
1.345 raeburn 3581: for (var i=0; i<num; i++) {
3582: if (form.elements[radioname][i].checked) {
3583: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3584: if (setvis == '') {
3585: if (setting == 'crsinc'){
3586: alert("$crsincalert");
3587: form.elements[radioname][0].checked = true;
3588: }
3589: } else {
3590: crsvis = 1;
3591: }
3592: break;
1.345 raeburn 3593: }
3594: }
3595: }
1.391 raeburn 3596: setvis = crsvis;
3597: }
3598: for (var j=0; j<crsfieldsets.length; j++) {
3599: if (setvis) {
3600: crsfieldsets[j].style.display = 'block';
3601: } else {
3602: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3603: }
3604: }
3605: }
1.363 raeburn 3606: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3607: var radioname = '';
3608: var divid = '';
3609: if (setting == 'user') {
3610: radioname = 'lti_mapuser_'+item;
3611: divid = 'lti_userfield_'+item;
1.343 raeburn 3612: } else if (setting == 'crs') {
1.320 raeburn 3613: radioname = 'lti_mapcrs_'+item;
3614: divid = 'lti_crsfield_'+item;
1.363 raeburn 3615: } else if (setting == 'callback') {
3616: radioname = 'lti_callback_'+item;
3617: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3618: } else {
1.351 raeburn 3619: radioname = 'lti_passback_'+item;
1.337 raeburn 3620: divid = 'lti_passback_'+item;
1.320 raeburn 3621: }
3622: var num = form.elements[radioname].length;
3623: if (num) {
3624: var setvis = '';
3625: for (var i=0; i<num; i++) {
3626: if (form.elements[radioname][i].checked) {
1.363 raeburn 3627: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3628: if (form.elements[radioname][i].value == '1') {
3629: if (document.getElementById(divid)) {
3630: document.getElementById(divid).style.display = 'inline-block';
3631: }
3632: setvis = 1;
3633: break;
3634: }
3635: } else {
3636: if (form.elements[radioname][i].value == 'other') {
3637: if (document.getElementById(divid)) {
3638: document.getElementById(divid).style.display = 'inline-block';
3639: }
3640: setvis = 1;
3641: break;
1.320 raeburn 3642: }
3643: }
1.425 raeburn 3644: }
1.320 raeburn 3645: }
3646: if (!setvis) {
3647: if (document.getElementById(divid)) {
3648: document.getElementById(divid).style.display = 'none';
3649: }
3650: }
3651: }
3652: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3653: var numsec = form.elements['lti_crssec_'+item].length;
3654: if (numsec) {
3655: var setvis = '';
3656: for (var i=0; i<numsec; i++) {
3657: if (form.elements['lti_crssec_'+item][i].checked) {
3658: if (form.elements['lti_crssec_'+item][i].value == '1') {
3659: if (document.getElementById('lti_crssecfield_'+item)) {
3660: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3661: setvis = 1;
3662: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3663: if (numsrcsec) {
3664: var setsrcvis = '';
3665: for (var j=0; j<numsrcsec; j++) {
3666: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3667: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3668: if (document.getElementById('lti_secsrcfield_'+item)) {
3669: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3670: setsrcvis = 1;
3671: }
3672: }
3673: }
3674: }
3675: if (!setsrcvis) {
3676: if (document.getElementById('lti_secsrcfield_'+item)) {
3677: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3678: }
3679: }
3680: }
3681: }
3682: }
3683: }
3684: }
3685: if (!setvis) {
3686: if (document.getElementById('lti_crssecfield_'+item)) {
3687: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3688: }
3689: if (document.getElementById('lti_secsrcfield_'+item)) {
3690: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3691: }
3692: }
3693: }
1.325 raeburn 3694: } else if (setting == 'lcauth') {
3695: var numauth = form.elements['lti_lcauth_'+item].length;
3696: if (numauth) {
3697: for (var i=0; i<numauth; i++) {
3698: if (form.elements['lti_lcauth_'+item][i].checked) {
3699: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3700: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3701: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3702: } else {
3703: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3704: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3705: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3706: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3707: } else {
3708: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3709: }
3710: }
3711: }
3712: }
3713: }
3714: }
3715: }
1.326 raeburn 3716: } else if (setting == 'lcmenu') {
3717: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3718: var divid = 'lti_menufield_'+item;
3719: var setvis = '';
3720: for (var i=0; i<menus.length; i++) {
1.425 raeburn 3721: var radioname = menus[i];
1.326 raeburn 3722: var num = form.elements[radioname].length;
3723: if (num) {
3724: for (var j=0; j<num; j++) {
3725: if (form.elements[radioname][j].checked) {
3726: if (form.elements[radioname][j].value == '1') {
3727: if (document.getElementById(divid)) {
3728: document.getElementById(divid).style.display = 'inline-block';
3729: }
3730: setvis = 1;
3731: break;
3732: }
3733: }
3734: }
3735: }
3736: if (setvis == 1) {
3737: break;
3738: }
3739: }
3740: if (!setvis) {
3741: if (document.getElementById(divid)) {
3742: document.getElementById(divid).style.display = 'none';
3743: }
3744: }
1.320 raeburn 3745: }
3746: return;
3747: }
1.405 raeburn 3748:
1.320 raeburn 3749: // ]]>
3750: </script>
3751:
3752: ENDSCRIPT
3753: }
3754:
1.385 raeburn 3755: sub autoupdate_javascript {
3756: return <<"ENDSCRIPT";
3757: <script type="text/javascript">
3758: // <![CDATA[
3759: function toggleLastActiveDays(form) {
3760: var radioname = 'lastactive';
3761: var divid = 'lastactive_div';
3762: var num = form.elements[radioname].length;
3763: if (num) {
3764: var setvis = '';
3765: for (var i=0; i<num; i++) {
3766: if (form.elements[radioname][i].checked) {
3767: if (form.elements[radioname][i].value == '1') {
3768: if (document.getElementById(divid)) {
3769: document.getElementById(divid).style.display = 'inline-block';
3770: }
3771: setvis = 1;
3772: }
3773: break;
3774: }
3775: }
3776: if (!setvis) {
3777: if (document.getElementById(divid)) {
3778: document.getElementById(divid).style.display = 'none';
3779: }
3780: }
3781: }
3782: return;
3783: }
3784: // ]]>
3785: </script>
3786:
3787: ENDSCRIPT
3788: }
3789:
1.399 raeburn 3790: sub autoenroll_javascript {
3791: return <<"ENDSCRIPT";
3792: <script type="text/javascript">
3793: // <![CDATA[
3794: function toggleFailsafe(form) {
3795: var radioname = 'autoenroll_failsafe';
3796: var divid = 'autoenroll_failsafe_div';
3797: var num = form.elements[radioname].length;
3798: if (num) {
3799: var setvis = '';
3800: for (var i=0; i<num; i++) {
3801: if (form.elements[radioname][i].checked) {
3802: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3803: if (document.getElementById(divid)) {
3804: document.getElementById(divid).style.display = 'inline-block';
3805: }
3806: setvis = 1;
3807: }
3808: break;
3809: }
3810: }
3811: if (!setvis) {
3812: if (document.getElementById(divid)) {
3813: document.getElementById(divid).style.display = 'none';
3814: }
3815: }
3816: }
3817: return;
3818: }
3819: // ]]>
3820: </script>
3821:
3822: ENDSCRIPT
3823: }
3824:
1.386 raeburn 3825: sub saml_javascript {
3826: return <<"ENDSCRIPT";
3827: <script type="text/javascript">
3828: // <![CDATA[
1.425 raeburn 3829: function toggleSamlOptions(form,hostid) {
1.386 raeburn 3830: var radioname = 'saml_'+hostid;
3831: var tablecellon = 'samloptionson_'+hostid;
3832: var tablecelloff = 'samloptionsoff_'+hostid;
3833: var num = form.elements[radioname].length;
3834: if (num) {
1.425 raeburn 3835: var setvis = '';
1.386 raeburn 3836: for (var i=0; i<num; i++) {
3837: if (form.elements[radioname][i].checked) {
1.425 raeburn 3838: if (form.elements[radioname][i].value == '1') {
1.386 raeburn 3839: if (document.getElementById(tablecellon)) {
3840: document.getElementById(tablecellon).style.display='';
3841: }
3842: if (document.getElementById(tablecelloff)) {
3843: document.getElementById(tablecelloff).style.display='none';
3844: }
3845: setvis = 1;
3846: }
3847: break;
3848: }
3849: }
3850: if (!setvis) {
3851: if (document.getElementById(tablecellon)) {
3852: document.getElementById(tablecellon).style.display='none';
3853: }
3854: if (document.getElementById(tablecelloff)) {
3855: document.getElementById(tablecelloff).style.display='';
3856: }
3857: }
3858: }
3859: return;
3860: }
3861: // ]]>
3862: </script>
3863:
3864: ENDSCRIPT
3865: }
3866:
1.394 raeburn 3867: sub ipaccess_javascript {
3868: my ($settings) = @_;
3869: my (%ordered,$total,%jstext);
3870: $total = 0;
3871: if (ref($settings) eq 'HASH') {
3872: foreach my $item (keys(%{$settings})) {
3873: if (ref($settings->{$item}) eq 'HASH') {
3874: my $num = $settings->{$item}{'order'};
3875: $ordered{$num} = $item;
3876: }
3877: }
3878: $total = scalar(keys(%{$settings}));
3879: }
3880: my @jsarray = ();
3881: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3882: push(@jsarray,$ordered{$item});
3883: }
3884: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3885: return <<"ENDSCRIPT";
3886: <script type="text/javascript">
3887: // <![CDATA[
3888: function reorderIPaccess(form,item) {
3889: var changedVal;
3890: $jstext
3891: var newpos = 'ipaccess_pos_add';
3892: var maxh = 1 + $total;
3893: var current = new Array;
3894: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3895: if (item == newpos) {
3896: changedVal = newitemVal;
3897: } else {
3898: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3899: current[newitemVal] = newpos;
3900: }
3901: for (var i=0; i<ipaccess.length; i++) {
3902: var elementName = 'ipaccess_pos_'+ipaccess[i];
3903: if (elementName != item) {
3904: if (form.elements[elementName]) {
3905: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3906: current[currVal] = elementName;
3907: }
3908: }
3909: }
3910: var oldVal;
3911: for (var j=0; j<maxh; j++) {
3912: if (current[j] == undefined) {
3913: oldVal = j;
3914: }
3915: }
3916: if (oldVal < changedVal) {
3917: for (var k=oldVal+1; k<=changedVal ; k++) {
3918: var elementName = current[k];
3919: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3920: }
3921: } else {
3922: for (var k=changedVal; k<oldVal; k++) {
3923: var elementName = current[k];
3924: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3925: }
3926: }
3927: return;
3928: }
3929: // ]]>
3930: </script>
3931:
3932: ENDSCRIPT
3933: }
3934:
1.429 raeburn 3935: sub authordefaults_javascript {
3936: my %alert = &Apache::lonlocal::texthash (
3937: reqd => 'Warning: at least one editor needs to be available.',
3938: rest => 'Unchecking this editor disallowed while others unchecked.',
3939: );
3940: &js_escape(\%alert);
3941: return <<"ENDSCRIPT";
3942: <script type="text/javascript">
3943: // <![CDATA[
3944:
3945: function checkEditors(form,checkbox,current) {
3946: if (form.elements[checkbox].length != undefined) {
3947: var count = 0;
3948: for (var i=0; i<form.elements[checkbox].length; i++) {
3949: if (form.elements[checkbox][i].checked) {
3950: count ++;
3951: }
3952: }
3953: if (count == 0) {
3954: if (current.type =='radio') {
3955: current.checked = true;
3956: alert('$alert{reqd}\\n$alert{rest}');
3957: }
3958: }
3959: }
3960: return;
3961: }
3962: // ]]>
3963: </script>
3964:
3965: ENDSCRIPT
3966: }
3967:
1.3 raeburn 3968: sub print_autoenroll {
1.30 raeburn 3969: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3970: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 3971: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3972: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3973: $failsafesty = 'none';
3974: %failsafechecked = (
3975: off => ' checked="checked"',
3976: );
1.3 raeburn 3977: if (ref($settings) eq 'HASH') {
3978: if (exists($settings->{'run'})) {
3979: if ($settings->{'run'} eq '0') {
3980: $runoff = ' checked="checked" ';
3981: $runon = ' ';
3982: } else {
3983: $runon = ' checked="checked" ';
3984: $runoff = ' ';
3985: }
3986: } else {
3987: if ($autorun) {
3988: $runon = ' checked="checked" ';
3989: $runoff = ' ';
3990: } else {
3991: $runoff = ' checked="checked" ';
3992: $runon = ' ';
3993: }
3994: }
1.129 raeburn 3995: if (exists($settings->{'co-owners'})) {
3996: if ($settings->{'co-owners'} eq '0') {
3997: $coownersoff = ' checked="checked" ';
3998: $coownerson = ' ';
3999: } else {
4000: $coownerson = ' checked="checked" ';
4001: $coownersoff = ' ';
4002: }
4003: } else {
4004: $coownersoff = ' checked="checked" ';
4005: $coownerson = ' ';
4006: }
1.3 raeburn 4007: if (exists($settings->{'sender_domain'})) {
4008: $defdom = $settings->{'sender_domain'};
4009: }
1.399 raeburn 4010: if (exists($settings->{'failsafe'})) {
4011: $failsafe = $settings->{'failsafe'};
4012: if ($failsafe eq 'zero') {
1.400 raeburn 4013: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 4014: $failsafechecked{'off'} = '';
4015: $failsafesty = 'inline-block';
4016: } elsif ($failsafe eq 'any') {
4017: $failsafechecked{'any'} = ' checked="checked"';
4018: $failsafechecked{'off'} = '';
4019: }
4020: $autofailsafe = $settings->{'autofailsafe'};
4021: } elsif (exists($settings->{'autofailsafe'})) {
4022: $autofailsafe = $settings->{'autofailsafe'};
4023: if ($autofailsafe ne '') {
4024: $failsafechecked{'zero'} = ' checked="checked"';
4025: $failsafe = 'zero';
1.400 raeburn 4026: $failsafechecked{'off'} = '';
1.399 raeburn 4027: }
1.274 raeburn 4028: }
1.14 raeburn 4029: } else {
4030: if ($autorun) {
4031: $runon = ' checked="checked" ';
4032: $runoff = ' ';
4033: } else {
4034: $runoff = ' checked="checked" ';
4035: $runon = ' ';
4036: }
1.3 raeburn 4037: }
4038: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4039: my $notif_sender;
4040: if (ref($settings) eq 'HASH') {
4041: $notif_sender = $settings->{'sender_uname'};
4042: }
1.3 raeburn 4043: my $datatable='<tr class="LC_odd_row">'.
4044: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4045: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4046: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4047: $runon.' value="1" />'.&mt('Yes').'</label> '.
4048: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4049: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4050: '</tr><tr>'.
4051: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4052: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4053: &mt('username').': '.
4054: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4055: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4056: ': '.$domform.'</span></td></tr>'.
4057: '<tr class="LC_odd_row">'.
4058: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4059: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4060: '<input type="radio" name="autoassign_coowners"'.
4061: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4062: '<label><input type="radio" name="autoassign_coowners"'.
4063: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4064: '</tr><tr>'.
4065: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4066: '<td class="LC_left_item"><span class="LC_nobreak">'.
4067: '<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> '.
4068: '<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 />'.
4069: '<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 4070: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4071: '<span class="LC_nobreak">'.
4072: &mt('Threshold for number of students in section to drop: [_1]',
4073: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4074: '</span></div></td></tr>';
1.274 raeburn 4075: $$rowtotal += 4;
1.3 raeburn 4076: return $datatable;
4077: }
4078:
4079: sub print_autoupdate {
1.30 raeburn 4080: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4081: my ($enable,$datatable);
1.3 raeburn 4082: if ($position eq 'top') {
1.385 raeburn 4083: my %choices = &Apache::lonlocal::texthash (
4084: run => 'Auto-update active?',
4085: classlists => 'Update information in classlists?',
4086: unexpired => 'Skip updates for users without active or future roles?',
4087: lastactive => 'Skip updates for inactive users?',
4088: );
4089: my $itemcount = 0;
1.3 raeburn 4090: my $updateon = ' ';
4091: my $updateoff = ' checked="checked" ';
4092: if (ref($settings) eq 'HASH') {
4093: if ($settings->{'run'} eq '1') {
4094: $updateon = $updateoff;
4095: $updateoff = ' ';
4096: }
4097: }
1.385 raeburn 4098: $enable = '<tr class="LC_odd_row">'.
4099: '<td>'.$choices{'run'}.'</td>'.
4100: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4101: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4102: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4103: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4104: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4105: '</tr>';
1.385 raeburn 4106: my @toggles = ('classlists','unexpired');
4107: my %defaultchecked = ('classlists' => 'off',
4108: 'unexpired' => 'off'
4109: );
4110: $$rowtotal ++;
4111: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4112: \%choices,$itemcount,'','','left','no');
4113: $datatable = $enable.$datatable;
4114: $$rowtotal += $itemcount;
4115: my $lastactiveon = ' ';
4116: my $lastactiveoff = ' checked="checked" ';
4117: my $lastactivestyle = 'none';
4118: my $lastactivedays;
4119: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4120: if (ref($settings) eq 'HASH') {
4121: if ($settings->{'lastactive'} =~ /^\d+$/) {
4122: $lastactiveon = $lastactiveoff;
4123: $lastactiveoff = ' ';
4124: $lastactivestyle = 'inline-block';
4125: $lastactivedays = $settings->{'lastactive'};
4126: }
4127: }
4128: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4129: $datatable .= '<tr'.$css_class.'>'.
4130: '<td>'.$choices{'lastactive'}.'</td>'.
4131: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4132: '<input type="radio" name="lastactive"'.
4133: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4134: ' <label>'.
4135: '<input type="radio" name="lastactive"'.
4136: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4137: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4138: ': '.&mt('inactive = no activity in last [_1] days',
4139: '<input type="text" size="5" name="lastactivedays" value="'.
4140: $lastactivedays.'" />').
4141: '</span></td>'.
4142: '</tr>';
4143: $$rowtotal ++;
1.131 raeburn 4144: } elsif ($position eq 'middle') {
4145: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4146: my $numinrow = 3;
4147: my $locknamesettings;
4148: $datatable .= &insttypes_row($settings,$types,$usertypes,
4149: $dom,$numinrow,$othertitle,
1.305 raeburn 4150: 'lockablenames',$rowtotal);
1.131 raeburn 4151: $$rowtotal ++;
1.3 raeburn 4152: } else {
1.44 raeburn 4153: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4154: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4155: 'permanentemail','id');
1.33 raeburn 4156: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4157: my $numrows = 0;
1.26 raeburn 4158: if (ref($types) eq 'ARRAY') {
4159: if (@{$types} > 0) {
4160: $datatable =
4161: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4162: \@fields,$types,\$numrows);
1.30 raeburn 4163: $$rowtotal += @{$types};
1.26 raeburn 4164: }
1.3 raeburn 4165: }
4166: $datatable .=
4167: &usertype_update_row($settings,{'default' => $othertitle},
4168: \%fieldtitles,\@fields,['default'],
4169: \$numrows);
1.30 raeburn 4170: $$rowtotal ++;
1.3 raeburn 4171: }
4172: return $datatable;
4173: }
4174:
1.125 raeburn 4175: sub print_autocreate {
4176: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4177: my (%createon,%createoff,%currhash);
1.125 raeburn 4178: my @types = ('xml','req');
4179: if (ref($settings) eq 'HASH') {
4180: foreach my $item (@types) {
4181: $createoff{$item} = ' checked="checked" ';
4182: $createon{$item} = ' ';
4183: if (exists($settings->{$item})) {
4184: if ($settings->{$item}) {
4185: $createon{$item} = ' checked="checked" ';
4186: $createoff{$item} = ' ';
4187: }
4188: }
4189: }
1.210 raeburn 4190: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4191: $currhash{$settings->{'xmldc'}} = 1;
4192: }
1.125 raeburn 4193: } else {
4194: foreach my $item (@types) {
4195: $createoff{$item} = ' checked="checked" ';
4196: $createon{$item} = ' ';
4197: }
4198: }
4199: $$rowtotal += 2;
1.191 raeburn 4200: my $numinrow = 2;
1.125 raeburn 4201: my $datatable='<tr class="LC_odd_row">'.
4202: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4203: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4204: '<input type="radio" name="autocreate_xml"'.
4205: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4206: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4207: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4208: '</td></tr><tr>'.
4209: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4210: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4211: '<input type="radio" name="autocreate_req"'.
4212: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4213: '<label><input type="radio" name="autocreate_req"'.
4214: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4215: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4216: 'autocreate_xmldc',%currhash);
1.247 raeburn 4217: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4218: if ($numdc > 1) {
1.247 raeburn 4219: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4220: '</td><td class="LC_left_item">';
1.125 raeburn 4221: } else {
1.247 raeburn 4222: $datatable .= &mt('Course creation processed as:').
4223: '</td><td class="LC_right_item">';
1.125 raeburn 4224: }
1.247 raeburn 4225: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4226: $$rowtotal += $rows;
1.125 raeburn 4227: return $datatable;
4228: }
4229:
1.23 raeburn 4230: sub print_directorysrch {
1.277 raeburn 4231: my ($position,$dom,$settings,$rowtotal) = @_;
4232: my $datatable;
4233: if ($position eq 'top') {
4234: my $instsrchon = ' ';
4235: my $instsrchoff = ' checked="checked" ';
4236: my ($exacton,$containson,$beginson);
4237: my $instlocalon = ' ';
4238: my $instlocaloff = ' checked="checked" ';
4239: if (ref($settings) eq 'HASH') {
4240: if ($settings->{'available'} eq '1') {
4241: $instsrchon = $instsrchoff;
4242: $instsrchoff = ' ';
4243: }
4244: if ($settings->{'localonly'} eq '1') {
4245: $instlocalon = $instlocaloff;
4246: $instlocaloff = ' ';
4247: }
4248: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4249: foreach my $type (@{$settings->{'searchtypes'}}) {
4250: if ($type eq 'exact') {
4251: $exacton = ' checked="checked" ';
4252: } elsif ($type eq 'contains') {
4253: $containson = ' checked="checked" ';
4254: } elsif ($type eq 'begins') {
4255: $beginson = ' checked="checked" ';
4256: }
4257: }
4258: } else {
4259: if ($settings->{'searchtypes'} eq 'exact') {
4260: $exacton = ' checked="checked" ';
4261: } elsif ($settings->{'searchtypes'} eq 'contains') {
4262: $containson = ' checked="checked" ';
4263: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4264: $exacton = ' checked="checked" ';
4265: $containson = ' checked="checked" ';
4266: }
4267: }
1.277 raeburn 4268: }
4269: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4270: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4271:
4272: my $numinrow = 4;
4273: my $cansrchrow = 0;
4274: $datatable='<tr class="LC_odd_row">'.
4275: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4276: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4277: '<input type="radio" name="dirsrch_available"'.
4278: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4279: '<label><input type="radio" name="dirsrch_available"'.
4280: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4281: '</tr><tr>'.
4282: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4283: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4284: '<input type="radio" name="dirsrch_instlocalonly"'.
4285: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4286: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4287: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4288: '</tr>';
4289: $$rowtotal += 2;
4290: if (ref($usertypes) eq 'HASH') {
4291: if (keys(%{$usertypes}) > 0) {
4292: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4293: $numinrow,$othertitle,'cansearch',
4294: $rowtotal);
1.277 raeburn 4295: $cansrchrow = 1;
1.25 raeburn 4296: }
1.23 raeburn 4297: }
1.277 raeburn 4298: if ($cansrchrow) {
4299: $$rowtotal ++;
4300: $datatable .= '<tr>';
4301: } else {
4302: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4303: }
1.277 raeburn 4304: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4305: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4306: foreach my $title (@{$titleorder}) {
4307: if (defined($searchtitles->{$title})) {
4308: my $check = ' ';
4309: if (ref($settings) eq 'HASH') {
4310: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4311: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4312: $check = ' checked="checked" ';
4313: }
1.39 raeburn 4314: }
1.25 raeburn 4315: }
1.277 raeburn 4316: $datatable .= '<td class="LC_left_item">'.
4317: '<span class="LC_nobreak"><label>'.
4318: '<input type="checkbox" name="searchby" '.
4319: 'value="'.$title.'"'.$check.'/>'.
4320: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4321: }
4322: }
1.277 raeburn 4323: $datatable .= '</tr></table></td></tr>';
4324: $$rowtotal ++;
4325: if ($cansrchrow) {
4326: $datatable .= '<tr class="LC_odd_row">';
4327: } else {
4328: $datatable .= '<tr>';
4329: }
4330: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4331: '<td class="LC_left_item" colspan="2">'.
4332: '<span class="LC_nobreak"><label>'.
4333: '<input type="checkbox" name="searchtypes" '.
4334: $exacton.' value="exact" />'.&mt('Exact match').
4335: '</label> '.
4336: '<label><input type="checkbox" name="searchtypes" '.
4337: $beginson.' value="begins" />'.&mt('Begins with').
4338: '</label> '.
4339: '<label><input type="checkbox" name="searchtypes" '.
4340: $containson.' value="contains" />'.&mt('Contains').
4341: '</label></span></td></tr>';
4342: $$rowtotal ++;
1.26 raeburn 4343: } else {
1.277 raeburn 4344: my $domsrchon = ' checked="checked" ';
4345: my $domsrchoff = ' ';
4346: my $domlocalon = ' ';
4347: my $domlocaloff = ' checked="checked" ';
4348: if (ref($settings) eq 'HASH') {
4349: if ($settings->{'lclocalonly'} eq '1') {
4350: $domlocalon = $domlocaloff;
4351: $domlocaloff = ' ';
4352: }
4353: if ($settings->{'lcavailable'} eq '0') {
4354: $domsrchoff = $domsrchon;
4355: $domsrchon = ' ';
4356: }
4357: }
4358: $datatable='<tr class="LC_odd_row">'.
4359: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4360: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4361: '<input type="radio" name="dirsrch_domavailable"'.
4362: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4363: '<label><input type="radio" name="dirsrch_domavailable"'.
4364: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4365: '</tr><tr>'.
4366: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4367: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4368: '<input type="radio" name="dirsrch_domlocalonly"'.
4369: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4370: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4371: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4372: '</tr>';
4373: $$rowtotal += 2;
1.26 raeburn 4374: }
1.25 raeburn 4375: return $datatable;
4376: }
4377:
1.28 raeburn 4378: sub print_contacts {
1.286 raeburn 4379: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4380: my $datatable;
4381: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4382: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4383: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4384: if ($position eq 'top') {
4385: if (ref($settings) eq 'HASH') {
4386: foreach my $item (@contacts) {
4387: if (exists($settings->{$item})) {
4388: $to{$item} = $settings->{$item};
4389: }
4390: }
4391: }
4392: } elsif ($position eq 'middle') {
4393: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4394: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4395: foreach my $type (@mailings) {
4396: $otheremails{$type} = '';
4397: }
1.340 raeburn 4398: } elsif ($position eq 'lower') {
4399: if (ref($settings) eq 'HASH') {
4400: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4401: %lonstatus = %{$settings->{'lonstatus'}};
4402: }
4403: }
1.286 raeburn 4404: } else {
4405: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4406: foreach my $type (@mailings) {
4407: $otheremails{$type} = '';
4408: }
1.286 raeburn 4409: $bccemails{'helpdeskmail'} = '';
4410: $bccemails{'otherdomsmail'} = '';
4411: $includestr{'helpdeskmail'} = '';
4412: $includestr{'otherdomsmail'} = '';
4413: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4414: }
1.28 raeburn 4415: if (ref($settings) eq 'HASH') {
1.340 raeburn 4416: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4417: foreach my $type (@mailings) {
4418: if (exists($settings->{$type})) {
4419: if (ref($settings->{$type}) eq 'HASH') {
4420: foreach my $item (@contacts) {
4421: if ($settings->{$type}{$item}) {
4422: $checked{$type}{$item} = ' checked="checked" ';
4423: }
4424: }
4425: $otheremails{$type} = $settings->{$type}{'others'};
4426: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4427: $bccemails{$type} = $settings->{$type}{'bcc'};
4428: if ($settings->{$type}{'include'} ne '') {
4429: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4430: $includestr{$type} = &unescape($includestr{$type});
4431: }
4432: }
4433: }
4434: } elsif ($type eq 'lonstatusmail') {
4435: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4436: }
1.28 raeburn 4437: }
4438: }
1.286 raeburn 4439: if ($position eq 'bottom') {
4440: foreach my $type (@mailings) {
4441: $bccemails{$type} = $settings->{$type}{'bcc'};
4442: if ($settings->{$type}{'include'} ne '') {
4443: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4444: $includestr{$type} = &unescape($includestr{$type});
4445: }
4446: }
4447: if (ref($settings->{'helpform'}) eq 'HASH') {
4448: if (ref($fields) eq 'ARRAY') {
4449: foreach my $field (@{$fields}) {
4450: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4451: }
1.286 raeburn 4452: }
4453: if (exists($settings->{'helpform'}{'maxsize'})) {
4454: $maxsize = $settings->{'helpform'}{'maxsize'};
4455: } else {
1.289 raeburn 4456: $maxsize = '1.0';
1.286 raeburn 4457: }
4458: } else {
4459: if (ref($fields) eq 'ARRAY') {
4460: foreach my $field (@{$fields}) {
4461: $currfield{$field} = 'yes';
1.134 raeburn 4462: }
1.28 raeburn 4463: }
1.286 raeburn 4464: $maxsize = '1.0';
1.28 raeburn 4465: }
4466: }
4467: } else {
1.286 raeburn 4468: if ($position eq 'top') {
4469: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4470: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4471: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4472: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4473: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4474: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4475: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4476: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4477: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4478: } elsif ($position eq 'bottom') {
4479: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4480: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4481: if (ref($fields) eq 'ARRAY') {
4482: foreach my $field (@{$fields}) {
4483: $currfield{$field} = 'yes';
4484: }
4485: }
4486: $maxsize = '1.0';
4487: }
1.28 raeburn 4488: }
4489: my ($titles,$short_titles) = &contact_titles();
4490: my $rownum = 0;
4491: my $css_class;
1.286 raeburn 4492: if ($position eq 'top') {
4493: foreach my $item (@contacts) {
4494: $css_class = $rownum%2?' class="LC_odd_row"':'';
4495: $datatable .= '<tr'.$css_class.'>'.
4496: '<td><span class="LC_nobreak">'.$titles->{$item}.
4497: '</span></td><td class="LC_right_item">'.
4498: '<input type="text" name="'.$item.'" value="'.
4499: $to{$item}.'" /></td></tr>';
4500: $rownum ++;
4501: }
1.315 raeburn 4502: } elsif ($position eq 'bottom') {
4503: $css_class = $rownum%2?' class="LC_odd_row"':'';
4504: $datatable .= '<tr'.$css_class.'>'.
4505: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4506: &mt('(e-mail, subject, and description always shown)').
4507: '</td><td class="LC_left_item">';
4508: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4509: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4510: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4511: foreach my $field (@{$fields}) {
4512: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4513: if (($field eq 'screenshot') || ($field eq 'cc')) {
4514: $datatable .= ' '.&mt('(logged-in users)');
4515: }
4516: $datatable .='</td><td>';
4517: my $clickaction;
4518: if ($field eq 'screenshot') {
4519: $clickaction = ' onclick="screenshotSize(this);"';
4520: }
4521: if (ref($possoptions->{$field}) eq 'ARRAY') {
4522: foreach my $option (@{$possoptions->{$field}}) {
4523: my $checked;
4524: if ($currfield{$field} eq $option) {
4525: $checked = ' checked="checked"';
4526: }
4527: $datatable .= '<span class="LC_nobreak"><label>'.
4528: '<input type="radio" name="helpform_'.$field.'" '.
4529: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4530: '</label></span>'.(' 'x2);
4531: }
4532: }
4533: if ($field eq 'screenshot') {
4534: my $display;
4535: if ($currfield{$field} eq 'no') {
4536: $display = ' style="display:none"';
4537: }
1.334 raeburn 4538: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4539: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4540: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4541: }
4542: $datatable .= '</td></tr>';
4543: }
4544: $datatable .= '</table>';
4545: }
4546: $datatable .= '</td></tr>'."\n";
4547: $rownum ++;
4548: }
1.340 raeburn 4549: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4550: foreach my $type (@mailings) {
4551: $css_class = $rownum%2?' class="LC_odd_row"':'';
4552: $datatable .= '<tr'.$css_class.'>'.
4553: '<td><span class="LC_nobreak">'.
4554: $titles->{$type}.': </span></td>'.
4555: '<td class="LC_left_item">';
4556: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4557: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4558: }
4559: $datatable .= '<span class="LC_nobreak">';
4560: foreach my $item (@contacts) {
4561: $datatable .= '<label>'.
4562: '<input type="checkbox" name="'.$type.'"'.
4563: $checked{$type}{$item}.
4564: ' value="'.$item.'" />'.$short_titles->{$item}.
4565: '</label> ';
4566: }
4567: $datatable .= '</span><br />'.&mt('Others').': '.
4568: '<input type="text" name="'.$type.'_others" '.
4569: 'value="'.$otheremails{$type}.'" />';
4570: my %locchecked;
4571: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4572: foreach my $loc ('s','b') {
4573: if ($includeloc{$type} eq $loc) {
4574: $locchecked{$loc} = ' checked="checked"';
4575: last;
4576: }
4577: }
4578: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4579: '<input type="text" name="'.$type.'_bcc" '.
4580: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4581: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4582: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4583: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4584: '<span class="LC_nobreak">'.&mt('Location:').' '.
4585: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4586: (' 'x2).
4587: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4588: '</span></fieldset>';
4589: }
4590: $datatable .= '</td></tr>'."\n";
4591: $rownum ++;
4592: }
1.28 raeburn 4593: }
1.286 raeburn 4594: if ($position eq 'middle') {
4595: my %choices;
1.340 raeburn 4596: my $corelink = &core_link_msu();
4597: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4598: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4599: $corelink);
4600: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4601: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4602: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4603: 'reportupdates' => 'on',
4604: 'reportstatus' => 'on');
1.286 raeburn 4605: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4606: \%choices,$rownum);
4607: $datatable .= $reports;
1.340 raeburn 4608: } elsif ($position eq 'lower') {
1.378 raeburn 4609: my (%current,%excluded,%weights);
1.340 raeburn 4610: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4611: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4612: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4613: } else {
1.378 raeburn 4614: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4615: }
4616: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4617: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4618: } else {
1.378 raeburn 4619: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4620: }
4621: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4622: foreach my $type ('E','W','N','U') {
1.340 raeburn 4623: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4624: $weights{$type} = $lonstatus{'weights'}{$type};
4625: } else {
4626: $weights{$type} = $defaults->{$type};
4627: }
4628: }
4629: } else {
1.341 raeburn 4630: foreach my $type ('E','W','N','U') {
1.340 raeburn 4631: $weights{$type} = $defaults->{$type};
4632: }
4633: }
4634: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4635: if (@{$lonstatus{'excluded'}} > 0) {
4636: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4637: }
4638: }
1.425 raeburn 4639: foreach my $item ('errorthreshold','errorsysmail') {
1.378 raeburn 4640: $css_class = $rownum%2?' class="LC_odd_row"':'';
4641: $datatable .= '<tr'.$css_class.'>'.
4642: '<td class="LC_left_item"><span class="LC_nobreak">'.
4643: $titles->{$item}.
4644: '</span></td><td class="LC_left_item">'.
4645: '<input type="text" name="'.$item.'" value="'.
4646: $current{$item}.'" size="5" /></td></tr>';
4647: $rownum ++;
4648: }
1.340 raeburn 4649: $css_class = $rownum%2?' class="LC_odd_row"':'';
4650: $datatable .= '<tr'.$css_class.'>'.
4651: '<td class="LC_left_item">'.
4652: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4653: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4654: foreach my $type ('E','W','N','U') {
1.340 raeburn 4655: $datatable .= '<td>'.$names->{$type}.'<br />'.
4656: '<input type="text" name="errorweights_'.$type.'" value="'.
4657: $weights{$type}.'" size="5" /></td>';
4658: }
4659: $datatable .= '</tr></table></tr>';
4660: $rownum ++;
4661: $css_class = $rownum%2?' class="LC_odd_row"':'';
4662: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4663: $titles->{'errorexcluded'}.'</td>'.
4664: '<td class="LC_left_item"><table>';
4665: my $numinrow = 4;
4666: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4667: for (my $i=0; $i<@ids; $i++) {
4668: my $rem = $i%($numinrow);
4669: if ($rem == 0) {
4670: if ($i > 0) {
4671: $datatable .= '</tr>';
4672: }
4673: $datatable .= '<tr>';
4674: }
4675: my $check;
4676: if ($excluded{$ids[$i]}) {
4677: $check = ' checked="checked" ';
4678: }
4679: $datatable .= '<td class="LC_left_item">'.
4680: '<span class="LC_nobreak"><label>'.
4681: '<input type="checkbox" name="errorexcluded" '.
4682: 'value="'.$ids[$i].'"'.$check.' />'.
4683: $ids[$i].'</label></span></td>';
4684: }
4685: my $colsleft = $numinrow - @ids%($numinrow);
4686: if ($colsleft > 1 ) {
4687: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4688: ' </td>';
4689: } elsif ($colsleft == 1) {
4690: $datatable .= '<td class="LC_left_item"> </td>';
4691: }
4692: $datatable .= '</tr></table></td></tr>';
4693: $rownum ++;
1.286 raeburn 4694: } elsif ($position eq 'bottom') {
1.315 raeburn 4695: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4696: my (@posstypes,%usertypeshash);
4697: if (ref($types) eq 'ARRAY') {
4698: @posstypes = @{$types};
4699: }
4700: if (@posstypes) {
4701: if (ref($usertypes) eq 'HASH') {
4702: %usertypeshash = %{$usertypes};
4703: }
4704: my @overridden;
4705: my $numinrow = 4;
4706: if (ref($settings) eq 'HASH') {
4707: if (ref($settings->{'overrides'}) eq 'HASH') {
4708: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4709: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4710: push(@overridden,$key);
4711: foreach my $item (@contacts) {
4712: if ($settings->{'overrides'}{$key}{$item}) {
4713: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4714: }
4715: }
4716: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4717: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4718: $includeloc{'override_'.$key} = '';
4719: $includestr{'override_'.$key} = '';
4720: if ($settings->{'overrides'}{$key}{'include'} ne '') {
1.425 raeburn 4721: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
1.315 raeburn 4722: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4723: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4724: }
1.286 raeburn 4725: }
4726: }
4727: }
1.315 raeburn 4728: }
4729: my $customclass = 'LC_helpdesk_override';
4730: my $optionsprefix = 'LC_options_helpdesk_';
4731:
4732: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4733: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4734: $numinrow,$othertitle,'overrides',
4735: \$rownum,$onclicktypes,$customclass);
4736: $rownum ++;
4737: $usertypeshash{'default'} = $othertitle;
4738: foreach my $status (@posstypes) {
4739: my $css_class;
4740: if ($rownum%2) {
4741: $css_class = 'LC_odd_row ';
4742: }
4743: $css_class .= $customclass;
4744: my $rowid = $optionsprefix.$status;
4745: my $hidden = 1;
4746: my $currstyle = 'display:none';
4747: if (grep(/^\Q$status\E$/,@overridden)) {
4748: $currstyle = 'display:table-row';
4749: $hidden = 0;
4750: }
4751: my $key = 'override_'.$status;
4752: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4753: $includeloc{$key},$includestr{$key},$status,$rowid,
4754: $usertypeshash{$status},$css_class,$currstyle,
4755: \@contacts,$short_titles);
4756: unless ($hidden) {
4757: $rownum ++;
1.286 raeburn 4758: }
4759: }
1.134 raeburn 4760: }
1.28 raeburn 4761: }
1.30 raeburn 4762: $$rowtotal += $rownum;
1.28 raeburn 4763: return $datatable;
4764: }
4765:
1.340 raeburn 4766: sub core_link_msu {
4767: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4768: &mt('LON-CAPA core group - MSU'),600,500);
4769: }
4770:
1.315 raeburn 4771: sub overridden_helpdesk {
4772: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4773: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4774: my $class = 'LC_left_item';
4775: if ($css_class) {
4776: $css_class = ' class="'.$css_class.'"';
4777: }
4778: if ($rowid) {
4779: $rowid = ' id="'.$rowid.'"';
4780: }
4781: if ($rowstyle) {
4782: $rowstyle = ' style="'.$rowstyle.'"';
4783: }
4784: my ($output,$description);
4785: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4786: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4787: "<td>$description</td>\n".
4788: '<td class="'.$class.'" colspan="2">'.
4789: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4790: '<span class="LC_nobreak">';
4791: if (ref($contacts) eq 'ARRAY') {
4792: foreach my $item (@{$contacts}) {
4793: my $check;
4794: if (ref($checked) eq 'HASH') {
4795: $check = $checked->{$item};
4796: }
4797: my $title;
4798: if (ref($short_titles) eq 'HASH') {
1.425 raeburn 4799: $title = $short_titles->{$item};
1.315 raeburn 4800: }
4801: $output .= '<label>'.
4802: '<input type="checkbox" name="override_'.$type.'"'.$check.
4803: ' value="'.$item.'" />'.$title.'</label> ';
4804: }
4805: }
4806: $output .= '</span><br />'.&mt('Others').': '.
4807: '<input type="text" name="override_'.$type.'_others" '.
4808: 'value="'.$otheremails.'" />';
4809: my %locchecked;
4810: foreach my $loc ('s','b') {
4811: if ($includeloc eq $loc) {
4812: $locchecked{$loc} = ' checked="checked"';
4813: last;
4814: }
4815: }
4816: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4817: '<input type="text" name="override_'.$type.'_bcc" '.
4818: 'value="'.$bccemails.'" /></fieldset>'.
4819: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4820: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4821: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4822: '<span class="LC_nobreak">'.&mt('Location:').' '.
4823: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4824: (' 'x2).
4825: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4826: '</span></fieldset>'.
4827: '</td></tr>'."\n";
4828: return $output;
4829: }
4830:
1.286 raeburn 4831: sub contacts_javascript {
4832: return <<"ENDSCRIPT";
4833:
4834: <script type="text/javascript">
4835: // <![CDATA[
4836:
4837: function screenshotSize(field) {
4838: if (document.getElementById('help_screenshotsize')) {
4839: if (field.value == 'no') {
1.289 raeburn 4840: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4841: } else {
4842: document.getElementById('help_screenshotsize').style.display="";
4843: }
4844: }
4845: return;
4846: }
4847:
1.315 raeburn 4848: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4849: if (form.elements[checkbox].length != undefined) {
4850: var count = 0;
4851: if (docount) {
4852: for (var i=0; i<form.elements[checkbox].length; i++) {
4853: if (form.elements[checkbox][i].checked) {
4854: count ++;
4855: }
4856: }
4857: }
4858: for (var i=0; i<form.elements[checkbox].length; i++) {
4859: var type = form.elements[checkbox][i].value;
4860: if (document.getElementById(prefix+type)) {
4861: if (form.elements[checkbox][i].checked) {
4862: document.getElementById(prefix+type).style.display = 'table-row';
4863: if (count % 2 == 1) {
4864: document.getElementById(prefix+type).className = target+' LC_odd_row';
4865: } else {
4866: document.getElementById(prefix+type).className = target;
4867: }
4868: count ++;
4869: } else {
4870: document.getElementById(prefix+type).style.display = 'none';
4871: }
4872: }
4873: }
4874: }
4875: return;
4876: }
4877:
1.286 raeburn 4878: // ]]>
4879: </script>
4880:
4881: ENDSCRIPT
4882: }
4883:
1.118 jms 4884: sub print_helpsettings {
1.282 raeburn 4885: my ($position,$dom,$settings,$rowtotal) = @_;
4886: my $confname = $dom.'-domainconfig';
1.285 raeburn 4887: my $formname = 'display';
1.168 raeburn 4888: my ($datatable,$itemcount);
1.282 raeburn 4889: if ($position eq 'top') {
4890: $itemcount = 1;
4891: my (%choices,%defaultchecked,@toggles);
4892: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4893: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4894: &mt('LON-CAPA bug tracker'),600,500));
4895: %defaultchecked = ('submitbugs' => 'on');
4896: @toggles = ('submitbugs');
4897: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4898: \%choices,$itemcount);
4899: $$rowtotal ++;
4900: } else {
4901: my $css_class;
4902: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4903: my (%customroles,%ordered,%current);
1.301 raeburn 4904: if (ref($settings) eq 'HASH') {
4905: if (ref($settings->{'adhoc'}) eq 'HASH') {
4906: %current = %{$settings->{'adhoc'}};
4907: }
1.285 raeburn 4908: }
4909: my $count = 0;
4910: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4911: if ($key=~/^rolesdef\_(\w+)$/) {
4912: my $rolename = $1;
1.285 raeburn 4913: my (%privs,$order);
1.282 raeburn 4914: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4915: $customroles{$rolename} = \%privs;
1.285 raeburn 4916: if (ref($current{$rolename}) eq 'HASH') {
4917: $order = $current{$rolename}{'order'};
4918: }
4919: if ($order eq '') {
4920: $order = $count;
4921: }
4922: $ordered{$order} = $rolename;
4923: $count++;
4924: }
4925: }
4926: my $maxnum = scalar(keys(%ordered));
4927: my @roles_by_num = ();
4928: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4929: push(@roles_by_num,$item);
4930: }
4931: my $context = 'domprefs';
4932: my $crstype = 'Course';
4933: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4934: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4935: my ($numstatustypes,@jsarray);
4936: if (ref($types) eq 'ARRAY') {
4937: if (@{$types} > 0) {
4938: $numstatustypes = scalar(@{$types});
4939: push(@accesstypes,'status');
4940: @jsarray = ('bystatus');
1.282 raeburn 4941: }
4942: }
1.290 raeburn 4943: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4944: if (keys(%domhelpdesk)) {
4945: push(@accesstypes,('inc','exc'));
4946: push(@jsarray,('notinc','notexc'));
4947: }
4948: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4949: my $context = 'domprefs';
4950: my $crstype = 'Course';
1.285 raeburn 4951: my $prefix = 'helproles_';
4952: my $add_class = 'LC_hidden';
4953: foreach my $num (@roles_by_num) {
4954: my $role = $ordered{$num};
4955: my ($desc,$access,@statuses);
4956: if (ref($current{$role}) eq 'HASH') {
4957: $desc = $current{$role}{'desc'};
4958: $access = $current{$role}{'access'};
4959: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4960: @statuses = @{$current{$role}{'insttypes'}};
4961: }
4962: }
4963: if ($desc eq '') {
4964: $desc = $role;
4965: }
4966: my $identifier = 'custhelp'.$num;
1.282 raeburn 4967: my %full=();
4968: my %levels= (
4969: course => {},
4970: domain => {},
4971: system => {},
4972: );
4973: my %levelscurrent=(
4974: course => {},
4975: domain => {},
4976: system => {},
4977: );
4978: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4979: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4980: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4981: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4982: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4983: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4984: for (my $k=0; $k<=$maxnum; $k++) {
4985: my $vpos = $k+1;
4986: my $selstr;
4987: if ($k == $num) {
4988: $selstr = ' selected="selected" ';
4989: }
4990: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4991: }
4992: $datatable .= '</select>'.(' 'x2).
4993: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4994: '</td>'.
4995: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4996: &mt('Name shown to users:').
4997: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4998: '</fieldset>'.
4999: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
5000: $othertitle,$usertypes,$types,\%domhelpdesk).
5001: '<fieldset>'.
5002: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 5003: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 5004: \%levelscurrent,$identifier,
5005: 'LC_hidden',$prefix.$num.'_privs').
5006: '</fieldset></td>';
1.282 raeburn 5007: $itemcount ++;
5008: }
5009: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5010: my $newcust = 'custhelp'.$count;
5011: my (%privs,%levelscurrent);
5012: my %full=();
5013: my %levels= (
5014: course => {},
5015: domain => {},
5016: system => {},
5017: );
5018: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
5019: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5020: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5021: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5022: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5023: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5024: for (my $k=0; $k<$maxnum+1; $k++) {
5025: my $vpos = $k+1;
5026: my $selstr;
5027: if ($k == $maxnum) {
5028: $selstr = ' selected="selected" ';
5029: }
5030: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5031: }
5032: $datatable .= '</select> '."\n".
1.282 raeburn 5033: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5034: '</label></span></td>'.
1.285 raeburn 5035: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5036: '<span class="LC_nobreak">'.
5037: &mt('Internal name:').
5038: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5039: '</span>'.(' 'x4).
5040: '<span class="LC_nobreak">'.
5041: &mt('Name shown to users:').
5042: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5043: '</span></fieldset>'.
5044: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5045: $usertypes,$types,\%domhelpdesk).
5046: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5047: &Apache::lonuserutils::custom_role_header($context,$crstype,
5048: \@templateroles,$newcust).
5049: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5050: \%levelscurrent,$newcust).
1.334 raeburn 5051: '</fieldset>'.
5052: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5053: '</td></tr>';
1.282 raeburn 5054: $count ++;
5055: $$rowtotal += $count;
5056: }
1.166 raeburn 5057: return $datatable;
1.121 raeburn 5058: }
5059:
1.285 raeburn 5060: sub adhocbutton {
5061: my ($prefix,$num,$field,$visibility) = @_;
5062: my %lt = &Apache::lonlocal::texthash(
5063: show => 'Show details',
5064: hide => 'Hide details',
5065: );
5066: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5067: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5068: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5069: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5070: }
5071:
5072: sub helpsettings_javascript {
5073: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5074: return unless(ref($roles_by_num) eq 'ARRAY');
5075: my %html_js_lt = &Apache::lonlocal::texthash(
5076: show => 'Show details',
5077: hide => 'Hide details',
5078: );
5079: &html_escape(\%html_js_lt);
5080: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5081: return <<"ENDSCRIPT";
5082: <script type="text/javascript">
5083: // <![CDATA[
5084:
5085: function reorderHelpRoles(form,item) {
5086: var changedVal;
5087: $jstext
5088: var newpos = 'helproles_${total}_pos';
5089: var maxh = 1 + $total;
5090: var current = new Array();
5091: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5092: if (item == newpos) {
5093: changedVal = newitemVal;
5094: } else {
5095: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5096: current[newitemVal] = newpos;
5097: }
5098: for (var i=0; i<helproles.length; i++) {
5099: var elementName = 'helproles_'+helproles[i]+'_pos';
5100: if (elementName != item) {
5101: if (form.elements[elementName]) {
5102: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5103: current[currVal] = elementName;
5104: }
5105: }
5106: }
5107: var oldVal;
5108: for (var j=0; j<maxh; j++) {
5109: if (current[j] == undefined) {
5110: oldVal = j;
5111: }
5112: }
5113: if (oldVal < changedVal) {
5114: for (var k=oldVal+1; k<=changedVal ; k++) {
5115: var elementName = current[k];
5116: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5117: }
5118: } else {
5119: for (var k=changedVal; k<oldVal; k++) {
5120: var elementName = current[k];
5121: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5122: }
5123: }
5124: return;
5125: }
5126:
5127: function helpdeskAccess(num) {
5128: var curraccess = null;
5129: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5130: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5131: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5132: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5133: }
5134: }
5135: }
5136: var shown = Array();
5137: var hidden = Array();
5138: if (curraccess == 'none') {
5139: hidden = Array('$hiddenstr');
5140: } else {
5141: if (curraccess == 'status') {
5142: shown = Array('bystatus');
5143: hidden = Array('notinc','notexc');
5144: } else {
5145: if (curraccess == 'exc') {
5146: shown = Array('notexc');
5147: hidden = Array('notinc','bystatus');
5148: }
5149: if (curraccess == 'inc') {
5150: shown = Array('notinc');
5151: hidden = Array('notexc','bystatus');
5152: }
1.293 raeburn 5153: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5154: hidden = Array('notinc','notexc','bystatus');
5155: }
5156: }
5157: }
5158: if (hidden.length > 0) {
5159: for (var i=0; i<hidden.length; i++) {
5160: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5161: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5162: }
5163: }
5164: }
5165: if (shown.length > 0) {
5166: for (var i=0; i<shown.length; i++) {
5167: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5168: if (shown[i] == 'privs') {
5169: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5170: } else {
5171: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5172: }
5173: }
5174: }
5175: }
5176: return;
5177: }
5178:
5179: function toggleHelpdeskItem(num,field) {
5180: if (document.getElementById('helproles_'+num+'_'+field)) {
5181: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5182: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5183: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5184: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5185: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5186: }
5187: } else {
5188: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5189: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5190: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5191: }
5192: }
5193: }
5194: return;
5195: }
5196:
5197: // ]]>
5198: </script>
5199:
5200: ENDSCRIPT
5201: }
5202:
5203: sub helpdeskroles_access {
5204: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5205: $usertypes,$types,$domhelpdesk) = @_;
5206: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5207: my %lt = &Apache::lonlocal::texthash(
5208: 'rou' => 'Role usage',
5209: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5210: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5211: 'dh' => 'All with domain helpdesk role',
5212: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5213: 'none' => 'None',
5214: 'status' => 'Determined based on institutional status',
5215: 'inc' => 'Include all, but exclude specific personnel',
5216: 'exc' => 'Exclude all, but include specific personnel',
5217: );
5218: my %usecheck = (
5219: all => ' checked="checked"',
5220: );
5221: my %displaydiv = (
5222: status => 'none',
5223: inc => 'none',
5224: exc => 'none',
5225: priv => 'block',
5226: );
5227: my $output;
5228: if (ref($current) eq 'HASH') {
5229: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5230: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5231: $usecheck{$current->{access}} = $usecheck{'all'};
5232: delete($usecheck{'all'});
5233: if ($current->{access} =~ /^(status|inc|exc)$/) {
5234: my $access = $1;
5235: $displaydiv{$access} = 'inline';
5236: } elsif ($current->{access} eq 'none') {
5237: $displaydiv{'priv'} = 'none';
5238: }
5239: }
5240: }
5241: }
5242: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5243: '<p>'.$lt{'whi'}.'</p>';
5244: foreach my $access (@{$accesstypes}) {
5245: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5246: ' onclick="helpdeskAccess('."'$num'".');" />'.
5247: $lt{$access}.'</label>';
5248: if ($access eq 'status') {
5249: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5250: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5251: $othertitle,$usertypes,$types).
5252: '</div>';
5253: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5254: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5255: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5256: '</div>';
5257: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5258: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5259: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5260: '</div>';
5261: }
5262: $output .= '</p>';
5263: }
5264: $output .= '</fieldset>';
5265: return $output;
5266: }
5267:
1.121 raeburn 5268: sub radiobutton_prefs {
1.192 raeburn 5269: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5270: $additional,$align,$firstval) = @_;
1.121 raeburn 5271: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5272: (ref($choices) eq 'HASH'));
5273:
1.170 raeburn 5274: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5275:
5276: foreach my $item (@{$toggles}) {
5277: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5278: $checkedon{$item} = ' checked="checked" ';
5279: $checkedoff{$item} = ' ';
1.121 raeburn 5280: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5281: $checkedoff{$item} = ' checked="checked" ';
5282: $checkedon{$item} = ' ';
5283: }
5284: }
5285: if (ref($settings) eq 'HASH') {
1.121 raeburn 5286: foreach my $item (@{$toggles}) {
1.118 jms 5287: if ($settings->{$item} eq '1') {
5288: $checkedon{$item} = ' checked="checked" ';
5289: $checkedoff{$item} = ' ';
5290: } elsif ($settings->{$item} eq '0') {
5291: $checkedoff{$item} = ' checked="checked" ';
5292: $checkedon{$item} = ' ';
5293: }
5294: }
1.121 raeburn 5295: }
1.192 raeburn 5296: if ($onclick) {
5297: $onclick = ' onclick="'.$onclick.'"';
5298: }
1.121 raeburn 5299: foreach my $item (@{$toggles}) {
1.118 jms 5300: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5301: $datatable .=
1.306 raeburn 5302: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5303: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5304: '</span></td>';
5305: if ($align eq 'left') {
5306: $datatable .= '<td class="LC_left_item">';
5307: } else {
5308: $datatable .= '<td class="LC_right_item">';
5309: }
1.385 raeburn 5310: $datatable .= '<span class="LC_nobreak">';
5311: if ($firstval eq 'no') {
5312: $datatable .=
5313: '<label><input type="radio" name="'.
5314: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5315: '</label> <label><input type="radio" name="'.$item.'" '.
5316: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5317: } else {
5318: $datatable .=
5319: '<label><input type="radio" name="'.
5320: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5321: '</label> <label><input type="radio" name="'.$item.'" '.
5322: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5323: }
5324: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5325: $itemcount ++;
1.121 raeburn 5326: }
5327: return ($datatable,$itemcount);
5328: }
5329:
1.267 raeburn 5330: sub print_ltitools {
1.421 raeburn 5331: my ($position,$dom,$settings,$rowtotal) = @_;
5332: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5333: if (ref($settings) eq 'HASH') {
1.421 raeburn 5334: if ($position eq 'top') {
5335: if (exists($settings->{'encrypt'})) {
5336: if (ref($settings->{'encrypt'}) eq 'HASH') {
5337: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5338: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5339: }
5340: }
1.267 raeburn 5341: }
1.421 raeburn 5342: if (exists($settings->{'private'})) {
5343: if (ref($settings->{'private'}) eq 'HASH') {
5344: if (ref($settings->{'private'}) eq 'HASH') {
5345: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5346: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5347: }
5348: }
5349: }
5350: }
1.421 raeburn 5351: } elsif ($position eq 'middle') {
5352: if (exists($settings->{'rules'})) {
5353: if (ref($settings->{'rules'}) eq 'HASH') {
5354: %rules = %{$settings->{'rules'}};
1.273 raeburn 5355: }
5356: }
1.421 raeburn 5357: } else {
5358: foreach my $key ('encrypt','private','rules') {
5359: if (exists($settings->{$key})) {
5360: delete($settings->{$key});
1.267 raeburn 5361: }
5362: }
5363: }
5364: }
1.421 raeburn 5365: my $datatable;
5366: my $itemcount = 1;
5367: if ($position eq 'top') {
5368: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5369: } elsif ($position eq 'middle') {
5370: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5371: $$rowtotal += $itemcount;
5372: } else {
5373: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5374: }
5375: return $datatable;
5376: }
5377:
5378: sub ltitools_names {
5379: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5380: 'title' => 'Title',
5381: 'version' => 'Version',
5382: 'msgtype' => 'Message Type',
1.323 raeburn 5383: 'sigmethod' => 'Signature Method',
1.296 raeburn 5384: 'url' => 'URL',
5385: 'key' => 'Key',
1.322 raeburn 5386: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5387: 'secret' => 'Secret',
1.425 raeburn 5388: 'icon' => 'Icon',
1.324 raeburn 5389: 'user' => 'User',
1.296 raeburn 5390: 'fullname' => 'Full Name',
5391: 'firstname' => 'First Name',
5392: 'lastname' => 'Last Name',
5393: 'email' => 'E-mail',
5394: 'roles' => 'Role',
1.298 raeburn 5395: 'window' => 'Window',
5396: 'tab' => 'Tab',
1.296 raeburn 5397: 'iframe' => 'iFrame',
5398: 'height' => 'Height',
5399: 'width' => 'Width',
5400: 'linktext' => 'Default Link Text',
5401: 'explanation' => 'Default Explanation',
5402: 'passback' => 'Tool can return grades:',
5403: 'roster' => 'Tool can retrieve roster:',
5404: 'crstarget' => 'Display target',
5405: 'crslabel' => 'Course label',
1.425 raeburn 5406: 'crstitle' => 'Course title',
1.296 raeburn 5407: 'crslinktext' => 'Link Text',
5408: 'crsexplanation' => 'Explanation',
1.318 raeburn 5409: 'crsappend' => 'Provider URL',
1.267 raeburn 5410: );
5411: return %lt;
5412: }
5413:
1.421 raeburn 5414: sub secrets_form {
5415: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5416: my @ids=&Apache::lonnet::current_machine_ids();
5417: my %servers = &Apache::lonnet::get_servers($dom,'library');
5418: my $primary = &Apache::lonnet::domain($dom,'primary');
5419: my ($css_class,$extra,$numshown,$itemcount,$output);
5420: $itemcount = 0;
5421: foreach my $hostid (sort(keys(%servers))) {
5422: my ($showextra,$divsty,$switch);
5423: if ($hostid eq $primary) {
5424: if ($context eq 'ltisec') {
5425: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5426: $showextra = 1;
5427: }
5428: if ($encrypt->{'ltisec_crslinkprot'}) {
5429: $showextra = 1;
5430: }
5431: } else {
5432: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5433: $showextra = 1;
5434: }
5435: }
5436: unless (grep(/^\Q$hostid\E$/,@ids)) {
5437: $switch = 1;
5438: }
5439: if ($showextra) {
5440: $numshown ++;
5441: $divsty = 'display:inline-block';
5442: } else {
5443: $divsty = 'display:none';
5444: }
5445: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5446: '<legend>'.$hostid.'</legend>';
5447: if ($switch) {
5448: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5449: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5450: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5451: if (exists($privkeys->{$hostid})) {
5452: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5453: '<span class="LC_nobreak">'.
5454: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5455: '<span class="LC_nobreak">'.&mt('Change?').
5456: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5457: (' 'x2).
5458: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5459: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5460: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5461: '</span></div>';
5462: } else {
5463: $extra .= '<span class="LC_nobreak">'.
5464: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5465: '</span>'."\n";
5466: }
5467: } elsif (exists($privkeys->{$hostid})) {
5468: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5469: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5470: '<span class="LC_nobreak">'.&mt('Change?').
5471: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5472: (' 'x2).
5473: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5474: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5475: '<span class="LC_nobreak">'.&mt('New Key').':'.
5476: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5477: '<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>'.
5478: '</span></div>';
5479: } else {
5480: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5481: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5482: '<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>';
5483: }
5484: $extra .= '</fieldset>';
5485: }
5486: }
5487: my (%choices,@toggles,%defaultchecked);
5488: if ($context eq 'ltisec') {
5489: %choices = &Apache::lonlocal::texthash (
5490: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5491: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5492: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5493: );
5494: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5495: %defaultchecked = (
5496: 'ltisec_crslinkprot' => 'off',
5497: 'ltisec_domlinkprot' => 'off',
5498: 'ltisec_consumers' => 'off',
5499: );
5500: } else {
5501: %choices = &Apache::lonlocal::texthash (
5502: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5503: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5504: );
5505: @toggles = qw(toolsec_crs toolsec_dom);
5506: %defaultchecked = (
5507: 'toolsec_crs' => 'off',
5508: 'toolsec_dom' => 'off',
5509: );
5510: }
5511: my ($onclick,$itemcount);
5512: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5513: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5514: \%choices,$itemcount,$onclick,'','left','no');
5515:
5516: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5517: my $noprivkeysty = 'display:inline-block';
5518: if ($numshown) {
5519: $noprivkeysty = 'display:none';
5520: }
5521: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5522: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5523: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5524: $extra.
5525: '</td></tr>';
5526: $itemcount ++;
5527: $$rowtotal += $itemcount;
5528: return $output;
5529: }
5530:
1.372 raeburn 5531: sub print_proctoring {
5532: my ($dom,$settings,$rowtotal) = @_;
5533: my $itemcount = 1;
5534: my (%ordered,%providernames,%current,%currentdef);
5535: my $confname = $dom.'-domainconfig';
5536: my $switchserver = &check_switchserver($dom,$confname);
5537: if (ref($settings) eq 'HASH') {
5538: foreach my $item (keys(%{$settings})) {
5539: if (ref($settings->{$item}) eq 'HASH') {
5540: my $num = $settings->{$item}{'order'};
5541: $ordered{$num} = $item;
5542: }
5543: }
5544: } else {
5545: %ordered = (
5546: 1 => 'proctorio',
5547: 2 => 'examity',
5548: );
5549: }
5550: %providernames = &proctoring_providernames();
5551: my $maxnum = scalar(keys(%ordered));
5552: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5553: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5554: if (ref($requref) eq 'HASH') {
5555: %requserfields = %{$requref};
5556: }
5557: if (ref($opturef) eq 'HASH') {
5558: %optuserfields = %{$opturef};
5559: }
5560: if (ref($defref) eq 'HASH') {
5561: %defaults = %{$defref};
5562: }
5563: if (ref($extref) eq 'HASH') {
5564: %extended = %{$extref};
5565: }
5566: if (ref($crsref) eq 'HASH') {
5567: %crsconf = %{$crsref};
5568: }
5569: if (ref($rolesref) eq 'ARRAY') {
5570: @courseroles = @{$rolesref};
5571: }
5572: if (ref($ltiref) eq 'ARRAY') {
5573: @ltiroles = @{$ltiref};
5574: }
5575: my $datatable;
5576: my $css_class;
5577: if (keys(%ordered)) {
5578: my @items = sort { $a <=> $b } keys(%ordered);
5579: for (my $i=0; $i<@items; $i++) {
5580: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5581: my $provider = $ordered{$items[$i]};
5582: my $optionsty = 'none';
5583: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5584: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5585: if (ref($settings) eq 'HASH') {
5586: if (ref($settings->{$provider}) eq 'HASH') {
5587: %current = %{$settings->{$provider}};
5588: if ($current{'available'}) {
5589: $optionsty = 'block';
5590: $available = 1;
5591: }
5592: if ($current{'lifetime'} =~ /^\d+$/) {
5593: $lifetime = $current{'lifetime'};
5594: }
5595: if ($current{'version'} =~ /^\d+\.\d+$/) {
5596: $version = $current{'version'};
5597: }
5598: if ($current{'image'} ne '') {
5599: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5600: }
5601: if (ref($current{'fields'}) eq 'ARRAY') {
5602: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5603: }
5604: $userincdom = $current{'incdom'};
5605: if (ref($current{'roles'}) eq 'HASH') {
5606: %rolemaps = %{$current{'roles'}};
5607: $checkedfields{'roles'} = 1;
5608: }
5609: if (ref($current{'defaults'}) eq 'ARRAY') {
5610: foreach my $val (@{$current{'defaults'}}) {
5611: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5612: $inuse{$val} = 1;
5613: } else {
5614: foreach my $poss (keys(%{$extended{$provider}})) {
5615: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5616: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5617: $inuse{$poss} = $val;
5618: last;
5619: }
5620: }
5621: }
5622: }
5623: }
5624: } elsif (ref($current{'defaults'}) eq 'HASH') {
5625: foreach my $key (keys(%{$current{'defaults'}})) {
5626: my $currval = $current{'defaults'}{$key};
5627: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5628: $inuse{$key} = 1;
5629: } else {
5630: my $match;
5631: foreach my $poss (keys(%{$extended{$provider}})) {
5632: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5633: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5634: $inuse{$poss} = $key;
5635: last;
5636: }
5637: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5638: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5639: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5640: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5641: $currentdef{$inner} = $currval;
5642: $match = 1;
5643: last;
5644: }
5645: } elsif ($inner eq $key) {
5646: $currentdef{$key} = $currval;
5647: $match = 1;
5648: last;
5649: }
5650: }
5651: }
5652: last if ($match);
5653: }
5654: }
5655: }
5656: }
5657: if (ref($current{'crsconf'}) eq 'ARRAY') {
5658: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5659: }
5660: }
5661: }
5662: my %lt = &proctoring_titles($provider);
5663: my %fieldtitles = &proctoring_fieldtitles($provider);
5664: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5665: my %checkedavailable = (
5666: yes => '',
5667: no => ' checked="checked"',
5668: );
5669: if ($available) {
5670: $checkedavailable{'yes'} = $checkedavailable{'no'};
5671: $checkedavailable{'no'} = '';
5672: }
5673: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5674: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5675: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5676: for (my $k=0; $k<$maxnum; $k++) {
5677: my $vpos = $k+1;
5678: my $selstr;
5679: if ($k == $i) {
5680: $selstr = ' selected="selected" ';
5681: }
5682: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5683: }
5684: if ($version eq '') {
5685: if ($provider eq 'proctorio') {
5686: $version = '1.0';
5687: } elsif ($provider eq 'examity') {
5688: $version = '1.1';
5689: }
5690: }
5691: if ($lifetime eq '') {
5692: $lifetime = '300';
5693: }
5694: $datatable .=
5695: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5696: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5697: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5698: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5699: '</td>'.
5700: '<td colspan="2">'.
5701: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5702: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5703: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5704: (' 'x2).
5705: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5706: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5707: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5708: (' 'x2).
5709: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5710: '<br />'.
5711: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5712: '<br />'.
5713: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5714: (' 'x2).
5715: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5716: '<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";
5717: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5718: if ($imgsrc) {
5719: $datatable .= $imgsrc.
5720: '<label><input type="checkbox" name="proctoring_image_del"'.
5721: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5722: '<span class="LC_nobreak"> '.&mt('Replace:');
5723: }
5724: $datatable .= ' ';
5725: if ($switchserver) {
5726: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5727: } else {
5728: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5729: }
5730: unless ($imgsrc) {
5731: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5732: }
5733: $datatable .= '</fieldset>'."\n";
5734: if (ref($requserfields{$provider}) eq 'ARRAY') {
5735: if (@{$requserfields{$provider}} > 0) {
5736: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5737: foreach my $field (@{$requserfields{$provider}}) {
5738: $datatable .= '<span class="LC_nobreak">'.
5739: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5740: $lt{$field}.'</label>';
5741: if ($field eq 'user') {
5742: my $seluserdom = '';
5743: my $unseluserdom = ' selected="selected"';
5744: if ($userincdom) {
5745: $seluserdom = $unseluserdom;
5746: $unseluserdom = '';
5747: }
5748: $datatable .= ': '.
5749: '<select name="proctoring_userincdom_'.$provider.'">'.
5750: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5751: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5752: '</select> ';
5753: } else {
5754: $datatable .= ' ';
5755: if ($field eq 'roles') {
5756: $showroles = 1;
5757: }
5758: }
5759: $datatable .= '</span> ';
5760: }
5761: }
5762: $datatable .= '</fieldset>'."\n";
5763: }
5764: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5765: if (@{$optuserfields{$provider}} > 0) {
5766: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5767: foreach my $field (@{$optuserfields{$provider}}) {
5768: my $checked;
5769: if ($checkedfields{$field}) {
5770: $checked = ' checked="checked"';
5771: }
5772: $datatable .= '<span class="LC_nobreak">'.
5773: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5774: }
5775: $datatable .= '</fieldset>'."\n";
5776: }
5777: }
5778: if (ref($defaults{$provider}) eq 'ARRAY') {
5779: if (@{$defaults{$provider}}) {
5780: my (%options,@selectboxes);
5781: if (ref($extended{$provider}) eq 'HASH') {
5782: %options = %{$extended{$provider}};
5783: }
5784: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5785: my ($rem,$numinrow,$dropdowns);
5786: if ($provider eq 'proctorio') {
5787: $datatable .= '<table>';
5788: $numinrow = 4;
5789: }
5790: my $i = 0;
5791: foreach my $field (@{$defaults{$provider}}) {
5792: my $checked;
5793: if ($inuse{$field}) {
5794: $checked = ' checked="checked"';
5795: }
5796: if ($provider eq 'examity') {
5797: if ($field eq 'display') {
5798: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5799: foreach my $option ('iframe','tab','window') {
5800: my $checkdisp;
5801: if ($currentdef{'target'} eq $option) {
5802: $checkdisp = ' checked="checked"';
5803: }
5804: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5805: $fieldtitles{$option}.'</label>'.(' 'x2);
5806: }
5807: $datatable .= (' 'x4);
5808: foreach my $dimen ('width','height') {
5809: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5810: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5811: 'value="'.$currentdef{$dimen}.'" /></label>'.
5812: (' 'x2);
5813: }
5814: $datatable .= '</span><br />'.
5815: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5816: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5817: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5818: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5819: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5820: $currentdef{'explanation'}.
5821: '</textarea></div><div style=""></div><br />';
5822: }
5823: } else {
5824: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5825: my ($output,$selnone);
5826: unless ($checked) {
5827: $selnone = ' selected="selected"';
5828: }
5829: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5830: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5831: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5832: foreach my $option (@{$options{$field}}) {
5833: my $sel;
5834: if ($inuse{$field} eq $option) {
5835: $sel = ' selected="selected"';
5836: }
5837: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5838: }
5839: $output .= '</select></span>';
5840: push(@selectboxes,$output);
5841: } else {
5842: $rem = $i%($numinrow);
5843: if ($rem == 0) {
5844: if ($i > 0) {
5845: $datatable .= '</tr>';
5846: }
5847: $datatable .= '<tr>';
5848: }
5849: $datatable .= '<td class="LC_left_item">'.
5850: '<span class="LC_nobreak">'.
5851: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5852: $fieldtitles{$field}.'</label></span></td>';
5853: $i++;
5854: }
5855: }
5856: }
5857: if ($provider eq 'proctorio') {
5858: if ($numinrow) {
5859: $rem = $i%$numinrow;
5860: }
5861: my $colsleft = $numinrow - $rem;
5862: if ($colsleft > 1) {
5863: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5864: } else {
5865: $datatable .= '<td class="LC_left_item">';
5866: }
5867: $datatable .= ' '.
5868: '</td></tr></table>';
5869: if (@selectboxes) {
5870: $datatable .= '<hr /><table>';
5871: $numinrow = 2;
5872: for (my $i=0; $i<@selectboxes; $i++) {
5873: $rem = $i%($numinrow);
5874: if ($rem == 0) {
5875: if ($i > 0) {
5876: $datatable .= '</tr>';
5877: }
5878: $datatable .= '<tr>';
5879: }
5880: $datatable .= '<td class="LC_left_item">'.
5881: $selectboxes[$i].'</td>';
5882: }
5883: if ($numinrow) {
5884: $rem = $i%$numinrow;
5885: }
5886: $colsleft = $numinrow - $rem;
5887: if ($colsleft > 1) {
5888: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5889: } else {
5890: $datatable .= '<td class="LC_left_item">';
5891: }
5892: $datatable .= ' '.
5893: '</td></tr></table>';
5894: }
5895: }
5896: $datatable .= '</fieldset>';
5897: }
5898: if (ref($crsconf{$provider}) eq 'ARRAY') {
5899: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5900: '<legend>'.&mt('Configurable in course').'</legend>';
5901: my ($rem,$numinrow);
5902: if ($provider eq 'proctorio') {
5903: $datatable .= '<table>';
5904: $numinrow = 4;
5905: }
5906: my $i = 0;
5907: foreach my $item (@{$crsconf{$provider}}) {
5908: my $name;
5909: if ($provider eq 'examity') {
5910: $name = $lt{'crs'.$item};
5911: } elsif ($provider eq 'proctorio') {
5912: $name = $fieldtitles{$item};
5913: $rem = $i%($numinrow);
5914: if ($rem == 0) {
5915: if ($i > 0) {
5916: $datatable .= '</tr>';
5917: }
5918: $datatable .= '<tr>';
5919: }
5920: $datatable .= '<td class="LC_left_item>';
5921: }
5922: my $checked;
5923: if ($crsconfig{$item}) {
5924: $checked = ' checked="checked"';
5925: }
5926: $datatable .= '<span class="LC_nobreak"><label>'.
5927: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5928: $name.'</label></span>';
5929: if ($provider eq 'examity') {
5930: $datatable .= ' ';
5931: }
5932: $datatable .= "\n";
5933: $i++;
5934: }
5935: if ($provider eq 'proctorio') {
5936: if ($numinrow) {
5937: $rem = $i%$numinrow;
5938: }
5939: my $colsleft = $numinrow - $rem;
5940: if ($colsleft > 1) {
5941: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5942: } else {
5943: $datatable .= '<td class="LC_left_item">';
5944: }
5945: $datatable .= ' '.
5946: '</td></tr></table>';
5947: }
5948: $datatable .= '</fieldset>';
5949: }
5950: if ($showroles) {
5951: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5952: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5953: foreach my $role (@courseroles) {
5954: my ($selected,$selectnone);
5955: if (!$rolemaps{$role}) {
5956: $selectnone = ' selected="selected"';
5957: }
5958: $datatable .= '<td style="text-align: center">'.
5959: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5960: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5961: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5962: foreach my $ltirole (@ltiroles) {
5963: unless ($selectnone) {
5964: if ($rolemaps{$role} eq $ltirole) {
5965: $selected = ' selected="selected"';
5966: } else {
5967: $selected = '';
5968: }
5969: }
5970: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5971: }
5972: $datatable .= '</select></td>';
5973: }
5974: $datatable .= '</tr></table></fieldset>'.
5975: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5976: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5977: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5978: '<tr><td></td><td>lms</td>'.
5979: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5980: ' value="Loncapa" disabled="disabled"/></td></tr>';
5981: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5982: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5983: my %custom = %{$settings->{$provider}->{'custom'}};
5984: if (keys(%custom) > 0) {
5985: foreach my $key (sort(keys(%custom))) {
5986: next if ($key eq 'lms');
5987: $datatable .= '<tr><td><span class="LC_nobreak">'.
5988: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5989: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5990: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
5991: ' value="'.$custom{$key}.'" /></td></tr>';
5992: }
5993: }
5994: }
5995: $datatable .= '<tr><td><span class="LC_nobreak">'.
5996: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
5997: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
5998: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
5999: '</table></fieldset></td></tr>'."\n";
6000: }
6001: $datatable .= '</td></tr>';
6002: }
6003: $itemcount ++;
6004: }
6005: }
6006: return $datatable;
6007: }
6008:
6009: sub proctoring_data {
6010: my $requserfields = {
6011: proctorio => ['user'],
6012: examity => ['roles','user'],
6013: };
6014: my $optuserfields = {
6015: proctorio => ['fullname'],
6016: examity => ['fullname','firstname','lastname','email'],
6017: };
6018: my $defaults = {
6019: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6020: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6021: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6022: 'closetabs','onescreen','print','downloads','cache','rightclick',
6023: 'reentry','calculator','whiteboard'],
6024: examity => ['display'],
6025: };
6026: my $extended = {
6027: proctorio => {
6028: verifyid => ['verifyidauto','verifyidlive'],
6029: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6030: tabslinks => ['notabs','linksonly'],
6031: reentry => ['noreentry','agentreentry'],
6032: calculator => ['calculatorbasic','calculatorsci'],
6033: },
6034: examity => {
6035: display => {
6036: target => ['iframe','tab','window'],
6037: width => '',
6038: height => '',
6039: linktext => '',
6040: explanation => '',
6041: },
6042: },
6043: };
6044: my $crsconf = {
6045: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6046: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6047: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6048: 'closetabs','onescreen','print','downloads','cache','rightclick',
6049: 'reentry','calculator','whiteboard'],
6050: examity => ['label','title','target','linktext','explanation','append'],
6051: };
6052: my $courseroles = ['cc','in','ta','ep','st'];
6053: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6054: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6055: }
6056:
6057: sub proctoring_titles {
6058: my ($item) = @_;
6059: my (%common_lt,%custom_lt);
6060: %common_lt = &Apache::lonlocal::texthash (
6061: 'avai' => 'Available?',
6062: 'base' => 'Basic Settings',
6063: 'requ' => 'User data required to be sent on launch',
6064: 'optu' => 'User data optionally sent on launch',
6065: 'udsl' => 'User data sent on launch',
6066: 'defa' => 'Defaults for items configurable in course',
6067: 'sigmethod' => 'Signature Method',
6068: 'key' => 'Key',
6069: 'lifetime' => 'Nonce lifetime (s)',
6070: 'secret' => 'Secret',
6071: 'icon' => 'Icon',
6072: 'fullname' => 'Full Name',
6073: 'visible' => 'Visible input',
6074: 'username' => 'username',
6075: 'user' => 'User',
6076: );
6077: if ($item eq 'proctorio') {
6078: %custom_lt = &Apache::lonlocal::texthash (
6079: 'version' => 'OAuth version',
6080: 'url' => 'API URL',
6081: 'uname:dom' => 'username-domain',
6082: );
6083: } elsif ($item eq 'examity') {
6084: %custom_lt = &Apache::lonlocal::texthash (
6085: 'version' => 'LTI Version',
6086: 'url' => 'URL',
6087: 'uname:dom' => 'username:domain',
6088: 'msgtype' => 'Message Type',
6089: 'firstname' => 'First Name',
6090: 'lastname' => 'Last Name',
6091: 'email' => 'E-mail',
6092: 'roles' => 'Role',
6093: 'crstarget' => 'Display target',
6094: 'crslabel' => 'Course label',
6095: 'crstitle' => 'Course title',
6096: 'crslinktext' => 'Link Text',
6097: 'crsexplanation' => 'Explanation',
6098: 'crsappend' => 'Provider URL',
6099: );
6100: }
6101: my %lt = (%common_lt,%custom_lt);
6102: return %lt;
6103: }
6104:
6105: sub proctoring_fieldtitles {
6106: my ($item) = @_;
6107: if ($item eq 'proctorio') {
6108: return &Apache::lonlocal::texthash (
6109: 'recordvideo' => 'Record video',
6110: 'recordaudio' => 'Record audio',
6111: 'recordscreen' => 'Record screen',
6112: 'recordwebtraffic' => 'Record web traffic',
6113: 'recordroomstart' => 'Record room scan',
6114: 'verifyvideo' => 'Verify webcam',
6115: 'verifyaudio' => 'Verify microphone',
6116: 'verifydesktop' => 'Verify desktop recording',
6117: 'verifyid' => 'Photo ID verification',
6118: 'verifysignature' => 'Require signature',
6119: 'fullscreen' => 'Fullscreen',
6120: 'clipboard' => 'Disable copy/paste',
6121: 'tabslinks' => 'New tabs/windows',
6122: 'closetabs' => 'Close other tabs',
6123: 'onescreen' => 'Limit to single screen',
6124: 'print' => 'Disable Printing',
6125: 'downloads' => 'Disable Downloads',
6126: 'cache' => 'Empty cache after exam',
6127: 'rightclick' => 'Disable right click',
6128: 'reentry' => 'Re-entry to exam',
6129: 'calculator' => 'Onscreen calculator',
6130: 'whiteboard' => 'Onscreen whiteboard',
6131: 'verifyidauto' => 'Automated verification',
6132: 'verifyidlive' => 'Live agent verification',
6133: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6134: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6135: 'fullscreensever' => 'Forced, navigation away ends exam',
6136: 'notabs' => 'Disaallowed',
6137: 'linksonly' => 'Allowed from links in exam',
6138: 'noreentry' => 'Disallowed',
6139: 'agentreentry' => 'Agent required for re-entry',
6140: 'calculatorbasic' => 'Basic',
6141: 'calculatorsci' => 'Scientific',
6142: );
6143: } elsif ($item eq 'examity') {
6144: return &Apache::lonlocal::texthash (
6145: 'target' => 'Display target',
6146: 'window' => 'Window',
6147: 'tab' => 'Tab',
6148: 'iframe' => 'iFrame',
6149: 'height' => 'Height (pixels)',
6150: 'width' => 'Width (pixels)',
6151: 'linktext' => 'Default Link Text',
6152: 'explanation' => 'Default Explanation',
6153: 'append' => 'Provider URL',
6154: );
6155: }
6156: }
6157:
6158: sub proctoring_providernames {
6159: return (
6160: proctorio => 'Proctorio',
6161: examity => 'Examity',
6162: );
6163: }
6164:
1.320 raeburn 6165: sub print_lti {
1.405 raeburn 6166: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6167: my $itemcount = 1;
1.405 raeburn 6168: my ($datatable,$css_class);
1.434 raeburn 6169: my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
1.320 raeburn 6170: if (ref($settings) eq 'HASH') {
1.405 raeburn 6171: if ($position eq 'top') {
6172: if (exists($settings->{'encrypt'})) {
6173: if (ref($settings->{'encrypt'}) eq 'HASH') {
6174: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6175: if ($key eq 'consumers') {
6176: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6177: } else {
6178: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6179: }
6180: }
6181: }
6182: }
6183: if (exists($settings->{'private'})) {
6184: if (ref($settings->{'private'}) eq 'HASH') {
6185: if (ref($settings->{'private'}) eq 'HASH') {
6186: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6187: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6188: }
6189: }
6190: }
6191: }
1.434 raeburn 6192: } elsif ($position eq 'upper') {
1.405 raeburn 6193: if (exists($settings->{'rules'})) {
6194: if (ref($settings->{'rules'}) eq 'HASH') {
6195: %rules = %{$settings->{'rules'}};
6196: }
6197: }
1.434 raeburn 6198: } elsif ($position eq 'middle') {
6199: if (exists($settings->{'suggested'})) {
6200: if (ref($settings->{'suggested'}) eq 'HASH') {
6201: %suggestions = %{$settings->{'suggested'}};
6202: }
6203: }
1.405 raeburn 6204: } elsif ($position eq 'lower') {
6205: if (exists($settings->{'linkprot'})) {
6206: if (ref($settings->{'linkprot'}) eq 'HASH') {
6207: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6208: if ($linkprot{'lock'}) {
6209: delete($linkprot{'lock'});
6210: }
1.405 raeburn 6211: }
6212: }
6213: } else {
1.434 raeburn 6214: foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
1.405 raeburn 6215: if (exists($settings->{$key})) {
6216: delete($settings->{$key});
1.390 raeburn 6217: }
1.320 raeburn 6218: }
6219: }
6220: }
1.405 raeburn 6221: if ($position eq 'top') {
1.421 raeburn 6222: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
1.434 raeburn 6223: } elsif ($position eq 'upper') {
6224: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
6225: $$rowtotal += $itemcount;
1.421 raeburn 6226: } elsif ($position eq 'middle') {
1.434 raeburn 6227: $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
1.421 raeburn 6228: $$rowtotal += $itemcount;
6229: } elsif ($position eq 'lower') {
1.434 raeburn 6230: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
1.421 raeburn 6231: } else {
1.424 raeburn 6232: my ($switchserver,$switchmessage);
6233: $switchserver = &check_switchserver($dom);
6234: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.421 raeburn 6235: my $maxnum = 0;
6236: my %ordered;
6237: if (ref($settings) eq 'HASH') {
6238: foreach my $item (keys(%{$settings})) {
6239: if (ref($settings->{$item}) eq 'HASH') {
6240: my $num = $settings->{$item}{'order'};
6241: if ($num eq '') {
6242: $num = scalar(keys(%{$settings}));
6243: }
6244: $ordered{$num} = $item;
1.405 raeburn 6245: }
1.352 raeburn 6246: }
1.405 raeburn 6247: }
6248: $maxnum = scalar(keys(%ordered));
6249: my %lt = <i_names();
6250: if (keys(%ordered)) {
6251: my @items = sort { $a <=> $b } keys(%ordered);
6252: for (my $i=0; $i<@items; $i++) {
6253: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6254: my $item = $ordered{$items[$i]};
1.424 raeburn 6255: my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
1.405 raeburn 6256: if (ref($settings->{$item}) eq 'HASH') {
6257: $key = $settings->{$item}->{'key'};
1.424 raeburn 6258: $usable = $settings->{$item}->{'usable'};
1.405 raeburn 6259: $lifetime = $settings->{$item}->{'lifetime'};
6260: $consumer = $settings->{$item}->{'consumer'};
6261: $requser = $settings->{$item}->{'requser'};
6262: $crsinc = $settings->{$item}->{'crsinc'};
6263: $current = $settings->{$item};
6264: }
6265: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6266: my %checkedrequser = (
6267: yes => ' checked="checked"',
6268: no => '',
6269: );
6270: if (!$requser) {
6271: $checkedrequser{'no'} = $checkedrequser{'yes'};
6272: $checkedrequser{'yes'} = '';
6273: }
6274: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6275: my %checkedcrsinc = (
1.391 raeburn 6276: yes => ' checked="checked"',
6277: no => '',
1.405 raeburn 6278: );
6279: if (!$crsinc) {
6280: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6281: $checkedcrsinc{'yes'} = '';
6282: }
6283: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6284: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6285: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6286: for (my $k=0; $k<=$maxnum; $k++) {
6287: my $vpos = $k+1;
6288: my $selstr;
6289: if ($k == $i) {
6290: $selstr = ' selected="selected" ';
6291: }
6292: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6293: }
1.405 raeburn 6294: $datatable .= '</select>'.(' 'x2).
6295: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6296: &mt('Delete?').'</label></span></td>'.
6297: '<td colspan="2">'.
6298: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6299: '<span class="LC_nobreak">'.$lt{'consumer'}.
6300: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6301: (' 'x2).
6302: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6303: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6304: (' 'x2).
6305: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.424 raeburn 6306: 'value="'.$lifetime.'" size="3" /></span><br /><br />';
6307: if ($key ne '') {
6308: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6309: if ($switchserver) {
6310: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6311: } else {
6312: $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
6313: }
6314: $datatable .= '</span> '.(' 'x2);
6315: } elsif (!$switchserver) {
6316: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6317: '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
6318: '</span> '.(' 'x2);
6319: }
6320: if ($switchserver) {
6321: if ($usable ne '') {
6322: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6323: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6324: '<span class="LC_nobreak">'.&mt('Change secret?').
6325: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6326: (' 'x2).
6327: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
6328: '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6329: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6330: '</div>';
6331: } elsif ($key eq '') {
6332: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6333: } else {
6334: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6335: }
6336: } else {
6337: if ($usable ne '') {
6338: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6339: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6340: '<span class="LC_nobreak">'.&mt('Change?').
6341: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6342: (' 'x2).
6343: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
6344: '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6345: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6346: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6347: '<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>';
6348: } else {
6349: $datatable .=
6350: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6351: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6352: '<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>';
6353: }
6354: }
1.425 raeburn 6355: $datatable .= '<br /><br />'.
1.405 raeburn 6356: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6357: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6358: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6359: '<br /><br />'.
6360: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6361: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6362: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6363: (' 'x4).
6364: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6365: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6366: $itemcount ++;
1.320 raeburn 6367: }
6368: }
1.405 raeburn 6369: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6370: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6371: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6372: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6373: '<select name="lti_pos_add"'.$chgstr.'>';
6374: for (my $k=0; $k<$maxnum+1; $k++) {
6375: my $vpos = $k+1;
6376: my $selstr;
6377: if ($k == $maxnum) {
6378: $selstr = ' selected="selected" ';
6379: }
6380: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6381: }
1.405 raeburn 6382: $datatable .= '</select> '."\n".
6383: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6384: '<td colspan="2">'.
6385: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6386: '<span class="LC_nobreak">'.$lt{'consumer'}.
6387: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6388: (' 'x2).
6389: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6390: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6391: (' 'x2).
1.424 raeburn 6392: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
6393: if ($switchserver) {
6394: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6395: } else {
6396: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
6397: (' 'x2).
6398: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
6399: '<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";
6400: }
6401: $datatable .= '<br /><br />'.
1.405 raeburn 6402: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6403: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6404: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6405: '<br /><br />'.
6406: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6407: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6408: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6409: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6410: '</td>'."\n".
6411: '</tr>'."\n";
6412: $itemcount ++;
1.320 raeburn 6413: }
1.405 raeburn 6414: $$rowtotal += $itemcount;
6415: return $datatable;
1.320 raeburn 6416: }
6417:
6418: sub lti_names {
6419: my %lt = &Apache::lonlocal::texthash(
6420: 'version' => 'LTI Version',
6421: 'url' => 'URL',
6422: 'key' => 'Key',
1.322 raeburn 6423: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6424: 'consumer' => 'Consumer',
1.320 raeburn 6425: 'secret' => 'Secret',
1.345 raeburn 6426: 'requser' => "User's identity sent",
1.391 raeburn 6427: 'crsinc' => "Course's identity sent",
1.320 raeburn 6428: 'email' => 'Email address',
6429: 'sourcedid' => 'User ID',
6430: 'other' => 'Other',
6431: 'passback' => 'Can return grades to Consumer:',
6432: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6433: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6434: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6435: );
6436: return %lt;
6437: }
6438:
6439: sub lti_options {
1.325 raeburn 6440: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6441: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6442: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6443: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6444: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6445: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6446: $checked{'mapcrstype'} = {};
6447: $checked{'makeuser'} = {};
6448: $checked{'selfenroll'} = {};
6449: $checked{'crssec'} = {};
6450: $checked{'crssecsrc'} = {};
1.325 raeburn 6451: $checked{'lcauth'} = {};
1.326 raeburn 6452: $checked{'menuitem'} = {};
1.325 raeburn 6453: if ($num eq 'add') {
6454: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6455: }
1.320 raeburn 6456: my $userfieldsty = 'none';
6457: my $crsfieldsty = 'none';
6458: my $crssecfieldsty = 'none';
6459: my $secsrcfieldsty = 'none';
1.363 raeburn 6460: my $callbacksty = 'none';
1.337 raeburn 6461: my $passbacksty = 'none';
1.345 raeburn 6462: my $optionsty = 'block';
1.391 raeburn 6463: my $crssty = 'block';
1.325 raeburn 6464: my $lcauthparm;
6465: my $lcauthparmstyle = 'display:none';
6466: my $lcauthparmtext;
1.326 raeburn 6467: my $menusty;
1.325 raeburn 6468: my $numinrow = 4;
1.326 raeburn 6469: my %menutitles = <imenu_titles();
1.320 raeburn 6470:
6471: if (ref($current) eq 'HASH') {
1.345 raeburn 6472: if (!$current->{'requser'}) {
6473: $optionsty = 'none';
1.391 raeburn 6474: $crssty = 'none';
6475: } elsif (!$current->{'crsinc'}) {
6476: $crssty = 'none';
1.345 raeburn 6477: }
1.320 raeburn 6478: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6479: $checked{'mapuser'}{'sourcedid'} = '';
6480: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
1.425 raeburn 6481: $checked{'mapuser'}{'email'} = ' checked="checked"';
1.320 raeburn 6482: } else {
6483: $checked{'mapuser'}{'other'} = ' checked="checked"';
6484: $userfield = $current->{'mapuser'};
6485: $userfieldsty = 'inline-block';
6486: }
6487: }
6488: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6489: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6490: if ($current->{'mapcrs'} eq 'context_id') {
1.425 raeburn 6491: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
1.320 raeburn 6492: } else {
6493: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6494: $cidfield = $current->{'mapcrs'};
6495: $crsfieldsty = 'inline-block';
6496: }
6497: }
6498: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6499: foreach my $type (@{$current->{'mapcrstype'}}) {
6500: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6501: }
6502: }
1.392 raeburn 6503: if (!$current->{'storecrs'}) {
6504: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6505: $checked{'storecrs'}{'Y'} = '';
6506: }
1.345 raeburn 6507: if ($current->{'makecrs'}) {
1.320 raeburn 6508: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6509: }
1.320 raeburn 6510: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6511: foreach my $role (@{$current->{'makeuser'}}) {
6512: $checked{'makeuser'}{$role} = ' checked="checked"';
6513: }
6514: }
1.325 raeburn 6515: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6516: $checked{'lcauth'}{$1} = ' checked="checked"';
6517: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6518: $lcauthparm = $current->{'lcauthparm'};
1.425 raeburn 6519: $lcauthparmstyle = 'display:table-row';
1.325 raeburn 6520: if ($current->{'lcauth'} eq 'localauth') {
6521: $lcauthparmtext = &mt('Local auth argument');
6522: } else {
6523: $lcauthparmtext = &mt('Kerberos domain');
6524: }
6525: }
6526: }
1.320 raeburn 6527: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6528: foreach my $role (@{$current->{'selfenroll'}}) {
6529: $checked{'selfenroll'}{$role} = ' checked="checked"';
6530: }
6531: }
6532: if (ref($current->{'maproles'}) eq 'HASH') {
6533: %rolemaps = %{$current->{'maproles'}};
6534: }
6535: if ($current->{'section'} ne '') {
1.425 raeburn 6536: $checked{'crssec'}{'Y'} = ' checked="checked"';
1.320 raeburn 6537: $crssecfieldsty = 'inline-block';
6538: if ($current->{'section'} eq 'course_section_sourcedid') {
6539: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6540: } else {
6541: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6542: $crssecsrc = $current->{'section'};
6543: $secsrcfieldsty = 'inline-block';
6544: }
6545: } else {
6546: $checked{'crssec'}{'N'} = ' checked="checked"';
6547: }
1.363 raeburn 6548: if ($current->{'callback'} ne '') {
6549: $callback = $current->{'callback'};
6550: $checked{'callback'}{'Y'} = ' checked="checked"';
6551: $callbacksty = 'inline-block';
6552: } else {
6553: $checked{'callback'}{'N'} = ' checked="checked"';
6554: }
1.326 raeburn 6555: if ($current->{'topmenu'}) {
6556: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6557: } else {
6558: $checked{'topmenu'}{'N'} = ' checked="checked"';
6559: }
6560: if ($current->{'inlinemenu'}) {
6561: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6562: } else {
6563: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6564: }
6565: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6566: $menusty = 'inline-block';
6567: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6568: foreach my $item (@{$current->{'lcmenu'}}) {
6569: if (exists($menutitles{$item})) {
6570: $checked{'menuitem'}{$item} = ' checked="checked"';
6571: }
6572: }
6573: }
6574: } else {
6575: $menusty = 'none';
6576: }
1.320 raeburn 6577: } else {
6578: $checked{'makecrs'}{'N'} = ' checked="checked"';
6579: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6580: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6581: $checked{'topmenu'}{'N'} = ' checked="checked"';
1.425 raeburn 6582: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
1.326 raeburn 6583: $checked{'menuitem'}{'grades'} = ' checked="checked"';
1.425 raeburn 6584: $menusty = 'inline-block';
1.320 raeburn 6585: }
1.325 raeburn 6586: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6587: my %coursetypetitles = &Apache::lonlocal::texthash (
6588: official => 'Official',
6589: unofficial => 'Unofficial',
6590: community => 'Community',
6591: textbook => 'Textbook',
6592: placement => 'Placement Test',
1.325 raeburn 6593: lti => 'LTI Provider',
1.320 raeburn 6594: );
1.325 raeburn 6595: my @authtypes = ('internal','krb4','krb5','localauth');
6596: my %shortauth = (
6597: internal => 'int',
6598: krb4 => 'krb4',
6599: krb5 => 'krb5',
6600: localauth => 'loc'
6601: );
6602: my %authnames = &authtype_names();
1.320 raeburn 6603: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6604: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6605: my @courseroles = ('cc','in','ta','ep','st');
6606: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6607: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6608: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6609: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6610: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6611: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6612: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6613: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6614: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6615: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6616: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6617: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6618: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6619: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6620: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6621: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6622: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6623: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6624: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6625: foreach my $option ('sourcedid','email','other') {
6626: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6627: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6628: ($option eq 'other' ? '' : (' 'x2) );
6629: }
6630: $output .= '</span></div>'.
6631: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6632: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6633: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6634: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6635: foreach my $ltirole (@ltiroles) {
6636: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
1.425 raeburn 6637: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
1.320 raeburn 6638: }
6639: $output .= '</fieldset>'.
1.391 raeburn 6640: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6641: '<table>'.
6642: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6643: '</table>'.
6644: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6645: '<td class="LC_left_item">';
6646: foreach my $auth ('lti',@authtypes) {
6647: my $authtext;
6648: if ($auth eq 'lti') {
6649: $authtext = &mt('None');
6650: } else {
6651: $authtext = $authnames{$shortauth{$auth}};
6652: }
6653: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6654: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6655: $authtext.'</label></span> ';
6656: }
6657: $output .= '</td></tr>'.
6658: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6659: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6660: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6661: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6662: '</table></fieldset>'.
1.391 raeburn 6663: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6664: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6665: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6666: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6667: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6668: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6669: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6670: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6671: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6672: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6673: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6674: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6675: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6676: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6677: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6678: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6679: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6680: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6681: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6682: (' 'x2);
6683: }
6684: $output .= '</span></div></fieldset>'.
6685: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6686: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6687: &mt('Unique course identifier').': ';
6688: foreach my $option ('course_offering_sourcedid','context_id','other') {
6689: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6690: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6691: ($option eq 'other' ? '' : (' 'x2) );
6692: }
1.334 raeburn 6693: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6694: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6695: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6696: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6697: foreach my $type (@coursetypes) {
6698: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6699: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6700: (' 'x2);
6701: }
1.392 raeburn 6702: $output .= '</span><br /><br />'.
6703: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6704: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6705: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6706: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6707: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6708: '</fieldset>'.
1.391 raeburn 6709: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6710: foreach my $ltirole (@lticourseroles) {
6711: my ($selected,$selectnone);
6712: if ($rolemaps{$ltirole} eq '') {
6713: $selectnone = ' selected="selected"';
6714: }
6715: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6716: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6717: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6718: foreach my $role (@courseroles) {
6719: unless ($selectnone) {
6720: if ($rolemaps{$ltirole} eq $role) {
6721: $selected = ' selected="selected"';
6722: } else {
6723: $selected = '';
6724: }
6725: }
6726: $output .= '<option value="'.$role.'"'.$selected.'>'.
6727: &Apache::lonnet::plaintext($role,'Course').
6728: '</option>';
6729: }
6730: $output .= '</select></td>';
6731: }
6732: $output .= '</tr></table></fieldset>'.
6733: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6734: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6735: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6736: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6737: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6738: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6739: '</fieldset>'.
1.391 raeburn 6740: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6741: foreach my $lticrsrole (@lticourseroles) {
6742: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6743: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6744: }
6745: $output .= '</fieldset>'.
1.391 raeburn 6746: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6747: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6748: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6749: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6750: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6751: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6752: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6753: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6754: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6755: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6756: &mt('Standard field').'</label>'.(' 'x2).
6757: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6758: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6759: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6760: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6761: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6762: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6763: foreach my $extra ('roster','passback') {
1.320 raeburn 6764: my $checkedon = '';
6765: my $checkedoff = ' checked="checked"';
1.337 raeburn 6766: if ($extra eq 'passback') {
6767: $pb1p1chk = ' checked="checked"';
6768: $pb1p0chk = '';
1.425 raeburn 6769: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
1.337 raeburn 6770: } else {
1.425 raeburn 6771: $onclickpb = '';
1.337 raeburn 6772: }
1.320 raeburn 6773: if (ref($current) eq 'HASH') {
6774: if (($current->{$extra})) {
6775: $checkedon = $checkedoff;
6776: $checkedoff = '';
1.337 raeburn 6777: if ($extra eq 'passback') {
6778: $passbacksty = 'inline-block';
6779: }
6780: if ($current->{'passbackformat'} eq '1.0') {
6781: $pb1p0chk = ' checked="checked"';
6782: $pb1p1chk = '';
6783: }
1.320 raeburn 6784: }
6785: }
6786: $output .= $lt{$extra}.' '.
1.337 raeburn 6787: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6788: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6789: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6790: &mt('Yes').'</label><br />';
6791: }
1.337 raeburn 6792: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6793: '<span class="LC_nobreak">'.&mt('Grade format').
6794: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6795: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6796: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6797: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6798: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6799: $output .= '</span></div></fieldset>';
1.320 raeburn 6800: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6801: #
6802: # $output .= '</fieldset>'.
6803: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6804: return $output;
6805: }
6806:
1.326 raeburn 6807: sub ltimenu_titles {
6808: return &Apache::lonlocal::texthash(
6809: fullname => 'Full name',
6810: coursetitle => 'Course title',
6811: role => 'Role',
6812: logout => 'Logout',
6813: grades => 'Grades',
6814: );
6815: }
6816:
1.434 raeburn 6817: sub linkprot_suggestions {
6818: my ($suggested,$itemcount) = @_;
6819: my $count = 0;
6820: my $next = 1;
6821: my %lt = &Apache::lonlocal::texthash(
6822: 'name' => 'Suggested Launcher',
6823: 'info' => 'Recommendations',
6824: );
6825: my ($datatable,$css_class,$dest);
6826: if (ref($suggested) eq 'HASH') {
6827: my @current = sort { $a <=> $b } keys(%{$suggested});
6828: $next += $current[-1];
6829: for (my $i=0; $i<@current; $i++) {
6830: my $num = $current[$i];
6831: my %values;
6832: if (ref($suggested->{$num}) eq 'HASH') {
6833: %values = %{$suggested->{$num}};
6834: } else {
6835: next;
6836: }
6837: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6838: $datatable .=
6839: '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6840: '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
6841: &mt('Delete?').'</label></span></td><td>'."\n".
6842: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6843: '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
6844: '</fieldset></div>'.
6845: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6846: '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
6847: '</fieldset></div>'.
6848: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6849: '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
6850: $$itemcount ++;
6851: }
6852: }
6853: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6854: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6855: '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
6856: '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6857: '<td>'."\n".
6858: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6859: '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
6860: '</fieldset></div>'.
6861: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6862: '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
6863: '</fieldset></div>'.
6864: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6865: '</td></tr>'."\n";
6866: return $datatable;
6867: }
6868:
1.121 raeburn 6869: sub print_coursedefaults {
1.139 raeburn 6870: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6871: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6872: my $itemcount = 1;
1.192 raeburn 6873: my %choices = &Apache::lonlocal::texthash (
6874: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6875: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.432 raeburn 6876: coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.192 raeburn 6877: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6878: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6879: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6880: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6881: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6882: texengine => 'Default method to display mathematics',
1.257 raeburn 6883: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6884: canclone => "People who may clone a course (besides course's owner and coordinators)",
6885: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6886: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422 raeburn 6887: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6888: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
1.432 raeburn 6889: crsauthor => 'Standard LON-CAPA problems can be created within a course/community (by type)',
1.438 raeburn 6890: crseditors => 'Available editors for web pages and/or problems created in a course/community',
1.192 raeburn 6891: );
1.198 raeburn 6892: my %staticdefaults = (
6893: anonsurvey_threshold => 10,
6894: uploadquota => 500,
1.428 raeburn 6895: coursequota => 20,
1.257 raeburn 6896: postsubmit => 60,
1.276 raeburn 6897: mysqltables => 172800,
1.422 raeburn 6898: domexttool => 1,
6899: exttool => 0,
1.432 raeburn 6900: crsauthor => 1,
1.438 raeburn 6901: crseditors => ['edit','xml'],
1.198 raeburn 6902: );
1.139 raeburn 6903: if ($position eq 'top') {
1.257 raeburn 6904: %defaultchecked = (
6905: 'canuse_pdfforms' => 'off',
6906: 'uselcmath' => 'on',
6907: 'usejsme' => 'on',
1.398 raeburn 6908: 'inline_chem' => 'on',
1.289 raeburn 6909: 'canclone' => 'none',
1.257 raeburn 6910: );
1.398 raeburn 6911: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6912: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6913: if (ref($settings) eq 'HASH') {
6914: if ($settings->{'texengine'}) {
6915: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6916: $deftex = $settings->{'texengine'};
6917: }
6918: }
6919: }
6920: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6921: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6922: '<span class="LC_nobreak">'.$choices{'texengine'}.
6923: '</span></td><td class="LC_right_item">'.
6924: '<select name="texengine">'."\n";
6925: my %texoptions = (
6926: MathJax => 'MathJax',
6927: mimetex => &mt('Convert to Images'),
6928: tth => &mt('TeX to HTML'),
6929: );
6930: foreach my $renderer ('MathJax','mimetex','tth') {
6931: my $selected = '';
6932: if ($renderer eq $deftex) {
6933: $selected = ' selected="selected"';
6934: }
6935: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6936: }
6937: $mathdisp .= '</select></td></tr>'."\n";
6938: $itemcount ++;
1.139 raeburn 6939: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6940: \%choices,$itemcount);
1.314 raeburn 6941: $datatable = $mathdisp.$datatable;
1.264 raeburn 6942: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6943: $datatable .=
1.306 raeburn 6944: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6945: '<span class="LC_nobreak">'.$choices{'canclone'}.
6946: '</span></td><td class="LC_left_item">';
6947: my $currcanclone = 'none';
6948: my $onclick;
6949: my @cloneoptions = ('none','domain');
1.380 raeburn 6950: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6951: none => 'No additional course requesters',
6952: domain => "Any course requester in course's domain",
6953: instcode => 'Course requests for official courses ...',
6954: );
6955: my (%codedefaults,@code_order,@posscodes);
6956: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6957: \@code_order) eq 'ok') {
6958: if (@code_order > 0) {
6959: push(@cloneoptions,'instcode');
6960: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6961: }
6962: }
6963: if (ref($settings) eq 'HASH') {
6964: if ($settings->{'canclone'}) {
6965: if (ref($settings->{'canclone'}) eq 'HASH') {
6966: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6967: if (@code_order > 0) {
6968: $currcanclone = 'instcode';
6969: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6970: }
6971: }
6972: } elsif ($settings->{'canclone'} eq 'domain') {
6973: $currcanclone = $settings->{'canclone'};
6974: }
6975: }
1.289 raeburn 6976: }
1.264 raeburn 6977: foreach my $option (@cloneoptions) {
6978: my ($checked,$additional);
6979: if ($currcanclone eq $option) {
6980: $checked = ' checked="checked"';
6981: }
6982: if ($option eq 'instcode') {
6983: if (@code_order) {
6984: my $show = 'none';
6985: if ($checked) {
6986: $show = 'block';
6987: }
1.317 raeburn 6988: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6989: &mt('Institutional codes for new and cloned course have identical:').
6990: '<br />';
6991: foreach my $item (@code_order) {
6992: my $codechk;
6993: if ($checked) {
6994: if (grep(/^\Q$item\E$/,@posscodes)) {
6995: $codechk = ' checked="checked"';
6996: }
6997: }
6998: $additional .= '<label>'.
6999: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
7000: $item.'</label>';
7001: }
7002: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
7003: }
7004: }
7005: $datatable .=
7006: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
7007: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
7008: '</label> '.$additional.'</span><br />';
7009: }
7010: $datatable .= '</td>'.
7011: '</tr>';
7012: $itemcount ++;
1.139 raeburn 7013: } else {
7014: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 7015: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
7016: %deftimeout,%currmysql);
1.192 raeburn 7017: my $currusecredits = 0;
1.257 raeburn 7018: my $postsubmitclient = 1;
1.405 raeburn 7019: my $ltiauth = 0;
1.422 raeburn 7020: my %domexttool;
7021: my %exttool;
1.432 raeburn 7022: my %crsauthor;
1.438 raeburn 7023: my %crseditors;
1.271 raeburn 7024: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 7025: if (ref($settings) eq 'HASH') {
1.404 raeburn 7026: if ($settings->{'ltiauth'}) {
7027: $ltiauth = 1;
1.405 raeburn 7028: }
1.422 raeburn 7029: if (ref($settings->{'domexttool'}) eq 'HASH') {
7030: foreach my $type (@types) {
7031: if ($settings->{'domexttool'}->{$type}) {
7032: $domexttool{$type} = ' checked="checked"';
7033: }
7034: }
7035: } else {
7036: foreach my $type (@types) {
7037: if ($staticdefaults{'domexttool'}) {
7038: $domexttool{$type} = ' checked="checked"';
7039: }
7040: }
7041: }
7042: if (ref($settings->{'exttool'}) eq 'HASH') {
7043: foreach my $type (@types) {
7044: if ($settings->{'exttool'}->{$type}) {
7045: $exttool{$type} = ' checked="checked"';
7046: }
7047: }
7048: }
1.432 raeburn 7049: if (ref($settings->{'crsauthor'}) eq 'HASH') {
7050: foreach my $type (@types) {
7051: if ($settings->{'crsauthor'}->{$type}) {
7052: $crsauthor{$type} = ' checked="checked"';
7053: }
7054: }
7055: } else {
7056: foreach my $type (@types) {
7057: if ($staticdefaults{'crsauthor'}) {
7058: $crsauthor{$type} = ' checked="checked"';
7059: }
7060: }
7061: }
1.438 raeburn 7062: if (ref($settings->{'crseditors'}) eq 'ARRAY') {
7063: foreach my $editor (@{$settings->{'crseditors'}}) {
7064: $crseditors{$editor} = ' checked="checked"';
7065: }
7066: } else {
7067: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7068: $crseditors{$editor} = ' checked="checked"';
7069: }
7070: }
1.139 raeburn 7071: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7072: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7073: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7074: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7075: }
7076: }
1.428 raeburn 7077: if (ref($settings->{'coursequota'}) eq 'HASH') {
7078: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7079: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7080: }
7081: }
1.192 raeburn 7082: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7083: foreach my $type (@types) {
7084: next if ($type eq 'community');
7085: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7086: if ($defcredits{$type} ne '') {
7087: $currusecredits = 1;
7088: }
7089: }
7090: }
7091: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7092: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7093: $postsubmitclient = 0;
7094: foreach my $type (@types) {
7095: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7096: }
7097: } else {
7098: foreach my $type (@types) {
7099: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7100: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7101: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7102: } else {
7103: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7104: }
7105: } else {
7106: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7107: }
7108: }
7109: }
7110: } else {
7111: foreach my $type (@types) {
7112: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7113: }
7114: }
1.276 raeburn 7115: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7116: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7117: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7118: }
7119: } else {
7120: foreach my $type (@types) {
7121: $currmysql{$type} = $staticdefaults{'mysqltables'};
7122: }
7123: }
1.258 raeburn 7124: } else {
7125: foreach my $type (@types) {
7126: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7127: if ($staticdefaults{'domexttool'}) {
7128: $domexttool{$type} = ' checked="checked"';
7129: }
1.432 raeburn 7130: if ($staticdefaults{'crsauthor'}) {
7131: $crsauthor{$type} = ' checked="checked"';
7132: }
1.258 raeburn 7133: }
1.438 raeburn 7134: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7135: $crseditors{$editor} = ' checked="checked"';
7136: }
1.139 raeburn 7137: }
7138: if (!$currdefresponder) {
1.198 raeburn 7139: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7140: } elsif ($currdefresponder < 1) {
7141: $currdefresponder = 1;
7142: }
1.198 raeburn 7143: foreach my $type (@types) {
7144: if ($curruploadquota{$type} eq '') {
7145: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7146: }
1.428 raeburn 7147: if ($currcoursequota{$type} eq '') {
7148: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7149: }
1.198 raeburn 7150: }
1.139 raeburn 7151: $datatable .=
1.192 raeburn 7152: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7153: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7154: '</span></td>'.
7155: '<td class="LC_right_item"><span class="LC_nobreak">'.
7156: '<input type="text" name="anonsurvey_threshold"'.
7157: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7158: '</td></tr>'."\n";
7159: $itemcount ++;
7160: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7161: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7162: $choices{'uploadquota'}.
7163: '</span></td>'.
1.306 raeburn 7164: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7165: '<table><tr>';
1.198 raeburn 7166: foreach my $type (@types) {
1.306 raeburn 7167: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7168: '<input type="text" name="uploadquota_'.$type.'"'.
7169: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7170: }
7171: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7172: $itemcount ++;
1.428 raeburn 7173: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7174: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7175: $choices{'coursequota'}.
7176: '</span></td>'.
7177: '<td style="text-align: right" class="LC_right_item">'.
7178: '<table><tr>';
7179: foreach my $type (@types) {
7180: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7181: '<input type="text" name="coursequota_'.$type.'"'.
7182: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7183: }
7184: $datatable .= '</tr></table></td></tr>'."\n";
7185: $itemcount ++;
1.236 raeburn 7186: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7187: my $display = 'none';
1.192 raeburn 7188: if ($currusecredits) {
7189: $display = 'block';
7190: }
7191: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7192: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7193: foreach my $type (@types) {
7194: next if ($type eq 'community');
1.306 raeburn 7195: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7196: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7197: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7198: }
7199: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7200: %defaultchecked = ('coursecredits' => 'off');
7201: @toggles = ('coursecredits');
7202: my $current = {
7203: 'coursecredits' => $currusecredits,
7204: };
7205: (my $table,$itemcount) =
7206: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7207: \%choices,$itemcount,$onclick,$additional,'left');
7208: $datatable .= $table;
7209: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7210: my $display = 'none';
7211: if ($postsubmitclient) {
7212: $display = 'block';
7213: }
7214: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7215: &mt('Number of seconds submit is disabled').'<br />'.
7216: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7217: '<table><tr>';
1.257 raeburn 7218: foreach my $type (@types) {
1.306 raeburn 7219: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7220: '<input type="text" name="'.$type.'_timeout" value="'.
7221: $deftimeout{$type}.'" size="5" /></td>';
7222: }
7223: $additional .= '</tr></table></div>'."\n";
7224: %defaultchecked = ('postsubmit' => 'on');
7225: @toggles = ('postsubmit');
1.280 raeburn 7226: $current = {
7227: 'postsubmit' => $postsubmitclient,
7228: };
1.257 raeburn 7229: ($table,$itemcount) =
7230: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7231: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7232: $datatable .= $table;
1.276 raeburn 7233: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7234: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7235: $choices{'mysqltables'}.
7236: '</span></td>'.
1.306 raeburn 7237: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7238: '<table><tr>';
7239: foreach my $type (@types) {
1.306 raeburn 7240: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7241: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7242: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7243: }
7244: $datatable .= '</tr></table></td></tr>'."\n";
7245: $itemcount ++;
1.404 raeburn 7246: %defaultchecked = ('ltiauth' => 'off');
7247: @toggles = ('ltiauth');
7248: $current = {
7249: 'ltiauth' => $ltiauth,
7250: };
7251: ($table,$itemcount) =
7252: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7253: \%choices,$itemcount,undef,undef,'left');
7254: $datatable .= $table;
1.422 raeburn 7255: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7256: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7257: $choices{'domexttool'}.
7258: '</span></td>'.
7259: '<td style="text-align: right" class="LC_right_item">'.
7260: '<table><tr>';
7261: foreach my $type (@types) {
7262: $datatable .= '<td style="text-align: left">'.
7263: '<span class="LC_nobreak">'.
1.438 raeburn 7264: '<label><input type="checkbox" name="domexttool"'.
1.422 raeburn 7265: ' value="'.$type.'"'.$domexttool{$type}.' />'.
1.438 raeburn 7266: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7267: }
7268: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7269: $itemcount ++;
1.422 raeburn 7270: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7271: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7272: $choices{'exttool'}.
7273: '</span></td>'.
7274: '<td style="text-align: right" class="LC_right_item">'.
7275: '<table><tr>';
7276: foreach my $type (@types) {
7277: $datatable .= '<td style="text-align: left">'.
7278: '<span class="LC_nobreak">'.
1.438 raeburn 7279: '<label><input type="checkbox" name="exttool"'.
1.422 raeburn 7280: ' value="'.$type.'"'.$exttool{$type}.' />'.
1.438 raeburn 7281: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7282: }
7283: $datatable .= '</tr></table></td></tr>'."\n";
1.432 raeburn 7284: $itemcount ++;
7285: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7286: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7287: $choices{'crsauthor'}.
7288: '</span></td>'.
7289: '<td style="text-align: right" class="LC_right_item">'.
7290: '<table><tr>';
7291: foreach my $type (@types) {
7292: $datatable .= '<td style="text-align: left">'.
7293: '<span class="LC_nobreak">'.
1.438 raeburn 7294: '<label><input type="checkbox" name="crsauthor"'.
1.432 raeburn 7295: ' value="'.$type.'"'.$crsauthor{$type}.' />'.
1.438 raeburn 7296: &mt($type).'</label></span></td>'."\n";
7297: }
7298: $datatable .= '</tr></table></td></tr>'."\n";
7299: $itemcount ++;
7300: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7301: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7302: $choices{'crseditors'}.
7303: '</span></td>'.
7304: '<td style="text-align: right" class="LC_right_item">'.
7305: '<table><tr>';
7306: my @editors = ('edit','xml','daxe');
7307: my %editornames = &crseditor_titles();
7308: foreach my $editor (@editors) {
7309: $datatable .= '<td style="text-align: left">'.
7310: '<span class="LC_nobreak">'.
7311: '<label><input type="checkbox" name="crseditors"'.
7312: ' value="'.$editor.'"'.$crseditors{$editor}.' />'.
7313: $editornames{$editor}.'</label></span></td>'."\n";
1.432 raeburn 7314: }
7315: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7316: }
1.192 raeburn 7317: $$rowtotal += $itemcount;
1.121 raeburn 7318: return $datatable;
1.118 jms 7319: }
7320:
1.438 raeburn 7321: sub crseditor_titles {
7322: return &Apache::lonlocal::texthash(
7323: edit => 'Standard editor (Edit)',
7324: xml => 'Text editor (EditXML)',
7325: daxe => 'Daxe editor (Daxe)',
7326: );
7327: }
7328:
1.429 raeburn 7329: sub print_authordefaults {
7330: my ($position,$dom,$settings,$rowtotal) = @_;
7331: my ($css_class,$datatable,%checkedon,%checkedoff);
7332: my $itemcount = 1;
7333: my %titles = &authordefaults_titles();
7334: if ($position eq 'top') {
7335: my %defaultchecked = (
7336: 'nocodemirror' => 'off',
1.437 raeburn 7337: 'daxecollapse' => 'off',
1.429 raeburn 7338: 'domcoordacc' => 'on',
7339: );
1.437 raeburn 7340: my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
1.429 raeburn 7341: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
7342: \%titles,$itemcount);
7343: my %staticdefaults = (
7344: 'copyright' => 'default',
7345: 'sourceavail' => 'closed',
7346: );
7347: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7348: my %currrights;
7349: foreach my $item ('copyright','sourceavail') {
7350: $currrights{$item} = $staticdefaults{$item};
7351: if (ref($settings) eq 'HASH') {
7352: if (exists($settings->{$item})) {
7353: $currrights{$item} = $settings->{$item};
7354: }
7355: }
7356: }
7357: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7358: '<span class="LC_nobreak">'.$titles{'copyright'}.
7359: '</span></td><td class="LC_right_item">'.
7360: &selectbox('copyright',$currrights{'copyright'},'',
7361: \&Apache::loncommon::copyrightdescription,
7362: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
7363: '</td></tr>'."\n";
7364: $itemcount ++;
7365: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7366: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7367: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
7368: '</span></td><td class="LC_right_item">'.
7369: &selectbox('sourceavail',$currrights{'sourceavail'},'',
7370: \&Apache::loncommon::source_copyrightdescription,
7371: (&Apache::loncommon::source_copyrightids)).
7372: '</td></tr>'."\n";
7373: } else {
7374: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7375: my $curreditors;
7376: my %staticdefaults = (
7377: editors => ['edit','xml'],
7378: authorquota => 500,
7379: webdav => 0,
7380: );
7381: my $curreditors = $staticdefaults{'editors'};
7382: if ((ref($settings) eq 'HASH') &&
7383: (ref($settings->{'editors'}) eq 'ARRAY')) {
7384: $curreditors = $settings->{'editors'};
7385: } else {
7386: $curreditors = $staticdefaults{'editors'};
7387: }
7388: my @editors = ('edit','xml','daxe');
7389: $datatable = '<tr'.$css_class.'>'."\n".
7390: '<td>'.$titles{'editors'}.'</td>'."\n".
7391: '<td class="LC_left_item">'."\n".
7392: '<span class="LC_nobreak">';
7393: foreach my $editor (@editors) {
7394: my $checked;
7395: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
7396: $checked = ' checked="checked"';
7397: }
7398: $datatable .= '<label>'.
7399: '<input type="checkbox" name="author_editors" '.
7400: $checked.' value="'.$editor.'" '.
7401: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
7402: $titles{$editor}.'</label> ';
7403: }
7404: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
7405: $itemcount ++;
7406: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7407: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7408: my @insttypes;
7409: if (ref($types) eq 'ARRAY') {
7410: @insttypes = @{$types};
7411: }
7412: my $typecount = 0;
7413: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
7414: my @items = ('webdav','authorquota');
7415: my %quotas;
7416: if (ref($domconf{'quotas'}) eq 'HASH') {
7417: %quotas = %{$domconf{'quotas'}};
7418: foreach my $item (@items) {
7419: if (ref($quotas{$item}) eq 'HASH') {
7420: foreach my $type (@insttypes,'default') {
7421: if ($item eq 'authorquota') {
7422: if ($quotas{$item}{$type} !~ /^\d+$/) {
7423: $quotas{$item}{$type} = $staticdefaults{$item};
7424: }
7425: } elsif ($item eq 'webdav') {
7426: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
7427: $quotas{$item}{$type} = $staticdefaults{$item};
7428: }
7429: }
7430: }
7431: } else {
7432: foreach my $type (@insttypes,'default') {
7433: $quotas{$item}{$type} = $staticdefaults{$item};
7434: }
7435: }
7436: }
7437: } else {
7438: foreach my $item (@items) {
7439: foreach my $type (@insttypes,'default') {
7440: $quotas{$item}{$type} = $staticdefaults{$item};
7441: }
7442: }
7443: }
7444: if (ref($usertypes) eq 'HASH') {
7445: my $numinrow = 4;
7446: my $onclick = '';
7447: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7448: $numinrow,$othertitle,'authorquota',
7449: \$itemcount,$onclick);
7450: $itemcount ++;
7451: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7452: $numinrow,$othertitle,'webdav',
7453: \$itemcount);
7454: $itemcount ++;
7455: }
7456: my $checkedno = ' checked="checked"';
7457: my ($checkedon,$checkedoff);
7458: if (ref($quotas{'webdav'}) eq 'HASH') {
1.436 raeburn 7459: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
1.429 raeburn 7460: if ($quotas{'webdav'}{'_LC_adv'}) {
7461: $checkedon = $checkedno;
7462: } else {
7463: $checkedoff = $checkedno;
7464: }
7465: undef($checkedno);
7466: }
7467: }
7468: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7469: $datatable .= '<tr'.$css_class.'>'.
7470: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
7471: $titles{'webdav_LC_adv_over'}.
7472: '</td>'.
7473: '<td class="LC_left_item">';
7474: foreach my $option ('none','off','on') {
7475: my ($text,$val,$checked);
7476: if ($option eq 'none') {
7477: $text = $titles{'none'};
7478: $val = '';
7479: $checked = $checkedno;
7480: } elsif ($option eq 'off') {
7481: $text = $titles{'overoff'};
7482: $val = 0;
7483: $checked = $checkedoff;
7484: } elsif ($option eq 'on') {
7485: $text = $titles{'overon'};
7486: $val = 1;
7487: $checked = $checkedon;
1.436 raeburn 7488: }
1.429 raeburn 7489: $datatable .= '<span class="LC_nobreak"><label>'.
7490: '<input type="radio" name="webdav_LC_adv"'.
7491: ' value="'.$val.'"'.$checked.' />'.
7492: $text.'</label></span> ';
7493: }
7494: $datatable .= '</td></tr>';
7495: $itemcount ++;
1.440 raeburn 7496: my %defchecked = (
7497: 'archive' => 'off',
7498: );
7499: my @toggles = ('archive');
7500: (my $archive,$itemcount) = &radiobutton_prefs($settings,['archive'],
7501: {'archive' => 'off'},
7502: \%titles,$itemcount);
7503: $datatable .= $archive."\n";
7504: $itemcount ++;
1.429 raeburn 7505: }
7506: $$rowtotal += $itemcount;
7507: return $datatable;
7508: }
7509:
7510: sub authordefaults_titles {
7511: return &Apache::lonlocal::texthash(
7512: copyright => 'Copyright/Distribution',
7513: sourceavail => ' Source Available',
7514: editors => 'Available Editors',
7515: webdav => 'WebDAV',
7516: authorquota => 'Authoring Space quotas (MB)',
7517: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
1.437 raeburn 7518: daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
1.429 raeburn 7519: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
7520: edit => 'Standard editor (Edit)',
7521: xml => 'Text editor (EditXML)',
7522: daxe => 'Daxe editor (Daxe)',
7523: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
7524: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
7525: none => 'No override set',
7526: overon => 'Override -- webDAV on',
1.436 raeburn 7527: overoff => 'Override -- webDAV off',
1.440 raeburn 7528: archive => 'Authors can download tar.gz file of Authoring Space',
1.429 raeburn 7529: );
7530: }
7531:
7532: sub selectbox {
7533: my ($name,$value,$readonly,$functionref,@idlist)=@_;
7534: my $selout = '<select name="'.$name.'">';
7535: foreach my $id (@idlist) {
7536: $selout.='<option value="'.$id.'"';
7537: if ($id eq $value) {
7538: $selout.=' selected="selected"';
7539: }
7540: if ($readonly) {
7541: $selout .= ' disabled="disabled"';
7542: }
7543: $selout.='>'.&{$functionref}($id).'</option>';
7544: }
7545: $selout.='</select>';
7546: return $selout;
7547: }
7548:
1.231 raeburn 7549: sub print_selfenrollment {
7550: my ($position,$dom,$settings,$rowtotal) = @_;
7551: my ($css_class,$datatable);
7552: my $itemcount = 1;
1.271 raeburn 7553: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7554: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7555: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7556: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7557: my @rows;
7558: my $key;
7559: if ($position eq 'top') {
7560: $key = 'admin';
7561: if (ref($rowsref) eq 'ARRAY') {
7562: @rows = @{$rowsref};
7563: }
7564: } elsif ($position eq 'middle') {
7565: $key = 'default';
7566: @rows = ('types','registered','approval','limit');
7567: }
7568: foreach my $row (@rows) {
7569: if (defined($titlesref->{$row})) {
7570: $itemcount ++;
7571: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7572: $datatable .= '<tr'.$css_class.'>'.
7573: '<td>'.$titlesref->{$row}.'</td>'.
7574: '<td class="LC_left_item">'.
7575: '<table><tr>';
7576: my (%current,%currentcap);
7577: if (ref($settings) eq 'HASH') {
7578: if (ref($settings->{$key}) eq 'HASH') {
7579: foreach my $type (@types) {
7580: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7581: $current{$type} = $settings->{$key}->{$type}->{$row};
7582: }
7583: if (($row eq 'limit') && ($key eq 'default')) {
7584: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7585: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7586: }
7587: }
7588: }
7589: }
7590: }
7591: my %roles = (
7592: '0' => &Apache::lonnet::plaintext('dc'),
7593: );
7594:
7595: foreach my $type (@types) {
7596: unless (($row eq 'registered') && ($key eq 'default')) {
7597: $datatable .= '<th>'.&mt($type).'</th>';
7598: }
7599: }
7600: unless (($row eq 'registered') && ($key eq 'default')) {
7601: $datatable .= '</tr><tr>';
7602: }
7603: foreach my $type (@types) {
7604: if ($type eq 'community') {
7605: $roles{'1'} = &mt('Community personnel');
7606: } else {
7607: $roles{'1'} = &mt('Course personnel');
7608: }
7609: $datatable .= '<td style="vertical-align: top">';
7610: if ($position eq 'top') {
7611: my %checked;
7612: if ($current{$type} eq '0') {
7613: $checked{'0'} = ' checked="checked"';
7614: } else {
7615: $checked{'1'} = ' checked="checked"';
7616: }
7617: foreach my $role ('1','0') {
7618: $datatable .= '<span class="LC_nobreak"><label>'.
7619: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7620: 'value="'.$role.'"'.$checked{$role}.' />'.
7621: $roles{$role}.'</label></span> ';
7622: }
7623: } else {
7624: if ($row eq 'types') {
7625: my %checked;
7626: if ($current{$type} =~ /^(all|dom)$/) {
7627: $checked{$1} = ' checked="checked"';
7628: } else {
7629: $checked{''} = ' checked="checked"';
7630: }
7631: foreach my $val ('','dom','all') {
7632: $datatable .= '<span class="LC_nobreak"><label>'.
7633: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7634: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7635: }
7636: } elsif ($row eq 'registered') {
7637: my %checked;
7638: if ($current{$type} eq '1') {
7639: $checked{'1'} = ' checked="checked"';
7640: } else {
7641: $checked{'0'} = ' checked="checked"';
7642: }
7643: foreach my $val ('0','1') {
7644: $datatable .= '<span class="LC_nobreak"><label>'.
7645: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7646: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7647: }
7648: } elsif ($row eq 'approval') {
7649: my %checked;
7650: if ($current{$type} =~ /^([12])$/) {
7651: $checked{$1} = ' checked="checked"';
7652: } else {
7653: $checked{'0'} = ' checked="checked"';
7654: }
7655: for my $val (0..2) {
7656: $datatable .= '<span class="LC_nobreak"><label>'.
7657: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7658: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7659: }
7660: } elsif ($row eq 'limit') {
7661: my %checked;
7662: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7663: $checked{$1} = ' checked="checked"';
7664: } else {
7665: $checked{'none'} = ' checked="checked"';
7666: }
7667: my $cap;
7668: if ($currentcap{$type} =~ /^\d+$/) {
7669: $cap = $currentcap{$type};
7670: }
7671: foreach my $val ('none','allstudents','selfenrolled') {
7672: $datatable .= '<span class="LC_nobreak"><label>'.
7673: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7674: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7675: }
7676: $datatable .= '<br />'.
7677: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7678: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7679: '</span>';
7680: }
7681: }
7682: $datatable .= '</td>';
7683: }
7684: $datatable .= '</tr>';
7685: }
7686: $datatable .= '</table></td></tr>';
7687: }
7688: } elsif ($position eq 'bottom') {
1.235 raeburn 7689: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7690: }
7691: $$rowtotal += $itemcount;
7692: return $datatable;
7693: }
7694:
7695: sub print_validation_rows {
7696: my ($caller,$dom,$settings,$rowtotal) = @_;
7697: my ($itemsref,$namesref,$fieldsref);
7698: if ($caller eq 'selfenroll') {
7699: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7700: } elsif ($caller eq 'requestcourses') {
7701: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7702: }
7703: my %currvalidation;
7704: if (ref($settings) eq 'HASH') {
7705: if (ref($settings->{'validation'}) eq 'HASH') {
7706: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7707: }
1.235 raeburn 7708: }
7709: my $datatable;
7710: my $itemcount = 0;
7711: foreach my $item (@{$itemsref}) {
7712: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7713: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7714: $namesref->{$item}.
7715: '</span></td>'.
7716: '<td class="LC_left_item">';
7717: if (($item eq 'url') || ($item eq 'button')) {
7718: $datatable .= '<span class="LC_nobreak">'.
7719: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7720: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7721: } elsif ($item eq 'fields') {
7722: my @currfields;
7723: if (ref($currvalidation{$item}) eq 'ARRAY') {
7724: @currfields = @{$currvalidation{$item}};
7725: }
7726: foreach my $field (@{$fieldsref}) {
7727: my $check = '';
7728: if (grep(/^\Q$field\E$/,@currfields)) {
7729: $check = ' checked="checked"';
7730: }
7731: $datatable .= '<span class="LC_nobreak"><label>'.
7732: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7733: ' value="'.$field.'"'.$check.' />'.$field.
7734: '</label></span> ';
7735: }
7736: } elsif ($item eq 'markup') {
1.334 raeburn 7737: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7738: $currvalidation{$item}.
1.231 raeburn 7739: '</textarea>';
1.235 raeburn 7740: }
7741: $datatable .= '</td></tr>'."\n";
7742: if (ref($rowtotal)) {
1.231 raeburn 7743: $itemcount ++;
7744: }
7745: }
1.235 raeburn 7746: if ($caller eq 'requestcourses') {
7747: my %currhash;
1.248 raeburn 7748: if (ref($settings) eq 'HASH') {
7749: if (ref($settings->{'validation'}) eq 'HASH') {
7750: if ($settings->{'validation'}{'dc'} ne '') {
7751: $currhash{$settings->{'validation'}{'dc'}} = 1;
7752: }
1.235 raeburn 7753: }
7754: }
7755: my $numinrow = 2;
7756: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7757: 'validationdc',%currhash);
1.247 raeburn 7758: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7759: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7760: if ($numdc > 1) {
1.247 raeburn 7761: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7762: } else {
1.247 raeburn 7763: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7764: }
1.247 raeburn 7765: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7766: $itemcount ++;
7767: }
7768: if (ref($rowtotal)) {
7769: $$rowtotal += $itemcount;
7770: }
1.231 raeburn 7771: return $datatable;
7772: }
7773:
1.357 raeburn 7774: sub print_privacy {
7775: my ($position,$dom,$settings,$rowtotal) = @_;
7776: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7777: my $itemcount = 0;
1.417 raeburn 7778: if ($position eq 'top') {
7779: $numinrow = 2;
7780: } else {
1.357 raeburn 7781: @items = ('domain','author','course','community');
7782: %names = &Apache::lonlocal::texthash (
7783: domain => 'Assigned domain role(s)',
7784: author => 'Assigned co-author role(s)',
7785: course => 'Assigned course role(s)',
1.416 raeburn 7786: community => 'Assigned community role(s)',
1.357 raeburn 7787: );
7788: $numinrow = 4;
7789: ($othertitle,$usertypes,$types) =
7790: &Apache::loncommon::sorted_inst_types($dom);
7791: }
7792: if (($position eq 'top') || ($position eq 'middle')) {
7793: my (%by_ip,%by_location,@intdoms,@instdoms);
7794: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7795: if ($position eq 'top') {
7796: my %curr;
7797: my @options = ('none','user','domain','auto');
7798: my %titles = &Apache::lonlocal::texthash (
7799: none => 'Not allowed',
7800: user => 'User authorizes',
7801: domain => 'DC authorizes',
7802: auto => 'Unrestricted',
7803: instdom => 'Other domain shares institution/provider',
7804: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7805: notify => 'Notify when role needs authorization',
1.357 raeburn 7806: );
7807: my %names = &Apache::lonlocal::texthash (
7808: domain => 'Domain role',
7809: author => 'Co-author role',
7810: course => 'Course role',
7811: community => 'Community role',
7812: );
7813: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7814: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7815: foreach my $domtype ('instdom','extdom') {
7816: my (%checked,$skip);
7817: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7818: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7819: '<td class="LC_left_item">';
7820: if ($domtype eq 'instdom') {
7821: unless (@instdoms > 1) {
7822: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7823: $skip = 1;
7824: }
7825: } elsif ($domtype eq 'extdom') {
7826: if (keys(%by_location) == 0) {
7827: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7828: $skip = 1;
7829: }
7830: }
7831: unless ($skip) {
7832: foreach my $roletype ('domain','author','course','community') {
7833: $checked{'auto'} = ' checked="checked"';
7834: if (ref($settings) eq 'HASH') {
7835: if (ref($settings->{approval}) eq 'HASH') {
7836: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7837: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7838: $checked{$1} = ' checked="checked"';
7839: $checked{'auto'} = '';
7840: }
7841: }
7842: }
7843: }
7844: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7845: foreach my $option (@options) {
7846: $datatable .= '<span class="LC_nobreak"><label>'.
7847: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7848: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7849: '</label></span> ';
7850: }
7851: $datatable .= '</fieldset>';
7852: }
7853: }
7854: $datatable .= '</td></tr>';
7855: $itemcount ++;
7856: }
1.417 raeburn 7857: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7858: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7859: '<td class="LC_left_item">';
7860: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7861: my %curr;
7862: if (ref($settings) eq 'HASH') {
7863: if ($settings->{'notify'} ne '') {
7864: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7865: }
7866: }
7867: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7868: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7869: 'privacy_notify',%curr);
7870: if ($numdc > 0) {
7871: $datatable .= $table;
7872: } else {
7873: $datatable .= &mt('There are no active Domain Coordinators');
7874: }
7875: } else {
7876: $datatable .= &mt('Nothing to set here, as there are no other domains');
7877: }
7878: $datatable .='</td></tr>';
1.357 raeburn 7879: } elsif ($position eq 'middle') {
7880: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7881: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7882: foreach my $item (@{$types}) {
7883: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7884: $numinrow,$itemcount,'','','','','',
7885: '',$usertypes->{$item});
7886: $itemcount ++;
7887: }
7888: }
7889: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7890: $numinrow,$itemcount,'','','','','',
7891: '',$othertitle);
7892: $itemcount ++;
7893: } else {
1.360 raeburn 7894: my (@insttypes,%insttitles);
7895: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7896: @insttypes = @{$types};
7897: %insttitles = %{$usertypes};
7898: }
7899: foreach my $item (@insttypes,'default') {
7900: my $title;
7901: if ($item eq 'default') {
7902: $title = $othertitle;
7903: } else {
7904: $title = $insttitles{$item};
7905: }
7906: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7907: $datatable .= '<tr'.$css_class.'>'.
7908: '<td class="LC_left_item">'.$title.'</td>'.
7909: '<td class="LC_left_item">'.
7910: &mt('Nothing to set here, as there are no other domains').
7911: '</td></tr>';
7912: $itemcount ++;
7913: }
1.357 raeburn 7914: }
7915: }
7916: } else {
7917: my $prefix;
7918: if ($position eq 'lower') {
7919: $prefix = 'priv';
7920: } else {
7921: $prefix = 'unpriv';
7922: }
7923: foreach my $item (@items) {
7924: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7925: $numinrow,$itemcount,'','','','','',
7926: '',$names{$item});
7927: $itemcount ++;
7928: }
7929: }
7930: if (ref($rowtotal)) {
7931: $$rowtotal += $itemcount;
7932: }
7933: return $datatable;
7934: }
7935:
1.354 raeburn 7936: sub print_passwords {
7937: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7938: my ($datatable,$css_class);
7939: my $itemcount = 0;
7940: my %titles = &Apache::lonlocal::texthash (
7941: captcha => '"Forgot Password" CAPTCHA validation',
7942: link => 'Reset link expiration (hours)',
7943: case => 'Case-sensitive usernames/e-mail',
7944: prelink => 'Information required (form 1)',
7945: postlink => 'Information required (form 2)',
7946: emailsrc => 'LON-CAPA e-mail address type(s)',
7947: customtext => 'Domain specific text (HTML)',
7948: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7949: intauth_check => 'Check bcrypt cost if authenticated',
7950: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7951: permanent => 'Permanent e-mail address',
7952: critical => 'Critical notification address',
7953: notify => 'Notification address',
7954: min => 'Minimum password length',
7955: max => 'Maximum password length',
7956: chars => 'Required characters',
7957: expire => 'Password expiration (days)',
1.356 raeburn 7958: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7959: );
7960: if ($position eq 'top') {
7961: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7962: my $shownlinklife = 2;
7963: my $prelink = 'both';
7964: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7965: if (ref($settings) eq 'HASH') {
7966: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7967: $shownlinklife = $settings->{resetlink};
7968: }
7969: if (ref($settings->{resetcase}) eq 'ARRAY') {
7970: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7971: }
7972: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7973: $prelink = $settings->{resetprelink};
7974: }
7975: if (ref($settings->{resetpostlink}) eq 'HASH') {
7976: %postlink = %{$settings->{resetpostlink}};
7977: }
7978: if (ref($settings->{resetemail}) eq 'ARRAY') {
7979: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7980: }
7981: if ($settings->{resetremove}) {
7982: $nostdtext = 1;
7983: }
7984: if ($settings->{resetcustom}) {
7985: $customurl = $settings->{resetcustom};
7986: }
7987: } else {
7988: if (ref($types) eq 'ARRAY') {
7989: foreach my $item (@{$types}) {
7990: $casesens{$item} = 1;
7991: $postlink{$item} = ['username','email'];
7992: }
7993: }
7994: $casesens{'default'} = 1;
7995: $postlink{'default'} = ['username','email'];
7996: $prelink = 'both';
7997: %emailsrc = (
7998: permanent => 1,
7999: critical => 1,
8000: notify => 1,
8001: );
8002: }
8003: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
8004: $itemcount ++;
8005: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8006: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
8007: '<td class="LC_left_item">'.
8008: '<input type="textbox" value="'.$shownlinklife.'" '.
8009: 'name="passwords_link" size="3" /></td></tr>';
8010: $itemcount ++;
8011: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8012: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
8013: '<td class="LC_left_item">';
8014: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8015: foreach my $item (@{$types}) {
8016: my $checkedcase;
8017: if ($casesens{$item}) {
8018: $checkedcase = ' checked="checked"';
8019: }
8020: $datatable .= '<span class="LC_nobreak"><label>'.
8021: '<input type="checkbox" name="passwords_case_sensitive" value="'.
8022: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 8023: '</span> ';
1.354 raeburn 8024: }
8025: }
8026: my $checkedcase;
8027: if ($casesens{'default'}) {
8028: $checkedcase = ' checked="checked"';
8029: }
8030: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8031: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
8032: $othertitle.'</label></span></td>';
8033: $itemcount ++;
8034: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8035: my %checkedpre = (
8036: both => ' checked="checked"',
8037: either => '',
8038: );
8039: if ($prelink eq 'either') {
8040: $checkedpre{either} = ' checked="checked"';
8041: $checkedpre{both} = '';
8042: }
8043: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
8044: '<td class="LC_left_item"><span class="LC_nobreak">'.
8045: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
8046: &mt('Both username and e-mail address').'</label></span> '.
8047: '<span class="LC_nobreak"><label>'.
8048: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
8049: &mt('Either username or e-mail address').'</label></span></td></tr>';
8050: $itemcount ++;
8051: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8052: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
8053: '<td class="LC_left_item">';
8054: my %postlinked;
8055: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8056: foreach my $item (@{$types}) {
8057: undef(%postlinked);
8058: $datatable .= '<fieldset style="display: inline-block;">'.
8059: '<legend>'.$usertypes->{$item}.'</legend>';
8060: if (ref($postlink{$item}) eq 'ARRAY') {
8061: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
8062: }
8063: foreach my $field ('email','username') {
8064: my $checked;
8065: if ($postlinked{$field}) {
8066: $checked = ' checked="checked"';
8067: }
8068: $datatable .= '<span class="LC_nobreak"><label>'.
8069: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
8070: $field.'"'.$checked.' />'.$field.'</label>'.
8071: '<span> ';
8072: }
8073: $datatable .= '</fieldset>';
8074: }
8075: }
8076: if (ref($postlink{'default'}) eq 'ARRAY') {
8077: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
8078: }
8079: $datatable .= '<fieldset style="display: inline-block;">'.
8080: '<legend>'.$othertitle.'</legend>';
8081: foreach my $field ('email','username') {
8082: my $checked;
8083: if ($postlinked{$field}) {
8084: $checked = ' checked="checked"';
8085: }
8086: $datatable .= '<span class="LC_nobreak"><label>'.
8087: '<input type="checkbox" name="passwords_postlink_default" value="'.
8088: $field.'"'.$checked.' />'.$field.'</label>'.
8089: '<span> ';
8090: }
8091: $datatable .= '</fieldset></td></tr>';
8092: $itemcount ++;
8093: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8094: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
8095: '<td class="LC_left_item">';
8096: foreach my $type ('permanent','critical','notify') {
8097: my $checkedemail;
8098: if ($emailsrc{$type}) {
8099: $checkedemail = ' checked="checked"';
8100: }
8101: $datatable .= '<span class="LC_nobreak"><label>'.
8102: '<input type="checkbox" name="passwords_emailsrc" value="'.
8103: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8104: '<span> ';
8105: }
8106: $datatable .= '</td></tr>';
8107: $itemcount ++;
8108: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8109: my $switchserver = &check_switchserver($dom,$confname);
8110: my ($showstd,$noshowstd);
8111: if ($nostdtext) {
8112: $noshowstd = ' checked="checked"';
8113: } else {
8114: $showstd = ' checked="checked"';
8115: }
8116: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8117: '<td class="LC_left_item"><span class="LC_nobreak">'.
8118: &mt('Retain standard text:').
8119: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8120: &mt('Yes').'</label>'.' '.
8121: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8122: &mt('No').'</label></span><br />'.
8123: '<span class="LC_fontsize_small">'.
8124: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8125: &mt('Include custom text:');
8126: if ($customurl) {
1.369 raeburn 8127: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8128: undef,undef,undef,undef,'background-color:#ffffff');
8129: $datatable .= '<span class="LC_nobreak"> '.$link.
8130: '<label><input type="checkbox" name="passwords_custom_del"'.
8131: ' value="1" />'.&mt('Delete?').'</label></span>'.
8132: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8133: }
8134: if ($switchserver) {
8135: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8136: } else {
8137: $datatable .='<span class="LC_nobreak"> '.
8138: '<input type="file" name="passwords_customfile" /></span>';
8139: }
8140: $datatable .= '</td></tr>';
8141: } elsif ($position eq 'middle') {
8142: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8143: my @items = ('intauth_cost','intauth_check','intauth_switch');
8144: my %defaults;
8145: if (ref($domconf{'defaults'}) eq 'HASH') {
8146: %defaults = %{$domconf{'defaults'}};
8147: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8148: $defaults{'intauth_cost'} = 10;
8149: }
8150: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8151: $defaults{'intauth_check'} = 0;
8152: }
8153: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8154: $defaults{'intauth_switch'} = 0;
8155: }
8156: } else {
8157: %defaults = (
8158: 'intauth_cost' => 10,
8159: 'intauth_check' => 0,
8160: 'intauth_switch' => 0,
8161: );
8162: }
8163: foreach my $item (@items) {
8164: if ($itemcount%2) {
8165: $css_class = '';
8166: } else {
8167: $css_class = ' class="LC_odd_row" ';
8168: }
8169: $datatable .= '<tr'.$css_class.'>'.
8170: '<td><span class="LC_nobreak">'.$titles{$item}.
8171: '</span></td><td class="LC_left_item" colspan="3">';
8172: if ($item eq 'intauth_switch') {
8173: my @options = (0,1,2);
8174: my %optiondesc = &Apache::lonlocal::texthash (
8175: 0 => 'No',
8176: 1 => 'Yes',
8177: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8178: );
8179: $datatable .= '<table width="100%">';
8180: foreach my $option (@options) {
8181: my $checked = ' ';
8182: if ($defaults{$item} eq $option) {
8183: $checked = ' checked="checked"';
8184: }
8185: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8186: '<label><input type="radio" name="'.$item.
8187: '" value="'.$option.'"'.$checked.' />'.
8188: $optiondesc{$option}.'</label></span></td></tr>';
8189: }
8190: $datatable .= '</table>';
8191: } elsif ($item eq 'intauth_check') {
8192: my @options = (0,1,2);
8193: my %optiondesc = &Apache::lonlocal::texthash (
8194: 0 => 'No',
8195: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8196: 2 => 'Yes, disallow login if stored cost is less than domain default',
8197: );
8198: $datatable .= '<table width="100%">';
8199: foreach my $option (@options) {
8200: my $checked = ' ';
8201: my $onclick;
8202: if ($defaults{$item} eq $option) {
8203: $checked = ' checked="checked"';
8204: }
8205: if ($option == 2) {
8206: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8207: }
8208: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8209: '<label><input type="radio" name="'.$item.
8210: '" value="'.$option.'"'.$checked.$onclick.' />'.
8211: $optiondesc{$option}.'</label></span></td></tr>';
8212: }
8213: $datatable .= '</table>';
8214: } else {
8215: $datatable .= '<input type="text" name="'.$item.'" value="'.
8216: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8217: }
8218: $datatable .= '</td></tr>';
8219: $itemcount ++;
8220: }
8221: } elsif ($position eq 'lower') {
1.405 raeburn 8222: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8223: } else {
1.359 raeburn 8224: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8225: my %ownerchg = (
8226: by => {},
8227: for => {},
8228: );
8229: my %ownertitles = &Apache::lonlocal::texthash (
8230: by => 'Course owner status(es) allowed',
8231: for => 'Student status(es) allowed',
8232: );
1.354 raeburn 8233: if (ref($settings) eq 'HASH') {
1.359 raeburn 8234: if (ref($settings->{crsownerchg}) eq 'HASH') {
8235: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8236: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8237: }
8238: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8239: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8240: }
1.354 raeburn 8241: }
8242: }
8243: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8244: $datatable .= '<tr '.$css_class.'>'.
8245: '<td>'.
8246: &mt('Requirements').'<ul>'.
1.359 raeburn 8247: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8248: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8249: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8250: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8251: '</ul>'.
8252: '</td>'.
1.359 raeburn 8253: '<td class="LC_left_item">';
8254: foreach my $item ('by','for') {
8255: $datatable .= '<fieldset style="display: inline-block;">'.
8256: '<legend>'.$ownertitles{$item}.'</legend>';
8257: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8258: foreach my $type (@{$types}) {
8259: my $checked;
8260: if ($ownerchg{$item}{$type}) {
8261: $checked = ' checked="checked"';
8262: }
8263: $datatable .= '<span class="LC_nobreak"><label>'.
8264: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8265: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8266: '</span> ';
1.359 raeburn 8267: }
8268: }
8269: my $checked;
8270: if ($ownerchg{$item}{'default'}) {
8271: $checked = ' checked="checked"';
8272: }
8273: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8274: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8275: $othertitle.'</label></span></fieldset>';
8276: }
8277: $datatable .= '</td></tr>';
1.354 raeburn 8278: }
8279: return $datatable;
8280: }
8281:
1.405 raeburn 8282: sub password_rules {
8283: my ($prefix,$itemcountref,$settings) = @_;
8284: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8285: my %titles;
8286: if ($prefix eq 'passwords') {
8287: %titles = &Apache::lonlocal::texthash (
8288: min => 'Minimum password length',
8289: max => 'Maximum password length',
8290: chars => 'Required characters',
8291: );
1.421 raeburn 8292: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8293: %titles = &Apache::lonlocal::texthash (
8294: min => 'Minimum secret length',
8295: max => 'Maximum secret length',
8296: chars => 'Required characters',
8297: );
8298: }
8299: $min = $Apache::lonnet::passwdmin;
8300: my $datatable;
8301: my $itemcount;
8302: if (ref($itemcountref)) {
8303: $itemcount = $$itemcountref;
8304: }
8305: if (ref($settings) eq 'HASH') {
8306: if ($settings->{min}) {
8307: $min = $settings->{min};
8308: }
8309: if ($settings->{max}) {
8310: $max = $settings->{max};
8311: }
8312: if (ref($settings->{chars}) eq 'ARRAY') {
8313: map { $chars{$_} = 1; } (@{$settings->{chars}});
8314: }
1.425 raeburn 8315: if ($prefix eq 'passwords') {
1.405 raeburn 8316: if ($settings->{expire}) {
8317: $expire = $settings->{expire};
8318: }
8319: if ($settings->{numsaved}) {
8320: $numsaved = $settings->{numsaved};
8321: }
8322: }
8323: }
8324: my %rulenames = &Apache::lonlocal::texthash(
8325: uc => 'At least one upper case letter',
8326: lc => 'At least one lower case letter',
8327: num => 'At least one number',
8328: spec => 'At least one non-alphanumeric',
8329: );
8330: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8331: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8332: '<td class="LC_left_item"><span class="LC_nobreak">'.
8333: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8334: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8335: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8336: '</span></td></tr>';
8337: $itemcount ++;
8338: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8339: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8340: '<td class="LC_left_item"><span class="LC_nobreak">'.
8341: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8342: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8343: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8344: '</span></td></tr>';
8345: $itemcount ++;
8346: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8347: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8348: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8349: '</span></td>';
8350: my $numinrow = 2;
8351: my @possrules = ('uc','lc','num','spec');
8352: $datatable .= '<td class="LC_left_item"><table>';
8353: for (my $i=0; $i<@possrules; $i++) {
8354: my ($rem,$checked);
8355: if ($chars{$possrules[$i]}) {
8356: $checked = ' checked="checked"';
8357: }
8358: $rem = $i%($numinrow);
8359: if ($rem == 0) {
8360: if ($i > 0) {
8361: $datatable .= '</tr>';
8362: }
8363: $datatable .= '<tr>';
8364: }
8365: $datatable .= '<td><span class="LC_nobreak"><label>'.
8366: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8367: $rulenames{$possrules[$i]}.'</label></span></td>';
8368: }
8369: my $rem = @possrules%($numinrow);
8370: my $colsleft = $numinrow - $rem;
8371: if ($colsleft > 1 ) {
8372: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8373: ' </td>';
8374: } elsif ($colsleft == 1) {
8375: $datatable .= '<td class="LC_left_item"> </td>';
8376: }
8377: $datatable .='</table></td></tr>';
8378: $itemcount ++;
8379: if ($prefix eq 'passwords') {
8380: $titles{'expire'} = &mt('Password expiration (days)');
8381: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8382: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8383: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8384: '<td class="LC_left_item"><span class="LC_nobreak">'.
8385: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8386: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8387: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8388: '</span></td></tr>';
8389: $itemcount ++;
8390: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8391: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8392: '<td class="LC_left_item"><span class="LC_nobreak">'.
8393: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8394: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8395: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8396: '</span></td></tr>';
8397: $itemcount ++;
8398: }
8399: if (ref($itemcountref)) {
8400: $$itemcountref += $itemcount;
8401: }
8402: return $datatable;
8403: }
8404:
1.373 raeburn 8405: sub print_wafproxy {
8406: my ($position,$dom,$settings,$rowtotal) = @_;
8407: my $css_class;
8408: my $itemcount = 0;
8409: my $datatable;
8410: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8411: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8412: my %lt = &wafproxy_titles();
1.373 raeburn 8413: foreach my $server (sort(keys(%servers))) {
8414: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8415: next if ($serverhome eq '');
1.373 raeburn 8416: my $serverdom;
8417: if ($serverhome ne $server) {
8418: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8419: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8420: $othercontrol{$server} = $serverdom;
8421: }
1.373 raeburn 8422: } else {
8423: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8424: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8425: if ($serverdom ne $dom) {
8426: $othercontrol{$server} = $serverdom;
8427: } else {
8428: $setdom = 1;
8429: if (ref($settings) eq 'HASH') {
8430: if (ref($settings->{'alias'}) eq 'HASH') {
8431: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8432: if ($aliases{$dom} ne '') {
8433: $showdom = 1;
8434: }
1.373 raeburn 8435: }
1.388 raeburn 8436: if (ref($settings->{'saml'}) eq 'HASH') {
8437: $saml{$dom} = $settings->{'saml'};
8438: }
1.373 raeburn 8439: }
8440: }
8441: }
8442: }
1.381 raeburn 8443: if ($setdom) {
8444: %{$values{$dom}} = ();
8445: if (ref($settings) eq 'HASH') {
8446: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8447: $values{$dom}{$item} = $settings->{$item};
8448: }
8449: }
8450: }
1.373 raeburn 8451: if (keys(%othercontrol)) {
8452: %otherdoms = reverse(%othercontrol);
8453: foreach my $domain (keys(%otherdoms)) {
8454: %{$values{$domain}} = ();
8455: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8456: if (ref($config{'wafproxy'}) eq 'HASH') {
8457: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8458: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8459: $saml{$domain} = $config{'wafproxy'}{'saml'};
8460: }
1.383 raeburn 8461: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8462: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8463: }
8464: }
8465: }
8466: }
8467: if ($position eq 'top') {
8468: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8469: my %aliasinfo;
1.373 raeburn 8470: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8471: $itemcount ++;
8472: my $dom_in_effect;
8473: my $aliasrows = '<tr>'.
1.383 raeburn 8474: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.433 raeburn 8475: &mt('Hostname').': '.
8476: '<span class="LC_nobreak LC_cusr_emph">'.
8477: &Apache::lonnet::hostname($server).
8478: '</span></td><td> </td>';
1.373 raeburn 8479: if ($othercontrol{$server}) {
1.381 raeburn 8480: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8481: my ($current,$forsaml);
1.383 raeburn 8482: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8483: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8484: }
1.388 raeburn 8485: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8486: if ($saml{$dom_in_effect}{$server}) {
8487: $forsaml = 1;
8488: }
8489: }
1.383 raeburn 8490: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8491: &mt('Alias').': ';
1.373 raeburn 8492: if ($current) {
1.381 raeburn 8493: $aliasrows .= $current;
1.388 raeburn 8494: if ($forsaml) {
1.396 raeburn 8495: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8496: }
1.373 raeburn 8497: } else {
1.383 raeburn 8498: $aliasrows .= &mt('None');
1.373 raeburn 8499: }
1.383 raeburn 8500: $aliasrows .= ' <span class="LC_small">('.
8501: &mt('controlled by domain: [_1]',
8502: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8503: } else {
1.381 raeburn 8504: $dom_in_effect = $dom;
1.388 raeburn 8505: my ($current,$samlon,$samloff);
8506: $samloff = ' checked="checked"';
1.373 raeburn 8507: if (ref($aliases{$dom}) eq 'HASH') {
8508: if ($aliases{$dom}{$server}) {
8509: $current = $aliases{$dom}{$server};
8510: }
8511: }
1.388 raeburn 8512: if (ref($saml{$dom}) eq 'HASH') {
8513: if ($saml{$dom}{$server}) {
8514: $samlon = $samloff;
8515: undef($samloff);
8516: }
8517: }
1.383 raeburn 8518: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8519: &mt('Alias').': '.
1.381 raeburn 8520: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8521: 'value="'.$current.'" size="30" />'.
8522: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8523: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8524: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8525: &mt('No').'</label> <label>'.
1.388 raeburn 8526: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8527: &mt('Yes').'</label></span>'.
1.425 raeburn 8528: '</td>';
1.381 raeburn 8529: }
8530: $aliasrows .= '</tr>';
8531: $aliasinfo{$dom_in_effect} .= $aliasrows;
8532: }
8533: if ($aliasinfo{$dom}) {
8534: my ($onclick,$wafon,$wafoff,$showtable);
8535: $onclick = ' onclick="javascript:toggleWAF();"';
8536: $wafoff = ' checked="checked"';
8537: $showtable = ' style="display:none";';
8538: if ($showdom) {
8539: $wafon = $wafoff;
8540: $wafoff = '';
8541: $showtable = ' style="display:inline;"';
8542: }
8543: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8544: $datatable = '<tr'.$css_class.'>'.
8545: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8546: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8547: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8548: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8549: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8550: &mt('No').'</label></span></td>'.
8551: '<td class="LC_left_item">'.
8552: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8553: '</table></td></tr>';
8554: $itemcount++;
8555: }
1.383 raeburn 8556: if (keys(%otherdoms)) {
8557: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8558: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8559: $datatable .= '<tr'.$css_class.'>'.
8560: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8561: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8562: '</table></td></tr>';
1.381 raeburn 8563: $itemcount++;
1.373 raeburn 8564: }
8565: }
8566: } else {
1.383 raeburn 8567: my %ip_methods = &remoteip_methods();
1.373 raeburn 8568: if ($setdom) {
8569: $itemcount ++;
8570: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8571: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8572: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8573: $wafstyle = ' style="display:none;"';
8574: $nowafstyle = ' style="display:table-row;"';
8575: $currwafdisplay = ' style="display: none"';
8576: $wafrangestyle = ' style="display: none"';
8577: $curr_remotip = 'n';
1.382 raeburn 8578: $ssltossl = ' checked="checked"';
1.381 raeburn 8579: if ($showdom) {
8580: $wafstyle = ' style="display:table-row;"';
8581: $nowafstyle = ' style="display:none;"';
8582: if (keys(%{$values{$dom}})) {
8583: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8584: $curr_remotip = $values{$dom}{remoteip};
8585: }
8586: if ($curr_remotip eq 'h') {
8587: $currwafdisplay = ' style="display:table-row"';
8588: $wafrangestyle = ' style="display:inline-block;"';
8589: }
1.382 raeburn 8590: if ($values{$dom}{'sslopt'}) {
8591: $alltossl = ' checked="checked"';
8592: $ssltossl = '';
8593: }
1.381 raeburn 8594: }
8595: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8596: $vpndircheck = ' checked="checked"';
8597: $currwafvpn = ' style="display:table-row;"';
8598: $wafrangestyle = ' style="display:inline-block;"';
8599: } else {
8600: $vpnaliascheck = ' checked="checked"';
8601: $currwafvpn = ' style="display:none;"';
8602: }
8603: }
8604: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8605: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8606: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8607: '</tr>'.
8608: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8609: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8610: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8611: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8612: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8613: '<td class="LC_left_item"><table>'.
8614: '<tr>'.
8615: '<td valign="top">'.$lt{'remoteip'}.': '.
8616: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8617: foreach my $option ('m','h','n') {
8618: my $sel;
8619: if ($option eq $curr_remotip) {
8620: $sel = ' selected="selected"';
8621: }
8622: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8623: $ip_methods{$option}.'</option>';
8624: }
8625: $datatable .= '</select></td></tr>'."\n".
8626: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8627: $lt{'ipheader'}.': '.
8628: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8629: 'name="wafproxy_ipheader" />'.
8630: '</td></tr>'."\n".
8631: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8632: $lt{'trusted'}.':<br />'.
1.381 raeburn 8633: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8634: $values{$dom}{'trusted'}.'</textarea>'.
8635: '</td></tr>'."\n".
8636: '<tr><td><hr /></td></tr>'."\n".
8637: '<tr>'.
8638: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8639: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8640: $lt{'vpndirect'}.'</label>'.(' 'x2).
8641: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8642: $lt{'vpnaliased'}.'</label></span></td></tr>';
8643: foreach my $item ('vpnint','vpnext') {
8644: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8645: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8646: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8647: $values{$dom}{$item}.'</textarea>'.
8648: '</td></tr>'."\n";
1.373 raeburn 8649: }
1.382 raeburn 8650: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8651: '<tr>'.
8652: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8653: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8654: $lt{'alltossl'}.'</label>'.(' 'x2).
8655: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8656: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8657: '</table></td></tr>';
1.373 raeburn 8658: }
8659: if (keys(%otherdoms)) {
8660: foreach my $domain (sort(keys(%otherdoms))) {
8661: $itemcount ++;
8662: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8663: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8664: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8665: '<td class="LC_left_item"><table>';
1.382 raeburn 8666: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8667: my $showval = &mt('None');
1.382 raeburn 8668: if ($item eq 'ssl') {
8669: $showval = $lt{'ssltossl'};
8670: }
1.373 raeburn 8671: if ($values{$domain}{$item}) {
1.381 raeburn 8672: $showval = $values{$domain}{$item};
1.382 raeburn 8673: if ($item eq 'ssl') {
8674: $showval = $lt{'alltossl'};
1.383 raeburn 8675: } elsif ($item eq 'remoteip') {
8676: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8677: }
1.373 raeburn 8678: }
8679: $datatable .= '<tr>'.
8680: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8681: }
1.381 raeburn 8682: $datatable .= '</table></td></tr>';
1.373 raeburn 8683: }
8684: }
8685: }
8686: $$rowtotal += $itemcount;
8687: return $datatable;
8688: }
8689:
8690: sub wafproxy_titles {
8691: return &Apache::lonlocal::texthash(
1.381 raeburn 8692: remoteip => "Method for determining user's IP",
8693: ipheader => 'Request header containing remote IP',
8694: trusted => 'Trusted IP range(s)',
8695: vpnaccess => 'Access from institutional VPN',
8696: vpndirect => 'via regular hostname (no WAF)',
8697: vpnaliased => 'via aliased hostname (WAF)',
8698: vpnint => 'Internal IP Range(s) for VPN sessions',
8699: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8700: sslopt => 'Forwarding http/https',
1.381 raeburn 8701: alltossl => 'WAF forwards both http and https requests to https',
8702: ssltossl => 'WAF forwards http requests to http and https to https',
8703: );
8704: }
8705:
8706: sub remoteip_methods {
8707: return &Apache::lonlocal::texthash(
8708: m => 'Use Apache mod_remoteip',
8709: h => 'Use headers parsed by LON-CAPA',
8710: n => 'Not in use',
1.373 raeburn 8711: );
8712: }
8713:
1.137 raeburn 8714: sub print_usersessions {
8715: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8716: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8717: my (%by_ip,%by_location,@intdoms,@instdoms);
8718: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8719:
8720: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8721: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8722: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8723: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8724: if ($position eq 'top') {
1.152 raeburn 8725: if (keys(%serverhomes) > 1) {
1.145 raeburn 8726: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8727: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8728: if (ref($settings) eq 'HASH') {
8729: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8730: $curroffloadnow = $settings->{'offloadnow'};
8731: }
1.371 raeburn 8732: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8733: $curroffloadoth = $settings->{'offloadoth'};
8734: }
1.261 raeburn 8735: }
1.371 raeburn 8736: my $other_insts = scalar(keys(%by_location));
8737: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8738: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8739: } else {
1.140 raeburn 8740: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8741: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8742: '</td></tr>';
1.140 raeburn 8743: }
1.137 raeburn 8744: } else {
1.279 raeburn 8745: my %titles = &usersession_titles();
8746: my ($prefix,@types);
8747: if ($position eq 'bottom') {
8748: $prefix = 'remote';
8749: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8750: } else {
1.279 raeburn 8751: $prefix = 'hosted';
8752: @types = ('excludedomain','includedomain');
8753: }
8754: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8755: }
8756: $$rowtotal += $itemcount;
8757: return $datatable;
8758: }
8759:
8760: sub rules_by_location {
8761: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8762: my ($datatable,$itemcount,$css_class);
8763: if (keys(%{$by_location}) == 0) {
8764: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8765: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8766: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8767: '</td></tr>';
8768: $itemcount = 1;
8769: } else {
8770: $itemcount = 0;
8771: my $numinrow = 5;
8772: my (%current,%checkedon,%checkedoff);
8773: my @locations = sort(keys(%{$by_location}));
8774: foreach my $type (@{$types}) {
8775: $checkedon{$type} = '';
8776: $checkedoff{$type} = ' checked="checked"';
8777: }
8778: if (ref($settings) eq 'HASH') {
8779: if (ref($settings->{$prefix}) eq 'HASH') {
8780: foreach my $key (keys(%{$settings->{$prefix}})) {
8781: $current{$key} = $settings->{$prefix}{$key};
8782: if ($key eq 'version') {
8783: if ($current{$key} ne '') {
1.145 raeburn 8784: $checkedon{$key} = ' checked="checked"';
8785: $checkedoff{$key} = '';
8786: }
1.279 raeburn 8787: } elsif (ref($current{$key}) eq 'ARRAY') {
8788: $checkedon{$key} = ' checked="checked"';
8789: $checkedoff{$key} = '';
1.137 raeburn 8790: }
8791: }
8792: }
1.279 raeburn 8793: }
8794: foreach my $type (@{$types}) {
8795: next if ($type ne 'version' && !@locations);
8796: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8797: $datatable .= '<tr'.$css_class.'>
8798: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8799: <span class="LC_nobreak">
8800: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8801: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8802: if ($type eq 'version') {
8803: my @lcversions = &Apache::lonnet::all_loncaparevs();
8804: my $selector = '<select name="'.$prefix.'_version">';
8805: foreach my $version (@lcversions) {
8806: my $selected = '';
8807: if ($current{'version'} eq $version) {
8808: $selected = ' selected="selected"';
1.145 raeburn 8809: }
1.279 raeburn 8810: $selector .= ' <option value="'.$version.'"'.
8811: $selected.'>'.$version.'</option>';
8812: }
8813: $selector .= '</select> ';
8814: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8815: } else {
8816: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8817: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8818: ' />'.(' 'x2).
8819: '<input type="button" value="'.&mt('uncheck all').'" '.
8820: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8821: "\n".
8822: '</div><div><table>';
8823: my $rem;
8824: for (my $i=0; $i<@locations; $i++) {
8825: my ($showloc,$value,$checkedtype);
8826: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8827: my $ip = $by_location->{$locations[$i]}->[0];
8828: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8829: $value = join(':',@{$by_ip->{$ip}});
8830: $showloc = join(', ',@{$by_ip->{$ip}});
8831: if (ref($current{$type}) eq 'ARRAY') {
8832: foreach my $loc (@{$by_ip->{$ip}}) {
8833: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8834: $checkedtype = ' checked="checked"';
8835: last;
1.145 raeburn 8836: }
1.138 raeburn 8837: }
8838: }
8839: }
1.137 raeburn 8840: }
1.279 raeburn 8841: $rem = $i%($numinrow);
8842: if ($rem == 0) {
8843: if ($i > 0) {
8844: $datatable .= '</tr>';
8845: }
8846: $datatable .= '<tr>';
8847: }
8848: $datatable .= '<td class="LC_left_item">'.
8849: '<span class="LC_nobreak"><label>'.
8850: '<input type="checkbox" name="'.$prefix.'_'.$type.
8851: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8852: '</label></span></td>';
8853: }
8854: $rem = @locations%($numinrow);
8855: my $colsleft = $numinrow - $rem;
8856: if ($colsleft > 1 ) {
8857: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8858: ' </td>';
8859: } elsif ($colsleft == 1) {
8860: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8861: }
1.279 raeburn 8862: $datatable .= '</tr></table>';
1.137 raeburn 8863: }
1.279 raeburn 8864: $datatable .= '</td></tr>';
8865: $itemcount ++;
1.137 raeburn 8866: }
8867: }
1.279 raeburn 8868: return ($datatable,$itemcount);
1.137 raeburn 8869: }
8870:
1.275 raeburn 8871: sub print_ssl {
8872: my ($position,$dom,$settings,$rowtotal) = @_;
8873: my ($css_class,$datatable);
8874: my $itemcount = 1;
8875: if ($position eq 'top') {
1.281 raeburn 8876: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8877: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8878: my $same_institution;
8879: if ($intdom ne '') {
8880: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8881: if (ref($internet_names) eq 'ARRAY') {
8882: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8883: $same_institution = 1;
8884: }
8885: }
8886: }
1.275 raeburn 8887: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8888: $datatable = '<tr'.$css_class.'><td colspan="2">';
8889: if ($same_institution) {
8890: my %domservers = &Apache::lonnet::get_servers($dom);
8891: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8892: } else {
8893: $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.");
8894: }
8895: $datatable .= '</td></tr>';
1.275 raeburn 8896: $itemcount ++;
8897: } else {
8898: my %titles = &ssl_titles();
8899: my (%by_ip,%by_location,@intdoms,@instdoms);
8900: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8901: my @alldoms = &Apache::lonnet::all_domains();
8902: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8903: my @domservers = &Apache::lonnet::get_servers($dom);
8904: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8905: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8906: if (($position eq 'connto') || ($position eq 'connfrom')) {
8907: my $legacy;
8908: unless (ref($settings) eq 'HASH') {
8909: my $name;
8910: if ($position eq 'connto') {
8911: $name = 'loncAllowInsecure';
8912: } else {
8913: $name = 'londAllowInsecure';
8914: }
8915: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8916: my @ids=&Apache::lonnet::current_machine_ids();
8917: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8918: my %what = (
8919: $name => 1,
8920: );
8921: my ($result,$returnhash) =
8922: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8923: if ($result eq 'ok') {
8924: if (ref($returnhash) eq 'HASH') {
8925: $legacy = $returnhash->{$name};
8926: }
8927: }
8928: } else {
8929: $legacy = $Apache::lonnet::perlvar{$name};
8930: }
8931: }
1.275 raeburn 8932: foreach my $type ('dom','intdom','other') {
8933: my %checked;
8934: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8935: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8936: '<td class="LC_right_item">';
8937: my $skip;
8938: if ($type eq 'dom') {
8939: unless (keys(%servers) > 1) {
8940: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8941: $skip = 1;
8942: }
8943: }
8944: if ($type eq 'intdom') {
8945: unless (@instdoms > 1) {
8946: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8947: $skip = 1;
8948: }
8949: } elsif ($type eq 'other') {
8950: if (keys(%by_location) == 0) {
8951: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8952: $skip = 1;
8953: }
8954: }
8955: unless ($skip) {
8956: $checked{'yes'} = ' checked="checked"';
8957: if (ref($settings) eq 'HASH') {
1.293 raeburn 8958: if (ref($settings->{$position}) eq 'HASH') {
8959: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8960: $checked{$1} = $checked{'yes'};
8961: delete($checked{'yes'});
8962: }
8963: }
1.293 raeburn 8964: } else {
8965: if ($legacy == 0) {
8966: $checked{'req'} = $checked{'yes'};
8967: delete($checked{'yes'});
8968: }
1.275 raeburn 8969: }
8970: foreach my $option ('no','yes','req') {
8971: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8972: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8973: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8974: '</label></span>'.(' 'x2);
8975: }
8976: }
8977: $datatable .= '</td></tr>';
8978: $itemcount ++;
8979: }
8980: } else {
8981: my $prefix = 'replication';
8982: my @types = ('certreq','nocertreq');
1.279 raeburn 8983: if (keys(%by_location) == 0) {
8984: $datatable .= '<tr'.$css_class.'><td>'.
8985: &mt('Nothing to set here, as there are no other institutions').
8986: '</td></tr>';
8987: $itemcount ++;
1.275 raeburn 8988: } else {
1.279 raeburn 8989: ($datatable,$itemcount) =
8990: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8991: }
8992: }
8993: }
8994: $$rowtotal += $itemcount;
8995: return $datatable;
8996: }
8997:
8998: sub ssl_titles {
8999: return &Apache::lonlocal::texthash (
9000: dom => 'LON-CAPA servers/VMs from same domain',
9001: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
9002: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 9003: connto => 'Connections to other servers',
9004: connfrom => 'Connections from other servers',
1.275 raeburn 9005: replication => 'Replicating content to other institutions',
9006: certreq => 'Client certificate required, but specific domains exempt',
9007: nocertreq => 'No client certificate required, except for specific domains',
9008: no => 'SSL not used',
9009: yes => 'SSL Optional (used if available)',
9010: req => 'SSL Required',
9011: );
1.279 raeburn 9012: }
9013:
9014: sub print_trust {
9015: my ($prefix,$dom,$settings,$rowtotal) = @_;
9016: my ($css_class,$datatable,%checked,%choices);
9017: my (%by_ip,%by_location,@intdoms,@instdoms);
9018: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
9019: my $itemcount = 1;
9020: my %titles = &trust_titles();
9021: my @types = ('exc','inc');
9022: if ($prefix eq 'top') {
9023: $prefix = 'content';
9024: } elsif ($prefix eq 'bottom') {
9025: $prefix = 'msg';
9026: }
9027: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
9028: $$rowtotal += $itemcount;
9029: return $datatable;
9030: }
9031:
9032: sub trust_titles {
9033: return &Apache::lonlocal::texthash(
9034: content => "Access to this domain's content by others",
9035: shared => "Access to other domain's content by this domain",
9036: enroll => "Enrollment in this domain's courses by others",
9037: othcoau => "Co-author roles in this domain for others",
9038: coaurem => "Co-author roles for this domain's users elsewhere",
9039: domroles => "Domain roles in this domain assignable to others",
9040: catalog => "Course Catalog for this domain displayed elsewhere",
9041: reqcrs => "Requests for creation of courses in this domain by others",
9042: msg => "Users in other domains can send messages to this domain",
9043: exc => "Allow all, but exclude specific domains",
9044: inc => "Deny all, but include specific domains",
9045: );
1.275 raeburn 9046: }
9047:
1.138 raeburn 9048: sub build_location_hashes {
1.275 raeburn 9049: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 9050: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 9051: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 9052: my %iphost = &Apache::lonnet::get_iphost();
9053: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
9054: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
9055: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
9056: foreach my $id (@{$iphost{$primary_ip}}) {
9057: my $intdom = &Apache::lonnet::internet_dom($id);
9058: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
9059: push(@{$intdoms},$intdom);
9060: }
9061: }
9062: }
9063: foreach my $ip (keys(%iphost)) {
9064: if (ref($iphost{$ip}) eq 'ARRAY') {
9065: foreach my $id (@{$iphost{$ip}}) {
9066: my $location = &Apache::lonnet::internet_dom($id);
9067: if ($location) {
1.275 raeburn 9068: if (grep(/^\Q$location\E$/,@{$intdoms})) {
9069: my $dom = &Apache::lonnet::host_domain($id);
9070: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
9071: push(@{$instdoms},$dom);
9072: }
9073: next;
9074: }
1.138 raeburn 9075: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9076: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
9077: push(@{$by_ip->{$ip}},$location);
9078: }
9079: } else {
9080: $by_ip->{$ip} = [$location];
9081: }
9082: }
9083: }
9084: }
9085: }
9086: foreach my $ip (sort(keys(%{$by_ip}))) {
9087: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9088: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
9089: my $first = $by_ip->{$ip}->[0];
9090: if (ref($by_location->{$first}) eq 'ARRAY') {
9091: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
9092: push(@{$by_location->{$first}},$ip);
9093: }
9094: } else {
9095: $by_location->{$first} = [$ip];
9096: }
9097: }
9098: }
9099: return;
9100: }
9101:
1.145 raeburn 9102: sub current_offloads_to {
9103: my ($dom,$settings,$servers) = @_;
9104: my (%spareid,%otherdomconfigs);
1.152 raeburn 9105: if (ref($servers) eq 'HASH') {
1.145 raeburn 9106: foreach my $lonhost (sort(keys(%{$servers}))) {
9107: my $gotspares;
1.152 raeburn 9108: if (ref($settings) eq 'HASH') {
9109: if (ref($settings->{'spares'}) eq 'HASH') {
9110: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9111: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9112: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9113: $gotspares = 1;
9114: }
1.145 raeburn 9115: }
9116: }
9117: unless ($gotspares) {
9118: my $gotspares;
9119: my $serverhomeID =
9120: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9121: my $serverhomedom =
9122: &Apache::lonnet::host_domain($serverhomeID);
9123: if ($serverhomedom ne $dom) {
9124: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9125: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9126: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9127: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9128: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9129: $gotspares = 1;
9130: }
9131: }
9132: } else {
9133: $otherdomconfigs{$serverhomedom} =
9134: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9135: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9136: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9137: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9138: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9139: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9140: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9141: $gotspares = 1;
9142: }
9143: }
9144: }
9145: }
9146: }
9147: }
9148: }
9149: unless ($gotspares) {
9150: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9151: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9152: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9153: } else {
9154: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9155: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9156: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9157: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9158: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9159: } else {
1.150 raeburn 9160: my %what = (
9161: spareid => 1,
9162: );
9163: my ($result,$returnhash) =
9164: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9165: if ($result eq 'ok') {
9166: if (ref($returnhash) eq 'HASH') {
9167: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9168: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9169: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9170: }
9171: }
1.145 raeburn 9172: }
9173: }
9174: }
9175: }
9176: }
9177: }
9178: return %spareid;
9179: }
9180:
9181: sub spares_row {
1.371 raeburn 9182: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9183: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9184: my $css_class;
9185: my $numinrow = 4;
9186: my $itemcount = 1;
9187: my $datatable;
1.152 raeburn 9188: my %typetitles = &sparestype_titles();
9189: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9190: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9191: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9192: my ($othercontrol,$serverdom);
9193: if ($serverhome ne $server) {
9194: $serverdom = &Apache::lonnet::host_domain($serverhome);
9195: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9196: } else {
9197: $serverdom = &Apache::lonnet::host_domain($server);
9198: if ($serverdom ne $dom) {
9199: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9200: }
9201: }
9202: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9203: my ($checkednow,$checkedoth);
1.261 raeburn 9204: if (ref($curroffloadnow) eq 'HASH') {
9205: if ($curroffloadnow->{$server}) {
9206: $checkednow = ' checked="checked"';
9207: }
9208: }
1.371 raeburn 9209: if (ref($curroffloadoth) eq 'HASH') {
9210: if ($curroffloadoth->{$server}) {
9211: $checkedoth = ' checked="checked"';
9212: }
9213: }
1.145 raeburn 9214: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9215: $datatable .= '<tr'.$css_class.'>
9216: <td rowspan="2">
1.183 bisitz 9217: <span class="LC_nobreak">'.
9218: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9219: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9220: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9221: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9222: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9223: "\n";
1.371 raeburn 9224: if ($other_insts) {
9225: $datatable .= '<br />'.
9226: '<span class="LC_nobreak">'."\n".
9227: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9228: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9229: "\n";
9230: }
1.145 raeburn 9231: my (%current,%canselect);
1.152 raeburn 9232: my @choices =
9233: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9234: foreach my $type ('primary','default') {
9235: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9236: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9237: my @spares = @{$spareid->{$server}{$type}};
9238: if (@spares > 0) {
1.152 raeburn 9239: if ($othercontrol) {
9240: $current{$type} = join(', ',@spares);
9241: } else {
9242: $current{$type} .= '<table>';
9243: my $numspares = scalar(@spares);
9244: for (my $i=0; $i<@spares; $i++) {
9245: my $rem = $i%($numinrow);
9246: if ($rem == 0) {
9247: if ($i > 0) {
9248: $current{$type} .= '</tr>';
9249: }
9250: $current{$type} .= '<tr>';
1.145 raeburn 9251: }
1.152 raeburn 9252: $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'".');" /> '.
9253: $spareid->{$server}{$type}[$i].
9254: '</label></td>'."\n";
9255: }
9256: my $rem = @spares%($numinrow);
9257: my $colsleft = $numinrow - $rem;
9258: if ($colsleft > 1 ) {
9259: $current{$type} .= '<td colspan="'.$colsleft.
9260: '" class="LC_left_item">'.
9261: ' </td>';
9262: } elsif ($colsleft == 1) {
9263: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9264: }
1.152 raeburn 9265: $current{$type} .= '</tr></table>';
1.150 raeburn 9266: }
1.145 raeburn 9267: }
9268: }
9269: if ($current{$type} eq '') {
9270: $current{$type} = &mt('None specified');
9271: }
1.152 raeburn 9272: if ($othercontrol) {
9273: if ($type eq 'primary') {
9274: $canselect{$type} = $othercontrol;
9275: }
9276: } else {
9277: $canselect{$type} =
9278: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9279: '<select name="newspare_'.$type.'_'.$server.'" '.
9280: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9281: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9282: if (@choices > 0) {
9283: foreach my $lonhost (@choices) {
9284: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9285: }
9286: }
9287: $canselect{$type} .= '</select>'."\n";
9288: }
9289: } else {
9290: $current{$type} = &mt('Could not be determined');
9291: if ($type eq 'primary') {
9292: $canselect{$type} = $othercontrol;
9293: }
1.145 raeburn 9294: }
1.152 raeburn 9295: if ($type eq 'default') {
9296: $datatable .= '<tr'.$css_class.'>';
9297: }
9298: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9299: '<td>'.$current{$type}.'</td>'."\n".
9300: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9301: }
9302: $itemcount ++;
9303: }
9304: }
9305: $$rowtotal += $itemcount;
9306: return $datatable;
9307: }
9308:
1.152 raeburn 9309: sub possible_newspares {
9310: my ($server,$currspares,$serverhomes,$altids) = @_;
9311: my $serverhostname = &Apache::lonnet::hostname($server);
9312: my %excluded;
9313: if ($serverhostname ne '') {
9314: %excluded = (
9315: $serverhostname => 1,
9316: );
9317: }
9318: if (ref($currspares) eq 'HASH') {
9319: foreach my $type (keys(%{$currspares})) {
9320: if (ref($currspares->{$type}) eq 'ARRAY') {
9321: if (@{$currspares->{$type}} > 0) {
9322: foreach my $curr (@{$currspares->{$type}}) {
9323: my $hostname = &Apache::lonnet::hostname($curr);
9324: $excluded{$hostname} = 1;
9325: }
9326: }
9327: }
9328: }
9329: }
9330: my @choices;
9331: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9332: if (keys(%{$serverhomes}) > 1) {
9333: foreach my $name (sort(keys(%{$serverhomes}))) {
9334: unless ($excluded{$name}) {
9335: if (exists($altids->{$serverhomes->{$name}})) {
9336: push(@choices,$altids->{$serverhomes->{$name}});
9337: } else {
9338: push(@choices,$serverhomes->{$name});
1.145 raeburn 9339: }
9340: }
9341: }
9342: }
9343: }
1.152 raeburn 9344: return sort(@choices);
1.145 raeburn 9345: }
9346:
1.150 raeburn 9347: sub print_loadbalancing {
9348: my ($dom,$settings,$rowtotal) = @_;
9349: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9350: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9351: my $numinrow = 1;
9352: my $datatable;
9353: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9354: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9355: if (ref($settings) eq 'HASH') {
9356: %existing = %{$settings};
9357: }
9358: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9359: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9360: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9361: } else {
9362: return;
9363: }
9364: my ($othertitle,$usertypes,$types) =
9365: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9366: my $rownum = 8;
1.150 raeburn 9367: if (ref($types) eq 'ARRAY') {
9368: $rownum += scalar(@{$types});
9369: }
1.171 raeburn 9370: my @css_class = ('LC_odd_row','LC_even_row');
9371: my $balnum = 0;
9372: my $islast;
9373: my (@toshow,$disabledtext);
9374: if (keys(%currbalancer) > 0) {
9375: @toshow = sort(keys(%currbalancer));
9376: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9377: push(@toshow,'');
9378: }
9379: } else {
9380: @toshow = ('');
9381: $disabledtext = &mt('No existing load balancer');
9382: }
9383: foreach my $lonhost (@toshow) {
9384: if ($balnum == scalar(@toshow)-1) {
9385: $islast = 1;
9386: } else {
9387: $islast = 0;
9388: }
9389: my $cssidx = $balnum%2;
9390: my $targets_div_style = 'display: none';
9391: my $disabled_div_style = 'display: block';
9392: my $homedom_div_style = 'display: none';
9393: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9394: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9395: '<p>';
9396: if ($lonhost eq '') {
1.210 raeburn 9397: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9398: if (keys(%currbalancer) > 0) {
9399: $datatable .= &mt('Add balancer:');
9400: } else {
9401: $datatable .= &mt('Enable balancer:');
9402: }
9403: $datatable .= ' '.
9404: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9405: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9406: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9407: '<option value="" selected="selected">'.&mt('None').
9408: '</option>'."\n";
9409: foreach my $server (sort(keys(%servers))) {
9410: next if ($currbalancer{$server});
9411: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9412: }
1.210 raeburn 9413: $datatable .=
1.171 raeburn 9414: '</select>'."\n".
9415: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9416: } else {
9417: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9418: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9419: &mt('Stop balancing').'</label>'.
9420: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9421: $targets_div_style = 'display: block';
9422: $disabled_div_style = 'display: none';
9423: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9424: $homedom_div_style = 'display: block';
9425: }
9426: }
1.306 raeburn 9427: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9428: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9429: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9430: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9431: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9432: my @sparestypes = ('primary','default');
9433: my %typetitles = &sparestype_titles();
1.284 raeburn 9434: my %hostherechecked = (
9435: no => ' checked="checked"',
9436: );
1.342 raeburn 9437: my %balcookiechecked = (
1.425 raeburn 9438: no => ' checked="checked"',
1.342 raeburn 9439: );
1.171 raeburn 9440: foreach my $sparetype (@sparestypes) {
9441: my $targettable;
9442: for (my $i=0; $i<$numspares; $i++) {
9443: my $checked;
9444: if (ref($currtargets{$lonhost}) eq 'HASH') {
9445: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9446: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9447: $checked = ' checked="checked"';
9448: }
9449: }
9450: }
9451: my ($chkboxval,$disabled);
9452: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9453: $chkboxval = $spares[$i];
9454: }
9455: if (exists($currbalancer{$spares[$i]})) {
9456: $disabled = ' disabled="disabled"';
9457: }
1.210 raeburn 9458: $targettable .=
1.253 raeburn 9459: '<td><span class="LC_nobreak"><label>'.
9460: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9461: $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 9462: '</span></label></span></td>';
1.171 raeburn 9463: my $rem = $i%($numinrow);
9464: if ($rem == 0) {
9465: if (($i > 0) && ($i < $numspares-1)) {
9466: $targettable .= '</tr>';
9467: }
9468: if ($i < $numspares-1) {
9469: $targettable .= '<tr>';
1.150 raeburn 9470: }
9471: }
9472: }
1.171 raeburn 9473: if ($targettable ne '') {
9474: my $rem = $numspares%($numinrow);
9475: my $colsleft = $numinrow - $rem;
9476: if ($colsleft > 1 ) {
9477: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9478: ' </td>';
9479: } elsif ($colsleft == 1) {
9480: $targettable .= '<td class="LC_left_item"> </td>';
9481: }
9482: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9483: '<table><tr>'.$targettable.'</tr></table><br />';
9484: }
1.284 raeburn 9485: $hostherechecked{$sparetype} = '';
9486: if (ref($currtargets{$lonhost}) eq 'HASH') {
9487: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9488: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9489: $hostherechecked{$sparetype} = ' checked="checked"';
9490: $hostherechecked{'no'} = '';
9491: }
9492: }
9493: }
9494: }
1.342 raeburn 9495: if ($currcookies{$lonhost}) {
9496: %balcookiechecked = (
9497: yes => ' checked="checked"',
9498: );
9499: }
1.284 raeburn 9500: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9501: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9502: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9503: foreach my $sparetype (@sparestypes) {
9504: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9505: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9506: '</i></label><br />';
1.171 raeburn 9507: }
1.342 raeburn 9508: $datatable .= &mt('Use balancer cookie').'<br />'.
9509: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9510: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9511: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9512: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9513: '</div></td></tr>'.
1.171 raeburn 9514: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9515: $othertitle,$usertypes,$types,\%servers,
9516: \%currbalancer,$lonhost,
9517: $targets_div_style,$homedom_div_style,
9518: $css_class[$cssidx],$balnum,$islast);
9519: $$rowtotal += $rownum;
9520: $balnum ++;
9521: }
9522: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9523: return $datatable;
9524: }
9525:
9526: sub get_loadbalancers_config {
1.342 raeburn 9527: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9528: return unless ((ref($servers) eq 'HASH') &&
9529: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9530: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9531: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9532: if (keys(%{$existing}) > 0) {
9533: my $oldlonhost;
9534: foreach my $key (sort(keys(%{$existing}))) {
9535: if ($key eq 'lonhost') {
9536: $oldlonhost = $existing->{'lonhost'};
9537: $currbalancer->{$oldlonhost} = 1;
9538: } elsif ($key eq 'targets') {
9539: if ($oldlonhost) {
9540: $currtargets->{$oldlonhost} = $existing->{'targets'};
9541: }
9542: } elsif ($key eq 'rules') {
9543: if ($oldlonhost) {
9544: $currrules->{$oldlonhost} = $existing->{'rules'};
9545: }
9546: } elsif (ref($existing->{$key}) eq 'HASH') {
9547: $currbalancer->{$key} = 1;
9548: $currtargets->{$key} = $existing->{$key}{'targets'};
9549: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9550: if ($existing->{$key}{'cookie'}) {
9551: $currcookies->{$key} = 1;
9552: }
1.150 raeburn 9553: }
9554: }
1.171 raeburn 9555: } else {
9556: my ($balancerref,$targetsref) =
9557: &Apache::lonnet::get_lonbalancer_config($servers);
9558: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9559: foreach my $server (sort(keys(%{$balancerref}))) {
9560: $currbalancer->{$server} = 1;
9561: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9562: }
9563: }
9564: }
1.171 raeburn 9565: return;
1.150 raeburn 9566: }
9567:
9568: sub loadbalancing_rules {
9569: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9570: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9571: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9572: my $output;
1.171 raeburn 9573: my $num = 0;
1.210 raeburn 9574: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9575: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9576: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9577: foreach my $type (@{$alltypes}) {
1.171 raeburn 9578: $num ++;
1.150 raeburn 9579: my $current;
9580: if (ref($currrules) eq 'HASH') {
9581: $current = $currrules->{$type};
9582: }
1.253 raeburn 9583: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9584: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9585: $current = '';
9586: }
9587: }
9588: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9589: $servers,$currbalancer,$lonhost,$dom,
9590: $targets_div_style,$homedom_div_style,
9591: $css_class,$balnum,$num,$islast);
1.150 raeburn 9592: }
9593: }
9594: return $output;
9595: }
9596:
9597: sub loadbalancing_titles {
9598: my ($dom,$intdom,$usertypes,$types) = @_;
9599: my %othertypes = (
9600: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9601: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9602: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9603: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9604: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9605: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9606: );
1.209 raeburn 9607: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9608: my @available;
1.150 raeburn 9609: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9610: @available = @{$types};
1.150 raeburn 9611: }
1.302 raeburn 9612: unless (grep(/^default$/,@available)) {
9613: push(@available,'default');
9614: }
9615: unshift(@alltypes,@available);
1.150 raeburn 9616: my %titles;
9617: foreach my $type (@alltypes) {
9618: if ($type =~ /^_LC_/) {
9619: $titles{$type} = $othertypes{$type};
9620: } elsif ($type eq 'default') {
9621: $titles{$type} = &mt('All users from [_1]',$dom);
9622: if (ref($types) eq 'ARRAY') {
9623: if (@{$types} > 0) {
9624: $titles{$type} = &mt('Other users from [_1]',$dom);
9625: }
9626: }
9627: } elsif (ref($usertypes) eq 'HASH') {
9628: $titles{$type} = $usertypes->{$type};
9629: }
9630: }
9631: return (\@alltypes,\%othertypes,\%titles);
9632: }
9633:
9634: sub loadbalance_rule_row {
1.171 raeburn 9635: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9636: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9637: my @rulenames;
1.150 raeburn 9638: my %ruletitles = &offloadtype_text();
1.209 raeburn 9639: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9640: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9641: } else {
1.209 raeburn 9642: @rulenames = ('default','homeserver');
9643: if ($type eq '_LC_external') {
9644: push(@rulenames,'externalbalancer');
9645: } else {
9646: push(@rulenames,'specific');
9647: }
9648: push(@rulenames,'none');
1.150 raeburn 9649: }
9650: my $style = $targets_div_style;
1.253 raeburn 9651: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9652: $style = $homedom_div_style;
9653: }
1.171 raeburn 9654: my $space;
9655: if ($islast && $num == 1) {
1.317 raeburn 9656: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9657: }
1.210 raeburn 9658: my $output =
1.306 raeburn 9659: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9660: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9661: '<td valaign="top">'.$space.
9662: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9663: for (my $i=0; $i<@rulenames; $i++) {
9664: my $rule = $rulenames[$i];
9665: my ($checked,$extra);
9666: if ($rulenames[$i] eq 'default') {
9667: $rule = '';
9668: }
9669: if ($rulenames[$i] eq 'specific') {
9670: if (ref($servers) eq 'HASH') {
9671: my $default;
9672: if (($current ne '') && (exists($servers->{$current}))) {
9673: $checked = ' checked="checked"';
9674: }
9675: unless ($checked) {
9676: $default = ' selected="selected"';
9677: }
1.210 raeburn 9678: $extra =
1.171 raeburn 9679: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9680: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9681: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9682: '<option value=""'.$default.'></option>'."\n";
9683: foreach my $server (sort(keys(%{$servers}))) {
9684: if (ref($currbalancer) eq 'HASH') {
9685: next if (exists($currbalancer->{$server}));
9686: }
1.150 raeburn 9687: my $selected;
1.171 raeburn 9688: if ($server eq $current) {
1.150 raeburn 9689: $selected = ' selected="selected"';
9690: }
1.171 raeburn 9691: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9692: }
9693: $extra .= '</select>';
9694: }
9695: } elsif ($rule eq $current) {
9696: $checked = ' checked="checked"';
9697: }
9698: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9699: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9700: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9701: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9702: ')"'.$checked.' /> ';
9703: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9704: $output .= $ruletitles{'particular'};
9705: } else {
9706: $output .= $ruletitles{$rulenames[$i]};
9707: }
9708: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9709: }
9710: $output .= '</div></td></tr>'."\n";
9711: return $output;
9712: }
9713:
9714: sub offloadtype_text {
9715: my %ruletitles = &Apache::lonlocal::texthash (
9716: 'default' => 'Offloads to default destinations',
9717: 'homeserver' => "Offloads to user's home server",
9718: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9719: 'specific' => 'Offloads to specific server',
1.161 raeburn 9720: 'none' => 'No offload',
1.209 raeburn 9721: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9722: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9723: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9724: );
9725: return %ruletitles;
9726: }
9727:
9728: sub sparestype_titles {
9729: my %typestitles = &Apache::lonlocal::texthash (
9730: 'primary' => 'primary',
9731: 'default' => 'default',
9732: );
9733: return %typestitles;
9734: }
9735:
1.28 raeburn 9736: sub contact_titles {
9737: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9738: 'supportemail' => 'Support E-mail address',
9739: 'adminemail' => 'Default Server Admin E-mail address',
9740: 'errormail' => 'Error reports to be e-mailed to',
9741: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9742: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9743: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9744: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9745: 'requestsmail' => 'E-mail from course requests requiring approval',
9746: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9747: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9748: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9749: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9750: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9751: 'errorweights' => 'Weights used to compute error count',
9752: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9753: );
9754: my %short_titles = &Apache::lonlocal::texthash (
9755: adminemail => 'Admin E-mail address',
9756: supportemail => 'Support E-mail',
9757: );
9758: return (\%titles,\%short_titles);
9759: }
9760:
1.286 raeburn 9761: sub helpform_fields {
9762: my %titles = &Apache::lonlocal::texthash (
9763: 'username' => 'Name',
9764: 'user' => 'Username/domain',
9765: 'phone' => 'Phone',
9766: 'cc' => 'Cc e-mail',
9767: 'course' => 'Course Details',
9768: 'section' => 'Sections',
1.289 raeburn 9769: 'screenshot' => 'File upload',
1.286 raeburn 9770: );
9771: my @fields = ('username','phone','user','course','section','cc','screenshot');
9772: my %possoptions = (
9773: username => ['yes','no','req'],
1.289 raeburn 9774: phone => ['yes','no','req'],
1.286 raeburn 9775: user => ['yes','no'],
1.289 raeburn 9776: cc => ['yes','no'],
1.286 raeburn 9777: course => ['yes','no'],
9778: section => ['yes','no'],
9779: screenshot => ['yes','no'],
9780: );
9781: my %fieldoptions = &Apache::lonlocal::texthash (
9782: 'yes' => 'Optional',
9783: 'req' => 'Required',
9784: 'no' => "Not shown",
9785: );
9786: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9787: }
9788:
1.72 raeburn 9789: sub tool_titles {
9790: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9791: aboutme => 'Personal web page',
1.86 raeburn 9792: blog => 'Blog',
9793: portfolio => 'Portfolio',
1.430 raeburn 9794: portaccess => 'Share portfolio files',
1.413 raeburn 9795: timezone => 'Can set time zone',
1.88 bisitz 9796: official => 'Official courses (with institutional codes)',
9797: unofficial => 'Unofficial courses',
1.98 raeburn 9798: community => 'Communities',
1.216 raeburn 9799: textbook => 'Textbook courses',
1.271 raeburn 9800: placement => 'Placement tests',
1.86 raeburn 9801: );
1.72 raeburn 9802: return %titles;
9803: }
9804:
1.101 raeburn 9805: sub courserequest_titles {
9806: my %titles = &Apache::lonlocal::texthash (
9807: official => 'Official',
9808: unofficial => 'Unofficial',
9809: community => 'Communities',
1.216 raeburn 9810: textbook => 'Textbook',
1.271 raeburn 9811: placement => 'Placement tests',
1.325 raeburn 9812: lti => 'LTI Provider',
1.101 raeburn 9813: norequest => 'Not allowed',
1.325 raeburn 9814: approval => 'Approval by DC',
1.101 raeburn 9815: validate => 'With validation',
9816: autolimit => 'Numerical limit',
1.103 raeburn 9817: unlimited => '(blank for unlimited)',
1.101 raeburn 9818: );
9819: return %titles;
9820: }
9821:
1.163 raeburn 9822: sub authorrequest_titles {
9823: my %titles = &Apache::lonlocal::texthash (
9824: norequest => 'Not allowed',
9825: approval => 'Approval by Dom. Coord.',
9826: automatic => 'Automatic approval',
9827: );
9828: return %titles;
1.210 raeburn 9829: }
1.163 raeburn 9830:
1.101 raeburn 9831: sub courserequest_conditions {
9832: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9833: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9834: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9835: );
9836: return %conditions;
9837: }
9838:
9839:
1.27 raeburn 9840: sub print_usercreation {
1.30 raeburn 9841: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9842: my $numinrow = 4;
1.28 raeburn 9843: my $datatable;
9844: if ($position eq 'top') {
1.30 raeburn 9845: $$rowtotal ++;
1.34 raeburn 9846: my $rowcount = 0;
1.32 raeburn 9847: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9848: if (ref($rules) eq 'HASH') {
9849: if (keys(%{$rules}) > 0) {
1.32 raeburn 9850: $datatable .= &user_formats_row('username',$settings,$rules,
9851: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9852: $$rowtotal ++;
1.32 raeburn 9853: $rowcount ++;
9854: }
9855: }
9856: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9857: if (ref($idrules) eq 'HASH') {
9858: if (keys(%{$idrules}) > 0) {
9859: $datatable .= &user_formats_row('id',$settings,$idrules,
9860: $idruleorder,$numinrow,$rowcount);
9861: $$rowtotal ++;
9862: $rowcount ++;
1.28 raeburn 9863: }
9864: }
1.39 raeburn 9865: if ($rowcount == 0) {
9866: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9867: $$rowtotal ++;
9868: $rowcount ++;
9869: }
1.34 raeburn 9870: } elsif ($position eq 'middle') {
1.224 raeburn 9871: my @creators = ('author','course','requestcrs');
1.37 raeburn 9872: my ($rules,$ruleorder) =
9873: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9874: my %lt = &usercreation_types();
9875: my %checked;
9876: if (ref($settings) eq 'HASH') {
9877: if (ref($settings->{'cancreate'}) eq 'HASH') {
9878: foreach my $item (@creators) {
9879: $checked{$item} = $settings->{'cancreate'}{$item};
9880: }
9881: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9882: foreach my $item (@creators) {
9883: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9884: $checked{$item} = 'none';
9885: }
9886: }
9887: }
9888: }
9889: my $rownum = 0;
9890: foreach my $item (@creators) {
9891: $rownum ++;
1.224 raeburn 9892: if ($checked{$item} eq '') {
9893: $checked{$item} = 'any';
1.34 raeburn 9894: }
9895: my $css_class;
9896: if ($rownum%2) {
9897: $css_class = '';
9898: } else {
9899: $css_class = ' class="LC_odd_row" ';
9900: }
9901: $datatable .= '<tr'.$css_class.'>'.
9902: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9903: '</span></td><td style="text-align: right">';
1.224 raeburn 9904: my @options = ('any');
9905: if (ref($rules) eq 'HASH') {
9906: if (keys(%{$rules}) > 0) {
9907: push(@options,('official','unofficial'));
1.37 raeburn 9908: }
9909: }
1.224 raeburn 9910: push(@options,'none');
1.37 raeburn 9911: foreach my $option (@options) {
1.50 raeburn 9912: my $type = 'radio';
1.34 raeburn 9913: my $check = ' ';
1.224 raeburn 9914: if ($checked{$item} eq $option) {
9915: $check = ' checked="checked" ';
1.34 raeburn 9916: }
9917: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9918: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9919: $item.'" value="'.$option.'"'.$check.'/> '.
9920: $lt{$option}.'</label> </span>';
9921: }
9922: $datatable .= '</td></tr>';
9923: }
1.28 raeburn 9924: } else {
9925: my @contexts = ('author','course','domain');
1.325 raeburn 9926: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9927: my %checked;
9928: if (ref($settings) eq 'HASH') {
9929: if (ref($settings->{'authtypes'}) eq 'HASH') {
9930: foreach my $item (@contexts) {
9931: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9932: foreach my $auth (@authtypes) {
9933: if ($settings->{'authtypes'}{$item}{$auth}) {
9934: $checked{$item}{$auth} = ' checked="checked" ';
9935: }
9936: }
9937: }
9938: }
1.27 raeburn 9939: }
1.35 raeburn 9940: } else {
9941: foreach my $item (@contexts) {
1.36 raeburn 9942: foreach my $auth (@authtypes) {
1.35 raeburn 9943: $checked{$item}{$auth} = ' checked="checked" ';
9944: }
9945: }
1.27 raeburn 9946: }
1.28 raeburn 9947: my %title = &context_names();
9948: my %authname = &authtype_names();
9949: my $rownum = 0;
9950: my $css_class;
9951: foreach my $item (@contexts) {
9952: if ($rownum%2) {
9953: $css_class = '';
9954: } else {
9955: $css_class = ' class="LC_odd_row" ';
9956: }
1.30 raeburn 9957: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9958: '<td>'.$title{$item}.
9959: '</td><td class="LC_left_item">'.
9960: '<span class="LC_nobreak">';
9961: foreach my $auth (@authtypes) {
9962: $datatable .= '<label>'.
9963: '<input type="checkbox" name="'.$item.'_auth" '.
9964: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9965: $authname{$auth}.'</label> ';
9966: }
9967: $datatable .= '</span></td></tr>';
9968: $rownum ++;
1.27 raeburn 9969: }
1.30 raeburn 9970: $$rowtotal += $rownum;
1.27 raeburn 9971: }
9972: return $datatable;
9973: }
9974:
1.224 raeburn 9975: sub print_selfcreation {
9976: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9977: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9978: $emaildomain,$datatable);
1.224 raeburn 9979: if (ref($settings) eq 'HASH') {
9980: if (ref($settings->{'cancreate'}) eq 'HASH') {
9981: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9982: if (ref($createsettings) eq 'HASH') {
9983: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9984: @selfcreate = @{$createsettings->{'selfcreate'}};
9985: } elsif ($createsettings->{'selfcreate'} ne '') {
9986: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9987: @selfcreate = ('email','login','sso');
9988: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9989: @selfcreate = ($createsettings->{'selfcreate'});
9990: }
9991: }
9992: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9993: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9994: }
1.305 raeburn 9995: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9996: $emailoptions = $createsettings->{'emailoptions'};
9997: }
1.303 raeburn 9998: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9999: $emailverified = $createsettings->{'emailverified'};
10000: }
10001: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
10002: $emaildomain = $createsettings->{'emaildomain'};
10003: }
1.224 raeburn 10004: }
10005: }
10006: }
10007: my %radiohash;
10008: my $numinrow = 4;
10009: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 10010: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 10011: if ($position eq 'top') {
10012: my %choices = &Apache::lonlocal::texthash (
10013: cancreate_login => 'Institutional Login',
10014: cancreate_sso => 'Institutional Single Sign On',
10015: );
10016: my @toggles = sort(keys(%choices));
10017: my %defaultchecked = (
10018: 'cancreate_login' => 'off',
10019: 'cancreate_sso' => 'off',
10020: );
1.228 raeburn 10021: my ($onclick,$itemcount);
1.224 raeburn 10022: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10023: \%choices,$itemcount,$onclick);
1.228 raeburn 10024: $$rowtotal += $itemcount;
1.425 raeburn 10025:
1.224 raeburn 10026: if (ref($usertypes) eq 'HASH') {
10027: if (keys(%{$usertypes}) > 0) {
10028: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
10029: $dom,$numinrow,$othertitle,
1.305 raeburn 10030: 'statustocreate',$rowtotal);
1.224 raeburn 10031: $$rowtotal ++;
10032: }
10033: }
1.240 raeburn 10034: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
10035: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10036: $fieldtitles{'inststatus'} = &mt('Institutional status');
10037: my $rem;
10038: my $numperrow = 2;
10039: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
10040: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 10041: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 10042: '<td class="LC_left_item">'."\n".
1.334 raeburn 10043: '<table>'."\n";
1.240 raeburn 10044: for (my $i=0; $i<@fields; $i++) {
10045: $rem = $i%($numperrow);
10046: if ($rem == 0) {
10047: if ($i > 0) {
10048: $datatable .= '</tr>';
10049: }
10050: $datatable .= '<tr>';
10051: }
10052: my $currval;
1.248 raeburn 10053: if (ref($createsettings) eq 'HASH') {
10054: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
10055: $currval = $createsettings->{'shibenv'}{$fields[$i]};
10056: }
1.240 raeburn 10057: }
10058: $datatable .= '<td class="LC_left_item">'.
10059: '<span class="LC_nobreak">'.
10060: '<input type="text" name="shibenv_'.$fields[$i].'" '.
10061: 'value="'.$currval.'" size="10" /> '.
10062: $fieldtitles{$fields[$i]}.'</span></td>';
10063: }
10064: my $colsleft = $numperrow - $rem;
10065: if ($colsleft > 1 ) {
10066: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10067: ' </td>';
10068: } elsif ($colsleft == 1) {
10069: $datatable .= '<td class="LC_left_item"> </td>';
10070: }
10071: $datatable .= '</tr></table></td></tr>';
10072: $$rowtotal ++;
1.224 raeburn 10073: } elsif ($position eq 'middle') {
10074: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 10075: my @posstypes;
1.224 raeburn 10076: if (ref($types) eq 'ARRAY') {
1.302 raeburn 10077: @posstypes = @{$types};
10078: }
10079: unless (grep(/^default$/,@posstypes)) {
10080: push(@posstypes,'default');
10081: }
10082: my %usertypeshash;
10083: if (ref($usertypes) eq 'HASH') {
10084: %usertypeshash = %{$usertypes};
10085: }
10086: $usertypeshash{'default'} = $othertitle;
10087: foreach my $status (@posstypes) {
10088: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
10089: $numinrow,$$rowtotal,\%usertypeshash);
10090: $$rowtotal ++;
1.224 raeburn 10091: }
10092: } else {
1.236 raeburn 10093: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 10094: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 10095: );
10096: my @toggles = sort(keys(%choices));
10097: my %defaultchecked = (
10098: 'cancreate_email' => 'off',
10099: );
1.305 raeburn 10100: my $customclass = 'LC_selfcreate_email';
10101: my $classprefix = 'LC_canmodify_emailusername_';
10102: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10103: my $display = 'none';
1.305 raeburn 10104: my $rowstyle = 'display:none';
1.236 raeburn 10105: if (grep(/^\Qemail\E$/,@selfcreate)) {
10106: $display = 'block';
1.305 raeburn 10107: $rowstyle = 'display:table-row';
1.236 raeburn 10108: }
1.305 raeburn 10109: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10110: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10111: \%choices,$$rowtotal,$onclick);
10112: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10113: $rowstyle);
10114: $$rowtotal ++;
10115: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10116: $rowstyle);
10117: $$rowtotal ++;
10118: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10119: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10120: my ($emailrules,$emailruleorder) =
10121: &Apache::lonnet::inst_userrules($dom,'email');
10122: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10123: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10124: if (ref($types) eq 'ARRAY') {
10125: @posstypes = @{$types};
10126: }
10127: if (@posstypes) {
10128: unless (grep(/^default$/,@posstypes)) {
10129: push(@posstypes,'default');
1.302 raeburn 10130: }
10131: if (ref($usertypes) eq 'HASH') {
10132: %usertypeshash = %{$usertypes};
10133: }
1.305 raeburn 10134: my $currassign;
10135: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10136: $currassign = {
10137: selfassign => $domdefaults{'inststatusguest'},
10138: };
10139: @ordered = @{$domdefaults{'inststatusguest'}};
10140: } else {
10141: $currassign = { selfassign => [] };
10142: }
10143: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10144: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10145: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10146: $numinrow,$othertitle,'selfassign',
10147: $rowtotal,$onclicktypes,$customclass,
10148: $rowstyle);
10149: $$rowtotal ++;
1.302 raeburn 10150: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10151: foreach my $status (@posstypes) {
10152: my $css_class;
10153: if ($$rowtotal%2) {
10154: $css_class = 'LC_odd_row ';
10155: }
10156: $css_class .= $customclass;
10157: my $rowid = $optionsprefix.$status;
10158: my $hidden = 1;
10159: my $currstyle = 'display:none';
10160: if (grep(/^\Q$status\E$/,@ordered)) {
10161: $currstyle = $rowstyle;
1.425 raeburn 10162: $hidden = 0;
1.305 raeburn 10163: }
10164: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10165: $emailrules,$emailruleorder,$settings,$status,$rowid,
10166: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10167: unless ($hidden) {
10168: $$rowtotal ++;
10169: }
1.224 raeburn 10170: }
1.302 raeburn 10171: } else {
1.305 raeburn 10172: my $css_class;
10173: if ($$rowtotal%2) {
10174: $css_class = 'LC_odd_row ';
10175: }
10176: $css_class .= $customclass;
1.302 raeburn 10177: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10178: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10179: $emailrules,$emailruleorder,$settings,'default','',
10180: $othertitle,$css_class,$rowstyle,$intdom);
10181: $$rowtotal ++;
1.224 raeburn 10182: }
10183: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10184: $numinrow = 1;
1.305 raeburn 10185: if (@posstypes) {
10186: foreach my $status (@posstypes) {
10187: my $rowid = $classprefix.$status;
10188: my $datarowstyle = 'display:none';
1.425 raeburn 10189: if (grep(/^\Q$status\E$/,@ordered)) {
10190: $datarowstyle = $rowstyle;
1.305 raeburn 10191: }
10192: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10193: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10194: $infotitles,$rowid,$customclass,$datarowstyle);
10195: unless ($datarowstyle eq 'display:none') {
10196: $$rowtotal ++;
10197: }
1.224 raeburn 10198: }
1.305 raeburn 10199: } else {
10200: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10201: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10202: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10203: }
10204: }
10205: return $datatable;
10206: }
10207:
1.305 raeburn 10208: sub selfcreate_javascript {
10209: return <<"ENDSCRIPT";
10210:
10211: <script type="text/javascript">
10212: // <![CDATA[
10213:
10214: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10215: var x = document.getElementsByClassName(target);
10216: var insttypes = 0;
10217: var insttypeRegExp = new RegExp(prefix);
10218: if ((x.length != undefined) && (x.length > 0)) {
10219: if (form.elements[radio].length != undefined) {
10220: for (var i=0; i<form.elements[radio].length; i++) {
10221: if (form.elements[radio][i].checked) {
10222: if (form.elements[radio][i].value == 1) {
10223: for (var j=0; j<x.length; j++) {
10224: if (x[j].id == 'undefined') {
10225: x[j].style.display = 'table-row';
10226: } else if (insttypeRegExp.test(x[j].id)) {
10227: insttypes ++;
10228: } else {
10229: x[j].style.display = 'table-row';
10230: }
10231: }
10232: } else {
10233: for (var j=0; j<x.length; j++) {
10234: x[j].style.display = 'none';
10235: }
1.236 raeburn 10236: }
1.305 raeburn 10237: break;
10238: }
10239: }
10240: if (insttypes > 0) {
10241: toggleDataRow(form,checkbox,target,altprefix);
10242: toggleDataRow(form,checkbox,target,prefix,1);
10243: }
10244: }
10245: }
10246: return;
10247: }
10248:
10249: function toggleDataRow(form,checkbox,target,prefix,docount) {
10250: if (form.elements[checkbox].length != undefined) {
10251: var count = 0;
10252: if (docount) {
10253: for (var i=0; i<form.elements[checkbox].length; i++) {
10254: if (form.elements[checkbox][i].checked) {
10255: count ++;
1.236 raeburn 10256: }
1.305 raeburn 10257: }
10258: }
10259: for (var i=0; i<form.elements[checkbox].length; i++) {
10260: var type = form.elements[checkbox][i].value;
10261: if (document.getElementById(prefix+type)) {
10262: if (form.elements[checkbox][i].checked) {
10263: document.getElementById(prefix+type).style.display = 'table-row';
10264: if (count % 2 == 1) {
10265: document.getElementById(prefix+type).className = target+' LC_odd_row';
10266: } else {
10267: document.getElementById(prefix+type).className = target;
1.236 raeburn 10268: }
1.305 raeburn 10269: count ++;
1.236 raeburn 10270: } else {
1.305 raeburn 10271: document.getElementById(prefix+type).style.display = 'none';
10272: }
10273: }
10274: }
10275: }
10276: return;
10277: }
10278:
10279: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10280: var caller = radio+'_'+status;
10281: if (form.elements[caller].length != undefined) {
10282: for (var i=0; i<form.elements[caller].length; i++) {
10283: if (form.elements[caller][i].checked) {
10284: if (document.getElementById(altprefix+'_inst_'+status)) {
10285: var curr = form.elements[caller][i].value;
10286: if (prefix) {
10287: document.getElementById(prefix+'_'+status).style.display = 'none';
10288: }
10289: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10290: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10291: if (curr == 'custom') {
1.425 raeburn 10292: if (prefix) {
1.305 raeburn 10293: document.getElementById(prefix+'_'+status).style.display = 'inline';
10294: }
10295: } else if (curr == 'inst') {
10296: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10297: } else if (curr == 'noninst') {
10298: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10299: }
1.305 raeburn 10300: break;
1.236 raeburn 10301: }
10302: }
10303: }
10304: }
10305: }
10306:
1.305 raeburn 10307: // ]]>
10308: </script>
10309:
10310: ENDSCRIPT
10311: }
10312:
10313: sub noninst_users {
10314: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10315: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10316: my $class = 'LC_left_item';
10317: if ($css_class) {
1.425 raeburn 10318: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10319: }
10320: if ($rowid) {
10321: $rowid = ' id="'.$rowid.'"';
10322: }
10323: if ($rowstyle) {
10324: $rowstyle = ' style="'.$rowstyle.'"';
10325: }
10326: my ($output,$description);
10327: if ($type eq 'default') {
10328: $description = &mt('Requests for: [_1]',$typetitle);
10329: } else {
10330: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10331: }
10332: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10333: "<td>$description</td>\n".
1.305 raeburn 10334: '<td class="'.$class.'" colspan="2">'.
10335: '<table><tr>';
1.425 raeburn 10336: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10337: approve => 'Processing',
10338: email => 'E-mail',
10339: username => 'Username',
10340: );
10341: foreach my $item ('approve','email','username') {
10342: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10343: }
1.305 raeburn 10344: $output .= '</tr><tr>';
10345: foreach my $item ('approve','email','username') {
1.306 raeburn 10346: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10347: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10348: if ($item eq 'approve') {
10349: %choices = &Apache::lonlocal::texthash (
10350: automatic => 'Automatically approved',
10351: approval => 'Queued for approval',
10352: );
10353: @options = ('automatic','approval');
10354: $hashref = $processing;
10355: $defoption = 'automatic';
10356: $name = 'cancreate_emailprocess_'.$type;
10357: } elsif ($item eq 'email') {
10358: %choices = &Apache::lonlocal::texthash (
10359: any => 'Any e-mail',
10360: inst => 'Institutional only',
10361: noninst => 'Non-institutional only',
10362: custom => 'Custom restrictions',
10363: );
10364: @options = ('any','inst','noninst');
10365: my $showcustom;
10366: if (ref($emailrules) eq 'HASH') {
10367: if (keys(%{$emailrules}) > 0) {
10368: push(@options,'custom');
10369: $showcustom = 'cancreate_emailrule';
10370: if (ref($settings) eq 'HASH') {
10371: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10372: foreach my $rule (@{$settings->{'email_rule'}}) {
10373: if (exists($emailrules->{$rule})) {
10374: $hascustom ++;
10375: }
10376: }
10377: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10378: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10379: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10380: if (exists($emailrules->{$rule})) {
10381: $hascustom ++;
10382: }
10383: }
10384: }
10385: }
10386: }
10387: }
10388: }
10389: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10390: "'cancreate_emaildomain','$type'".');"';
10391: $hashref = $emailoptions;
10392: $defoption = 'any';
10393: $name = 'cancreate_emailoptions_'.$type;
10394: } elsif ($item eq 'username') {
10395: %choices = &Apache::lonlocal::texthash (
10396: all => 'Same as e-mail',
10397: first => 'Omit @domain',
10398: free => 'Free to choose',
10399: );
10400: @options = ('all','first','free');
10401: $hashref = $emailverified;
10402: $defoption = 'all';
10403: $name = 'cancreate_usernameoptions_'.$type;
10404: }
10405: foreach my $option (@options) {
10406: my $checked;
10407: if (ref($hashref) eq 'HASH') {
10408: if ($type eq '') {
10409: if (!exists($hashref->{'default'})) {
10410: if ($option eq $defoption) {
10411: $checked = ' checked="checked"';
10412: }
10413: } else {
10414: if ($hashref->{'default'} eq $option) {
10415: $checked = ' checked="checked"';
10416: }
1.303 raeburn 10417: }
10418: } else {
1.305 raeburn 10419: if (!exists($hashref->{$type})) {
10420: if ($option eq $defoption) {
10421: $checked = ' checked="checked"';
10422: }
10423: } else {
10424: if ($hashref->{$type} eq $option) {
10425: $checked = ' checked="checked"';
10426: }
1.303 raeburn 10427: }
10428: }
1.305 raeburn 10429: } elsif (($item eq 'email') && ($hascustom)) {
10430: if ($option eq 'custom') {
10431: $checked = ' checked="checked"';
10432: }
10433: } elsif ($option eq $defoption) {
10434: $checked = ' checked="checked"';
10435: }
10436: $output .= '<span class="LC_nobreak"><label>'.
10437: '<input type="radio" name="'.$name.'"'.
10438: $checked.' value="'.$option.'"'.$onclick.' />'.
10439: $choices{$option}.'</label></span><br />';
10440: if ($item eq 'email') {
10441: if ($option eq 'custom') {
10442: my $id = 'cancreate_emailrule_'.$type;
10443: my $display = 'none';
10444: if ($checked) {
10445: $display = 'inline';
1.303 raeburn 10446: }
1.305 raeburn 10447: my $numinrow = 2;
10448: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10449: '<legend>'.&mt('Disallow').'</legend><table>'.
10450: &user_formats_row('email',$settings,$emailrules,
10451: $emailruleorder,$numinrow,'',$type);
10452: '</table></fieldset>';
10453: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10454: my %text = &Apache::lonlocal::texthash (
10455: inst => 'must end:',
10456: noninst => 'cannot end:',
10457: );
10458: my $value;
10459: if (ref($emaildomain) eq 'HASH') {
10460: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10461: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10462: }
10463: }
1.305 raeburn 10464: if ($value eq '') {
10465: $value = '@'.$intdom;
10466: }
10467: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10468: my $display = 'none';
10469: if ($checked) {
10470: $display = 'inline';
10471: }
10472: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10473: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10474: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10475: '</div>';
1.303 raeburn 10476: }
10477: }
10478: }
1.305 raeburn 10479: $output .= '</td>'."\n";
1.303 raeburn 10480: }
1.305 raeburn 10481: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10482: return $output;
10483: }
10484:
1.165 raeburn 10485: sub captcha_choice {
1.305 raeburn 10486: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10487: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10488: $vertext,$currver);
1.165 raeburn 10489: my %lt = &captcha_phrases();
10490: $keyentry = 'hidden';
1.354 raeburn 10491: my $colspan=2;
1.165 raeburn 10492: if ($context eq 'cancreate') {
1.224 raeburn 10493: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10494: } elsif ($context eq 'login') {
10495: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10496: } elsif ($context eq 'passwords') {
10497: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10498: $colspan=1;
1.165 raeburn 10499: }
10500: if (ref($settings) eq 'HASH') {
10501: if ($settings->{'captcha'}) {
10502: $checked{$settings->{'captcha'}} = ' checked="checked"';
10503: } else {
10504: $checked{'original'} = ' checked="checked"';
10505: }
10506: if ($settings->{'captcha'} eq 'recaptcha') {
10507: $pubtext = $lt{'pub'};
10508: $privtext = $lt{'priv'};
10509: $keyentry = 'text';
1.269 raeburn 10510: $vertext = $lt{'ver'};
10511: $currver = $settings->{'recaptchaversion'};
10512: if ($currver ne '2') {
10513: $currver = 1;
10514: }
1.165 raeburn 10515: }
10516: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10517: $currpub = $settings->{'recaptchakeys'}{'public'};
10518: $currpriv = $settings->{'recaptchakeys'}{'private'};
10519: }
10520: } else {
10521: $checked{'original'} = ' checked="checked"';
10522: }
1.305 raeburn 10523: my $css_class;
10524: if ($itemcount%2) {
10525: $css_class = 'LC_odd_row';
10526: }
10527: if ($customcss) {
10528: $css_class .= " $customcss";
10529: }
10530: $css_class =~ s/^\s+//;
10531: if ($css_class) {
10532: $css_class = ' class="'.$css_class.'"';
10533: }
10534: if ($rowstyle) {
10535: $css_class .= ' style="'.$rowstyle.'"';
10536: }
1.169 raeburn 10537: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10538: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10539: '<table><tr><td>'."\n";
10540: foreach my $option ('original','recaptcha','notused') {
10541: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10542: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10543: $lt{$option}.'</label></span>';
10544: unless ($option eq 'notused') {
10545: $output .= (' 'x2)."\n";
10546: }
10547: }
10548: #
10549: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10550: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10551: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10552: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10553: #
1.165 raeburn 10554: $output .= '</td></tr>'."\n".
1.305 raeburn 10555: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10556: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10557: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10558: $currpub.'" size="40" /></span><br />'."\n".
10559: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10560: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10561: $currpriv.'" size="40" /></span><br />'.
10562: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10563: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10564: $currver.'" size="3" /></span><br />'.
10565: '</td></tr></table>'."\n".
1.165 raeburn 10566: '</td></tr>';
10567: return $output;
10568: }
10569:
1.32 raeburn 10570: sub user_formats_row {
1.305 raeburn 10571: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10572: my $output;
10573: my %text = (
10574: 'username' => 'new usernames',
10575: 'id' => 'IDs',
10576: );
1.409 raeburn 10577: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10578: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10579: $output = '<tr '.$css_class.'>'.
10580: '<td><span class="LC_nobreak">'.
10581: &mt("Format rules to check for $text{$type}: ").
10582: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10583: }
1.27 raeburn 10584: my $rem;
10585: if (ref($ruleorder) eq 'ARRAY') {
10586: for (my $i=0; $i<@{$ruleorder}; $i++) {
10587: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10588: my $rem = $i%($numinrow);
10589: if ($rem == 0) {
10590: if ($i > 0) {
10591: $output .= '</tr>';
10592: }
10593: $output .= '<tr>';
10594: }
10595: my $check = ' ';
1.39 raeburn 10596: if (ref($settings) eq 'HASH') {
10597: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10598: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10599: $check = ' checked="checked" ';
10600: }
1.305 raeburn 10601: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10602: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10603: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10604: $check = ' checked="checked" ';
10605: }
10606: }
1.27 raeburn 10607: }
10608: }
1.305 raeburn 10609: my $name = $type.'_rule';
10610: if ($type eq 'email') {
10611: $name .= '_'.$status;
10612: }
1.27 raeburn 10613: $output .= '<td class="LC_left_item">'.
10614: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10615: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10616: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10617: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10618: }
10619: }
10620: $rem = @{$ruleorder}%($numinrow);
10621: }
1.305 raeburn 10622: my $colsleft;
10623: if ($rem) {
10624: $colsleft = $numinrow - $rem;
10625: }
1.27 raeburn 10626: if ($colsleft > 1 ) {
10627: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10628: ' </td>';
10629: } elsif ($colsleft == 1) {
10630: $output .= '<td class="LC_left_item"> </td>';
10631: }
1.409 raeburn 10632: $output .= '</tr>';
10633: unless (($type eq 'email') || ($type eq 'unamemap')) {
10634: $output .= '</table></td></tr>';
1.305 raeburn 10635: }
1.27 raeburn 10636: return $output;
10637: }
10638:
1.34 raeburn 10639: sub usercreation_types {
10640: my %lt = &Apache::lonlocal::texthash (
10641: author => 'When adding a co-author',
10642: course => 'When adding a user to a course',
1.100 raeburn 10643: requestcrs => 'When requesting a course',
1.34 raeburn 10644: any => 'Any',
10645: official => 'Institutional only ',
10646: unofficial => 'Non-institutional only',
10647: none => 'None',
10648: );
10649: return %lt;
1.48 raeburn 10650: }
1.34 raeburn 10651:
1.224 raeburn 10652: sub selfcreation_types {
10653: my %lt = &Apache::lonlocal::texthash (
10654: selfcreate => 'User creates own account',
10655: any => 'Any',
10656: official => 'Institutional only ',
10657: unofficial => 'Non-institutional only',
10658: email => 'E-mail address',
10659: login => 'Institutional Login',
10660: sso => 'SSO',
10661: );
10662: }
10663:
1.28 raeburn 10664: sub authtype_names {
10665: my %lt = &Apache::lonlocal::texthash(
10666: int => 'Internal',
10667: krb4 => 'Kerberos 4',
10668: krb5 => 'Kerberos 5',
10669: loc => 'Local',
1.325 raeburn 10670: lti => 'LTI',
1.28 raeburn 10671: );
10672: return %lt;
10673: }
10674:
10675: sub context_names {
10676: my %context_title = &Apache::lonlocal::texthash(
10677: author => 'Creating users when an Author',
10678: course => 'Creating users when in a course',
10679: domain => 'Creating users when a Domain Coordinator',
10680: );
10681: return %context_title;
10682: }
10683:
1.33 raeburn 10684: sub print_usermodification {
10685: my ($position,$dom,$settings,$rowtotal) = @_;
10686: my $numinrow = 4;
10687: my ($context,$datatable,$rowcount);
10688: if ($position eq 'top') {
10689: $rowcount = 0;
10690: $context = 'author';
10691: foreach my $role ('ca','aa') {
10692: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10693: $numinrow,$rowcount);
10694: $$rowtotal ++;
10695: $rowcount ++;
10696: }
1.443 raeburn 10697: } elsif ($position eq 'middle') {
10698: $rowcount = 0;
10699: $context = 'coauthor';
10700: foreach my $role ('ca','aa') {
10701: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10702: $numinrow,$rowcount);
10703: $$rowtotal ++;
10704: $rowcount ++;
10705: }
1.230 raeburn 10706: } elsif ($position eq 'bottom') {
1.33 raeburn 10707: $context = 'course';
10708: $rowcount = 0;
10709: foreach my $role ('st','ep','ta','in','cr') {
10710: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10711: $numinrow,$rowcount);
10712: $$rowtotal ++;
10713: $rowcount ++;
10714: }
10715: }
10716: return $datatable;
10717: }
10718:
1.43 raeburn 10719: sub print_defaults {
1.236 raeburn 10720: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10721: my $rownum = 0;
1.294 raeburn 10722: my ($datatable,$css_class,$titles);
10723: unless ($position eq 'bottom') {
10724: $titles = &defaults_titles($dom);
10725: }
1.236 raeburn 10726: if ($position eq 'top') {
10727: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10728: 'datelocale_def','portal_def');
10729: my %defaults;
10730: if (ref($settings) eq 'HASH') {
10731: %defaults = %{$settings};
1.43 raeburn 10732: } else {
1.236 raeburn 10733: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10734: foreach my $item (@items) {
10735: $defaults{$item} = $domdefaults{$item};
10736: }
1.43 raeburn 10737: }
1.236 raeburn 10738: foreach my $item (@items) {
10739: if ($rownum%2) {
10740: $css_class = '';
10741: } else {
10742: $css_class = ' class="LC_odd_row" ';
10743: }
10744: $datatable .= '<tr'.$css_class.'>'.
10745: '<td><span class="LC_nobreak">'.$titles->{$item}.
10746: '</span></td><td class="LC_right_item" colspan="3">';
10747: if ($item eq 'auth_def') {
1.325 raeburn 10748: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10749: my %shortauth = (
10750: internal => 'int',
10751: krb4 => 'krb4',
10752: krb5 => 'krb5',
1.325 raeburn 10753: localauth => 'loc',
10754: lti => 'lti',
1.236 raeburn 10755: );
10756: my %authnames = &authtype_names();
10757: foreach my $auth (@authtypes) {
10758: my $checked = ' ';
10759: if ($defaults{$item} eq $auth) {
10760: $checked = ' checked="checked" ';
10761: }
10762: $datatable .= '<label><input type="radio" name="'.$item.
10763: '" value="'.$auth.'"'.$checked.'/>'.
10764: $authnames{$shortauth{$auth}}.'</label> ';
10765: }
10766: } elsif ($item eq 'timezone_def') {
10767: my $includeempty = 1;
10768: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10769: } elsif ($item eq 'datelocale_def') {
10770: my $includeempty = 1;
10771: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10772: } elsif ($item eq 'lang_def') {
1.263 raeburn 10773: my $includeempty = 1;
10774: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10775: } elsif ($item eq 'portal_def') {
10776: $datatable .= '<input type="text" name="'.$item.'" value="'.
10777: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10778: my $portalsty = 'none';
10779: if ($defaults{$item}) {
10780: $portalsty = 'block';
10781: }
10782: foreach my $field ('email','web') {
10783: my $checkedoff = ' checked="checked"';
10784: my $checkedon;
10785: if ($defaults{$item.'_'.$field}) {
10786: $checkedon = $checkedoff;
10787: $checkedoff = '';
1.425 raeburn 10788: }
1.414 raeburn 10789: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10790: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10791: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10792: (' 'x2).
10793: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10794: '</div>';
10795: }
1.236 raeburn 10796: } else {
1.414 raeburn 10797: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10798: }
1.236 raeburn 10799: $datatable .= '</td></tr>';
10800: $rownum ++;
10801: }
1.409 raeburn 10802: } elsif ($position eq 'middle') {
1.294 raeburn 10803: my %defaults;
10804: if (ref($settings) eq 'HASH') {
1.354 raeburn 10805: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10806: my $maxnum = @{$settings->{'inststatusorder'}};
10807: for (my $i=0; $i<$maxnum; $i++) {
10808: $css_class = $rownum%2?' class="LC_odd_row"':'';
10809: my $item = $settings->{'inststatusorder'}->[$i];
10810: my $title = $settings->{'inststatustypes'}->{$item};
10811: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10812: $datatable .= '<tr'.$css_class.'>'.
10813: '<td><span class="LC_nobreak">'.
10814: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10815: for (my $k=0; $k<=$maxnum; $k++) {
10816: my $vpos = $k+1;
10817: my $selstr;
10818: if ($k == $i) {
10819: $selstr = ' selected="selected" ';
10820: }
10821: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10822: }
10823: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10824: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10825: &mt('delete').'</span></td>'.
1.380 raeburn 10826: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10827: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10828: '</span></td></tr>';
10829: }
10830: $css_class = $rownum%2?' class="LC_odd_row"':'';
10831: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10832: $datatable .= '<tr '.$css_class.'>'.
10833: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10834: for (my $k=0; $k<=$maxnum; $k++) {
10835: my $vpos = $k+1;
10836: my $selstr;
10837: if ($k == $maxnum) {
10838: $selstr = ' selected="selected" ';
10839: }
10840: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10841: }
10842: $datatable .= '</select> '.&mt('Internal ID:').
10843: '<input type="text" size="10" name="addinststatus" value="" />'.
10844: ' '.&mt('(new)').
10845: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10846: &mt('Name displayed').':'.
1.354 raeburn 10847: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10848: '</tr>'."\n";
10849: $rownum ++;
1.294 raeburn 10850: }
1.354 raeburn 10851: }
1.409 raeburn 10852: } else {
10853: my ($unamemaprules,$ruleorder) =
10854: &Apache::lonnet::inst_userrules($dom,'unamemap');
10855: $css_class = $rownum%2?' class="LC_odd_row"':'';
10856: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10857: my $numinrow = 2;
10858: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10859: &user_formats_row('unamemap',$settings,$unamemaprules,
10860: $ruleorder,$numinrow).
10861: '</table></td></tr>';
10862: }
10863: if ($datatable eq '') {
10864: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10865: &mt('No rules set for domain in customized localenroll.pm').
10866: '</td></tr>';
10867: }
1.354 raeburn 10868: }
10869: $$rowtotal += $rownum;
1.43 raeburn 10870: return $datatable;
10871: }
10872:
1.168 raeburn 10873: sub get_languages_hash {
10874: my %langchoices;
10875: foreach my $id (&Apache::loncommon::languageids()) {
10876: my $code = &Apache::loncommon::supportedlanguagecode($id);
10877: if ($code ne '') {
10878: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10879: }
10880: }
10881: return %langchoices;
10882: }
10883:
1.43 raeburn 10884: sub defaults_titles {
1.141 raeburn 10885: my ($dom) = @_;
1.43 raeburn 10886: my %titles = &Apache::lonlocal::texthash (
10887: 'auth_def' => 'Default authentication type',
10888: 'auth_arg_def' => 'Default authentication argument',
10889: 'lang_def' => 'Default language',
1.54 raeburn 10890: 'timezone_def' => 'Default timezone',
1.68 raeburn 10891: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10892: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10893: 'email' => 'Email links use portal URL',
10894: 'web' => 'Public web links use portal URL',
1.294 raeburn 10895: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10896: 'intauth_check' => 'Check bcrypt cost if authenticated',
10897: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10898: );
1.141 raeburn 10899: if ($dom) {
10900: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10901: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10902: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10903: $protocol = 'http' if ($protocol ne 'https');
10904: if ($uint_dom) {
10905: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10906: $uint_dom);
10907: }
10908: }
1.43 raeburn 10909: return (\%titles);
10910: }
10911:
1.346 raeburn 10912: sub print_scantron {
10913: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10914: if ($position eq 'top') {
10915: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10916: } else {
10917: return &print_scantronconfig($dom,$settings,\$rowtotal);
10918: }
10919: }
10920:
10921: sub scantron_javascript {
10922: return <<"ENDSCRIPT";
10923:
10924: <script type="text/javascript">
10925: // <![CDATA[
10926:
10927: function toggleScantron(form) {
1.347 raeburn 10928: var csvfieldset = new Array();
1.346 raeburn 10929: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10930: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10931: }
10932: if (document.getElementById('scantroncsv_options')) {
10933: csvfieldset.push(document.getElementById('scantroncsv_options'));
10934: }
10935: if (csvfieldset.length) {
1.346 raeburn 10936: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10937: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10938: if (scantroncsv.checked) {
1.347 raeburn 10939: for (var i=0; i<csvfieldset.length; i++) {
10940: csvfieldset[i].style.display = 'block';
10941: }
1.346 raeburn 10942: } else {
1.347 raeburn 10943: for (var i=0; i<csvfieldset.length; i++) {
10944: csvfieldset[i].style.display = 'none';
10945: }
1.346 raeburn 10946: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10947: if (csvselects.length) {
10948: for (var j=0; j<csvselects.length; j++) {
10949: csvselects[j].selectedIndex = 0;
10950: }
10951: }
10952: }
10953: }
10954: }
10955: return;
10956: }
10957: // ]]>
10958: </script>
10959:
10960: ENDSCRIPT
10961:
10962: }
10963:
1.46 raeburn 10964: sub print_scantronformat {
10965: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10966: my $itemcount = 1;
1.60 raeburn 10967: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10968: %confhash);
1.46 raeburn 10969: my $switchserver = &check_switchserver($dom,$confname);
10970: my %lt = &Apache::lonlocal::texthash (
1.95 www 10971: default => 'Default bubblesheet format file error',
10972: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10973: );
10974: my %scantronfiles = (
10975: default => 'default.tab',
10976: custom => 'custom.tab',
10977: );
10978: foreach my $key (keys(%scantronfiles)) {
10979: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10980: .$scantronfiles{$key};
10981: }
10982: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10983: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10984: if (!$switchserver) {
10985: my $servadm = $r->dir_config('lonAdmEMail');
10986: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10987: if ($configuserok eq 'ok') {
10988: if ($author_ok eq 'ok') {
10989: my %legacyfile = (
1.346 raeburn 10990: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10991: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10992: );
10993: my %md5chk;
10994: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10995: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10996: chomp($md5chk{$type});
1.46 raeburn 10997: }
10998: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10999: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 11000: ($scantronurls{$type},my $error) =
1.46 raeburn 11001: &legacy_scantronformat($r,$dom,$confname,
11002: $type,$legacyfile{$type},
11003: $scantronurls{$type},
11004: $scantronfiles{$type});
1.60 raeburn 11005: if ($error ne '') {
11006: $error{$type} = $error;
11007: }
11008: }
11009: if (keys(%error) == 0) {
11010: $is_custom = 1;
1.346 raeburn 11011: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 11012: $scantronurls{'custom'};
1.346 raeburn 11013: my $putresult =
1.60 raeburn 11014: &Apache::lonnet::put_dom('configuration',
11015: \%confhash,$dom);
11016: if ($putresult ne 'ok') {
1.346 raeburn 11017: $error{'custom'} =
1.60 raeburn 11018: '<span class="LC_error">'.
11019: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11020: }
1.46 raeburn 11021: }
11022: } else {
1.60 raeburn 11023: ($scantronurls{'default'},my $error) =
1.46 raeburn 11024: &legacy_scantronformat($r,$dom,$confname,
11025: 'default',$legacyfile{'default'},
11026: $scantronurls{'default'},
11027: $scantronfiles{'default'});
1.60 raeburn 11028: if ($error eq '') {
11029: $confhash{'scantron'}{'scantronformat'} = '';
11030: my $putresult =
11031: &Apache::lonnet::put_dom('configuration',
11032: \%confhash,$dom);
11033: if ($putresult ne 'ok') {
11034: $error{'default'} =
11035: '<span class="LC_error">'.
11036: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11037: }
11038: } else {
11039: $error{'default'} = $error;
11040: }
1.46 raeburn 11041: }
11042: }
11043: }
11044: } else {
1.95 www 11045: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 11046: }
11047: }
11048: if (ref($settings) eq 'HASH') {
11049: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
11050: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
11051: if ((!@info) || ($info[0] eq 'no_such_dir')) {
11052: $scantronurl = '';
11053: } else {
11054: $scantronurl = $settings->{'scantronformat'};
11055: }
11056: $is_custom = 1;
11057: } else {
11058: $scantronurl = $scantronurls{'default'};
11059: }
11060: } else {
1.60 raeburn 11061: if ($is_custom) {
11062: $scantronurl = $scantronurls{'custom'};
11063: } else {
11064: $scantronurl = $scantronurls{'default'};
11065: }
1.46 raeburn 11066: }
11067: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11068: $datatable .= '<tr'.$css_class.'>';
11069: if (!$is_custom) {
1.65 raeburn 11070: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
11071: '<span class="LC_nobreak">';
1.46 raeburn 11072: if ($scantronurl) {
1.199 raeburn 11073: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
11074: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 11075: } else {
11076: $datatable = &mt('File unavailable for display');
11077: }
1.65 raeburn 11078: $datatable .= '</span></td>';
1.60 raeburn 11079: if (keys(%error) == 0) {
1.306 raeburn 11080: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 11081: if (!$switchserver) {
11082: $datatable .= &mt('Upload:').'<br />';
11083: }
11084: } else {
11085: my $errorstr;
11086: foreach my $key (sort(keys(%error))) {
11087: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11088: }
11089: $datatable .= '<td>'.$errorstr;
11090: }
1.46 raeburn 11091: } else {
11092: if (keys(%error) > 0) {
11093: my $errorstr;
11094: foreach my $key (sort(keys(%error))) {
11095: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11096: }
1.60 raeburn 11097: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 11098: } elsif ($scantronurl) {
1.199 raeburn 11099: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
11100: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 11101: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 11102: $link.
11103: '<label><input type="checkbox" name="scantronformat_del"'.
11104: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 11105: '<td><span class="LC_nobreak"> '.
11106: &mt('Replace:').'</span><br />';
1.46 raeburn 11107: }
11108: }
11109: if (keys(%error) == 0) {
11110: if ($switchserver) {
11111: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
11112: } else {
1.65 raeburn 11113: $datatable .='<span class="LC_nobreak"> '.
11114: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11115: }
11116: }
11117: $datatable .= '</td></tr>';
11118: $$rowtotal ++;
11119: return $datatable;
11120: }
11121:
11122: sub legacy_scantronformat {
11123: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11124: my ($url,$error);
11125: my @statinfo = &Apache::lonnet::stat_file($newurl);
11126: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 11127: my $modified = [];
1.46 raeburn 11128: (my $result,$url) =
1.421 raeburn 11129: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
11130: 'scantron','','',$newfile,$modified);
11131: if ($result eq 'ok') {
11132: &update_modify_urls($r,$modified);
11133: } else {
1.130 raeburn 11134: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11135: }
11136: }
11137: return ($url,$error);
11138: }
1.43 raeburn 11139:
1.346 raeburn 11140: sub print_scantronconfig {
11141: my ($dom,$settings,$rowtotal) = @_;
11142: my $itemcount = 2;
11143: my $is_checked = ' checked="checked"';
1.347 raeburn 11144: my %optionson = (
11145: hdr => ' checked="checked"',
11146: pad => ' checked="checked"',
11147: rem => ' checked="checked"',
11148: );
11149: my %optionsoff = (
11150: hdr => '',
11151: pad => '',
11152: rem => '',
11153: );
1.346 raeburn 11154: my $currcsvsty = 'none';
1.347 raeburn 11155: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11156: my @fields = &scantroncsv_fields();
11157: my %titles = &scantronconfig_titles();
11158: if (ref($settings) eq 'HASH') {
11159: if (ref($settings->{config}) eq 'HASH') {
11160: if ($settings->{config}->{dat}) {
11161: $checked{'dat'} = $is_checked;
11162: }
11163: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11164: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11165: %csvfields = %{$settings->{config}->{csv}->{fields}};
11166: if (keys(%csvfields) > 0) {
11167: $checked{'csv'} = $is_checked;
11168: $currcsvsty = 'block';
11169: }
11170: }
11171: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11172: %csvoptions = %{$settings->{config}->{csv}->{options}};
11173: foreach my $option (keys(%optionson)) {
11174: unless ($csvoptions{$option}) {
11175: $optionsoff{$option} = $optionson{$option};
11176: $optionson{$option} = '';
11177: }
11178: }
1.346 raeburn 11179: }
11180: }
11181: } else {
11182: $checked{'dat'} = $is_checked;
11183: }
11184: } else {
11185: $checked{'dat'} = $is_checked;
11186: }
11187: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11188: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11189: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11190: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11191: foreach my $item ('dat','csv') {
11192: my $id;
11193: if ($item eq 'csv') {
11194: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11195: }
1.346 raeburn 11196: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11197: $titles{$item}.'</label>'.(' 'x3);
11198: if ($item eq 'csv') {
11199: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11200: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11201: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11202: foreach my $col (@fields) {
11203: my $selnone;
11204: if ($csvfields{$col} eq '') {
11205: $selnone = ' selected="selected"';
11206: }
11207: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11208: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11209: '<option value=""'.$selnone.'></option>';
11210: for (my $i=0; $i<20; $i++) {
11211: my $shown = $i+1;
11212: my $sel;
11213: unless ($selnone) {
11214: if (exists($csvfields{$col})) {
11215: if ($csvfields{$col} == $i) {
11216: $sel = ' selected="selected"';
11217: }
11218: }
11219: }
11220: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11221: }
11222: $datatable .= '</select></td></tr>';
11223: }
1.347 raeburn 11224: $datatable .= '</table></fieldset>'.
11225: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11226: '<legend>'.&mt('CSV Options').'</legend>';
11227: foreach my $option ('hdr','pad','rem') {
11228: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11229: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11230: &mt('Yes').'</label>'.(' 'x2)."\n".
11231: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11232: }
11233: $datatable .= '</fieldset>';
1.346 raeburn 11234: $itemcount ++;
11235: }
11236: }
11237: $datatable .= '</td></tr>';
11238: $$rowtotal ++;
11239: return $datatable;
11240: }
11241:
11242: sub scantronconfig_titles {
11243: return &Apache::lonlocal::texthash(
11244: dat => 'Standard format (.dat)',
11245: csv => 'Comma separated values (.csv)',
1.347 raeburn 11246: hdr => 'Remove first line in file (contains column titles)',
11247: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11248: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11249: CODE => 'CODE',
11250: ID => 'Student ID',
11251: PaperID => 'Paper ID',
11252: FirstName => 'First Name',
11253: LastName => 'Last Name',
11254: FirstQuestion => 'First Question Response',
11255: Section => 'Section',
11256: );
11257: }
11258:
11259: sub scantroncsv_fields {
11260: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11261: }
11262:
1.49 raeburn 11263: sub print_coursecategories {
1.57 raeburn 11264: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11265: my $datatable;
11266: if ($position eq 'top') {
1.238 raeburn 11267: my (%checked);
11268: my @catitems = ('unauth','auth');
11269: my @cattypes = ('std','domonly','codesrch','none');
11270: $checked{'unauth'} = 'std';
11271: $checked{'auth'} = 'std';
11272: if (ref($settings) eq 'HASH') {
11273: foreach my $type (@cattypes) {
11274: if ($type eq $settings->{'unauth'}) {
11275: $checked{'unauth'} = $type;
11276: }
11277: if ($type eq $settings->{'auth'}) {
11278: $checked{'auth'} = $type;
11279: }
11280: }
11281: }
11282: my %lt = &Apache::lonlocal::texthash (
11283: unauth => 'Catalog type for unauthenticated users',
11284: auth => 'Catalog type for authenticated users',
11285: none => 'No catalog',
11286: std => 'Standard catalog',
11287: domonly => 'Domain-only catalog',
11288: codesrch => "Code search form",
11289: );
11290: my $itemcount = 0;
11291: foreach my $item (@catitems) {
11292: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11293: $datatable .= '<tr '.$css_class.'>'.
11294: '<td>'.$lt{$item}.'</td>'.
11295: '<td class="LC_right_item"><span class="LC_nobreak">';
11296: foreach my $type (@cattypes) {
11297: my $ischecked;
11298: if ($checked{$item} eq $type) {
11299: $ischecked=' checked="checked"';
11300: }
11301: $datatable .= '<label>'.
11302: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11303: ' />'.$lt{$type}.'</label> ';
11304: }
1.327 raeburn 11305: $datatable .= '</span></td></tr>';
1.238 raeburn 11306: $itemcount ++;
11307: }
11308: $$rowtotal += $itemcount;
11309: } elsif ($position eq 'middle') {
1.57 raeburn 11310: my $toggle_cats_crs = ' ';
11311: my $toggle_cats_dom = ' checked="checked" ';
11312: my $can_cat_crs = ' ';
11313: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11314: my $toggle_catscomm_comm = ' ';
11315: my $toggle_catscomm_dom = ' checked="checked" ';
11316: my $can_catcomm_comm = ' ';
11317: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11318: my $toggle_catsplace_place = ' ';
11319: my $toggle_catsplace_dom = ' checked="checked" ';
11320: my $can_catplace_place = ' ';
11321: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11322:
1.57 raeburn 11323: if (ref($settings) eq 'HASH') {
11324: if ($settings->{'togglecats'} eq 'crs') {
11325: $toggle_cats_crs = $toggle_cats_dom;
11326: $toggle_cats_dom = ' ';
11327: }
11328: if ($settings->{'categorize'} eq 'crs') {
11329: $can_cat_crs = $can_cat_dom;
11330: $can_cat_dom = ' ';
11331: }
1.120 raeburn 11332: if ($settings->{'togglecatscomm'} eq 'comm') {
11333: $toggle_catscomm_comm = $toggle_catscomm_dom;
11334: $toggle_catscomm_dom = ' ';
11335: }
11336: if ($settings->{'categorizecomm'} eq 'comm') {
11337: $can_catcomm_comm = $can_catcomm_dom;
11338: $can_catcomm_dom = ' ';
11339: }
1.272 raeburn 11340: if ($settings->{'togglecatsplace'} eq 'place') {
11341: $toggle_catsplace_place = $toggle_catsplace_dom;
11342: $toggle_catsplace_dom = ' ';
11343: }
11344: if ($settings->{'categorizeplace'} eq 'place') {
11345: $can_catplace_place = $can_catplace_dom;
11346: $can_catplace_dom = ' ';
11347: }
1.57 raeburn 11348: }
11349: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11350: togglecats => 'Show/Hide a course in catalog',
11351: togglecatscomm => 'Show/Hide a community in catalog',
11352: togglecatsplace => 'Show/Hide a placement test in catalog',
11353: categorize => 'Assign a category to a course',
11354: categorizecomm => 'Assign a category to a community',
11355: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11356: );
11357: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11358: dom => 'Set in Domain',
11359: crs => 'Set in Course',
11360: comm => 'Set in Community',
11361: place => 'Set in Placement Test',
1.57 raeburn 11362: );
11363: $datatable = '<tr class="LC_odd_row">'.
11364: '<td>'.$title{'togglecats'}.'</td>'.
11365: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11366: '<input type="radio" name="togglecats"'.
11367: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11368: '<label><input type="radio" name="togglecats"'.
11369: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11370: '</tr><tr>'.
11371: '<td>'.$title{'categorize'}.'</td>'.
11372: '<td class="LC_right_item"><span class="LC_nobreak">'.
11373: '<label><input type="radio" name="categorize"'.
11374: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11375: '<label><input type="radio" name="categorize"'.
11376: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11377: '</tr><tr class="LC_odd_row">'.
11378: '<td>'.$title{'togglecatscomm'}.'</td>'.
11379: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11380: '<input type="radio" name="togglecatscomm"'.
11381: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11382: '<label><input type="radio" name="togglecatscomm"'.
11383: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11384: '</tr><tr>'.
11385: '<td>'.$title{'categorizecomm'}.'</td>'.
11386: '<td class="LC_right_item"><span class="LC_nobreak">'.
11387: '<label><input type="radio" name="categorizecomm"'.
11388: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11389: '<label><input type="radio" name="categorizecomm"'.
11390: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11391: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11392: '<td>'.$title{'togglecatsplace'}.'</td>'.
11393: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11394: '<input type="radio" name="togglecatsplace"'.
11395: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11396: '<label><input type="radio" name="togglecatscomm"'.
11397: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11398: '</tr><tr>'.
11399: '<td>'.$title{'categorizeplace'}.'</td>'.
11400: '<td class="LC_right_item"><span class="LC_nobreak">'.
11401: '<label><input type="radio" name="categorizeplace"'.
11402: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11403: '<label><input type="radio" name="categorizeplace"'.
11404: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11405: '</tr>';
1.272 raeburn 11406: $$rowtotal += 6;
1.57 raeburn 11407: } else {
11408: my $css_class;
11409: my $itemcount = 1;
11410: my $cathash;
11411: if (ref($settings) eq 'HASH') {
11412: $cathash = $settings->{'cats'};
11413: }
11414: if (ref($cathash) eq 'HASH') {
11415: my (@cats,@trails,%allitems,%idx,@jsarray);
11416: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11417: \%allitems,\%idx,\@jsarray);
11418: my $maxdepth = scalar(@cats);
11419: my $colattrib = '';
11420: if ($maxdepth > 2) {
11421: $colattrib = ' colspan="2" ';
11422: }
11423: my @path;
11424: if (@cats > 0) {
11425: if (ref($cats[0]) eq 'ARRAY') {
11426: my $numtop = @{$cats[0]};
11427: my $maxnum = $numtop;
1.120 raeburn 11428: my %default_names = (
11429: instcode => &mt('Official courses'),
11430: communities => &mt('Communities'),
1.272 raeburn 11431: placement => &mt('Placement Tests'),
1.120 raeburn 11432: );
11433:
11434: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11435: ($cathash->{'instcode::0'} eq '') ||
11436: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11437: ($cathash->{'communities::0'} eq '') ||
11438: (!grep(/^placement$/,@{$cats[0]})) ||
11439: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11440: $maxnum ++;
11441: }
11442: my $lastidx;
11443: for (my $i=0; $i<$numtop; $i++) {
11444: my $parent = $cats[0][$i];
11445: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11446: my $item = &escape($parent).'::0';
11447: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11448: $lastidx = $idx{$item};
11449: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11450: .'<select name="'.$item.'"'.$chgstr.'>';
11451: for (my $k=0; $k<=$maxnum; $k++) {
11452: my $vpos = $k+1;
11453: my $selstr;
11454: if ($k == $i) {
11455: $selstr = ' selected="selected" ';
11456: }
11457: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11458: }
1.214 raeburn 11459: $datatable .= '</select></span></td><td>';
1.272 raeburn 11460: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11461: $datatable .= '<span class="LC_nobreak">'
11462: .$default_names{$parent}.'</span>';
11463: if ($parent eq 'instcode') {
11464: $datatable .= '<br /><span class="LC_nobreak">('
11465: .&mt('with institutional codes')
11466: .')</span></td><td'.$colattrib.'>';
11467: } else {
11468: $datatable .= '<table><tr><td>';
11469: }
11470: $datatable .= '<span class="LC_nobreak">'
11471: .'<label><input type="radio" name="'
11472: .$parent.'" value="1" checked="checked" />'
11473: .&mt('Display').'</label>';
11474: if ($parent eq 'instcode') {
11475: $datatable .= ' ';
11476: } else {
11477: $datatable .= '</span></td></tr><tr><td>'
11478: .'<span class="LC_nobreak">';
11479: }
11480: $datatable .= '<label><input type="radio" name="'
11481: .$parent.'" value="0" />'
11482: .&mt('Do not display').'</label></span>';
1.272 raeburn 11483: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11484: $datatable .= '</td></tr></table>';
11485: }
11486: $datatable .= '</td>';
1.57 raeburn 11487: } else {
11488: $datatable .= $parent
1.214 raeburn 11489: .' <span class="LC_nobreak"><label>'
11490: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11491: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11492: }
11493: my $depth = 1;
11494: push(@path,$parent);
11495: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11496: pop(@path);
11497: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11498: $itemcount ++;
11499: }
1.48 raeburn 11500: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11501: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11502: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11503: for (my $k=0; $k<=$maxnum; $k++) {
11504: my $vpos = $k+1;
11505: my $selstr;
1.57 raeburn 11506: if ($k == $numtop) {
1.48 raeburn 11507: $selstr = ' selected="selected" ';
11508: }
11509: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11510: }
1.59 bisitz 11511: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11512: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11513: .'</tr>'."\n";
1.48 raeburn 11514: $itemcount ++;
1.272 raeburn 11515: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11516: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11517: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11518: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11519: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11520: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11521: for (my $k=0; $k<=$maxnum; $k++) {
11522: my $vpos = $k+1;
11523: my $selstr;
11524: if ($k == $maxnum) {
11525: $selstr = ' selected="selected" ';
11526: }
11527: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11528: }
1.120 raeburn 11529: $datatable .= '</select></span></td>'.
11530: '<td><span class="LC_nobreak">'.
11531: $default_names{$default}.'</span>';
11532: if ($default eq 'instcode') {
11533: $datatable .= '<br /><span class="LC_nobreak">('
11534: .&mt('with institutional codes').')</span>';
11535: }
11536: $datatable .= '</td>'
11537: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11538: .&mt('Display').'</label> '
11539: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11540: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11541: }
11542: }
11543: }
1.57 raeburn 11544: } else {
11545: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11546: }
11547: } else {
1.327 raeburn 11548: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11549: .&initialize_categories($itemcount);
1.48 raeburn 11550: }
1.57 raeburn 11551: $$rowtotal += $itemcount;
1.48 raeburn 11552: }
11553: return $datatable;
11554: }
11555:
1.69 raeburn 11556: sub print_serverstatuses {
11557: my ($dom,$settings,$rowtotal) = @_;
11558: my $datatable;
11559: my @pages = &serverstatus_pages();
11560: my (%namedaccess,%machineaccess);
11561: foreach my $type (@pages) {
11562: $namedaccess{$type} = '';
11563: $machineaccess{$type}= '';
11564: }
11565: if (ref($settings) eq 'HASH') {
11566: foreach my $type (@pages) {
11567: if (exists($settings->{$type})) {
11568: if (ref($settings->{$type}) eq 'HASH') {
11569: foreach my $key (keys(%{$settings->{$type}})) {
11570: if ($key eq 'namedusers') {
11571: $namedaccess{$type} = $settings->{$type}->{$key};
11572: } elsif ($key eq 'machines') {
11573: $machineaccess{$type} = $settings->{$type}->{$key};
11574: }
11575: }
11576: }
11577: }
11578: }
11579: }
1.81 raeburn 11580: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11581: my $rownum = 0;
11582: my $css_class;
11583: foreach my $type (@pages) {
11584: $rownum ++;
11585: $css_class = $rownum%2?' class="LC_odd_row"':'';
11586: $datatable .= '<tr'.$css_class.'>'.
11587: '<td><span class="LC_nobreak">'.
11588: $titles->{$type}.'</span></td>'.
11589: '<td class="LC_left_item">'.
11590: '<input type="text" name="'.$type.'_namedusers" '.
11591: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11592: '<td class="LC_right_item">'.
11593: '<span class="LC_nobreak">'.
11594: '<input type="text" name="'.$type.'_machines" '.
11595: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11596: '</span></td></tr>'."\n";
1.69 raeburn 11597: }
11598: $$rowtotal += $rownum;
11599: return $datatable;
11600: }
11601:
11602: sub serverstatus_pages {
11603: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11604: 'checksums','clusterstatus','certstatus','metadata_keywords',
11605: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11606: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11607: }
11608:
1.236 raeburn 11609: sub defaults_javascript {
11610: my ($settings) = @_;
1.354 raeburn 11611: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11612: my $portal_js = <<"ENDPORTAL";
11613:
11614: function portalExtras(caller) {
11615: var x = caller.value;
11616: var y = new Array('email','web');
1.425 raeburn 11617: for (var i=0; i<y.length; i++) {
1.414 raeburn 11618: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11619: var z = document.getElementById('portal_def_'+y[i]+'_div');
11620: if (x.length > 0) {
11621: z.style.display = 'block';
11622: } else {
11623: z.style.display = 'none';
11624: }
11625: }
11626: }
11627: }
11628: ENDPORTAL
1.236 raeburn 11629: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11630: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11631: if ($maxnum eq '') {
11632: $maxnum = 0;
11633: }
11634: $maxnum ++;
1.249 raeburn 11635: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11636: return <<"ENDSCRIPT";
11637: <script type="text/javascript">
11638: // <![CDATA[
11639: function reorderTypes(form,caller) {
11640: var changedVal;
11641: $jstext
11642: var newpos = 'addinststatus_pos';
11643: var current = new Array;
11644: var maxh = $maxnum;
11645: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11646: var oldVal;
11647: if (caller == newpos) {
11648: changedVal = newitemVal;
11649: } else {
11650: var curritem = 'inststatus_pos_'+caller;
11651: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11652: current[newitemVal] = newpos;
11653: }
11654: for (var i=0; i<inststatuses.length; i++) {
11655: if (inststatuses[i] != caller) {
11656: var elementName = 'inststatus_pos_'+inststatuses[i];
11657: if (form.elements[elementName]) {
11658: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11659: current[currVal] = elementName;
11660: }
11661: }
11662: }
11663: for (var j=0; j<maxh; j++) {
11664: if (current[j] == undefined) {
11665: oldVal = j;
11666: }
11667: }
11668: if (oldVal < changedVal) {
11669: for (var k=oldVal+1; k<=changedVal ; k++) {
11670: var elementName = current[k];
11671: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11672: }
11673: } else {
11674: for (var k=changedVal; k<oldVal; k++) {
11675: var elementName = current[k];
11676: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11677: }
11678: }
11679: return;
11680: }
11681:
1.414 raeburn 11682: $portal_js
11683:
11684: // ]]>
11685: </script>
11686:
11687: ENDSCRIPT
11688: } else {
11689: return <<"ENDSCRIPT";
11690: <script type="text/javascript">
11691: // <![CDATA[
11692: $portal_js
1.236 raeburn 11693: // ]]>
11694: </script>
11695:
11696: ENDSCRIPT
11697: }
1.354 raeburn 11698: return;
11699: }
11700:
11701: sub passwords_javascript {
1.405 raeburn 11702: my ($prefix) = @_;
11703: my %intalert;
11704: if ($prefix eq 'passwords') {
11705: %intalert = &Apache::lonlocal::texthash (
11706: 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.',
11707: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11708: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11709: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11710: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11711: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11712: );
1.421 raeburn 11713: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11714: %intalert = &Apache::lonlocal::texthash (
11715: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11716: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11717: );
11718: }
1.365 raeburn 11719: &js_escape(\%intalert);
11720: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11721: my $intauthjs;
1.405 raeburn 11722: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11723:
11724: function warnIntAuth(field) {
11725: if (field.name == 'intauth_check') {
11726: if (field.value == '2') {
1.365 raeburn 11727: alert('$intalert{authcheck}');
1.354 raeburn 11728: }
11729: }
11730: if (field.name == 'intauth_cost') {
11731: field.value.replace(/\s/g,'');
11732: if (field.value != '') {
11733: var regexdigit=/^\\d+\$/;
11734: if (!regexdigit.test(field.value)) {
1.365 raeburn 11735: alert('$intalert{authcost}');
11736: }
11737: }
11738: }
11739: return;
11740: }
11741:
1.405 raeburn 11742: ENDSCRIPT
11743:
11744: }
11745:
11746: $intauthjs .= <<"ENDSCRIPT";
11747:
11748: function warnInt$prefix(field) {
1.365 raeburn 11749: field.value.replace(/^\s+/,'');
11750: field.value.replace(/\s+\$/,'');
11751: var regexdigit=/^\\d+\$/;
1.408 raeburn 11752: if (field.name == '${prefix}_min') {
1.365 raeburn 11753: if (field.value == '') {
11754: alert('$intalert{passmin}');
11755: field.value = '$defmin';
11756: } else {
11757: if (!regexdigit.test(field.value)) {
11758: alert('$intalert{passmin}');
11759: field.value = '$defmin';
11760: }
1.366 raeburn 11761: var minval = parseInt(field.value,10);
1.365 raeburn 11762: if (minval < $defmin) {
11763: alert('$intalert{passmin}');
11764: field.value = '$defmin';
11765: }
11766: }
11767: } else {
11768: if (field.value == '0') {
11769: field.value = '';
11770: }
11771: if (field.value != '') {
1.408 raeburn 11772: if (field.name == '${prefix}_expire') {
1.365 raeburn 11773: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11774: if (!regexpposnum.test(field.value)) {
11775: alert('$intalert{passexp}');
11776: field.value = '';
11777: } else {
11778: var expval = parseFloat(field.value);
11779: if (expval == 0) {
11780: alert('$intalert{passexp}');
11781: field.value = '';
11782: }
11783: }
11784: } else {
11785: if (!regexdigit.test(field.value)) {
1.408 raeburn 11786: if (field.name == '${prefix}_max') {
1.365 raeburn 11787: alert('$intalert{passmax}');
11788: } else {
1.408 raeburn 11789: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11790: alert('$intalert{passnum}');
11791: }
11792: }
1.370 raeburn 11793: field.value = '';
1.365 raeburn 11794: }
1.354 raeburn 11795: }
11796: }
11797: }
11798: return;
11799: }
11800:
11801: ENDSCRIPT
11802: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11803: }
11804:
1.49 raeburn 11805: sub coursecategories_javascript {
11806: my ($settings) = @_;
1.57 raeburn 11807: my ($output,$jstext,$cathash);
1.49 raeburn 11808: if (ref($settings) eq 'HASH') {
1.57 raeburn 11809: $cathash = $settings->{'cats'};
11810: }
11811: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11812: my (@cats,@jsarray,%idx);
1.57 raeburn 11813: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11814: if (@jsarray > 0) {
11815: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11816: for (my $i=0; $i<@jsarray; $i++) {
11817: if (ref($jsarray[$i]) eq 'ARRAY') {
11818: my $catstr = join('","',@{$jsarray[$i]});
11819: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11820: }
11821: }
11822: }
11823: } else {
11824: $jstext = ' var categories = Array(1);'."\n".
11825: ' categories[0] = Array("instcode_pos");'."\n";
11826: }
1.237 bisitz 11827: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11828: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11829: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11830: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11831: &js_escape(\$instcode_reserved);
11832: &js_escape(\$communities_reserved);
1.272 raeburn 11833: &js_escape(\$placement_reserved);
1.265 damieng 11834: &js_escape(\$choose_again);
1.49 raeburn 11835: $output = <<"ENDSCRIPT";
11836: <script type="text/javascript">
1.109 raeburn 11837: // <![CDATA[
1.49 raeburn 11838: function reorderCats(form,parent,item,idx) {
11839: var changedVal;
11840: $jstext
11841: var newpos = 'addcategory_pos';
11842: if (parent == '') {
11843: var has_instcode = 0;
11844: var maxtop = categories[idx].length;
11845: for (var j=0; j<maxtop; j++) {
11846: if (categories[idx][j] == 'instcode::0') {
11847: has_instcode == 1;
11848: }
11849: }
11850: if (has_instcode == 0) {
11851: categories[idx][maxtop] = 'instcode_pos';
11852: }
11853: } else {
11854: newpos += '_'+parent;
11855: }
11856: var maxh = 1 + categories[idx].length;
11857: var current = new Array;
11858: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11859: if (item == newpos) {
11860: changedVal = newitemVal;
11861: } else {
11862: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11863: current[newitemVal] = newpos;
11864: }
11865: for (var i=0; i<categories[idx].length; i++) {
11866: var elementName = categories[idx][i];
11867: if (elementName != item) {
11868: if (form.elements[elementName]) {
11869: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11870: current[currVal] = elementName;
11871: }
11872: }
11873: }
11874: var oldVal;
11875: for (var j=0; j<maxh; j++) {
11876: if (current[j] == undefined) {
11877: oldVal = j;
11878: }
11879: }
11880: if (oldVal < changedVal) {
11881: for (var k=oldVal+1; k<=changedVal ; k++) {
11882: var elementName = current[k];
11883: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11884: }
11885: } else {
11886: for (var k=changedVal; k<oldVal; k++) {
11887: var elementName = current[k];
11888: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11889: }
11890: }
11891: return;
11892: }
1.120 raeburn 11893:
11894: function categoryCheck(form) {
11895: if (form.elements['addcategory_name'].value == 'instcode') {
11896: alert('$instcode_reserved\\n$choose_again');
11897: return false;
11898: }
11899: if (form.elements['addcategory_name'].value == 'communities') {
11900: alert('$communities_reserved\\n$choose_again');
11901: return false;
11902: }
1.272 raeburn 11903: if (form.elements['addcategory_name'].value == 'placement') {
11904: alert('$placement_reserved\\n$choose_again');
11905: return false;
11906: }
1.120 raeburn 11907: return true;
11908: }
11909:
1.109 raeburn 11910: // ]]>
1.49 raeburn 11911: </script>
11912:
11913: ENDSCRIPT
11914: return $output;
11915: }
11916:
1.48 raeburn 11917: sub initialize_categories {
11918: my ($itemcount) = @_;
1.120 raeburn 11919: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11920: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11921: instcode => 'Official courses (with institutional codes)',
11922: communities => 'Communities',
1.272 raeburn 11923: placement => 'Placement Tests',
1.120 raeburn 11924: );
1.328 raeburn 11925: my %selnum = (
11926: instcode => '0',
11927: communities => '1',
11928: placement => '2',
11929: );
11930: my %selected;
1.272 raeburn 11931: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11932: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11933: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11934: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11935: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11936: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11937: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11938: .'<option value="0"'.$selected{'0'}.'>1</option>'
11939: .'<option value="1"'.$selected{'1'}.'>2</option>'
11940: .'<option value="2"'.$selected{'2'}.'>3</option>'
11941: .'<option value="3">4</option></select> '
1.120 raeburn 11942: .$default_names{$default}
11943: .'</span></td><td><span class="LC_nobreak">'
11944: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11945: .&mt('Display').'</label> <label>'
11946: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11947: .'</label></span></td></tr>';
1.120 raeburn 11948: $itemcount ++;
11949: }
1.48 raeburn 11950: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11951: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11952: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11953: .'<select name="addcategory_pos"'.$chgstr.'>'
11954: .'<option value="0">1</option>'
11955: .'<option value="1">2</option>'
1.328 raeburn 11956: .'<option value="2">3</option>'
11957: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11958: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11959: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11960: .'</td></tr>';
1.48 raeburn 11961: return $datatable;
11962: }
11963:
11964: sub build_category_rows {
1.49 raeburn 11965: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11966: my ($text,$name,$item,$chgstr);
1.48 raeburn 11967: if (ref($cats) eq 'ARRAY') {
11968: my $maxdepth = scalar(@{$cats});
11969: if (ref($cats->[$depth]) eq 'HASH') {
11970: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11971: my $numchildren = @{$cats->[$depth]{$parent}};
11972: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11973: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11974: my ($idxnum,$parent_name,$parent_item);
11975: my $higher = $depth - 1;
11976: if ($higher == 0) {
11977: $parent_name = &escape($parent).'::'.$higher;
11978: } else {
11979: if (ref($path) eq 'ARRAY') {
11980: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11981: }
11982: }
11983: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11984: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11985: if ($j < $numchildren) {
1.48 raeburn 11986: $name = $cats->[$depth]{$parent}[$j];
11987: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11988: $idxnum = $idx->{$item};
11989: } else {
11990: $name = $parent_name;
11991: $item = $parent_item;
1.48 raeburn 11992: }
1.49 raeburn 11993: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11994: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11995: for (my $i=0; $i<=$numchildren; $i++) {
11996: my $vpos = $i+1;
11997: my $selstr;
11998: if ($j == $i) {
11999: $selstr = ' selected="selected" ';
12000: }
12001: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
12002: }
12003: $text .= '</select> ';
12004: if ($j < $numchildren) {
12005: my $deeper = $depth+1;
12006: $text .= $name.' '
12007: .'<label><input type="checkbox" name="deletecategory" value="'
12008: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
12009: if(ref($path) eq 'ARRAY') {
12010: push(@{$path},$name);
1.49 raeburn 12011: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 12012: pop(@{$path});
12013: }
12014: } else {
1.330 raeburn 12015: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 12016: if ($j == $numchildren) {
12017: $text .= $name;
12018: } else {
12019: $text .= $item;
12020: }
12021: $text .= '" value="" />';
12022: }
12023: $text .= '</td></tr>';
12024: }
12025: $text .= '</table></td>';
12026: } else {
12027: my $higher = $depth-1;
12028: if ($higher == 0) {
12029: $name = &escape($parent).'::'.$higher;
12030: } else {
12031: if (ref($path) eq 'ARRAY') {
12032: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12033: }
12034: }
12035: my $colspan;
12036: if ($parent ne 'instcode') {
12037: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 12038: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 12039: }
12040: }
12041: }
12042: }
12043: return $text;
12044: }
12045:
1.33 raeburn 12046: sub modifiable_userdata_row {
1.305 raeburn 12047: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 12048: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 12049: my ($role,$rolename,$statustype);
12050: $role = $item;
1.224 raeburn 12051: if ($context eq 'cancreate') {
1.305 raeburn 12052: if ($item =~ /^(emailusername)_(.+)$/) {
12053: $role = $1;
12054: $statustype = $2;
1.228 raeburn 12055: if (ref($usertypes) eq 'HASH') {
12056: if ($usertypes->{$statustype}) {
12057: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
12058: } else {
12059: $rolename = &mt('Data provided by user');
12060: }
12061: }
1.224 raeburn 12062: }
12063: } elsif ($context eq 'selfcreate') {
1.63 raeburn 12064: if (ref($usertypes) eq 'HASH') {
12065: $rolename = $usertypes->{$role};
12066: } else {
12067: $rolename = $role;
12068: }
1.325 raeburn 12069: } elsif ($context eq 'lti') {
12070: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 12071: } elsif ($context eq 'privacy') {
12072: $rolename = $itemdesc;
1.33 raeburn 12073: } else {
1.63 raeburn 12074: if ($role eq 'cr') {
12075: $rolename = &mt('Custom role');
12076: } else {
12077: $rolename = &Apache::lonnet::plaintext($role);
12078: }
1.33 raeburn 12079: }
1.224 raeburn 12080: my (@fields,%fieldtitles);
12081: if (ref($fieldsref) eq 'ARRAY') {
12082: @fields = @{$fieldsref};
12083: } else {
12084: @fields = ('lastname','firstname','middlename','generation',
12085: 'permanentemail','id');
12086: }
12087: if ((ref($titlesref) eq 'HASH')) {
12088: %fieldtitles = %{$titlesref};
12089: } else {
12090: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12091: }
1.33 raeburn 12092: my $output;
1.305 raeburn 12093: my $css_class;
12094: if ($rowcount%2) {
12095: $css_class = 'LC_odd_row';
12096: }
12097: if ($customcss) {
12098: $css_class .= " $customcss";
12099: }
12100: $css_class =~ s/^\s+//;
12101: if ($css_class) {
12102: $css_class = ' class="'.$css_class.'"';
12103: }
12104: if ($rowstyle) {
12105: $css_class .= ' style="'.$rowstyle.'"';
12106: }
12107: if ($rowid) {
12108: $rowid = ' id="'.$rowid.'"';
12109: }
12110: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 12111: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
12112: '<td class="LC_left_item" colspan="2"><table>';
12113: my $rem;
12114: my %checks;
12115: if (ref($settings) eq 'HASH') {
1.325 raeburn 12116: my $hashref;
12117: if ($context eq 'lti') {
12118: if (ref($settings) eq 'HASH') {
12119: $hashref = $settings->{'instdata'};
12120: }
1.357 raeburn 12121: } elsif ($context eq 'privacy') {
12122: my ($key,$inner) = split(/_/,$role);
12123: if (ref($settings) eq 'HASH') {
12124: if (ref($settings->{$key}) eq 'HASH') {
12125: $hashref = $settings->{$key}->{$inner};
12126: }
12127: }
1.325 raeburn 12128: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12129: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 12130: $hashref = $settings->{'lti_instdata'};
12131: }
12132: if ($role eq 'emailusername') {
12133: if ($statustype) {
12134: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12135: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12136: }
1.325 raeburn 12137: }
12138: }
12139: }
1.425 raeburn 12140: if (ref($hashref) eq 'HASH') {
1.325 raeburn 12141: foreach my $field (@fields) {
12142: if ($hashref->{$field}) {
12143: if ($role eq 'emailusername') {
12144: $checks{$field} = $hashref->{$field};
12145: } else {
12146: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12147: }
12148: }
12149: }
12150: }
12151: }
1.305 raeburn 12152: my $total = scalar(@fields);
12153: for (my $i=0; $i<$total; $i++) {
12154: $rem = $i%($numinrow);
1.33 raeburn 12155: if ($rem == 0) {
12156: if ($i > 0) {
12157: $output .= '</tr>';
12158: }
12159: $output .= '<tr>';
12160: }
12161: my $check = ' ';
1.228 raeburn 12162: unless ($role eq 'emailusername') {
12163: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12164: $check = $checks{$fields[$i]};
1.357 raeburn 12165: } elsif ($context eq 'privacy') {
12166: if ($role =~ /^priv_(domain|course)$/) {
12167: if (ref($settings) ne 'HASH') {
12168: $check = ' checked="checked" ';
12169: }
12170: } elsif ($role =~ /^priv_(author|community)$/) {
12171: if (ref($settings) ne 'HASH') {
12172: unless ($fields[$i] eq 'id') {
12173: $check = ' checked="checked" ';
12174: }
12175: }
12176: } elsif ($role =~ /^(unpriv|othdom)_/) {
12177: if (ref($settings) ne 'HASH') {
12178: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12179: $check = ' checked="checked" ';
12180: }
12181: }
12182: }
1.325 raeburn 12183: } elsif ($context ne 'lti') {
1.228 raeburn 12184: if ($role eq 'st') {
12185: if (ref($settings) ne 'HASH') {
12186: $check = ' checked="checked" ';
12187: }
1.33 raeburn 12188: }
12189: }
12190: }
12191: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12192: '<span class="LC_nobreak">';
1.325 raeburn 12193: my $prefix = 'canmodify';
1.228 raeburn 12194: if ($role eq 'emailusername') {
12195: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12196: $checks{$fields[$i]} = 'omit';
12197: }
12198: foreach my $option ('required','optional','omit') {
12199: my $checked='';
12200: if ($checks{$fields[$i]} eq $option) {
12201: $checked='checked="checked" ';
12202: }
12203: $output .= '<label>'.
1.325 raeburn 12204: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12205: &mt($option).'</label>'.(' ' x2);
12206: }
12207: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12208: } else {
1.325 raeburn 12209: if ($context eq 'lti') {
12210: $prefix = 'lti';
1.443 raeburn 12211: } elsif ($context eq 'coauthor') {
12212: $prefix = 'cacanmodify';
1.357 raeburn 12213: } elsif ($context eq 'privacy') {
12214: $prefix = 'privacy';
1.325 raeburn 12215: }
1.228 raeburn 12216: $output .= '<label>'.
1.325 raeburn 12217: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12218: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12219: '</label>';
12220: }
12221: $output .= '</span></td>';
1.33 raeburn 12222: }
1.305 raeburn 12223: $rem = $total%$numinrow;
12224: my $colsleft;
12225: if ($rem) {
12226: $colsleft = $numinrow - $rem;
12227: }
12228: if ($colsleft > 1) {
1.33 raeburn 12229: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12230: ' </td>';
12231: } elsif ($colsleft == 1) {
12232: $output .= '<td class="LC_left_item"> </td>';
12233: }
12234: $output .= '</tr></table></td></tr>';
12235: return $output;
12236: }
1.28 raeburn 12237:
1.93 raeburn 12238: sub insttypes_row {
1.305 raeburn 12239: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12240: $customcss,$rowstyle) = @_;
1.93 raeburn 12241: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12242: cansearch => 'Users allowed to search',
1.93 raeburn 12243: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12244: lockablenames => 'User preference to lock name',
12245: selfassign => 'Self-reportable affiliations',
12246: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12247: webdav => 'WebDAV access available',
12248: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12249: );
1.429 raeburn 12250: my ($showdom,$defaultquota);
1.93 raeburn 12251: if ($context eq 'cansearch') {
12252: $showdom = ' ('.$dom.')';
1.429 raeburn 12253: } elsif ($context eq 'authorquota') {
12254: $defaultquota = 500;
1.93 raeburn 12255: }
1.165 raeburn 12256: my $class = 'LC_left_item';
12257: if ($context eq 'statustocreate') {
12258: $class = 'LC_right_item';
12259: }
1.305 raeburn 12260: my $css_class;
12261: if ($$rowtotal%2) {
12262: $css_class = 'LC_odd_row';
12263: }
12264: if ($customcss) {
12265: $css_class .= ' '.$customcss;
12266: }
12267: $css_class =~ s/^\s+//;
12268: if ($css_class) {
12269: $css_class = ' class="'.$css_class.'"';
12270: }
12271: if ($rowstyle) {
12272: $css_class .= ' style="'.$rowstyle.'"';
12273: }
12274: if ($onclick) {
12275: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12276: }
12277: my $output = '<tr'.$css_class.'>'.
12278: '<td>'.$lt{$context}.$showdom.
12279: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12280: my $rem;
12281: if (ref($types) eq 'ARRAY') {
12282: for (my $i=0; $i<@{$types}; $i++) {
12283: if (defined($usertypes->{$types->[$i]})) {
12284: my $rem = $i%($numinrow);
12285: if ($rem == 0) {
12286: if ($i > 0) {
12287: $output .= '</tr>';
12288: }
12289: $output .= '<tr>';
1.23 raeburn 12290: }
1.429 raeburn 12291: if ($context eq 'authorquota') {
12292: my $currquota;
12293: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12294: $currquota = $settings->{$context}->{$types->[$i]};
12295: } else {
12296: $currquota = $defaultquota;
12297: }
12298: $output .= '<td class="LC_left_item">'."\n".
12299: '<label><span class="LC_nobreak">'."\n".
12300: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12301: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12302: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12303: '</label></td>';
12304: } else {
12305: my $check = ' ';
12306: if (ref($settings) eq 'HASH') {
12307: if (ref($settings->{$context}) eq 'ARRAY') {
12308: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12309: $check = ' checked="checked" ';
12310: }
12311: } elsif (ref($settings->{$context}) eq 'HASH') {
12312: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12313: $check = ' checked="checked" ';
12314: } elsif ($context eq 'webdav') {
12315: if ($settings->{$context}->{$types->[$i]}) {
12316: $check = ' checked="checked" ';
12317: }
12318: }
12319: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12320: $check = ' checked="checked" ';
12321: }
1.26 raeburn 12322: }
1.429 raeburn 12323: $output .= '<td class="LC_left_item">'.
12324: '<span class="LC_nobreak"><label>'.
12325: '<input type="checkbox" name="'.$context.'" '.
12326: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12327: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12328: }
12329: }
12330: }
1.26 raeburn 12331: $rem = @{$types}%($numinrow);
1.23 raeburn 12332: }
12333: my $colsleft = $numinrow - $rem;
1.315 raeburn 12334: if ($context eq 'overrides') {
12335: if ($colsleft > 1) {
12336: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12337: } else {
12338: $output .= '<td class="LC_left_item">';
12339: }
1.425 raeburn 12340: $output .= ' ';
1.23 raeburn 12341: } else {
1.334 raeburn 12342: if ($rem == 0) {
1.315 raeburn 12343: $output .= '<tr>';
12344: }
12345: if ($colsleft > 1) {
12346: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12347: } else {
12348: $output .= '<td class="LC_left_item">';
12349: }
1.429 raeburn 12350: if ($context eq 'authorquota') {
12351: my $currquota = 500;
12352: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12353: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12354: $currquota = $settings->{$context}{'default'};
12355: }
12356: }
12357: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12358: '<input type="text" name="'.$context.'_default" '.
12359: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12360: '</label>';
12361: } else {
12362: my $defcheck = ' ';
12363: if (ref($settings) eq 'HASH') {
12364: if (ref($settings->{$context}) eq 'ARRAY') {
12365: if (grep(/^default$/,@{$settings->{$context}})) {
12366: $defcheck = ' checked="checked" ';
12367: }
12368: } elsif (ref($settings->{$context}) eq 'HASH') {
12369: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12370: $defcheck = ' checked="checked" ';
12371: } elsif ($context eq 'webdav') {
12372: if ($settings->{$context}->{'default'}) {
12373: $defcheck = ' checked="checked" ';
12374: }
12375: }
12376: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12377: $defcheck = ' checked="checked" ';
12378: }
1.99 raeburn 12379: }
1.429 raeburn 12380: $output .= '<span class="LC_nobreak"><label>'.
12381: '<input type="checkbox" name="'.$context.'" '.
12382: 'value="default"'.$defcheck.$onclick.'/>'.
12383: $othertitle.'</label></span>';
1.26 raeburn 12384: }
1.23 raeburn 12385: }
1.315 raeburn 12386: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12387: return $output;
1.23 raeburn 12388: }
12389:
12390: sub sorted_searchtitles {
12391: my %searchtitles = &Apache::lonlocal::texthash(
12392: 'uname' => 'username',
12393: 'lastname' => 'last name',
12394: 'lastfirst' => 'last name, first name',
12395: );
12396: my @titleorder = ('uname','lastname','lastfirst');
12397: return (\%searchtitles,\@titleorder);
12398: }
12399:
1.25 raeburn 12400: sub sorted_searchtypes {
12401: my %srchtypes_desc = (
12402: exact => 'is exact match',
12403: contains => 'contains ..',
12404: begins => 'begins with ..',
12405: );
12406: my @srchtypeorder = ('exact','begins','contains');
12407: return (\%srchtypes_desc,\@srchtypeorder);
12408: }
12409:
1.3 raeburn 12410: sub usertype_update_row {
12411: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12412: my $datatable;
12413: my $numinrow = 4;
12414: foreach my $type (@{$types}) {
12415: if (defined($usertypes->{$type})) {
12416: $$rownums ++;
12417: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12418: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12419: '</td><td class="LC_left_item"><table>';
12420: for (my $i=0; $i<@{$fields}; $i++) {
12421: my $rem = $i%($numinrow);
12422: if ($rem == 0) {
12423: if ($i > 0) {
12424: $datatable .= '</tr>';
12425: }
12426: $datatable .= '<tr>';
12427: }
12428: my $check = ' ';
1.39 raeburn 12429: if (ref($settings) eq 'HASH') {
12430: if (ref($settings->{'fields'}) eq 'HASH') {
12431: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12432: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12433: $check = ' checked="checked" ';
12434: }
1.3 raeburn 12435: }
12436: }
12437: }
12438:
12439: if ($i == @{$fields}-1) {
12440: my $colsleft = $numinrow - $rem;
12441: if ($colsleft > 1) {
12442: $datatable .= '<td colspan="'.$colsleft.'">';
12443: } else {
12444: $datatable .= '<td>';
12445: }
12446: } else {
12447: $datatable .= '<td>';
12448: }
1.8 raeburn 12449: $datatable .= '<span class="LC_nobreak"><label>'.
12450: '<input type="checkbox" name="updateable_'.$type.
12451: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12452: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12453: }
12454: $datatable .= '</tr></table></td></tr>';
12455: }
12456: }
12457: return $datatable;
1.1 raeburn 12458: }
12459:
12460: sub modify_login {
1.205 raeburn 12461: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12462: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12463: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12464: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12465: %title = ( coursecatalog => 'Display course catalog',
12466: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12467: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12468: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12469: loginheader => 'Log-in box header',
12470: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12471: @offon = ('off','on');
1.112 raeburn 12472: if (ref($domconfig{login}) eq 'HASH') {
12473: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12474: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12475: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12476: }
12477: }
1.386 raeburn 12478: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12479: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12480: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12481: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12482: $saml{$lonhost} = 1;
12483: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12484: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12485: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12486: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12487: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12488: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12489: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12490: }
12491: }
12492: }
1.112 raeburn 12493: }
1.9 raeburn 12494: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12495: \%domconfig,\%loginhash);
1.188 raeburn 12496: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12497: foreach my $item (@toggles) {
12498: $loginhash{login}{$item} = $env{'form.'.$item};
12499: }
1.41 raeburn 12500: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12501: if (ref($colchanges{'login'}) eq 'HASH') {
12502: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12503: \%loginhash);
12504: }
1.110 raeburn 12505:
1.149 raeburn 12506: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12507: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12508: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12509: if (keys(%servers) > 1) {
12510: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12511: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12512: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12513: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12514: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12515: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12516: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12517: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12518: $changes{'loginvia'}{$lonhost} = 1;
12519: } else {
12520: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12521: $changes{'loginvia'}{$lonhost} = 1;
12522: }
12523: } else {
12524: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12525: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12526: $changes{'loginvia'}{$lonhost} = 1;
12527: }
12528: }
12529: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12530: foreach my $item (@loginvia_attribs) {
12531: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12532: }
12533: } else {
12534: foreach my $item (@loginvia_attribs) {
12535: my $new = $env{'form.'.$lonhost.'_'.$item};
12536: if (($item eq 'serverpath') && ($new eq 'custom')) {
12537: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12538: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12539: $new = '/';
12540: }
12541: }
12542: if (($item eq 'custompath') &&
12543: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12544: $new = '';
12545: }
12546: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12547: $changes{'loginvia'}{$lonhost} = 1;
12548: }
12549: if ($item eq 'exempt') {
1.256 raeburn 12550: $new = &check_exempt_addresses($new);
1.128 raeburn 12551: }
12552: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12553: }
12554: }
1.112 raeburn 12555: } else {
1.128 raeburn 12556: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12557: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12558: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12559: foreach my $item (@loginvia_attribs) {
12560: my $new = $env{'form.'.$lonhost.'_'.$item};
12561: if (($item eq 'serverpath') && ($new eq 'custom')) {
12562: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12563: $new = '/';
12564: }
12565: }
12566: if (($item eq 'custompath') &&
12567: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12568: $new = '';
12569: }
12570: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12571: }
1.110 raeburn 12572: }
12573: }
12574: }
12575: }
1.119 raeburn 12576:
1.168 raeburn 12577: my $servadm = $r->dir_config('lonAdmEMail');
12578: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12579: if (ref($domconfig{'login'}) eq 'HASH') {
12580: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12581: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12582: if ($lang eq 'nolang') {
12583: push(@currlangs,$lang);
12584: } elsif (defined($langchoices{$lang})) {
12585: push(@currlangs,$lang);
12586: } else {
12587: next;
12588: }
12589: }
12590: }
12591: }
12592: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12593: if (@currlangs > 0) {
12594: foreach my $lang (@currlangs) {
12595: if (grep(/^\Q$lang\E$/,@delurls)) {
12596: $changes{'helpurl'}{$lang} = 1;
12597: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12598: $changes{'helpurl'}{$lang} = 1;
12599: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12600: push(@newlangs,$lang);
12601: } else {
12602: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12603: }
12604: }
12605: }
12606: unless (grep(/^nolang$/,@currlangs)) {
12607: if ($env{'form.loginhelpurl_nolang.filename'}) {
12608: $changes{'helpurl'}{'nolang'} = 1;
12609: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12610: push(@newlangs,'nolang');
12611: }
12612: }
12613: if ($env{'form.loginhelpurl_add_lang'}) {
12614: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12615: ($env{'form.loginhelpurl_add_file.filename'})) {
12616: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12617: $addedfile = $env{'form.loginhelpurl_add_lang'};
12618: }
12619: }
12620: if ((@newlangs > 0) || ($addedfile)) {
12621: my $error;
12622: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12623: if ($configuserok eq 'ok') {
12624: if ($switchserver) {
12625: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12626: } elsif ($author_ok eq 'ok') {
12627: my @allnew = @newlangs;
12628: if ($addedfile ne '') {
12629: push(@allnew,$addedfile);
12630: }
1.421 raeburn 12631: my $modified = [];
1.168 raeburn 12632: foreach my $lang (@allnew) {
12633: my $formelem = 'loginhelpurl_'.$lang;
12634: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12635: $formelem = 'loginhelpurl_add_file';
12636: }
1.425 raeburn 12637: (my $result,$newurl{$lang}) =
1.421 raeburn 12638: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12639: "help/$lang",'','',$newfile{$lang},
12640: $modified);
1.168 raeburn 12641: if ($result eq 'ok') {
12642: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12643: $changes{'helpurl'}{$lang} = 1;
12644: } else {
12645: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12646: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12647: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12648: (!grep(/^\Q$lang\E$/,@delurls))) {
12649: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12650: }
12651: }
12652: }
1.421 raeburn 12653: &update_modify_urls($r,$modified);
1.168 raeburn 12654: } else {
12655: $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);
12656: }
12657: } else {
12658: $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);
12659: }
12660: if ($error) {
12661: &Apache::lonnet::logthis($error);
12662: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12663: }
12664: }
1.256 raeburn 12665:
12666: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12667: if (ref($domconfig{'login'}) eq 'HASH') {
12668: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12669: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12670: if ($domservers{$lonhost}) {
12671: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12672: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12673: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12674: }
12675: }
12676: }
12677: }
12678: }
12679: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12680: foreach my $lonhost (sort(keys(%domservers))) {
12681: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12682: $changes{'headtag'}{$lonhost} = 1;
12683: } else {
12684: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12685: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12686: }
12687: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12688: push(@newhosts,$lonhost);
12689: } elsif ($currheadtagurls{$lonhost}) {
12690: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12691: if ($currexempt{$lonhost}) {
1.289 raeburn 12692: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12693: $changes{'headtag'}{$lonhost} = 1;
12694: }
12695: } elsif ($possexempt{$lonhost}) {
12696: $changes{'headtag'}{$lonhost} = 1;
12697: }
12698: if ($possexempt{$lonhost}) {
12699: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12700: }
12701: }
12702: }
12703: }
12704: if (@newhosts) {
12705: my $error;
12706: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12707: if ($configuserok eq 'ok') {
12708: if ($switchserver) {
12709: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12710: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12711: my $modified = [];
1.256 raeburn 12712: foreach my $lonhost (@newhosts) {
12713: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12714: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12715: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12716: "login/headtag/$lonhost",'','',
12717: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12718: $modified);
1.256 raeburn 12719: if ($result eq 'ok') {
12720: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12721: $changes{'headtag'}{$lonhost} = 1;
12722: if ($possexempt{$lonhost}) {
12723: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12724: }
12725: } else {
12726: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12727: $newheadtagurls{$lonhost},$result);
12728: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12729: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12730: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12731: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12732: }
12733: }
12734: }
1.421 raeburn 12735: &update_modify_urls($r,$modified);
1.256 raeburn 12736: } else {
12737: $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);
12738: }
12739: } else {
12740: $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);
12741: }
12742: if ($error) {
12743: &Apache::lonnet::logthis($error);
12744: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12745: }
12746: }
1.386 raeburn 12747: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12748: my @newsamlimgs;
12749: foreach my $lonhost (keys(%domservers)) {
12750: if ($env{'form.saml_'.$lonhost}) {
12751: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12752: push(@newsamlimgs,$lonhost);
12753: }
1.412 raeburn 12754: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12755: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12756: }
12757: if ($saml{$lonhost}) {
1.412 raeburn 12758: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12759: $env{'form.saml_window_'.$lonhost} = '';
12760: }
1.386 raeburn 12761: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12762: #FIXME Need to obsolete published image
12763: delete($currsaml{$lonhost}{'img'});
12764: $changes{'saml'}{$lonhost} = 1;
12765: }
12766: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12767: $changes{'saml'}{$lonhost} = 1;
12768: }
12769: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12770: $changes{'saml'}{$lonhost} = 1;
12771: }
12772: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12773: $changes{'saml'}{$lonhost} = 1;
12774: }
12775: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12776: $changes{'saml'}{$lonhost} = 1;
12777: }
1.412 raeburn 12778: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12779: $changes{'saml'}{$lonhost} = 1;
12780: }
1.386 raeburn 12781: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12782: $changes{'saml'}{$lonhost} = 1;
12783: }
12784: } else {
12785: $changes{'saml'}{$lonhost} = 1;
12786: }
1.412 raeburn 12787: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12788: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12789: }
12790: } else {
1.425 raeburn 12791: if ($saml{$lonhost}) {
1.389 raeburn 12792: $changes{'saml'}{$lonhost} = 1;
12793: delete($currsaml{$lonhost});
12794: }
1.386 raeburn 12795: }
12796: }
12797: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12798: unless (exists($domservers{$posshost})) {
12799: delete($currsaml{$posshost});
1.386 raeburn 12800: }
12801: }
12802: %{$loginhash{'login'}{'saml'}} = %currsaml;
12803: if (@newsamlimgs) {
12804: my $error;
12805: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12806: if ($configuserok eq 'ok') {
12807: if ($switchserver) {
12808: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12809: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12810: my $modified = [];
1.386 raeburn 12811: foreach my $lonhost (@newsamlimgs) {
12812: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12813: my ($result,$imgurl) =
1.421 raeburn 12814: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12815: "login/saml/$lonhost",'','',
12816: $env{'form.saml_img_'.$lonhost.'.filename'},
12817: $modified);
1.386 raeburn 12818: if ($result eq 'ok') {
12819: $currsaml{$lonhost}{'img'} = $imgurl;
12820: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12821: $changes{'saml'}{$lonhost} = 1;
12822: } else {
12823: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12824: $lonhost,$result);
12825: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12826: }
12827: }
1.421 raeburn 12828: &update_modify_urls($r,$modified);
1.386 raeburn 12829: } else {
12830: $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);
12831: }
12832: } else {
12833: $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);
12834: }
12835: if ($error) {
12836: &Apache::lonnet::logthis($error);
12837: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12838: }
12839: }
1.169 raeburn 12840: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12841:
12842: my $defaulthelpfile = '/adm/loginproblems.html';
12843: my $defaulttext = &mt('Default in use');
12844:
1.1 raeburn 12845: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12846: $dom);
12847: if ($putresult eq 'ok') {
1.188 raeburn 12848: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12849: my %defaultchecked = (
12850: 'coursecatalog' => 'on',
1.188 raeburn 12851: 'helpdesk' => 'on',
1.42 raeburn 12852: 'adminmail' => 'off',
1.43 raeburn 12853: 'newuser' => 'off',
1.42 raeburn 12854: );
1.55 raeburn 12855: if (ref($domconfig{'login'}) eq 'HASH') {
12856: foreach my $item (@toggles) {
12857: if ($defaultchecked{$item} eq 'on') {
12858: if (($domconfig{'login'}{$item} eq '0') &&
12859: ($env{'form.'.$item} eq '1')) {
12860: $changes{$item} = 1;
12861: } elsif (($domconfig{'login'}{$item} eq '' ||
12862: $domconfig{'login'}{$item} eq '1') &&
12863: ($env{'form.'.$item} eq '0')) {
12864: $changes{$item} = 1;
12865: }
12866: } elsif ($defaultchecked{$item} eq 'off') {
12867: if (($domconfig{'login'}{$item} eq '1') &&
12868: ($env{'form.'.$item} eq '0')) {
12869: $changes{$item} = 1;
12870: } elsif (($domconfig{'login'}{$item} eq '' ||
12871: $domconfig{'login'}{$item} eq '0') &&
12872: ($env{'form.'.$item} eq '1')) {
12873: $changes{$item} = 1;
12874: }
1.42 raeburn 12875: }
12876: }
1.41 raeburn 12877: }
1.6 raeburn 12878: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12879: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12880: if (exists($changes{'saml'})) {
12881: my $hostid_in_use;
12882: my @hosts = &Apache::lonnet::current_machine_ids();
12883: if (@hosts > 1) {
12884: foreach my $hostid (@hosts) {
12885: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12886: $hostid_in_use = $hostid;
12887: last;
12888: }
12889: }
12890: } else {
12891: $hostid_in_use = $r->dir_config('lonHostID');
12892: }
12893: if (($hostid_in_use) &&
12894: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12895: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12896: }
12897: if (ref($lastactref) eq 'HASH') {
12898: if (ref($changes{'saml'}) eq 'HASH') {
12899: my %updates;
12900: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12901: $lastactref->{'samllanding'} = \%updates;
12902: }
12903: }
12904: }
1.212 raeburn 12905: if (ref($lastactref) eq 'HASH') {
12906: $lastactref->{'domainconfig'} = 1;
12907: }
1.1 raeburn 12908: $resulttext = &mt('Changes made:').'<ul>';
12909: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12910: if ($item eq 'loginvia') {
1.112 raeburn 12911: if (ref($changes{$item}) eq 'HASH') {
12912: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12913: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12914: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12915: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12916: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12917: $protocol = 'http' if ($protocol ne 'https');
12918: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12919:
12920: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12921: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12922: } else {
12923: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12924: }
12925: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12926: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12927: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12928: }
12929: $resulttext .= '</li>';
12930: } else {
12931: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12932: }
1.112 raeburn 12933: } else {
1.128 raeburn 12934: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12935: }
12936: }
1.128 raeburn 12937: $resulttext .= '</ul></li>';
1.112 raeburn 12938: }
1.168 raeburn 12939: } elsif ($item eq 'helpurl') {
12940: if (ref($changes{$item}) eq 'HASH') {
12941: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12942: if (grep(/^\Q$lang\E$/,@delurls)) {
12943: my ($chg,$link);
12944: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12945: if ($lang eq 'nolang') {
12946: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12947: } else {
12948: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12949: }
12950: $resulttext .= '<li>'.$chg.'</li>';
12951: } else {
12952: my $chg;
12953: if ($lang eq 'nolang') {
12954: $chg = &mt('custom log-in help file for no preferred language');
12955: } else {
12956: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12957: }
12958: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12959: $loginhash{'login'}{'helpurl'}{$lang}.
12960: '?inhibitmenu=yes',$chg,600,500).
12961: '</li>';
12962: }
12963: }
12964: }
1.256 raeburn 12965: } elsif ($item eq 'headtag') {
12966: if (ref($changes{$item}) eq 'HASH') {
12967: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12968: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12969: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12970: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12971: $resulttext .= '<li><a href="'.
12972: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12973: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12974: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12975: if ($possexempt{$lonhost}) {
12976: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12977: } else {
12978: $resulttext .= &mt('included for any client IP');
12979: }
12980: $resulttext .= '</li>';
12981: }
12982: }
12983: }
1.386 raeburn 12984: } elsif ($item eq 'saml') {
12985: if (ref($changes{$item}) eq 'HASH') {
12986: my %notlt = (
12987: text => 'Text for log-in by SSO',
12988: img => 'SSO button image',
12989: alt => 'Alt text for button image',
12990: url => 'SSO URL',
12991: title => 'Tooltip for SSO link',
1.412 raeburn 12992: window => 'Pop-up window if iframe',
1.386 raeburn 12993: notsso => 'Text for non-SSO log-in',
12994: );
12995: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12996: if (ref($currsaml{$lonhost}) eq 'HASH') {
12997: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12998: '<ul>';
1.412 raeburn 12999: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 13000: if ($currsaml{$lonhost}{$key} eq '') {
13001: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
13002: } else {
13003: my $value = "'$currsaml{$lonhost}{$key}'";
13004: if ($key eq 'img') {
13005: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 13006: } elsif ($key eq 'window') {
13007: $value = 'On';
1.386 raeburn 13008: }
13009: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
13010: $value).'</li>';
13011: }
13012: }
13013: $resulttext .= '</ul></li>';
13014: } else {
13015: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
13016: }
13017: }
13018: }
1.169 raeburn 13019: } elsif ($item eq 'captcha') {
13020: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 13021: my $chgtxt;
1.169 raeburn 13022: if ($loginhash{'login'}{$item} eq 'notused') {
13023: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
13024: } else {
13025: my %captchas = &captcha_phrases();
13026: if ($captchas{$loginhash{'login'}{$item}}) {
13027: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
13028: } else {
13029: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
13030: }
13031: }
13032: $resulttext .= '<li>'.$chgtxt.'</li>';
13033: }
13034: } elsif ($item eq 'recaptchakeys') {
13035: if (ref($loginhash{'login'}) eq 'HASH') {
13036: my ($privkey,$pubkey);
13037: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
13038: $pubkey = $loginhash{'login'}{$item}{'public'};
13039: $privkey = $loginhash{'login'}{$item}{'private'};
13040: }
13041: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
13042: if (!$pubkey) {
13043: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
13044: } else {
13045: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13046: }
13047: if (!$privkey) {
13048: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
13049: } else {
1.251 raeburn 13050: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 13051: }
13052: $chgtxt .= '</ul>';
13053: $resulttext .= '<li>'.$chgtxt.'</li>';
13054: }
1.269 raeburn 13055: } elsif ($item eq 'recaptchaversion') {
13056: if (ref($loginhash{'login'}) eq 'HASH') {
13057: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 13058: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 13059: '</li>';
13060: }
13061: }
1.41 raeburn 13062: } else {
13063: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
13064: }
1.1 raeburn 13065: }
1.6 raeburn 13066: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 13067: } else {
13068: $resulttext = &mt('No changes made to log-in page settings');
13069: }
13070: } else {
1.11 albertel 13071: $resulttext = '<span class="LC_error">'.
13072: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13073: }
1.6 raeburn 13074: if ($errors) {
1.9 raeburn 13075: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 13076: $errors.'</ul>';
13077: }
13078: return $resulttext;
13079: }
13080:
1.256 raeburn 13081: sub check_exempt_addresses {
13082: my ($iplist) = @_;
13083: $iplist =~ s/^\s+//;
13084: $iplist =~ s/\s+$//;
13085: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
13086: my (@okips,$new);
13087: foreach my $ip (@poss_ips) {
13088: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
13089: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
13090: push(@okips,$ip);
13091: }
13092: }
13093: }
13094: if (@okips > 0) {
13095: $new = join(',',@okips);
13096: } else {
13097: $new = '';
13098: }
13099: return $new;
13100: }
13101:
1.6 raeburn 13102: sub color_font_choices {
13103: my %choices =
13104: &Apache::lonlocal::texthash (
13105: bgs => "Background colors",
13106: links => "Link colors",
1.55 raeburn 13107: images => "Images",
1.6 raeburn 13108: font => "Font color",
1.201 raeburn 13109: fontmenu => "Font menu",
1.76 raeburn 13110: pgbg => "Page",
1.6 raeburn 13111: tabbg => "Header",
13112: sidebg => "Border",
13113: link => "Link",
13114: alink => "Active link",
13115: vlink => "Visited link",
13116: );
13117: return %choices;
13118: }
13119:
1.394 raeburn 13120: sub modify_ipaccess {
13121: my ($dom,$lastactref,%domconfig) = @_;
13122: my (@allpos,%changes,%confhash,$errors,$resulttext);
13123: my (@items,%deletions,%itemids,@warnings);
13124: my ($typeorder,$types) = &commblocktype_text();
13125: if ($env{'form.ipaccess_add'}) {
13126: my $name = $env{'form.ipaccess_name_add'};
13127: my ($newid,$error) = &get_ipaccess_id($dom,$name);
13128: if ($newid) {
13129: $itemids{'add'} = $newid;
13130: push(@items,'add');
13131: $changes{$newid} = 1;
13132: } else {
13133: $error = &mt('Failed to acquire unique ID for new IP access control item');
13134: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13135: }
13136: }
13137: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13138: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13139: if (@todelete) {
13140: map { $deletions{$_} = 1; } @todelete;
13141: }
13142: my $maxnum = $env{'form.ipaccess_maxnum'};
13143: for (my $i=0; $i<$maxnum; $i++) {
13144: my $itemid = $env{'form.ipaccess_id_'.$i};
13145: $itemid =~ s/\D+//g;
13146: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13147: if ($deletions{$itemid}) {
13148: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13149: } else {
13150: push(@items,$i);
13151: $itemids{$i} = $itemid;
13152: }
13153: }
13154: }
13155: }
13156: foreach my $idx (@items) {
13157: my $itemid = $itemids{$idx};
13158: next unless ($itemid);
1.446 raeburn 13159: my ($position,%current);
13160: if ($idx eq 'add') {
13161: $position = $env{'form.ipaccess_pos_add'};
13162: } else {
13163: $position = $env{'form.ipaccess_pos_'.$itemid};
1.394 raeburn 13164: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13165: %current = %{$domconfig{'ipaccess'}{$itemid}};
13166: }
13167: }
13168: $position =~ s/\D+//g;
13169: if ($position ne '') {
13170: $allpos[$position] = $itemid;
13171: }
13172: my $name = $env{'form.ipaccess_name_'.$idx};
13173: $name =~ s/^\s+|\s+$//g;
13174: $confhash{$itemid}{'name'} = $name;
13175: my $possrange = $env{'form.ipaccess_range_'.$idx};
13176: $possrange =~ s/^\s+|\s+$//g;
13177: unless ($possrange eq '') {
13178: $possrange =~ s/[\r\n]+/\s/g;
13179: $possrange =~ s/\s*-\s*/-/g;
13180: $possrange =~ s/\s+/,/g;
13181: $possrange =~ s/,+/,/g;
13182: if ($possrange ne '') {
13183: my (@ok,$count);
1.425 raeburn 13184: $count = 0;
1.394 raeburn 13185: foreach my $poss (split(/\,/,$possrange)) {
13186: $count ++;
13187: $poss = &validate_ip_pattern($poss);
13188: if ($poss ne '') {
13189: push(@ok,$poss);
13190: }
13191: }
13192: my $diff = $count - scalar(@ok);
13193: if ($diff) {
13194: $errors .= '<li><span class="LC_error">'.
13195: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13196: $diff,$name).
13197: '</span></li>';
13198: }
13199: if (@ok) {
13200: my @cidr_list;
13201: foreach my $item (@ok) {
13202: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13203: }
13204: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13205: }
13206: }
13207: }
13208: foreach my $field ('name','ip') {
13209: unless (($idx eq 'add') || ($changes{$itemid})) {
13210: if ($current{$field} ne $confhash{$itemid}{$field}) {
13211: $changes{$itemid} = 1;
13212: last;
13213: }
13214: }
13215: }
13216: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13217:
1.394 raeburn 13218: my %commblocks;
1.425 raeburn 13219: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13220: foreach my $type (@{$typeorder}) {
13221: if ($commblocks{$type}) {
13222: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13223: }
13224: unless (($idx eq 'add') || ($changes{$itemid})) {
13225: if (ref($current{'commblocks'}) eq 'HASH') {
13226: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13227: $changes{$itemid} = 1;
13228: }
13229: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13230: $changes{$itemid} = 1;
13231: }
13232: }
13233: }
13234: $confhash{$itemid}{'courses'} = {};
13235: my %crsdeletions;
13236: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13237: if (@delcrs) {
13238: map { $crsdeletions{$_} = 1; } @delcrs;
13239: }
13240: if (ref($current{'courses'}) eq 'HASH') {
13241: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13242: if ($crsdeletions{$cid}) {
13243: $changes{$itemid} = 1;
13244: } else {
13245: $confhash{$itemid}{'courses'}{$cid} = 1;
13246: }
13247: }
13248: }
13249: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13250: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13251: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13252: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13253: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13254: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13255: $errors .= '<li><span class="LC_error">'.
13256: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13257: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13258: '</span></li>';
13259: } else {
13260: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13261: $changes{$itemid} = 1;
13262: }
13263: }
13264: }
13265: if (@allpos > 0) {
13266: my $idx = 0;
13267: foreach my $itemid (@allpos) {
13268: if ($itemid ne '') {
13269: $confhash{$itemid}{'order'} = $idx;
13270: unless ($changes{$itemid}) {
13271: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13272: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13273: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13274: $changes{$itemid} = 1;
13275: }
13276: }
13277: }
13278: }
13279: $idx ++;
13280: }
13281: }
13282: }
13283: if (keys(%changes)) {
13284: my %defaultshash = (
13285: ipaccess => \%confhash,
13286: );
13287: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13288: $dom);
13289: if ($putresult eq 'ok') {
13290: my $cachetime = 1800;
13291: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13292: if (ref($lastactref) eq 'HASH') {
13293: $lastactref->{'ipaccess'} = 1;
13294: }
13295: $resulttext = &mt('Changes made:').'<ul>';
13296: my %bynum;
13297: foreach my $itemid (sort(keys(%changes))) {
13298: if (ref($confhash{$itemid}) eq 'HASH') {
13299: my $position = $confhash{$itemid}{'order'};
13300: if ($position =~ /^\d+$/) {
13301: $bynum{$position} = $itemid;
13302: }
13303: }
13304: }
13305: if (keys(%deletions)) {
13306: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13307: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13308: }
13309: }
13310: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13311: my $itemid = $bynum{$pos};
13312: if (ref($confhash{$itemid}) eq 'HASH') {
13313: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13314: my $position = $pos + 1;
13315: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13316: if ($confhash{$itemid}{'ip'} eq '') {
13317: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13318: } else {
13319: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13320: }
13321: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13322: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13323: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13324: '</li>';
13325: } else {
13326: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13327: }
13328: if (keys(%{$confhash{$itemid}{'courses'}})) {
13329: my @courses;
13330: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13331: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13332: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13333: }
13334: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13335: join('</li><li>',@courses).'</li></ul>';
13336: } else {
13337: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13338: }
1.395 raeburn 13339: $resulttext .= '</ul></li>';
1.394 raeburn 13340: }
13341: }
1.395 raeburn 13342: $resulttext .= '</ul>';
1.394 raeburn 13343: } else {
13344: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13345: }
13346: } else {
13347: $resulttext = &mt('No changes made');
13348: }
13349: if ($errors) {
13350: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13351: $errors.'</ul></p>';
13352: }
13353: return $resulttext;
13354: }
13355:
13356: sub get_ipaccess_id {
13357: my ($domain,$location) = @_;
13358: # get lock on ipaccess db
13359: my $lockhash = {
13360: lock => $env{'user.name'}.
13361: ':'.$env{'user.domain'},
13362: };
13363: my $tries = 0;
13364: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13365: my ($id,$error);
13366:
13367: while (($gotlock ne 'ok') && ($tries<10)) {
13368: $tries ++;
13369: sleep (0.1);
13370: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13371: }
13372: if ($gotlock eq 'ok') {
13373: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13374: if ($currids{'lock'}) {
13375: delete($currids{'lock'});
13376: if (keys(%currids)) {
13377: my @curr = sort { $a <=> $b } keys(%currids);
13378: if ($curr[-1] =~ /^\d+$/) {
13379: $id = 1 + $curr[-1];
13380: }
13381: } else {
13382: $id = 1;
13383: }
13384: if ($id) {
13385: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13386: $error = 'nostore';
13387: }
13388: } else {
13389: $error = 'nonumber';
13390: }
13391: }
13392: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13393: } else {
13394: $error = 'nolock';
13395: }
13396: return ($id,$error);
13397: }
13398:
1.429 raeburn 13399: sub modify_authordefaults {
13400: my ($dom,$lastactref,%domconfig) = @_;
13401: #
13402: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13403: #
13404: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13405: if (ref($domconfig{'quotas'}) eq 'HASH') {
13406: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13407: if ($key =~ /^webdav|authorquota$/) {
13408: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13409: } else {
13410: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13411: }
13412: }
13413: }
13414: my %staticdefaults = (
13415: 'copyright' => 'default',
13416: 'sourceavail' => 'closed',
13417: 'nocodemirror' => 'off',
1.437 raeburn 13418: 'daxecollapse' => 'off',
1.429 raeburn 13419: 'domcoordacc' => 'on',
1.439 raeburn 13420: 'editors' => ['edit','xml'],
1.429 raeburn 13421: 'authorquota' => 500,
13422: 'webdav' => 0,
1.440 raeburn 13423: 'archive' => 'off',
1.429 raeburn 13424: );
13425: my %titles = &authordefaults_titles();
1.440 raeburn 13426: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.429 raeburn 13427: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13428: $confhash{$item} = $env{'form.'.$item};
13429: }
13430: }
13431: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13432: $confhash{'copyright'} = $1;
13433: }
13434: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13435: $confhash{'sourceavail'} = $1;
13436: }
13437: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13438: my @okeditors = ('edit','xml','daxe');
13439: my @editors;
13440: foreach my $item (@posseditors) {
13441: if (grep(/^\Q$item\E$/,@okeditors)) {
13442: push(@editors,$item);
13443: }
13444: }
13445: $confhash{'editors'} = \@editors;
1.436 raeburn 13446:
1.429 raeburn 13447: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13448: my @insttypes;
13449: if (ref($types) eq 'ARRAY') {
13450: @insttypes = @{$types};
13451: }
13452: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13453: my %webdav;
13454: map { $webdav{$_} = 1; } @webdavon;
13455: foreach my $type (@insttypes,'default') {
13456: my $possquota = $env{'form.authorquota_'.$type};
13457: if ($possquota =~ /^\d+$/) {
13458: $save_quotas{'authorquota'}{$type} = $possquota;
13459: }
13460: if ($webdav{$type}) {
13461: $save_quotas{'webdav'}{$type} = 1;
13462: } else {
13463: $save_quotas{'webdav'}{$type} = 0;
13464: }
13465: }
13466: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13467: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13468: }
13469: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
1.440 raeburn 13470: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail','archive') {
1.429 raeburn 13471: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13472: $changes{$item} = 1;
13473: }
13474: }
13475: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
1.436 raeburn 13476: my @diffs =
1.429 raeburn 13477: &Apache::loncommon::compare_arrays($confhash{'editors'},
13478: $domconfig{'authordefaults'}{'editors'});
13479: unless (@diffs == 0) {
13480: $changes{'editors'} = 1;
13481: }
13482: } else {
13483: my @diffs =
13484: &Apache::loncommon::compare_arrays($confhash{'editors'},
13485: $staticdefaults{'editors'});
13486: unless (@diffs == 0) {
13487: $changes{'editors'} = 1;
13488: }
13489: }
13490: } else {
13491: my @offon = ('off','on');
1.440 raeburn 13492: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.436 raeburn 13493: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
1.429 raeburn 13494: $changes{$item} = 1;
13495: }
13496: }
13497: foreach my $item ('copyright','sourceavail') {
13498: if ($confhash{$item} ne $staticdefaults{$item}) {
13499: $changes{$item} = 1;
13500: }
13501: }
1.439 raeburn 13502: my @diffs =
13503: &Apache::loncommon::compare_arrays($confhash{'editors'},
13504: $staticdefaults{'editors'});
13505: unless (@diffs == 0) {
13506: $changes{'editors'} = 1;
13507: }
1.429 raeburn 13508: }
13509: foreach my $key ('authorquota','webdav') {
13510: if (ref($curr_quotas{$key}) eq 'HASH') {
13511: foreach my $type (@insttypes,'default') {
13512: if (exists($save_quotas{$key}{$type})) {
13513: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13514: $changes{$key}{$type} = 1;
13515: }
13516: } elsif (exists($curr_quotas{$key}{$type})) {
13517: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13518: } else {
13519: $save_quotas{$key}{$type} = $staticdefaults{$key};
13520: }
13521: }
13522: } else {
13523: foreach my $type (@insttypes,'default') {
13524: if (exists($save_quotas{$key}{$type})) {
13525: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13526: $changes{$key}{$type} = 1;
13527: }
13528: } else {
13529: $save_quotas{$key}{$type} = $staticdefaults{$key};
13530: }
13531: }
13532: }
13533: }
13534: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13535: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
1.436 raeburn 13536: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
1.429 raeburn 13537: $changes{'webdav_LC_adv'} = 1;
13538: }
13539: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13540: $changes{'webdav_LC_adv'} = 1;
13541: }
13542: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13543: $changes{'webdav_LC_adv'} = 1;
13544: }
13545: my %confighash = (
13546: quotas => \%save_quotas,
13547: authordefaults => \%confhash,
13548: );
13549: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13550: $dom);
13551: my $resulttext;
13552: if ($putresult eq 'ok') {
13553: if (keys(%changes)) {
1.431 raeburn 13554: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13555: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
1.436 raeburn 13556: ($changes{'webdav_LC_adv'})) {
1.429 raeburn 13557: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13558: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13559: }
13560: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13561: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13562: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13563: }
13564: }
13565: $resulttext = &mt('Changes made:').'<ul>';
13566: my $authoroverride;
1.437 raeburn 13567: foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
1.429 raeburn 13568: if (exists($changes{$key})) {
1.431 raeburn 13569: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13570: my $shown;
13571: unless ($authoroverride) {
13572: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13573: $authoroverride = 1;
13574: }
1.437 raeburn 13575: if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
1.429 raeburn 13576: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13577: } elsif ($key eq 'copyright') {
13578: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13579: } elsif ($key eq 'sourceavail') {
13580: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13581: }
1.436 raeburn 13582: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.429 raeburn 13583: }
13584: }
13585: if ($authoroverride) {
13586: $resulttext .= '</ul></li>';
13587: }
13588: my $domcoordoverride;
1.440 raeburn 13589: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv','archive') {
1.429 raeburn 13590: if (exists($changes{$key})) {
13591: my $shown;
13592: unless ($domcoordoverride) {
13593: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13594: $domcoordoverride = 1;
13595: }
13596: if ($key eq 'editors') {
1.431 raeburn 13597: if (ref($confhash{'editors'}) eq 'ARRAY') {
13598: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
13599: if (@{$confhash{'editors'}}) {
13600: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
13601: } else {
13602: $shown = &mt('None');
13603: }
1.429 raeburn 13604: }
13605: } elsif ($key eq 'authorquota') {
13606: foreach my $type (@insttypes) {
13607: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13608: }
13609: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13610: } elsif ($key eq 'webdav') {
13611: foreach my $type (@insttypes) {
13612: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13613: }
13614: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13615: } elsif ($key eq 'webdav_LC_adv') {
13616: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13617: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13618: } else {
13619: $shown = $titles{'none'};
13620: }
1.440 raeburn 13621: } elsif ($key eq 'archive') {
1.441 raeburn 13622: $domdefaults{$key} = $confhash{$key};
1.440 raeburn 13623: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
1.429 raeburn 13624: }
13625: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.436 raeburn 13626: }
1.429 raeburn 13627: }
13628: if ($domcoordoverride) {
13629: $resulttext .= '</ul></li>';
13630: }
1.439 raeburn 13631: $resulttext .= '</ul>';
1.431 raeburn 13632: my $cachetime = 24*60*60;
13633: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13634: if (ref($lastactref) eq 'HASH') {
13635: $lastactref->{'domdefaults'} = 1;
13636: }
1.429 raeburn 13637: } else {
13638: $resulttext = &mt('No changes made to Authoring Space defaults');
13639: }
13640: }
13641: return $resulttext;
13642: }
13643:
1.6 raeburn 13644: sub modify_rolecolors {
1.205 raeburn 13645: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13646: my ($resulttext,%rolehash);
13647: $rolehash{'rolecolors'} = {};
1.55 raeburn 13648: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13649: if ($domconfig{'rolecolors'} eq '') {
13650: $domconfig{'rolecolors'} = {};
13651: }
13652: }
1.9 raeburn 13653: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13654: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13655: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13656: $dom);
13657: if ($putresult eq 'ok') {
13658: if (keys(%changes) > 0) {
1.41 raeburn 13659: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13660: if (ref($lastactref) eq 'HASH') {
13661: $lastactref->{'domainconfig'} = 1;
13662: }
1.6 raeburn 13663: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13664: $rolehash{'rolecolors'});
13665: } else {
13666: $resulttext = &mt('No changes made to default color schemes');
13667: }
13668: } else {
1.11 albertel 13669: $resulttext = '<span class="LC_error">'.
13670: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13671: }
13672: if ($errors) {
13673: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13674: $errors.'</ul>';
13675: }
13676: return $resulttext;
13677: }
13678:
13679: sub modify_colors {
1.9 raeburn 13680: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13681: my (%changes,%choices);
1.51 raeburn 13682: my @bgs;
1.6 raeburn 13683: my @links = ('link','alink','vlink');
1.41 raeburn 13684: my @logintext;
1.6 raeburn 13685: my @images;
13686: my $servadm = $r->dir_config('lonAdmEMail');
13687: my $errors;
1.200 raeburn 13688: my %defaults;
1.6 raeburn 13689: foreach my $role (@{$roles}) {
13690: if ($role eq 'login') {
1.12 raeburn 13691: %choices = &login_choices();
1.41 raeburn 13692: @logintext = ('textcol','bgcol');
1.12 raeburn 13693: } else {
13694: %choices = &color_font_choices();
13695: }
13696: if ($role eq 'login') {
1.41 raeburn 13697: @images = ('img','logo','domlogo','login');
1.51 raeburn 13698: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13699: } else {
1.445 raeburn 13700: @images = ();
1.200 raeburn 13701: @bgs = ('pgbg','tabbg','sidebg');
13702: }
13703: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
1.444 raeburn 13704: $env{'form.'.$role.'_font'} = lc($env{'form.'.$role.'_font'});
13705: if ($env{'form.'.$role.'_font'} =~ /^\w+/) {
13706: $env{'form.'.$role.'_font'} = '#'.$env{'form.'.$role.'_font'};
13707: }
13708: unless ($env{'form.'.$role.'_font'} eq lc($defaults{'font'})) {
1.200 raeburn 13709: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13710: }
13711: if ($role eq 'login') {
13712: foreach my $item (@logintext) {
1.234 raeburn 13713: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13714: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13715: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13716: }
13717: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13718: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13719: }
13720: }
13721: } else {
1.234 raeburn 13722: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13723: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13724: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13725: }
1.445 raeburn 13726: unless ($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13727: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13728: }
1.6 raeburn 13729: }
1.200 raeburn 13730: foreach my $item (@bgs) {
1.234 raeburn 13731: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13732: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13733: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13734: }
13735: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13736: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13737: }
13738: }
13739: foreach my $item (@links) {
1.234 raeburn 13740: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13741: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13742: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13743: }
13744: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13745: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13746: }
1.6 raeburn 13747: }
1.46 raeburn 13748: my ($configuserok,$author_ok,$switchserver) =
13749: &config_check($dom,$confname,$servadm);
1.9 raeburn 13750: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13751: if (ref($domconfig->{$role}) ne 'HASH') {
13752: $domconfig->{$role} = {};
13753: }
1.8 raeburn 13754: foreach my $img (@images) {
1.402 raeburn 13755: if ($role eq 'login') {
13756: if (($img eq 'img') || ($img eq 'logo')) {
13757: if (defined($env{'form.login_showlogo_'.$img})) {
13758: $confhash->{$role}{'showlogo'}{$img} = 1;
13759: } else {
13760: $confhash->{$role}{'showlogo'}{$img} = 0;
13761: }
13762: }
13763: if ($env{'form.login_alt_'.$img} ne '') {
13764: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13765: }
1.402 raeburn 13766: }
1.18 albertel 13767: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13768: && !defined($domconfig->{$role}{$img})
13769: && !$env{'form.'.$role.'_del_'.$img}
13770: && $env{'form.'.$role.'_import_'.$img}) {
13771: # import the old configured image from the .tab setting
13772: # if they haven't provided a new one
13773: $domconfig->{$role}{$img} =
13774: $env{'form.'.$role.'_import_'.$img};
13775: }
1.6 raeburn 13776: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13777: my $error;
1.6 raeburn 13778: if ($configuserok eq 'ok') {
1.9 raeburn 13779: if ($switchserver) {
1.12 raeburn 13780: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13781: } else {
13782: if ($author_ok eq 'ok') {
1.421 raeburn 13783: my $modified = [];
1.9 raeburn 13784: my ($result,$logourl) =
1.421 raeburn 13785: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13786: $dom,$confname,$img,$width,$height,
13787: '',$modified);
1.9 raeburn 13788: if ($result eq 'ok') {
13789: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13790: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13791: &update_modify_urls($r,$modified);
1.9 raeburn 13792: } else {
1.12 raeburn 13793: $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 13794: }
13795: } else {
1.46 raeburn 13796: $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 13797: }
13798: }
13799: } else {
1.46 raeburn 13800: $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 13801: }
13802: if ($error) {
1.8 raeburn 13803: &Apache::lonnet::logthis($error);
1.11 albertel 13804: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13805: }
13806: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13807: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13808: my $error;
13809: if ($configuserok eq 'ok') {
13810: # is confname an author?
13811: if ($switchserver eq '') {
13812: if ($author_ok eq 'ok') {
1.421 raeburn 13813: my $modified = [];
1.9 raeburn 13814: my ($result,$logourl) =
1.421 raeburn 13815: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13816: $dom,$confname,$img,$width,$height,
13817: '',$modified);
1.9 raeburn 13818: if ($result eq 'ok') {
13819: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13820: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13821: &update_modify_urls($r,$modified);
1.9 raeburn 13822: }
13823: }
13824: }
13825: }
1.6 raeburn 13826: }
13827: }
13828: }
13829: if (ref($domconfig) eq 'HASH') {
13830: if (ref($domconfig->{$role}) eq 'HASH') {
13831: foreach my $img (@images) {
13832: if ($domconfig->{$role}{$img} ne '') {
13833: if ($env{'form.'.$role.'_del_'.$img}) {
13834: $confhash->{$role}{$img} = '';
1.12 raeburn 13835: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13836: } else {
1.9 raeburn 13837: if ($confhash->{$role}{$img} eq '') {
13838: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13839: }
1.6 raeburn 13840: }
13841: } else {
13842: if ($env{'form.'.$role.'_del_'.$img}) {
13843: $confhash->{$role}{$img} = '';
1.12 raeburn 13844: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13845: }
13846: }
1.402 raeburn 13847: if ($role eq 'login') {
13848: if (($img eq 'logo') || ($img eq 'img')) {
13849: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13850: if ($confhash->{$role}{'showlogo'}{$img} ne
13851: $domconfig->{$role}{'showlogo'}{$img}) {
13852: $changes{$role}{'showlogo'}{$img} = 1;
13853: }
13854: } else {
13855: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13856: $changes{$role}{'showlogo'}{$img} = 1;
13857: }
1.70 raeburn 13858: }
1.402 raeburn 13859: }
13860: if ($img ne 'login') {
13861: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13862: if ($confhash->{$role}{'alttext'}{$img} ne
13863: $domconfig->{$role}{'alttext'}{$img}) {
13864: $changes{$role}{'alttext'}{$img} = 1;
13865: }
13866: } else {
13867: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13868: $changes{$role}{'alttext'}{$img} = 1;
13869: }
1.70 raeburn 13870: }
13871: }
13872: }
13873: }
1.6 raeburn 13874: if ($domconfig->{$role}{'font'} ne '') {
13875: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13876: $changes{$role}{'font'} = 1;
13877: }
13878: } else {
13879: if ($confhash->{$role}{'font'}) {
13880: $changes{$role}{'font'} = 1;
13881: }
13882: }
1.107 raeburn 13883: if ($role ne 'login') {
13884: if ($domconfig->{$role}{'fontmenu'} ne '') {
13885: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13886: $changes{$role}{'fontmenu'} = 1;
13887: }
13888: } else {
13889: if ($confhash->{$role}{'fontmenu'}) {
13890: $changes{$role}{'fontmenu'} = 1;
13891: }
1.97 tempelho 13892: }
13893: }
1.6 raeburn 13894: foreach my $item (@bgs) {
13895: if ($domconfig->{$role}{$item} ne '') {
13896: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13897: $changes{$role}{'bgs'}{$item} = 1;
13898: }
13899: } else {
13900: if ($confhash->{$role}{$item}) {
13901: $changes{$role}{'bgs'}{$item} = 1;
13902: }
13903: }
13904: }
13905: foreach my $item (@links) {
13906: if ($domconfig->{$role}{$item} ne '') {
13907: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13908: $changes{$role}{'links'}{$item} = 1;
13909: }
13910: } else {
13911: if ($confhash->{$role}{$item}) {
13912: $changes{$role}{'links'}{$item} = 1;
13913: }
13914: }
13915: }
1.41 raeburn 13916: foreach my $item (@logintext) {
13917: if ($domconfig->{$role}{$item} ne '') {
13918: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13919: $changes{$role}{'logintext'}{$item} = 1;
13920: }
13921: } else {
13922: if ($confhash->{$role}{$item}) {
13923: $changes{$role}{'logintext'}{$item} = 1;
13924: }
13925: }
13926: }
1.6 raeburn 13927: } else {
13928: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13929: \@logintext,$confhash,\%changes);
1.6 raeburn 13930: }
13931: } else {
13932: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13933: \@logintext,$confhash,\%changes);
1.6 raeburn 13934: }
13935: }
13936: return ($errors,%changes);
13937: }
13938:
1.46 raeburn 13939: sub config_check {
13940: my ($dom,$confname,$servadm) = @_;
13941: my ($configuserok,$author_ok,$switchserver,%currroles);
13942: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13943: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13944: $confname,$servadm);
13945: if ($configuserok eq 'ok') {
13946: $switchserver = &check_switchserver($dom,$confname);
13947: if ($switchserver eq '') {
13948: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13949: }
13950: }
13951: return ($configuserok,$author_ok,$switchserver);
13952: }
13953:
1.6 raeburn 13954: sub default_change_checker {
1.41 raeburn 13955: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13956: foreach my $item (@{$links}) {
13957: if ($confhash->{$role}{$item}) {
13958: $changes->{$role}{'links'}{$item} = 1;
13959: }
13960: }
13961: foreach my $item (@{$bgs}) {
13962: if ($confhash->{$role}{$item}) {
13963: $changes->{$role}{'bgs'}{$item} = 1;
13964: }
13965: }
1.41 raeburn 13966: foreach my $item (@{$logintext}) {
13967: if ($confhash->{$role}{$item}) {
13968: $changes->{$role}{'logintext'}{$item} = 1;
13969: }
13970: }
1.6 raeburn 13971: foreach my $img (@{$images}) {
13972: if ($env{'form.'.$role.'_del_'.$img}) {
13973: $confhash->{$role}{$img} = '';
1.12 raeburn 13974: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13975: }
1.70 raeburn 13976: if ($role eq 'login') {
13977: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13978: $changes->{$role}{'showlogo'}{$img} = 1;
13979: }
1.402 raeburn 13980: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13981: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13982: $changes->{$role}{'alttext'}{$img} = 1;
13983: }
13984: }
1.70 raeburn 13985: }
1.6 raeburn 13986: }
13987: if ($confhash->{$role}{'font'}) {
13988: $changes->{$role}{'font'} = 1;
13989: }
1.48 raeburn 13990: }
1.6 raeburn 13991:
13992: sub display_colorchgs {
13993: my ($dom,$changes,$roles,$confhash) = @_;
13994: my (%choices,$resulttext);
13995: if (!grep(/^login$/,@{$roles})) {
13996: $resulttext = &mt('Changes made:').'<br />';
13997: }
13998: foreach my $role (@{$roles}) {
13999: if ($role eq 'login') {
14000: %choices = &login_choices();
14001: } else {
14002: %choices = &color_font_choices();
14003: }
14004: if (ref($changes->{$role}) eq 'HASH') {
14005: if ($role ne 'login') {
14006: $resulttext .= '<h4>'.&mt($role).'</h4>';
14007: }
14008: foreach my $key (sort(keys(%{$changes->{$role}}))) {
14009: if ($role ne 'login') {
14010: $resulttext .= '<ul>';
14011: }
14012: if (ref($changes->{$role}{$key}) eq 'HASH') {
14013: if ($role ne 'login') {
14014: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
14015: }
14016: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 14017: if (($role eq 'login') && ($key eq 'showlogo')) {
14018: if ($confhash->{$role}{$key}{$item}) {
14019: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
14020: } else {
14021: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
14022: }
1.402 raeburn 14023: } elsif (($role eq 'login') && ($key eq 'alttext')) {
14024: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 14025: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 14026: $confhash->{$role}{$key}{$item}).'</li>';
14027: } else {
14028: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
14029: }
1.70 raeburn 14030: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 14031: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
14032: } else {
1.12 raeburn 14033: my $newitem = $confhash->{$role}{$item};
14034: if ($key eq 'images') {
1.306 raeburn 14035: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 14036: }
14037: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 14038: }
14039: }
14040: if ($role ne 'login') {
14041: $resulttext .= '</ul></li>';
14042: }
14043: } else {
14044: if ($confhash->{$role}{$key} eq '') {
14045: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
14046: } else {
14047: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
14048: }
14049: }
14050: if ($role ne 'login') {
14051: $resulttext .= '</ul>';
14052: }
14053: }
14054: }
14055: }
1.3 raeburn 14056: return $resulttext;
1.1 raeburn 14057: }
14058:
1.9 raeburn 14059: sub thumb_dimensions {
14060: return ('200','50');
14061: }
14062:
1.16 raeburn 14063: sub check_dimensions {
14064: my ($inputfile) = @_;
14065: my ($fullwidth,$fullheight);
14066: if ($inputfile =~ m|^[/\w.\-]+$|) {
14067: if (open(PIPE,"identify $inputfile 2>&1 |")) {
14068: my $imageinfo = <PIPE>;
14069: if (!close(PIPE)) {
14070: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
14071: }
14072: chomp($imageinfo);
14073: my ($fullsize) =
1.21 raeburn 14074: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 14075: if ($fullsize) {
14076: ($fullwidth,$fullheight) = split(/x/,$fullsize);
14077: }
14078: }
14079: }
14080: return ($fullwidth,$fullheight);
14081: }
14082:
1.9 raeburn 14083: sub check_configuser {
14084: my ($uhome,$dom,$confname,$servadm) = @_;
14085: my ($configuserok,%currroles);
14086: if ($uhome eq 'no_host') {
14087: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 14088: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 14089: $configuserok =
14090: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
14091: $configpass,'','','','','',undef,$servadm);
14092: } else {
14093: $configuserok = 'ok';
14094: %currroles =
14095: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
14096: }
14097: return ($configuserok,%currroles);
14098: }
14099:
14100: sub check_authorstatus {
14101: my ($dom,$confname,%currroles) = @_;
14102: my $author_ok;
1.40 raeburn 14103: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 14104: my $start = time;
14105: my $end = 0;
14106: $author_ok =
14107: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 14108: 'au',$end,$start,'','','domconfig');
1.9 raeburn 14109: } else {
14110: $author_ok = 'ok';
14111: }
14112: return $author_ok;
14113: }
14114:
1.421 raeburn 14115: sub update_modify_urls {
14116: my ($r,$modified) = @_;
14117: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
14118: push(@{$modified_urls},$modified);
14119: unless ($registered_cleanup) {
14120: my $handlers = $r->get_handlers('PerlCleanupHandler');
14121: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
14122: $registered_cleanup=1;
1.9 raeburn 14123: }
14124: }
1.155 raeburn 14125: }
14126:
14127: sub notifysubscribed {
14128: foreach my $targetsource (@{$modified_urls}){
14129: next unless (ref($targetsource) eq 'ARRAY');
14130: my ($target,$source)=@{$targetsource};
14131: if ($source ne '') {
1.316 raeburn 14132: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 14133: print $logfh "\nCleanup phase: Notifications\n";
14134: my @subscribed=&subscribed_hosts($target);
14135: foreach my $subhost (@subscribed) {
14136: print $logfh "\nNotifying host ".$subhost.':';
14137: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
14138: print $logfh $reply;
14139: }
14140: my @subscribedmeta=&subscribed_hosts("$target.meta");
14141: foreach my $subhost (@subscribedmeta) {
14142: print $logfh "\nNotifying host for metadata only ".$subhost.':';
14143: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
14144: $subhost);
14145: print $logfh $reply;
14146: }
14147: print $logfh "\n============ Done ============\n";
1.160 raeburn 14148: close($logfh);
1.155 raeburn 14149: }
14150: }
14151: }
14152: return OK;
14153: }
14154:
14155: sub subscribed_hosts {
14156: my ($target) = @_;
14157: my @subscribed;
1.316 raeburn 14158: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 14159: while (my $subline=<$fh>) {
14160: if ($subline =~ /^($match_lonid):/) {
14161: my $host = $1;
14162: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
14163: unless (grep(/^\Q$host\E$/,@subscribed)) {
14164: push(@subscribed,$host);
14165: }
14166: }
14167: }
14168: }
14169: }
14170: return @subscribed;
1.9 raeburn 14171: }
14172:
14173: sub check_switchserver {
14174: my ($dom,$confname) = @_;
1.424 raeburn 14175: my ($allowed,$switchserver,$home);
14176: if ($confname eq '') {
1.9 raeburn 14177: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14178: } else {
14179: $home = &Apache::lonnet::homeserver($confname,$dom);
14180: if ($home eq 'no_host') {
14181: $home = &Apache::lonnet::domain($dom,'primary');
14182: }
1.9 raeburn 14183: }
14184: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14185: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14186: if (!$allowed) {
1.426 raeburn 14187: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14188: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14189: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14190: }
14191: return $switchserver;
14192: }
14193:
1.1 raeburn 14194: sub modify_quotas {
1.216 raeburn 14195: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14196: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14197: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14198: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14199: $validationfieldsref);
1.86 raeburn 14200: if ($action eq 'quotas') {
1.429 raeburn 14201: $context = 'tools';
1.163 raeburn 14202: } else {
1.86 raeburn 14203: $context = $action;
14204: }
14205: if ($context eq 'requestcourses') {
1.325 raeburn 14206: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14207: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14208: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14209: %titles = &courserequest_titles();
14210: $toolregexp = join('|',@usertools);
14211: %conditions = &courserequest_conditions();
1.216 raeburn 14212: $confname = $dom.'-domainconfig';
14213: my $servadm = $r->dir_config('lonAdmEMail');
14214: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14215: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14216: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14217: } elsif ($context eq 'requestauthor') {
14218: @usertools = ('author');
14219: %titles = &authorrequest_titles();
1.86 raeburn 14220: } else {
1.430 raeburn 14221: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14222: %titles = &tool_titles();
1.86 raeburn 14223: }
1.212 raeburn 14224: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14225: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14226: foreach my $key (keys(%env)) {
1.101 raeburn 14227: if ($context eq 'requestcourses') {
14228: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14229: my $item = $1;
14230: my $type = $2;
14231: if ($type =~ /^limit_(.+)/) {
14232: $limithash{$item}{$1} = $env{$key};
14233: } else {
14234: $confhash{$item}{$type} = $env{$key};
14235: }
14236: }
1.163 raeburn 14237: } elsif ($context eq 'requestauthor') {
14238: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14239: $confhash{$1} = $env{$key};
14240: }
1.101 raeburn 14241: } else {
1.86 raeburn 14242: if ($key =~ /^form\.quota_(.+)$/) {
14243: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14244: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14245: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14246: }
1.72 raeburn 14247: }
14248: }
1.163 raeburn 14249: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14250: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14251: @approvalnotify = sort(@approvalnotify);
14252: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14253: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14254: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14255: foreach my $type (@hasuniquecode) {
14256: if (grep(/^\Q$type\E$/,@crstypes)) {
14257: $confhash{'uniquecode'}{$type} = 1;
14258: }
1.216 raeburn 14259: }
1.242 raeburn 14260: my (%newbook,%allpos);
1.216 raeburn 14261: if ($context eq 'requestcourses') {
1.242 raeburn 14262: foreach my $type ('textbooks','templates') {
14263: @{$allpos{$type}} = ();
14264: my $invalid;
14265: if ($type eq 'textbooks') {
14266: $invalid = &mt('Invalid LON-CAPA course for textbook');
14267: } else {
14268: $invalid = &mt('Invalid LON-CAPA course for template');
14269: }
14270: if ($env{'form.'.$type.'_addbook'}) {
14271: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14272: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14273: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14274: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14275: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14276: } else {
14277: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14278: my $position = $env{'form.'.$type.'_addbook_pos'};
14279: $position =~ s/\D+//g;
14280: if ($position ne '') {
14281: $allpos{$type}[$position] = $newbook{$type};
14282: }
1.216 raeburn 14283: }
1.242 raeburn 14284: } else {
14285: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14286: }
14287: }
1.242 raeburn 14288: }
1.216 raeburn 14289: }
1.102 raeburn 14290: if (ref($domconfig{$action}) eq 'HASH') {
14291: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14292: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14293: $changes{'notify'}{'approval'} = 1;
14294: }
14295: } else {
1.144 raeburn 14296: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14297: $changes{'notify'}{'approval'} = 1;
14298: }
14299: }
1.218 raeburn 14300: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14301: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14302: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14303: unless ($confhash{'uniquecode'}{$crstype}) {
14304: $changes{'uniquecode'} = 1;
14305: }
14306: }
14307: unless ($changes{'uniquecode'}) {
14308: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14309: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14310: $changes{'uniquecode'} = 1;
14311: }
14312: }
14313: }
14314: } else {
14315: $changes{'uniquecode'} = 1;
14316: }
14317: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14318: $changes{'uniquecode'} = 1;
1.216 raeburn 14319: }
14320: if ($context eq 'requestcourses') {
1.242 raeburn 14321: foreach my $type ('textbooks','templates') {
14322: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14323: my %deletions;
14324: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14325: if (@todelete) {
14326: map { $deletions{$_} = 1; } @todelete;
14327: }
14328: my %imgdeletions;
14329: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14330: if (@todeleteimages) {
14331: map { $imgdeletions{$_} = 1; } @todeleteimages;
14332: }
14333: my $maxnum = $env{'form.'.$type.'_maxnum'};
14334: for (my $i=0; $i<=$maxnum; $i++) {
14335: my $itemid = $env{'form.'.$type.'_id_'.$i};
14336: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14337: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14338: if ($deletions{$key}) {
14339: if ($domconfig{$action}{$type}{$key}{'image'}) {
14340: #FIXME need to obsolete item in RES space
14341: }
14342: next;
14343: } else {
14344: my $newpos = $env{'form.'.$itemid};
14345: $newpos =~ s/\D+//g;
1.243 raeburn 14346: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14347: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14348: ($type eq 'templates'));
1.242 raeburn 14349: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14350: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14351: $changes{$type}{$key} = 1;
14352: }
14353: }
14354: $allpos{$type}[$newpos] = $key;
14355: }
14356: if ($imgdeletions{$key}) {
14357: $changes{$type}{$key} = 1;
1.216 raeburn 14358: #FIXME need to obsolete item in RES space
1.242 raeburn 14359: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14360: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14361: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14362: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14363: } else {
14364: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14365: $cdom,$cnum,$type,$configuserok,
14366: $switchserver,$author_ok);
14367: if ($imgurl) {
14368: $confhash{$type}{$key}{'image'} = $imgurl;
14369: $changes{$type}{$key} = 1;
14370: }
14371: if ($error) {
14372: &Apache::lonnet::logthis($error);
14373: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14374: }
14375: }
1.242 raeburn 14376: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14377: $confhash{$type}{$key}{'image'} =
14378: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14379: }
14380: }
14381: }
14382: }
14383: }
14384: }
1.102 raeburn 14385: } else {
1.144 raeburn 14386: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14387: $changes{'notify'}{'approval'} = 1;
14388: }
1.218 raeburn 14389: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14390: $changes{'uniquecode'} = 1;
14391: }
14392: }
14393: if ($context eq 'requestcourses') {
1.242 raeburn 14394: foreach my $type ('textbooks','templates') {
14395: if ($newbook{$type}) {
14396: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14397: foreach my $item ('subject','title','publisher','author') {
14398: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14399: ($type eq 'template'));
1.242 raeburn 14400: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14401: if ($env{'form.'.$type.'_addbook_'.$item}) {
14402: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14403: }
14404: }
14405: if ($type eq 'textbooks') {
14406: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14407: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14408: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14409: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14410: } else {
14411: my ($imageurl,$error) =
14412: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14413: $configuserok,$switchserver,$author_ok);
14414: if ($imageurl) {
14415: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14416: }
14417: if ($error) {
14418: &Apache::lonnet::logthis($error);
14419: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14420: }
1.242 raeburn 14421: }
14422: }
1.216 raeburn 14423: }
14424: }
1.242 raeburn 14425: if (@{$allpos{$type}} > 0) {
14426: my $idx = 0;
14427: foreach my $item (@{$allpos{$type}}) {
14428: if ($item ne '') {
14429: $confhash{$type}{$item}{'order'} = $idx;
14430: if (ref($domconfig{$action}) eq 'HASH') {
14431: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14432: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14433: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14434: $changes{$type}{$item} = 1;
14435: }
1.216 raeburn 14436: }
14437: }
14438: }
1.242 raeburn 14439: $idx ++;
1.216 raeburn 14440: }
14441: }
14442: }
14443: }
1.235 raeburn 14444: if (ref($validationitemsref) eq 'ARRAY') {
14445: foreach my $item (@{$validationitemsref}) {
14446: if ($item eq 'fields') {
14447: my @changed;
14448: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14449: if (@{$confhash{'validation'}{$item}} > 0) {
14450: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14451: }
1.266 raeburn 14452: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14453: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14454: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14455: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14456: $domconfig{'requestcourses'}{'validation'}{$item});
14457: } else {
14458: @changed = @{$confhash{'validation'}{$item}};
14459: }
1.235 raeburn 14460: } else {
14461: @changed = @{$confhash{'validation'}{$item}};
14462: }
14463: } else {
14464: @changed = @{$confhash{'validation'}{$item}};
14465: }
14466: if (@changed) {
14467: if ($confhash{'validation'}{$item}) {
14468: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14469: } else {
14470: $changes{'validation'}{$item} = &mt('None');
14471: }
14472: }
14473: } else {
14474: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14475: if ($item eq 'markup') {
14476: if ($env{'form.requestcourses_validation_'.$item}) {
14477: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14478: }
14479: }
1.266 raeburn 14480: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14481: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14482: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14483: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14484: }
14485: } else {
14486: if ($confhash{'validation'}{$item} ne '') {
14487: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14488: }
1.235 raeburn 14489: }
14490: } else {
14491: if ($confhash{'validation'}{$item} ne '') {
14492: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14493: }
14494: }
14495: }
14496: }
14497: }
14498: if ($env{'form.validationdc'}) {
14499: my $newval = $env{'form.validationdc'};
1.285 raeburn 14500: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14501: if (exists($domcoords{$newval})) {
14502: $confhash{'validation'}{'dc'} = $newval;
14503: }
14504: }
14505: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14506: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14507: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14508: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14509: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14510: if ($confhash{'validation'}{'dc'} eq '') {
14511: $changes{'validation'}{'dc'} = &mt('None');
14512: } else {
14513: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14514: }
1.235 raeburn 14515: }
1.266 raeburn 14516: } elsif ($confhash{'validation'}{'dc'} ne '') {
14517: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14518: }
14519: } elsif ($confhash{'validation'}{'dc'} ne '') {
14520: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14521: }
14522: } elsif ($confhash{'validation'}{'dc'} ne '') {
14523: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14524: }
1.266 raeburn 14525: } else {
14526: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14527: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14528: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14529: $changes{'validation'}{'dc'} = &mt('None');
14530: }
14531: }
1.235 raeburn 14532: }
14533: }
1.102 raeburn 14534: }
14535: } else {
1.86 raeburn 14536: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14537: }
1.72 raeburn 14538: foreach my $item (@usertools) {
14539: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14540: my $unset;
1.101 raeburn 14541: if ($context eq 'requestcourses') {
1.104 raeburn 14542: $unset = '0';
14543: if ($type eq '_LC_adv') {
14544: $unset = '';
14545: }
1.101 raeburn 14546: if ($confhash{$item}{$type} eq 'autolimit') {
14547: $confhash{$item}{$type} .= '=';
14548: unless ($limithash{$item}{$type} =~ /\D/) {
14549: $confhash{$item}{$type} .= $limithash{$item}{$type};
14550: }
14551: }
1.163 raeburn 14552: } elsif ($context eq 'requestauthor') {
14553: $unset = '0';
14554: if ($type eq '_LC_adv') {
14555: $unset = '';
14556: }
1.72 raeburn 14557: } else {
1.101 raeburn 14558: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14559: $confhash{$item}{$type} = 1;
14560: } else {
14561: $confhash{$item}{$type} = 0;
14562: }
1.72 raeburn 14563: }
1.86 raeburn 14564: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14565: if ($action eq 'requestauthor') {
14566: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14567: $changes{$type} = 1;
14568: }
14569: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14570: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14571: $changes{$item}{$type} = 1;
14572: }
14573: } else {
14574: if ($context eq 'requestcourses') {
1.104 raeburn 14575: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14576: $changes{$item}{$type} = 1;
14577: }
14578: } else {
14579: if (!$confhash{$item}{$type}) {
14580: $changes{$item}{$type} = 1;
14581: }
14582: }
14583: }
14584: } else {
14585: if ($context eq 'requestcourses') {
1.104 raeburn 14586: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14587: $changes{$item}{$type} = 1;
14588: }
1.163 raeburn 14589: } elsif ($context eq 'requestauthor') {
14590: if ($confhash{$type} ne $unset) {
14591: $changes{$type} = 1;
14592: }
1.72 raeburn 14593: } else {
14594: if (!$confhash{$item}{$type}) {
14595: $changes{$item}{$type} = 1;
14596: }
14597: }
14598: }
1.1 raeburn 14599: }
14600: }
1.163 raeburn 14601: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14602: if (ref($domconfig{'quotas'}) eq 'HASH') {
14603: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14604: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14605: if (exists($confhash{'defaultquota'}{$key})) {
14606: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14607: $changes{'defaultquota'}{$key} = 1;
14608: }
14609: } else {
14610: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14611: }
14612: }
1.86 raeburn 14613: } else {
14614: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14615: if (exists($confhash{'defaultquota'}{$key})) {
14616: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14617: $changes{'defaultquota'}{$key} = 1;
14618: }
14619: } else {
14620: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14621: }
1.1 raeburn 14622: }
14623: }
1.197 raeburn 14624: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14625: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14626: }
14627: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14628: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14629: }
1.1 raeburn 14630: }
1.86 raeburn 14631: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14632: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14633: if (ref($domconfig{'quotas'}) eq 'HASH') {
14634: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14635: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14636: $changes{'defaultquota'}{$key} = 1;
14637: }
14638: } else {
14639: if (!exists($domconfig{'quotas'}{$key})) {
14640: $changes{'defaultquota'}{$key} = 1;
14641: }
1.72 raeburn 14642: }
14643: } else {
1.86 raeburn 14644: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14645: }
1.1 raeburn 14646: }
14647: }
14648: }
1.72 raeburn 14649:
1.163 raeburn 14650: if ($context eq 'requestauthor') {
14651: $domdefaults{'requestauthor'} = \%confhash;
14652: } else {
14653: foreach my $key (keys(%confhash)) {
1.242 raeburn 14654: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14655: $domdefaults{$key} = $confhash{$key};
14656: }
1.163 raeburn 14657: }
1.72 raeburn 14658: }
1.163 raeburn 14659:
1.1 raeburn 14660: my %quotahash = (
1.86 raeburn 14661: $action => { %confhash }
1.1 raeburn 14662: );
14663: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14664: $dom);
14665: if ($putresult eq 'ok') {
14666: if (keys(%changes) > 0) {
1.72 raeburn 14667: my $cachetime = 24*60*60;
14668: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14669: if (ref($lastactref) eq 'HASH') {
14670: $lastactref->{'domdefaults'} = 1;
14671: }
1.1 raeburn 14672: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14673: unless (($context eq 'requestcourses') ||
1.163 raeburn 14674: ($context eq 'requestauthor')) {
1.86 raeburn 14675: if (ref($changes{'defaultquota'}) eq 'HASH') {
14676: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14677: foreach my $type (@{$types},'default') {
14678: if (defined($changes{'defaultquota'}{$type})) {
14679: my $typetitle = $usertypes->{$type};
14680: if ($type eq 'default') {
14681: $typetitle = $othertitle;
14682: }
1.213 raeburn 14683: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14684: }
14685: }
1.86 raeburn 14686: $resulttext .= '</ul></li>';
1.72 raeburn 14687: }
14688: }
1.80 raeburn 14689: my %newenv;
1.72 raeburn 14690: foreach my $item (@usertools) {
1.163 raeburn 14691: my (%haschgs,%inconf);
14692: if ($context eq 'requestauthor') {
14693: %haschgs = %changes;
1.210 raeburn 14694: %inconf = %confhash;
1.163 raeburn 14695: } else {
14696: if (ref($changes{$item}) eq 'HASH') {
14697: %haschgs = %{$changes{$item}};
14698: }
14699: if (ref($confhash{$item}) eq 'HASH') {
14700: %inconf = %{$confhash{$item}};
14701: }
14702: }
14703: if (keys(%haschgs) > 0) {
1.80 raeburn 14704: my $newacc =
14705: &Apache::lonnet::usertools_access($env{'user.name'},
14706: $env{'user.domain'},
1.86 raeburn 14707: $item,'reload',$context);
1.210 raeburn 14708: if (($context eq 'requestcourses') ||
1.163 raeburn 14709: ($context eq 'requestauthor')) {
1.108 raeburn 14710: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14711: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14712: }
14713: } else {
14714: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14715: $newenv{'environment.availabletools.'.$item} = $newacc;
14716: }
1.80 raeburn 14717: }
1.163 raeburn 14718: unless ($context eq 'requestauthor') {
14719: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14720: }
1.72 raeburn 14721: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14722: if ($haschgs{$type}) {
1.72 raeburn 14723: my $typetitle = $usertypes->{$type};
14724: if ($type eq 'default') {
14725: $typetitle = $othertitle;
14726: } elsif ($type eq '_LC_adv') {
14727: $typetitle = 'LON-CAPA Advanced Users';
14728: }
1.163 raeburn 14729: if ($inconf{$type}) {
1.101 raeburn 14730: if ($context eq 'requestcourses') {
14731: my $cond;
1.163 raeburn 14732: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14733: if ($1 eq '') {
14734: $cond = &mt('(Automatic processing of any request).');
14735: } else {
14736: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14737: }
14738: } else {
1.163 raeburn 14739: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14740: }
14741: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14742: } elsif ($context eq 'requestauthor') {
14743: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14744: $titles{$inconf{$type}},$typetitle);
14745:
1.101 raeburn 14746: } else {
14747: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14748: }
1.72 raeburn 14749: } else {
1.104 raeburn 14750: if ($type eq '_LC_adv') {
1.163 raeburn 14751: if ($inconf{$type} eq '0') {
1.104 raeburn 14752: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14753: } else {
14754: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14755: }
14756: } else {
14757: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14758: }
1.72 raeburn 14759: }
14760: }
1.26 raeburn 14761: }
1.163 raeburn 14762: unless ($context eq 'requestauthor') {
14763: $resulttext .= '</ul></li>';
14764: }
1.26 raeburn 14765: }
1.1 raeburn 14766: }
1.163 raeburn 14767: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14768: if (ref($changes{'notify'}) eq 'HASH') {
14769: if ($changes{'notify'}{'approval'}) {
14770: if (ref($confhash{'notify'}) eq 'HASH') {
14771: if ($confhash{'notify'}{'approval'}) {
14772: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14773: } else {
1.163 raeburn 14774: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14775: }
14776: }
14777: }
14778: }
14779: }
1.216 raeburn 14780: if ($action eq 'requestcourses') {
14781: my @offon = ('off','on');
14782: if ($changes{'uniquecode'}) {
1.218 raeburn 14783: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14784: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14785: $resulttext .= '<li>'.
14786: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14787: '</li>';
14788: } else {
14789: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14790: '</li>';
14791: }
1.216 raeburn 14792: }
1.242 raeburn 14793: foreach my $type ('textbooks','templates') {
14794: if (ref($changes{$type}) eq 'HASH') {
14795: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14796: foreach my $key (sort(keys(%{$changes{$type}}))) {
14797: my %coursehash = &Apache::lonnet::coursedescription($key);
14798: my $coursetitle = $coursehash{'description'};
14799: my $position = $confhash{$type}{$key}{'order'} + 1;
14800: $resulttext .= '<li>';
1.243 raeburn 14801: foreach my $item ('subject','title','publisher','author') {
14802: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14803: ($type eq 'templates'));
1.242 raeburn 14804: my $name = $item.':';
14805: $name =~ s/^(\w)/\U$1/;
14806: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14807: }
14808: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14809: if ($type eq 'textbooks') {
14810: if ($confhash{$type}{$key}{'image'}) {
14811: $resulttext .= ' '.&mt('Image: [_1]',
14812: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14813: ' alt="Textbook cover" />').'<br />';
14814: }
14815: }
14816: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14817: }
1.242 raeburn 14818: $resulttext .= '</ul></li>';
1.216 raeburn 14819: }
14820: }
1.235 raeburn 14821: if (ref($changes{'validation'}) eq 'HASH') {
14822: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14823: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14824: foreach my $item (@{$validationitemsref}) {
14825: if (exists($changes{'validation'}{$item})) {
14826: if ($item eq 'markup') {
14827: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14828: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14829: } else {
14830: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14831: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14832: }
14833: }
14834: }
14835: if (exists($changes{'validation'}{'dc'})) {
14836: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14837: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14838: }
1.442 raeburn 14839: $resulttext .= '</ul></li>';
1.235 raeburn 14840: }
14841: }
1.216 raeburn 14842: }
1.1 raeburn 14843: $resulttext .= '</ul>';
1.80 raeburn 14844: if (keys(%newenv)) {
14845: &Apache::lonnet::appenv(\%newenv);
14846: }
1.1 raeburn 14847: } else {
1.86 raeburn 14848: if ($context eq 'requestcourses') {
14849: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14850: } elsif ($context eq 'requestauthor') {
14851: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14852: } else {
1.90 weissno 14853: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14854: }
1.1 raeburn 14855: }
14856: } else {
1.11 albertel 14857: $resulttext = '<span class="LC_error">'.
14858: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14859: }
1.216 raeburn 14860: if ($errors) {
14861: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14862: '<ul>'.$errors.'</ul></p>';
14863: }
1.3 raeburn 14864: return $resulttext;
1.1 raeburn 14865: }
14866:
1.216 raeburn 14867: sub process_textbook_image {
1.242 raeburn 14868: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14869: my $filename = $env{'form.'.$caller.'.filename'};
14870: my ($error,$url);
14871: my ($width,$height) = (50,50);
14872: if ($configuserok eq 'ok') {
14873: if ($switchserver) {
14874: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14875: $switchserver);
14876: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14877: my $modified = [];
1.216 raeburn 14878: my ($result,$imageurl) =
1.421 raeburn 14879: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14880: "$type/$cdom/$cnum/cover",$width,$height,
14881: '',$modified);
1.216 raeburn 14882: if ($result eq 'ok') {
14883: $url = $imageurl;
1.421 raeburn 14884: &update_modify_urls($r,$modified);
1.216 raeburn 14885: } else {
14886: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14887: }
14888: } else {
14889: $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);
14890: }
14891: } else {
14892: $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);
14893: }
14894: return ($url,$error);
14895: }
14896:
1.267 raeburn 14897: sub modify_ltitools {
14898: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14899: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14900: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14901:
1.267 raeburn 14902: my $confname = $dom.'-domainconfig';
14903: my $servadm = $r->dir_config('lonAdmEMail');
14904: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14905:
14906: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14907: my $toolserror =
14908: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14909: $lastactref,$configuserok,$switchserver,$author_ok);
14910:
14911: my $home = &Apache::lonnet::domain($dom,'primary');
14912: unless (($home eq 'no_host') || ($home eq '')) {
14913: my @ids=&Apache::lonnet::current_machine_ids();
14914: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14915: }
14916:
14917: if (keys(%ltitoolschg)) {
14918: foreach my $id (keys(%ltitoolschg)) {
14919: if (ref($ltitoolschg{$id}) eq 'HASH') {
14920: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14921: if (($inner eq 'secret') || ($inner eq 'key')) {
14922: if ($is_home) {
14923: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14924: }
14925: }
14926: }
1.267 raeburn 14927: }
1.421 raeburn 14928: }
14929: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14930: if (keys(%ltitoolschg)) {
14931: %newltitools = %ltitoolschg;
14932: }
14933: }
14934: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14935: foreach my $id (%{$domconfig{'ltitools'}}) {
14936: next if ($id !~ /^\d+$/);
14937: unless (exists($ltitoolschg{$id})) {
14938: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14939: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14940: if (($inner eq 'secret') || ($inner eq 'key')) {
14941: if ($is_home) {
14942: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14943: }
14944: } else {
14945: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14946: }
14947: }
14948: } else {
14949: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14950: }
1.421 raeburn 14951: }
14952: }
14953: }
14954: if ($toolserror) {
14955: $errors = '<li>'.$toolserror.'</li>';
14956: }
14957: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14958: $resulttext = &mt('No changes made.');
14959: if ($errors) {
14960: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14961: $errors.'</ul>';
14962: }
14963: return $resulttext;
14964: }
14965: my %ltitoolshash = (
14966: $action => { %newltitools }
14967: );
14968: if (keys(%secchanges)) {
14969: $ltitoolshash{'toolsec'} = \%newtoolsec;
14970: }
14971: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14972: if ($putresult eq 'ok') {
14973: my %keystore;
14974: if ($is_home) {
14975: my %toolsenchash = (
14976: $action => { %newtoolsenc }
14977: );
14978: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 14979: my $cachetime = 24*60*60;
14980: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 14981: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
14982: }
14983: $resulttext = &mt('Changes made:').'<ul>';
14984: if (keys(%secchanges) > 0) {
1.423 raeburn 14985: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 14986: }
14987: if (keys(%ltitoolschg) > 0) {
14988: $resulttext .= $ltitoolsoutput;
14989: }
1.423 raeburn 14990: my $cachetime = 24*60*60;
14991: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
14992: if (ref($lastactref) eq 'HASH') {
14993: $lastactref->{'ltitools'} = 1;
14994: }
1.421 raeburn 14995: } else {
14996: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14997: }
14998: if ($errors) {
14999: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
15000: $errors.'</ul></p>';
15001: }
15002: return $resulttext;
15003: }
15004:
15005: sub fetch_secrets {
15006: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
15007: my %keyset;
15008: %{$currsec} = ();
15009: $newsec->{'private'}{'keys'} = [];
15010: $newsec->{'encrypt'} = {};
15011: $newsec->{'rules'} = {};
15012: if ($context eq 'ltisec') {
15013: $newsec->{'linkprot'} = {};
15014: }
15015: if (ref($domconfig->{$context}) eq 'HASH') {
15016: %{$currsec} = %{$domconfig->{$context}};
15017: if ($context eq 'ltisec') {
15018: if (ref($currsec->{'linkprot'}) eq 'HASH') {
15019: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
15020: unless ($id =~ /^\d+$/) {
15021: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 15022: }
1.267 raeburn 15023: }
15024: }
1.421 raeburn 15025: }
15026: if (ref($currsec->{'private'}) eq 'HASH') {
15027: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
15028: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
15029: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 15030: }
1.421 raeburn 15031: }
15032: }
15033: my @items= ('crs','dom');
15034: if ($context eq 'ltisec') {
15035: push(@items,'consumers');
15036: }
15037: foreach my $item (@items) {
15038: my $formelement;
15039: if (($context eq 'toolsec') || ($item eq 'consumers')) {
15040: $formelement = 'form.'.$context.'_'.$item;
15041: } else {
15042: $formelement = 'form.'.$context.'_'.$item.'linkprot';
15043: }
15044: if ($env{$formelement}) {
15045: $newsec->{'encrypt'}{$item} = 1;
15046: if (ref($currsec->{'encrypt'}) eq 'HASH') {
15047: unless ($currsec->{'encrypt'}{$item}) {
15048: $secchanges->{'encrypt'} = 1;
15049: }
15050: } else {
15051: $secchanges->{'encrypt'} = 1;
1.267 raeburn 15052: }
1.421 raeburn 15053: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
15054: if ($currsec->{'encrypt'}{$item}) {
15055: $secchanges->{'encrypt'} = 1;
1.323 raeburn 15056: }
1.421 raeburn 15057: }
15058: }
15059: my $secrets;
15060: if ($context eq 'ltisec') {
15061: $secrets = 'ltisecrets';
15062: } else {
15063: $secrets = 'toolsecrets';
15064: }
15065: unless (exists($currsec->{'rules'})) {
15066: $currsec->{'rules'} = {};
15067: }
15068: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
15069:
15070: my @ids=&Apache::lonnet::current_machine_ids();
15071: my %servers = &Apache::lonnet::get_servers($dom,'library');
15072:
15073: foreach my $hostid (keys(%servers)) {
15074: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
15075: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
15076: if (exists($env{$keyitem})) {
15077: $env{$keyitem} =~ s/(`)/'/g;
15078: if ($keyset{$hostid}) {
15079: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
15080: if ($env{$keyitem} ne '') {
15081: $secchanges->{'private'} = 1;
15082: $newkeyset->{$hostid} = $env{$keyitem};
15083: }
1.296 raeburn 15084: }
1.421 raeburn 15085: } elsif ($env{$keyitem} ne '') {
15086: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
15087: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 15088: }
1.421 raeburn 15089: $secchanges->{'private'} = 1;
15090: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 15091: }
15092: }
1.421 raeburn 15093: }
15094: }
15095: }
15096:
15097: sub store_security {
1.424 raeburn 15098: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 15099: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
15100: (ref($keystore) eq 'HASH'));
15101: if (keys(%{$secchanges})) {
15102: if ($secchanges->{'private'}) {
15103: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
15104: foreach my $hostid (keys(%{$newkeyset})) {
15105: my $storehash = {
15106: key => $newkeyset->{$hostid},
15107: who => $env{'user.name'}.':'.$env{'user.domain'},
15108: };
15109: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
15110: $dom,$hostid);
15111: }
15112: }
15113: }
15114: }
15115:
15116: sub lti_security_results {
1.423 raeburn 15117: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 15118: my $output;
1.423 raeburn 15119: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15120: my $needs_update;
1.421 raeburn 15121: foreach my $item (keys(%{$secchanges})) {
15122: if ($item eq 'encrypt') {
1.423 raeburn 15123: $needs_update = 1;
1.421 raeburn 15124: my %encrypted;
15125: if ($context eq 'lti') {
15126: %encrypted = (
15127: crs => {
15128: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
15129: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
15130: },
15131: dom => {
15132: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
15133: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
15134: },
15135: consumers => {
15136: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
15137: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
15138: },
15139: );
1.267 raeburn 15140: } else {
1.421 raeburn 15141: %encrypted = (
15142: crs => {
15143: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
15144: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
15145: },
15146: dom => {
15147: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
15148: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
15149: },
15150: );
15151: }
15152: my @types= ('crs','dom');
15153: if ($context eq 'lti') {
1.423 raeburn 15154: foreach my $type (@types) {
15155: undef($domdefaults{'linkprotenc_'.$type});
15156: }
1.421 raeburn 15157: push(@types,'consumers');
1.423 raeburn 15158: undef($domdefaults{'ltienc_consumers'});
15159: } elsif ($context eq 'ltitools') {
15160: foreach my $type (@types) {
15161: undef($domdefaults{'toolenc_'.$type});
15162: }
1.267 raeburn 15163: }
1.421 raeburn 15164: foreach my $type (@types) {
15165: my $shown = $encrypted{$type}{'off'};
15166: if (ref($newsec->{$item}) eq 'HASH') {
15167: if ($newsec->{$item}{$type}) {
1.423 raeburn 15168: if ($context eq 'lti') {
15169: if ($type eq 'consumers') {
15170: $domdefaults{'ltienc_consumers'} = 1;
15171: } else {
15172: $domdefaults{'linkprotenc_'.$type} = 1;
15173: }
15174: } elsif ($context eq 'ltitools') {
15175: $domdefaults{'toolenc_'.$type} = 1;
15176: }
1.421 raeburn 15177: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15178: }
1.267 raeburn 15179: }
1.421 raeburn 15180: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15181: }
1.421 raeburn 15182: } elsif ($item eq 'rules') {
15183: my %titles = &Apache::lonlocal::texthash(
15184: min => 'Minimum password length',
15185: max => 'Maximum password length',
15186: chars => 'Required characters',
15187: );
15188: foreach my $rule ('min','max') {
15189: if ($newsec->{rules}{$rule} eq '') {
15190: if ($rule eq 'min') {
15191: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15192: ' '.&mt('Default of [_1] will be used',
15193: $Apache::lonnet::passwdmin).'</li>';
15194: } else {
15195: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15196: }
15197: } else {
15198: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15199: }
15200: }
15201: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15202: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15203: my %rulenames = &Apache::lonlocal::texthash(
15204: uc => 'At least one upper case letter',
15205: lc => 'At least one lower case letter',
15206: num => 'At least one number',
15207: spec => 'At least one non-alphanumeric',
15208: );
15209: my $needed = '<ul><li>'.
15210: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15211: '</li></ul>';
15212: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15213: } else {
15214: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15215: }
1.421 raeburn 15216: } else {
15217: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15218: }
1.421 raeburn 15219: } elsif ($item eq 'private') {
1.423 raeburn 15220: $needs_update = 1;
15221: if ($context eq 'lti') {
15222: undef($domdefaults{'ltiprivhosts'});
15223: } elsif ($context eq 'ltitools') {
15224: undef($domdefaults{'toolprivhosts'});
15225: }
1.421 raeburn 15226: if (keys(%{$newkeyset})) {
1.423 raeburn 15227: my @privhosts;
1.421 raeburn 15228: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15229: if ($keystore->{$hostid} eq 'ok') {
15230: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15231: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15232: push(@privhosts,$hostid);
15233: }
15234: }
15235: }
15236: if (@privhosts) {
15237: if ($context eq 'lti') {
15238: $domdefaults{'ltiprivhosts'} = \@privhosts;
15239: } elsif ($context eq 'ltitools') {
15240: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15241: }
15242: }
15243: }
1.421 raeburn 15244: } elsif ($item eq 'linkprot') {
15245: next;
1.434 raeburn 15246: } elsif ($item eq 'suggested') {
15247: if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
15248: (ref($newsec->{'suggested'}) eq 'HASH')) {
15249: my $suggestions;
15250: foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
15251: if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
15252: my $name = $newsec->{'suggested'}->{$id}->{'name'};
15253: my $info = $newsec->{'suggested'}->{$id}->{'info'};
15254: $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
15255: &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
15256: '</li>';
15257: } else {
15258: $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
15259: $newsec->{'suggested'}->{$id}).'</li>';
15260: }
15261: }
15262: if ($suggestions) {
15263: $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
15264: '<ul>'.$suggestions.'</ul>'.
15265: '</li>';
15266: }
15267: }
1.267 raeburn 15268: }
15269: }
1.423 raeburn 15270: if ($needs_update) {
15271: my $cachetime = 24*60*60;
15272: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15273: }
1.421 raeburn 15274: return $output;
15275: }
15276:
15277: sub modify_proctoring {
15278: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15279: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15280: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15281: my $confname = $dom.'-domainconfig';
15282: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15283: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15284: my %providernames = &proctoring_providernames();
15285: my $maxnum = scalar(keys(%providernames));
15286:
15287: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15288: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15289: if (ref($requref) eq 'HASH') {
15290: %requserfields = %{$requref};
15291: }
15292: if (ref($opturef) eq 'HASH') {
15293: %optuserfields = %{$opturef};
15294: }
15295: if (ref($defref) eq 'HASH') {
15296: %defaults = %{$defref};
15297: }
15298: if (ref($extref) eq 'HASH') {
15299: %extended = %{$extref};
15300: }
15301: if (ref($crsref) eq 'HASH') {
15302: %crsconf = %{$crsref};
15303: }
15304: if (ref($rolesref) eq 'ARRAY') {
15305: @courseroles = @{$rolesref};
15306: }
15307: if (ref($ltiref) eq 'ARRAY') {
15308: @ltiroles = @{$ltiref};
15309: }
15310:
15311: if (ref($domconfig{$action}) eq 'HASH') {
15312: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15313: if (@todeleteimages) {
15314: map { $imgdeletions{$_} = 1; } @todeleteimages;
15315: }
15316: }
15317: my %customadds;
15318: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15319: if (@newcustom) {
15320: map { $customadds{$_} = 1; } @newcustom;
15321: }
15322: foreach my $provider (sort(keys(%providernames))) {
15323: $confhash{$provider} = {};
15324: my $pos = $env{'form.proctoring_pos_'.$provider};
15325: $pos =~ s/\D+//g;
15326: $allpos[$pos] = $provider;
15327: my (%current,%currentenc);
15328: my $showroles = 0;
15329: if (ref($domconfig{$action}) eq 'HASH') {
15330: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15331: %current = %{$domconfig{$action}{$provider}};
15332: foreach my $item ('key','secret') {
15333: $currentenc{$item} = $current{$item};
15334: delete($current{$item});
15335: }
15336: }
15337: }
15338: if ($env{'form.proctoring_available_'.$provider}) {
15339: $confhash{$provider}{'available'} = 1;
15340: unless ($current{'available'}) {
15341: $changes{$provider} = 1;
15342: }
15343: } else {
15344: %{$confhash{$provider}} = %current;
15345: %{$encconfhash{$provider}} = %currentenc;
15346: $confhash{$provider}{'available'} = 0;
15347: if ($current{'available'}) {
15348: $changes{$provider} = 1;
15349: }
15350: }
15351: if ($confhash{$provider}{'available'}) {
15352: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15353: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15354: if ($field eq 'lifetime') {
15355: if ($possval =~ /^\d+$/) {
15356: $confhash{$provider}{$field} = $possval;
15357: }
15358: } elsif ($field eq 'version') {
15359: if ($possval =~ /^\d+\.\d+$/) {
15360: $confhash{$provider}{$field} = $possval;
15361: }
15362: } elsif ($field eq 'sigmethod') {
15363: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15364: $confhash{$provider}{$field} = $possval;
15365: }
15366: } elsif ($field eq 'url') {
15367: $confhash{$provider}{$field} = $possval;
15368: } elsif (($field eq 'key') || ($field eq 'secret')) {
15369: $encconfhash{$provider}{$field} = $possval;
15370: unless ($currentenc{$field} eq $possval) {
15371: $changes{$provider} = 1;
15372: }
15373: }
15374: unless (($field eq 'key') || ($field eq 'secret')) {
15375: unless ($current{$field} eq $confhash{$provider}{$field}) {
15376: $changes{$provider} = 1;
15377: }
15378: }
15379: }
15380: if ($imgdeletions{$provider}) {
15381: $changes{$provider} = 1;
15382: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15383: my ($imageurl,$error) =
15384: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15385: $configuserok,$switchserver,$author_ok);
15386: if ($imageurl) {
15387: $confhash{$provider}{'image'} = $imageurl;
15388: $changes{$provider} = 1;
15389: }
15390: if ($error) {
15391: &Apache::lonnet::logthis($error);
15392: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15393: }
15394: } elsif (exists($current{'image'})) {
15395: $confhash{$provider}{'image'} = $current{'image'};
15396: }
15397: if (ref($requserfields{$provider}) eq 'ARRAY') {
15398: if (@{$requserfields{$provider}} > 0) {
15399: if (grep(/^user$/,@{$requserfields{$provider}})) {
15400: if ($env{'form.proctoring_userincdom_'.$provider}) {
15401: $confhash{$provider}{'incdom'} = 1;
15402: }
15403: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15404: $changes{$provider} = 1;
15405: }
15406: }
15407: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15408: $showroles = 1;
15409: }
15410: }
15411: }
15412: $confhash{$provider}{'fields'} = [];
15413: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15414: if (@{$optuserfields{$provider}} > 0) {
15415: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15416: foreach my $field (@{$optuserfields{$provider}}) {
15417: if (grep(/^\Q$field\E$/,@optfields)) {
15418: push(@{$confhash{$provider}{'fields'}},$field);
15419: }
15420: }
15421: }
15422: if (ref($current{'fields'}) eq 'ARRAY') {
15423: unless ($changes{$provider}) {
15424: my @new = sort(@{$confhash{$provider}{'fields'}});
15425: my @old = sort(@{$current{'fields'}});
15426: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15427: if (@diffs) {
15428: $changes{$provider} = 1;
15429: }
15430: }
15431: } elsif (@{$confhash{$provider}{'fields'}}) {
15432: $changes{$provider} = 1;
15433: }
15434: }
15435: if (ref($defaults{$provider}) eq 'ARRAY') {
15436: if (@{$defaults{$provider}} > 0) {
15437: my %options;
15438: if (ref($extended{$provider}) eq 'HASH') {
15439: %options = %{$extended{$provider}};
15440: }
15441: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15442: foreach my $field (@{$defaults{$provider}}) {
15443: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15444: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15445: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15446: push(@{$confhash{$provider}{'defaults'}},$poss);
15447: }
15448: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15449: foreach my $inner (keys(%{$options{$field}})) {
15450: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15451: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15452: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15453: $confhash{$provider}{'defaults'}{$inner} = $poss;
15454: }
15455: } else {
15456: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15457: }
15458: }
15459: } else {
15460: if (grep(/^\Q$field\E$/,@checked)) {
15461: push(@{$confhash{$provider}{'defaults'}},$field);
15462: }
15463: }
15464: }
15465: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15466: if (ref($current{'defaults'}) eq 'ARRAY') {
15467: unless ($changes{$provider}) {
15468: my @new = sort(@{$confhash{$provider}{'defaults'}});
15469: my @old = sort(@{$current{'defaults'}});
15470: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15471: if (@diffs) {
15472: $changes{$provider} = 1;
15473: }
15474: }
15475: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15476: if (@{$current{'defaults'}}) {
15477: $changes{$provider} = 1;
15478: }
15479: }
15480: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15481: if (ref($current{'defaults'}) eq 'HASH') {
15482: unless ($changes{$provider}) {
15483: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15484: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15485: $changes{$provider} = 1;
15486: last;
15487: }
15488: }
15489: }
15490: unless ($changes{$provider}) {
15491: foreach my $key (keys(%{$current{'defaults'}})) {
15492: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15493: $changes{$provider} = 1;
15494: last;
15495: }
15496: }
15497: }
15498: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15499: $changes{$provider} = 1;
15500: }
15501: }
15502: }
15503: }
15504: if (ref($crsconf{$provider}) eq 'ARRAY') {
15505: if (@{$crsconf{$provider}} > 0) {
15506: $confhash{$provider}{'crsconf'} = [];
15507: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15508: foreach my $crsfield (@{$crsconf{$provider}}) {
15509: if (grep(/^\Q$crsfield\E$/,@checked)) {
15510: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15511: }
15512: }
15513: if (ref($current{'crsconf'}) eq 'ARRAY') {
15514: unless ($changes{$provider}) {
15515: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15516: my @old = sort(@{$current{'crsconf'}});
15517: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15518: if (@diffs) {
15519: $changes{$provider} = 1;
15520: }
15521: }
15522: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15523: $changes{$provider} = 1;
15524: }
15525: }
15526: }
15527: if ($showroles) {
15528: $confhash{$provider}{'roles'} = {};
15529: foreach my $role (@courseroles) {
15530: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15531: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15532: $confhash{$provider}{'roles'}{$role} = $poss;
15533: }
15534: }
15535: unless ($changes{$provider}) {
15536: if (ref($current{'roles'}) eq 'HASH') {
15537: foreach my $role (keys(%{$current{'roles'}})) {
15538: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15539: $changes{$provider} = 1;
15540: last
15541: }
15542: }
15543: unless ($changes{$provider}) {
15544: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15545: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15546: $changes{$provider} = 1;
15547: last;
15548: }
15549: }
15550: }
15551: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15552: $changes{$provider} = 1;
15553: }
15554: }
15555: }
15556: if (ref($current{'custom'}) eq 'HASH') {
15557: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15558: foreach my $key (keys(%{$current{'custom'}})) {
15559: if (grep(/^\Q$key\E$/,@customdels)) {
15560: $changes{$provider} = 1;
15561: } else {
15562: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15563: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15564: $changes{$provider} = 1;
15565: }
15566: }
15567: }
15568: }
15569: if ($customadds{$provider}) {
15570: my $name = $env{'form.proctoring_custom_name_'.$provider};
15571: $name =~ s/(`)/'/g;
15572: $name =~ s/^\s+//;
15573: $name =~ s/\s+$//;
15574: my $value = $env{'form.proctoring_custom_value_'.$provider};
15575: $value =~ s/(`)/'/g;
15576: $value =~ s/^\s+//;
15577: $value =~ s/\s+$//;
15578: if ($name ne '') {
15579: $confhash{$provider}{'custom'}{$name} = $value;
15580: $changes{$provider} = 1;
15581: }
15582: }
15583: }
15584: }
15585: if (@allpos > 0) {
15586: my $idx = 0;
15587: foreach my $provider (@allpos) {
15588: if ($provider ne '') {
15589: $confhash{$provider}{'order'} = $idx;
15590: unless ($changes{$provider}) {
15591: if (ref($domconfig{$action}) eq 'HASH') {
15592: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15593: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15594: $changes{$provider} = 1;
15595: }
15596: }
15597: }
15598: }
15599: $idx ++;
15600: }
15601: }
15602: }
15603: my %proc_hash = (
15604: $action => { %confhash }
15605: );
15606: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15607: $dom);
15608: if ($putresult eq 'ok') {
15609: my %proc_enchash = (
15610: $action => { %encconfhash }
15611: );
1.384 raeburn 15612: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15613: if (keys(%changes) > 0) {
15614: my $cachetime = 24*60*60;
15615: my %procall = %confhash;
15616: foreach my $provider (keys(%procall)) {
15617: if (ref($encconfhash{$provider}) eq 'HASH') {
15618: foreach my $key ('key','secret') {
15619: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15620: }
15621: }
15622: }
15623: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15624: if (ref($lastactref) eq 'HASH') {
15625: $lastactref->{'proctoring'} = 1;
15626: }
15627: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15628: my %bynum;
15629: foreach my $provider (sort(keys(%changes))) {
15630: my $position = $confhash{$provider}{'order'};
15631: $bynum{$position} = $provider;
15632: }
15633: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15634: my $provider = $bynum{$pos};
15635: my %lt = &proctoring_titles($provider);
15636: my %fieldtitles = &proctoring_fieldtitles($provider);
15637: if (!$confhash{$provider}{'available'}) {
15638: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15639: } else {
15640: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15641: if ($confhash{$provider}{'image'}) {
15642: $resulttext .= ' '.
15643: '<img src="'.$confhash{$provider}{'image'}.'"'.
15644: ' alt="'.&mt('Proctoring icon').'" />';
15645: }
15646: $resulttext .= '<ul>';
15647: my $position = $pos + 1;
15648: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15649: foreach my $key ('version','sigmethod','url','lifetime') {
15650: if ($confhash{$provider}{$key} ne '') {
15651: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15652: }
15653: }
15654: if ($encconfhash{$provider}{'key'} ne '') {
15655: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15656: }
15657: if ($encconfhash{$provider}{'secret'} ne '') {
15658: $resulttext .= '<li>'.$lt{'secret'}.': ';
15659: my $num = length($encconfhash{$provider}{'secret'});
15660: $resulttext .= ('*'x$num).'</li>';
15661: }
15662: my (@fields,$showroles);
15663: if (ref($requserfields{$provider}) eq 'ARRAY') {
15664: push(@fields,@{$requserfields{$provider}});
15665: }
15666: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15667: push(@fields,@{$confhash{$provider}{'fields'}});
15668: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15669: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15670: }
15671: if (@fields) {
15672: if (grep(/^roles$/,@fields)) {
15673: $showroles = 1;
15674: }
15675: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15676: join('", "', map { $lt{$_}; } @fields).'"</li>';
15677: }
15678: if (ref($requserfields{$provider}) eq 'ARRAY') {
15679: if (grep(/^user$/,@{$requserfields{$provider}})) {
15680: if ($confhash{$provider}{'incdom'}) {
15681: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15682: } else {
15683: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15684: }
15685: }
15686: }
15687: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15688: if (@{$confhash{$provider}{'defaults'}} > 0) {
15689: $resulttext .= '<li>'.$lt{'defa'};
15690: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15691: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15692: }
15693: $resulttext =~ s/,$//;
15694: $resulttext .= '</li>';
15695: }
15696: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15697: if (keys(%{$confhash{$provider}{'defaults'}})) {
15698: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15699: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15700: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15701: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15702: }
15703: }
15704: $resulttext .= '</ul></li>';
15705: }
15706: }
15707: if (ref($crsconf{$provider}) eq 'ARRAY') {
15708: if (@{$crsconf{$provider}} > 0) {
15709: $resulttext .= '<li>'.&mt('Configurable in course:');
15710: my $numconfig = 0;
15711: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15712: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15713: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15714: $numconfig ++;
15715: if ($provider eq 'examity') {
15716: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15717: } else {
15718: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15719: }
15720: }
15721: $resulttext =~ s/,$//;
15722: }
15723: }
15724: if (!$numconfig) {
15725: $resulttext .= ' '.&mt('None');
15726: }
15727: $resulttext .= '</li>';
15728: }
15729: }
15730: if ($showroles) {
15731: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15732: my $rolemaps;
15733: foreach my $role (@courseroles) {
15734: if ($confhash{$provider}{'roles'}{$role}) {
15735: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15736: $confhash{$provider}{'roles'}{$role}.',';
15737: }
15738: }
15739: if ($rolemaps) {
15740: $rolemaps =~ s/,$//;
15741: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15742: }
15743: }
15744: }
15745: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15746: my $customlist;
15747: if (keys(%{$confhash{$provider}{'custom'}})) {
15748: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15749: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15750: }
15751: $customlist =~ s/,$//;
15752: }
15753: if ($customlist) {
15754: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15755: }
15756: }
15757: $resulttext .= '</ul></li>';
15758: }
15759: }
15760: $resulttext .= '</ul>';
15761: } else {
15762: $resulttext = &mt('No changes made.');
15763: }
15764: } else {
15765: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15766: }
15767: if ($errors) {
15768: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15769: $errors.'</ul>';
15770: }
15771: return $resulttext;
15772: }
15773:
15774: sub process_proctoring_image {
15775: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15776: my $filename = $env{'form.'.$caller.'.filename'};
15777: my ($error,$url);
15778: my ($width,$height) = (21,21);
15779: if ($configuserok eq 'ok') {
15780: if ($switchserver) {
15781: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15782: $switchserver);
15783: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15784: my $modified = [];
1.372 raeburn 15785: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15786: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15787: "proctoring/$provider/icon",$width,$height,
15788: '',$modified);
1.372 raeburn 15789: if ($result eq 'ok') {
15790: if ($madethumb) {
15791: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15792: my $imagethumb = "$path/tn-".$imagefile;
15793: $url = $imagethumb;
15794: } else {
15795: $url = $imageurl;
15796: }
1.421 raeburn 15797: &update_modify_urls($r,$modified);
1.372 raeburn 15798: } else {
15799: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15800: }
15801: } else {
15802: $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);
15803: }
15804: } else {
15805: $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);
15806: }
15807: return ($url,$error);
15808: }
15809:
1.320 raeburn 15810: sub modify_lti {
15811: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15812: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15813: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15814: my (%posslti,%posslticrs,%posscrstype);
15815: my @courseroles = ('cc','in','ta','ep','st');
15816: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15817: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15818: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15819: my %coursetypetitles = &Apache::lonlocal::texthash (
15820: official => 'Official',
15821: unofficial => 'Unofficial',
15822: community => 'Community',
15823: textbook => 'Textbook',
15824: placement => 'Placement Test',
1.392 raeburn 15825: lti => 'LTI Provider',
1.320 raeburn 15826: );
1.325 raeburn 15827: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15828: my %lt = <i_names();
15829: map { $posslti{$_} = 1; } @ltiroles;
15830: map { $posslticrs{$_} = 1; } @lticourseroles;
15831: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15832:
1.326 raeburn 15833: my %menutitles = <imenu_titles();
1.421 raeburn 15834: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15835:
1.421 raeburn 15836: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15837:
1.406 raeburn 15838: my (%linkprotchg,$linkprotoutput,$is_home);
15839: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15840: \%linkprotchg,'domain');
15841: my $home = &Apache::lonnet::domain($dom,'primary');
15842: unless (($home eq 'no_host') || ($home eq '')) {
15843: my @ids=&Apache::lonnet::current_machine_ids();
15844: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15845: }
15846:
15847: if (keys(%linkprotchg)) {
15848: $secchanges{'linkprot'} = 1;
15849: my %oldlinkprot;
15850: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15851: %oldlinkprot = %{$currltisec{'linkprot'}};
15852: }
15853: foreach my $id (keys(%linkprotchg)) {
15854: if (ref($linkprotchg{$id}) eq 'HASH') {
15855: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15856: if (($inner eq 'secret') || ($inner eq 'key')) {
15857: if ($is_home) {
15858: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15859: }
15860: }
15861: }
15862: } else {
15863: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15864: }
15865: }
15866: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15867: if (keys(%linkprotchg)) {
15868: %{$newltisec{'linkprot'}} = %linkprotchg;
15869: }
15870: }
15871: if (ref($currltisec{'linkprot'}) eq 'HASH') {
1.434 raeburn 15872: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
1.406 raeburn 15873: next if ($id !~ /^\d+$/);
15874: unless (exists($linkprotchg{$id})) {
15875: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15876: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15877: if (($inner eq 'secret') || ($inner eq 'key')) {
15878: if ($is_home) {
15879: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15880: }
15881: } else {
15882: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15883: }
15884: }
15885: } else {
15886: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15887: }
15888: }
15889: }
15890: }
15891: if ($proterror) {
15892: $errors .= '<li>'.$proterror.'</li>';
15893: }
1.434 raeburn 15894:
15895: my (%delsuggested,%suggids,@suggested);;
15896: if (ref($currltisec{'suggested'}) eq 'HASH') {
15897: my $maxnum = $env{'form.linkprot_suggested_maxnum'};
15898: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
15899: for (my $i=0; $i<$maxnum; $i++) {
15900: my $itemid = $env{'form.linkprot_suggested_id_'.$i};
15901: $itemid =~ s/\D+//g;
15902: if ($itemid) {
15903: if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
15904: push(@suggested,$i);
15905: $suggids{$i} = $itemid;
15906: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
15907: if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
15908: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15909: }
15910: } else {
15911: if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
15912: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15913: } else {
15914: $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
15915: $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
15916: $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
15917: $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
15918: if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
15919: ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
15920: $secchanges{'suggested'}{$itemid} = 1;
15921: }
15922: }
15923: }
15924: }
15925: }
15926: }
15927: }
15928: foreach my $key (keys(%delsuggested)) {
15929: $newltisec{'suggested'}{$key} = $delsuggested{$key};
15930: $secchanges{'suggested'}{$key} = 1;
15931: }
15932: if (($env{'form.linkprot_suggested_add'}) &&
15933: ($env{'form.linkprot_suggested_name_add'} ne '')) {
15934: $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
15935: $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
15936: my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
15937: if ($newsuggid) {
15938: $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
15939: $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
15940: $secchanges{'suggested'}{$newsuggid} = 1;
15941: } else {
15942: my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
15943: if ($errormsg) {
15944: $error .= ' ('.$errormsg.')';
15945: }
15946: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15947: }
15948: }
1.320 raeburn 15949: my (@items,%deletions,%itemids);
15950: if ($env{'form.lti_add'}) {
15951: my $consumer = $env{'form.lti_consumer_add'};
15952: $consumer =~ s/(`)/'/g;
1.434 raeburn 15953: ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
1.320 raeburn 15954: if ($newid) {
15955: $itemids{'add'} = $newid;
15956: push(@items,'add');
15957: $changes{$newid} = 1;
15958: } else {
15959: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
1.434 raeburn 15960: if ($errormsg) {
15961: $error .= ' ('.$errormsg.')';
15962: }
1.320 raeburn 15963: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15964: }
15965: }
15966: if (ref($domconfig{$action}) eq 'HASH') {
15967: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15968: if (@todelete) {
15969: map { $deletions{$_} = 1; } @todelete;
15970: }
15971: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15972: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15973: my $itemid = $env{'form.lti_id_'.$i};
15974: $itemid =~ s/\D+//g;
15975: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15976: if ($deletions{$itemid}) {
15977: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15978: } else {
1.390 raeburn 15979: push(@items,$i);
15980: $itemids{$i} = $itemid;
1.320 raeburn 15981: }
15982: }
15983: }
15984: }
1.424 raeburn 15985: my (%keystore,$secstored);
15986: if ($is_home) {
15987: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
15988: }
15989:
15990: my ($cipher,$privnum);
15991: if ((@items > 0) && ($is_home)) {
15992: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
15993: $newltisec{'encrypt'},$keystore{$home});
15994: }
1.320 raeburn 15995: foreach my $idx (@items) {
15996: my $itemid = $itemids{$idx};
15997: next unless ($itemid);
1.424 raeburn 15998: my %currlti;
15999: unless ($idx eq 'add') {
16000: if (ref($domconfig{$action}) eq 'HASH') {
16001: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16002: %currlti = %{$domconfig{$action}{$itemid}};
16003: }
16004: }
16005: }
1.390 raeburn 16006: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 16007: $position =~ s/\D+//g;
16008: if ($position ne '') {
16009: $allpos[$position] = $itemid;
16010: }
1.424 raeburn 16011: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 16012: my $formitem = 'form.lti_'.$item.'_'.$idx;
16013: $env{$formitem} =~ s/(`)/'/g;
16014: if ($item eq 'lifetime') {
16015: $env{$formitem} =~ s/[^\d.]//g;
16016: }
16017: if ($env{$formitem} ne '') {
1.424 raeburn 16018: $confhash{$itemid}{$item} = $env{$formitem};
16019: unless (($idx eq 'add') || ($changes{$itemid})) {
16020: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
16021: $changes{$itemid} = 1;
1.320 raeburn 16022: }
16023: }
16024: }
16025: }
16026: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
16027: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
16028: }
1.345 raeburn 16029: if ($confhash{$itemid}{'requser'}) {
16030: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 16031: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 16032: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
16033: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
16034: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
16035: my $mapuser = $env{'form.lti_customuser_'.$idx};
16036: $mapuser =~ s/(`)/'/g;
1.405 raeburn 16037: $mapuser =~ s/^\s+|\s+$//g;
16038: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 16039: }
16040: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
16041: my @makeuser;
16042: foreach my $ltirole (sort(@possmakeuser)) {
16043: if ($posslti{$ltirole}) {
16044: push(@makeuser,$ltirole);
16045: }
16046: }
16047: $confhash{$itemid}{'makeuser'} = \@makeuser;
16048: if (@makeuser) {
16049: my $lcauth = $env{'form.lti_lcauth_'.$idx};
16050: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
16051: $confhash{$itemid}{'lcauth'} = $lcauth;
16052: if ($lcauth ne 'internal') {
16053: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
16054: $lcauthparm =~ s/^(\s+|\s+)$//g;
16055: $lcauthparm =~ s/`//g;
16056: if ($lcauthparm ne '') {
16057: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
16058: }
16059: }
16060: } else {
16061: $confhash{$itemid}{'lcauth'} = 'lti';
16062: }
1.320 raeburn 16063: }
1.345 raeburn 16064: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
16065: if (@possinstdata) {
16066: foreach my $field (@possinstdata) {
16067: if (exists($fieldtitles{$field})) {
16068: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 16069: }
16070: }
16071: }
1.363 raeburn 16072: if ($env{'form.lti_callback_'.$idx}) {
16073: if ($env{'form.lti_callbackparam_'.$idx}) {
16074: my $callback = $env{'form.lti_callbackparam_'.$idx};
16075: $callback =~ s/^\s+|\s+$//g;
16076: $confhash{$itemid}{'callback'} = $callback;
16077: }
16078: }
1.391 raeburn 16079: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 16080: if ($env{'form.lti_'.$field.'_'.$idx}) {
16081: $confhash{$itemid}{$field} = 1;
16082: }
1.320 raeburn 16083: }
1.345 raeburn 16084: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
16085: $confhash{$itemid}{lcmenu} = [];
16086: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
16087: foreach my $field (@possmenu) {
16088: if (exists($menutitles{$field})) {
16089: if ($field eq 'grades') {
16090: next unless ($env{'form.lti_inlinemenu_'.$idx});
16091: }
16092: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 16093: }
16094: }
16095: }
1.391 raeburn 16096: if ($confhash{$itemid}{'crsinc'}) {
16097: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
16098: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
16099: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
16100: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
16101: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
16102: $mapcrs =~ s/(`)/'/g;
16103: $mapcrs =~ s/^\s+|\s+$//g;
16104: $confhash{$itemid}{'mapcrs'} = $mapcrs;
16105: }
16106: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
16107: my @crstypes;
16108: foreach my $type (sort(@posstypes)) {
16109: if ($posscrstype{$type}) {
16110: push(@crstypes,$type);
16111: }
16112: }
16113: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 16114: if ($env{'form.lti_storecrs_'.$idx}) {
16115: $confhash{$itemid}{'storecrs'} = 1;
16116: }
1.391 raeburn 16117: if ($env{'form.lti_makecrs_'.$idx}) {
16118: $confhash{$itemid}{'makecrs'} = 1;
16119: }
16120: foreach my $ltirole (@lticourseroles) {
16121: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
16122: if (grep(/^\Q$possrole\E$/,@courseroles)) {
16123: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
16124: }
16125: }
16126: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
16127: my @selfenroll;
16128: foreach my $type (sort(@possenroll)) {
16129: if ($posslticrs{$type}) {
16130: push(@selfenroll,$type);
16131: }
16132: }
16133: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
16134: if ($env{'form.lti_crssec_'.$idx}) {
16135: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
16136: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
16137: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
16138: my $section = $env{'form.lti_customsection_'.$idx};
16139: $section =~ s/(`)/'/g;
16140: $section =~ s/^\s+|\s+$//g;
16141: if ($section ne '') {
16142: $confhash{$itemid}{'section'} = $section;
16143: }
16144: }
16145: }
16146: foreach my $field ('passback','roster') {
16147: if ($env{'form.lti_'.$field.'_'.$idx}) {
16148: $confhash{$itemid}{$field} = 1;
16149: }
16150: }
16151: if ($env{'form.lti_passback_'.$idx}) {
16152: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
16153: $confhash{$itemid}{'passbackformat'} = '1.0';
16154: } else {
16155: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 16156: }
16157: }
1.391 raeburn 16158: }
16159: unless (($idx eq 'add') || ($changes{$itemid})) {
16160: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 16161: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 16162: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 16163: $changes{$itemid} = 1;
16164: }
1.345 raeburn 16165: }
16166: unless ($changes{$itemid}) {
1.424 raeburn 16167: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
16168: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 16169: $changes{$itemid} = 1;
16170: }
16171: }
1.345 raeburn 16172: }
1.391 raeburn 16173: foreach my $field ('mapcrstype','selfenroll') {
16174: unless ($changes{$itemid}) {
1.424 raeburn 16175: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16176: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16177: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16178: $confhash{$itemid}{$field});
16179: if (@diffs) {
16180: $changes{$itemid} = 1;
16181: }
1.424 raeburn 16182: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16183: $changes{$itemid} = 1;
16184: }
16185: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16186: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 16187: $changes{$itemid} = 1;
16188: }
16189: }
1.391 raeburn 16190: }
16191: }
16192: unless ($changes{$itemid}) {
1.424 raeburn 16193: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 16194: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 16195: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
16196: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 16197: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 16198: $changes{$itemid} = 1;
16199: last;
16200: }
16201: }
1.391 raeburn 16202: unless ($changes{$itemid}) {
16203: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
16204: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 16205: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 16206: $changes{$itemid} = 1;
16207: last;
16208: }
16209: }
16210: }
1.424 raeburn 16211: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 16212: $changes{$itemid} = 1;
1.345 raeburn 16213: }
1.391 raeburn 16214: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16215: unless ($changes{$itemid}) {
16216: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16217: $changes{$itemid} = 1;
16218: }
16219: }
16220: }
16221: }
16222: }
16223: unless ($changes{$itemid}) {
16224: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 16225: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16226: $changes{$itemid} = 1;
1.320 raeburn 16227: }
1.391 raeburn 16228: }
16229: unless ($changes{$itemid}) {
16230: foreach my $field ('makeuser','lcmenu') {
1.424 raeburn 16231: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16232: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16233: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16234: $confhash{$itemid}{$field});
16235: if (@diffs) {
16236: $changes{$itemid} = 1;
16237: }
1.424 raeburn 16238: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16239: $changes{$itemid} = 1;
16240: }
16241: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16242: if (@{$confhash{$itemid}{$field}} > 0) {
16243: $changes{$itemid} = 1;
16244: }
1.345 raeburn 16245: }
1.320 raeburn 16246: }
16247: }
16248: }
16249: }
16250: }
1.424 raeburn 16251: if ($is_home) {
16252: my $keyitem = 'form.lti_key_'.$idx;
16253: $env{$keyitem} =~ s/(`)/'/g;
16254: if ($env{$keyitem} ne '') {
16255: $ltienc{$itemid}{'key'} = $env{$keyitem};
16256: unless ($changes{$itemid}) {
16257: if ($currlti{'key'} ne $env{$keyitem}) {
16258: $changes{$itemid} = 1;
16259: }
16260: }
16261: }
16262: my $secretitem = 'form.lti_secret_'.$idx;
16263: $env{$secretitem} =~ s/(`)/'/g;
16264: if ($currlti{'usable'}) {
16265: if ($env{'form.lti_changesecret_'.$idx}) {
16266: if ($env{$secretitem} ne '') {
16267: if ($privnum && $cipher) {
16268: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16269: $confhash{$itemid}{'cipher'} = $privnum;
16270: } else {
16271: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16272: }
16273: $changes{$itemid} = 1;
16274: }
16275: } else {
16276: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16277: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16278: }
16279: if (ref($ltienc{$itemid}) eq 'HASH') {
16280: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16281: $confhash{$itemid}{'usable'} = 1;
16282: }
16283: }
16284: } elsif ($env{$secretitem} ne '') {
16285: if ($privnum && $cipher) {
16286: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16287: $confhash{$itemid}{'cipher'} = $privnum;
16288: } else {
16289: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16290: }
16291: if (ref($ltienc{$itemid}) eq 'HASH') {
16292: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16293: $confhash{$itemid}{'usable'} = 1;
16294: }
16295: }
16296: $changes{$itemid} = 1;
16297: }
16298: }
16299: unless ($changes{$itemid}) {
16300: foreach my $key (keys(%currlti)) {
16301: if (ref($currlti{$key}) eq 'HASH') {
16302: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16303: foreach my $innerkey (keys(%{$currlti{$key}})) {
16304: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16305: $changes{$itemid} = 1;
16306: last;
16307: }
16308: }
16309: } elsif (keys(%{$currlti{$key}}) > 0) {
16310: $changes{$itemid} = 1;
16311: }
16312: }
16313: last if ($changes{$itemid});
16314: }
16315: }
1.320 raeburn 16316: }
16317: if (@allpos > 0) {
16318: my $idx = 0;
16319: foreach my $itemid (@allpos) {
16320: if ($itemid ne '') {
16321: $confhash{$itemid}{'order'} = $idx;
16322: if (ref($domconfig{$action}) eq 'HASH') {
16323: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16324: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16325: $changes{$itemid} = 1;
16326: }
16327: }
16328: }
16329: $idx ++;
16330: }
16331: }
16332: }
1.424 raeburn 16333:
16334: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16335: return &mt('No changes made.');
16336: }
16337:
1.320 raeburn 16338: my %ltihash = (
1.405 raeburn 16339: $action => { %confhash }
16340: );
1.424 raeburn 16341: my %ltienchash;
16342:
16343: if ($is_home) {
16344: %ltienchash = (
16345: $action => { %ltienc }
16346: );
16347: }
1.405 raeburn 16348: if (keys(%secchanges)) {
16349: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16350: if ($secchanges{'linkprot'}) {
16351: if ($is_home) {
16352: $ltienchash{'linkprot'} = \%newltienc;
16353: }
16354: }
1.405 raeburn 16355: }
16356: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16357: if ($putresult eq 'ok') {
1.424 raeburn 16358: if (keys(%ltienchash)) {
16359: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16360: }
16361: $resulttext = &mt('Changes made:').'<ul>';
16362: if (keys(%secchanges) > 0) {
1.423 raeburn 16363: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16364: if (exists($secchanges{'linkprot'})) {
16365: $resulttext .= $linkprotoutput;
1.405 raeburn 16366: }
16367: }
1.320 raeburn 16368: if (keys(%changes) > 0) {
16369: my $cachetime = 24*60*60;
1.424 raeburn 16370: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16371: if (ref($lastactref) eq 'HASH') {
16372: $lastactref->{'lti'} = 1;
16373: }
16374: my %bynum;
16375: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16376: if (ref($confhash{$itemid}) eq 'HASH') {
16377: my $position = $confhash{$itemid}{'order'};
16378: $bynum{$position} = $itemid;
16379: }
1.320 raeburn 16380: }
16381: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16382: my $itemid = $bynum{$pos};
1.424 raeburn 16383: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16384: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16385: my $position = $pos + 1;
16386: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16387: foreach my $item ('version','lifetime') {
16388: if ($confhash{$itemid}{$item} ne '') {
16389: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16390: }
16391: }
1.424 raeburn 16392: if ($ltienc{$itemid}{'key'} ne '') {
16393: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16394: }
1.424 raeburn 16395: if ($ltienc{$itemid}{'secret'} ne '') {
16396: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16397: }
1.345 raeburn 16398: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16399: if ($confhash{$itemid}{'callback'}) {
16400: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16401: } else {
1.392 raeburn 16402: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16403: }
1.345 raeburn 16404: if ($confhash{$itemid}{'mapuser'}) {
16405: my $shownmapuser;
16406: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16407: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16408: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16409: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16410: } else {
16411: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16412: }
1.345 raeburn 16413: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16414: }
1.345 raeburn 16415: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16416: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16417: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16418: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16419: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16420: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16421: } else {
16422: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16423: $confhash{$itemid}{'lcauth'});
16424: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16425: $resulttext .= '; '.&mt('a randomly generated password will be created');
16426: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16427: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16428: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16429: }
16430: } else {
16431: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16432: }
16433: }
16434: $resulttext .= '</li>';
16435: } else {
16436: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16437: }
1.320 raeburn 16438: }
1.345 raeburn 16439: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16440: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16441: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16442: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16443: } else {
1.345 raeburn 16444: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 16445: }
1.320 raeburn 16446: }
1.391 raeburn 16447: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16448: $resulttext .= '<li>'.$lt{$item}.': ';
16449: if ($confhash{$itemid}{$item}) {
16450: $resulttext .= &mt('Yes');
16451: } else {
16452: $resulttext .= &mt('No');
1.337 raeburn 16453: }
1.345 raeburn 16454: $resulttext .= '</li>';
1.320 raeburn 16455: }
1.345 raeburn 16456: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16457: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16458: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16459: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16460: } else {
16461: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16462: }
16463: }
16464: if ($confhash{$itemid}{'crsinc'}) {
16465: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16466: my $rolemaps;
16467: foreach my $role (@ltiroles) {
16468: if ($confhash{$itemid}{'maproles'}{$role}) {
16469: $rolemaps .= (' 'x2).$role.'='.
16470: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16471: 'Course').',';
16472: }
16473: }
16474: if ($rolemaps) {
16475: $rolemaps =~ s/,$//;
16476: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16477: }
16478: }
16479: if ($confhash{$itemid}{'mapcrs'}) {
16480: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16481: }
16482: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16483: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16484: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16485: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16486: '</li>';
16487: } else {
16488: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16489: }
16490: }
1.392 raeburn 16491: if ($confhash{$itemid}{'storecrs'}) {
16492: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16493: }
1.391 raeburn 16494: if ($confhash{$itemid}{'makecrs'}) {
16495: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16496: } else {
16497: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16498: }
16499: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16500: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16501: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16502: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16503: '</li>';
16504: } else {
16505: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16506: }
16507: }
16508: if ($confhash{$itemid}{'section'}) {
16509: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16510: $resulttext .= '<li>'.&mt('User section from standard field:').
16511: ' (course_section_sourcedid)'.'</li>';
16512: } else {
16513: $resulttext .= '<li>'.&mt('User section from:').' '.
16514: $confhash{$itemid}{'section'}.'</li>';
16515: }
1.345 raeburn 16516: } else {
1.391 raeburn 16517: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16518: }
16519: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16520: $resulttext .= '<li>'.$lt{$item}.': ';
16521: if ($confhash{$itemid}{$item}) {
16522: $resulttext .= &mt('Yes');
16523: if ($item eq 'passback') {
16524: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16525: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16526: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16527: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16528: }
16529: }
16530: } else {
16531: $resulttext .= &mt('No');
16532: }
16533: $resulttext .= '</li>';
16534: }
16535: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16536: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16537: $resulttext .= '<li>'.&mt('Menu items:').' '.
16538: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16539: } else {
16540: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16541: }
1.345 raeburn 16542: }
1.326 raeburn 16543: }
16544: }
1.320 raeburn 16545: $resulttext .= '</ul></li>';
16546: }
16547: }
1.424 raeburn 16548: if (keys(%deletions)) {
16549: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16550: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16551: }
16552: }
1.320 raeburn 16553: }
1.405 raeburn 16554: $resulttext .= '</ul>';
1.424 raeburn 16555: if (ref($lastactref) eq 'HASH') {
1.434 raeburn 16556: if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
16557: &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 16558: $lastactref->{'domdefaults'} = 1;
16559: }
16560: }
1.320 raeburn 16561: } else {
16562: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16563: }
16564: if ($errors) {
16565: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16566: $errors.'</ul>';
16567: }
16568: return $resulttext;
16569: }
16570:
1.424 raeburn 16571: sub get_priv_creds {
16572: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16573: my ($needenc,$cipher,$privnum);
16574: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16575: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16576: $needenc = $encrypt->{'consumers'}
16577: } else {
16578: $needenc = $domdefs{'ltienc_consumers'};
16579: }
16580: if ($needenc) {
16581: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16582: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16583: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16584: my $privkey = $privhash{'key'};
16585: $privnum = $privhash{'version'};
16586: if (($privnum) && ($privkey ne '')) {
16587: $cipher = Crypt::CBC->new({'key' => $privkey,
16588: 'cipher' => 'DES'});
16589: }
16590: }
16591: }
16592: return ($cipher,$privnum);
16593: }
16594:
1.320 raeburn 16595: sub get_lti_id {
1.434 raeburn 16596: my ($domain,$consumer,$dbname) = @_;
16597: unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
16598: return ('','invalid db');
16599: }
16600: # get lock on db
1.320 raeburn 16601: my $lockhash = {
16602: lock => $env{'user.name'}.
16603: ':'.$env{'user.domain'},
16604: };
16605: my $tries = 0;
1.434 raeburn 16606: my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16607: my ($id,$error);
16608:
16609: while (($gotlock ne 'ok') && ($tries<10)) {
16610: $tries ++;
16611: sleep (0.1);
1.434 raeburn 16612: $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16613: }
16614: if ($gotlock eq 'ok') {
1.434 raeburn 16615: my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1.320 raeburn 16616: if ($currids{'lock'}) {
16617: delete($currids{'lock'});
16618: if (keys(%currids)) {
16619: my @curr = sort { $a <=> $b } keys(%currids);
16620: if ($curr[-1] =~ /^\d+$/) {
16621: $id = 1 + $curr[-1];
16622: }
16623: } else {
16624: $id = 1;
16625: }
16626: if ($id) {
1.434 raeburn 16627: unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1.320 raeburn 16628: $error = 'nostore';
16629: }
16630: } else {
16631: $error = 'nonumber';
16632: }
16633: }
1.434 raeburn 16634: my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1.320 raeburn 16635: } else {
16636: $error = 'nolock';
16637: }
16638: return ($id,$error);
16639: }
16640:
1.3 raeburn 16641: sub modify_autoenroll {
1.205 raeburn 16642: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16643: my ($resulttext,%changes);
16644: my %currautoenroll;
16645: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16646: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16647: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16648: }
16649: }
16650: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16651: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16652: sender => 'Sender for notification messages',
1.274 raeburn 16653: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16654: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16655: my @offon = ('off','on');
1.17 raeburn 16656: my $sender_uname = $env{'form.sender_uname'};
16657: my $sender_domain = $env{'form.sender_domain'};
16658: if ($sender_domain eq '') {
16659: $sender_uname = '';
16660: } elsif ($sender_uname eq '') {
16661: $sender_domain = '';
16662: }
1.129 raeburn 16663: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16664: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16665: $autofailsafe =~ s{^\s+|\s+$}{}g;
16666: if ($autofailsafe =~ /\D/) {
16667: undef($autofailsafe);
16668: }
1.274 raeburn 16669: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16670: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16671: $failsafe = 'off';
1.400 raeburn 16672: undef($autofailsafe);
1.274 raeburn 16673: }
1.1 raeburn 16674: my %autoenrollhash = (
1.129 raeburn 16675: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16676: 'sender_uname' => $sender_uname,
16677: 'sender_domain' => $sender_domain,
16678: 'co-owners' => $coowners,
1.399 raeburn 16679: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16680: 'failsafe' => $failsafe,
1.1 raeburn 16681: }
16682: );
1.4 raeburn 16683: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16684: $dom);
1.1 raeburn 16685: if ($putresult eq 'ok') {
16686: if (exists($currautoenroll{'run'})) {
16687: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16688: $changes{'run'} = 1;
16689: }
16690: } elsif ($autorun) {
16691: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16692: $changes{'run'} = 1;
1.1 raeburn 16693: }
16694: }
1.17 raeburn 16695: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16696: $changes{'sender'} = 1;
16697: }
1.17 raeburn 16698: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16699: $changes{'sender'} = 1;
16700: }
1.129 raeburn 16701: if ($currautoenroll{'co-owners'} ne '') {
16702: if ($currautoenroll{'co-owners'} ne $coowners) {
16703: $changes{'coowners'} = 1;
16704: }
16705: } elsif ($coowners) {
16706: $changes{'coowners'} = 1;
1.274 raeburn 16707: }
1.399 raeburn 16708: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16709: $changes{'autofailsafe'} = 1;
16710: }
1.399 raeburn 16711: if ($currautoenroll{'failsafe'} ne $failsafe) {
16712: $changes{'failsafe'} = 1;
16713: }
1.1 raeburn 16714: if (keys(%changes) > 0) {
16715: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16716: if ($changes{'run'}) {
1.1 raeburn 16717: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16718: }
16719: if ($changes{'sender'}) {
1.17 raeburn 16720: if ($sender_uname eq '' || $sender_domain eq '') {
16721: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16722: } else {
16723: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16724: }
1.1 raeburn 16725: }
1.129 raeburn 16726: if ($changes{'coowners'}) {
16727: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16728: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16729: if (ref($lastactref) eq 'HASH') {
16730: $lastactref->{'domainconfig'} = 1;
16731: }
1.129 raeburn 16732: }
1.274 raeburn 16733: if ($changes{'autofailsafe'}) {
1.399 raeburn 16734: if ($autofailsafe ne '') {
16735: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16736: } else {
1.399 raeburn 16737: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16738: }
1.399 raeburn 16739: }
16740: if ($changes{'failsafe'}) {
16741: if ($failsafe eq 'off') {
16742: unless ($changes{'autofailsafe'}) {
16743: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16744: }
16745: } elsif ($failsafe eq 'zero') {
16746: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16747: } else {
16748: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16749: }
16750: }
16751: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16752: &Apache::lonnet::get_domain_defaults($dom,1);
16753: if (ref($lastactref) eq 'HASH') {
16754: $lastactref->{'domdefaults'} = 1;
16755: }
16756: }
1.1 raeburn 16757: $resulttext .= '</ul>';
16758: } else {
16759: $resulttext = &mt('No changes made to auto-enrollment settings');
16760: }
16761: } else {
1.11 albertel 16762: $resulttext = '<span class="LC_error">'.
16763: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16764: }
1.3 raeburn 16765: return $resulttext;
1.1 raeburn 16766: }
16767:
16768: sub modify_autoupdate {
1.3 raeburn 16769: my ($dom,%domconfig) = @_;
1.1 raeburn 16770: my ($resulttext,%currautoupdate,%fields,%changes);
16771: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16772: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16773: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16774: }
16775: }
16776: my @offon = ('off','on');
16777: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16778: run => 'Auto-update:',
16779: classlists => 'Updates to user information in classlists?',
16780: unexpired => 'Skip updates for users without active or future roles?',
16781: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16782: );
1.44 raeburn 16783: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16784: my %fieldtitles = &Apache::lonlocal::texthash (
16785: id => 'Student/Employee ID',
1.20 raeburn 16786: permanentemail => 'E-mail address',
1.1 raeburn 16787: lastname => 'Last Name',
16788: firstname => 'First Name',
16789: middlename => 'Middle Name',
1.132 raeburn 16790: generation => 'Generation',
1.1 raeburn 16791: );
1.142 raeburn 16792: $othertitle = &mt('All users');
1.1 raeburn 16793: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16794: $othertitle = &mt('Other users');
1.1 raeburn 16795: }
16796: foreach my $key (keys(%env)) {
16797: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16798: my ($usertype,$item) = ($1,$2);
16799: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16800: if ($usertype eq 'default') {
16801: push(@{$fields{$1}},$2);
16802: } elsif (ref($types) eq 'ARRAY') {
16803: if (grep(/^\Q$usertype\E$/,@{$types})) {
16804: push(@{$fields{$1}},$2);
16805: }
16806: }
16807: }
1.1 raeburn 16808: }
16809: }
1.131 raeburn 16810: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16811: @lockablenames = sort(@lockablenames);
16812: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16813: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16814: if (@changed) {
16815: $changes{'lockablenames'} = 1;
16816: }
16817: } else {
16818: if (@lockablenames) {
16819: $changes{'lockablenames'} = 1;
16820: }
16821: }
1.1 raeburn 16822: my %updatehash = (
16823: autoupdate => { run => $env{'form.autoupdate_run'},
16824: classlists => $env{'form.classlists'},
1.385 raeburn 16825: unexpired => $env{'form.unexpired'},
1.1 raeburn 16826: fields => {%fields},
1.131 raeburn 16827: lockablenames => \@lockablenames,
1.1 raeburn 16828: }
16829: );
1.385 raeburn 16830: my $lastactivedays;
16831: if ($env{'form.lastactive'}) {
16832: $lastactivedays = $env{'form.lastactivedays'};
16833: $lastactivedays =~ s/^\s+|\s+$//g;
16834: unless ($lastactivedays =~ /^\d+$/) {
16835: undef($lastactivedays);
16836: $env{'form.lastactive'} = 0;
16837: }
16838: }
16839: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16840: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16841: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16842: if (exists($updatehash{autoupdate}{$key})) {
16843: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16844: $changes{$key} = 1;
16845: }
16846: }
16847: } elsif ($key eq 'fields') {
16848: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16849: foreach my $item (@{$types},'default') {
1.1 raeburn 16850: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16851: my $change = 0;
16852: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16853: if (!exists($fields{$item})) {
16854: $change = 1;
1.132 raeburn 16855: last;
1.1 raeburn 16856: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16857: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16858: $change = 1;
1.132 raeburn 16859: last;
1.1 raeburn 16860: }
16861: }
16862: }
16863: if ($change) {
16864: push(@{$changes{$key}},$item);
16865: }
1.26 raeburn 16866: }
1.1 raeburn 16867: }
16868: }
1.131 raeburn 16869: } elsif ($key eq 'lockablenames') {
16870: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16871: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16872: if (@changed) {
16873: $changes{'lockablenames'} = 1;
16874: }
16875: } else {
16876: if (@lockablenames) {
16877: $changes{'lockablenames'} = 1;
16878: }
16879: }
16880: }
16881: }
16882: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16883: if (@lockablenames) {
16884: $changes{'lockablenames'} = 1;
1.1 raeburn 16885: }
16886: }
1.385 raeburn 16887: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16888: if ($updatehash{'autoupdate'}{'unexpired'}) {
16889: $changes{'unexpired'} = 1;
16890: }
16891: }
16892: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16893: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16894: $changes{'lastactive'} = 1;
16895: }
16896: }
1.26 raeburn 16897: foreach my $item (@{$types},'default') {
16898: if (defined($fields{$item})) {
16899: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16900: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16901: my $change = 0;
16902: if (ref($fields{$item}) eq 'ARRAY') {
16903: foreach my $type (@{$fields{$item}}) {
16904: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16905: $change = 1;
16906: last;
16907: }
16908: }
16909: }
16910: if ($change) {
16911: push(@{$changes{'fields'}},$item);
16912: }
16913: } else {
1.26 raeburn 16914: push(@{$changes{'fields'}},$item);
16915: }
16916: } else {
16917: push(@{$changes{'fields'}},$item);
1.1 raeburn 16918: }
16919: }
16920: }
16921: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16922: $dom);
16923: if ($putresult eq 'ok') {
16924: if (keys(%changes) > 0) {
16925: $resulttext = &mt('Changes made:').'<ul>';
16926: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16927: if ($key eq 'lockablenames') {
16928: $resulttext .= '<li>';
16929: if (@lockablenames) {
16930: $usertypes->{'default'} = $othertitle;
16931: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16932: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16933: } else {
16934: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16935: }
16936: $resulttext .= '</li>';
16937: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16938: foreach my $item (@{$changes{$key}}) {
16939: my @newvalues;
16940: foreach my $type (@{$fields{$item}}) {
16941: push(@newvalues,$fieldtitles{$type});
16942: }
1.3 raeburn 16943: my $newvaluestr;
16944: if (@newvalues > 0) {
16945: $newvaluestr = join(', ',@newvalues);
16946: } else {
16947: $newvaluestr = &mt('none');
1.6 raeburn 16948: }
1.1 raeburn 16949: if ($item eq 'default') {
1.26 raeburn 16950: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16951: } else {
1.26 raeburn 16952: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16953: }
16954: }
16955: } else {
16956: my $newvalue;
16957: if ($key eq 'run') {
16958: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16959: } elsif ($key eq 'lastactive') {
16960: $newvalue = $offon[$env{'form.lastactive'}];
16961: unless ($lastactivedays eq '') {
16962: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16963: }
1.1 raeburn 16964: } else {
16965: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16966: }
1.1 raeburn 16967: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16968: }
16969: }
16970: $resulttext .= '</ul>';
16971: } else {
1.3 raeburn 16972: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16973: }
16974: } else {
1.11 albertel 16975: $resulttext = '<span class="LC_error">'.
16976: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16977: }
1.3 raeburn 16978: return $resulttext;
1.1 raeburn 16979: }
16980:
1.125 raeburn 16981: sub modify_autocreate {
16982: my ($dom,%domconfig) = @_;
16983: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
16984: if (ref($domconfig{'autocreate'}) eq 'HASH') {
16985: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
16986: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
16987: }
16988: }
16989: my %title= ( xml => 'Auto-creation of courses in XML course description files',
16990: req => 'Auto-creation of validated requests for official courses',
16991: xmldc => 'Identity of course creator of courses from XML files',
16992: );
16993: my @types = ('xml','req');
16994: foreach my $item (@types) {
16995: $newvals{$item} = $env{'form.autocreate_'.$item};
16996: $newvals{$item} =~ s/\D//g;
16997: $newvals{$item} = 0 if ($newvals{$item} eq '');
16998: }
16999: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 17000: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 17001: unless (exists($domcoords{$newvals{'xmldc'}})) {
17002: $newvals{'xmldc'} = '';
17003: }
17004: %autocreatehash = (
17005: autocreate => { xml => $newvals{'xml'},
17006: req => $newvals{'req'},
17007: }
17008: );
17009: if ($newvals{'xmldc'} ne '') {
17010: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
17011: }
17012: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
17013: $dom);
17014: if ($putresult eq 'ok') {
17015: my @items = @types;
17016: if ($newvals{'xml'}) {
17017: push(@items,'xmldc');
17018: }
17019: foreach my $item (@items) {
17020: if (exists($currautocreate{$item})) {
17021: if ($currautocreate{$item} ne $newvals{$item}) {
17022: $changes{$item} = 1;
17023: }
17024: } elsif ($newvals{$item}) {
17025: $changes{$item} = 1;
17026: }
17027: }
17028: if (keys(%changes) > 0) {
17029: my @offon = ('off','on');
17030: $resulttext = &mt('Changes made:').'<ul>';
17031: foreach my $item (@types) {
17032: if ($changes{$item}) {
17033: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 17034: $resulttext .= '<li>'.
17035: &mt("$title{$item} set to [_1]$newtxt [_2]",
17036: '<b>','</b>').
17037: '</li>';
1.125 raeburn 17038: }
17039: }
17040: if ($changes{'xmldc'}) {
17041: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
17042: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 17043: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 17044: }
17045: $resulttext .= '</ul>';
17046: } else {
17047: $resulttext = &mt('No changes made to auto-creation settings');
17048: }
17049: } else {
17050: $resulttext = '<span class="LC_error">'.
17051: &mt('An error occurred: [_1]',$putresult).'</span>';
17052: }
17053: return $resulttext;
17054: }
17055:
1.23 raeburn 17056: sub modify_directorysrch {
1.295 raeburn 17057: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 17058: my ($resulttext,%changes);
17059: my %currdirsrch;
17060: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
17061: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
17062: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
17063: }
17064: }
1.277 raeburn 17065: my %title = ( available => 'Institutional directory search available',
17066: localonly => 'Other domains can search institution',
17067: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 17068: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 17069: searchby => 'Search types',
17070: searchtypes => 'Search latitude');
17071: my @offon = ('off','on');
1.24 raeburn 17072: my @otherdoms = ('Yes','No');
1.23 raeburn 17073:
1.25 raeburn 17074: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 17075: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
17076: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
17077:
1.44 raeburn 17078: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 17079: if (keys(%{$usertypes}) == 0) {
17080: @cansearch = ('default');
17081: } else {
17082: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
17083: foreach my $type (@{$currdirsrch{'cansearch'}}) {
17084: if (!grep(/^\Q$type\E$/,@cansearch)) {
17085: push(@{$changes{'cansearch'}},$type);
17086: }
1.23 raeburn 17087: }
1.26 raeburn 17088: foreach my $type (@cansearch) {
17089: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
17090: push(@{$changes{'cansearch'}},$type);
17091: }
1.23 raeburn 17092: }
1.26 raeburn 17093: } else {
17094: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 17095: }
17096: }
17097:
17098: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
17099: foreach my $by (@{$currdirsrch{'searchby'}}) {
17100: if (!grep(/^\Q$by\E$/,@searchby)) {
17101: push(@{$changes{'searchby'}},$by);
17102: }
17103: }
17104: foreach my $by (@searchby) {
17105: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
17106: push(@{$changes{'searchby'}},$by);
17107: }
17108: }
17109: } else {
17110: push(@{$changes{'searchby'}},@searchby);
17111: }
1.25 raeburn 17112:
17113: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
17114: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
17115: if (!grep(/^\Q$type\E$/,@searchtypes)) {
17116: push(@{$changes{'searchtypes'}},$type);
17117: }
17118: }
17119: foreach my $type (@searchtypes) {
17120: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
17121: push(@{$changes{'searchtypes'}},$type);
17122: }
17123: }
17124: } else {
17125: if (exists($currdirsrch{'searchtypes'})) {
17126: foreach my $type (@searchtypes) {
17127: if ($type ne $currdirsrch{'searchtypes'}) {
17128: push(@{$changes{'searchtypes'}},$type);
17129: }
17130: }
17131: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
17132: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
17133: }
17134: } else {
17135: push(@{$changes{'searchtypes'}},@searchtypes);
17136: }
17137: }
17138:
1.23 raeburn 17139: my %dirsrch_hash = (
17140: directorysrch => { available => $env{'form.dirsrch_available'},
17141: cansearch => \@cansearch,
1.277 raeburn 17142: localonly => $env{'form.dirsrch_instlocalonly'},
17143: lclocalonly => $env{'form.dirsrch_domlocalonly'},
17144: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 17145: searchby => \@searchby,
1.25 raeburn 17146: searchtypes => \@searchtypes,
1.23 raeburn 17147: }
17148: );
17149: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
17150: $dom);
17151: if ($putresult eq 'ok') {
17152: if (exists($currdirsrch{'available'})) {
17153: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
17154: $changes{'available'} = 1;
17155: }
17156: } else {
17157: if ($env{'form.dirsrch_available'} eq '1') {
17158: $changes{'available'} = 1;
17159: }
17160: }
1.277 raeburn 17161: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 17162: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
17163: $changes{'lcavailable'} = 1;
17164: }
1.277 raeburn 17165: } else {
17166: if ($env{'form.dirsrch_lcavailable'} eq '1') {
17167: $changes{'lcavailable'} = 1;
17168: }
17169: }
1.24 raeburn 17170: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 17171: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
17172: $changes{'localonly'} = 1;
17173: }
1.24 raeburn 17174: } else {
1.277 raeburn 17175: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 17176: $changes{'localonly'} = 1;
17177: }
17178: }
1.277 raeburn 17179: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 17180: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
17181: $changes{'lclocalonly'} = 1;
17182: }
1.277 raeburn 17183: } else {
17184: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
17185: $changes{'lclocalonly'} = 1;
17186: }
17187: }
1.23 raeburn 17188: if (keys(%changes) > 0) {
17189: $resulttext = &mt('Changes made:').'<ul>';
17190: if ($changes{'available'}) {
17191: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
17192: }
1.277 raeburn 17193: if ($changes{'lcavailable'}) {
17194: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
17195: }
1.24 raeburn 17196: if ($changes{'localonly'}) {
1.277 raeburn 17197: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 17198: }
1.277 raeburn 17199: if ($changes{'lclocalonly'}) {
17200: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 17201: }
1.23 raeburn 17202: if (ref($changes{'cansearch'}) eq 'ARRAY') {
17203: my $chgtext;
1.26 raeburn 17204: if (ref($usertypes) eq 'HASH') {
17205: if (keys(%{$usertypes}) > 0) {
17206: foreach my $type (@{$types}) {
17207: if (grep(/^\Q$type\E$/,@cansearch)) {
17208: $chgtext .= $usertypes->{$type}.'; ';
17209: }
17210: }
17211: if (grep(/^default$/,@cansearch)) {
17212: $chgtext .= $othertitle;
17213: } else {
17214: $chgtext =~ s/\; $//;
17215: }
1.210 raeburn 17216: $resulttext .=
1.178 raeburn 17217: '<li>'.
17218: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17219: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17220: '</li>';
1.23 raeburn 17221: }
17222: }
17223: }
17224: if (ref($changes{'searchby'}) eq 'ARRAY') {
17225: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17226: my $chgtext;
17227: foreach my $type (@{$titleorder}) {
17228: if (grep(/^\Q$type\E$/,@searchby)) {
17229: if (defined($searchtitles->{$type})) {
17230: $chgtext .= $searchtitles->{$type}.'; ';
17231: }
17232: }
17233: }
17234: $chgtext =~ s/\; $//;
17235: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17236: }
1.25 raeburn 17237: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17238: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17239: my $chgtext;
17240: foreach my $type (@{$srchtypeorder}) {
17241: if (grep(/^\Q$type\E$/,@searchtypes)) {
17242: if (defined($srchtypes_desc->{$type})) {
17243: $chgtext .= $srchtypes_desc->{$type}.'; ';
17244: }
17245: }
17246: }
17247: $chgtext =~ s/\; $//;
1.178 raeburn 17248: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17249: }
17250: $resulttext .= '</ul>';
1.295 raeburn 17251: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17252: if (ref($lastactref) eq 'HASH') {
17253: $lastactref->{'directorysrch'} = 1;
17254: }
1.23 raeburn 17255: } else {
1.277 raeburn 17256: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17257: }
17258: } else {
17259: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17260: &mt('An error occurred: [_1]',$putresult).'</span>';
17261: }
17262: return $resulttext;
17263: }
17264:
1.28 raeburn 17265: sub modify_contacts {
1.205 raeburn 17266: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17267: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17268: if (ref($domconfig{'contacts'}) eq 'HASH') {
17269: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17270: $currsetting{$key} = $domconfig{'contacts'}{$key};
17271: }
17272: }
1.286 raeburn 17273: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17274: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17275: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17276: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17277: my @toggles = ('reporterrors','reportupdates','reportstatus');
17278: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17279: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17280: foreach my $type (@mailings) {
17281: @{$newsetting{$type}} =
17282: &Apache::loncommon::get_env_multiple('form.'.$type);
17283: foreach my $item (@contacts) {
17284: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17285: $contacts_hash{contacts}{$type}{$item} = 1;
17286: } else {
17287: $contacts_hash{contacts}{$type}{$item} = 0;
17288: }
1.289 raeburn 17289: }
1.28 raeburn 17290: $others{$type} = $env{'form.'.$type.'_others'};
17291: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17292: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17293: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17294: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17295: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17296: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17297: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17298: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17299: }
1.134 raeburn 17300: }
1.28 raeburn 17301: }
17302: foreach my $item (@contacts) {
17303: $to{$item} = $env{'form.'.$item};
17304: $contacts_hash{'contacts'}{$item} = $to{$item};
17305: }
1.203 raeburn 17306: foreach my $item (@toggles) {
17307: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17308: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17309: }
17310: }
1.340 raeburn 17311: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17312: foreach my $item (@lonstatus) {
17313: if ($item eq 'excluded') {
17314: my (%serverhomes,@excluded);
17315: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17316: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17317: if (@possexcluded) {
17318: foreach my $id (sort(@possexcluded)) {
17319: if ($serverhomes{$id}) {
17320: push(@excluded,$id);
17321: }
17322: }
17323: }
17324: if (@excluded) {
17325: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17326: }
17327: } elsif ($item eq 'weights') {
1.377 raeburn 17328: foreach my $type ('E','W','N','U') {
1.340 raeburn 17329: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17330: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17331: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17332: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17333: $env{'form.error'.$item.'_'.$type};
17334: }
17335: }
17336: }
17337: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17338: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17339: if ($env{'form.error'.$item} =~ /^\d+$/) {
17340: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17341: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17342: }
17343: }
17344: }
17345: }
1.286 raeburn 17346: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17347: foreach my $field (@{$fields}) {
17348: if (ref($possoptions->{$field}) eq 'ARRAY') {
17349: my $value = $env{'form.helpform_'.$field};
17350: $value =~ s/^\s+|\s+$//g;
17351: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17352: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17353: if ($field eq 'screenshot') {
17354: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17355: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17356: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17357: }
17358: }
17359: }
17360: }
17361: }
17362: }
1.315 raeburn 17363: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17364: my (@statuses,%usertypeshash,@overrides);
17365: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17366: @statuses = @{$types};
17367: if (ref($usertypes) eq 'HASH') {
17368: %usertypeshash = %{$usertypes};
17369: }
17370: }
17371: if (@statuses) {
17372: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17373: foreach my $type (@possoverrides) {
17374: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17375: push(@overrides,$type);
17376: }
17377: }
17378: if (@overrides) {
17379: foreach my $type (@overrides) {
17380: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17381: foreach my $item (@contacts) {
17382: if (grep(/^\Q$item\E$/,@standard)) {
17383: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17384: $newsetting{'override_'.$type}{$item} = 1;
17385: } else {
17386: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17387: $newsetting{'override_'.$type}{$item} = 0;
17388: }
17389: }
17390: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17391: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17392: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17393: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17394: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17395: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17396: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17397: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17398: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17399: }
1.425 raeburn 17400: }
1.315 raeburn 17401: }
17402: }
1.28 raeburn 17403: if (keys(%currsetting) > 0) {
17404: foreach my $item (@contacts) {
17405: if ($to{$item} ne $currsetting{$item}) {
17406: $changes{$item} = 1;
17407: }
17408: }
17409: foreach my $type (@mailings) {
17410: foreach my $item (@contacts) {
17411: if (ref($currsetting{$type}) eq 'HASH') {
17412: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17413: push(@{$changes{$type}},$item);
17414: }
17415: } else {
17416: push(@{$changes{$type}},@{$newsetting{$type}});
17417: }
17418: }
17419: if ($others{$type} ne $currsetting{$type}{'others'}) {
17420: push(@{$changes{$type}},'others');
17421: }
1.289 raeburn 17422: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17423: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17424: push(@{$changes{$type}},'bcc');
17425: }
1.286 raeburn 17426: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17427: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17428: push(@{$changes{$type}},'include');
17429: }
17430: }
17431: }
17432: if (ref($fields) eq 'ARRAY') {
17433: if (ref($currsetting{'helpform'}) eq 'HASH') {
17434: foreach my $field (@{$fields}) {
17435: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17436: push(@{$changes{'helpform'}},$field);
17437: }
17438: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17439: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17440: push(@{$changes{'helpform'}},'maxsize');
17441: }
17442: }
17443: }
17444: } else {
17445: foreach my $field (@{$fields}) {
17446: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17447: push(@{$changes{'helpform'}},$field);
17448: }
17449: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17450: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17451: push(@{$changes{'helpform'}},'maxsize');
17452: }
17453: }
17454: }
1.134 raeburn 17455: }
1.28 raeburn 17456: }
1.315 raeburn 17457: if (@statuses) {
1.425 raeburn 17458: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17459: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17460: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17461: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17462: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17463: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17464: push(@{$changes{'overrides'}},$key);
17465: last;
17466: }
17467: }
17468: } else {
17469: push(@{$changes{'overrides'}},$key);
17470: }
17471: }
17472: }
17473: foreach my $key (@overrides) {
17474: unless (exists($currsetting{'overrides'}{$key})) {
17475: push(@{$changes{'overrides'}},$key);
17476: }
17477: }
17478: } else {
17479: foreach my $key (@overrides) {
1.425 raeburn 17480: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17481: }
17482: }
17483: }
1.340 raeburn 17484: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17485: foreach my $key ('excluded','weights','threshold','sysmail') {
17486: if ($key eq 'excluded') {
17487: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17488: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17489: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17490: (@{$currsetting{'lonstatus'}{$key}})) {
17491: my @diffs =
17492: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17493: $currsetting{'lonstatus'}{$key});
17494: if (@diffs) {
17495: push(@{$changes{'lonstatus'}},$key);
17496: }
17497: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17498: push(@{$changes{'lonstatus'}},$key);
17499: }
17500: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17501: (@{$currsetting{'lonstatus'}{$key}})) {
17502: push(@{$changes{'lonstatus'}},$key);
17503: }
17504: } elsif ($key eq 'weights') {
17505: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17506: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17507: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17508: foreach my $type ('E','W','N','U') {
1.340 raeburn 17509: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17510: $currsetting{'lonstatus'}{$key}{$type}) {
17511: push(@{$changes{'lonstatus'}},$key);
17512: last;
17513: }
17514: }
17515: } else {
1.341 raeburn 17516: foreach my $type ('E','W','N','U') {
1.340 raeburn 17517: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17518: push(@{$changes{'lonstatus'}},$key);
17519: last;
17520: }
17521: }
17522: }
17523: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17524: foreach my $type ('E','W','N','U') {
1.340 raeburn 17525: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17526: push(@{$changes{'lonstatus'}},$key);
17527: last;
17528: }
17529: }
17530: }
17531: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17532: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17533: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17534: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17535: push(@{$changes{'lonstatus'}},$key);
17536: }
17537: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17538: push(@{$changes{'lonstatus'}},$key);
17539: }
17540: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17541: push(@{$changes{'lonstatus'}},$key);
17542: }
17543: }
17544: }
17545: } else {
17546: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17547: foreach my $key ('excluded','weights','threshold','sysmail') {
17548: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17549: push(@{$changes{'lonstatus'}},$key);
17550: }
17551: }
17552: }
17553: }
1.28 raeburn 17554: } else {
17555: my %default;
17556: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17557: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17558: $default{'errormail'} = 'adminemail';
17559: $default{'packagesmail'} = 'adminemail';
17560: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17561: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17562: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17563: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17564: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17565: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17566: foreach my $item (@contacts) {
17567: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17568: $changes{$item} = 1;
1.203 raeburn 17569: }
1.28 raeburn 17570: }
17571: foreach my $type (@mailings) {
17572: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17573: push(@{$changes{$type}},@{$newsetting{$type}});
17574: }
17575: if ($others{$type} ne '') {
17576: push(@{$changes{$type}},'others');
1.134 raeburn 17577: }
1.286 raeburn 17578: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17579: if ($bcc{$type} ne '') {
17580: push(@{$changes{$type}},'bcc');
17581: }
1.286 raeburn 17582: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17583: push(@{$changes{$type}},'include');
17584: }
1.134 raeburn 17585: }
1.28 raeburn 17586: }
1.286 raeburn 17587: if (ref($fields) eq 'ARRAY') {
17588: foreach my $field (@{$fields}) {
17589: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17590: push(@{$changes{'helpform'}},$field);
17591: }
17592: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17593: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17594: push(@{$changes{'helpform'}},'maxsize');
17595: }
17596: }
17597: }
1.289 raeburn 17598: }
1.340 raeburn 17599: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17600: foreach my $key ('excluded','weights','threshold','sysmail') {
17601: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17602: push(@{$changes{'lonstatus'}},$key);
17603: }
17604: }
17605: }
1.28 raeburn 17606: }
1.203 raeburn 17607: foreach my $item (@toggles) {
17608: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17609: $changes{$item} = 1;
17610: } elsif ((!$env{'form.'.$item}) &&
17611: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17612: $changes{$item} = 1;
17613: }
17614: }
1.28 raeburn 17615: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17616: $dom);
17617: if ($putresult eq 'ok') {
17618: if (keys(%changes) > 0) {
1.205 raeburn 17619: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17620: if (ref($lastactref) eq 'HASH') {
17621: $lastactref->{'domainconfig'} = 1;
17622: }
1.28 raeburn 17623: my ($titles,$short_titles) = &contact_titles();
17624: $resulttext = &mt('Changes made:').'<ul>';
17625: foreach my $item (@contacts) {
17626: if ($changes{$item}) {
17627: $resulttext .= '<li>'.$titles->{$item}.
17628: &mt(' set to: ').
17629: '<span class="LC_cusr_emph">'.
17630: $to{$item}.'</span></li>';
17631: }
17632: }
17633: foreach my $type (@mailings) {
17634: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17635: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17636: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17637: } else {
17638: $resulttext .= '<li>'.$titles->{$type}.': ';
17639: }
1.28 raeburn 17640: my @text;
17641: foreach my $item (@{$newsetting{$type}}) {
17642: push(@text,$short_titles->{$item});
17643: }
17644: if ($others{$type} ne '') {
17645: push(@text,$others{$type});
17646: }
1.286 raeburn 17647: if (@text) {
17648: $resulttext .= '<span class="LC_cusr_emph">'.
17649: join(', ',@text).'</span>';
17650: }
17651: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17652: if ($bcc{$type} ne '') {
1.286 raeburn 17653: my $bcctext;
17654: if (@text) {
1.289 raeburn 17655: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17656: } else {
17657: $bcctext = '(Bcc)';
17658: }
17659: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17660: } elsif (!@text) {
17661: $resulttext .= &mt('No one');
1.425 raeburn 17662: }
1.289 raeburn 17663: if ($includestr{$type} ne '') {
1.286 raeburn 17664: if ($includeloc{$type} eq 'b') {
17665: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17666: } elsif ($includeloc{$type} eq 's') {
17667: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17668: }
1.134 raeburn 17669: }
1.286 raeburn 17670: } elsif (!@text) {
17671: $resulttext .= &mt('No recipients');
1.134 raeburn 17672: }
17673: $resulttext .= '</li>';
1.28 raeburn 17674: }
17675: }
1.315 raeburn 17676: if (ref($changes{'overrides'}) eq 'ARRAY') {
17677: my @deletions;
17678: foreach my $type (@{$changes{'overrides'}}) {
17679: if ($usertypeshash{$type}) {
17680: if (grep(/^\Q$type\E/,@overrides)) {
17681: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17682: $usertypeshash{$type}).'<ul><li>';
17683: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17684: my @text;
17685: foreach my $item (@contacts) {
1.425 raeburn 17686: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17687: push(@text,$short_titles->{$item});
17688: }
17689: }
17690: if ($newsetting{'override_'.$type}{'others'} ne '') {
17691: push(@text,$newsetting{'override_'.$type}{'others'});
17692: }
1.425 raeburn 17693:
1.315 raeburn 17694: if (@text) {
17695: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17696: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17697: }
17698: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17699: my $bcctext;
17700: if (@text) {
17701: $bcctext = ' '.&mt('with Bcc to');
17702: } else {
17703: $bcctext = '(Bcc)';
17704: }
17705: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17706: } elsif (!@text) {
17707: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17708: }
17709: $resulttext .= '</li>';
17710: if ($newsetting{'override_'.$type}{'include'} ne '') {
17711: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17712: if ($loc eq 'b') {
17713: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17714: } elsif ($loc eq 's') {
17715: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17716: }
17717: }
17718: }
17719: $resulttext .= '</li></ul></li>';
17720: } else {
17721: push(@deletions,$usertypeshash{$type});
17722: }
17723: }
17724: }
17725: if (@deletions) {
17726: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17727: join(', ',@deletions)).'</li>';
17728: }
17729: }
1.203 raeburn 17730: my @offon = ('off','on');
1.340 raeburn 17731: my $corelink = &core_link_msu();
1.203 raeburn 17732: if ($changes{'reporterrors'}) {
17733: $resulttext .= '<li>'.
17734: &mt('E-mail error reports to [_1] set to "'.
17735: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17736: $corelink).
1.203 raeburn 17737: '</li>';
17738: }
17739: if ($changes{'reportupdates'}) {
17740: $resulttext .= '<li>'.
17741: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17742: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17743: $corelink).
1.203 raeburn 17744: '</li>';
17745: }
1.340 raeburn 17746: if ($changes{'reportstatus'}) {
17747: $resulttext .= '<li>'.
17748: &mt('E-mail status if errors above threshold to [_1] set to "'.
17749: $offon[$env{'form.reportstatus'}].'".',
17750: $corelink).
17751: '</li>';
17752: }
17753: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17754: $resulttext .= '<li>'.
17755: &mt('Nightly status check e-mail settings').':<ul>';
17756: my (%defval,%use_def,%shown);
17757: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17758: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17759: $defval{'weights'} =
1.341 raeburn 17760: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17761: $defval{'excluded'} = &mt('None');
17762: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17763: foreach my $item ('threshold','sysmail','weights','excluded') {
17764: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17765: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17766: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17767: } elsif ($item eq 'weights') {
17768: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17769: foreach my $type ('E','W','N','U') {
1.340 raeburn 17770: $shown{$item} .= $lonstatus_names->{$type}.'=';
17771: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17772: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17773: } else {
17774: $shown{$item} .= $lonstatus_defs->{$type};
17775: }
17776: $shown{$item} .= ', ';
17777: }
17778: $shown{$item} =~ s/, $//;
17779: } else {
17780: $shown{$item} = $defval{$item};
17781: }
17782: } elsif ($item eq 'excluded') {
17783: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17784: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17785: } else {
17786: $shown{$item} = $defval{$item};
17787: }
17788: }
17789: } else {
17790: $shown{$item} = $defval{$item};
17791: }
17792: }
17793: } else {
17794: foreach my $item ('threshold','weights','excluded','sysmail') {
17795: $shown{$item} = $defval{$item};
17796: }
17797: }
17798: foreach my $item ('threshold','weights','excluded','sysmail') {
17799: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17800: $shown{$item}).'</li>';
17801: }
17802: $resulttext .= '</ul></li>';
17803: }
1.286 raeburn 17804: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17805: my (@optional,@required,@unused,$maxsizechg);
17806: foreach my $field (@{$changes{'helpform'}}) {
17807: if ($field eq 'maxsize') {
17808: $maxsizechg = 1;
17809: next;
17810: }
17811: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17812: push(@optional,$field);
1.286 raeburn 17813: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17814: push(@unused,$field);
17815: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17816: push(@required,$field);
1.286 raeburn 17817: }
17818: }
17819: if (@optional) {
17820: $resulttext .= '<li>'.
17821: &mt('Help form fields changed to "Optional": [_1].',
17822: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17823: '</li>';
17824: }
17825: if (@required) {
17826: $resulttext .= '<li>'.
17827: &mt('Help form fields changed to "Required": [_1].',
17828: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17829: '</li>';
17830: }
17831: if (@unused) {
17832: $resulttext .= '<li>'.
17833: &mt('Help form fields changed to "Not shown": [_1].',
17834: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17835: '</li>';
17836: }
17837: if ($maxsizechg) {
17838: $resulttext .= '<li>'.
17839: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17840: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17841: '</li>';
17842: }
17843: }
1.28 raeburn 17844: $resulttext .= '</ul>';
17845: } else {
1.288 raeburn 17846: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17847: }
17848: } else {
17849: $resulttext = '<span class="LC_error">'.
17850: &mt('An error occurred: [_1].',$putresult).'</span>';
17851: }
17852: return $resulttext;
17853: }
17854:
1.357 raeburn 17855: sub modify_privacy {
1.427 raeburn 17856: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17857: my ($resulttext,%current,%changes);
17858: if (ref($domconfig{'privacy'}) eq 'HASH') {
17859: %current = %{$domconfig{'privacy'}};
17860: }
17861: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17862: my @items = ('domain','author','course','community');
17863: my %names = &Apache::lonlocal::texthash (
17864: domain => 'Assigned domain role(s)',
17865: author => 'Assigned co-author role(s)',
17866: course => 'Assigned course role(s)',
1.416 raeburn 17867: community => 'Assigned community role(s)',
1.357 raeburn 17868: );
17869: my %roles = &Apache::lonlocal::texthash (
17870: domain => 'Domain role',
17871: author => 'Co-author role',
17872: course => 'Course role',
17873: community => 'Community role',
17874: );
17875: my %titles = &Apache::lonlocal::texthash (
17876: approval => 'Approval for role in different domain',
17877: othdom => 'User information available in other domain',
17878: priv => 'Information viewable by privileged user in same domain',
17879: unpriv => 'Information viewable by unprivileged user in same domain',
17880: instdom => 'Other domain shares institution/provider',
17881: extdom => 'Other domain has different institution/provider',
17882: none => 'Not allowed',
17883: user => 'User authorizes',
17884: domain => 'Domain Coordinator authorizes',
17885: auto => 'Unrestricted',
1.418 raeburn 17886: notify => 'Notify when role needs authorization',
1.357 raeburn 17887: );
17888: my %fieldnames = &Apache::lonlocal::texthash (
17889: id => 'Student/Employee ID',
17890: permanentemail => 'E-mail address',
17891: lastname => 'Last Name',
17892: firstname => 'First Name',
17893: middlename => 'Middle Name',
17894: generation => 'Generation',
17895: );
17896: my ($othertitle,$usertypes,$types) =
17897: &Apache::loncommon::sorted_inst_types($dom);
17898: my (%by_ip,%by_location,@intdoms,@instdoms);
17899: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17900:
17901: my %privacyhash = (
17902: 'approval' => {
17903: instdom => {},
17904: extdom => {},
17905: },
17906: 'othdom' => {},
17907: 'priv' => {},
17908: 'unpriv' => {},
17909: );
17910: foreach my $item (@items) {
17911: if (@instdoms > 1) {
1.416 raeburn 17912: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17913: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17914: }
17915: if (ref($current{'approval'}) eq 'HASH') {
17916: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17917: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17918: $changes{'approval'} = 1;
17919: }
17920: }
17921: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17922: $changes{'approval'} = 1;
17923: }
17924: }
17925: if (keys(%by_location) > 0) {
17926: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17927: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17928: }
17929: if (ref($current{'approval'}) eq 'HASH') {
17930: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17931: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17932: $changes{'approval'} = 1;
17933: }
17934: }
17935: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17936: $changes{'approval'} = 1;
17937: }
17938: }
17939: foreach my $status ('priv','unpriv') {
17940: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17941: my @newvalues;
17942: foreach my $field (@possibles) {
17943: if (grep(/^\Q$field\E$/,@fields)) {
17944: $privacyhash{$status}{$item}{$field} = 1;
17945: push(@newvalues,$field);
17946: }
17947: }
17948: @newvalues = sort(@newvalues);
17949: if (ref($current{$status}) eq 'HASH') {
17950: if (ref($current{$status}{$item}) eq 'HASH') {
17951: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17952: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17953: if (@diffs > 0) {
17954: $changes{$status} = 1;
17955: }
17956: }
17957: } else {
17958: my @stdfields;
17959: foreach my $field (@fields) {
17960: if ($field eq 'id') {
17961: next if ($status eq 'unpriv');
17962: next if (($status eq 'priv') && ($item eq 'community'));
17963: }
17964: push(@stdfields,$field);
17965: }
17966: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17967: if (@diffs > 0) {
17968: $changes{$status} = 1;
17969: }
17970: }
17971: }
17972: }
17973: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17974: my @statuses;
17975: if (ref($types) eq 'ARRAY') {
17976: @statuses = @{$types};
17977: }
17978: foreach my $type (@statuses,'default') {
17979: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17980: my @newvalues;
17981: foreach my $field (sort(@possfields)) {
17982: if (grep(/^\Q$field\E$/,@fields)) {
17983: $privacyhash{'othdom'}{$type}{$field} = 1;
17984: push(@newvalues,$field);
17985: }
17986: }
17987: @newvalues = sort(@newvalues);
17988: if (ref($current{'othdom'}) eq 'HASH') {
17989: if (ref($current{'othdom'}{$type}) eq 'HASH') {
17990: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
17991: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17992: if (@diffs > 0) {
17993: $changes{'othdom'} = 1;
17994: }
17995: }
17996: } else {
17997: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
17998: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17999: if (@diffs > 0) {
18000: $changes{'othdom'} = 1;
18001: }
18002: }
18003: }
1.417 raeburn 18004: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
18005: my %notify;
18006: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
18007: if (exists($domcoords{$possdc})) {
18008: $notify{$possdc} = 1;
18009: }
18010: }
18011: my $notify = join(',',sort(keys(%notify)));
18012: if ($current{'notify'} ne $notify) {
18013: $changes{'notify'} = 1;
18014: }
18015: $privacyhash{'notify'} = $notify;
1.357 raeburn 18016: }
18017: my %confighash = (
18018: privacy => \%privacyhash,
18019: );
18020: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18021: if ($putresult eq 'ok') {
18022: if (keys(%changes) > 0) {
18023: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 18024: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 18025: if ($changes{$key}) {
18026: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18027: if ($key eq 'approval') {
18028: if (keys(%{$privacyhash{$key}{instdom}})) {
18029: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
18030: foreach my $item (@items) {
18031: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
18032: }
18033: $resulttext .= '</ul></li>';
18034: }
18035: if (keys(%{$privacyhash{$key}{extdom}})) {
18036: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
18037: foreach my $item (@items) {
18038: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
18039: }
18040: $resulttext .= '</ul></li>';
18041: }
1.417 raeburn 18042: } elsif ($key eq 'notify') {
18043: if ($privacyhash{$key}) {
18044: foreach my $dc (split(/,/,$privacyhash{$key})) {
18045: my ($dcname,$dcdom) = split(/:/,$dc);
18046: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
18047: }
18048: } else {
18049: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
18050: }
1.357 raeburn 18051: } elsif ($key eq 'othdom') {
18052: my @statuses;
18053: if (ref($types) eq 'ARRAY') {
18054: @statuses = @{$types};
18055: }
18056: if (ref($privacyhash{$key}) eq 'HASH') {
18057: foreach my $status (@statuses,'default') {
18058: if ($status eq 'default') {
18059: $resulttext .= '<li>'.$othertitle.': ';
18060: } elsif (ref($usertypes) eq 'HASH') {
18061: $resulttext .= '<li>'.$usertypes->{$status}.': ';
18062: } else {
18063: next;
18064: }
18065: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
18066: if (keys(%{$privacyhash{$key}{$status}})) {
18067: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
18068: } else {
18069: $resulttext .= &mt('none');
18070: }
18071: }
18072: $resulttext .= '</li>';
18073: }
18074: }
18075: } else {
18076: foreach my $item (@items) {
18077: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
18078: $resulttext .= '<li>'.$names{$item}.': ';
18079: if (keys(%{$privacyhash{$key}{$item}})) {
18080: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
18081: } else {
18082: $resulttext .= &mt('none');
18083: }
18084: $resulttext .= '</li>';
18085: }
18086: }
18087: }
18088: $resulttext .= '</ul></li>';
18089: }
18090: }
1.421 raeburn 18091: $resulttext .= '</ul>';
1.427 raeburn 18092: if ($changes{'approval'}) {
18093: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18094: delete($domdefaults{'userapprovals'});
18095: if (ref($privacyhash{'approval'}) eq 'HASH') {
18096: foreach my $domtype ('instdom','extdom') {
18097: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
18098: foreach my $roletype ('domain','author','course','community') {
18099: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
18100: $domdefaults{'userapprovals'} = 1;
18101: last;
18102: }
18103: }
18104: }
18105: last if ($domdefaults{'userapprovals'});
18106: }
18107: }
18108: my $cachetime = 24*60*60;
18109: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18110: if (ref($lastactref) eq 'HASH') {
18111: $lastactref->{'domdefaults'} = 1;
18112: }
18113: }
1.357 raeburn 18114: } else {
18115: $resulttext = &mt('No changes made to user information settings');
18116: }
18117: } else {
18118: $resulttext = '<span class="LC_error">'.
18119: &mt('An error occurred: [_1]',$putresult).'</span>';
18120: }
18121: return $resulttext;
18122: }
18123:
1.354 raeburn 18124: sub modify_passwords {
18125: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18126: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18127: $updatedefaults,$updateconf);
1.354 raeburn 18128: my $customfn = 'resetpw.html';
18129: if (ref($domconfig{'passwords'}) eq 'HASH') {
18130: %current = %{$domconfig{'passwords'}};
18131: }
18132: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18133: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18134: if (ref($types) eq 'ARRAY') {
18135: @oktypes = @{$types};
18136: }
18137: push(@oktypes,'default');
18138:
18139: my %titles = &Apache::lonlocal::texthash (
18140: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18141: intauth_check => 'Check bcrypt cost if authenticated',
18142: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18143: permanent => 'Permanent e-mail address',
18144: critical => 'Critical notification address',
18145: notify => 'Notification address',
18146: min => 'Minimum password length',
18147: max => 'Maximum password length',
18148: chars => 'Required characters',
18149: expire => 'Password expiration (days)',
1.356 raeburn 18150: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18151: reset => 'Resetting Forgotten Password',
18152: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18153: rules => 'Rules for LON-CAPA Passwords',
18154: crsownerchg => 'Course Owner Changing Student Passwords',
18155: username => 'Username',
18156: email => 'E-mail address',
18157: );
18158:
18159: #
18160: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18161: #
18162: my (%curr_defaults,%save_defaults);
18163: if (ref($domconfig{'defaults'}) eq 'HASH') {
18164: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18165: if ($key =~ /^intauth_(cost|check|switch)$/) {
18166: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18167: } else {
18168: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18169: }
18170: }
18171: }
18172: my %staticdefaults = (
18173: 'resetlink' => 2,
18174: 'resetcase' => \@oktypes,
18175: 'resetprelink' => 'both',
18176: 'resetemail' => ['critical','notify','permanent'],
18177: 'intauth_cost' => 10,
18178: 'intauth_check' => 0,
18179: 'intauth_switch' => 0,
18180: );
1.365 raeburn 18181: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18182: foreach my $type (@oktypes) {
18183: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18184: }
18185: my $linklife = $env{'form.passwords_link'};
18186: $linklife =~ s/^\s+|\s+$//g;
18187: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18188: $newvalues{'resetlink'} = $linklife;
18189: if ($current{'resetlink'}) {
18190: if ($current{'resetlink'} ne $linklife) {
18191: $changes{'reset'} = 1;
18192: }
1.368 raeburn 18193: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18194: if ($staticdefaults{'resetlink'} ne $linklife) {
18195: $changes{'reset'} = 1;
18196: }
18197: }
18198: } elsif ($current{'resetlink'}) {
18199: $changes{'reset'} = 1;
18200: }
18201: my @casesens;
18202: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18203: foreach my $case (sort(@posscase)) {
18204: if (grep(/^\Q$case\E$/,@oktypes)) {
18205: push(@casesens,$case);
18206: }
18207: }
18208: $newvalues{'resetcase'} = \@casesens;
18209: if (ref($current{'resetcase'}) eq 'ARRAY') {
18210: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18211: if (@diffs > 0) {
18212: $changes{'reset'} = 1;
18213: }
1.368 raeburn 18214: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18215: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18216: if (@diffs > 0) {
18217: $changes{'reset'} = 1;
18218: }
18219: }
18220: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18221: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18222: if (exists($current{'resetprelink'})) {
18223: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18224: $changes{'reset'} = 1;
18225: }
1.368 raeburn 18226: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18227: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18228: $changes{'reset'} = 1;
18229: }
18230: }
18231: } elsif ($current{'resetprelink'}) {
18232: $changes{'reset'} = 1;
18233: }
18234: foreach my $type (@oktypes) {
18235: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18236: my @postlink;
18237: foreach my $item (sort(@possplink)) {
18238: if ($item =~ /^(email|username)$/) {
18239: push(@postlink,$item);
18240: }
18241: }
18242: $newvalues{'resetpostlink'}{$type} = \@postlink;
18243: unless ($changes{'reset'}) {
18244: if (ref($current{'resetpostlink'}) eq 'HASH') {
18245: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18246: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18247: if (@diffs > 0) {
18248: $changes{'reset'} = 1;
18249: }
18250: } else {
18251: $changes{'reset'} = 1;
18252: }
1.368 raeburn 18253: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18254: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18255: if (@diffs > 0) {
18256: $changes{'reset'} = 1;
18257: }
18258: }
18259: }
18260: }
18261: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18262: my @resetemail;
18263: foreach my $item (sort(@possemailsrc)) {
18264: if ($item =~ /^(permanent|critical|notify)$/) {
18265: push(@resetemail,$item);
18266: }
18267: }
18268: $newvalues{'resetemail'} = \@resetemail;
18269: unless ($changes{'reset'}) {
18270: if (ref($current{'resetemail'}) eq 'ARRAY') {
18271: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18272: if (@diffs > 0) {
18273: $changes{'reset'} = 1;
18274: }
1.368 raeburn 18275: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18276: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18277: if (@diffs > 0) {
18278: $changes{'reset'} = 1;
18279: }
18280: }
18281: }
18282: if ($env{'form.passwords_stdtext'} == 0) {
18283: $newvalues{'resetremove'} = 1;
18284: unless ($current{'resetremove'}) {
18285: $changes{'reset'} = 1;
18286: }
18287: } elsif ($current{'resetremove'}) {
18288: $changes{'reset'} = 1;
18289: }
18290: if ($env{'form.passwords_customfile.filename'} ne '') {
18291: my $servadm = $r->dir_config('lonAdmEMail');
18292: my ($configuserok,$author_ok,$switchserver) =
18293: &config_check($dom,$confname,$servadm);
18294: my $error;
18295: if ($configuserok eq 'ok') {
18296: if ($switchserver) {
18297: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18298: } else {
18299: if ($author_ok eq 'ok') {
1.421 raeburn 18300: my $modified = [];
1.354 raeburn 18301: my ($result,$customurl) =
1.421 raeburn 18302: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18303: $confname,'customtext/resetpw','','',$customfn,
18304: $modified);
1.354 raeburn 18305: if ($result eq 'ok') {
18306: $newvalues{'resetcustom'} = $customurl;
18307: $changes{'reset'} = 1;
1.421 raeburn 18308: &update_modify_urls($r,$modified);
1.354 raeburn 18309: } else {
18310: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18311: }
18312: } else {
18313: $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);
18314: }
18315: }
18316: } else {
18317: $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);
18318: }
18319: if ($error) {
18320: &Apache::lonnet::logthis($error);
18321: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18322: }
18323: } elsif ($current{'resetcustom'}) {
18324: if ($env{'form.passwords_custom_del'}) {
18325: $changes{'reset'} = 1;
18326: } else {
18327: $newvalues{'resetcustom'} = $current{'resetcustom'};
18328: }
18329: }
18330: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18331: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18332: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18333: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18334: $changes{'intauth'} = 1;
18335: }
18336: } else {
18337: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18338: }
18339: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18340: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18341: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18342: $changes{'intauth'} = 1;
18343: }
18344: } else {
18345: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18346: }
18347: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18348: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18349: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18350: $changes{'intauth'} = 1;
18351: }
18352: } else {
18353: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18354: }
18355: foreach my $item ('cost','check','switch') {
18356: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18357: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18358: $updatedefaults = 1;
18359: }
18360: }
1.405 raeburn 18361: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18362: my %crsownerchg = (
18363: by => [],
18364: for => [],
18365: );
18366: foreach my $item ('by','for') {
18367: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18368: foreach my $type (sort(@posstypes)) {
18369: if (grep(/^\Q$type\E$/,@oktypes)) {
18370: push(@{$crsownerchg{$item}},$type);
18371: }
18372: }
18373: }
18374: $newvalues{'crsownerchg'} = \%crsownerchg;
18375: if (ref($current{'crsownerchg'}) eq 'HASH') {
18376: foreach my $item ('by','for') {
18377: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18378: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18379: if (@diffs > 0) {
18380: $changes{'crsownerchg'} = 1;
18381: last;
18382: }
18383: }
18384: }
1.368 raeburn 18385: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18386: foreach my $item ('by','for') {
18387: if (@{$crsownerchg{$item}} > 0) {
18388: $changes{'crsownerchg'} = 1;
18389: last;
18390: }
1.354 raeburn 18391: }
18392: }
18393:
18394: my %confighash = (
18395: defaults => \%save_defaults,
18396: passwords => \%newvalues,
18397: );
18398: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18399:
18400: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18401: if ($putresult eq 'ok') {
18402: if (keys(%changes) > 0) {
18403: $resulttext = &mt('Changes made: ').'<ul>';
18404: foreach my $key ('reset','intauth','rules','crsownerchg') {
18405: if ($changes{$key}) {
1.355 raeburn 18406: unless ($key eq 'intauth') {
18407: $updateconf = 1;
18408: }
1.354 raeburn 18409: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18410: if ($key eq 'reset') {
18411: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18412: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18413: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18414: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18415: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18416: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18417: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18418: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18419: }
1.354 raeburn 18420: } else {
18421: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18422: }
18423: if ($confighash{'passwords'}{'resetlink'}) {
18424: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18425: } else {
18426: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18427: &mt('Will default to 2 hours').'</li>';
18428: }
18429: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18430: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18431: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18432: } else {
18433: my $casesens;
18434: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18435: if ($type eq 'default') {
18436: $casesens .= $othertitle.', ';
18437: } elsif ($usertypes->{$type} ne '') {
18438: $casesens .= $usertypes->{$type}.', ';
18439: }
18440: }
18441: $casesens =~ s/\Q, \E$//;
18442: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18443: }
18444: } else {
18445: $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>';
18446: }
18447: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18448: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18449: } else {
18450: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18451: }
18452: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18453: my $output;
18454: if (ref($types) eq 'ARRAY') {
18455: foreach my $type (@{$types}) {
18456: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18457: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18458: $output .= $usertypes->{$type}.' -- '.&mt('none');
18459: } else {
18460: $output .= $usertypes->{$type}.' -- '.
18461: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18462: }
18463: }
18464: }
18465: }
18466: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18467: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18468: $output .= $othertitle.' -- '.&mt('none');
18469: } else {
18470: $output .= $othertitle.' -- '.
18471: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18472: }
18473: }
18474: if ($output) {
18475: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18476: } else {
18477: $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>';
18478: }
18479: } else {
18480: $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>';
18481: }
18482: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18483: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18484: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18485: } else {
18486: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18487: }
18488: } else {
1.379 raeburn 18489: $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 18490: }
18491: if ($confighash{'passwords'}{'resetremove'}) {
18492: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18493: } else {
18494: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18495: }
18496: if ($confighash{'passwords'}{'resetcustom'}) {
18497: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18498: &mt('custom text'),600,500,undef,undef,
18499: undef,undef,'background-color:#ffffff');
18500: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18501: } else {
18502: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18503: }
18504: } elsif ($key eq 'intauth') {
18505: foreach my $item ('cost','switch','check') {
18506: my $value = $save_defaults{$key.'_'.$item};
18507: if ($item eq 'switch') {
18508: my %optiondesc = &Apache::lonlocal::texthash (
18509: 0 => 'No',
18510: 1 => 'Yes',
18511: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18512: );
18513: if ($value =~ /^(0|1|2)$/) {
18514: $value = $optiondesc{$value};
18515: } else {
18516: $value = &mt('none -- defaults to No');
18517: }
18518: } elsif ($item eq 'check') {
18519: my %optiondesc = &Apache::lonlocal::texthash (
18520: 0 => 'No',
18521: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18522: 2 => 'Yes, disallow login if stored cost is less than domain default',
18523: );
18524: if ($value =~ /^(0|1|2)$/) {
18525: $value = $optiondesc{$value};
18526: } else {
18527: $value = &mt('none -- defaults to No');
18528: }
18529: }
18530: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18531: }
18532: } elsif ($key eq 'rules') {
1.356 raeburn 18533: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18534: if ($confighash{'passwords'}{$rule} eq '') {
18535: if ($rule eq 'min') {
1.356 raeburn 18536: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18537: ' '.&mt('Default of [_1] will be used',
18538: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18539: } else {
18540: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18541: }
18542: } else {
18543: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18544: }
18545: }
1.370 raeburn 18546: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18547: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18548: my %rulenames = &Apache::lonlocal::texthash(
18549: uc => 'At least one upper case letter',
18550: lc => 'At least one lower case letter',
18551: num => 'At least one number',
18552: spec => 'At least one non-alphanumeric',
18553: );
18554: my $needed = '<ul><li>'.
18555: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18556: '</li></ul>';
1.370 raeburn 18557: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18558: } else {
18559: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18560: }
18561: } else {
18562: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18563: }
1.354 raeburn 18564: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18565: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18566: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18567: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18568: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18569: } else {
18570: my %crsownerstr;
18571: foreach my $item ('by','for') {
18572: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18573: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18574: if ($type eq 'default') {
18575: $crsownerstr{$item} .= $othertitle.', ';
18576: } elsif ($usertypes->{$type} ne '') {
18577: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18578: }
18579: }
18580: $crsownerstr{$item} =~ s/\Q, \E$//;
18581: }
18582: }
18583: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18584: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18585: }
1.354 raeburn 18586: } else {
1.359 raeburn 18587: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18588: }
18589: }
18590: $resulttext .= '</ul></li>';
18591: }
18592: }
18593: $resulttext .= '</ul>';
18594: } else {
18595: $resulttext = &mt('No changes made to password settings');
18596: }
1.355 raeburn 18597: my $cachetime = 24*60*60;
1.354 raeburn 18598: if ($updatedefaults) {
18599: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18600: if (ref($lastactref) eq 'HASH') {
18601: $lastactref->{'domdefaults'} = 1;
18602: }
18603: }
1.355 raeburn 18604: if ($updateconf) {
18605: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18606: if (ref($lastactref) eq 'HASH') {
18607: $lastactref->{'passwdconf'} = 1;
18608: }
18609: }
1.354 raeburn 18610: } else {
18611: $resulttext = '<span class="LC_error">'.
18612: &mt('An error occurred: [_1]',$putresult).'</span>';
18613: }
18614: if ($errors) {
18615: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18616: $errors.'</ul></p>';
18617: }
18618: return $resulttext;
18619: }
18620:
1.405 raeburn 18621: sub password_rule_changes {
18622: my ($prefix,$newvalues,$current,$changes) = @_;
18623: return unless ((ref($newvalues) eq 'HASH') &&
18624: (ref($current) eq 'HASH') &&
18625: (ref($changes) eq 'HASH'));
18626: my (@rules,%staticdefaults);
18627: if ($prefix eq 'passwords') {
18628: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18629: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18630: @rules = ('min','max');
18631: }
18632: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18633: foreach my $rule (@rules) {
18634: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18635: my $ruleok;
18636: if ($rule eq 'expire') {
18637: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18638: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18639: $ruleok = 1;
18640: }
18641: } elsif ($rule eq 'min') {
18642: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18643: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18644: $ruleok = 1;
18645: }
18646: }
18647: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18648: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18649: $ruleok = 1;
18650: }
18651: if ($ruleok) {
18652: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18653: if (exists($current->{$rule})) {
18654: if ($newvalues->{$rule} ne $current->{$rule}) {
18655: $changes->{'rules'} = 1;
18656: }
18657: } elsif ($rule eq 'min') {
18658: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18659: $changes->{'rules'} = 1;
18660: }
18661: } else {
18662: $changes->{'rules'} = 1;
18663: }
18664: } elsif (exists($current->{$rule})) {
18665: $changes->{'rules'} = 1;
18666: }
18667: }
18668: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18669: my @chars;
18670: foreach my $item (sort(@posschars)) {
18671: if ($item =~ /^(uc|lc|num|spec)$/) {
18672: push(@chars,$item);
18673: }
18674: }
18675: $newvalues->{'chars'} = \@chars;
18676: unless ($changes->{'rules'}) {
18677: if (ref($current->{'chars'}) eq 'ARRAY') {
18678: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18679: if (@diffs > 0) {
18680: $changes->{'rules'} = 1;
18681: }
18682: } else {
18683: if (@chars > 0) {
18684: $changes->{'rules'} = 1;
18685: }
18686: }
18687: }
18688: return;
18689: }
18690:
1.28 raeburn 18691: sub modify_usercreation {
1.27 raeburn 18692: my ($dom,%domconfig) = @_;
1.224 raeburn 18693: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18694: my $warningmsg;
1.27 raeburn 18695: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18696: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18697: if ($key eq 'cancreate') {
18698: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18699: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18700: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18701: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18702: } else {
1.224 raeburn 18703: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18704: }
18705: }
18706: }
18707: } elsif ($key eq 'email_rule') {
18708: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18709: } else {
18710: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18711: }
1.27 raeburn 18712: }
18713: }
18714: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18715: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18716: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18717: foreach my $item(@contexts) {
1.224 raeburn 18718: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18719: }
1.34 raeburn 18720: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18721: foreach my $item (@contexts) {
1.224 raeburn 18722: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18723: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18724: }
1.27 raeburn 18725: }
1.34 raeburn 18726: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18727: foreach my $item (@contexts) {
1.43 raeburn 18728: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18729: if ($cancreate{$item} ne 'any') {
18730: push(@{$changes{'cancreate'}},$item);
18731: }
18732: } else {
18733: if ($cancreate{$item} ne 'none') {
18734: push(@{$changes{'cancreate'}},$item);
18735: }
1.27 raeburn 18736: }
18737: }
18738: } else {
1.43 raeburn 18739: foreach my $item (@contexts) {
1.34 raeburn 18740: push(@{$changes{'cancreate'}},$item);
18741: }
1.27 raeburn 18742: }
1.34 raeburn 18743:
1.27 raeburn 18744: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18745: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18746: if (!grep(/^\Q$type\E$/,@username_rule)) {
18747: push(@{$changes{'username_rule'}},$type);
18748: }
18749: }
18750: foreach my $type (@username_rule) {
18751: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18752: push(@{$changes{'username_rule'}},$type);
18753: }
18754: }
18755: } else {
18756: push(@{$changes{'username_rule'}},@username_rule);
18757: }
18758:
1.32 raeburn 18759: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18760: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18761: if (!grep(/^\Q$type\E$/,@id_rule)) {
18762: push(@{$changes{'id_rule'}},$type);
18763: }
18764: }
18765: foreach my $type (@id_rule) {
18766: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18767: push(@{$changes{'id_rule'}},$type);
18768: }
18769: }
18770: } else {
18771: push(@{$changes{'id_rule'}},@id_rule);
18772: }
18773:
1.43 raeburn 18774: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18775: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18776: my %authhash;
1.43 raeburn 18777: foreach my $item (@authen_contexts) {
1.28 raeburn 18778: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18779: foreach my $auth (@authtypes) {
18780: if (grep(/^\Q$auth\E$/,@authallowed)) {
18781: $authhash{$item}{$auth} = 1;
18782: } else {
18783: $authhash{$item}{$auth} = 0;
18784: }
18785: }
18786: }
18787: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18788: foreach my $item (@authen_contexts) {
1.28 raeburn 18789: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18790: foreach my $auth (@authtypes) {
18791: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18792: push(@{$changes{'authtypes'}},$item);
18793: last;
18794: }
18795: }
18796: }
18797: }
18798: } else {
1.43 raeburn 18799: foreach my $item (@authen_contexts) {
1.28 raeburn 18800: push(@{$changes{'authtypes'}},$item);
18801: }
18802: }
18803:
1.224 raeburn 18804: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18805: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18806: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18807: $save_usercreate{'id_rule'} = \@id_rule;
18808: $save_usercreate{'username_rule'} = \@username_rule,
18809: $save_usercreate{'authtypes'} = \%authhash;
18810:
1.27 raeburn 18811: my %usercreation_hash = (
1.224 raeburn 18812: usercreation => \%save_usercreate,
18813: );
1.27 raeburn 18814:
18815: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18816: $dom);
1.50 raeburn 18817:
1.224 raeburn 18818: if ($putresult eq 'ok') {
18819: if (keys(%changes) > 0) {
18820: $resulttext = &mt('Changes made:').'<ul>';
18821: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18822: my %lt = &usercreation_types();
18823: foreach my $type (@{$changes{'cancreate'}}) {
18824: my $chgtext = $lt{$type}.', ';
18825: if ($cancreate{$type} eq 'none') {
18826: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18827: } elsif ($cancreate{$type} eq 'any') {
18828: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18829: } elsif ($cancreate{$type} eq 'official') {
18830: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18831: } elsif ($cancreate{$type} eq 'unofficial') {
18832: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18833: }
18834: $resulttext .= '<li>'.$chgtext.'</li>';
18835: }
18836: }
18837: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18838: my ($rules,$ruleorder) =
18839: &Apache::lonnet::inst_userrules($dom,'username');
18840: my $chgtext = '<ul>';
18841: foreach my $type (@username_rule) {
18842: if (ref($rules->{$type}) eq 'HASH') {
18843: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18844: }
18845: }
18846: $chgtext .= '</ul>';
18847: if (@username_rule > 0) {
18848: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18849: } else {
18850: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18851: }
18852: }
18853: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18854: my ($idrules,$idruleorder) =
18855: &Apache::lonnet::inst_userrules($dom,'id');
18856: my $chgtext = '<ul>';
18857: foreach my $type (@id_rule) {
18858: if (ref($idrules->{$type}) eq 'HASH') {
18859: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18860: }
18861: }
18862: $chgtext .= '</ul>';
18863: if (@id_rule > 0) {
18864: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18865: } else {
18866: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18867: }
18868: }
18869: my %authname = &authtype_names();
18870: my %context_title = &context_names();
18871: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18872: my $chgtext = '<ul>';
18873: foreach my $type (@{$changes{'authtypes'}}) {
18874: my @allowed;
18875: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18876: foreach my $auth (@authtypes) {
18877: if ($authhash{$type}{$auth}) {
18878: push(@allowed,$authname{$auth});
18879: }
18880: }
18881: if (@allowed > 0) {
18882: $chgtext .= join(', ',@allowed).'</li>';
18883: } else {
18884: $chgtext .= &mt('none').'</li>';
18885: }
18886: }
18887: $chgtext .= '</ul>';
18888: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18889: $resulttext .= '</li>';
18890: }
18891: $resulttext .= '</ul>';
18892: } else {
18893: $resulttext = &mt('No changes made to user creation settings');
18894: }
18895: } else {
18896: $resulttext = '<span class="LC_error">'.
18897: &mt('An error occurred: [_1]',$putresult).'</span>';
18898: }
18899: if ($warningmsg ne '') {
18900: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18901: }
18902: return $resulttext;
18903: }
18904:
18905: sub modify_selfcreation {
1.305 raeburn 18906: my ($dom,$lastactref,%domconfig) = @_;
18907: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18908: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18909: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18910: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18911: if (ref($typesref) eq 'ARRAY') {
18912: @types = @{$typesref};
18913: }
18914: if (ref($usertypesref) eq 'HASH') {
18915: %usertypes = %{$usertypesref};
1.228 raeburn 18916: }
1.303 raeburn 18917: $usertypes{'default'} = $othertitle;
1.224 raeburn 18918: #
18919: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18920: #
18921: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18922: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18923: if ($key eq 'cancreate') {
18924: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18925: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18926: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18927: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18928: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18929: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18930: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18931: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18932: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18933: } else {
18934: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18935: }
18936: }
18937: }
18938: } elsif ($key eq 'email_rule') {
18939: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18940: } else {
18941: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18942: }
18943: }
18944: }
18945: #
18946: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18947: #
18948: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18949: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18950: if ($key eq 'selfcreate') {
18951: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18952: } else {
18953: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18954: }
18955: }
18956: }
1.305 raeburn 18957: #
18958: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18959: #
18960: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18961: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18962: if ($key eq 'inststatusguest') {
18963: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18964: } else {
18965: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18966: }
18967: }
18968: }
1.224 raeburn 18969:
18970: my @contexts = ('selfcreate');
18971: @{$cancreate{'selfcreate'}} = ();
18972: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18973: if (@types) {
18974: @{$cancreate{'statustocreate'}} = ();
18975: }
1.236 raeburn 18976: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18977: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18978: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18979: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18980: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18981: my %selfcreatetypes = (
18982: sso => 'users authenticated by institutional single sign on',
18983: login => 'users authenticated by institutional log-in',
1.303 raeburn 18984: email => 'users verified by e-mail',
1.50 raeburn 18985: );
1.224 raeburn 18986: #
18987: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18988: # is permitted.
18989: #
1.305 raeburn 18990: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 18991:
1.305 raeburn 18992: my (@statuses,%email_rule);
1.228 raeburn 18993: foreach my $item ('login','sso','email') {
1.224 raeburn 18994: if ($item eq 'email') {
1.236 raeburn 18995: if ($env{'form.cancreate_email'}) {
1.305 raeburn 18996: if (@types) {
18997: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
18998: foreach my $status (@poss_statuses) {
18999: if (grep(/^\Q$status\E$/,(@types,'default'))) {
19000: push(@statuses,$status);
19001: }
19002: }
19003: $save_inststatus{'inststatusguest'} = \@statuses;
19004: } else {
19005: push(@statuses,'default');
19006: }
19007: if (@statuses) {
19008: my %curr_rule;
19009: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
19010: foreach my $type (@statuses) {
19011: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 19012: }
1.305 raeburn 19013: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
19014: foreach my $type (@statuses) {
19015: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
19016: }
19017: }
19018: push(@{$cancreate{'selfcreate'}},'email');
19019: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
19020: my %curremaildom;
19021: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
19022: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
19023: }
19024: foreach my $type (@statuses) {
19025: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
19026: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
19027: }
19028: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
19029: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
19030: }
19031: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
19032: #
19033: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
19034: #
19035: my $chosen = $1;
19036: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
19037: my $emaildom;
19038: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 19039: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 19040: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
19041: if (ref($curremaildom{$type}) eq 'HASH') {
19042: if (exists($curremaildom{$type}{$chosen})) {
19043: if ($curremaildom{$type}{$chosen} ne $emaildom) {
19044: push(@{$changes{'cancreate'}},'emaildomain');
19045: }
19046: } elsif ($emaildom ne '') {
19047: push(@{$changes{'cancreate'}},'emaildomain');
19048: }
19049: } elsif ($emaildom ne '') {
19050: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 19051: }
1.305 raeburn 19052: }
19053: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19054: } elsif ($chosen eq 'custom') {
19055: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
19056: $email_rule{$type} = [];
19057: if (ref($emailrules) eq 'HASH') {
19058: foreach my $rule (@possemail_rules) {
19059: if (exists($emailrules->{$rule})) {
19060: push(@{$email_rule{$type}},$rule);
19061: }
19062: }
19063: }
19064: if (@{$email_rule{$type}}) {
19065: $cancreate{'emailoptions'}{$type} = 'custom';
19066: if (ref($curr_rule{$type}) eq 'ARRAY') {
19067: if (@{$curr_rule{$type}} > 0) {
19068: foreach my $rule (@{$curr_rule{$type}}) {
19069: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
19070: push(@{$changes{'email_rule'}},$type);
19071: }
19072: }
19073: }
19074: foreach my $type (@{$email_rule{$type}}) {
19075: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
19076: push(@{$changes{'email_rule'}},$type);
19077: }
19078: }
19079: } else {
19080: push(@{$changes{'email_rule'}},$type);
19081: }
19082: }
19083: } else {
19084: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19085: }
19086: }
19087: }
19088: if (@types) {
19089: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19090: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
19091: if (@changed) {
19092: push(@{$changes{'inststatus'}},'inststatusguest');
19093: }
19094: } else {
19095: push(@{$changes{'inststatus'}},'inststatusguest');
19096: }
19097: }
19098: } else {
19099: delete($env{'form.cancreate_email'});
19100: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19101: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19102: push(@{$changes{'inststatus'}},'inststatusguest');
19103: }
19104: }
19105: }
19106: } else {
19107: $save_inststatus{'inststatusguest'} = [];
19108: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19109: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19110: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 19111: }
19112: }
1.224 raeburn 19113: }
19114: } else {
19115: if ($env{'form.cancreate_'.$item}) {
19116: push(@{$cancreate{'selfcreate'}},$item);
19117: }
19118: }
19119: }
1.305 raeburn 19120: my (%userinfo,%savecaptcha);
1.224 raeburn 19121: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
19122: #
1.228 raeburn 19123: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
19124: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19125: #
1.236 raeburn 19126:
1.244 raeburn 19127: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19128: push(@contexts,'emailusername');
1.305 raeburn 19129: if (@statuses) {
19130: foreach my $type (@statuses) {
1.228 raeburn 19131: if (ref($infofields) eq 'ARRAY') {
19132: foreach my $field (@{$infofields}) {
19133: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19134: $cancreate{'emailusername'}{$type}{$field} = $1;
19135: }
19136: }
1.224 raeburn 19137: }
19138: }
19139: }
19140: #
19141: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19142: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19143: #
19144:
19145: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19146: @approvalnotify = sort(@approvalnotify);
19147: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19148: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19149: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19150: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19151: push(@{$changes{'cancreate'}},'notify');
19152: }
19153: } else {
19154: if ($cancreate{'notify'}{'approval'}) {
19155: push(@{$changes{'cancreate'}},'notify');
19156: }
19157: }
19158: } elsif ($cancreate{'notify'}{'approval'}) {
19159: push(@{$changes{'cancreate'}},'notify');
19160: }
19161:
19162: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19163: }
19164: #
1.236 raeburn 19165: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19166: # institutional log-in.
19167: #
19168: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19169: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19170: ($domdefaults{'auth_def'} eq 'localauth'))) {
19171: $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.').' '.
19172: &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.');
19173: }
19174: }
19175: my @fields = ('lastname','firstname','middlename','generation',
19176: 'permanentemail','id');
1.240 raeburn 19177: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19178: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19179: #
19180: # Where usernames may created for institutional log-in and/or institutional single sign on:
19181: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19182: # may self-create accounts
19183: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19184: # which the user may supply, if institutional data is unavailable.
19185: #
19186: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19187: if (@types) {
1.305 raeburn 19188: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19189: push(@contexts,'statustocreate');
1.303 raeburn 19190: foreach my $type (@types) {
1.224 raeburn 19191: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19192: foreach my $field (@fields) {
19193: if (grep(/^\Q$field\E$/,@modifiable)) {
19194: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19195: } else {
19196: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19197: }
19198: }
19199: }
19200: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19201: foreach my $type (@types) {
1.224 raeburn 19202: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19203: foreach my $field (@fields) {
19204: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19205: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19206: push(@{$changes{'selfcreate'}},$type);
19207: last;
19208: }
19209: }
19210: }
19211: }
19212: } else {
1.303 raeburn 19213: foreach my $type (@types) {
1.224 raeburn 19214: push(@{$changes{'selfcreate'}},$type);
19215: }
19216: }
19217: }
1.240 raeburn 19218: foreach my $field (@shibfields) {
19219: if ($env{'form.shibenv_'.$field} ne '') {
19220: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19221: }
19222: }
19223: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19224: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19225: foreach my $field (@shibfields) {
19226: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19227: push(@{$changes{'cancreate'}},'shibenv');
19228: }
19229: }
19230: } else {
19231: foreach my $field (@shibfields) {
19232: if ($env{'form.shibenv_'.$field}) {
19233: push(@{$changes{'cancreate'}},'shibenv');
19234: last;
19235: }
19236: }
19237: }
19238: }
1.224 raeburn 19239: }
19240: foreach my $item (@contexts) {
19241: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19242: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19243: if (ref($cancreate{$item}) eq 'ARRAY') {
19244: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19245: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19246: push(@{$changes{'cancreate'}},$item);
19247: }
19248: }
19249: }
19250: }
19251: if (ref($cancreate{$item}) eq 'ARRAY') {
19252: foreach my $type (@{$cancreate{$item}}) {
19253: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19254: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19255: push(@{$changes{'cancreate'}},$item);
19256: }
19257: }
19258: }
19259: }
19260: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19261: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19262: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19263: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19264: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19265: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19266: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19267: push(@{$changes{'cancreate'}},$item);
19268: }
19269: }
19270: }
1.305 raeburn 19271: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19272: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19273: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19274: push(@{$changes{'cancreate'}},$item);
19275: }
1.224 raeburn 19276: }
19277: }
19278: }
1.305 raeburn 19279: foreach my $type (keys(%{$cancreate{$item}})) {
19280: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19281: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19282: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19283: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19284: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19285: push(@{$changes{'cancreate'}},$item);
19286: }
19287: }
19288: } else {
19289: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19290: push(@{$changes{'cancreate'}},$item);
19291: }
19292: }
19293: }
1.305 raeburn 19294: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19295: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19296: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19297: push(@{$changes{'cancreate'}},$item);
19298: }
1.224 raeburn 19299: }
19300: }
19301: }
19302: }
19303: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19304: if (ref($cancreate{$item}) eq 'ARRAY') {
19305: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19306: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19307: push(@{$changes{'cancreate'}},$item);
19308: }
19309: }
1.305 raeburn 19310: }
19311: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19312: if (ref($cancreate{$item}) eq 'HASH') {
19313: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19314: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19315: }
19316: }
19317: } elsif ($item eq 'emailusername') {
1.228 raeburn 19318: if (ref($cancreate{$item}) eq 'HASH') {
19319: foreach my $type (keys(%{$cancreate{$item}})) {
19320: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19321: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19322: if ($cancreate{$item}{$type}{$field}) {
19323: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19324: push(@{$changes{'cancreate'}},$item);
19325: }
19326: last;
19327: }
19328: }
19329: }
19330: }
1.224 raeburn 19331: }
19332: }
19333: }
19334: #
19335: # Populate %save_usercreate hash with updates to self-creation configuration.
19336: #
19337: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19338: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19339: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19340: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19341: if (ref($cancreate{'notify'}) eq 'HASH') {
19342: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19343: }
1.236 raeburn 19344: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19345: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19346: }
1.303 raeburn 19347: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19348: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19349: }
1.305 raeburn 19350: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19351: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19352: }
1.303 raeburn 19353: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19354: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19355: }
1.224 raeburn 19356: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19357: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19358: }
1.240 raeburn 19359: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19360: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19361: }
1.224 raeburn 19362: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19363: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19364:
19365: my %userconfig_hash = (
19366: usercreation => \%save_usercreate,
19367: usermodification => \%save_usermodify,
1.305 raeburn 19368: inststatus => \%save_inststatus,
1.224 raeburn 19369: );
1.305 raeburn 19370:
1.224 raeburn 19371: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19372: $dom);
19373: #
1.305 raeburn 19374: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19375: #
1.27 raeburn 19376: if ($putresult eq 'ok') {
19377: if (keys(%changes) > 0) {
19378: $resulttext = &mt('Changes made:').'<ul>';
19379: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19380: my %lt = &selfcreation_types();
1.34 raeburn 19381: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19382: my $chgtext = '';
1.45 raeburn 19383: if ($type eq 'selfcreate') {
1.50 raeburn 19384: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19385: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19386: } else {
1.224 raeburn 19387: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19388: '<ul>';
1.50 raeburn 19389: foreach my $case (@{$cancreate{$type}}) {
19390: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19391: }
19392: $chgtext .= '</ul>';
1.100 raeburn 19393: if (ref($cancreate{$type}) eq 'ARRAY') {
19394: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19395: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19396: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19397: $chgtext .= '<span class="LC_warning">'.
19398: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19399: '</span><br />';
19400: }
19401: }
19402: }
19403: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19404: if (!@statuses) {
19405: $chgtext .= '<span class="LC_warning">'.
19406: &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.").
19407: '</span><br />';
1.303 raeburn 19408:
1.100 raeburn 19409: }
19410: }
19411: }
1.43 raeburn 19412: }
1.240 raeburn 19413: } elsif ($type eq 'shibenv') {
19414: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19415: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19416: } else {
19417: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19418: '<ul>';
19419: foreach my $field (@shibfields) {
19420: next if ($cancreate{$type}{$field} eq '');
19421: if ($field eq 'inststatus') {
19422: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19423: } else {
19424: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19425: }
19426: }
19427: $chgtext .= '</ul>';
1.303 raeburn 19428: }
1.93 raeburn 19429: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19430: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19431: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19432: if (@{$cancreate{'selfcreate'}} > 0) {
19433: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19434: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19435: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19436: $chgtext .= '<br />'.
19437: '<span class="LC_warning">'.
19438: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19439: '</span>';
19440: }
1.303 raeburn 19441: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19442: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19443: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19444: } else {
19445: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19446: }
19447: $chgtext .= '<ul>';
19448: foreach my $case (@{$cancreate{$type}}) {
19449: if ($case eq 'default') {
19450: $chgtext .= '<li>'.$othertitle.'</li>';
19451: } else {
1.303 raeburn 19452: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19453: }
19454: }
1.100 raeburn 19455: $chgtext .= '</ul>';
19456: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19457: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19458: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19459: '</span>';
1.100 raeburn 19460: }
19461: }
19462: } else {
19463: if (@{$cancreate{$type}} == 0) {
19464: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19465: } else {
19466: $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 19467: }
19468: }
1.303 raeburn 19469: $chgtext .= '<br />';
1.93 raeburn 19470: }
1.236 raeburn 19471: } elsif ($type eq 'selfcreateprocessing') {
19472: my %choices = &Apache::lonlocal::texthash (
19473: automatic => 'Automatic approval',
19474: approval => 'Queued for approval',
19475: );
1.305 raeburn 19476: if (@types) {
19477: if (@statuses) {
1.425 raeburn 19478: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19479: '<ul>';
1.305 raeburn 19480: foreach my $status (@statuses) {
19481: if ($status eq 'default') {
19482: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19483: } else {
1.305 raeburn 19484: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19485: }
19486: }
19487: $chgtext .= '</ul>';
19488: }
19489: } else {
19490: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19491: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19492: }
19493: } elsif ($type eq 'emailverified') {
19494: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19495: all => 'Same as e-mail',
19496: first => 'Omit @domain',
19497: free => 'Free to choose',
1.303 raeburn 19498: );
1.305 raeburn 19499: if (@types) {
19500: if (@statuses) {
1.303 raeburn 19501: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19502: '<ul>';
1.305 raeburn 19503: foreach my $status (@statuses) {
1.362 raeburn 19504: if ($status eq 'default') {
1.305 raeburn 19505: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19506: } else {
1.305 raeburn 19507: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19508: }
19509: }
19510: $chgtext .= '</ul>';
19511: }
19512: } else {
1.305 raeburn 19513: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19514: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19515: }
1.305 raeburn 19516: } elsif ($type eq 'emailoptions') {
19517: my %options = &Apache::lonlocal::texthash (
19518: any => 'Any e-mail',
19519: inst => 'Institutional only',
19520: noninst => 'Non-institutional only',
19521: custom => 'Custom restrictions',
19522: );
19523: if (@types) {
19524: if (@statuses) {
19525: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19526: '<ul>';
19527: foreach my $status (@statuses) {
19528: if ($type eq 'default') {
19529: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19530: } else {
19531: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19532: }
19533: }
1.305 raeburn 19534: $chgtext .= '</ul>';
19535: }
19536: } else {
19537: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19538: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19539: } else {
19540: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19541: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19542: }
1.305 raeburn 19543: }
19544: } elsif ($type eq 'emaildomain') {
19545: my $output;
19546: if (@statuses) {
19547: foreach my $type (@statuses) {
19548: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19549: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19550: if ($type eq 'default') {
19551: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19552: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19553: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19554: } else {
19555: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19556: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19557: }
1.303 raeburn 19558: } else {
1.305 raeburn 19559: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19560: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19561: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19562: } else {
19563: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19564: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19565: }
1.303 raeburn 19566: }
1.305 raeburn 19567: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19568: if ($type eq 'default') {
19569: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19570: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19571: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19572: } else {
19573: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19574: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19575: }
1.303 raeburn 19576: } else {
1.305 raeburn 19577: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19578: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19579: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19580: } else {
19581: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19582: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19583: }
1.303 raeburn 19584: }
19585: }
19586: }
19587: }
1.305 raeburn 19588: }
19589: if ($output ne '') {
19590: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19591: '<ul>'.$output.'</ul>';
1.236 raeburn 19592: }
1.165 raeburn 19593: } elsif ($type eq 'captcha') {
1.224 raeburn 19594: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19595: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19596: } else {
19597: my %captchas = &captcha_phrases();
1.224 raeburn 19598: if ($captchas{$savecaptcha{$type}}) {
19599: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19600: } else {
1.210 raeburn 19601: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19602: }
19603: }
19604: } elsif ($type eq 'recaptchakeys') {
19605: my ($privkey,$pubkey);
1.224 raeburn 19606: if (ref($savecaptcha{$type}) eq 'HASH') {
19607: $pubkey = $savecaptcha{$type}{'public'};
19608: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19609: }
19610: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19611: if (!$pubkey) {
19612: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19613: } else {
19614: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19615: }
19616: if (!$privkey) {
19617: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19618: } else {
19619: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19620: }
19621: $chgtext .= '</ul>';
1.269 raeburn 19622: } elsif ($type eq 'recaptchaversion') {
19623: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19624: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19625: }
1.224 raeburn 19626: } elsif ($type eq 'emailusername') {
19627: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19628: if (@statuses) {
19629: foreach my $type (@statuses) {
1.228 raeburn 19630: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19631: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19632: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19633: '<ul>';
19634: foreach my $field (@{$infofields}) {
19635: if ($cancreate{'emailusername'}{$type}{$field}) {
19636: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19637: }
19638: }
1.245 raeburn 19639: $chgtext .= '</ul>';
19640: } else {
1.303 raeburn 19641: $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 19642: }
19643: } else {
1.303 raeburn 19644: $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 19645: }
19646: }
19647: }
19648: }
19649: } elsif ($type eq 'notify') {
1.303 raeburn 19650: my $numapprove = 0;
1.224 raeburn 19651: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19652: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19653: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19654: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19655: $numapprove ++;
1.224 raeburn 19656: }
19657: }
1.43 raeburn 19658: }
1.303 raeburn 19659: unless ($numapprove) {
19660: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19661: }
1.34 raeburn 19662: }
1.224 raeburn 19663: if ($chgtext) {
19664: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19665: }
19666: }
19667: }
1.305 raeburn 19668: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19669: my ($emailrules,$emailruleorder) =
19670: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19671: foreach my $type (@{$changes{'email_rule'}}) {
19672: if (ref($email_rule{$type}) eq 'ARRAY') {
19673: my $chgtext = '<ul>';
19674: foreach my $rule (@{$email_rule{$type}}) {
19675: if (ref($emailrules->{$rule}) eq 'HASH') {
19676: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19677: }
19678: }
19679: $chgtext .= '</ul>';
1.310 raeburn 19680: my $typename;
1.305 raeburn 19681: if (@types) {
19682: if ($type eq 'default') {
19683: $typename = $othertitle;
19684: } else {
19685: $typename = $usertypes{$type};
1.425 raeburn 19686: }
1.305 raeburn 19687: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19688: }
19689: if (@{$email_rule{$type}} > 0) {
19690: $resulttext .= '<li>'.
19691: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19692: $usertypes{$type}).
19693: $chgtext.
19694: '</li>';
19695: } else {
19696: $resulttext .= '<li>'.
1.310 raeburn 19697: &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 19698: '</li>'.
1.310 raeburn 19699: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19700: }
1.43 raeburn 19701: }
19702: }
1.305 raeburn 19703: }
19704: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19705: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19706: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19707: my $chgtext = '<ul>';
19708: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19709: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19710: }
19711: $chgtext .= '</ul>';
19712: $resulttext .= '<li>'.
19713: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19714: $chgtext.
19715: '</li>';
19716: } else {
19717: $resulttext .= '<li>'.
19718: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19719: '</li>';
19720: }
1.43 raeburn 19721: }
19722: }
1.224 raeburn 19723: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19724: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19725: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19726: foreach my $type (@{$changes{'selfcreate'}}) {
19727: my $typename = $type;
1.303 raeburn 19728: if (keys(%usertypes) > 0) {
19729: if ($usertypes{$type} ne '') {
19730: $typename = $usertypes{$type};
1.224 raeburn 19731: }
19732: }
19733: my @modifiable;
19734: $resulttext .= '<li>'.
19735: &mt('Self-creation of account by users with status: [_1]',
19736: '<span class="LC_cusr_emph">'.$typename.'</span>').
19737: ' - '.&mt('modifiable fields (if institutional data blank): ');
19738: foreach my $field (@fields) {
19739: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19740: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19741: }
19742: }
1.224 raeburn 19743: if (@modifiable > 0) {
19744: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19745: } else {
1.224 raeburn 19746: $resulttext .= &mt('none');
1.43 raeburn 19747: }
1.224 raeburn 19748: $resulttext .= '</li>';
1.28 raeburn 19749: }
1.224 raeburn 19750: $resulttext .= '</ul></li>';
1.28 raeburn 19751: }
1.27 raeburn 19752: $resulttext .= '</ul>';
1.305 raeburn 19753: my $cachetime = 24*60*60;
19754: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19755: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19756: if (ref($lastactref) eq 'HASH') {
19757: $lastactref->{'domdefaults'} = 1;
19758: }
1.27 raeburn 19759: } else {
1.224 raeburn 19760: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19761: }
19762: } else {
19763: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19764: &mt('An error occurred: [_1]',$putresult).'</span>';
19765: }
1.43 raeburn 19766: if ($warningmsg ne '') {
19767: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19768: }
1.23 raeburn 19769: return $resulttext;
19770: }
19771:
1.165 raeburn 19772: sub process_captcha {
1.369 raeburn 19773: my ($container,$changes,$newsettings,$currsettings) = @_;
19774: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19775: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19776: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19777: $newsettings->{'captcha'} = 'original';
19778: }
1.369 raeburn 19779: my %current;
19780: if (ref($currsettings) eq 'HASH') {
19781: %current = %{$currsettings};
19782: }
19783: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19784: if ($container eq 'cancreate') {
1.169 raeburn 19785: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19786: push(@{$changes->{'cancreate'}},'captcha');
19787: } elsif (!defined($changes->{'cancreate'})) {
19788: $changes->{'cancreate'} = ['captcha'];
19789: }
1.368 raeburn 19790: } elsif ($container eq 'passwords') {
19791: $changes->{'reset'} = 1;
1.169 raeburn 19792: } else {
19793: $changes->{'captcha'} = 1;
1.165 raeburn 19794: }
19795: }
1.269 raeburn 19796: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19797: if ($newsettings->{'captcha'} eq 'recaptcha') {
19798: $newpub = $env{'form.'.$container.'_recaptchapub'};
19799: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19800: $newpub =~ s/[^\w\-]//g;
19801: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19802: $newsettings->{'recaptchakeys'} = {
19803: public => $newpub,
19804: private => $newpriv,
19805: };
1.269 raeburn 19806: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19807: $newversion =~ s/\D//g;
19808: if ($newversion ne '2') {
19809: $newversion = 1;
19810: }
19811: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19812: }
1.369 raeburn 19813: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19814: $currpub = $current{'recaptchakeys'}{'public'};
19815: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19816: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19817: $newsettings->{'recaptchakeys'} = {
19818: public => '',
19819: private => '',
19820: }
19821: }
1.165 raeburn 19822: }
1.369 raeburn 19823: if ($current{'captcha'} eq 'recaptcha') {
19824: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19825: if ($currversion ne '2') {
19826: $currversion = 1;
19827: }
19828: }
19829: if ($currversion ne $newversion) {
19830: if ($container eq 'cancreate') {
19831: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19832: push(@{$changes->{'cancreate'}},'recaptchaversion');
19833: } elsif (!defined($changes->{'cancreate'})) {
19834: $changes->{'cancreate'} = ['recaptchaversion'];
19835: }
1.368 raeburn 19836: } elsif ($container eq 'passwords') {
19837: $changes->{'reset'} = 1;
1.269 raeburn 19838: } else {
19839: $changes->{'recaptchaversion'} = 1;
19840: }
19841: }
1.165 raeburn 19842: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19843: if ($container eq 'cancreate') {
19844: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19845: push(@{$changes->{'cancreate'}},'recaptchakeys');
19846: } elsif (!defined($changes->{'cancreate'})) {
19847: $changes->{'cancreate'} = ['recaptchakeys'];
19848: }
1.368 raeburn 19849: } elsif ($container eq 'passwords') {
19850: $changes->{'reset'} = 1;
1.169 raeburn 19851: } else {
1.210 raeburn 19852: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19853: }
19854: }
19855: return;
19856: }
19857:
1.33 raeburn 19858: sub modify_usermodification {
19859: my ($dom,%domconfig) = @_;
1.224 raeburn 19860: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19861: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19862: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19863: if ($key eq 'selfcreate') {
19864: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19865: } else {
19866: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19867: }
1.33 raeburn 19868: }
19869: }
1.443 raeburn 19870: my @contexts = ('author','coauthor','course');
1.33 raeburn 19871: my %context_title = (
19872: author => 'In author context',
1.443 raeburn 19873: coauthor => 'As co-author manager',
1.33 raeburn 19874: course => 'In course context',
19875: );
19876: my @fields = ('lastname','firstname','middlename','generation',
19877: 'permanentemail','id');
19878: my %roles = (
19879: author => ['ca','aa'],
1.443 raeburn 19880: coauthor => ['ca','aa'],
1.33 raeburn 19881: course => ['st','ep','ta','in','cr'],
19882: );
19883: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19884: foreach my $context (@contexts) {
1.443 raeburn 19885: my $prefix = 'canmodify';
19886: if ($context eq 'coauthor') {
19887: $prefix = 'cacanmodify';
19888: }
1.33 raeburn 19889: foreach my $role (@{$roles{$context}}) {
1.443 raeburn 19890: my @modifiable = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$role);
1.33 raeburn 19891: foreach my $item (@fields) {
19892: if (grep(/^\Q$item\E$/,@modifiable)) {
19893: $modifyhash{$context}{$role}{$item} = 1;
19894: } else {
19895: $modifyhash{$context}{$role}{$item} = 0;
19896: }
19897: }
19898: }
19899: if (ref($curr_usermodification{$context}) eq 'HASH') {
19900: foreach my $role (@{$roles{$context}}) {
19901: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19902: foreach my $field (@fields) {
19903: if ($modifyhash{$context}{$role}{$field} ne
19904: $curr_usermodification{$context}{$role}{$field}) {
19905: push(@{$changes{$context}},$role);
19906: last;
19907: }
19908: }
19909: }
19910: }
19911: } else {
19912: foreach my $context (@contexts) {
19913: foreach my $role (@{$roles{$context}}) {
19914: push(@{$changes{$context}},$role);
19915: }
19916: }
19917: }
19918: }
19919: my %usermodification_hash = (
19920: usermodification => \%modifyhash,
19921: );
19922: my $putresult = &Apache::lonnet::put_dom('configuration',
19923: \%usermodification_hash,$dom);
19924: if ($putresult eq 'ok') {
19925: if (keys(%changes) > 0) {
19926: $resulttext = &mt('Changes made: ').'<ul>';
19927: foreach my $context (@contexts) {
19928: if (ref($changes{$context}) eq 'ARRAY') {
19929: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19930: if (ref($changes{$context}) eq 'ARRAY') {
19931: foreach my $role (@{$changes{$context}}) {
19932: my $rolename;
1.224 raeburn 19933: if ($role eq 'cr') {
19934: $rolename = &mt('Custom');
1.33 raeburn 19935: } else {
1.224 raeburn 19936: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19937: }
19938: my @modifiable;
1.224 raeburn 19939: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19940: foreach my $field (@fields) {
19941: if ($modifyhash{$context}{$role}{$field}) {
19942: push(@modifiable,$fieldtitles{$field});
19943: }
19944: }
19945: if (@modifiable > 0) {
19946: $resulttext .= join(', ',@modifiable);
19947: } else {
19948: $resulttext .= &mt('none');
19949: }
19950: $resulttext .= '</li>';
19951: }
19952: $resulttext .= '</ul></li>';
19953: }
19954: }
19955: }
19956: $resulttext .= '</ul>';
19957: } else {
19958: $resulttext = &mt('No changes made to user modification settings');
19959: }
19960: } else {
19961: $resulttext = '<span class="LC_error">'.
19962: &mt('An error occurred: [_1]',$putresult).'</span>';
19963: }
19964: return $resulttext;
19965: }
19966:
1.43 raeburn 19967: sub modify_defaults {
1.212 raeburn 19968: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19969: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19970: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19971: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19972: 'portal_def');
1.325 raeburn 19973: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19974: foreach my $item (@items) {
19975: $newvalues{$item} = $env{'form.'.$item};
19976: if ($item eq 'auth_def') {
19977: if ($newvalues{$item} ne '') {
19978: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19979: push(@errors,$item);
19980: }
19981: }
19982: } elsif ($item eq 'lang_def') {
19983: if ($newvalues{$item} ne '') {
19984: if ($newvalues{$item} =~ /^(\w+)/) {
19985: my $langcode = $1;
1.103 raeburn 19986: if ($langcode ne 'x_chef') {
19987: if (code2language($langcode) eq '') {
19988: push(@errors,$item);
19989: }
1.43 raeburn 19990: }
19991: } else {
19992: push(@errors,$item);
19993: }
19994: }
1.54 raeburn 19995: } elsif ($item eq 'timezone_def') {
19996: if ($newvalues{$item} ne '') {
1.62 raeburn 19997: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 19998: push(@errors,$item);
19999: }
20000: }
1.68 raeburn 20001: } elsif ($item eq 'datelocale_def') {
20002: if ($newvalues{$item} ne '') {
20003: my @datelocale_ids = DateTime::Locale->ids();
20004: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
20005: push(@errors,$item);
20006: }
20007: }
1.141 raeburn 20008: } elsif ($item eq 'portal_def') {
20009: if ($newvalues{$item} ne '') {
1.414 raeburn 20010: 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])\/?$/) {
20011: foreach my $field ('email','web') {
20012: if ($env{'form.'.$item.'_'.$field}) {
20013: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
20014: }
20015: }
20016: } else {
1.141 raeburn 20017: push(@errors,$item);
20018: }
20019: }
1.43 raeburn 20020: }
20021: if (grep(/^\Q$item\E$/,@errors)) {
20022: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 20023: if ($item eq 'portal_def') {
20024: if ($domdefaults{$item}) {
20025: foreach my $field ('email','web') {
20026: if (exists($domdefaults{$item.'_'.$field})) {
20027: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
20028: }
20029: }
20030: }
20031: }
1.43 raeburn 20032: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
20033: $changes{$item} = 1;
20034: }
1.414 raeburn 20035: if ($item eq 'portal_def') {
20036: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 20037: if ($newvalues{$item} eq '') {
1.414 raeburn 20038: foreach my $field ('email','web') {
20039: if (exists($domdefaults{$item.'_'.$field})) {
20040: delete($domdefaults{$item.'_'.$field});
20041: }
20042: }
20043: } else {
20044: unless ($changes{$item}) {
20045: foreach my $field ('email','web') {
20046: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
20047: $changes{$item} = 1;
20048: last;
20049: }
20050: }
20051: }
20052: foreach my $field ('email','web') {
20053: if ($newvalues{$item.'_'.$field}) {
20054: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
20055: } elsif (exists($domdefaults{$item.'_'.$field})) {
20056: delete($domdefaults{$item.'_'.$field});
20057: }
20058: }
20059: }
20060: }
20061: }
1.72 raeburn 20062: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 20063: }
1.354 raeburn 20064: my %staticdefaults = (
20065: 'intauth_cost' => 10,
20066: 'intauth_check' => 0,
20067: 'intauth_switch' => 0,
20068: );
20069: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
20070: if (exists($domdefaults{$item})) {
20071: $newvalues{$item} = $domdefaults{$item};
20072: } else {
20073: $newvalues{$item} = $staticdefaults{$item};
20074: }
20075: }
1.409 raeburn 20076: my ($unamemaprules,$ruleorder);
20077: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
20078: if (@possunamemaprules) {
20079: ($unamemaprules,$ruleorder) =
20080: &Apache::lonnet::inst_userrules($dom,'unamemap');
20081: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
20082: if (@{$ruleorder} > 0) {
20083: my %possrules;
20084: map { $possrules{$_} = 1; } @possunamemaprules;
20085: foreach my $rule (@{$ruleorder}) {
20086: if ($possrules{$rule}) {
20087: push(@{$newvalues{'unamemap_rule'}},$rule);
20088: }
20089: }
20090: }
20091: }
20092: }
20093: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
20094: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20095: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
20096: $newvalues{'unamemap_rule'});
20097: if (@rulediffs) {
20098: $changes{'unamemap_rule'} = 1;
20099: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20100: }
20101: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
20102: $changes{'unamemap_rule'} = 1;
20103: delete($domdefaults{'unamemap_rule'});
20104: }
20105: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20106: if (@{$newvalues{'unamemap_rule'}} > 0) {
20107: $changes{'unamemap_rule'} = 1;
20108: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20109: }
20110: }
1.43 raeburn 20111: my %defaults_hash = (
1.72 raeburn 20112: defaults => \%newvalues,
20113: );
1.43 raeburn 20114: my $title = &defaults_titles();
1.236 raeburn 20115:
20116: my $currinststatus;
20117: if (ref($domconfig{'inststatus'}) eq 'HASH') {
20118: $currinststatus = $domconfig{'inststatus'};
20119: } else {
20120: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
20121: $currinststatus = {
20122: inststatustypes => $usertypes,
20123: inststatusorder => $types,
20124: inststatusguest => [],
20125: };
20126: }
20127: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20128: my @allpos;
20129: my %alltypes;
1.305 raeburn 20130: my @inststatusguest;
20131: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20132: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20133: unless (grep(/^\Q$type\E$/,@todelete)) {
20134: push(@inststatusguest,$type);
20135: }
20136: }
20137: }
20138: my ($currtitles,$currorder);
1.236 raeburn 20139: if (ref($currinststatus) eq 'HASH') {
20140: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20141: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20142: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20143: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20144: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20145: }
20146: }
20147: unless (grep(/^\Q$type\E$/,@todelete)) {
20148: my $position = $env{'form.inststatus_pos_'.$type};
20149: $position =~ s/\D+//g;
20150: $allpos[$position] = $type;
20151: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20152: $alltypes{$type} =~ s/`//g;
20153: }
20154: }
20155: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20156: $currtitles =~ s/,$//;
20157: }
20158: }
20159: if ($env{'form.addinststatus'}) {
20160: my $newtype = $env{'form.addinststatus'};
20161: $newtype =~ s/\W//g;
20162: unless (exists($alltypes{$newtype})) {
20163: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20164: $alltypes{$newtype} =~ s/`//g;
20165: my $position = $env{'form.addinststatus_pos'};
20166: $position =~ s/\D+//g;
20167: if ($position ne '') {
20168: $allpos[$position] = $newtype;
20169: }
20170: }
20171: }
1.305 raeburn 20172: my @orderedstatus;
1.236 raeburn 20173: foreach my $type (@allpos) {
20174: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20175: push(@orderedstatus,$type);
20176: }
20177: }
20178: foreach my $type (keys(%alltypes)) {
20179: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20180: delete($alltypes{$type});
20181: }
20182: }
20183: $defaults_hash{'inststatus'} = {
20184: inststatustypes => \%alltypes,
20185: inststatusorder => \@orderedstatus,
1.305 raeburn 20186: inststatusguest => \@inststatusguest,
1.236 raeburn 20187: };
20188: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20189: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20190: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20191: }
20192: }
20193: if ($currorder ne join(',',@orderedstatus)) {
20194: $changes{'inststatus'}{'inststatusorder'} = 1;
20195: }
20196: my $newtitles;
20197: foreach my $item (@orderedstatus) {
20198: $newtitles .= $alltypes{$item}.',';
20199: }
20200: $newtitles =~ s/,$//;
20201: if ($currtitles ne $newtitles) {
20202: $changes{'inststatus'}{'inststatustypes'} = 1;
20203: }
1.43 raeburn 20204: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20205: $dom);
20206: if ($putresult eq 'ok') {
20207: if (keys(%changes) > 0) {
20208: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20209: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20210: 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";
20211: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20212: if ($item eq 'inststatus') {
20213: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20214: if (@orderedstatus) {
1.236 raeburn 20215: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20216: foreach my $type (@orderedstatus) {
20217: $resulttext .= $alltypes{$type}.', ';
20218: }
20219: $resulttext =~ s/, $//;
20220: $resulttext .= '</li>';
1.305 raeburn 20221: } else {
1.425 raeburn 20222: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20223: }
20224: }
1.409 raeburn 20225: } elsif ($item eq 'unamemap_rule') {
20226: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20227: my @rulenames;
20228: if (ref($unamemaprules) eq 'HASH') {
20229: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20230: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20231: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20232: }
20233: }
20234: }
20235: if (@rulenames) {
20236: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20237: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20238: '</li>';
20239: } else {
20240: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20241: }
20242: } else {
20243: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20244: }
1.236 raeburn 20245: } else {
20246: my $value = $env{'form.'.$item};
20247: if ($value eq '') {
20248: $value = &mt('none');
20249: } elsif ($item eq 'auth_def') {
20250: my %authnames = &authtype_names();
20251: my %shortauth = (
20252: internal => 'int',
20253: krb4 => 'krb4',
20254: krb5 => 'krb5',
20255: localauth => 'loc',
1.325 raeburn 20256: lti => 'lti',
1.236 raeburn 20257: );
20258: $value = $authnames{$shortauth{$value}};
20259: }
20260: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20261: $mailmsgtext .= "$title->{$item} set to $value\n";
20262: if ($item eq 'portal_def') {
20263: if ($env{'form.'.$item} ne '') {
20264: foreach my $field ('email','web') {
20265: $value = $env{'form.'.$item.'_'.$field};
20266: if ($value) {
20267: $value = &mt('Yes');
20268: } else {
20269: $value = &mt('No');
20270: }
20271: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20272: }
20273: }
20274: }
1.43 raeburn 20275: }
20276: }
20277: $resulttext .= '</ul>';
20278: $mailmsgtext .= "\n";
20279: my $cachetime = 24*60*60;
1.72 raeburn 20280: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20281: if (ref($lastactref) eq 'HASH') {
20282: $lastactref->{'domdefaults'} = 1;
20283: }
1.68 raeburn 20284: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20285: my $notify = 1;
20286: if (ref($domconfig{'contacts'}) eq 'HASH') {
20287: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20288: $notify = 0;
20289: }
20290: }
20291: if ($notify) {
20292: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20293: "LON-CAPA Domain Settings Change - $dom",
20294: $mailmsgtext);
20295: }
1.54 raeburn 20296: }
1.43 raeburn 20297: } else {
1.54 raeburn 20298: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20299: }
20300: } else {
20301: $resulttext = '<span class="LC_error">'.
20302: &mt('An error occurred: [_1]',$putresult).'</span>';
20303: }
20304: if (@errors > 0) {
20305: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20306: foreach my $item (@errors) {
20307: $resulttext .= ' "'.$title->{$item}.'",';
20308: }
20309: $resulttext =~ s/,$//;
20310: }
20311: return $resulttext;
20312: }
20313:
1.46 raeburn 20314: sub modify_scantron {
1.205 raeburn 20315: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20316: my ($resulttext,%confhash,%changes,$errors);
20317: my $custom = 'custom.tab';
20318: my $default = 'default.tab';
20319: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20320: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20321: &config_check($dom,$confname,$servadm);
20322: if ($env{'form.scantronformat.filename'} ne '') {
20323: my $error;
20324: if ($configuserok eq 'ok') {
20325: if ($switchserver) {
1.130 raeburn 20326: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20327: } else {
20328: if ($author_ok eq 'ok') {
1.421 raeburn 20329: my $modified = [];
1.46 raeburn 20330: my ($result,$scantronurl) =
1.421 raeburn 20331: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20332: $confname,'scantron','','',$custom,
20333: $modified);
1.46 raeburn 20334: if ($result eq 'ok') {
20335: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20336: $changes{'scantronformat'} = 1;
1.421 raeburn 20337: &update_modify_urls($r,$modified);
1.46 raeburn 20338: } else {
20339: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20340: }
20341: } else {
20342: $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);
20343: }
20344: }
20345: } else {
20346: $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);
20347: }
20348: if ($error) {
20349: &Apache::lonnet::logthis($error);
20350: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20351: }
20352: }
1.48 raeburn 20353: if (ref($domconfig{'scantron'}) eq 'HASH') {
20354: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20355: if ($env{'form.scantronformat_del'}) {
20356: $confhash{'scantron'}{'scantronformat'} = '';
20357: $changes{'scantronformat'} = 1;
1.347 raeburn 20358: } else {
20359: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20360: }
20361: }
20362: }
1.347 raeburn 20363: my @options = ('hdr','pad','rem');
1.346 raeburn 20364: my @fields = &scantroncsv_fields();
20365: my %titles = &scantronconfig_titles();
1.347 raeburn 20366: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20367: my ($newdat,$currdat,%newcol,%currcol);
20368: if (grep(/^dat$/,@formats)) {
20369: $confhash{'scantron'}{config}{dat} = 1;
20370: $newdat = 1;
20371: } else {
20372: $newdat = 0;
20373: }
20374: if (grep(/^csv$/,@formats)) {
20375: my %bynum;
20376: foreach my $field (@fields) {
20377: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20378: my $posscol = $1;
20379: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20380: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20381: $bynum{$posscol} = $field;
20382: $newcol{$field} = $posscol;
20383: }
20384: }
20385: }
1.347 raeburn 20386: if (keys(%newcol)) {
20387: foreach my $option (@options) {
20388: if ($env{'form.scantroncsv_'.$option}) {
20389: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20390: }
20391: }
20392: }
1.346 raeburn 20393: }
20394: $currdat = 1;
20395: if (ref($domconfig{'scantron'}) eq 'HASH') {
20396: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20397: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20398: $currdat = 0;
20399: }
20400: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20401: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20402: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20403: }
1.346 raeburn 20404: }
20405: }
20406: }
20407: if ($currdat != $newdat) {
20408: $changes{'config'} = 1;
20409: } else {
20410: foreach my $field (@fields) {
20411: if ($currcol{$field} ne '') {
20412: if ($currcol{$field} ne $newcol{$field}) {
20413: $changes{'config'} = 1;
20414: last;
1.347 raeburn 20415: }
1.346 raeburn 20416: } elsif ($newcol{$field} ne '') {
20417: $changes{'config'} = 1;
20418: last;
20419: }
20420: }
20421: }
1.46 raeburn 20422: if (keys(%confhash) > 0) {
20423: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20424: $dom);
20425: if ($putresult eq 'ok') {
20426: if (keys(%changes) > 0) {
1.48 raeburn 20427: if (ref($confhash{'scantron'}) eq 'HASH') {
20428: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20429: if ($changes{'scantronformat'}) {
20430: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20431: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20432: } else {
20433: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20434: }
20435: }
1.347 raeburn 20436: if ($changes{'config'}) {
1.346 raeburn 20437: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20438: if ($confhash{'scantron'}{'config'}{'dat'}) {
20439: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20440: }
20441: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20442: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20443: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20444: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20445: foreach my $field (@fields) {
20446: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20447: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20448: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20449: }
20450: }
20451: $resulttext .= '</ul></li>';
20452: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20453: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20454: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20455: foreach my $option (@options) {
20456: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20457: $resulttext .= '<li>'.$titles{$option}.'</li>';
20458: }
20459: }
20460: $resulttext .= '</ul></li>';
20461: }
1.346 raeburn 20462: }
20463: }
20464: }
20465: }
20466: } else {
20467: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20468: }
1.46 raeburn 20469: }
1.48 raeburn 20470: $resulttext .= '</ul>';
20471: } else {
1.130 raeburn 20472: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20473: }
20474: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20475: if (ref($lastactref) eq 'HASH') {
20476: $lastactref->{'domainconfig'} = 1;
20477: }
1.46 raeburn 20478: } else {
1.346 raeburn 20479: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20480: }
20481: } else {
20482: $resulttext = '<span class="LC_error">'.
20483: &mt('An error occurred: [_1]',$putresult).'</span>';
20484: }
20485: } else {
1.130 raeburn 20486: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20487: }
20488: if ($errors) {
1.353 raeburn 20489: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20490: $errors.'</ul></p>';
1.46 raeburn 20491: }
20492: return $resulttext;
20493: }
20494:
1.48 raeburn 20495: sub modify_coursecategories {
1.239 raeburn 20496: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20497: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20498: $cathash);
1.48 raeburn 20499: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20500: my @catitems = ('unauth','auth');
20501: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20502: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20503: $cathash = $domconfig{'coursecategories'}{'cats'};
20504: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20505: $changes{'togglecats'} = 1;
20506: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20507: }
20508: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20509: $changes{'categorize'} = 1;
20510: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20511: }
1.120 raeburn 20512: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20513: $changes{'togglecatscomm'} = 1;
20514: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20515: }
20516: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20517: $changes{'categorizecomm'} = 1;
20518: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20519:
20520: }
20521: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20522: $changes{'togglecatsplace'} = 1;
20523: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20524: }
20525: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20526: $changes{'categorizeplace'} = 1;
20527: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20528: }
1.238 raeburn 20529: foreach my $item (@catitems) {
20530: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20531: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20532: $changes{$item} = 1;
20533: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20534: }
20535: }
20536: }
1.57 raeburn 20537: } else {
20538: $changes{'togglecats'} = 1;
20539: $changes{'categorize'} = 1;
1.124 raeburn 20540: $changes{'togglecatscomm'} = 1;
20541: $changes{'categorizecomm'} = 1;
1.272 raeburn 20542: $changes{'togglecatsplace'} = 1;
20543: $changes{'categorizeplace'} = 1;
1.87 raeburn 20544: $domconfig{'coursecategories'} = {
20545: togglecats => $env{'form.togglecats'},
20546: categorize => $env{'form.categorize'},
1.124 raeburn 20547: togglecatscomm => $env{'form.togglecatscomm'},
20548: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20549: togglecatsplace => $env{'form.togglecatsplace'},
20550: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20551: };
1.238 raeburn 20552: foreach my $item (@catitems) {
20553: if ($env{'form.coursecat_'.$item} ne 'std') {
20554: $changes{$item} = 1;
20555: }
20556: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20557: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20558: }
20559: }
1.57 raeburn 20560: }
20561: if (ref($cathash) eq 'HASH') {
20562: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20563: push (@deletecategory,'instcode::0');
20564: }
1.120 raeburn 20565: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20566: push(@deletecategory,'communities::0');
20567: }
1.272 raeburn 20568: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20569: push(@deletecategory,'placement::0');
20570: }
1.48 raeburn 20571: }
1.57 raeburn 20572: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20573: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20574: if (@deletecategory > 0) {
20575: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20576: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20577: foreach my $item (@deletecategory) {
1.57 raeburn 20578: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20579: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20580: $deletions{$item} = 1;
1.57 raeburn 20581: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20582: }
20583: }
20584: }
1.57 raeburn 20585: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20586: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20587: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20588: $reorderings{$item} = 1;
1.57 raeburn 20589: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20590: }
20591: if ($env{'form.addcategory_name_'.$item} ne '') {
20592: my $newcat = $env{'form.addcategory_name_'.$item};
20593: my $newdepth = $depth+1;
20594: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20595: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20596: $adds{$newitem} = 1;
20597: }
20598: if ($env{'form.subcat_'.$item} ne '') {
20599: my $newcat = $env{'form.subcat_'.$item};
20600: my $newdepth = $depth+1;
20601: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20602: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20603: $adds{$newitem} = 1;
20604: }
20605: }
20606: }
20607: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20608: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20609: my $newitem = 'instcode::0';
1.57 raeburn 20610: if ($cathash->{$newitem} eq '') {
20611: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20612: $adds{$newitem} = 1;
20613: }
20614: } else {
20615: my $newitem = 'instcode::0';
1.57 raeburn 20616: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20617: $adds{$newitem} = 1;
20618: }
20619: }
1.120 raeburn 20620: if ($env{'form.communities'} eq '1') {
20621: if (ref($cathash) eq 'HASH') {
20622: my $newitem = 'communities::0';
20623: if ($cathash->{$newitem} eq '') {
20624: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20625: $adds{$newitem} = 1;
20626: }
20627: } else {
20628: my $newitem = 'communities::0';
20629: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20630: $adds{$newitem} = 1;
20631: }
20632: }
1.272 raeburn 20633: if ($env{'form.placement'} eq '1') {
20634: if (ref($cathash) eq 'HASH') {
20635: my $newitem = 'placement::0';
20636: if ($cathash->{$newitem} eq '') {
20637: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20638: $adds{$newitem} = 1;
20639: }
20640: } else {
20641: my $newitem = 'placement::0';
20642: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20643: $adds{$newitem} = 1;
20644: }
20645: }
1.48 raeburn 20646: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20647: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20648: ($env{'form.addcategory_name'} ne 'communities') &&
20649: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20650: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20651: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20652: $adds{$newitem} = 1;
20653: }
1.48 raeburn 20654: }
1.57 raeburn 20655: my $putresult;
1.48 raeburn 20656: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20657: if (keys(%deletions) > 0) {
20658: foreach my $key (keys(%deletions)) {
20659: if ($predelallitems{$key} ne '') {
20660: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20661: }
20662: }
20663: }
20664: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20665: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20666: if (ref($chkcats[0]) eq 'ARRAY') {
20667: my $depth = 0;
20668: my $chg = 0;
20669: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20670: my $name = $chkcats[0][$i];
20671: my $item;
20672: if ($name eq '') {
20673: $chg ++;
20674: } else {
20675: $item = &escape($name).'::0';
20676: if ($chg) {
1.57 raeburn 20677: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20678: }
20679: $depth ++;
1.57 raeburn 20680: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20681: $depth --;
20682: }
20683: }
20684: }
1.57 raeburn 20685: }
20686: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20687: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20688: if ($putresult eq 'ok') {
1.57 raeburn 20689: my %title = (
1.120 raeburn 20690: togglecats => 'Show/Hide a course in catalog',
20691: categorize => 'Assign a category to a course',
20692: togglecatscomm => 'Show/Hide a community in catalog',
20693: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20694: );
20695: my %level = (
1.120 raeburn 20696: dom => 'set in Domain ("Modify Course/Community")',
20697: crs => 'set in Course ("Course Configuration")',
20698: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20699: none => 'No catalog',
20700: std => 'Standard catalog',
20701: domonly => 'Domain-only catalog',
20702: codesrch => 'Code search form',
1.57 raeburn 20703: );
1.48 raeburn 20704: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20705: if ($changes{'togglecats'}) {
20706: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20707: }
20708: if ($changes{'categorize'}) {
20709: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20710: }
1.120 raeburn 20711: if ($changes{'togglecatscomm'}) {
20712: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20713: }
20714: if ($changes{'categorizecomm'}) {
20715: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20716: }
1.238 raeburn 20717: if ($changes{'unauth'}) {
20718: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20719: }
20720: if ($changes{'auth'}) {
20721: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20722: }
1.57 raeburn 20723: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20724: my $cathash;
20725: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20726: $cathash = $domconfig{'coursecategories'}{'cats'};
20727: } else {
20728: $cathash = {};
20729: }
20730: my (@cats,@trails,%allitems);
20731: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20732: if (keys(%deletions) > 0) {
20733: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20734: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20735: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20736: }
20737: $resulttext .= '</ul></li>';
20738: }
20739: if (keys(%reorderings) > 0) {
20740: my %sort_by_trail;
20741: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20742: foreach my $key (keys(%reorderings)) {
20743: if ($allitems{$key} ne '') {
20744: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20745: }
1.48 raeburn 20746: }
1.57 raeburn 20747: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20748: $resulttext .= '<li>'.$trails[$trail].'</li>';
20749: }
20750: $resulttext .= '</ul></li>';
1.48 raeburn 20751: }
1.57 raeburn 20752: if (keys(%adds) > 0) {
20753: my %sort_by_trail;
20754: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20755: foreach my $key (keys(%adds)) {
20756: if ($allitems{$key} ne '') {
20757: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20758: }
20759: }
20760: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20761: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20762: }
1.57 raeburn 20763: $resulttext .= '</ul></li>';
1.48 raeburn 20764: }
1.364 raeburn 20765: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20766: if (ref($lastactref) eq 'HASH') {
20767: $lastactref->{'cats'} = 1;
20768: }
1.48 raeburn 20769: }
20770: $resulttext .= '</ul>';
1.239 raeburn 20771: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20772: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20773: if ($changes{'auth'}) {
20774: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20775: }
20776: if ($changes{'unauth'}) {
20777: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20778: }
20779: my $cachetime = 24*60*60;
20780: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20781: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20782: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20783: }
20784: }
1.48 raeburn 20785: } else {
20786: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20787: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20788: }
20789: } else {
1.120 raeburn 20790: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20791: }
20792: return $resulttext;
20793: }
20794:
1.69 raeburn 20795: sub modify_serverstatuses {
20796: my ($dom,%domconfig) = @_;
20797: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20798: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20799: %currserverstatus = %{$domconfig{'serverstatuses'}};
20800: }
20801: my @pages = &serverstatus_pages();
20802: foreach my $type (@pages) {
20803: $newserverstatus{$type}{'namedusers'} = '';
20804: $newserverstatus{$type}{'machines'} = '';
20805: if (defined($env{'form.'.$type.'_namedusers'})) {
20806: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20807: my @okusers;
20808: foreach my $user (@users) {
20809: my ($uname,$udom) = split(/:/,$user);
20810: if (($udom =~ /^$match_domain$/) &&
20811: (&Apache::lonnet::domain($udom)) &&
20812: ($uname =~ /^$match_username$/)) {
20813: if (!grep(/^\Q$user\E/,@okusers)) {
20814: push(@okusers,$user);
20815: }
20816: }
20817: }
20818: if (@okusers > 0) {
20819: @okusers = sort(@okusers);
20820: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20821: }
20822: }
20823: if (defined($env{'form.'.$type.'_machines'})) {
20824: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20825: my @okmachines;
20826: foreach my $ip (@machines) {
20827: my @parts = split(/\./,$ip);
20828: next if (@parts < 4);
20829: my $badip = 0;
20830: for (my $i=0; $i<4; $i++) {
20831: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20832: $badip = 1;
20833: last;
20834: }
20835: }
20836: if (!$badip) {
20837: push(@okmachines,$ip);
20838: }
20839: }
20840: @okmachines = sort(@okmachines);
20841: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20842: }
20843: }
20844: my %serverstatushash = (
20845: serverstatuses => \%newserverstatus,
20846: );
20847: foreach my $type (@pages) {
1.83 raeburn 20848: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20849: my (@current,@new);
1.83 raeburn 20850: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20851: if ($currserverstatus{$type}{$setting} ne '') {
20852: @current = split(/,/,$currserverstatus{$type}{$setting});
20853: }
20854: }
20855: if ($newserverstatus{$type}{$setting} ne '') {
20856: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20857: }
20858: if (@current > 0) {
20859: if (@new > 0) {
20860: foreach my $item (@current) {
20861: if (!grep(/^\Q$item\E$/,@new)) {
20862: $changes{$type}{$setting} = 1;
1.82 raeburn 20863: last;
20864: }
20865: }
1.84 raeburn 20866: foreach my $item (@new) {
20867: if (!grep(/^\Q$item\E$/,@current)) {
20868: $changes{$type}{$setting} = 1;
20869: last;
1.82 raeburn 20870: }
20871: }
20872: } else {
1.83 raeburn 20873: $changes{$type}{$setting} = 1;
1.69 raeburn 20874: }
1.83 raeburn 20875: } elsif (@new > 0) {
20876: $changes{$type}{$setting} = 1;
1.69 raeburn 20877: }
20878: }
20879: }
20880: if (keys(%changes) > 0) {
1.81 raeburn 20881: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20882: my $putresult = &Apache::lonnet::put_dom('configuration',
20883: \%serverstatushash,$dom);
20884: if ($putresult eq 'ok') {
20885: $resulttext .= &mt('Changes made:').'<ul>';
20886: foreach my $type (@pages) {
1.84 raeburn 20887: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20888: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20889: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20890: if ($newserverstatus{$type}{'namedusers'} eq '') {
20891: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20892: } else {
20893: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20894: }
1.84 raeburn 20895: }
20896: if ($changes{$type}{'machines'}) {
1.69 raeburn 20897: if ($newserverstatus{$type}{'machines'} eq '') {
20898: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20899: } else {
20900: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20901: }
20902:
20903: }
20904: $resulttext .= '</ul></li>';
20905: }
20906: }
20907: $resulttext .= '</ul>';
20908: } else {
20909: $resulttext = '<span class="LC_error">'.
20910: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20911:
20912: }
20913: } else {
20914: $resulttext = &mt('No changes made to access to server status pages');
20915: }
20916: return $resulttext;
20917: }
20918:
1.118 jms 20919: sub modify_helpsettings {
1.285 raeburn 20920: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20921: my ($resulttext,$errors,%changes,%helphash);
20922: my %defaultchecked = ('submitbugs' => 'on');
20923: my @offon = ('off','on');
1.118 jms 20924: my @toggles = ('submitbugs');
1.285 raeburn 20925: my %current = ('submitbugs' => '',
20926: 'adhoc' => {},
20927: );
1.118 jms 20928: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20929: %current = %{$domconfig{'helpsettings'}};
20930: }
1.285 raeburn 20931: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20932: foreach my $item (@toggles) {
20933: if ($defaultchecked{$item} eq 'on') {
20934: if ($current{$item} eq '') {
20935: if ($env{'form.'.$item} eq '0') {
20936: $changes{$item} = 1;
20937: }
20938: } elsif ($current{$item} ne $env{'form.'.$item}) {
20939: $changes{$item} = 1;
20940: }
20941: } elsif ($defaultchecked{$item} eq 'off') {
20942: if ($current{$item} eq '') {
20943: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20944: $changes{$item} = 1;
20945: }
1.282 raeburn 20946: } elsif ($current{$item} ne $env{'form.'.$item}) {
20947: $changes{$item} = 1;
20948: }
20949: }
20950: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20951: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20952: }
20953: }
1.285 raeburn 20954: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20955: my $confname = $dom.'-domainconfig';
20956: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20957: my (@allpos,%newsettings,%changedprivs,$newrole);
20958: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20959: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20960: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20961: my %lt = &Apache::lonlocal::texthash(
20962: s => 'system',
20963: d => 'domain',
20964: order => 'Display order',
20965: access => 'Role usage',
1.291 raeburn 20966: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20967: dh => 'All with domain helpdesk role',
20968: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20969: none => 'None',
20970: status => 'Determined based on institutional status',
20971: inc => 'Include all, but exclude specific personnel',
20972: exc => 'Exclude all, but include specific personnel',
20973: );
20974: for (my $num=0; $num<=$maxnum; $num++) {
20975: my ($prefix,$identifier,$rolename,%curr);
20976: if ($num == $maxnum) {
20977: next unless ($env{'form.newcusthelp'} == $maxnum);
20978: $identifier = 'custhelp'.$num;
20979: $prefix = 'helproles_'.$num;
20980: $rolename = $env{'form.custhelpname'.$num};
20981: $rolename=~s/[^A-Za-z0-9]//gs;
20982: next if ($rolename eq '');
20983: next if (exists($existing{'rolesdef_'.$rolename}));
20984: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20985: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20986: $newprivs{'c'},$confname,$dom);
20987: if ($result ne 'ok') {
20988: $errors .= '<li><span class="LC_error">'.
20989: &mt('An error occurred storing the new custom role: [_1]',
20990: $result).'</span></li>';
20991: next;
20992: } else {
20993: $changedprivs{$rolename} = \%newprivs;
20994: $newrole = $rolename;
20995: }
20996: } else {
20997: $prefix = 'helproles_'.$num;
20998: $rolename = $env{'form.'.$prefix};
20999: next if ($rolename eq '');
21000: next unless (exists($existing{'rolesdef_'.$rolename}));
21001: $identifier = 'custhelp'.$num;
21002: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21003: my %currprivs;
1.289 raeburn 21004: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 21005: split(/\_/,$existing{'rolesdef_'.$rolename});
21006: foreach my $level ('c','d','s') {
21007: if ($newprivs{$level} ne $currprivs{$level}) {
21008: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21009: $newprivs{'c'},$confname,$dom);
21010: if ($result ne 'ok') {
21011: $errors .= '<li><span class="LC_error">'.
21012: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
21013: $rolename,$result).'</span></li>';
21014: } else {
21015: $changedprivs{$rolename} = \%newprivs;
21016: }
21017: last;
21018: }
21019: }
21020: if (ref($current{'adhoc'}) eq 'HASH') {
21021: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21022: %curr = %{$current{'adhoc'}{$rolename}};
21023: }
21024: }
21025: }
21026: my $newpos = $env{'form.'.$prefix.'_pos'};
21027: $newpos =~ s/\D+//g;
21028: $allpos[$newpos] = $rolename;
21029: my $newdesc = $env{'form.'.$prefix.'_desc'};
21030: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
21031: if ($curr{'desc'}) {
21032: if ($curr{'desc'} ne $newdesc) {
21033: $changes{'customrole'}{$rolename}{'desc'} = 1;
21034: $newsettings{$rolename}{'desc'} = $newdesc;
21035: }
21036: } elsif ($newdesc ne '') {
21037: $changes{'customrole'}{$rolename}{'desc'} = 1;
21038: $newsettings{$rolename}{'desc'} = $newdesc;
21039: }
21040: my $access = $env{'form.'.$prefix.'_access'};
21041: if (grep(/^\Q$access\E$/,@accesstypes)) {
21042: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
21043: if ($access eq 'status') {
21044: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
21045: if (scalar(@statuses) == 0) {
1.289 raeburn 21046: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 21047: } else {
21048: my (@shownstatus,$numtypes);
21049: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21050: if (ref($types) eq 'ARRAY') {
21051: $numtypes = scalar(@{$types});
21052: foreach my $type (sort(@statuses)) {
21053: if ($type eq 'default') {
21054: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21055: } elsif (grep(/^\Q$type\E$/,@{$types})) {
21056: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21057: push(@shownstatus,$usertypes->{$type});
21058: }
21059: }
21060: }
21061: if (grep(/^default$/,@statuses)) {
21062: push(@shownstatus,$othertitle);
21063: }
21064: if (scalar(@shownstatus) == 1+$numtypes) {
21065: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
21066: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
21067: } else {
21068: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
21069: if (ref($curr{'status'}) eq 'ARRAY') {
21070: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21071: if (@diffs) {
21072: $changes{'customrole'}{$rolename}{$access} = 1;
21073: }
21074: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21075: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 21076: }
1.166 raeburn 21077: }
21078: }
1.285 raeburn 21079: } elsif (($access eq 'inc') || ($access eq 'exc')) {
21080: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
21081: my @newspecstaff;
21082: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21083: foreach my $person (sort(@personnel)) {
21084: if ($domhelpdesk{$person}) {
21085: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
21086: }
21087: }
21088: if (ref($curr{$access}) eq 'ARRAY') {
21089: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21090: if (@diffs) {
21091: $changes{'customrole'}{$rolename}{$access} = 1;
21092: }
21093: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21094: $changes{'customrole'}{$rolename}{$access} = 1;
21095: }
21096: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21097: my ($uname,$udom) = split(/:/,$person);
21098: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
21099: }
21100: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 21101: }
1.285 raeburn 21102: } else {
21103: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
21104: }
21105: unless ($curr{'access'} eq $access) {
21106: $changes{'customrole'}{$rolename}{'access'} = 1;
21107: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 21108: }
21109: }
1.285 raeburn 21110: if (@allpos > 0) {
21111: my $idx = 0;
21112: foreach my $rolename (@allpos) {
21113: if ($rolename ne '') {
21114: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
21115: if (ref($current{'adhoc'}) eq 'HASH') {
21116: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21117: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
21118: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 21119: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 21120: }
21121: }
1.282 raeburn 21122: }
1.285 raeburn 21123: $idx ++;
1.166 raeburn 21124: }
21125: }
1.118 jms 21126: }
1.123 jms 21127: my $putresult;
21128: if (keys(%changes) > 0) {
1.166 raeburn 21129: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21130: if ($putresult eq 'ok') {
1.285 raeburn 21131: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21132: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21133: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21134: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21135: }
21136: }
21137: my $cachetime = 24*60*60;
21138: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21139: if (ref($lastactref) eq 'HASH') {
21140: $lastactref->{'domdefaults'} = 1;
21141: }
21142: } else {
21143: $errors .= '<li><span class="LC_error">'.
21144: &mt('An error occurred storing the settings: [_1]',
21145: $putresult).'</span></li>';
21146: }
21147: }
21148: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21149: $resulttext = &mt('Changes made:').'<ul>';
21150: my (%shownprivs,@levelorder);
21151: @levelorder = ('c','d','s');
21152: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21153: foreach my $item (sort(keys(%changes))) {
21154: if ($item eq 'submitbugs') {
21155: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21156: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21157: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21158: } elsif ($item eq 'customrole') {
21159: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21160: my @keyorder = ('order','desc','access','status','exc','inc');
21161: my %keytext = &Apache::lonlocal::texthash(
21162: order => 'Order',
21163: desc => 'Role description',
21164: access => 'Role usage',
1.300 droeschl 21165: status => 'Allowed institutional types',
1.285 raeburn 21166: exc => 'Allowed personnel',
21167: inc => 'Disallowed personnel',
21168: );
1.282 raeburn 21169: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21170: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21171: if ($role eq $newrole) {
21172: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21173: $role).'<ul>';
21174: } else {
21175: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21176: $role).'<ul>';
21177: }
21178: foreach my $key (@keyorder) {
21179: if ($changes{'customrole'}{$role}{$key}) {
21180: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21181: $keytext{$key},$newsettings{$role}{$key}).
21182: '</li>';
21183: }
21184: }
21185: if (ref($changedprivs{$role}) eq 'HASH') {
21186: $shownprivs{$role} = 1;
21187: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21188: foreach my $level (@levelorder) {
21189: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21190: next if ($item eq '');
21191: my ($priv) = split(/\&/,$item,2);
21192: if (&Apache::lonnet::plaintext($priv)) {
21193: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21194: unless ($level eq 'c') {
21195: $resulttext .= ' ('.$lt{$level}.')';
21196: }
21197: $resulttext .= '</li>';
21198: }
21199: }
21200: }
21201: $resulttext .= '</ul>';
21202: }
21203: $resulttext .= '</ul></li>';
21204: }
21205: }
21206: }
21207: }
21208: }
21209: }
21210: if (keys(%changedprivs)) {
21211: foreach my $role (sort(keys(%changedprivs))) {
21212: unless ($shownprivs{$role}) {
21213: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21214: $role).'<ul>'.
21215: '<li>'.&mt('Privileges set to :').'<ul>';
21216: foreach my $level (@levelorder) {
21217: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21218: next if ($item eq '');
21219: my ($priv) = split(/\&/,$item,2);
21220: if (&Apache::lonnet::plaintext($priv)) {
21221: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21222: unless ($level eq 'c') {
21223: $resulttext .= ' ('.$lt{$level}.')';
21224: }
21225: $resulttext .= '</li>';
21226: }
1.282 raeburn 21227: }
21228: }
1.285 raeburn 21229: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21230: }
21231: }
21232: }
1.285 raeburn 21233: $resulttext .= '</ul>';
21234: } else {
21235: $resulttext = &mt('No changes made to help settings');
1.118 jms 21236: }
21237: if ($errors) {
1.168 raeburn 21238: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21239: $errors.'</ul>';
1.118 jms 21240: }
21241: return $resulttext;
21242: }
21243:
1.121 raeburn 21244: sub modify_coursedefaults {
1.212 raeburn 21245: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21246: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21247: my %defaultchecked = (
21248: 'canuse_pdfforms' => 'off',
21249: 'uselcmath' => 'on',
1.398 raeburn 21250: 'usejsme' => 'on',
21251: 'inline_chem' => 'on',
1.404 raeburn 21252: 'ltiauth' => 'off',
1.257 raeburn 21253: );
1.404 raeburn 21254: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21255: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21256: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21257: 'coursequota_official','coursequota_unofficial','coursequota_community',
21258: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21259: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21260: 'mysqltables_placement');
1.271 raeburn 21261: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21262: my %staticdefaults = (
21263: anonsurvey_threshold => 10,
21264: uploadquota => 500,
1.428 raeburn 21265: coursequota => 20,
1.257 raeburn 21266: postsubmit => 60,
1.276 raeburn 21267: mysqltables => 172800,
1.422 raeburn 21268: domexttool => 1,
1.432 raeburn 21269: crsauthor => 1,
1.438 raeburn 21270: crseditors => ['edit','xml'],
1.198 raeburn 21271: );
1.314 raeburn 21272: my %texoptions = (
21273: MathJax => 'MathJax',
21274: mimetex => &mt('Convert to Images'),
21275: tth => &mt('TeX to HTML'),
21276: );
1.438 raeburn 21277:
21278: my @editors = ('edit','xml','daxe');
21279: my %editornames = &crseditor_titles();
21280:
1.121 raeburn 21281: $defaultshash{'coursedefaults'} = {};
21282:
21283: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21284: if ($domconfig{'coursedefaults'} eq '') {
21285: $domconfig{'coursedefaults'} = {};
21286: }
21287: }
21288:
21289: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21290: foreach my $item (@toggles) {
21291: if ($defaultchecked{$item} eq 'on') {
21292: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21293: ($env{'form.'.$item} eq '0')) {
21294: $changes{$item} = 1;
1.192 raeburn 21295: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21296: $changes{$item} = 1;
21297: }
21298: } elsif ($defaultchecked{$item} eq 'off') {
21299: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21300: ($env{'form.'.$item} eq '1')) {
21301: $changes{$item} = 1;
21302: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21303: $changes{$item} = 1;
21304: }
21305: }
21306: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21307: }
1.198 raeburn 21308: foreach my $item (@numbers) {
21309: my ($currdef,$newdef);
1.208 raeburn 21310: $newdef = $env{'form.'.$item};
1.198 raeburn 21311: if ($item eq 'anonsurvey_threshold') {
21312: $currdef = $domconfig{'coursedefaults'}{$item};
21313: $newdef =~ s/\D//g;
21314: if ($newdef eq '' || $newdef < 1) {
21315: $newdef = 1;
21316: }
21317: $defaultshash{'coursedefaults'}{$item} = $newdef;
21318: } else {
1.428 raeburn 21319: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21320: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21321: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21322: }
21323: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21324: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21325: }
21326: if ($currdef ne $newdef) {
21327: if ($item eq 'anonsurvey_threshold') {
21328: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21329: $changes{$item} = 1;
21330: }
1.428 raeburn 21331: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21332: my $setting = $1;
1.276 raeburn 21333: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21334: $changes{$setting} = 1;
1.198 raeburn 21335: }
21336: }
1.139 raeburn 21337: }
21338: }
1.314 raeburn 21339: my $texengine;
21340: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21341: $texengine = $env{'form.texengine'};
1.349 raeburn 21342: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21343: if ($currdef eq '') {
21344: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21345: $changes{'texengine'} = 1;
21346: }
1.349 raeburn 21347: } elsif ($currdef ne $texengine) {
1.314 raeburn 21348: $changes{'texengine'} = 1;
21349: }
21350: }
21351: if ($texengine ne '') {
21352: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21353: }
1.264 raeburn 21354: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21355: my @currclonecode;
21356: if (ref($currclone) eq 'HASH') {
21357: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21358: @currclonecode = @{$currclone->{'instcode'}};
21359: }
21360: }
21361: my $newclone;
1.289 raeburn 21362: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21363: $newclone = $env{'form.canclone'};
21364: }
21365: if ($newclone eq 'instcode') {
21366: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21367: my (%codedefaults,@code_order,@clonecode);
21368: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21369: \@code_order);
21370: foreach my $item (@code_order) {
21371: if (grep(/^\Q$item\E$/,@newcodes)) {
21372: push(@clonecode,$item);
21373: }
21374: }
21375: if (@clonecode) {
21376: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21377: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21378: if (@diffs) {
21379: $changes{'canclone'} = 1;
21380: }
21381: } else {
21382: $newclone eq '';
21383: }
21384: } elsif ($newclone ne '') {
1.289 raeburn 21385: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21386: }
1.264 raeburn 21387: if ($newclone ne $currclone) {
21388: $changes{'canclone'} = 1;
21389: }
1.257 raeburn 21390: my %credits;
21391: foreach my $type (@types) {
21392: unless ($type eq 'community') {
21393: $credits{$type} = $env{'form.'.$type.'_credits'};
21394: $credits{$type} =~ s/[^\d.]+//g;
21395: }
21396: }
21397: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21398: ($env{'form.coursecredits'} eq '1')) {
21399: $changes{'coursecredits'} = 1;
21400: foreach my $type (keys(%credits)) {
21401: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21402: }
21403: } else {
1.289 raeburn 21404: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21405: foreach my $type (@types) {
21406: unless ($type eq 'community') {
1.289 raeburn 21407: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21408: $changes{'coursecredits'} = 1;
21409: }
21410: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21411: }
21412: }
21413: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21414: foreach my $type (@types) {
21415: unless ($type eq 'community') {
21416: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21417: $changes{'coursecredits'} = 1;
21418: last;
21419: }
21420: }
21421: }
21422: }
21423: }
21424: if ($env{'form.postsubmit'} eq '1') {
21425: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21426: my %currtimeout;
21427: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21428: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21429: $changes{'postsubmit'} = 1;
21430: }
21431: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21432: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21433: }
21434: } else {
21435: $changes{'postsubmit'} = 1;
21436: }
21437: foreach my $type (@types) {
21438: my $timeout = $env{'form.'.$type.'_timeout'};
21439: $timeout =~ s/\D//g;
21440: if ($timeout == $staticdefaults{'postsubmit'}) {
21441: $timeout = '';
21442: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21443: $timeout = '0';
21444: }
21445: unless ($timeout eq '') {
21446: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21447: }
21448: if (exists($currtimeout{$type})) {
21449: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21450: $changes{'postsubmit'} = 1;
1.257 raeburn 21451: }
21452: } elsif ($timeout ne '') {
21453: $changes{'postsubmit'} = 1;
21454: }
21455: }
21456: } else {
21457: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21458: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21459: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21460: $changes{'postsubmit'} = 1;
21461: }
21462: } else {
21463: $changes{'postsubmit'} = 1;
21464: }
1.192 raeburn 21465: }
1.438 raeburn 21466: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor,
21467: %posscrseditors);
1.422 raeburn 21468: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21469: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 raeburn 21470: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.438 raeburn 21471: map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
1.422 raeburn 21472: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21473: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21474: } else {
21475: foreach my $type (@types) {
21476: if ($staticdefaults{'domexttool'}) {
21477: $olddomexttool{$type} = 1;
21478: } else {
21479: $olddomexttool{$type} = 0;
21480: }
21481: }
21482: }
21483: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21484: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21485: } else {
21486: foreach my $type (@types) {
21487: if ($staticdefaults{'exttool'}) {
21488: $oldexttool{$type} = 1;
21489: } else {
21490: $oldexttool{$type} = 0;
21491: }
21492: }
21493: }
1.432 raeburn 21494: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21495: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
21496: } else {
21497: foreach my $type (@types) {
21498: if ($staticdefaults{'crsauthor'}) {
21499: $oldcrsauthor{$type} = 1;
21500: } else {
21501: $oldcrsauthor{$type} = 0;
21502: }
21503: }
21504: }
1.438 raeburn 21505: my @newcrseditors = ();
21506: foreach my $editor (@editors) {
21507: if ($posscrseditors{$editor}) {
21508: push(@newcrseditors,$editor);
21509: }
21510: }
21511: if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21512: my @diffs =
21513: &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
21514: \@newcrseditors);
21515: if (@diffs) {
21516: $changes{'crseditors'} = 1;
21517: }
21518: } else {
21519: my @diffs =
21520: &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
21521: \@newcrseditors);
21522: unless (@diffs == 0) {
21523: $changes{'crseditors'} = 1;
21524: }
21525: }
1.422 raeburn 21526: foreach my $type (@types) {
21527: unless ($newdomexttool{$type}) {
21528: $newdomexttool{$type} = 0;
21529: }
21530: unless ($newexttool{$type}) {
21531: $newexttool{$type} = 0;
21532: }
1.432 raeburn 21533: unless ($newcrsauthor{$type}) {
21534: $newcrsauthor{$type} = 0;
21535: }
1.422 raeburn 21536: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21537: $changes{'domexttool'} = 1;
21538: }
21539: if ($newexttool{$type} != $oldexttool{$type}) {
21540: $changes{'exttool'} = 1;
21541: }
1.432 raeburn 21542: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
21543: $changes{'crsauthor'} = 1;
21544: }
1.422 raeburn 21545: }
21546: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21547: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 raeburn 21548: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.438 raeburn 21549: $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 21550: }
21551: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21552: $dom);
21553: if ($putresult eq 'ok') {
21554: if (keys(%changes) > 0) {
1.213 raeburn 21555: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21556: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21557: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21558: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21559: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 raeburn 21560: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21561: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21562: 'ltiauth') {
1.257 raeburn 21563: if ($changes{$item}) {
21564: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21565: }
1.289 raeburn 21566: }
1.192 raeburn 21567: if ($changes{'coursecredits'}) {
21568: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21569: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21570: $domdefaults{$type.'credits'} =
21571: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21572: }
21573: }
21574: }
21575: if ($changes{'postsubmit'}) {
21576: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21577: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21578: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21579: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21580: $domdefaults{$type.'postsubtimeout'} =
21581: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21582: }
21583: }
1.192 raeburn 21584: }
21585: }
1.198 raeburn 21586: if ($changes{'uploadquota'}) {
21587: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21588: foreach my $type (@types) {
21589: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21590: }
21591: }
21592: }
1.428 raeburn 21593: if ($changes{'coursequota'}) {
21594: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21595: foreach my $type (@types) {
21596: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21597: }
21598: }
21599: }
1.264 raeburn 21600: if ($changes{'canclone'}) {
21601: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21602: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21603: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21604: if (@clonecodes) {
21605: $domdefaults{'canclone'} = join('+',@clonecodes);
21606: }
21607: }
21608: } else {
21609: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21610: }
21611: }
1.422 raeburn 21612: if ($changes{'domexttool'}) {
21613: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21614: foreach my $type (@types) {
21615: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21616: }
21617: }
21618: }
21619: if ($changes{'exttool'}) {
21620: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21621: foreach my $type (@types) {
21622: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21623: }
21624: }
21625: }
1.432 raeburn 21626: if ($changes{'crsauthor'}) {
21627: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21628: foreach my $type (@types) {
21629: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
21630: }
21631: }
21632: }
1.438 raeburn 21633: if ($changes{'crseditors'}) {
21634: if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21635: $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
21636: }
21637: }
1.121 raeburn 21638: my $cachetime = 24*60*60;
21639: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21640: if (ref($lastactref) eq 'HASH') {
21641: $lastactref->{'domdefaults'} = 1;
21642: }
1.121 raeburn 21643: }
21644: $resulttext = &mt('Changes made:').'<ul>';
21645: foreach my $item (sort(keys(%changes))) {
21646: if ($item eq 'canuse_pdfforms') {
21647: if ($env{'form.'.$item} eq '1') {
21648: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21649: } else {
21650: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21651: }
1.257 raeburn 21652: } elsif ($item eq 'uselcmath') {
21653: if ($env{'form.'.$item} eq '1') {
21654: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21655: } else {
21656: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21657: }
21658: } elsif ($item eq 'usejsme') {
21659: if ($env{'form.'.$item} eq '1') {
21660: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21661: } else {
1.289 raeburn 21662: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21663: }
1.398 raeburn 21664: } elsif ($item eq 'inline_chem') {
21665: if ($env{'form.'.$item} eq '1') {
21666: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21667: } else {
21668: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21669: }
1.314 raeburn 21670: } elsif ($item eq 'texengine') {
21671: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21672: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21673: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21674: }
1.139 raeburn 21675: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21676: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21677: } elsif ($item eq 'uploadquota') {
21678: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21679: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21680: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21681: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21682: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21683: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21684: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21685: '</ul>'.
21686: '</li>';
21687: } else {
21688: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21689: }
1.428 raeburn 21690: } elsif ($item eq 'coursequota') {
21691: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21692: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21693: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21694: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21695: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21696: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21697: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21698: '</ul>'.
21699: '</li>';
21700: } else {
21701: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21702: }
1.276 raeburn 21703: } elsif ($item eq 'mysqltables') {
21704: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21705: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21706: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21707: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21708: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21709: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21710: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21711: '</ul>'.
21712: '</li>';
21713: } else {
21714: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21715: }
1.257 raeburn 21716: } elsif ($item eq 'postsubmit') {
21717: if ($domdefaults{'postsubmit'} eq 'off') {
21718: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21719: } else {
21720: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21721: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21722: $resulttext .= &mt('durations:').'<ul>';
21723: foreach my $type (@types) {
21724: $resulttext .= '<li>';
21725: my $timeout;
21726: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21727: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21728: }
21729: my $display;
21730: if ($timeout eq '0') {
21731: $display = &mt('unlimited');
21732: } elsif ($timeout eq '') {
21733: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21734: } else {
21735: $display = &mt('[quant,_1,second]',$timeout);
21736: }
21737: if ($type eq 'community') {
21738: $resulttext .= &mt('Communities');
21739: } elsif ($type eq 'official') {
21740: $resulttext .= &mt('Official courses');
21741: } elsif ($type eq 'unofficial') {
21742: $resulttext .= &mt('Unofficial courses');
21743: } elsif ($type eq 'textbook') {
21744: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21745: } elsif ($type eq 'placement') {
21746: $resulttext .= &mt('Placement tests');
1.257 raeburn 21747: }
21748: $resulttext .= ' -- '.$display.'</li>';
21749: }
21750: $resulttext .= '</ul>';
21751: }
1.289 raeburn 21752: $resulttext .= '</li>';
1.257 raeburn 21753: }
1.192 raeburn 21754: } elsif ($item eq 'coursecredits') {
21755: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21756: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21757: ($domdefaults{'unofficialcredits'} eq '') &&
21758: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21759: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21760: } else {
21761: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21762: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21763: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21764: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21765: '</ul>'.
21766: '</li>';
21767: }
21768: } else {
21769: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21770: }
1.264 raeburn 21771: } elsif ($item eq 'canclone') {
21772: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21773: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21774: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21775: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21776: }
21777: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21778: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21779: } else {
1.289 raeburn 21780: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21781: }
1.404 raeburn 21782: } elsif ($item eq 'ltiauth') {
21783: if ($env{'form.'.$item} eq '1') {
21784: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21785: } else {
21786: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21787: }
1.432 raeburn 21788: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21789: my @noyes = (&mt('no'),&mt('yes'));
1.432 raeburn 21790: my %status = (
21791: domexttool => {
21792: ishash => &mt('External Tools defined in the domain may be used as follows:'),
21793: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
21794: },
21795: exttool => {
21796: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
21797: default => &mt('External Tools can not be defined in any course types, by default'),
21798: },
21799: crsauthor => {
21800: ishash => &mt('Standard Problems can be created within course containers as follows:'),
21801: default => &mt('Standard Problems can be created within any course type, by default'),
21802: },
21803: );
21804:
21805: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
21806: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
21807: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
21808: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
21809: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
21810: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
21811: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21812: '</ul>'.
21813: '</li>';
21814: } else {
1.432 raeburn 21815: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21816: }
1.438 raeburn 21817: } elsif ($item eq 'crseditors') {
21818: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
21819: my $shown;
21820: if (@{$defaultshash{'coursedefaults'}{$item}}) {
21821: $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
21822: } else {
21823: $shown = &mt('None');
21824: }
21825: $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
21826: }
1.140 raeburn 21827: }
1.121 raeburn 21828: }
21829: $resulttext .= '</ul>';
21830: } else {
21831: $resulttext = &mt('No changes made to course defaults');
21832: }
21833: } else {
21834: $resulttext = '<span class="LC_error">'.
21835: &mt('An error occurred: [_1]',$putresult).'</span>';
21836: }
21837: return $resulttext;
21838: }
21839:
1.231 raeburn 21840: sub modify_selfenrollment {
21841: my ($dom,$lastactref,%domconfig) = @_;
21842: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21843: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21844: my %titles = &tool_titles();
1.232 raeburn 21845: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21846: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21847: $ordered{'default'} = ['types','registered','approval','limit'];
21848:
21849: my (%roles,%shown,%toplevel);
21850: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21851:
21852: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21853: if ($domconfig{'selfenrollment'} eq '') {
21854: $domconfig{'selfenrollment'} = {};
21855: }
21856: }
21857: %toplevel = (
21858: admin => 'Configuration Rights',
21859: default => 'Default settings',
21860: validation => 'Validation of self-enrollment requests',
21861: );
1.233 raeburn 21862: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21863:
21864: if (ref($ordered{'admin'}) eq 'ARRAY') {
21865: foreach my $item (@{$ordered{'admin'}}) {
21866: foreach my $type (@types) {
21867: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21868: $selfenrollhash{'admin'}{$type}{$item} = 1;
21869: } else {
21870: $selfenrollhash{'admin'}{$type}{$item} = 0;
21871: }
21872: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21873: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21874: if ($selfenrollhash{'admin'}{$type}{$item} ne
21875: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21876: push(@{$changes{'admin'}{$type}},$item);
21877: }
21878: } else {
21879: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21880: push(@{$changes{'admin'}{$type}},$item);
21881: }
21882: }
21883: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21884: push(@{$changes{'admin'}{$type}},$item);
21885: }
21886: }
21887: }
21888: }
21889:
21890: foreach my $item (@{$ordered{'default'}}) {
21891: foreach my $type (@types) {
21892: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21893: if ($item eq 'types') {
21894: unless (($value eq 'all') || ($value eq 'dom')) {
21895: $value = '';
21896: }
21897: } elsif ($item eq 'registered') {
21898: unless ($value eq '1') {
21899: $value = 0;
21900: }
21901: } elsif ($item eq 'approval') {
21902: unless ($value =~ /^[012]$/) {
21903: $value = 0;
21904: }
21905: } else {
21906: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21907: $value = 'none';
21908: }
21909: }
21910: $selfenrollhash{'default'}{$type}{$item} = $value;
21911: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21912: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21913: if ($selfenrollhash{'default'}{$type}{$item} ne
21914: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21915: push(@{$changes{'default'}{$type}},$item);
21916: }
21917: } else {
21918: push(@{$changes{'default'}{$type}},$item);
21919: }
21920: } else {
21921: push(@{$changes{'default'}{$type}},$item);
21922: }
21923: if ($item eq 'limit') {
21924: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21925: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21926: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21927: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21928: }
21929: } else {
21930: $selfenrollhash{'default'}{$type}{'cap'} = '';
21931: }
21932: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21933: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21934: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21935: push(@{$changes{'default'}{$type}},'cap');
21936: }
21937: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21938: push(@{$changes{'default'}{$type}},'cap');
21939: }
21940: }
21941: }
21942: }
21943:
21944: foreach my $item (@{$itemsref}) {
21945: if ($item eq 'fields') {
21946: my @changed;
21947: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21948: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21949: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21950: }
21951: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21952: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21953: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21954: $domconfig{'selfenrollment'}{'validation'}{$item});
21955: } else {
21956: @changed = @{$selfenrollhash{'validation'}{$item}};
21957: }
21958: } else {
21959: @changed = @{$selfenrollhash{'validation'}{$item}};
21960: }
21961: if (@changed) {
21962: if ($selfenrollhash{'validation'}{$item}) {
21963: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21964: } else {
21965: $changes{'validation'}{$item} = &mt('None');
21966: }
21967: }
21968: } else {
21969: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21970: if ($item eq 'markup') {
21971: if ($env{'form.selfenroll_validation_'.$item}) {
21972: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21973: }
21974: }
21975: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21976: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21977: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21978: }
21979: }
21980: }
21981: }
21982:
21983: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21984: $dom);
21985: if ($putresult eq 'ok') {
21986: if (keys(%changes) > 0) {
21987: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21988: $resulttext = &mt('Changes made:').'<ul>';
21989: foreach my $key ('admin','default','validation') {
21990: if (ref($changes{$key}) eq 'HASH') {
21991: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
21992: if ($key eq 'validation') {
21993: foreach my $item (@{$itemsref}) {
21994: if (exists($changes{$key}{$item})) {
21995: if ($item eq 'markup') {
21996: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21997: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
21998: } else {
21999: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22000: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
22001: }
22002: }
22003: }
22004: } else {
22005: foreach my $type (@types) {
22006: if ($type eq 'community') {
22007: $roles{'1'} = &mt('Community personnel');
22008: } else {
22009: $roles{'1'} = &mt('Course personnel');
22010: }
22011: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 22012: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22013: if ($key eq 'admin') {
22014: my @mgrdc = ();
22015: if (ref($ordered{$key}) eq 'ARRAY') {
22016: foreach my $item (@{$ordered{'admin'}}) {
22017: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22018: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
22019: push(@mgrdc,$item);
22020: }
22021: }
22022: }
22023: if (@mgrdc) {
22024: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
22025: } else {
22026: delete($domdefaults{$type.'selfenrolladmdc'});
22027: }
22028: }
22029: } else {
22030: if (ref($ordered{$key}) eq 'ARRAY') {
22031: foreach my $item (@{$ordered{$key}}) {
22032: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22033: $domdefaults{$type.'selfenroll'.$item} =
22034: $selfenrollhash{$key}{$type}{$item};
22035: }
22036: }
22037: }
22038: }
22039: }
1.231 raeburn 22040: $resulttext .= '<li>'.$titles{$type}.'<ul>';
22041: foreach my $item (@{$ordered{$key}}) {
22042: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22043: $resulttext .= '<li>';
22044: if ($key eq 'admin') {
22045: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
22046: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
22047: } else {
22048: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
22049: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
22050: }
22051: $resulttext .= '</li>';
22052: }
22053: }
22054: $resulttext .= '</ul></li>';
22055: }
22056: }
22057: $resulttext .= '</ul></li>';
22058: }
22059: }
1.305 raeburn 22060: }
22061: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
22062: my $cachetime = 24*60*60;
22063: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22064: if (ref($lastactref) eq 'HASH') {
22065: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 22066: }
1.231 raeburn 22067: }
22068: $resulttext .= '</ul>';
22069: } else {
22070: $resulttext = &mt('No changes made to self-enrollment settings');
22071: }
22072: } else {
22073: $resulttext = '<span class="LC_error">'.
22074: &mt('An error occurred: [_1]',$putresult).'</span>';
22075: }
22076: return $resulttext;
22077: }
22078:
1.373 raeburn 22079: sub modify_wafproxy {
22080: my ($dom,$action,$lastactref,%domconfig) = @_;
22081: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 22082: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
22083: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 22084: foreach my $server (sort(keys(%servers))) {
22085: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
22086: if ($serverhome eq $server) {
22087: my $serverdom = &Apache::lonnet::host_domain($server);
22088: if ($serverdom eq $dom) {
22089: $canset{$server} = 1;
22090: }
22091: }
22092: }
1.381 raeburn 22093: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
22094: %{$values{$dom}} = ();
22095: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
22096: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
22097: }
1.388 raeburn 22098: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
22099: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
22100: }
1.382 raeburn 22101: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 22102: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
22103: }
22104: }
1.373 raeburn 22105: my $output;
22106: if (keys(%canset)) {
22107: %{$wafproxy{'alias'}} = ();
1.388 raeburn 22108: %{$wafproxy{'saml'}} = ();
1.373 raeburn 22109: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 22110: if ($env{'form.wafproxy_'.$dom}) {
22111: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
22112: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
22113: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
22114: $changes{'alias'} = 1;
22115: }
1.388 raeburn 22116: if ($env{'form.wafproxy_alias_saml_'.$key}) {
22117: $wafproxy{'saml'}{$key} = 1;
22118: }
22119: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
22120: $changes{'saml'} = 1;
22121: }
1.381 raeburn 22122: } else {
22123: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 22124: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 22125: if ($curralias{$key}) {
22126: $changes{'alias'} = 1;
22127: }
1.388 raeburn 22128: if ($currsaml{$key}) {
22129: $changes{'saml'} = 1;
22130: }
1.373 raeburn 22131: }
22132: if ($wafproxy{'alias'}{$key} eq '') {
22133: if ($curralias{$key}) {
22134: $expirecache{$key} = 1;
22135: }
22136: delete($wafproxy{'alias'}{$key});
22137: }
1.388 raeburn 22138: if ($wafproxy{'saml'}{$key} eq '') {
22139: if ($currsaml{$key}) {
22140: $expiresaml{$key} = 1;
22141: }
22142: delete($wafproxy{'saml'}{$key});
22143: }
1.373 raeburn 22144: }
22145: unless (keys(%{$wafproxy{'alias'}})) {
22146: delete($wafproxy{'alias'});
22147: }
1.388 raeburn 22148: unless (keys(%{$wafproxy{'saml'}})) {
22149: delete($wafproxy{'saml'});
22150: }
22151: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 22152: my %warn = (
22153: trusted => 'trusted IP range(s)',
1.381 raeburn 22154: vpnint => 'internal IP range(s) for VPN sessions(s)',
22155: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 22156: );
1.382 raeburn 22157: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22158: my $possible = $env{'form.wafproxy_'.$item};
22159: $possible =~ s/^\s+|\s+$//g;
22160: if ($possible ne '') {
1.381 raeburn 22161: if ($item eq 'remoteip') {
22162: if ($possible =~ /^[mhn]$/) {
22163: $wafproxy{$item} = $possible;
22164: }
22165: } elsif ($item eq 'ipheader') {
22166: if ($wafproxy{'remoteip'} eq 'h') {
22167: $wafproxy{$item} = $possible;
22168: }
1.382 raeburn 22169: } elsif ($item eq 'sslopt') {
22170: if ($possible =~ /^0|1$/) {
22171: $wafproxy{$item} = $possible;
22172: }
1.373 raeburn 22173: } else {
22174: my (@ok,$count);
1.381 raeburn 22175: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
22176: unless ($env{'form.wafproxy_vpnaccess'}) {
22177: $possible = '';
22178: }
22179: } elsif ($item eq 'trusted') {
22180: unless ($wafproxy{'remoteip'} eq 'h') {
22181: $possible = '';
22182: }
22183: }
22184: unless ($possible eq '') {
22185: $possible =~ s/[\r\n]+/\s/g;
22186: $possible =~ s/\s*-\s*/-/g;
22187: $possible =~ s/\s+/,/g;
1.393 raeburn 22188: $possible =~ s/,+/,/g;
1.381 raeburn 22189: }
1.373 raeburn 22190: $count = 0;
1.381 raeburn 22191: if ($possible ne '') {
1.373 raeburn 22192: foreach my $poss (split(/\,/,$possible)) {
22193: $count ++;
1.393 raeburn 22194: $poss = &validate_ip_pattern($poss);
22195: if ($poss ne '') {
1.373 raeburn 22196: push(@ok,$poss);
22197: }
22198: }
22199: my $diff = $count - scalar(@ok);
22200: if ($diff) {
22201: push(@warnings,'<li>'.
22202: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
22203: $diff,$warn{$item}).
22204: '</li>');
22205: }
1.393 raeburn 22206: if (@ok) {
22207: my @cidr_list;
22208: foreach my $item (@ok) {
22209: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
22210: }
22211: $wafproxy{$item} = join(',',@cidr_list);
22212: }
1.373 raeburn 22213: }
22214: }
1.381 raeburn 22215: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 22216: $changes{$item} = 1;
22217: }
1.381 raeburn 22218: } elsif ($currvalue{$item}) {
22219: $changes{$item} = 1;
1.425 raeburn 22220: }
1.381 raeburn 22221: }
22222: } else {
22223: if (keys(%curralias)) {
22224: $changes{'alias'} = 1;
1.388 raeburn 22225: }
22226: if (keys(%currsaml)) {
22227: $changes{'saml'} = 1;
1.425 raeburn 22228: }
1.381 raeburn 22229: if (keys(%currvalue)) {
22230: foreach my $key (keys(%currvalue)) {
22231: $changes{$key} = 1;
1.373 raeburn 22232: }
22233: }
22234: }
22235: if (keys(%changes)) {
22236: my %defaultshash = (
22237: wafproxy => \%wafproxy,
1.425 raeburn 22238: );
1.373 raeburn 22239: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22240: $dom);
22241: if ($putresult eq 'ok') {
22242: my $cachetime = 24*60*60;
22243: my (%domdefaults,$updatedomdefs);
1.382 raeburn 22244: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22245: if ($changes{$item}) {
22246: unless ($updatedomdefs) {
22247: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
22248: $updatedomdefs = 1;
22249: }
22250: if ($wafproxy{$item}) {
22251: $domdefaults{'waf_'.$item} = $wafproxy{$item};
22252: } elsif (exists($domdefaults{'waf_'.$item})) {
22253: delete($domdefaults{'waf_'.$item});
1.425 raeburn 22254: }
1.373 raeburn 22255: }
22256: }
22257: if ($updatedomdefs) {
22258: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22259: if (ref($lastactref) eq 'HASH') {
22260: $lastactref->{'domdefaults'} = 1;
22261: }
22262: }
22263: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22264: my %updates = %expirecache;
22265: foreach my $key (keys(%expirecache)) {
22266: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22267: }
22268: if (ref($wafproxy{'alias'}) eq 'HASH') {
22269: my $cachetime = 24*60*60;
22270: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22271: $updates{$key} = 1;
22272: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22273: $cachetime);
22274: }
22275: }
22276: if (ref($lastactref) eq 'HASH') {
22277: $lastactref->{'proxyalias'} = \%updates;
22278: }
22279: }
1.388 raeburn 22280: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22281: my %samlupdates = %expiresaml;
22282: foreach my $key (keys(%expiresaml)) {
22283: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22284: }
22285: if (ref($wafproxy{'saml'}) eq 'HASH') {
22286: my $cachetime = 24*60*60;
22287: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22288: $samlupdates{$key} = 1;
22289: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22290: $cachetime);
22291: }
22292: }
22293: if (ref($lastactref) eq 'HASH') {
22294: $lastactref->{'proxysaml'} = \%samlupdates;
22295: }
22296: }
1.373 raeburn 22297: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22298: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22299: if ($changes{$item}) {
22300: if ($item eq 'alias') {
22301: my $numaliased = 0;
22302: if (ref($wafproxy{'alias'}) eq 'HASH') {
22303: my $shown;
22304: if (keys(%{$wafproxy{'alias'}})) {
22305: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22306: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22307: &Apache::lonnet::hostname($server),
22308: $wafproxy{'alias'}{$server}).'</li>';
22309: $numaliased ++;
22310: }
22311: if ($numaliased) {
22312: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22313: '<ul>'.$shown.'</ul>').'</li>';
22314: }
22315: }
22316: }
22317: unless ($numaliased) {
22318: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22319: }
1.388 raeburn 22320: } elsif ($item eq 'saml') {
1.425 raeburn 22321: my $shown;
1.388 raeburn 22322: if (ref($wafproxy{'saml'}) eq 'HASH') {
22323: if (keys(%{$wafproxy{'saml'}})) {
22324: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22325: }
22326: }
22327: if ($shown) {
1.396 raeburn 22328: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22329: $shown).'</li>';
22330: } else {
1.396 raeburn 22331: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22332: }
1.373 raeburn 22333: } else {
1.381 raeburn 22334: if ($item eq 'remoteip') {
22335: my %ip_methods = &remoteip_methods();
22336: if ($wafproxy{$item} =~ /^[mh]$/) {
22337: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22338: $ip_methods{$wafproxy{$item}}).'</li>';
22339: } else {
22340: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22341: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22342: '</li>';
22343: } else {
22344: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22345: }
22346: }
22347: } elsif ($item eq 'ipheader') {
1.373 raeburn 22348: if ($wafproxy{$item}) {
1.381 raeburn 22349: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22350: $wafproxy{$item}).'</li>';
22351: } else {
1.381 raeburn 22352: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22353: }
22354: } elsif ($item eq 'trusted') {
22355: if ($wafproxy{$item}) {
1.381 raeburn 22356: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22357: $wafproxy{$item}).'</li>';
22358: } else {
22359: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22360: }
1.381 raeburn 22361: } elsif ($item eq 'vpnint') {
22362: if ($wafproxy{$item}) {
22363: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22364: $wafproxy{$item}).'</li>';
22365: } else {
22366: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22367: }
22368: } elsif ($item eq 'vpnext') {
1.373 raeburn 22369: if ($wafproxy{$item}) {
1.381 raeburn 22370: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22371: $wafproxy{$item}).'</li>';
22372: } else {
1.381 raeburn 22373: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22374: }
1.382 raeburn 22375: } elsif ($item eq 'sslopt') {
22376: if ($wafproxy{$item}) {
22377: $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>';
22378: } else {
22379: $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>';
22380: }
1.373 raeburn 22381: }
22382: }
22383: }
22384: }
1.420 raeburn 22385: $output .= '</ul>';
1.373 raeburn 22386: } else {
22387: $output = '<span class="LC_error">'.
22388: &mt('An error occurred: [_1]',$putresult).'</span>';
22389: }
22390: } elsif (keys(%canset)) {
22391: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22392: }
22393: if (@warnings) {
22394: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22395: join("\n",@warnings).'</ul>';
22396: }
22397: return $output;
22398: }
22399:
22400: sub validate_ip_pattern {
22401: my ($pattern) = @_;
22402: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22403: my ($start,$end) = ($1,$2);
22404: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22405: if (($start !~ m{/}) && ($end !~ m{/})) {
22406: return $start.'-'.$end;
22407: }
22408: }
22409: } elsif ($pattern ne '') {
22410: $pattern = &Net::CIDR::cidrvalidate($pattern);
22411: if ($pattern ne '') {
22412: return $pattern;
1.373 raeburn 22413: }
22414: }
1.393 raeburn 22415: return;
1.373 raeburn 22416: }
22417:
1.137 raeburn 22418: sub modify_usersessions {
1.212 raeburn 22419: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22420: my @hostingtypes = ('version','excludedomain','includedomain');
22421: my @offloadtypes = ('primary','default');
22422: my %types = (
22423: remote => \@hostingtypes,
22424: hosted => \@hostingtypes,
22425: spares => \@offloadtypes,
22426: );
22427: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22428: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22429: my (%by_ip,%by_location,@intdoms,@instdoms);
22430: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22431: my @locations = sort(keys(%by_location));
1.137 raeburn 22432: my (%defaultshash,%changes);
22433: foreach my $prefix (@prefixes) {
22434: $defaultshash{'usersessions'}{$prefix} = {};
22435: }
1.212 raeburn 22436: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22437: my $resulttext;
1.138 raeburn 22438: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22439: foreach my $prefix (@prefixes) {
1.145 raeburn 22440: next if ($prefix eq 'spares');
22441: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22442: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22443: if ($type eq 'version') {
22444: my $value = $env{'form.'.$prefix.'_'.$type};
22445: my $okvalue;
22446: if ($value ne '') {
22447: if (grep(/^\Q$value\E$/,@lcversions)) {
22448: $okvalue = $value;
22449: }
22450: }
22451: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22452: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22453: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22454: if ($inuse == 0) {
22455: $changes{$prefix}{$type} = 1;
22456: } else {
22457: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22458: $changes{$prefix}{$type} = 1;
22459: }
22460: if ($okvalue ne '') {
22461: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22462: }
22463: }
22464: } else {
22465: if (($inuse == 1) && ($okvalue ne '')) {
22466: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22467: $changes{$prefix}{$type} = 1;
22468: }
22469: }
22470: } else {
22471: if (($inuse == 1) && ($okvalue ne '')) {
22472: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22473: $changes{$prefix}{$type} = 1;
22474: }
22475: }
22476: } else {
22477: if (($inuse == 1) && ($okvalue ne '')) {
22478: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22479: $changes{$prefix}{$type} = 1;
22480: }
22481: }
22482: } else {
22483: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22484: my @okvals;
22485: foreach my $val (@vals) {
1.138 raeburn 22486: if ($val =~ /:/) {
22487: my @items = split(/:/,$val);
22488: foreach my $item (@items) {
22489: if (ref($by_location{$item}) eq 'ARRAY') {
22490: push(@okvals,$item);
22491: }
22492: }
22493: } else {
22494: if (ref($by_location{$val}) eq 'ARRAY') {
22495: push(@okvals,$val);
22496: }
1.137 raeburn 22497: }
22498: }
22499: @okvals = sort(@okvals);
22500: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22501: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22502: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22503: if ($inuse == 0) {
22504: $changes{$prefix}{$type} = 1;
22505: } else {
22506: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22507: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22508: if (@changed > 0) {
22509: $changes{$prefix}{$type} = 1;
22510: }
22511: }
22512: } else {
22513: if ($inuse == 1) {
22514: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22515: $changes{$prefix}{$type} = 1;
22516: }
22517: }
22518: } else {
22519: if ($inuse == 1) {
22520: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22521: $changes{$prefix}{$type} = 1;
22522: }
22523: }
22524: } else {
22525: if ($inuse == 1) {
22526: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22527: $changes{$prefix}{$type} = 1;
22528: }
22529: }
22530: }
22531: }
22532: }
1.145 raeburn 22533:
22534: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22535: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22536: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22537: my $savespares;
22538:
22539: foreach my $lonhost (sort(keys(%servers))) {
22540: my $serverhomeID =
22541: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22542: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22543: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22544: my %spareschg;
22545: foreach my $type (@{$types{'spares'}}) {
22546: my @okspares;
22547: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22548: foreach my $server (@checked) {
1.152 raeburn 22549: if (&Apache::lonnet::hostname($server) ne '') {
22550: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22551: unless (grep(/^\Q$server\E$/,@okspares)) {
22552: push(@okspares,$server);
22553: }
1.145 raeburn 22554: }
22555: }
22556: }
22557: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22558: my $newspare;
1.152 raeburn 22559: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22560: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22561: $newspare = $new;
22562: }
22563: }
1.152 raeburn 22564: my @spares;
22565: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22566: @spares = sort(@okspares,$newspare);
22567: } else {
22568: @spares = sort(@okspares);
22569: }
22570: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22571: if (ref($spareid{$lonhost}) eq 'HASH') {
22572: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22573: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22574: if (@diffs > 0) {
22575: $spareschg{$type} = 1;
22576: }
22577: }
22578: }
22579: }
22580: if (keys(%spareschg) > 0) {
22581: $changes{'spares'}{$lonhost} = \%spareschg;
22582: }
22583: }
1.261 raeburn 22584: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22585: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22586: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22587: my @okoffload;
22588: if (@offloadnow) {
22589: foreach my $server (@offloadnow) {
22590: if (&Apache::lonnet::hostname($server) ne '') {
22591: unless (grep(/^\Q$server\E$/,@okoffload)) {
22592: push(@okoffload,$server);
22593: }
22594: }
22595: }
22596: if (@okoffload) {
22597: foreach my $lonhost (@okoffload) {
22598: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22599: }
22600: }
22601: }
1.371 raeburn 22602: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22603: my @okoffloadoth;
22604: if (@offloadoth) {
22605: foreach my $server (@offloadoth) {
22606: if (&Apache::lonnet::hostname($server) ne '') {
22607: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22608: push(@okoffloadoth,$server);
22609: }
22610: }
22611: }
22612: if (@okoffloadoth) {
22613: foreach my $lonhost (@okoffloadoth) {
22614: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22615: }
22616: }
22617: }
1.145 raeburn 22618: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22619: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22620: if (ref($changes{'spares'}) eq 'HASH') {
22621: if (keys(%{$changes{'spares'}}) > 0) {
22622: $savespares = 1;
22623: }
22624: }
22625: } else {
22626: $savespares = 1;
22627: }
1.371 raeburn 22628: foreach my $offload ('offloadnow','offloadoth') {
22629: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22630: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22631: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22632: $changes{$offload} = 1;
22633: last;
22634: }
1.261 raeburn 22635: }
1.371 raeburn 22636: unless ($changes{$offload}) {
22637: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22638: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22639: $changes{$offload} = 1;
22640: last;
22641: }
1.261 raeburn 22642: }
22643: }
1.371 raeburn 22644: } else {
22645: if (($offload eq 'offloadnow') && (@okoffload)) {
22646: $changes{'offloadnow'} = 1;
22647: }
22648: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22649: $changes{'offloadoth'} = 1;
22650: }
1.425 raeburn 22651: }
1.371 raeburn 22652: }
22653: } else {
22654: if (@okoffload) {
1.261 raeburn 22655: $changes{'offloadnow'} = 1;
22656: }
1.371 raeburn 22657: if (@okoffloadoth) {
22658: $changes{'offloadoth'} = 1;
22659: }
1.145 raeburn 22660: }
1.147 raeburn 22661: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22662: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22663: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22664: $dom);
22665: if ($putresult eq 'ok') {
22666: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22667: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22668: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22669: }
22670: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22671: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22672: }
1.261 raeburn 22673: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22674: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22675: }
1.371 raeburn 22676: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22677: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22678: }
1.137 raeburn 22679: }
22680: my $cachetime = 24*60*60;
22681: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22682: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22683: if (ref($lastactref) eq 'HASH') {
22684: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22685: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22686: }
1.147 raeburn 22687: if (keys(%changes) > 0) {
22688: my %lt = &usersession_titles();
22689: $resulttext = &mt('Changes made:').'<ul>';
22690: foreach my $prefix (@prefixes) {
22691: if (ref($changes{$prefix}) eq 'HASH') {
22692: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22693: if ($prefix eq 'spares') {
22694: if (ref($changes{$prefix}) eq 'HASH') {
22695: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22696: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22697: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22698: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22699: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22700: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22701: foreach my $type (@{$types{$prefix}}) {
22702: if ($changes{$prefix}{$lonhost}{$type}) {
22703: my $offloadto = &mt('None');
22704: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22705: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22706: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22707: }
1.145 raeburn 22708: }
1.147 raeburn 22709: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22710: }
1.137 raeburn 22711: }
22712: }
1.147 raeburn 22713: $resulttext .= '</li>';
1.137 raeburn 22714: }
22715: }
1.147 raeburn 22716: } else {
22717: foreach my $type (@{$types{$prefix}}) {
22718: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22719: my ($newvalue,$notinuse);
1.147 raeburn 22720: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22721: if (ref($defaultshash{'usersessions'}{$prefix})) {
22722: if ($type eq 'version') {
22723: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22724: } else {
22725: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22726: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22727: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22728: }
22729: } else {
22730: $notinuse = 1;
1.147 raeburn 22731: }
1.145 raeburn 22732: }
22733: }
22734: }
1.147 raeburn 22735: if ($newvalue eq '') {
22736: if ($type eq 'version') {
22737: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22738: } elsif ($notinuse) {
22739: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22740: } else {
22741: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22742: }
1.145 raeburn 22743: } else {
1.147 raeburn 22744: if ($type eq 'version') {
1.344 raeburn 22745: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22746: }
22747: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22748: }
1.137 raeburn 22749: }
22750: }
22751: }
1.147 raeburn 22752: $resulttext .= '</ul>';
1.137 raeburn 22753: }
22754: }
1.261 raeburn 22755: if ($changes{'offloadnow'}) {
22756: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22757: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22758: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22759: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22760: $resulttext .= '<li>'.$lonhost.'</li>';
22761: }
22762: $resulttext .= '</ul>';
22763: } else {
1.371 raeburn 22764: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22765: }
22766: } else {
22767: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22768: }
22769: }
22770: if ($changes{'offloadoth'}) {
22771: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22772: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22773: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22774: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22775: $resulttext .= '<li>'.$lonhost.'</li>';
22776: }
22777: $resulttext .= '</ul>';
22778: } else {
22779: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22780: }
22781: } else {
1.371 raeburn 22782: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22783: }
22784: }
1.147 raeburn 22785: $resulttext .= '</ul>';
22786: } else {
22787: $resulttext = $nochgmsg;
1.137 raeburn 22788: }
22789: } else {
22790: $resulttext = '<span class="LC_error">'.
22791: &mt('An error occurred: [_1]',$putresult).'</span>';
22792: }
22793: } else {
1.147 raeburn 22794: $resulttext = $nochgmsg;
1.137 raeburn 22795: }
22796: return $resulttext;
22797: }
22798:
1.275 raeburn 22799: sub modify_ssl {
22800: my ($dom,$lastactref,%domconfig) = @_;
22801: my (%by_ip,%by_location,@intdoms,@instdoms);
22802: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22803: my @locations = sort(keys(%by_location));
22804: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22805: my (%defaultshash,%changes);
22806: my $action = 'ssl';
1.293 raeburn 22807: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22808: foreach my $prefix (@prefixes) {
22809: $defaultshash{$action}{$prefix} = {};
22810: }
22811: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22812: my $resulttext;
22813: my %iphost = &Apache::lonnet::get_iphost();
22814: my @reptypes = ('certreq','nocertreq');
22815: my @connecttypes = ('dom','intdom','other');
22816: my %types = (
1.293 raeburn 22817: connto => \@connecttypes,
22818: connfrom => \@connecttypes,
22819: replication => \@reptypes,
1.275 raeburn 22820: );
22821: foreach my $prefix (sort(keys(%types))) {
22822: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22823: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22824: my $value = 'yes';
22825: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22826: $value = $env{'form.'.$prefix.'_'.$type};
22827: }
1.335 raeburn 22828: if (ref($domconfig{$action}) eq 'HASH') {
22829: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22830: if ($domconfig{$action}{$prefix}{$type} ne '') {
22831: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22832: $changes{$prefix}{$type} = 1;
22833: }
22834: $defaultshash{$action}{$prefix}{$type} = $value;
22835: } else {
22836: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22837: $changes{$prefix}{$type} = 1;
22838: }
22839: } else {
22840: $defaultshash{$action}{$prefix}{$type} = $value;
22841: $changes{$prefix}{$type} = 1;
22842: }
22843: } else {
22844: $defaultshash{$action}{$prefix}{$type} = $value;
22845: $changes{$prefix}{$type} = 1;
22846: }
22847: if (($type eq 'dom') && (keys(%servers) == 1)) {
22848: delete($changes{$prefix}{$type});
22849: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22850: delete($changes{$prefix}{$type});
22851: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22852: delete($changes{$prefix}{$type});
22853: }
22854: } elsif ($prefix eq 'replication') {
22855: if (@locations > 0) {
22856: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22857: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22858: my @okvals;
22859: foreach my $val (@vals) {
22860: if ($val =~ /:/) {
22861: my @items = split(/:/,$val);
22862: foreach my $item (@items) {
22863: if (ref($by_location{$item}) eq 'ARRAY') {
22864: push(@okvals,$item);
22865: }
22866: }
22867: } else {
22868: if (ref($by_location{$val}) eq 'ARRAY') {
22869: push(@okvals,$val);
22870: }
22871: }
22872: }
22873: @okvals = sort(@okvals);
22874: if (ref($domconfig{$action}) eq 'HASH') {
22875: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22876: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22877: if ($inuse == 0) {
22878: $changes{$prefix}{$type} = 1;
22879: } else {
22880: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22881: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22882: if (@changed > 0) {
22883: $changes{$prefix}{$type} = 1;
22884: }
22885: }
22886: } else {
22887: if ($inuse == 1) {
22888: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22889: $changes{$prefix}{$type} = 1;
22890: }
22891: }
22892: } else {
22893: if ($inuse == 1) {
22894: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22895: $changes{$prefix}{$type} = 1;
22896: }
22897: }
22898: } else {
22899: if ($inuse == 1) {
22900: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22901: $changes{$prefix}{$type} = 1;
22902: }
22903: }
22904: }
22905: }
22906: }
22907: }
1.336 raeburn 22908: if (keys(%changes)) {
22909: foreach my $prefix (keys(%changes)) {
22910: if (ref($changes{$prefix}) eq 'HASH') {
22911: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22912: delete($changes{$prefix});
22913: }
22914: } else {
22915: delete($changes{$prefix});
22916: }
22917: }
22918: }
1.275 raeburn 22919: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22920: if (keys(%changes) > 0) {
22921: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22922: $dom);
22923: if ($putresult eq 'ok') {
22924: if (ref($defaultshash{$action}) eq 'HASH') {
22925: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22926: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22927: }
1.293 raeburn 22928: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22929: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22930: }
22931: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22932: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22933: }
22934: }
22935: my $cachetime = 24*60*60;
22936: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22937: if (ref($lastactref) eq 'HASH') {
22938: $lastactref->{'domdefaults'} = 1;
22939: }
22940: if (keys(%changes) > 0) {
22941: my %titles = &ssl_titles();
22942: $resulttext = &mt('Changes made:').'<ul>';
22943: foreach my $prefix (@prefixes) {
22944: if (ref($changes{$prefix}) eq 'HASH') {
22945: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22946: foreach my $type (@{$types{$prefix}}) {
22947: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22948: my ($newvalue,$notinuse);
1.275 raeburn 22949: if (ref($defaultshash{$action}) eq 'HASH') {
22950: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22951: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22952: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22953: } else {
22954: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22955: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22956: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22957: }
22958: } else {
22959: $notinuse = 1;
1.275 raeburn 22960: }
22961: }
22962: }
1.344 raeburn 22963: if ($notinuse) {
22964: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22965: } elsif ($newvalue eq '') {
1.275 raeburn 22966: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22967: } else {
22968: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22969: }
22970: }
22971: }
22972: }
22973: $resulttext .= '</ul>';
22974: }
22975: }
22976: } else {
22977: $resulttext = $nochgmsg;
22978: }
22979: } else {
22980: $resulttext = '<span class="LC_error">'.
22981: &mt('An error occurred: [_1]',$putresult).'</span>';
22982: }
22983: } else {
22984: $resulttext = $nochgmsg;
22985: }
22986: return $resulttext;
22987: }
22988:
1.279 raeburn 22989: sub modify_trust {
22990: my ($dom,$lastactref,%domconfig) = @_;
22991: my (%by_ip,%by_location,@intdoms,@instdoms);
22992: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22993: my @locations = sort(keys(%by_location));
22994: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
22995: my @types = ('exc','inc');
22996: my (%defaultshash,%changes);
22997: foreach my $prefix (@prefixes) {
22998: $defaultshash{'trust'}{$prefix} = {};
22999: }
23000: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
23001: my $resulttext;
23002: foreach my $prefix (@prefixes) {
23003: foreach my $type (@types) {
23004: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
23005: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
23006: my @okvals;
23007: foreach my $val (@vals) {
23008: if ($val =~ /:/) {
23009: my @items = split(/:/,$val);
23010: foreach my $item (@items) {
23011: if (ref($by_location{$item}) eq 'ARRAY') {
23012: push(@okvals,$item);
23013: }
23014: }
23015: } else {
23016: if (ref($by_location{$val}) eq 'ARRAY') {
23017: push(@okvals,$val);
23018: }
23019: }
23020: }
23021: @okvals = sort(@okvals);
23022: if (ref($domconfig{'trust'}) eq 'HASH') {
23023: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
23024: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23025: if ($inuse == 0) {
23026: $changes{$prefix}{$type} = 1;
23027: } else {
23028: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23029: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
23030: if (@changed > 0) {
23031: $changes{$prefix}{$type} = 1;
23032: }
23033: }
23034: } else {
23035: if ($inuse == 1) {
23036: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23037: $changes{$prefix}{$type} = 1;
23038: }
23039: }
23040: } else {
23041: if ($inuse == 1) {
23042: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23043: $changes{$prefix}{$type} = 1;
23044: }
23045: }
23046: } else {
23047: if ($inuse == 1) {
23048: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23049: $changes{$prefix}{$type} = 1;
23050: }
23051: }
23052: }
23053: }
23054: my $nochgmsg = &mt('No changes made to trust settings.');
23055: if (keys(%changes) > 0) {
23056: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
23057: $dom);
23058: if ($putresult eq 'ok') {
23059: if (ref($defaultshash{'trust'}) eq 'HASH') {
23060: foreach my $prefix (@prefixes) {
23061: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
23062: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
23063: }
23064: }
23065: }
23066: my $cachetime = 24*60*60;
23067: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 23068: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 23069: if (ref($lastactref) eq 'HASH') {
23070: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 23071: $lastactref->{'trust'} = 1;
1.279 raeburn 23072: }
23073: if (keys(%changes) > 0) {
23074: my %lt = &trust_titles();
23075: $resulttext = &mt('Changes made:').'<ul>';
23076: foreach my $prefix (@prefixes) {
23077: if (ref($changes{$prefix}) eq 'HASH') {
23078: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
23079: foreach my $type (@types) {
23080: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 23081: my ($newvalue,$notinuse);
1.279 raeburn 23082: if (ref($defaultshash{'trust'}) eq 'HASH') {
23083: if (ref($defaultshash{'trust'}{$prefix})) {
23084: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23085: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
23086: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
23087: }
1.344 raeburn 23088: } else {
23089: $notinuse = 1;
1.279 raeburn 23090: }
23091: }
23092: }
1.344 raeburn 23093: if ($notinuse) {
23094: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
23095: } elsif ($newvalue eq '') {
1.279 raeburn 23096: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
23097: } else {
23098: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
23099: }
23100: }
23101: }
23102: $resulttext .= '</ul>';
23103: }
23104: }
23105: $resulttext .= '</ul>';
23106: } else {
23107: $resulttext = $nochgmsg;
23108: }
23109: } else {
23110: $resulttext = '<span class="LC_error">'.
23111: &mt('An error occurred: [_1]',$putresult).'</span>';
23112: }
23113: } else {
23114: $resulttext = $nochgmsg;
23115: }
23116: return $resulttext;
23117: }
23118:
1.150 raeburn 23119: sub modify_loadbalancing {
23120: my ($dom,%domconfig) = @_;
23121: my $primary_id = &Apache::lonnet::domain($dom,'primary');
23122: my $intdom = &Apache::lonnet::internet_dom($primary_id);
23123: my ($othertitle,$usertypes,$types) =
23124: &Apache::loncommon::sorted_inst_types($dom);
23125: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 23126: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 23127: my @sparestypes = ('primary','default');
23128: my %typetitles = &sparestype_titles();
23129: my $resulttext;
1.342 raeburn 23130: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23131: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23132: %existing = %{$domconfig{'loadbalancing'}};
23133: }
23134: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 23135: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 23136: my ($saveloadbalancing,%defaultshash,%changes);
23137: my ($alltypes,$othertypes,$titles) =
23138: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
23139: my %ruletitles = &offloadtype_text();
23140: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
23141: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
23142: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
23143: if ($balancer eq '') {
23144: next;
23145: }
1.210 raeburn 23146: if (!exists($servers{$balancer})) {
1.171 raeburn 23147: if (exists($currbalancer{$balancer})) {
23148: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 23149: }
1.171 raeburn 23150: next;
23151: }
23152: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
23153: push(@{$changes{'delete'}},$balancer);
23154: next;
23155: }
23156: if (!exists($currbalancer{$balancer})) {
23157: push(@{$changes{'add'}},$balancer);
23158: }
23159: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
23160: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
23161: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
23162: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23163: $saveloadbalancing = 1;
23164: }
23165: foreach my $sparetype (@sparestypes) {
23166: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
23167: my @offloadto;
23168: foreach my $target (@targets) {
23169: if (($servers{$target}) && ($target ne $balancer)) {
23170: if ($sparetype eq 'default') {
23171: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
23172: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 23173: }
23174: }
1.171 raeburn 23175: unless(grep(/^\Q$target\E$/,@offloadto)) {
23176: push(@offloadto,$target);
23177: }
1.150 raeburn 23178: }
23179: }
1.284 raeburn 23180: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
23181: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
23182: push(@offloadto,$balancer);
23183: }
23184: }
23185: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 23186: }
1.342 raeburn 23187: if ($env{'form.loadbalancing_cookie_'.$i}) {
23188: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 23189: if (exists($currbalancer{$balancer})) {
1.342 raeburn 23190: unless ($currcookies{$balancer}) {
23191: $changes{'curr'}{$balancer}{'cookie'} = 1;
23192: }
23193: }
23194: } elsif (exists($currbalancer{$balancer})) {
23195: if ($currcookies{$balancer}) {
23196: $changes{'curr'}{$balancer}{'cookie'} = 1;
23197: }
23198: }
1.171 raeburn 23199: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 23200: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23201: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
23202: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 23203: if (@targetdiffs > 0) {
1.171 raeburn 23204: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23205: }
1.171 raeburn 23206: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23207: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23208: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23209: }
23210: }
23211: }
23212: } else {
1.171 raeburn 23213: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 23214: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23215: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23216: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23217: $changes{'curr'}{$balancer}{'targets'} = 1;
23218: }
1.150 raeburn 23219: }
23220: }
1.210 raeburn 23221: }
1.150 raeburn 23222: }
23223: my $ishomedom;
1.171 raeburn 23224: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
23225: $ishomedom = 1;
1.150 raeburn 23226: }
23227: if (ref($alltypes) eq 'ARRAY') {
23228: foreach my $type (@{$alltypes}) {
23229: my $rule;
1.210 raeburn 23230: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 23231: (!$ishomedom)) {
1.171 raeburn 23232: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
23233: }
23234: if ($rule eq 'specific') {
1.255 raeburn 23235: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 23236: if (exists($servers{$specifiedhost})) {
1.255 raeburn 23237: $rule = $specifiedhost;
23238: }
1.150 raeburn 23239: }
1.171 raeburn 23240: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
23241: if (ref($currrules{$balancer}) eq 'HASH') {
23242: if ($rule ne $currrules{$balancer}{$type}) {
23243: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23244: }
23245: } elsif ($rule ne '') {
1.171 raeburn 23246: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23247: }
23248: }
23249: }
1.171 raeburn 23250: }
23251: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
23252: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
23253: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23254: $defaultshash{'loadbalancing'} = {};
23255: }
23256: my $putresult = &Apache::lonnet::put_dom('configuration',
23257: \%defaultshash,$dom);
23258: if ($putresult eq 'ok') {
23259: if (keys(%changes) > 0) {
1.252 raeburn 23260: my %toupdate;
1.171 raeburn 23261: if (ref($changes{'delete'}) eq 'ARRAY') {
23262: foreach my $balancer (sort(@{$changes{'delete'}})) {
23263: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23264: $toupdate{$balancer} = 1;
1.150 raeburn 23265: }
1.171 raeburn 23266: }
23267: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23268: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23269: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23270: $toupdate{$balancer} = 1;
1.171 raeburn 23271: }
23272: }
23273: if (ref($changes{'curr'}) eq 'HASH') {
23274: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23275: $toupdate{$balancer} = 1;
1.171 raeburn 23276: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23277: if ($changes{'curr'}{$balancer}{'targets'}) {
23278: my %offloadstr;
23279: foreach my $sparetype (@sparestypes) {
23280: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23281: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23282: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23283: }
23284: }
1.150 raeburn 23285: }
1.171 raeburn 23286: if (keys(%offloadstr) == 0) {
23287: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23288: } else {
1.171 raeburn 23289: my $showoffload;
23290: foreach my $sparetype (@sparestypes) {
23291: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23292: if (defined($offloadstr{$sparetype})) {
23293: $showoffload .= $offloadstr{$sparetype};
23294: } else {
23295: $showoffload .= &mt('None');
23296: }
23297: $showoffload .= (' 'x3);
23298: }
23299: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23300: }
23301: }
23302: }
1.171 raeburn 23303: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23304: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23305: foreach my $type (@{$alltypes}) {
23306: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23307: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23308: my $balancetext;
23309: if ($rule eq '') {
23310: $balancetext = $ruletitles{'default'};
1.209 raeburn 23311: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23312: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23313: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23314: foreach my $sparetype (@sparestypes) {
23315: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23316: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23317: }
23318: }
1.253 raeburn 23319: foreach my $item (@{$alltypes}) {
23320: next if ($item =~ /^_LC_ipchange/);
23321: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23322: if ($hasrule eq 'homeserver') {
23323: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23324: } else {
23325: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23326: if ($servers{$hasrule}) {
23327: $toupdate{$hasrule} = 1;
23328: }
23329: }
23330: }
23331: }
1.254 raeburn 23332: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23333: $balancetext = $ruletitles{$rule};
23334: } else {
23335: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23336: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23337: if ($receiver) {
23338: $toupdate{$receiver};
23339: }
23340: }
23341: } else {
23342: $balancetext = $ruletitles{$rule};
1.252 raeburn 23343: }
1.171 raeburn 23344: } else {
23345: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23346: }
1.210 raeburn 23347: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23348: }
23349: }
23350: }
23351: }
1.342 raeburn 23352: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23353: if ($currcookies{$balancer}) {
23354: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23355: $balancer).'</li>';
23356: } else {
23357: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23358: $balancer).'</li>';
23359: }
1.342 raeburn 23360: }
1.375 raeburn 23361: }
23362: }
23363: if (keys(%toupdate)) {
23364: my %thismachine;
23365: my $updatedhere;
23366: my $cachetime = 60*60*24;
23367: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23368: foreach my $lonhost (keys(%toupdate)) {
23369: if ($thismachine{$lonhost}) {
23370: unless ($updatedhere) {
23371: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23372: $defaultshash{'loadbalancing'},
23373: $cachetime);
23374: $updatedhere = 1;
1.252 raeburn 23375: }
1.375 raeburn 23376: } else {
23377: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23378: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23379: }
1.150 raeburn 23380: }
1.171 raeburn 23381: }
23382: if ($resulttext ne '') {
23383: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23384: } else {
23385: $resulttext = $nochgmsg;
23386: }
23387: } else {
1.171 raeburn 23388: $resulttext = $nochgmsg;
1.150 raeburn 23389: }
23390: } else {
1.171 raeburn 23391: $resulttext = '<span class="LC_error">'.
23392: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23393: }
23394: } else {
1.171 raeburn 23395: $resulttext = $nochgmsg;
1.150 raeburn 23396: }
23397: return $resulttext;
23398: }
23399:
1.48 raeburn 23400: sub recurse_check {
23401: my ($chkcats,$categories,$depth,$name) = @_;
23402: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23403: my $chg = 0;
23404: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23405: my $category = $chkcats->[$depth]{$name}[$j];
23406: my $item;
23407: if ($category eq '') {
23408: $chg ++;
23409: } else {
23410: my $deeper = $depth + 1;
23411: $item = &escape($category).':'.&escape($name).':'.$depth;
23412: if ($chg) {
23413: $categories->{$item} -= $chg;
23414: }
23415: &recurse_check($chkcats,$categories,$deeper,$category);
23416: $deeper --;
23417: }
23418: }
23419: }
23420: return;
23421: }
23422:
23423: sub recurse_cat_deletes {
23424: my ($item,$coursecategories,$deletions) = @_;
23425: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23426: my $subdepth = $depth + 1;
23427: if (ref($coursecategories) eq 'HASH') {
23428: foreach my $subitem (keys(%{$coursecategories})) {
23429: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23430: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23431: delete($coursecategories->{$subitem});
23432: $deletions->{$subitem} = 1;
23433: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23434: }
1.48 raeburn 23435: }
23436: }
23437: return;
23438: }
23439:
1.125 raeburn 23440: sub active_dc_picker {
1.191 raeburn 23441: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23442: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23443: my @domcoord = keys(%domcoords);
23444: if (keys(%currhash)) {
23445: foreach my $dc (keys(%currhash)) {
23446: unless (exists($domcoords{$dc})) {
23447: push(@domcoord,$dc);
23448: }
23449: }
23450: }
23451: @domcoord = sort(@domcoord);
1.210 raeburn 23452: my $numdcs = scalar(@domcoord);
1.191 raeburn 23453: my $rows = 0;
23454: my $table;
1.125 raeburn 23455: if ($numdcs > 1) {
1.191 raeburn 23456: $table = '<table>';
23457: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23458: my $rem = $i%($numinrow);
23459: if ($rem == 0) {
23460: if ($i > 0) {
1.191 raeburn 23461: $table .= '</tr>';
1.125 raeburn 23462: }
1.191 raeburn 23463: $table .= '<tr>';
23464: $rows ++;
1.125 raeburn 23465: }
1.191 raeburn 23466: my $check = '';
23467: if ($inputtype eq 'radio') {
23468: if (keys(%currhash) == 0) {
23469: if (!$i) {
23470: $check = ' checked="checked"';
23471: }
23472: } elsif (exists($currhash{$domcoord[$i]})) {
23473: $check = ' checked="checked"';
23474: }
23475: } else {
23476: if (exists($currhash{$domcoord[$i]})) {
23477: $check = ' checked="checked"';
1.125 raeburn 23478: }
23479: }
1.191 raeburn 23480: if ($i == @domcoord - 1) {
1.125 raeburn 23481: my $colsleft = $numinrow - $rem;
23482: if ($colsleft > 1) {
1.191 raeburn 23483: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23484: } else {
1.191 raeburn 23485: $table .= '<td class="LC_left_item">';
1.125 raeburn 23486: }
23487: } else {
1.191 raeburn 23488: $table .= '<td class="LC_left_item">';
23489: }
23490: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23491: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23492: $table .= '<span class="LC_nobreak"><label>'.
23493: '<input type="'.$inputtype.'" name="'.$name.'"'.
23494: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23495: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23496: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23497: }
1.219 raeburn 23498: $table .= '</label></span></td>';
1.191 raeburn 23499: }
23500: $table .= '</tr></table>';
23501: } elsif ($numdcs == 1) {
1.219 raeburn 23502: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23503: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23504: if ($inputtype eq 'radio') {
1.247 raeburn 23505: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23506: if ($user ne $dcname.':'.$dcdom) {
23507: $table .= ' ('.$dcname.':'.$dcdom.')';
23508: }
1.191 raeburn 23509: } else {
23510: my $check;
23511: if (exists($currhash{$domcoord[0]})) {
23512: $check = ' checked="checked"';
1.125 raeburn 23513: }
1.247 raeburn 23514: $table = '<span class="LC_nobreak"><label>'.
23515: '<input type="checkbox" name="'.$name.'" '.
23516: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23517: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23518: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23519: }
1.220 raeburn 23520: $table .= '</label></span>';
1.191 raeburn 23521: $rows ++;
1.125 raeburn 23522: }
23523: }
1.191 raeburn 23524: return ($numdcs,$table,$rows);
1.125 raeburn 23525: }
23526:
1.137 raeburn 23527: sub usersession_titles {
23528: return &Apache::lonlocal::texthash(
23529: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23530: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23531: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23532: version => 'LON-CAPA version requirement',
1.138 raeburn 23533: excludedomain => 'Allow all, but exclude specific domains',
23534: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23535: primary => 'Primary (checked first)',
1.154 raeburn 23536: default => 'Default',
1.137 raeburn 23537: );
23538: }
23539:
1.152 raeburn 23540: sub id_for_thisdom {
23541: my (%servers) = @_;
23542: my %altids;
23543: foreach my $server (keys(%servers)) {
23544: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23545: if ($serverhome ne $server) {
23546: $altids{$serverhome} = $server;
23547: }
23548: }
23549: return %altids;
23550: }
23551:
1.150 raeburn 23552: sub count_servers {
23553: my ($currbalancer,%servers) = @_;
23554: my (@spares,$numspares);
23555: foreach my $lonhost (sort(keys(%servers))) {
23556: next if ($currbalancer eq $lonhost);
23557: push(@spares,$lonhost);
23558: }
23559: if ($currbalancer) {
23560: $numspares = scalar(@spares);
23561: } else {
23562: $numspares = scalar(@spares) - 1;
23563: }
23564: return ($numspares,@spares);
23565: }
23566:
23567: sub lonbalance_targets_js {
1.171 raeburn 23568: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23569: my $select = &mt('Select');
23570: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23571: if (ref($servers) eq 'HASH') {
23572: $alltargets = join("','",sort(keys(%{$servers})));
23573: my @homedoms;
23574: foreach my $server (sort(keys(%{$servers}))) {
23575: if (&Apache::lonnet::host_domain($server) eq $dom) {
23576: push(@homedoms,'1');
23577: } else {
23578: push(@homedoms,'0');
23579: }
23580: }
23581: $allishome = join("','",@homedoms);
23582: }
23583: if (ref($types) eq 'ARRAY') {
23584: if (@{$types} > 0) {
23585: @alltypes = @{$types};
23586: }
23587: }
23588: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23589: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23590: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23591: if (ref($settings) eq 'HASH') {
23592: %existing = %{$settings};
23593: }
23594: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23595: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23596: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23597: return <<"END";
23598:
23599: <script type="text/javascript">
23600: // <![CDATA[
23601:
1.171 raeburn 23602: currBalancers = new Array('$balancers');
23603:
23604: function toggleTargets(balnum) {
23605: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23606: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23607: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23608: var prevbalancer = prevhostitem.value;
23609: var baltotal = document.getElementById('loadbalancing_total').value;
23610: prevhostitem.value = balancer;
23611: if (prevbalancer != '') {
23612: var prevIdx = currBalancers.indexOf(prevbalancer);
23613: if (prevIdx != -1) {
23614: currBalancers.splice(prevIdx,1);
23615: }
23616: }
1.150 raeburn 23617: if (balancer == '') {
1.171 raeburn 23618: hideSpares(balnum);
1.150 raeburn 23619: } else {
1.171 raeburn 23620: var currIdx = currBalancers.indexOf(balancer);
23621: if (currIdx == -1) {
23622: currBalancers.push(balancer);
23623: }
1.150 raeburn 23624: var homedoms = new Array('$allishome');
1.171 raeburn 23625: var ishomedom = homedoms[lonhostitem.selectedIndex];
23626: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23627: }
1.171 raeburn 23628: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23629: return;
23630: }
23631:
1.171 raeburn 23632: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23633: var alltargets = new Array('$alltargets');
23634: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23635: var offloadtypes = new Array('primary','default');
23636:
1.171 raeburn 23637: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23638: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23639:
1.151 raeburn 23640: for (var i=0; i<offloadtypes.length; i++) {
23641: var count = 0;
23642: for (var j=0; j<alltargets.length; j++) {
23643: if (alltargets[j] != balancer) {
1.171 raeburn 23644: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23645: item.value = alltargets[j];
23646: item.style.textAlign='left';
23647: item.style.textFace='normal';
23648: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23649: if (currBalancers.indexOf(alltargets[j]) == -1) {
23650: item.disabled = '';
23651: } else {
23652: item.disabled = 'disabled';
23653: item.checked = false;
23654: }
1.151 raeburn 23655: count ++;
23656: }
1.150 raeburn 23657: }
23658: }
1.151 raeburn 23659: for (var k=0; k<insttypes.length; k++) {
23660: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23661: if (ishomedom == 1) {
1.171 raeburn 23662: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23663: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23664: } else {
1.171 raeburn 23665: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23666: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23667: }
23668: } else {
1.171 raeburn 23669: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23670: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23671: }
1.151 raeburn 23672: if ((insttypes[k] != '_LC_external') &&
23673: ((insttypes[k] != '_LC_internetdom') ||
23674: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23675: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23676: item.options.length = 0;
23677: item.options[0] = new Option("","",true,true);
1.210 raeburn 23678: var idx = 0;
1.151 raeburn 23679: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23680: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23681: idx ++;
23682: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23683: }
23684: }
23685: }
23686: }
23687: return;
23688: }
23689:
1.171 raeburn 23690: function hideSpares(balnum) {
1.150 raeburn 23691: var alltargets = new Array('$alltargets');
23692: var insttypes = new Array('$allinsttypes');
23693: var offloadtypes = new Array('primary','default');
23694:
1.171 raeburn 23695: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23696: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23697:
23698: var total = alltargets.length - 1;
23699: for (var i=0; i<offloadtypes; i++) {
23700: for (var j=0; j<total; j++) {
1.171 raeburn 23701: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23702: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23703: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23704: }
1.150 raeburn 23705: }
23706: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23707: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23708: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23709: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23710: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23711: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23712: }
23713: }
23714: return;
23715: }
23716:
1.171 raeburn 23717: function checkOffloads(item,balnum,type) {
1.150 raeburn 23718: var alltargets = new Array('$alltargets');
23719: var offloadtypes = new Array('primary','default');
23720: if (item.checked) {
23721: var total = alltargets.length - 1;
23722: var other;
23723: if (type == offloadtypes[0]) {
1.151 raeburn 23724: other = offloadtypes[1];
1.150 raeburn 23725: } else {
1.151 raeburn 23726: other = offloadtypes[0];
1.150 raeburn 23727: }
23728: for (var i=0; i<total; i++) {
1.171 raeburn 23729: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23730: if (server == item.value) {
1.171 raeburn 23731: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23732: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23733: }
23734: }
23735: }
23736: }
23737: return;
23738: }
23739:
1.171 raeburn 23740: function singleServerToggle(balnum,type) {
23741: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23742: if (offloadtoSelIdx == 0) {
1.171 raeburn 23743: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23744: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23745:
23746: } else {
1.171 raeburn 23747: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23748: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23749: }
23750: return;
23751: }
23752:
1.171 raeburn 23753: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23754: if (type == '_LC_external') {
1.171 raeburn 23755: return;
1.150 raeburn 23756: }
1.171 raeburn 23757: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23758: for (var i=0; i<typesRules.length; i++) {
23759: if (formname.elements[typesRules[i]].checked) {
23760: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23761: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23762: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23763: } else {
1.171 raeburn 23764: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23765: }
23766: }
23767: }
23768: return;
23769: }
23770:
23771: function balancerDeleteChange(balnum) {
23772: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23773: var baltotal = document.getElementById('loadbalancing_total').value;
23774: var addtarget;
23775: var removetarget;
23776: var action = 'delete';
23777: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23778: var lonhost = hostitem.value;
23779: var currIdx = currBalancers.indexOf(lonhost);
23780: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23781: if (currIdx != -1) {
23782: currBalancers.splice(currIdx,1);
23783: }
23784: addtarget = lonhost;
23785: } else {
23786: if (currIdx == -1) {
23787: currBalancers.push(lonhost);
23788: }
23789: removetarget = lonhost;
23790: action = 'undelete';
23791: }
23792: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23793: }
23794: return;
23795: }
23796:
23797: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23798: if (baltotal > 1) {
23799: var offloadtypes = new Array('primary','default');
23800: var alltargets = new Array('$alltargets');
23801: var insttypes = new Array('$allinsttypes');
23802: for (var i=0; i<baltotal; i++) {
23803: if (i != balnum) {
23804: for (var j=0; j<offloadtypes.length; j++) {
23805: var total = alltargets.length - 1;
23806: for (var k=0; k<total; k++) {
23807: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23808: var server = serveritem.value;
23809: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23810: if (server == addtarget) {
23811: serveritem.disabled = '';
23812: }
23813: }
23814: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23815: if (server == removetarget) {
23816: serveritem.disabled = 'disabled';
23817: serveritem.checked = false;
23818: }
23819: }
23820: }
23821: }
23822: for (var j=0; j<insttypes.length; j++) {
23823: if (insttypes[j] != '_LC_external') {
23824: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23825: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23826: var currSel = singleserver.selectedIndex;
23827: var currVal = singleserver.options[currSel].value;
23828: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23829: var numoptions = singleserver.options.length;
23830: var needsnew = 1;
23831: for (var k=0; k<numoptions; k++) {
23832: if (singleserver.options[k] == addtarget) {
23833: needsnew = 0;
23834: break;
23835: }
23836: }
23837: if (needsnew == 1) {
23838: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23839: }
23840: }
23841: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23842: singleserver.options.length = 0;
23843: if ((currVal) && (currVal != removetarget)) {
23844: singleserver.options[0] = new Option("","",false,false);
23845: } else {
23846: singleserver.options[0] = new Option("","",true,true);
23847: }
23848: var idx = 0;
23849: for (var m=0; m<alltargets.length; m++) {
23850: if (currBalancers.indexOf(alltargets[m]) == -1) {
23851: idx ++;
23852: if (currVal == alltargets[m]) {
23853: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23854: } else {
23855: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23856: }
23857: }
23858: }
23859: }
23860: }
23861: }
23862: }
1.150 raeburn 23863: }
23864: }
23865: }
23866: return;
23867: }
23868:
1.152 raeburn 23869: // ]]>
23870: </script>
23871:
23872: END
23873: }
23874:
23875: sub new_spares_js {
23876: my @sparestypes = ('primary','default');
23877: my $types = join("','",@sparestypes);
23878: my $select = &mt('Select');
23879: return <<"END";
23880:
23881: <script type="text/javascript">
23882: // <![CDATA[
23883:
23884: function updateNewSpares(formname,lonhost) {
23885: var types = new Array('$types');
23886: var include = new Array();
23887: var exclude = new Array();
23888: for (var i=0; i<types.length; i++) {
23889: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23890: for (var j=0; j<spareboxes.length; j++) {
23891: if (formname.elements[spareboxes[j]].checked) {
23892: exclude.push(formname.elements[spareboxes[j]].value);
23893: } else {
23894: include.push(formname.elements[spareboxes[j]].value);
23895: }
23896: }
23897: }
23898: for (var i=0; i<types.length; i++) {
23899: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23900: var selIdx = newSpare.selectedIndex;
23901: var currnew = newSpare.options[selIdx].value;
23902: var okSpares = new Array();
23903: for (var j=0; j<newSpare.options.length; j++) {
23904: var possible = newSpare.options[j].value;
23905: if (possible != '') {
23906: if (exclude.indexOf(possible) == -1) {
23907: okSpares.push(possible);
23908: } else {
23909: if (currnew == possible) {
23910: selIdx = 0;
23911: }
23912: }
23913: }
23914: }
23915: for (var k=0; k<include.length; k++) {
23916: if (okSpares.indexOf(include[k]) == -1) {
23917: okSpares.push(include[k]);
23918: }
23919: }
23920: okSpares.sort();
23921: newSpare.options.length = 0;
23922: if (selIdx == 0) {
23923: newSpare.options[0] = new Option("$select","",true,true);
23924: } else {
23925: newSpare.options[0] = new Option("$select","",false,false);
23926: }
23927: for (var m=0; m<okSpares.length; m++) {
23928: var idx = m+1;
23929: var selThis = 0;
23930: if (selIdx != 0) {
23931: if (okSpares[m] == currnew) {
23932: selThis = 1;
23933: }
23934: }
23935: if (selThis == 1) {
23936: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23937: } else {
23938: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23939: }
23940: }
23941: }
23942: return;
23943: }
23944:
23945: function checkNewSpares(lonhost,type) {
23946: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23947: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23948: if (chosen != '') {
1.152 raeburn 23949: var othertype;
23950: var othernewSpare;
23951: if (type == 'primary') {
23952: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23953: }
23954: if (type == 'default') {
23955: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23956: }
23957: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23958: othernewSpare.selectedIndex = 0;
23959: }
23960: }
23961: return;
23962: }
23963:
23964: // ]]>
23965: </script>
23966:
23967: END
23968:
23969: }
23970:
23971: sub common_domprefs_js {
23972: return <<"END";
23973:
23974: <script type="text/javascript">
23975: // <![CDATA[
23976:
1.150 raeburn 23977: function getIndicesByName(formname,item) {
1.152 raeburn 23978: var group = new Array();
1.150 raeburn 23979: for (var i=0;i<formname.elements.length;i++) {
23980: if (formname.elements[i].name == item) {
1.152 raeburn 23981: group.push(formname.elements[i].id);
1.150 raeburn 23982: }
23983: }
1.152 raeburn 23984: return group;
1.150 raeburn 23985: }
23986:
23987: // ]]>
23988: </script>
23989:
23990: END
1.152 raeburn 23991:
1.150 raeburn 23992: }
23993:
1.165 raeburn 23994: sub recaptcha_js {
23995: my %lt = &captcha_phrases();
23996: return <<"END";
23997:
23998: <script type="text/javascript">
23999: // <![CDATA[
24000:
24001: function updateCaptcha(caller,context) {
24002: var privitem;
24003: var pubitem;
24004: var privtext;
24005: var pubtext;
1.269 raeburn 24006: var versionitem;
24007: var versiontext;
1.165 raeburn 24008: if (document.getElementById(context+'_recaptchapub')) {
24009: pubitem = document.getElementById(context+'_recaptchapub');
24010: } else {
24011: return;
24012: }
24013: if (document.getElementById(context+'_recaptchapriv')) {
24014: privitem = document.getElementById(context+'_recaptchapriv');
24015: } else {
24016: return;
24017: }
24018: if (document.getElementById(context+'_recaptchapubtxt')) {
24019: pubtext = document.getElementById(context+'_recaptchapubtxt');
24020: } else {
24021: return;
24022: }
24023: if (document.getElementById(context+'_recaptchaprivtxt')) {
24024: privtext = document.getElementById(context+'_recaptchaprivtxt');
24025: } else {
24026: return;
24027: }
1.269 raeburn 24028: if (document.getElementById(context+'_recaptchaversion')) {
24029: versionitem = document.getElementById(context+'_recaptchaversion');
24030: } else {
24031: return;
24032: }
24033: if (document.getElementById(context+'_recaptchavertxt')) {
24034: versiontext = document.getElementById(context+'_recaptchavertxt');
24035: } else {
24036: return;
24037: }
1.165 raeburn 24038: if (caller.checked) {
24039: if (caller.value == 'recaptcha') {
24040: pubitem.type = 'text';
24041: privitem.type = 'text';
24042: pubitem.size = '40';
24043: privitem.size = '40';
24044: pubtext.innerHTML = "$lt{'pub'}";
24045: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 24046: versionitem.type = 'text';
24047: versionitem.size = '3';
1.289 raeburn 24048: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 24049: } else {
24050: pubitem.type = 'hidden';
24051: privitem.type = 'hidden';
1.269 raeburn 24052: versionitem.type = 'hidden';
1.165 raeburn 24053: pubtext.innerHTML = '';
24054: privtext.innerHTML = '';
1.269 raeburn 24055: versiontext.innerHTML = '';
1.165 raeburn 24056: }
24057: }
24058: return;
24059: }
24060:
24061: // ]]>
24062: </script>
24063:
24064: END
24065:
24066: }
24067:
1.236 raeburn 24068: sub toggle_display_js {
1.192 raeburn 24069: return <<"END";
24070:
24071: <script type="text/javascript">
24072: // <![CDATA[
24073:
1.236 raeburn 24074: function toggleDisplay(domForm,caller) {
24075: if (document.getElementById(caller)) {
24076: var divitem = document.getElementById(caller);
24077: var optionsElement = domForm.coursecredits;
1.264 raeburn 24078: var checkval = 1;
24079: var dispval = 'block';
1.303 raeburn 24080: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 24081: if (caller == 'emailoptions') {
1.372 raeburn 24082: optionsElement = domForm.cancreate_email;
1.236 raeburn 24083: }
1.257 raeburn 24084: if (caller == 'studentsubmission') {
24085: optionsElement = domForm.postsubmit;
24086: }
1.264 raeburn 24087: if (caller == 'cloneinstcode') {
24088: optionsElement = domForm.canclone;
24089: checkval = 'instcode';
24090: }
1.303 raeburn 24091: if (selfcreateRegExp.test(caller)) {
24092: optionsElement = domForm.elements[caller];
24093: checkval = 'other';
24094: dispval = 'inline'
24095: }
1.236 raeburn 24096: if (optionsElement.length) {
1.192 raeburn 24097: var currval;
1.236 raeburn 24098: for (var i=0; i<optionsElement.length; i++) {
24099: if (optionsElement[i].checked) {
24100: currval = optionsElement[i].value;
1.192 raeburn 24101: }
24102: }
1.264 raeburn 24103: if (currval == checkval) {
24104: divitem.style.display = dispval;
1.192 raeburn 24105: } else {
1.236 raeburn 24106: divitem.style.display = 'none';
1.192 raeburn 24107: }
24108: }
24109: }
24110: return;
24111: }
24112:
24113: // ]]>
24114: </script>
24115:
24116: END
24117:
24118: }
24119:
1.165 raeburn 24120: sub captcha_phrases {
24121: return &Apache::lonlocal::texthash (
24122: priv => 'Private key',
24123: pub => 'Public key',
24124: original => 'original (CAPTCHA)',
24125: recaptcha => 'successor (ReCAPTCHA)',
24126: notused => 'unused',
1.289 raeburn 24127: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 24128: );
24129: }
24130:
1.205 raeburn 24131: sub devalidate_remote_domconfs {
1.212 raeburn 24132: my ($dom,$cachekeys) = @_;
24133: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 24134: my %servers = &Apache::lonnet::internet_dom_servers($dom);
24135: my %thismachine;
24136: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 24137: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 24138: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 24139: 'ipaccess','trust');
1.386 raeburn 24140: my %cache_by_lonhost;
24141: if (exists($cachekeys->{'samllanding'})) {
24142: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
24143: my %landing = %{$cachekeys->{'samllanding'}};
24144: my %domservers = &Apache::lonnet::get_servers($dom);
24145: if (keys(%domservers)) {
24146: foreach my $server (keys(%domservers)) {
24147: my @cached;
24148: next if ($thismachine{$server});
24149: if ($landing{$server}) {
24150: push(@cached,&escape('samllanding').':'.&escape($server));
24151: }
24152: if (@cached) {
24153: $cache_by_lonhost{$server} = \@cached;
24154: }
24155: }
24156: }
24157: }
24158: }
1.260 raeburn 24159: if (keys(%servers)) {
1.205 raeburn 24160: foreach my $server (keys(%servers)) {
24161: next if ($thismachine{$server});
1.212 raeburn 24162: my @cached;
24163: foreach my $name (@posscached) {
24164: if ($cachekeys->{$name}) {
1.388 raeburn 24165: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 24166: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 24167: foreach my $key (keys(%{$cachekeys->{$name}})) {
24168: push(@cached,&escape($name).':'.&escape($key));
24169: }
24170: }
24171: } else {
24172: push(@cached,&escape($name).':'.&escape($dom));
24173: }
1.212 raeburn 24174: }
24175: }
1.386 raeburn 24176: if ((exists($cache_by_lonhost{$server})) &&
24177: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
24178: push(@cached,@{$cache_by_lonhost{$server}});
24179: }
1.212 raeburn 24180: if (@cached) {
24181: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
24182: }
1.205 raeburn 24183: }
24184: }
24185: return;
24186: }
24187:
1.3 raeburn 24188: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>