Annotation of loncom/interface/domainprefs.pm, revision 1.447.2.6
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.447.2.6! raeburn 4: # $Id: domainprefs.pm,v 1.447.2.5 2025/01/14 13:38:26 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.429 raeburn 98: used by course owners to request creation of a course.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 106: (official, unofficial, community, textbook, placement, and lti).
1.425 raeburn 107: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.232 raeburn 167: use Apache::lonuserutils();
1.235 raeburn 168: use Apache::loncoursequeueadmin();
1.419 raeburn 169: use Apache::courseprefs();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.373 raeburn 179: use Net::CIDR;
1.424 raeburn 180: use Crypt::CBC;
1.1 raeburn 181:
1.155 raeburn 182: my $registered_cleanup;
183: my $modified_urls;
184:
1.1 raeburn 185: sub handler {
186: my $r=shift;
187: if ($r->header_only) {
188: &Apache::loncommon::content_type($r,'text/html');
189: $r->send_http_header;
190: return OK;
191: }
192:
1.91 raeburn 193: my $context = 'domain';
1.1 raeburn 194: my $dom = $env{'request.role.domain'};
1.5 albertel 195: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 196: if (&Apache::lonnet::allowed('mau',$dom)) {
197: &Apache::loncommon::content_type($r,'text/html');
198: $r->send_http_header;
199: } else {
200: $env{'user.error.msg'}=
201: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
202: return HTTP_NOT_ACCEPTABLE;
203: }
1.155 raeburn 204:
205: $registered_cleanup=0;
206: @{$modified_urls}=();
207:
1.1 raeburn 208: &Apache::lonhtmlcommon::clear_breadcrumbs();
209: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 210: ['phase','actions']);
1.30 raeburn 211: my $phase = 'pickactions';
1.3 raeburn 212: if ( exists($env{'form.phase'}) ) {
213: $phase = $env{'form.phase'};
214: }
1.150 raeburn 215: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 216: my %domconfig =
1.6 raeburn 217: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 218: 'quotas','autoenroll','autoupdate','autocreate',
219: 'directorysrch','usercreation','usermodification',
220: 'contacts','defaults','scantron','coursecategories',
221: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 222: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 223: 'requestauthor','selfenrollment','inststatus',
1.421 raeburn 224: 'ltitools','toolsec','ssl','trust','lti','ltisec',
1.447.2.1 raeburn 225: 'privacy','passwords','wafproxy',
1.429 raeburn 226: 'ipaccess','authordefaults'],$dom);
1.320 raeburn 227: my %encconfig =
1.447.2.1 raeburn 228: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','linkprot'],$dom,undef,1);
1.424 raeburn 229: my ($checked_is_home,$is_home);
1.297 raeburn 230: if (ref($domconfig{'ltitools'}) eq 'HASH') {
231: if (ref($encconfig{'ltitools'}) eq 'HASH') {
1.423 raeburn 232: my $home = &Apache::lonnet::domain($dom,'primary');
233: unless (($home eq 'no_host') || ($home eq '')) {
234: my @ids=&Apache::lonnet::current_machine_ids();
235: if (grep(/^\Q$home\E$/,@ids)) {
236: $is_home = 1;
237: }
238: }
1.425 raeburn 239: $checked_is_home = 1;
1.297 raeburn 240: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 241: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
242: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.421 raeburn 243: $domconfig{'ltitools'}{$id}{'key'} = $encconfig{'ltitools'}{$id}{'key'};
1.423 raeburn 244: if (($is_home) && ($phase eq 'process')) {
245: $domconfig{'ltitools'}{$id}{'secret'} = $encconfig{'ltitools'}{$id}{'secret'};
246: }
1.297 raeburn 247: }
248: }
249: }
250: }
1.320 raeburn 251: if (ref($domconfig{'lti'}) eq 'HASH') {
252: if (ref($encconfig{'lti'}) eq 'HASH') {
1.424 raeburn 253: unless ($checked_is_home) {
254: my $home = &Apache::lonnet::domain($dom,'primary');
255: unless (($home eq 'no_host') || ($home eq '')) {
256: my @ids=&Apache::lonnet::current_machine_ids();
257: if (grep(/^\Q$home\E$/,@ids)) {
258: $is_home = 1;
259: }
260: }
261: $checked_is_home = 1;
262: }
1.320 raeburn 263: foreach my $id (keys(%{$domconfig{'lti'}})) {
264: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
265: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
1.424 raeburn 266: $domconfig{'lti'}{$id}{'key'} = $encconfig{'lti'}{$id}{'key'};
267: if (($is_home) && ($phase eq 'process')) {
268: $domconfig{'lti'}{$id}{'secret'} = $encconfig{'lti'}{$id}{'secret'};
1.320 raeburn 269: }
270: }
271: }
272: }
273: }
1.405 raeburn 274: if (ref($domconfig{'ltisec'}) eq 'HASH') {
1.406 raeburn 275: if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
1.405 raeburn 276: if (ref($encconfig{'linkprot'}) eq 'HASH') {
1.406 raeburn 277: foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
278: unless ($id =~ /^\d+$/) {
279: delete($domconfig{'ltisec'}{'linkprot'}{$id});
280: }
281: if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
1.405 raeburn 282: (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
283: foreach my $item ('key','secret') {
1.406 raeburn 284: $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
1.405 raeburn 285: }
286: }
287: }
288: }
289: }
290: }
1.394 raeburn 291: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
292: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373 raeburn 293: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 294: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 295: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.447.2.1 raeburn 296: 'authordefaults','ltitools','selfenrollment',
1.429 raeburn 297: 'usersessions','ssl','trust','lti');
1.171 raeburn 298: my %existing;
299: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
300: %existing = %{$domconfig{'loadbalancing'}};
301: }
302: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 303: push(@prefs_order,'loadbalancing');
304: }
1.30 raeburn 305: my %prefs = (
306: 'rolecolors' =>
307: { text => 'Default color schemes',
1.67 raeburn 308: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 309: header => [{col1 => 'Student Settings',
310: col2 => '',},
311: {col1 => 'Coordinator Settings',
312: col2 => '',},
313: {col1 => 'Author Settings',
314: col2 => '',},
315: {col1 => 'Administrator Settings',
316: col2 => '',}],
1.230 raeburn 317: print => \&print_rolecolors,
318: modify => \&modify_rolecolors,
1.30 raeburn 319: },
1.110 raeburn 320: 'login' =>
1.30 raeburn 321: { text => 'Log-in page options',
1.67 raeburn 322: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 323: header => [{col1 => 'Log-in Page Items',
324: col2 => '',},
325: {col1 => 'Log-in Help',
1.256 raeburn 326: col2 => 'Value'},
327: {col1 => 'Custom HTML in document head',
1.386 raeburn 328: col2 => 'Value'},
329: {col1 => 'SSO',
330: col2 => 'Dual login: SSO and non-SSO options'},
331: ],
1.230 raeburn 332: print => \&print_login,
333: modify => \&modify_login,
1.30 raeburn 334: },
1.43 raeburn 335: 'defaults' =>
1.236 raeburn 336: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 337: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 338: header => [{col1 => 'Setting',
1.236 raeburn 339: col2 => 'Value'},
340: {col1 => 'Institutional user types',
1.409 raeburn 341: col2 => 'Name displayed'},
342: {col1 => 'Mapping for missing usernames via standard log-in',
343: col2 => 'Rules in use'}],
1.230 raeburn 344: print => \&print_defaults,
345: modify => \&modify_defaults,
1.43 raeburn 346: },
1.381 raeburn 347: 'wafproxy' =>
348: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 349: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 350: header => [{col1 => 'Domain(s)',
351: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 352: },
1.381 raeburn 353: {col1 => 'Domain(s)',
354: col2 => 'WAF Configuration',}],
1.373 raeburn 355: print => \&print_wafproxy,
1.381 raeburn 356: modify => \&modify_wafproxy,
1.373 raeburn 357: },
1.354 raeburn 358: 'passwords' =>
359: { text => 'Passwords (Internal authentication)',
360: help => 'Domain_Configuration_Passwords',
361: header => [{col1 => 'Resetting Forgotten Password',
362: col2 => 'Settings'},
363: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
364: col2 => 'Settings'},
365: {col1 => 'Rules for LON-CAPA Passwords',
366: col2 => 'Settings'},
367: {col1 => 'Course Owner Changing Student Passwords',
368: col2 => 'Settings'}],
369: print => \&print_passwords,
370: modify => \&modify_passwords,
371: },
1.30 raeburn 372: 'quotas' =>
1.429 raeburn 373: { text => 'Blogs, personal pages/timezones, portfolio/quotas',
1.67 raeburn 374: help => 'Domain_Configuration_Quotas',
1.77 raeburn 375: header => [{col1 => 'User affiliation',
1.72 raeburn 376: col2 => 'Available tools',
1.435 raeburn 377: col3 => 'Portfolio quota (MB)',}],
1.230 raeburn 378: print => \&print_quotas,
379: modify => \&modify_quotas,
1.30 raeburn 380: },
381: 'autoenroll' =>
382: { text => 'Auto-enrollment settings',
1.67 raeburn 383: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 384: header => [{col1 => 'Configuration setting',
385: col2 => 'Value(s)'}],
1.230 raeburn 386: print => \&print_autoenroll,
387: modify => \&modify_autoenroll,
1.30 raeburn 388: },
389: 'autoupdate' =>
390: { text => 'Auto-update settings',
1.67 raeburn 391: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 392: header => [{col1 => 'Setting',
393: col2 => 'Value',},
1.131 raeburn 394: {col1 => 'Setting',
395: col2 => 'Affiliation'},
1.43 raeburn 396: {col1 => 'User population',
1.227 bisitz 397: col2 => 'Updatable user data'}],
1.230 raeburn 398: print => \&print_autoupdate,
399: modify => \&modify_autoupdate,
1.30 raeburn 400: },
1.125 raeburn 401: 'autocreate' =>
402: { text => 'Auto-course creation settings',
403: help => 'Domain_Configuration_Auto_Creation',
404: header => [{col1 => 'Configuration Setting',
405: col2 => 'Value',}],
1.230 raeburn 406: print => \&print_autocreate,
407: modify => \&modify_autocreate,
1.125 raeburn 408: },
1.30 raeburn 409: 'directorysrch' =>
1.277 raeburn 410: { text => 'Directory searches',
1.67 raeburn 411: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 412: header => [{col1 => 'Institutional Directory Setting',
413: col2 => 'Value',},
414: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 415: col2 => 'Value',}],
1.230 raeburn 416: print => \&print_directorysrch,
417: modify => \&modify_directorysrch,
1.30 raeburn 418: },
419: 'contacts' =>
1.286 raeburn 420: { text => 'E-mail addresses and helpform',
1.67 raeburn 421: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 422: header => [{col1 => 'Default e-mail addresses',
423: col2 => 'Value',},
424: {col1 => 'Recipient(s) for notifications',
425: col2 => 'Value',},
1.340 raeburn 426: {col1 => 'Nightly status check e-mail',
427: col2 => 'Settings',},
1.286 raeburn 428: {col1 => 'Ask helpdesk form settings',
429: col2 => 'Value',},],
1.230 raeburn 430: print => \&print_contacts,
431: modify => \&modify_contacts,
1.30 raeburn 432: },
433: 'usercreation' =>
434: { text => 'User creation',
1.67 raeburn 435: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 436: header => [{col1 => 'Format rule type',
437: col2 => 'Format rules in force'},
1.34 raeburn 438: {col1 => 'User account creation',
439: col2 => 'Usernames which may be created',},
1.30 raeburn 440: {col1 => 'Context',
1.43 raeburn 441: col2 => 'Assignable authentication types'}],
1.230 raeburn 442: print => \&print_usercreation,
443: modify => \&modify_usercreation,
1.30 raeburn 444: },
1.224 raeburn 445: 'selfcreation' =>
446: { text => 'Users self-creating accounts',
447: help => 'Domain_Configuration_Self_Creation',
448: header => [{col1 => 'Self-creation with institutional username',
449: col2 => 'Enabled?'},
450: {col1 => 'Institutional user type (login/SSO self-creation)',
451: col2 => 'Information user can enter'},
1.303 raeburn 452: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 453: col2 => 'Settings'}],
1.230 raeburn 454: print => \&print_selfcreation,
455: modify => \&modify_selfcreation,
1.224 raeburn 456: },
1.69 raeburn 457: 'usermodification' =>
1.33 raeburn 458: { text => 'User modification',
1.67 raeburn 459: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 460: header => [{col1 => 'Target user has role',
1.227 bisitz 461: col2 => 'User information updatable in author context'},
1.33 raeburn 462: {col1 => 'Target user has role',
1.443 raeburn 463: col2 => 'User information updatable by co-author manager'},
464: {col1 => 'Target user has role',
1.227 bisitz 465: col2 => 'User information updatable in course context'}],
1.230 raeburn 466: print => \&print_usermodification,
467: modify => \&modify_usermodification,
1.33 raeburn 468: },
1.69 raeburn 469: 'scantron' =>
1.346 raeburn 470: { text => 'Bubblesheet format',
1.67 raeburn 471: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 472: header => [ {col1 => 'Bubblesheet format file',
473: col2 => ''},
474: {col1 => 'Bubblesheet data upload formats',
475: col2 => 'Settings'}],
1.230 raeburn 476: print => \&print_scantron,
477: modify => \&modify_scantron,
1.46 raeburn 478: },
1.86 raeburn 479: 'requestcourses' =>
480: {text => 'Request creation of courses',
481: help => 'Domain_Configuration_Request_Courses',
482: header => [{col1 => 'User affiliation',
1.102 raeburn 483: col2 => 'Availability/Processing of requests',},
484: {col1 => 'Setting',
1.216 raeburn 485: col2 => 'Value'},
486: {col1 => 'Available textbooks',
1.235 raeburn 487: col2 => ''},
1.242 raeburn 488: {col1 => 'Available templates',
489: col2 => ''},
1.235 raeburn 490: {col1 => 'Validation (not official courses)',
491: col2 => 'Value'},],
1.230 raeburn 492: print => \&print_quotas,
493: modify => \&modify_quotas,
1.86 raeburn 494: },
1.163 raeburn 495: 'requestauthor' =>
1.223 bisitz 496: {text => 'Request Authoring Space',
1.163 raeburn 497: help => 'Domain_Configuration_Request_Author',
498: header => [{col1 => 'User affiliation',
499: col2 => 'Availability/Processing of requests',},
500: {col1 => 'Setting',
501: col2 => 'Value'}],
1.230 raeburn 502: print => \&print_quotas,
503: modify => \&modify_quotas,
1.163 raeburn 504: },
1.69 raeburn 505: 'coursecategories' =>
1.120 raeburn 506: { text => 'Cataloging of courses/communities',
1.67 raeburn 507: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 508: header => [{col1 => 'Catalog type/availability',
509: col2 => '',},
510: {col1 => 'Category settings for standard catalog',
1.57 raeburn 511: col2 => '',},
512: {col1 => 'Categories',
513: col2 => '',
514: }],
1.230 raeburn 515: print => \&print_coursecategories,
516: modify => \&modify_coursecategories,
1.69 raeburn 517: },
518: 'serverstatuses' =>
1.77 raeburn 519: {text => 'Access to server status pages',
1.69 raeburn 520: help => 'Domain_Configuration_Server_Status',
521: header => [{col1 => 'Status Page',
522: col2 => 'Other named users',
523: col3 => 'Specific IPs',
524: }],
1.230 raeburn 525: print => \&print_serverstatuses,
526: modify => \&modify_serverstatuses,
1.69 raeburn 527: },
1.118 jms 528: 'helpsettings' =>
1.282 raeburn 529: {text => 'Support settings',
1.118 jms 530: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 531: header => [{col1 => 'Help Page Settings (logged-in users)',
532: col2 => 'Value'},
533: {col1 => 'Helpdesk Roles',
534: col2 => 'Settings'},],
1.230 raeburn 535: print => \&print_helpsettings,
536: modify => \&modify_helpsettings,
1.118 jms 537: },
1.121 raeburn 538: 'coursedefaults' =>
539: {text => 'Course/Community defaults',
540: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 541: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
542: col2 => 'Value',},
543: {col1 => 'Defaults which can be overridden for each course by a DC',
544: col2 => 'Value',},],
1.230 raeburn 545: print => \&print_coursedefaults,
546: modify => \&modify_coursedefaults,
1.121 raeburn 547: },
1.231 raeburn 548: 'selfenrollment' =>
549: {text => 'Self-enrollment in Course/Community',
550: help => 'Domain_Configuration_Selfenrollment',
551: header => [{col1 => 'Configuration Rights',
552: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
553: {col1 => 'Defaults',
554: col2 => 'Value'},
555: {col1 => 'Self-enrollment validation (optional)',
556: col2 => 'Value'},],
557: print => \&print_selfenrollment,
558: modify => \&modify_selfenrollment,
559: },
1.120 raeburn 560: 'privacy' =>
1.427 raeburn 561: {text => 'Role assignments and user privacy',
1.120 raeburn 562: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 563: header => [{col1 => 'Role assigned in different domain',
564: col2 => 'Approval options'},
565: {col1 => 'Role assigned in different domain to user of type',
1.447.2.4 raeburn 566: col2 => 'User information available in that domain'}],
1.230 raeburn 567: print => \&print_privacy,
568: modify => \&modify_privacy,
1.120 raeburn 569: },
1.141 raeburn 570: 'usersessions' =>
1.145 raeburn 571: {text => 'User session hosting/offloading',
1.137 raeburn 572: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 573: header => [{col1 => 'Domain server',
574: col2 => 'Servers to offload sessions to when busy'},
575: {col1 => 'Hosting of users from other domains',
1.137 raeburn 576: col2 => 'Rules'},
577: {col1 => "Hosting domain's own users elsewhere",
578: col2 => 'Rules'}],
1.230 raeburn 579: print => \&print_usersessions,
580: modify => \&modify_usersessions,
1.137 raeburn 581: },
1.279 raeburn 582: 'loadbalancing' =>
1.185 raeburn 583: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 584: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 585: header => [{col1 => 'Balancers',
1.150 raeburn 586: col2 => 'Default destinations',
1.183 bisitz 587: col3 => 'User affiliation',
1.150 raeburn 588: col4 => 'Overrides'},
589: ],
1.230 raeburn 590: print => \&print_loadbalancing,
591: modify => \&modify_loadbalancing,
1.150 raeburn 592: },
1.425 raeburn 593: 'ltitools' =>
1.267 raeburn 594: {text => 'External Tools (LTI)',
1.296 raeburn 595: help => 'Domain_Configuration_LTI_Tools',
1.421 raeburn 596: header => [{col1 => 'Encryption of shared secrets',
597: col2 => 'Settings'},
598: {col1 => 'Rules for shared secrets',
599: col2 => 'Settings'},
600: {col1 => 'Providers',
601: col2 => 'Settings',}],
1.267 raeburn 602: print => \&print_ltitools,
603: modify => \&modify_ltitools,
604: },
1.279 raeburn 605: 'ssl' =>
1.275 raeburn 606: {text => 'LON-CAPA Network (SSL)',
607: help => 'Domain_Configuration_Network_SSL',
608: header => [{col1 => 'Server',
609: col2 => 'Certificate Status'},
610: {col1 => 'Connections to other servers',
611: col2 => 'Rules'},
1.293 raeburn 612: {col1 => 'Connections from other servers',
613: col2 => 'Rules'},
1.275 raeburn 614: {col1 => "Replicating domain's published content",
615: col2 => 'Rules'}],
616: print => \&print_ssl,
617: modify => \&modify_ssl,
618: },
1.279 raeburn 619: 'trust' =>
620: {text => 'Trust Settings',
621: help => 'Domain_Configuration_Trust',
622: header => [{col1 => "Access to this domain's content by others",
623: col2 => 'Rules'},
624: {col1 => "Access to other domain's content by this domain",
625: col2 => 'Rules'},
626: {col1 => "Enrollment in this domain's courses by others",
627: col2 => 'Rules',},
628: {col1 => "Co-author roles in this domain for others",
629: col2 => 'Rules',},
630: {col1 => "Co-author roles for this domain's users elsewhere",
631: col2 => 'Rules',},
632: {col1 => "Domain roles in this domain assignable to others",
633: col2 => 'Rules'},
634: {col1 => "Course catalog for this domain displayed elsewhere",
635: col2 => 'Rules'},
636: {col1 => "Requests for creation of courses in this domain by others",
637: col2 => 'Rules'},
638: {col1 => "Users in other domains can send messages to this domain",
639: col2 => 'Rules'},],
640: print => \&print_trust,
641: modify => \&modify_trust,
642: },
1.425 raeburn 643: 'lti' =>
1.405 raeburn 644: {text => 'LTI Link Protection and LTI Consumers',
1.320 raeburn 645: help => 'Domain_Configuration_LTI_Provider',
1.405 raeburn 646: header => [{col1 => 'Encryption of shared secrets',
647: col2 => 'Settings'},
1.425 raeburn 648: {col1 => 'Rules for shared secrets',
1.405 raeburn 649: col2 => 'Settings'},
1.434 raeburn 650: {col1 => 'Link Protectors in Courses',
1.436 raeburn 651: col2 => 'Values'},
1.406 raeburn 652: {col1 => 'Link Protectors',
1.405 raeburn 653: col2 => 'Settings'},
654: {col1 => 'Consumers',
655: col2 => 'Settings'},],
1.320 raeburn 656: print => \&print_lti,
657: modify => \&modify_lti,
658: },
1.425 raeburn 659: 'ipaccess' =>
1.394 raeburn 660: {text => 'IP-based access control',
661: help => 'Domain_Configuration_IP_Access',
662: header => [{col1 => 'Setting',
663: col2 => 'Value'},],
664: print => \&print_ipaccess,
665: modify => \&modify_ipaccess,
666: },
1.436 raeburn 667: 'authordefaults' =>
1.429 raeburn 668: {text => 'Authoring Space defaults',
669: help => 'Domain_Configuration_Author_Defaults',
670: header => [{col1 => 'Defaults which can be overridden by Author',
671: col2 => 'Settings',},
672: {col1 => 'Defaults which can be overridden by a Dom. Coord.',
673: col2 => 'Settings',},],
674: print => \&print_authordefaults,
675: modify => \&modify_authordefaults,
676: },
1.3 raeburn 677: );
1.110 raeburn 678: if (keys(%servers) > 1) {
679: $prefs{'login'} = { text => 'Log-in page options',
680: help => 'Domain_Configuration_Login_Page',
681: header => [{col1 => 'Log-in Service',
682: col2 => 'Server Setting',},
683: {col1 => 'Log-in Page Items',
1.405 raeburn 684: col2 => 'Settings'},
1.168 raeburn 685: {col1 => 'Log-in Help',
1.256 raeburn 686: col2 => 'Value'},
687: {col1 => 'Custom HTML in document head',
1.386 raeburn 688: col2 => 'Value'},
689: {col1 => 'SSO',
690: col2 => 'Dual login: SSO and non-SSO options'},
691: ],
1.230 raeburn 692: print => \&print_login,
693: modify => \&modify_login,
1.110 raeburn 694: };
695: }
1.174 foxr 696:
1.6 raeburn 697: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 698: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 699: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 700: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 701: text=>"Settings to display/modify"});
1.9 raeburn 702: my $confname = $dom.'-domainconfig';
1.174 foxr 703:
1.3 raeburn 704: if ($phase eq 'process') {
1.212 raeburn 705: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
706: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 707: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 708: $r->rflush();
1.212 raeburn 709: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 710: }
1.30 raeburn 711: } elsif ($phase eq 'display') {
1.192 raeburn 712: my $js = &recaptcha_js().
1.236 raeburn 713: &toggle_display_js();
1.171 raeburn 714: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 715: my ($othertitle,$usertypes,$types) =
716: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 717: $js .= &lonbalance_targets_js($dom,$types,\%servers,
718: $domconfig{'loadbalancing'}).
1.170 raeburn 719: &new_spares_js().
720: &common_domprefs_js().
721: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 722: }
1.216 raeburn 723: if (grep(/^requestcourses$/,@actions)) {
724: my $javascript_validations;
725: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
726: $js .= <<END;
727: <script type="text/javascript">
728: $javascript_validations
729: </script>
730: $coursebrowserjs
731: END
1.394 raeburn 732: } elsif (grep(/^ipaccess$/,@actions)) {
733: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 734: }
1.305 raeburn 735: if (grep(/^selfcreation$/,@actions)) {
736: $js .= &selfcreate_javascript();
737: }
1.286 raeburn 738: if (grep(/^contacts$/,@actions)) {
739: $js .= &contacts_javascript();
740: }
1.346 raeburn 741: if (grep(/^scantron$/,@actions)) {
742: $js .= &scantron_javascript();
743: }
1.150 raeburn 744: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 745: } else {
1.180 raeburn 746: # check if domconfig user exists for the domain.
747: my $servadm = $r->dir_config('lonAdmEMail');
748: my ($configuserok,$author_ok,$switchserver) =
749: &config_check($dom,$confname,$servadm);
750: unless ($configuserok eq 'ok') {
1.181 raeburn 751: &Apache::lonconfigsettings::print_header($r,$phase,$context);
752: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 753: $confname).
1.181 raeburn 754: '<br />'
755: );
1.180 raeburn 756: if ($switchserver) {
1.181 raeburn 757: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
758: '<br />'.
759: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
760: '<br />'.
761: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
762: '<br />'.
763: &mt('To do that now, use the following link: [_1]',$switchserver)
764: );
765: } else {
766: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
767: '<br />'.
768: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
769: );
1.180 raeburn 770: }
771: $r->print(&Apache::loncommon::end_page());
772: return OK;
773: }
1.21 raeburn 774: if (keys(%domconfig) == 0) {
775: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 776: my @ids=&Apache::lonnet::current_machine_ids();
777: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 778: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 779: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 780: my $custom_img_count = 0;
781: foreach my $img (@loginimages) {
782: if ($designhash{$dom.'.login.'.$img} ne '') {
783: $custom_img_count ++;
784: }
785: }
786: foreach my $role (@roles) {
787: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
788: $custom_img_count ++;
789: }
790: }
791: if ($custom_img_count > 0) {
1.94 raeburn 792: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 793: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 794: $r->print(
795: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
796: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
797: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
798: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
799: if ($switch_server) {
1.30 raeburn 800: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 801: }
1.91 raeburn 802: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 803: return OK;
804: }
805: }
806: }
1.91 raeburn 807: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 808: }
809: return OK;
810: }
811:
812: sub process_changes {
1.205 raeburn 813: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 814: my %domconfig;
815: if (ref($values) eq 'HASH') {
816: %domconfig = %{$values};
817: }
1.3 raeburn 818: my $output;
819: if ($action eq 'login') {
1.205 raeburn 820: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 821: } elsif ($action eq 'rolecolors') {
1.9 raeburn 822: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 823: $lastactref,%domconfig);
1.3 raeburn 824: } elsif ($action eq 'quotas') {
1.216 raeburn 825: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 826: } elsif ($action eq 'autoenroll') {
1.205 raeburn 827: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 828: } elsif ($action eq 'autoupdate') {
829: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 830: } elsif ($action eq 'autocreate') {
831: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 832: } elsif ($action eq 'directorysrch') {
1.295 raeburn 833: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 834: } elsif ($action eq 'usercreation') {
1.28 raeburn 835: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 836: } elsif ($action eq 'selfcreation') {
1.305 raeburn 837: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 838: } elsif ($action eq 'usermodification') {
839: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 840: } elsif ($action eq 'contacts') {
1.205 raeburn 841: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 842: } elsif ($action eq 'defaults') {
1.212 raeburn 843: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 844: } elsif ($action eq 'scantron') {
1.205 raeburn 845: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 846: } elsif ($action eq 'coursecategories') {
1.239 raeburn 847: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 848: } elsif ($action eq 'serverstatuses') {
849: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 850: } elsif ($action eq 'requestcourses') {
1.216 raeburn 851: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 852: } elsif ($action eq 'requestauthor') {
1.216 raeburn 853: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 854: } elsif ($action eq 'helpsettings') {
1.285 raeburn 855: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 856: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 857: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 858: } elsif ($action eq 'selfenrollment') {
859: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 860: } elsif ($action eq 'usersessions') {
1.212 raeburn 861: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 862: } elsif ($action eq 'loadbalancing') {
863: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 864: } elsif ($action eq 'ltitools') {
865: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 866: } elsif ($action eq 'ssl') {
867: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 868: } elsif ($action eq 'trust') {
869: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 870: } elsif ($action eq 'lti') {
871: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 872: } elsif ($action eq 'privacy') {
1.427 raeburn 873: $output = &modify_privacy($dom,$lastactref,%domconfig);
1.354 raeburn 874: } elsif ($action eq 'passwords') {
875: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 876: } elsif ($action eq 'wafproxy') {
877: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 878: } elsif ($action eq 'ipaccess') {
879: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.429 raeburn 880: } elsif ($action eq 'authordefaults') {
881: $output = &modify_authordefaults($dom,$lastactref,%domconfig);
1.3 raeburn 882: }
883: return $output;
884: }
885:
886: sub print_config_box {
1.9 raeburn 887: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 888: my $rowtotal = 0;
1.49 raeburn 889: my $output;
890: if ($action eq 'coursecategories') {
891: $output = &coursecategories_javascript($settings);
1.236 raeburn 892: } elsif ($action eq 'defaults') {
893: $output = &defaults_javascript($settings);
1.354 raeburn 894: } elsif ($action eq 'passwords') {
1.405 raeburn 895: $output = &passwords_javascript($action);
1.282 raeburn 896: } elsif ($action eq 'helpsettings') {
897: my (%privs,%levelscurrent);
898: my %full=();
899: my %levels=(
900: course => {},
901: domain => {},
902: system => {},
903: );
904: my $context = 'domain';
905: my $crstype = 'Course';
906: my $formname = 'display';
907: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
908: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
909: $output =
1.425 raeburn 910: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
1.282 raeburn 911: \@templateroles);
1.334 raeburn 912: } elsif ($action eq 'ltitools') {
1.421 raeburn 913: $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
1.334 raeburn 914: } elsif ($action eq 'lti') {
1.421 raeburn 915: $output .= &passwords_javascript('ltisecrets')."\n".
1.405 raeburn 916: <i_javascript($dom,$settings);
1.381 raeburn 917: } elsif ($action eq 'wafproxy') {
918: $output .= &wafproxy_javascript($dom);
1.385 raeburn 919: } elsif ($action eq 'autoupdate') {
920: $output .= &autoupdate_javascript();
1.399 raeburn 921: } elsif ($action eq 'autoenroll') {
922: $output .= &autoenroll_javascript();
1.386 raeburn 923: } elsif ($action eq 'login') {
924: $output .= &saml_javascript();
1.394 raeburn 925: } elsif ($action eq 'ipaccess') {
926: $output .= &ipaccess_javascript($settings);
1.429 raeburn 927: } elsif ($action eq 'authordefaults') {
928: $output .= &authordefaults_javascript();
1.91 raeburn 929: }
1.236 raeburn 930: $output .=
1.30 raeburn 931: '<table class="LC_nested_outer">
1.3 raeburn 932: <tr>
1.306 raeburn 933: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 934: &mt($item->{text}).' '.
935: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
936: '</tr>';
1.30 raeburn 937: $rowtotal ++;
1.110 raeburn 938: my $numheaders = 1;
939: if (ref($item->{'header'}) eq 'ARRAY') {
940: $numheaders = scalar(@{$item->{'header'}});
941: }
942: if ($numheaders > 1) {
1.64 raeburn 943: my $colspan = '';
1.145 raeburn 944: my $rightcolspan = '';
1.369 raeburn 945: my $leftnobr = '';
1.238 raeburn 946: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 947: ($action eq 'directorysrch') ||
1.386 raeburn 948: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 949: $colspan = ' colspan="2"';
950: }
1.145 raeburn 951: if ($action eq 'usersessions') {
952: $rightcolspan = ' colspan="3"';
953: }
1.369 raeburn 954: if ($action eq 'passwords') {
955: $leftnobr = ' LC_nobreak';
956: }
1.30 raeburn 957: $output .= '
1.3 raeburn 958: <tr>
959: <td>
960: <table class="LC_nested">
961: <tr class="LC_info_row">
1.369 raeburn 962: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 963: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 964: </tr>';
1.69 raeburn 965: $rowtotal ++;
1.230 raeburn 966: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 967: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 968: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 969: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.421 raeburn 970: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') ||
1.429 raeburn 971: ($action eq 'lti') || ($action eq 'ltitools') || ($action eq 'authordefaults')) {
1.230 raeburn 972: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 973: } elsif ($action eq 'passwords') {
974: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 975: } elsif ($action eq 'coursecategories') {
1.230 raeburn 976: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 977: } elsif ($action eq 'scantron') {
978: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 979: } elsif ($action eq 'login') {
1.386 raeburn 980: if ($numheaders == 5) {
1.168 raeburn 981: $colspan = ' colspan="2"';
982: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
983: } else {
984: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
985: }
1.230 raeburn 986: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 987: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 988: } elsif ($action eq 'rolecolors') {
1.30 raeburn 989: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 990: }
1.30 raeburn 991: $output .= '
1.6 raeburn 992: </table>
993: </td>
994: </tr>
995: <tr>
996: <td>
997: <table class="LC_nested">
998: <tr class="LC_info_row">
1.230 raeburn 999: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 1000: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 1001: </tr>';
1002: $rowtotal ++;
1.230 raeburn 1003: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
1004: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 1005: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 1006: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.447.2.4 raeburn 1007: ($action eq 'passwords') || ($action eq 'lti') || ($action eq 'ltitools') ||
1008: ($action eq 'usermodification')) {
1.238 raeburn 1009: if ($action eq 'coursecategories') {
1010: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
1011: $colspan = ' colspan="2"';
1.279 raeburn 1012: } elsif ($action eq 'trust') {
1013: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 1014: } elsif ($action eq 'passwords') {
1015: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.434 raeburn 1016: } elsif ($action eq 'lti') {
1017: $output .= $item->{'print'}->('upper',$dom,$settings,\$rowtotal).'
1018: </table>
1019: </td>
1020: </tr>
1021: <tr>
1022: <td>
1023: <table class="LC_nested">
1024: <tr class="LC_info_row">
1025: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1026: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1027: </tr>'."\n".
1028: $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1.238 raeburn 1029: } else {
1030: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1031: }
1.279 raeburn 1032: if ($action eq 'trust') {
1033: $output .= '
1034: </table>
1035: </td>
1036: </tr>';
1037: my @trusthdrs = qw(2 3 4 5 6 7);
1038: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1039: for (my $i=0; $i<@trusthdrs; $i++) {
1040: $output .= '
1041: <tr>
1042: <td>
1043: <table class="LC_nested">
1044: <tr class="LC_info_row">
1045: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1046: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1047: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1048: </table>
1049: </td>
1050: </tr>';
1051: }
1052: $output .= '
1053: <tr>
1054: <td>
1055: <table class="LC_nested">
1056: <tr class="LC_info_row">
1057: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1058: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1059: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1060: } else {
1.434 raeburn 1061: my $hdridx = 2;
1062: if ($action eq 'lti') {
1063: $hdridx = 3;
1064: }
1.279 raeburn 1065: $output .= '
1.63 raeburn 1066: </table>
1067: </td>
1068: </tr>
1069: <tr>
1070: <td>
1071: <table class="LC_nested">
1072: <tr class="LC_info_row">
1.434 raeburn 1073: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1074: <td class="LC_right_item">'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td>
1.238 raeburn 1075: </tr>'."\n";
1.279 raeburn 1076: if ($action eq 'coursecategories') {
1077: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.447.2.4 raeburn 1078: } elsif (($action eq 'contacts') || ($action eq 'passwords') ||
1079: ($action eq 'lti')) {
1.354 raeburn 1080: if ($action eq 'passwords') {
1081: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1082: } else {
1083: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1084: }
1.434 raeburn 1085: $hdridx ++;
1.354 raeburn 1086: $output .= '
1.340 raeburn 1087: </tr>
1088: </table>
1089: </td>
1090: </tr>
1091: <tr>
1092: <td>
1093: <table class="LC_nested">
1094: <tr class="LC_info_row">
1.434 raeburn 1095: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1096: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td></tr>'."\n";
1.354 raeburn 1097: if ($action eq 'passwords') {
1098: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1099: } else {
1100: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1101: }
1102: $output .= '
1.340 raeburn 1103: </table>
1104: </td>
1105: </tr>
1106: <tr>';
1.279 raeburn 1107: } else {
1108: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1109: }
1.238 raeburn 1110: }
1.63 raeburn 1111: $rowtotal ++;
1.443 raeburn 1112: } elsif (($action eq 'coursedefaults') || ($action eq 'authordefaults') ||
1.409 raeburn 1113: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1.447.2.4 raeburn 1114: ($action eq 'wafproxy') || ($action eq 'privacy')) {
1.230 raeburn 1115: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1116: } elsif ($action eq 'scantron') {
1117: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1118: } elsif ($action eq 'ssl') {
1119: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1120: </table>
1121: </td>
1122: </tr>
1123: <tr>
1124: <td>
1125: <table class="LC_nested">
1126: <tr class="LC_info_row">
1127: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1128: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1129: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1130: </table>
1131: </td>
1132: </tr>
1133: <tr>
1134: <td>
1135: <table class="LC_nested">
1136: <tr class="LC_info_row">
1137: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1138: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1139: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1140: } elsif ($action eq 'login') {
1.386 raeburn 1141: if ($numheaders == 5) {
1.168 raeburn 1142: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1143: </table>
1144: </td>
1145: </tr>
1146: <tr>
1147: <td>
1148: <table class="LC_nested">
1149: <tr class="LC_info_row">
1150: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1151: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1152: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1153: $rowtotal ++;
1154: } else {
1155: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1156: }
1.256 raeburn 1157: $output .= '
1158: </table>
1159: </td>
1160: </tr>
1161: <tr>
1162: <td>
1163: <table class="LC_nested">
1164: <tr class="LC_info_row">';
1.386 raeburn 1165: if ($numheaders == 5) {
1.256 raeburn 1166: $output .= '
1167: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1168: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1169: </tr>';
1170: } else {
1171: $output .= '
1172: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1173: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1174: </tr>';
1175: }
1176: $rowtotal ++;
1.386 raeburn 1177: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1178: </table>
1179: </td>
1180: </tr>
1181: <tr>
1182: <td>
1183: <table class="LC_nested">
1184: <tr class="LC_info_row">';
1185: if ($numheaders == 5) {
1186: $output .= '
1187: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1188: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1189: </tr>';
1190: } else {
1191: $output .= '
1192: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1193: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1194: </tr>';
1195: }
1196: $rowtotal ++;
1197: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1198: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1199: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1200: $rowtotal ++;
1201: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1202: </table>
1203: </td>
1204: </tr>
1205: <tr>
1206: <td>
1207: <table class="LC_nested">
1208: <tr class="LC_info_row">
1209: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1210: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1211: &textbookcourses_javascript($settings).
1212: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1213: </table>
1214: </td>
1215: </tr>
1216: <tr>
1217: <td>
1218: <table class="LC_nested">
1219: <tr class="LC_info_row">
1220: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1221: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1222: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1223: </table>
1224: </td>
1225: </tr>
1226: <tr>
1227: <td>
1228: <table class="LC_nested">
1229: <tr class="LC_info_row">
1.306 raeburn 1230: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1231: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1232: </tr>'.
1233: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1234: } elsif ($action eq 'requestauthor') {
1235: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1236: $rowtotal ++;
1.122 jms 1237: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1238: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1239: </table>
1240: </td>
1241: </tr>
1242: <tr>
1243: <td>
1244: <table class="LC_nested">
1245: <tr class="LC_info_row">
1.306 raeburn 1246: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1247: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1248: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1249: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1250: </tr>'.
1.30 raeburn 1251: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1252: </table>
1253: </td>
1254: </tr>
1255: <tr>
1256: <td>
1257: <table class="LC_nested">
1258: <tr class="LC_info_row">
1.59 bisitz 1259: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1260: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1261: </tr>'.
1.30 raeburn 1262: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1263: $rowtotal += 2;
1.6 raeburn 1264: }
1.3 raeburn 1265: } else {
1.30 raeburn 1266: $output .= '
1.3 raeburn 1267: <tr>
1268: <td>
1269: <table class="LC_nested">
1.30 raeburn 1270: <tr class="LC_info_row">';
1.277 raeburn 1271: if ($action eq 'login') {
1.30 raeburn 1272: $output .= '
1.59 bisitz 1273: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1274: } elsif ($action eq 'serverstatuses') {
1275: $output .= '
1.306 raeburn 1276: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1277: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1278:
1.6 raeburn 1279: } else {
1.30 raeburn 1280: $output .= '
1.306 raeburn 1281: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1282: }
1.72 raeburn 1283: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1284: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1285: &mt($item->{'header'}->[0]->{'col2'});
1286: if ($action eq 'serverstatuses') {
1287: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1288: }
1.69 raeburn 1289: } else {
1.306 raeburn 1290: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1291: &mt($item->{'header'}->[0]->{'col2'});
1292: }
1293: $output .= '</td>';
1294: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1295: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1296: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1297: &mt($item->{'header'}->[0]->{'col3'});
1298: } else {
1.306 raeburn 1299: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1300: &mt($item->{'header'}->[0]->{'col3'});
1301: }
1.69 raeburn 1302: if ($action eq 'serverstatuses') {
1303: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1304: }
1305: $output .= '</td>';
1.6 raeburn 1306: }
1.150 raeburn 1307: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1308: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1309: &mt($item->{'header'}->[0]->{'col4'});
1310: }
1.69 raeburn 1311: $output .= '</tr>';
1.48 raeburn 1312: $rowtotal ++;
1.168 raeburn 1313: if ($action eq 'quotas') {
1.86 raeburn 1314: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1315: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1316: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.447.2.1 raeburn 1317: ($action eq 'ipaccess')) {
1.230 raeburn 1318: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1319: }
1.3 raeburn 1320: }
1.30 raeburn 1321: $output .= '
1.3 raeburn 1322: </table>
1323: </td>
1324: </tr>
1.30 raeburn 1325: </table><br />';
1326: return ($output,$rowtotal);
1.1 raeburn 1327: }
1328:
1.3 raeburn 1329: sub print_login {
1.168 raeburn 1330: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1331: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1332: my %choices = &login_choices();
1.386 raeburn 1333: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1334: %lt = &login_file_options();
1335: $switchserver = &check_switchserver($dom,$confname);
1336: }
1.168 raeburn 1337: if ($caller eq 'service') {
1.149 raeburn 1338: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1339: my $choice = $choices{'disallowlogin'};
1340: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1341: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1342: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1343: '<th>'.$choices{'server'}.'</th>'.
1344: '<th>'.$choices{'serverpath'}.'</th>'.
1345: '<th>'.$choices{'custompath'}.'</th>'.
1346: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1347: my %disallowed;
1348: if (ref($settings) eq 'HASH') {
1349: if (ref($settings->{'loginvia'}) eq 'HASH') {
1350: %disallowed = %{$settings->{'loginvia'}};
1351: }
1352: }
1353: foreach my $lonhost (sort(keys(%servers))) {
1354: my $direct = 'selected="selected"';
1.128 raeburn 1355: if (ref($disallowed{$lonhost}) eq 'HASH') {
1356: if ($disallowed{$lonhost}{'server'} ne '') {
1357: $direct = '';
1358: }
1.110 raeburn 1359: }
1.115 raeburn 1360: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1361: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1362: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1363: '</option>';
1.184 raeburn 1364: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1365: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1366: my $selected = '';
1.128 raeburn 1367: if (ref($disallowed{$lonhost}) eq 'HASH') {
1368: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1369: $selected = 'selected="selected"';
1370: }
1.110 raeburn 1371: }
1372: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1373: $servers{$hostid}.'</option>';
1374: }
1.128 raeburn 1375: $datatable .= '</select></td>'.
1376: '<td><select name="'.$lonhost.'_serverpath">';
1377: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1378: my $pathname = $path;
1379: if ($path eq 'custom') {
1380: $pathname = &mt('Custom Path').' ->';
1381: }
1382: my $selected = '';
1383: if (ref($disallowed{$lonhost}) eq 'HASH') {
1384: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1385: $selected = 'selected="selected"';
1386: }
1387: } elsif ($path eq '') {
1388: $selected = 'selected="selected"';
1389: }
1390: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1391: }
1392: $datatable .= '</select></td>';
1393: my ($custom,$exempt);
1394: if (ref($disallowed{$lonhost}) eq 'HASH') {
1395: $custom = $disallowed{$lonhost}{'custompath'};
1396: $exempt = $disallowed{$lonhost}{'exempt'};
1397: }
1398: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1399: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1400: '</tr>';
1.110 raeburn 1401: }
1402: $datatable .= '</table></td></tr>';
1403: return $datatable;
1.168 raeburn 1404: } elsif ($caller eq 'page') {
1405: my %defaultchecked = (
1406: 'coursecatalog' => 'on',
1.188 raeburn 1407: 'helpdesk' => 'on',
1.168 raeburn 1408: 'adminmail' => 'off',
1409: 'newuser' => 'off',
1410: );
1.188 raeburn 1411: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1412: my (%checkedon,%checkedoff);
1.42 raeburn 1413: foreach my $item (@toggles) {
1.168 raeburn 1414: if ($defaultchecked{$item} eq 'on') {
1415: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1416: $checkedoff{$item} = ' ';
1.168 raeburn 1417: } elsif ($defaultchecked{$item} eq 'off') {
1418: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1419: $checkedon{$item} = ' ';
1420: }
1.1 raeburn 1421: }
1.168 raeburn 1422: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1423: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1424: my @logintext = ('textcol','bgcol');
1425: my @bgs = ('pgbg','mainbg','sidebg');
1426: my @links = ('link','alink','vlink');
1427: my %designhash = &Apache::loncommon::get_domainconf($dom);
1428: my %defaultdesign = %Apache::loncommon::defaultdesign;
1429: my (%is_custom,%designs);
1430: my %defaults = (
1431: font => $defaultdesign{'login.font'},
1432: );
1.6 raeburn 1433: foreach my $item (@images) {
1.168 raeburn 1434: $defaults{$item} = $defaultdesign{'login.'.$item};
1435: $defaults{'showlogo'}{$item} = 1;
1436: }
1437: foreach my $item (@bgs) {
1438: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1439: }
1.41 raeburn 1440: foreach my $item (@logintext) {
1.168 raeburn 1441: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1442: }
1.168 raeburn 1443: foreach my $item (@links) {
1444: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1445: }
1.168 raeburn 1446: if (ref($settings) eq 'HASH') {
1447: foreach my $item (@toggles) {
1448: if ($settings->{$item} eq '1') {
1449: $checkedon{$item} = ' checked="checked" ';
1450: $checkedoff{$item} = ' ';
1451: } elsif ($settings->{$item} eq '0') {
1452: $checkedoff{$item} = ' checked="checked" ';
1453: $checkedon{$item} = ' ';
1454: }
1455: }
1456: foreach my $item (@images) {
1457: if (defined($settings->{$item})) {
1458: $designs{$item} = $settings->{$item};
1459: $is_custom{$item} = 1;
1460: }
1461: if (defined($settings->{'showlogo'}{$item})) {
1462: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1463: }
1464: }
1.402 raeburn 1465: foreach my $item (@alttext) {
1466: if (ref($settings->{'alttext'}) eq 'HASH') {
1467: if ($settings->{'alttext'}->{$item} ne '') {
1468: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1469: }
1470: }
1471: }
1.168 raeburn 1472: foreach my $item (@logintext) {
1473: if ($settings->{$item} ne '') {
1474: $designs{'logintext'}{$item} = $settings->{$item};
1475: $is_custom{$item} = 1;
1476: }
1477: }
1478: if ($settings->{'font'} ne '') {
1479: $designs{'font'} = $settings->{'font'};
1480: $is_custom{'font'} = 1;
1481: }
1482: foreach my $item (@bgs) {
1483: if ($settings->{$item} ne '') {
1484: $designs{'bgs'}{$item} = $settings->{$item};
1485: $is_custom{$item} = 1;
1486: }
1487: }
1488: foreach my $item (@links) {
1489: if ($settings->{$item} ne '') {
1490: $designs{'links'}{$item} = $settings->{$item};
1491: $is_custom{$item} = 1;
1492: }
1493: }
1494: } else {
1495: if ($designhash{$dom.'.login.font'} ne '') {
1496: $designs{'font'} = $designhash{$dom.'.login.font'};
1497: $is_custom{'font'} = 1;
1498: }
1499: foreach my $item (@images) {
1500: if ($designhash{$dom.'.login.'.$item} ne '') {
1501: $designs{$item} = $designhash{$dom.'.login.'.$item};
1502: $is_custom{$item} = 1;
1503: }
1504: }
1505: foreach my $item (@bgs) {
1506: if ($designhash{$dom.'.login.'.$item} ne '') {
1507: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1508: $is_custom{$item} = 1;
1509: }
1.6 raeburn 1510: }
1.168 raeburn 1511: foreach my $item (@links) {
1512: if ($designhash{$dom.'.login.'.$item} ne '') {
1513: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1514: $is_custom{$item} = 1;
1515: }
1.6 raeburn 1516: }
1517: }
1.168 raeburn 1518: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1519: logo => 'Institution Logo',
1520: domlogo => 'Domain Logo',
1521: login => 'Login box');
1522: my $itemcount = 1;
1523: foreach my $item (@toggles) {
1524: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1525: $datatable .=
1526: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1527: '</td><td>'.
1528: '<span class="LC_nobreak"><label><input type="radio" name="'.
1529: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1530: '</label> <label><input type="radio" name="'.$item.'"'.
1531: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1532: '</tr>';
1533: $itemcount ++;
1.6 raeburn 1534: }
1.168 raeburn 1535: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1536: $datatable .= '</tr></table></td></tr>';
1537: } elsif ($caller eq 'help') {
1.386 raeburn 1538: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1539: my $itemcount = 1;
1540: $defaulturl = '/adm/loginproblems.html';
1541: $defaulttype = 'default';
1542: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1543: my @currlangs;
1544: if (ref($settings) eq 'HASH') {
1545: if (ref($settings->{'helpurl'}) eq 'HASH') {
1546: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1547: next if ($settings->{'helpurl'}{$key} eq '');
1548: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1549: $type{$key} = 'custom';
1550: unless ($key eq 'nolang') {
1551: push(@currlangs,$key);
1552: }
1553: }
1554: } elsif ($settings->{'helpurl'} ne '') {
1555: $type{'nolang'} = 'custom';
1556: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1557: }
1558: }
1.168 raeburn 1559: foreach my $lang ('nolang',sort(@currlangs)) {
1560: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1561: $datatable .= '<tr'.$css_class.'>';
1562: if ($url{$lang} eq '') {
1563: $url{$lang} = $defaulturl;
1564: }
1565: if ($type{$lang} eq '') {
1566: $type{$lang} = $defaulttype;
1567: }
1568: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1569: if ($lang eq 'nolang') {
1570: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1571: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1572: } else {
1573: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1574: $langchoices{$lang},
1575: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1576: }
1577: $datatable .= '</span></td>'."\n".
1578: '<td class="LC_left_item">';
1579: if ($type{$lang} eq 'custom') {
1580: $datatable .= '<span class="LC_nobreak"><label>'.
1581: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1582: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1583: } else {
1584: $datatable .= $lt{'upl'};
1585: }
1586: $datatable .='<br />';
1587: if ($switchserver) {
1588: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1589: } else {
1590: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1591: }
1.168 raeburn 1592: $datatable .= '</td></tr>';
1593: $itemcount ++;
1.6 raeburn 1594: }
1.168 raeburn 1595: my @addlangs;
1596: foreach my $lang (sort(keys(%langchoices))) {
1597: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1598: push(@addlangs,$lang);
1599: }
1600: if (@addlangs > 0) {
1601: my %toadd;
1602: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1603: $toadd{''} = &mt('Select');
1604: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1605: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1606: &mt('Add log-in help page for a specific language:').' '.
1607: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1608: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1609: if ($switchserver) {
1610: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1611: } else {
1612: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1613: }
1.168 raeburn 1614: $datatable .= '</td></tr>';
1.169 raeburn 1615: $itemcount ++;
1.6 raeburn 1616: }
1.169 raeburn 1617: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1618: } elsif ($caller eq 'headtag') {
1619: my %domservers = &Apache::lonnet::get_servers($dom);
1620: my $choice = $choices{'headtag'};
1621: $css_class = ' class="LC_odd_row"';
1622: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1623: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1624: '<th>'.$choices{'current'}.'</th>'.
1625: '<th>'.$choices{'action'}.'</th>'.
1626: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1627: my (%currurls,%currexempt);
1628: if (ref($settings) eq 'HASH') {
1629: if (ref($settings->{'headtag'}) eq 'HASH') {
1630: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1631: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1632: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1633: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1634: }
1635: }
1636: }
1637: }
1638: foreach my $lonhost (sort(keys(%domservers))) {
1639: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1640: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1641: if ($currurls{$lonhost}) {
1642: $datatable .= '<td class="LC_right_item"><a href="'.
1643: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1644: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1645: '">'.$lt{'curr'}.'</a></td>'.
1646: '<td><span class="LC_nobreak"><label>'.
1647: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1648: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1649: } else {
1650: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1651: }
1652: $datatable .='<br />';
1653: if ($switchserver) {
1654: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1655: } else {
1656: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1657: }
1.330 raeburn 1658: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1659: }
1660: $datatable .= '</table></td></tr>';
1.386 raeburn 1661: } elsif ($caller eq 'saml') {
1662: my %domservers = &Apache::lonnet::get_servers($dom);
1663: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1664: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1665: '<th>'.$choices{'samllanding'}.'</th>'.
1666: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1667: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1668: foreach my $lonhost (keys(%domservers)) {
1669: $samlurl{$lonhost} = '/adm/sso';
1670: $styleon{$lonhost} = 'display:none';
1671: $styleoff{$lonhost} = '';
1672: }
1.411 raeburn 1673: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1674: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1675: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1676: $saml{$lonhost} = 1;
1677: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1678: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1679: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1680: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1681: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1682: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1683: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1684: $styleon{$lonhost} = '';
1685: $styleoff{$lonhost} = 'display:none';
1686: } else {
1687: $styleon{$lonhost} = 'display:none';
1688: $styleoff{$lonhost} = '';
1689: }
1690: }
1691: }
1692: my $itemcount = 1;
1693: foreach my $lonhost (sort(keys(%domservers))) {
1694: my $samlon = ' ';
1695: my $samloff = ' checked="checked" ';
1696: if ($saml{$lonhost}) {
1697: $samlon = $samloff;
1698: $samloff = ' ';
1699: }
1.412 raeburn 1700: my $samlwinon = '';
1701: my $samlwinoff = ' checked="checked"';
1702: if ($samlwindow{$lonhost}) {
1703: $samlwinon = $samlwinoff;
1704: $samlwinoff = '';
1705: }
1.386 raeburn 1706: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1707: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1708: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1709: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1710: &mt('No').'</label>'.(' 'x2).
1711: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1712: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1713: &mt('Yes').'</label></span></td>'.
1714: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1715: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1716: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1717: '<th>'.&mt('Alt Text').'</th></tr>'.
1718: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1719: $samltext{$lonhost}.'" /></td><td>';
1720: if ($samlimg{$lonhost}) {
1721: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1722: '<span class="LC_nobreak"><label>'.
1723: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1724: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1725: } else {
1726: $datatable .= $lt{'upl'};
1727: }
1728: $datatable .='<br />';
1729: if ($switchserver) {
1730: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1731: } else {
1732: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1733: }
1734: $datatable .= '</td>'.
1.412 raeburn 1735: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1736: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1737: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1738: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1739: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1740: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1741: '<tr'.$css_class.'>'.
1742: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1743: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1744: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1745: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1746: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1747: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1748: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1749: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1750: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1751: '</table></td>'.
1752: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1753: $itemcount ++;
1754: }
1755: $datatable .= '</table></td></tr>';
1.1 raeburn 1756: }
1.6 raeburn 1757: return $datatable;
1758: }
1759:
1760: sub login_choices {
1761: my %choices =
1762: &Apache::lonlocal::texthash (
1.116 bisitz 1763: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1764: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1765: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1766: disallowlogin => "Login page requests redirected",
1767: hostid => "Server",
1.128 raeburn 1768: server => "Redirect to:",
1769: serverpath => "Path",
1770: custompath => "Custom",
1771: exempt => "Exempt IP(s)",
1.110 raeburn 1772: directlogin => "No redirect",
1773: newuser => "Link to create a user account",
1774: img => "Header",
1775: logo => "Main Logo",
1776: domlogo => "Domain Logo",
1777: login => "Log-in Header",
1778: textcol => "Text color",
1779: bgcol => "Box color",
1780: bgs => "Background colors",
1781: links => "Link colors",
1782: font => "Font color",
1783: pgbg => "Header",
1784: mainbg => "Page",
1785: sidebg => "Login box",
1786: link => "Link",
1787: alink => "Active link",
1788: vlink => "Visited link",
1.256 raeburn 1789: headtag => "Custom markup",
1790: action => "Action",
1791: current => "Current",
1.386 raeburn 1792: samllanding => "Dual login?",
1793: samloptions => "Options",
1.402 raeburn 1794: alttext => "Alt text",
1.6 raeburn 1795: );
1796: return %choices;
1797: }
1798:
1.386 raeburn 1799: sub login_file_options {
1800: return &Apache::lonlocal::texthash(
1801: del => 'Delete?',
1802: rep => 'Replace:',
1803: upl => 'Upload:',
1804: curr => 'View contents',
1805: default => 'Default',
1806: custom => 'Custom',
1807: none => 'None',
1808: );
1809: }
1810:
1.394 raeburn 1811: sub print_ipaccess {
1812: my ($dom,$settings,$rowtotal) = @_;
1813: my $css_class;
1814: my $itemcount = 0;
1815: my $datatable;
1816: my %ordered;
1817: if (ref($settings) eq 'HASH') {
1818: foreach my $item (keys(%{$settings})) {
1819: if (ref($settings->{$item}) eq 'HASH') {
1820: my $num = $settings->{$item}{'order'};
1821: if ($num eq '') {
1822: $num = scalar(keys(%{$settings}));
1823: }
1824: $ordered{$num} = $item;
1825: }
1826: }
1827: }
1828: my $maxnum = scalar(keys(%ordered));
1829: if (keys(%ordered)) {
1830: my @items = sort { $a <=> $b } keys(%ordered);
1831: for (my $i=0; $i<@items; $i++) {
1832: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1833: my $item = $ordered{$items[$i]};
1834: my ($name,$ipranges,%commblocks,%courses);
1835: if (ref($settings->{$item}) eq 'HASH') {
1836: $name = $settings->{$item}->{'name'};
1837: $ipranges = $settings->{$item}->{'ip'};
1838: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1839: %commblocks = %{$settings->{$item}->{'commblocks'}};
1840: }
1841: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1842: %courses = %{$settings->{$item}->{'courses'}};
1843: }
1844: }
1845: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1846: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1847: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1848: for (my $k=0; $k<=$maxnum; $k++) {
1849: my $vpos = $k+1;
1850: my $selstr;
1851: if ($k == $i) {
1852: $selstr = ' selected="selected" ';
1853: }
1854: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1855: }
1856: $datatable .= '</select>'.(' 'x2).
1857: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1858: &mt('Delete?').'</label></span></td>'.
1859: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1860: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1861: '</td></tr>';
1862: $itemcount ++;
1863: }
1864: }
1865: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1866: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1867: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1868: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1869: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1870: for (my $k=0; $k<$maxnum+1; $k++) {
1871: my $vpos = $k+1;
1872: my $selstr;
1873: if ($k == $maxnum) {
1874: $selstr = ' selected="selected" ';
1875: }
1876: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1877: }
1878: $datatable .= '</select> '."\n".
1879: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1880: '<td colspan="2">'.
1881: &ipaccess_options('add',$itemcount,$dom).
1882: '</td>'."\n".
1883: '</tr>'."\n";
1884: $$rowtotal ++;
1885: return $datatable;
1886: }
1887:
1888: sub ipaccess_options {
1889: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1890: my (%currblocks,%currcourses,$output);
1891: if (ref($blocksref) eq 'HASH') {
1892: %currblocks = %{$blocksref};
1893: }
1894: if (ref($coursesref) eq 'HASH') {
1895: %currcourses = %{$coursesref};
1896: }
1897: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1898: '<span class="LC_nobreak">'.&mt('Name').': '.
1899: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1900: '</span></fieldset>'.
1901: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1902: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1903: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1904: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1905: $ipranges.'</textarea></fieldset>'.
1906: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1907: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1908: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1909: '<table>';
1910: foreach my $cid (sort(keys(%currcourses))) {
1911: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1912: $output .= '<tr><td><span class="LC_nobreak">'.
1913: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1914: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1915: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1916: }
1917: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1918: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1919: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1920: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1921: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1922: '</span></td></tr></table>'."\n".
1923: '</fieldset>';
1924: return $output;
1925: }
1926:
1927: sub blocker_checkboxes {
1928: my ($num,$blocks) = @_;
1929: my ($typeorder,$types) = &commblocktype_text();
1930: my $numinrow = 6;
1931: my $output = '<table>';
1932: for (my $i=0; $i<@{$typeorder}; $i++) {
1933: my $block = $typeorder->[$i];
1934: my $blockstatus;
1935: if (ref($blocks) eq 'HASH') {
1936: if ($blocks->{$block} eq 'on') {
1937: $blockstatus = 'checked="checked"';
1938: }
1939: }
1940: my $rem = $i%($numinrow);
1941: if ($rem == 0) {
1942: if ($i > 0) {
1943: $output .= '</tr>';
1944: }
1945: $output .= '<tr>';
1946: }
1947: if ($i == scalar(@{$typeorder})-1) {
1948: my $colsleft = $numinrow-$rem;
1949: if ($colsleft > 1) {
1950: $output .= '<td colspan="'.$colsleft.'">';
1951: } else {
1952: $output .= '<td>';
1953: }
1954: } else {
1955: $output .= '<td>';
1956: }
1957: my $item = 'ipaccess_block_'.$num;
1958: if ($blockstatus) {
1959: $blockstatus = ' '.$blockstatus;
1960: }
1961: $output .= '<span class="LC_nobreak"><label>'."\n".
1962: '<input type="checkbox" name="'.$item.'"'.
1963: $blockstatus.' value="'.$block.'"'.' />'.
1964: $types->{$block}.'</label></span>'."\n".
1965: '<br /></td>';
1966: }
1967: $output .= '</tr></table>';
1968: return $output;
1969: }
1970:
1971: sub commblocktype_text {
1972: my %types = &Apache::lonlocal::texthash(
1973: 'com' => 'Messaging',
1974: 'chat' => 'Chat Room',
1975: 'boards' => 'Discussion',
1976: 'port' => 'Portfolio',
1977: 'groups' => 'Groups',
1978: 'blogs' => 'Blogs',
1979: 'about' => 'User Information',
1980: 'printout' => 'Printouts',
1981: 'passwd' => 'Change Password',
1982: 'grades' => 'Gradebook',
1.397 raeburn 1983: 'search' => 'Course search',
1.447 raeburn 1984: 'index' => 'Course content index',
1.397 raeburn 1985: 'wishlist' => 'Stored links',
1986: 'annotate' => 'Annotations',
1.394 raeburn 1987: );
1.447 raeburn 1988: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','index','annotate','passwd'];
1.394 raeburn 1989: return ($typeorder,\%types);
1990: }
1991:
1.6 raeburn 1992: sub print_rolecolors {
1.30 raeburn 1993: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1994: my %choices = &color_font_choices();
1995: my @bgs = ('pgbg','tabbg','sidebg');
1996: my @links = ('link','alink','vlink');
1.445 raeburn 1997: my @images = ();
1.6 raeburn 1998: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1999: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 2000: my %defaultdesign = %Apache::loncommon::defaultdesign;
2001: my (%is_custom,%designs);
1.200 raeburn 2002: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 2003: if (ref($settings) eq 'HASH') {
2004: if (ref($settings->{$role}) eq 'HASH') {
2005: if ($settings->{$role}->{'font'} ne '') {
2006: $designs{'font'} = $settings->{$role}->{'font'};
2007: $is_custom{'font'} = 1;
2008: }
1.97 tempelho 2009: if ($settings->{$role}->{'fontmenu'} ne '') {
2010: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
2011: $is_custom{'fontmenu'} = 1;
2012: }
1.6 raeburn 2013: foreach my $item (@bgs) {
2014: if ($settings->{$role}->{$item} ne '') {
2015: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
2016: $is_custom{$item} = 1;
2017: }
2018: }
2019: foreach my $item (@links) {
2020: if ($settings->{$role}->{$item} ne '') {
2021: $designs{'links'}{$item} = $settings->{$role}->{$item};
2022: $is_custom{$item} = 1;
2023: }
2024: }
2025: }
2026: } else {
1.97 tempelho 2027: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2028: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2029: $is_custom{'fontmenu'} = 1;
2030: }
1.6 raeburn 2031: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2032: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2033: $is_custom{'font'} = 1;
2034: }
2035: foreach my $item (@bgs) {
2036: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2037: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2038: $is_custom{$item} = 1;
2039:
2040: }
2041: }
2042: foreach my $item (@links) {
2043: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2044: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2045: $is_custom{$item} = 1;
2046: }
2047: }
2048: }
2049: my $itemcount = 1;
1.30 raeburn 2050: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2051: $datatable .= '</tr></table></td></tr>';
2052: return $datatable;
2053: }
2054:
1.200 raeburn 2055: sub role_defaults {
2056: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2057: my %defaults;
2058: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2059: return %defaults;
2060: }
2061: my %defaultdesign = %Apache::loncommon::defaultdesign;
2062: if ($role eq 'login') {
2063: %defaults = (
2064: font => $defaultdesign{$role.'.font'},
2065: );
2066: if (ref($logintext) eq 'ARRAY') {
2067: foreach my $item (@{$logintext}) {
2068: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2069: }
2070: }
2071: foreach my $item (@{$images}) {
2072: $defaults{'showlogo'}{$item} = 1;
2073: }
2074: } else {
2075: %defaults = (
2076: font => $defaultdesign{$role.'.font'},
2077: fontmenu => $defaultdesign{$role.'.fontmenu'},
2078: );
2079: }
2080: foreach my $item (@{$bgs}) {
2081: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2082: }
2083: foreach my $item (@{$links}) {
2084: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2085: }
2086: foreach my $item (@{$images}) {
2087: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2088: }
2089: return %defaults;
2090: }
2091:
1.6 raeburn 2092: sub display_color_options {
1.9 raeburn 2093: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2094: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2095: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2096: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2097: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2098: '<td>'.$choices->{'font'}.'</td>';
2099: if (!$is_custom->{'font'}) {
1.329 raeburn 2100: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2101: } else {
2102: $datatable .= '<td> </td>';
2103: }
1.174 foxr 2104: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2105:
1.8 raeburn 2106: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2107: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2108: ' value="'.$current_color.'" /> '.
1.329 raeburn 2109: ' </span></td></tr>';
1.107 raeburn 2110: unless ($role eq 'login') {
2111: $datatable .= '<tr'.$css_class.'>'.
2112: '<td>'.$choices->{'fontmenu'}.'</td>';
2113: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2114: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2115: } else {
2116: $datatable .= '<td> </td>';
2117: }
1.202 raeburn 2118: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2119: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2120: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2121: '<input class="colorchooser" type="text" size="10" name="'
2122: .$role.'_fontmenu"'.
2123: ' value="'.$current_color.'" /> '.
1.329 raeburn 2124: ' </span></td></tr>';
1.97 tempelho 2125: }
1.9 raeburn 2126: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2127: foreach my $img (@{$images}) {
1.18 albertel 2128: $itemcount ++;
1.6 raeburn 2129: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2130: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2131: '<td>'.$choices->{$img};
1.402 raeburn 2132: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2133: if ($role eq 'login') {
2134: if ($img eq 'login') {
2135: $login_hdr_pick =
1.135 bisitz 2136: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2137: $logincolors =
2138: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2139: $designs,$defaults);
1.402 raeburn 2140: } else {
2141: if ($img ne 'domlogo') {
2142: $datatable.= &logo_display_options($img,$defaults,$designs);
2143: }
2144: if (ref($designs->{'alttext'}) eq 'HASH') {
2145: $alttext = $designs->{'alttext'}{$img};
2146: }
1.70 raeburn 2147: }
2148: }
2149: $datatable .= '</td>';
1.6 raeburn 2150: if ($designs->{$img} ne '') {
2151: $imgfile = $designs->{$img};
1.18 albertel 2152: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2153: } else {
2154: $imgfile = $defaults->{$img};
2155: }
2156: if ($imgfile) {
1.9 raeburn 2157: my ($showfile,$fullsize);
2158: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2159: my $urldir = $1;
2160: my $filename = $2;
2161: my @info = &Apache::lonnet::stat_file($designs->{$img});
2162: if (@info) {
2163: my $thumbfile = 'tn-'.$filename;
2164: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2165: if (@thumb) {
2166: $showfile = $urldir.'/'.$thumbfile;
2167: } else {
2168: $showfile = $imgfile;
2169: }
2170: } else {
2171: $showfile = '';
2172: }
2173: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2174: $showfile = $imgfile;
1.6 raeburn 2175: my $imgdir = $1;
2176: my $filename = $2;
1.159 raeburn 2177: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2178: $showfile = "/$imgdir/tn-".$filename;
2179: } else {
1.159 raeburn 2180: my $input = $londocroot.$imgfile;
2181: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2182: if (!-e $output) {
1.9 raeburn 2183: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2184: my ($fullwidth,$fullheight) = &check_dimensions($input);
2185: if ($fullwidth ne '' && $fullheight ne '') {
2186: if ($fullwidth > $width && $fullheight > $height) {
2187: my $size = $width.'x'.$height;
1.316 raeburn 2188: my @args = ('convert','-sample',$size,$input,$output);
2189: system({$args[0]} @args);
1.159 raeburn 2190: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2191: }
2192: }
1.6 raeburn 2193: }
2194: }
1.16 raeburn 2195: }
1.6 raeburn 2196: if ($showfile) {
1.40 raeburn 2197: if ($showfile =~ m{^/(adm|res)/}) {
2198: if ($showfile =~ m{^/res/}) {
2199: my $local_showfile =
2200: &Apache::lonnet::filelocation('',$showfile);
2201: &Apache::lonnet::repcopy($local_showfile);
2202: }
2203: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2204: }
2205: if ($imgfile) {
2206: if ($imgfile =~ m{^/(adm|res)/}) {
2207: if ($imgfile =~ m{^/res/}) {
2208: my $local_imgfile =
2209: &Apache::lonnet::filelocation('',$imgfile);
2210: &Apache::lonnet::repcopy($local_imgfile);
2211: }
2212: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2213: } else {
2214: $fullsize = $imgfile;
2215: }
2216: }
1.41 raeburn 2217: $datatable .= '<td>';
2218: if ($img eq 'login') {
1.135 bisitz 2219: $datatable .= $login_hdr_pick;
2220: }
1.41 raeburn 2221: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2222: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2223: } else {
1.201 raeburn 2224: $datatable .= '<td> </td><td class="LC_left_item">'.
2225: &mt('Upload:').'<br />';
1.6 raeburn 2226: }
2227: } else {
1.201 raeburn 2228: $datatable .= '<td> </td><td class="LC_left_item">'.
2229: &mt('Upload:').'<br />';
1.6 raeburn 2230: }
1.9 raeburn 2231: if ($switchserver) {
2232: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2233: } else {
1.135 bisitz 2234: if ($img ne 'login') { # suppress file selection for Log-in header
2235: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2236: }
1.9 raeburn 2237: }
1.402 raeburn 2238: if (($role eq 'login') && ($img ne 'login')) {
2239: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2240: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2241: '</label></span>';
2242: }
1.9 raeburn 2243: $datatable .= '</td></tr>';
1.6 raeburn 2244: }
2245: $itemcount ++;
2246: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2247: $datatable .= '<tr'.$css_class.'>'.
2248: '<td>'.$choices->{'bgs'}.'</td>';
2249: my $bgs_def;
2250: foreach my $item (@{$bgs}) {
2251: if (!$is_custom->{$item}) {
1.329 raeburn 2252: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 2253: }
2254: }
2255: if ($bgs_def) {
1.8 raeburn 2256: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2257: } else {
2258: $datatable .= '<td> </td>';
2259: }
2260: $datatable .= '<td class="LC_right_item">'.
2261: '<table border="0"><tr>';
1.174 foxr 2262:
1.6 raeburn 2263: foreach my $item (@{$bgs}) {
1.306 raeburn 2264: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2265: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2266: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2267: $datatable .= ' ';
1.6 raeburn 2268: }
1.174 foxr 2269: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2270: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2271: }
2272: $datatable .= '</tr></table></td></tr>';
2273: $itemcount ++;
2274: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2275: $datatable .= '<tr'.$css_class.'>'.
2276: '<td>'.$choices->{'links'}.'</td>';
2277: my $links_def;
2278: foreach my $item (@{$links}) {
2279: if (!$is_custom->{$item}) {
1.329 raeburn 2280: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 2281: }
2282: }
2283: if ($links_def) {
1.8 raeburn 2284: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2285: } else {
2286: $datatable .= '<td> </td>';
2287: }
2288: $datatable .= '<td class="LC_right_item">'.
2289: '<table border="0"><tr>';
2290: foreach my $item (@{$links}) {
1.234 raeburn 2291: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2292: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2293: if ($designs->{'links'}{$item}) {
1.174 foxr 2294: $datatable.=' ';
1.6 raeburn 2295: }
1.174 foxr 2296: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2297: '" /></td>';
2298: }
1.30 raeburn 2299: $$rowtotal += $itemcount;
1.3 raeburn 2300: return $datatable;
2301: }
2302:
1.70 raeburn 2303: sub logo_display_options {
2304: my ($img,$defaults,$designs) = @_;
2305: my $checkedon;
2306: if (ref($defaults) eq 'HASH') {
2307: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2308: if ($defaults->{'showlogo'}{$img}) {
2309: $checkedon = 'checked="checked" ';
2310: }
2311: }
2312: }
2313: if (ref($designs) eq 'HASH') {
2314: if (ref($designs->{'showlogo'}) eq 'HASH') {
2315: if (defined($designs->{'showlogo'}{$img})) {
2316: if ($designs->{'showlogo'}{$img} == 0) {
2317: $checkedon = '';
2318: } elsif ($designs->{'showlogo'}{$img} == 1) {
2319: $checkedon = 'checked="checked" ';
2320: }
2321: }
2322: }
2323: }
2324: return '<br /><label> <input type="checkbox" name="'.
2325: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2326: &mt('show').'</label>'."\n";
2327: }
2328:
1.41 raeburn 2329: sub login_header_options {
1.135 bisitz 2330: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2331: my $output = '';
1.41 raeburn 2332: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2333: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2334: if (!$is_custom->{'textcol'}) {
2335: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2336: ' ';
2337: }
2338: if (!$is_custom->{'bgcol'}) {
2339: $output .= $choices->{'bgcol'}.': '.
2340: '<span id="css_'.$role.'_font" style="background-color: '.
2341: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2342: }
2343: $output .= '<br />';
2344: }
2345: $output .='<br />';
2346: return $output;
2347: }
2348:
2349: sub login_text_colors {
1.201 raeburn 2350: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2351: my $color_menu = '<table border="0"><tr>';
2352: foreach my $item (@{$logintext}) {
1.306 raeburn 2353: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2354: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2355: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2356: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2357: }
2358: $color_menu .= '</tr></table><br />';
2359: return $color_menu;
2360: }
2361:
2362: sub image_changes {
2363: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2364: my $output;
1.135 bisitz 2365: if ($img eq 'login') {
1.331 raeburn 2366: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2367: } elsif (!$is_custom) {
1.70 raeburn 2368: if ($img ne 'domlogo') {
1.331 raeburn 2369: $output = &mt('Default image:').'<br />';
1.41 raeburn 2370: } else {
1.331 raeburn 2371: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2372: }
2373: }
1.331 raeburn 2374: if ($img ne 'login') {
1.135 bisitz 2375: if ($img_import) {
2376: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2377: }
2378: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2379: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2380: if ($is_custom) {
2381: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2382: '<input type="checkbox" name="'.
2383: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2384: '</label> '.&mt('Replace:').'</span><br />';
2385: } else {
1.306 raeburn 2386: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2387: }
1.41 raeburn 2388: }
2389: return $output;
2390: }
2391:
1.3 raeburn 2392: sub print_quotas {
1.86 raeburn 2393: my ($dom,$settings,$rowtotal,$action) = @_;
2394: my $context;
2395: if ($action eq 'quotas') {
2396: $context = 'tools';
2397: } else {
2398: $context = $action;
2399: }
1.429 raeburn 2400: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2401: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2402: my $typecount = 0;
1.101 raeburn 2403: my ($css_class,%titles);
1.86 raeburn 2404: if ($context eq 'requestcourses') {
1.325 raeburn 2405: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2406: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2407: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2408: %titles = &courserequest_titles();
1.163 raeburn 2409: } elsif ($context eq 'requestauthor') {
2410: @usertools = ('author');
2411: @options = ('norequest','approval','automatic');
1.210 raeburn 2412: %titles = &authorrequest_titles();
1.86 raeburn 2413: } else {
1.430 raeburn 2414: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 2415: %titles = &tool_titles();
1.86 raeburn 2416: }
1.26 raeburn 2417: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2418: foreach my $type (@{$types}) {
1.429 raeburn 2419: my $currdefquota;
1.163 raeburn 2420: unless (($context eq 'requestcourses') ||
2421: ($context eq 'requestauthor')) {
1.86 raeburn 2422: if (ref($settings) eq 'HASH') {
2423: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2424: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2425: } else {
2426: $currdefquota = $settings->{$type};
2427: }
1.78 raeburn 2428: }
1.72 raeburn 2429: }
1.3 raeburn 2430: if (defined($usertypes->{$type})) {
2431: $typecount ++;
2432: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2433: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2434: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2435: '<td class="LC_left_item">';
1.101 raeburn 2436: if ($context eq 'requestcourses') {
2437: $datatable .= '<table><tr>';
2438: }
2439: my %cell;
1.72 raeburn 2440: foreach my $item (@usertools) {
1.101 raeburn 2441: if ($context eq 'requestcourses') {
2442: my ($curroption,$currlimit);
2443: if (ref($settings) eq 'HASH') {
2444: if (ref($settings->{$item}) eq 'HASH') {
2445: $curroption = $settings->{$item}->{$type};
2446: if ($curroption =~ /^autolimit=(\d*)$/) {
2447: $currlimit = $1;
2448: }
2449: }
2450: }
2451: if (!$curroption) {
2452: $curroption = 'norequest';
2453: }
2454: $datatable .= '<th>'.$titles{$item}.'</th>';
2455: foreach my $option (@options) {
2456: my $val = $option;
2457: if ($option eq 'norequest') {
2458: $val = 0;
2459: }
2460: if ($option eq 'validate') {
2461: my $canvalidate = 0;
2462: if (ref($validations{$item}) eq 'HASH') {
2463: if ($validations{$item}{$type}) {
2464: $canvalidate = 1;
2465: }
2466: }
2467: next if (!$canvalidate);
2468: }
2469: my $checked = '';
2470: if ($option eq $curroption) {
2471: $checked = ' checked="checked"';
2472: } elsif ($option eq 'autolimit') {
2473: if ($curroption =~ /^autolimit/) {
2474: $checked = ' checked="checked"';
2475: }
2476: }
2477: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2478: '<input type="radio" name="crsreq_'.$item.
2479: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2480: $titles{$option}.'</label>';
1.101 raeburn 2481: if ($option eq 'autolimit') {
1.127 raeburn 2482: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2483: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2484: 'value="'.$currlimit.'" />';
1.101 raeburn 2485: }
1.127 raeburn 2486: $cell{$item} .= '</span> ';
1.103 raeburn 2487: if ($option eq 'autolimit') {
1.127 raeburn 2488: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2489: }
1.101 raeburn 2490: }
1.163 raeburn 2491: } elsif ($context eq 'requestauthor') {
2492: my $curroption;
2493: if (ref($settings) eq 'HASH') {
2494: $curroption = $settings->{$type};
2495: }
2496: if (!$curroption) {
2497: $curroption = 'norequest';
2498: }
2499: foreach my $option (@options) {
2500: my $val = $option;
2501: if ($option eq 'norequest') {
2502: $val = 0;
2503: }
2504: my $checked = '';
2505: if ($option eq $curroption) {
2506: $checked = ' checked="checked"';
2507: }
2508: $datatable .= '<span class="LC_nobreak"><label>'.
2509: '<input type="radio" name="authorreq_'.$type.
2510: '" value="'.$val.'"'.$checked.' />'.
2511: $titles{$option}.'</label></span> ';
2512: }
1.101 raeburn 2513: } else {
2514: my $checked = 'checked="checked" ';
1.413 raeburn 2515: if ($item eq 'timezone') {
2516: $checked = '';
2517: }
1.101 raeburn 2518: if (ref($settings) eq 'HASH') {
2519: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2520: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2521: $checked = '';
2522: } elsif ($settings->{$item}->{$type} == 1) {
2523: $checked = 'checked="checked" ';
2524: }
1.78 raeburn 2525: }
1.72 raeburn 2526: }
1.101 raeburn 2527: $datatable .= '<span class="LC_nobreak"><label>'.
2528: '<input type="checkbox" name="'.$context.'_'.$item.
2529: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2530: '</label></span> ';
1.72 raeburn 2531: }
1.101 raeburn 2532: }
2533: if ($context eq 'requestcourses') {
2534: $datatable .= '</tr><tr>';
2535: foreach my $item (@usertools) {
1.106 raeburn 2536: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2537: }
2538: $datatable .= '</tr></table>';
1.72 raeburn 2539: }
1.86 raeburn 2540: $datatable .= '</td>';
1.163 raeburn 2541: unless (($context eq 'requestcourses') ||
2542: ($context eq 'requestauthor')) {
1.86 raeburn 2543: $datatable .=
1.197 raeburn 2544: '<td class="LC_right_item">'.
1.429 raeburn 2545: '<span class="LC_nobreak">'.
1.3 raeburn 2546: '<input type="text" name="quota_'.$type.
1.72 raeburn 2547: '" value="'.$currdefquota.
1.197 raeburn 2548: '" size="5" /></span></td>';
1.86 raeburn 2549: }
2550: $datatable .= '</tr>';
1.3 raeburn 2551: }
2552: }
2553: }
1.163 raeburn 2554: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2555: $defaultquota = '20';
2556: if (ref($settings) eq 'HASH') {
2557: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2558: $defaultquota = $settings->{'defaultquota'}->{'default'};
2559: } elsif (defined($settings->{'default'})) {
2560: $defaultquota = $settings->{'default'};
2561: }
1.3 raeburn 2562: }
2563: }
2564: $typecount ++;
2565: $css_class = $typecount%2?' class="LC_odd_row"':'';
2566: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2567: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2568: '<td class="LC_left_item">';
1.101 raeburn 2569: if ($context eq 'requestcourses') {
2570: $datatable .= '<table><tr>';
2571: }
2572: my %defcell;
1.72 raeburn 2573: foreach my $item (@usertools) {
1.101 raeburn 2574: if ($context eq 'requestcourses') {
2575: my ($curroption,$currlimit);
2576: if (ref($settings) eq 'HASH') {
2577: if (ref($settings->{$item}) eq 'HASH') {
2578: $curroption = $settings->{$item}->{'default'};
2579: if ($curroption =~ /^autolimit=(\d*)$/) {
2580: $currlimit = $1;
2581: }
2582: }
2583: }
2584: if (!$curroption) {
2585: $curroption = 'norequest';
2586: }
2587: $datatable .= '<th>'.$titles{$item}.'</th>';
2588: foreach my $option (@options) {
2589: my $val = $option;
2590: if ($option eq 'norequest') {
2591: $val = 0;
2592: }
2593: if ($option eq 'validate') {
2594: my $canvalidate = 0;
2595: if (ref($validations{$item}) eq 'HASH') {
2596: if ($validations{$item}{'default'}) {
2597: $canvalidate = 1;
2598: }
2599: }
2600: next if (!$canvalidate);
2601: }
2602: my $checked = '';
2603: if ($option eq $curroption) {
2604: $checked = ' checked="checked"';
2605: } elsif ($option eq 'autolimit') {
2606: if ($curroption =~ /^autolimit/) {
2607: $checked = ' checked="checked"';
2608: }
2609: }
2610: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2611: '<input type="radio" name="crsreq_'.$item.
2612: '_default" value="'.$val.'"'.$checked.' />'.
2613: $titles{$option}.'</label>';
2614: if ($option eq 'autolimit') {
1.127 raeburn 2615: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2616: $item.'_limit_default" size="1" '.
2617: 'value="'.$currlimit.'" />';
2618: }
1.127 raeburn 2619: $defcell{$item} .= '</span> ';
1.104 raeburn 2620: if ($option eq 'autolimit') {
1.127 raeburn 2621: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2622: }
1.101 raeburn 2623: }
1.163 raeburn 2624: } elsif ($context eq 'requestauthor') {
2625: my $curroption;
2626: if (ref($settings) eq 'HASH') {
1.172 raeburn 2627: $curroption = $settings->{'default'};
1.163 raeburn 2628: }
2629: if (!$curroption) {
2630: $curroption = 'norequest';
2631: }
2632: foreach my $option (@options) {
2633: my $val = $option;
2634: if ($option eq 'norequest') {
2635: $val = 0;
2636: }
2637: my $checked = '';
2638: if ($option eq $curroption) {
2639: $checked = ' checked="checked"';
2640: }
2641: $datatable .= '<span class="LC_nobreak"><label>'.
2642: '<input type="radio" name="authorreq_default"'.
2643: ' value="'.$val.'"'.$checked.' />'.
2644: $titles{$option}.'</label></span> ';
2645: }
1.101 raeburn 2646: } else {
2647: my $checked = 'checked="checked" ';
2648: if (ref($settings) eq 'HASH') {
2649: if (ref($settings->{$item}) eq 'HASH') {
2650: if ($settings->{$item}->{'default'} == 0) {
2651: $checked = '';
2652: } elsif ($settings->{$item}->{'default'} == 1) {
2653: $checked = 'checked="checked" ';
2654: }
1.78 raeburn 2655: }
1.72 raeburn 2656: }
1.101 raeburn 2657: $datatable .= '<span class="LC_nobreak"><label>'.
2658: '<input type="checkbox" name="'.$context.'_'.$item.
2659: '" value="default" '.$checked.'/>'.$titles{$item}.
2660: '</label></span> ';
2661: }
2662: }
2663: if ($context eq 'requestcourses') {
2664: $datatable .= '</tr><tr>';
2665: foreach my $item (@usertools) {
1.106 raeburn 2666: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2667: }
1.101 raeburn 2668: $datatable .= '</tr></table>';
1.72 raeburn 2669: }
1.86 raeburn 2670: $datatable .= '</td>';
1.163 raeburn 2671: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2672: $datatable .= '<td class="LC_right_item">'.
1.429 raeburn 2673: '<span class="LC_nobreak">'.
1.86 raeburn 2674: '<input type="text" name="defaultquota" value="'.
1.429 raeburn 2675: $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2676: }
2677: $datatable .= '</tr>';
1.72 raeburn 2678: $typecount ++;
2679: $css_class = $typecount%2?' class="LC_odd_row"':'';
2680: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2681: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2682: if ($context eq 'requestcourses') {
1.109 raeburn 2683: $datatable .= &mt('(overrides affiliation, if set)').
2684: '</td>'.
2685: '<td class="LC_left_item">'.
2686: '<table><tr>';
1.101 raeburn 2687: } else {
1.109 raeburn 2688: $datatable .= &mt('(overrides affiliation, if checked)').
2689: '</td>'.
2690: '<td class="LC_left_item" colspan="2">'.
2691: '<br />';
1.101 raeburn 2692: }
2693: my %advcell;
1.72 raeburn 2694: foreach my $item (@usertools) {
1.101 raeburn 2695: if ($context eq 'requestcourses') {
2696: my ($curroption,$currlimit);
2697: if (ref($settings) eq 'HASH') {
2698: if (ref($settings->{$item}) eq 'HASH') {
2699: $curroption = $settings->{$item}->{'_LC_adv'};
2700: if ($curroption =~ /^autolimit=(\d*)$/) {
2701: $currlimit = $1;
2702: }
2703: }
2704: }
2705: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2706: my $checked = '';
2707: if ($curroption eq '') {
2708: $checked = ' checked="checked"';
2709: }
2710: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2711: '<input type="radio" name="crsreq_'.$item.
2712: '__LC_adv" value=""'.$checked.' />'.
2713: &mt('No override set').'</label></span> ';
1.101 raeburn 2714: foreach my $option (@options) {
2715: my $val = $option;
2716: if ($option eq 'norequest') {
2717: $val = 0;
2718: }
2719: if ($option eq 'validate') {
2720: my $canvalidate = 0;
2721: if (ref($validations{$item}) eq 'HASH') {
2722: if ($validations{$item}{'_LC_adv'}) {
2723: $canvalidate = 1;
2724: }
2725: }
2726: next if (!$canvalidate);
2727: }
2728: my $checked = '';
1.104 raeburn 2729: if ($val eq $curroption) {
1.101 raeburn 2730: $checked = ' checked="checked"';
2731: } elsif ($option eq 'autolimit') {
2732: if ($curroption =~ /^autolimit/) {
2733: $checked = ' checked="checked"';
2734: }
2735: }
2736: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2737: '<input type="radio" name="crsreq_'.$item.
2738: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2739: $titles{$option}.'</label>';
2740: if ($option eq 'autolimit') {
1.127 raeburn 2741: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2742: $item.'_limit__LC_adv" size="1" '.
2743: 'value="'.$currlimit.'" />';
2744: }
1.127 raeburn 2745: $advcell{$item} .= '</span> ';
1.104 raeburn 2746: if ($option eq 'autolimit') {
1.127 raeburn 2747: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2748: }
1.101 raeburn 2749: }
1.163 raeburn 2750: } elsif ($context eq 'requestauthor') {
2751: my $curroption;
2752: if (ref($settings) eq 'HASH') {
2753: $curroption = $settings->{'_LC_adv'};
2754: }
2755: my $checked = '';
2756: if ($curroption eq '') {
2757: $checked = ' checked="checked"';
2758: }
2759: $datatable .= '<span class="LC_nobreak"><label>'.
2760: '<input type="radio" name="authorreq__LC_adv"'.
2761: ' value=""'.$checked.' />'.
2762: &mt('No override set').'</label></span> ';
2763: foreach my $option (@options) {
2764: my $val = $option;
2765: if ($option eq 'norequest') {
2766: $val = 0;
2767: }
2768: my $checked = '';
2769: if ($val eq $curroption) {
2770: $checked = ' checked="checked"';
2771: }
2772: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2773: '<input type="radio" name="authorreq__LC_adv"'.
2774: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2775: $titles{$option}.'</label></span> ';
2776: }
1.101 raeburn 2777: } else {
2778: my $checked = 'checked="checked" ';
2779: if (ref($settings) eq 'HASH') {
2780: if (ref($settings->{$item}) eq 'HASH') {
2781: if ($settings->{$item}->{'_LC_adv'} == 0) {
2782: $checked = '';
2783: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2784: $checked = 'checked="checked" ';
2785: }
1.79 raeburn 2786: }
1.72 raeburn 2787: }
1.101 raeburn 2788: $datatable .= '<span class="LC_nobreak"><label>'.
2789: '<input type="checkbox" name="'.$context.'_'.$item.
2790: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2791: '</label></span> ';
2792: }
2793: }
2794: if ($context eq 'requestcourses') {
2795: $datatable .= '</tr><tr>';
2796: foreach my $item (@usertools) {
1.106 raeburn 2797: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2798: }
1.101 raeburn 2799: $datatable .= '</tr></table>';
1.72 raeburn 2800: }
1.98 raeburn 2801: $datatable .= '</td></tr>';
1.30 raeburn 2802: $$rowtotal += $typecount;
1.3 raeburn 2803: return $datatable;
2804: }
2805:
1.163 raeburn 2806: sub print_requestmail {
1.305 raeburn 2807: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2808: my ($now,$datatable,%currapp);
1.102 raeburn 2809: $now = time;
2810: if (ref($settings) eq 'HASH') {
2811: if (ref($settings->{'notify'}) eq 'HASH') {
2812: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2813: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2814: }
2815: }
2816: }
1.191 raeburn 2817: my $numinrow = 2;
1.224 raeburn 2818: my $css_class;
1.305 raeburn 2819: if ($$rowtotal%2) {
2820: $css_class = 'LC_odd_row';
2821: }
2822: if ($customcss) {
2823: $css_class .= " $customcss";
2824: }
2825: $css_class =~ s/^\s+//;
2826: if ($css_class) {
2827: $css_class = ' class="'.$css_class.'"';
2828: }
2829: if ($rowstyle) {
2830: $css_class .= ' style="'.$rowstyle.'"';
2831: }
1.163 raeburn 2832: my $text;
2833: if ($action eq 'requestcourses') {
2834: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2835: } elsif ($action eq 'requestauthor') {
2836: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2837: } else {
1.224 raeburn 2838: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2839: }
1.224 raeburn 2840: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2841: ' <td>'.$text.'</td>'.
1.102 raeburn 2842: ' <td class="LC_left_item">';
1.191 raeburn 2843: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2844: $action.'notifyapproval',%currapp);
1.191 raeburn 2845: if ($numdc > 0) {
2846: $datatable .= $table;
1.102 raeburn 2847: } else {
2848: $datatable .= &mt('There are no active Domain Coordinators');
2849: }
2850: $datatable .='</td></tr>';
2851: return $datatable;
2852: }
2853:
1.216 raeburn 2854: sub print_studentcode {
2855: my ($settings,$rowtotal) = @_;
2856: my $rownum = 0;
1.218 raeburn 2857: my ($output,%current);
1.325 raeburn 2858: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2859: if (ref($settings) eq 'HASH') {
2860: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2861: foreach my $type (@crstypes) {
2862: $current{$type} = $settings->{'uniquecode'}{$type};
2863: }
1.218 raeburn 2864: }
2865: }
2866: $output .= '<tr>'.
2867: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2868: '<td class="LC_left_item">';
2869: foreach my $type (@crstypes) {
2870: my $check = ' ';
2871: if ($current{$type}) {
2872: $check = ' checked="checked" ';
2873: }
2874: $output .= '<span class="LC_nobreak"><label>'.
2875: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2876: &mt($type).'</label></span>'.(' 'x2).' ';
2877: }
2878: $output .= '</td></tr>';
2879: $$rowtotal ++;
2880: return $output;
1.216 raeburn 2881: }
2882:
2883: sub print_textbookcourses {
1.242 raeburn 2884: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2885: my $rownum = 0;
2886: my $css_class;
2887: my $itemcount = 1;
2888: my $maxnum = 0;
2889: my $bookshash;
2890: if (ref($settings) eq 'HASH') {
1.242 raeburn 2891: $bookshash = $settings->{$type};
1.216 raeburn 2892: }
2893: my %ordered;
2894: if (ref($bookshash) eq 'HASH') {
2895: foreach my $item (keys(%{$bookshash})) {
2896: if (ref($bookshash->{$item}) eq 'HASH') {
2897: my $num = $bookshash->{$item}{'order'};
2898: $ordered{$num} = $item;
2899: }
2900: }
2901: }
2902: my $confname = $dom.'-domainconfig';
2903: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2904: my $maxnum = scalar(keys(%ordered));
2905: my $datatable;
1.216 raeburn 2906: if (keys(%ordered)) {
2907: my @items = sort { $a <=> $b } keys(%ordered);
2908: for (my $i=0; $i<@items; $i++) {
2909: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2910: my $key = $ordered{$items[$i]};
2911: my %coursehash=&Apache::lonnet::coursedescription($key);
2912: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2913: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2914: if (ref($bookshash->{$key}) eq 'HASH') {
2915: $subject = $bookshash->{$key}->{'subject'};
2916: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2917: if ($type eq 'textbooks') {
1.243 raeburn 2918: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2919: $author = $bookshash->{$key}->{'author'};
2920: $image = $bookshash->{$key}->{'image'};
2921: if ($image ne '') {
2922: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2923: my $imagethumb = "$path/tn-".$imagefile;
2924: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2925: }
1.216 raeburn 2926: }
2927: }
1.242 raeburn 2928: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2929: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2930: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2931: for (my $k=0; $k<=$maxnum; $k++) {
2932: my $vpos = $k+1;
2933: my $selstr;
2934: if ($k == $i) {
2935: $selstr = ' selected="selected" ';
2936: }
2937: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2938: }
2939: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2940: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2941: &mt('Delete?').'</label></span></td>'.
2942: '<td colspan="2">'.
1.242 raeburn 2943: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2944: (' 'x2).
1.242 raeburn 2945: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2946: if ($type eq 'textbooks') {
2947: $datatable .= (' 'x2).
1.243 raeburn 2948: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2949: (' 'x2).
1.242 raeburn 2950: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2951: (' 'x2).
2952: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2953: if ($image) {
1.267 raeburn 2954: $datatable .= $imgsrc.
1.242 raeburn 2955: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2956: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2957: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2958: }
2959: if ($switchserver) {
2960: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2961: } else {
2962: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2963: }
1.216 raeburn 2964: }
1.242 raeburn 2965: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2966: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2967: $coursetitle.'</span></td></tr>'."\n";
2968: $itemcount ++;
2969: }
2970: }
2971: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2972: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2973: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2974: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2975: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2976: for (my $k=0; $k<$maxnum+1; $k++) {
2977: my $vpos = $k+1;
2978: my $selstr;
2979: if ($k == $maxnum) {
2980: $selstr = ' selected="selected" ';
2981: }
2982: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2983: }
2984: $datatable .= '</select> '."\n".
1.334 raeburn 2985: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2986: '<td colspan="2">'.
1.242 raeburn 2987: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2988: (' 'x2).
1.242 raeburn 2989: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2990: (' 'x2);
2991: if ($type eq 'textbooks') {
1.243 raeburn 2992: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2993: (' 'x2).
2994: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2995: (' 'x2).
2996: '<span class="LC_nobreak">'.&mt('Image:').' ';
2997: if ($switchserver) {
2998: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2999: } else {
3000: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
3001: }
1.334 raeburn 3002: $datatable .= '</span>'."\n";
1.216 raeburn 3003: }
1.334 raeburn 3004: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 3005: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
3006: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 3007: &Apache::loncommon::selectcourse_link
1.334 raeburn 3008: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 3009: '</span></td>'."\n".
3010: '</tr>'."\n";
3011: $itemcount ++;
3012: return $datatable;
3013: }
3014:
1.217 raeburn 3015: sub textbookcourses_javascript {
1.242 raeburn 3016: my ($settings) = @_;
3017: return unless(ref($settings) eq 'HASH');
3018: my (%ordered,%total,%jstext);
3019: foreach my $type ('textbooks','templates') {
3020: $total{$type} = 0;
3021: if (ref($settings->{$type}) eq 'HASH') {
3022: foreach my $item (keys(%{$settings->{$type}})) {
3023: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3024: my $num = $settings->{$type}->{$item}{'order'};
3025: $ordered{$type}{$num} = $item;
3026: }
3027: }
3028: $total{$type} = scalar(keys(%{$settings->{$type}}));
3029: }
3030: my @jsarray = ();
3031: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3032: push(@jsarray,$ordered{$type}{$item});
3033: }
3034: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3035: }
3036: return <<"ENDSCRIPT";
3037: <script type="text/javascript">
3038: // <![CDATA[
1.242 raeburn 3039: function reorderBooks(form,item,caller) {
1.217 raeburn 3040: var changedVal;
1.242 raeburn 3041: $jstext{'textbooks'};
3042: $jstext{'templates'};
3043: var newpos;
3044: var maxh;
3045: if (caller == 'textbooks') {
3046: newpos = 'textbooks_addbook_pos';
3047: maxh = 1 + $total{'textbooks'};
3048: } else {
3049: newpos = 'templates_addbook_pos';
3050: maxh = 1 + $total{'templates'};
3051: }
1.217 raeburn 3052: var current = new Array;
3053: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3054: if (item == newpos) {
3055: changedVal = newitemVal;
3056: } else {
3057: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3058: current[newitemVal] = newpos;
3059: }
1.242 raeburn 3060: if (caller == 'textbooks') {
3061: for (var i=0; i<textbooks.length; i++) {
3062: var elementName = 'textbooks_'+textbooks[i];
3063: if (elementName != item) {
3064: if (form.elements[elementName]) {
3065: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3066: current[currVal] = elementName;
3067: }
3068: }
3069: }
3070: }
3071: if (caller == 'templates') {
3072: for (var i=0; i<templates.length; i++) {
3073: var elementName = 'templates_'+templates[i];
3074: if (elementName != item) {
3075: if (form.elements[elementName]) {
3076: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3077: current[currVal] = elementName;
3078: }
1.217 raeburn 3079: }
3080: }
3081: }
3082: var oldVal;
3083: for (var j=0; j<maxh; j++) {
3084: if (current[j] == undefined) {
3085: oldVal = j;
3086: }
3087: }
3088: if (oldVal < changedVal) {
3089: for (var k=oldVal+1; k<=changedVal ; k++) {
3090: var elementName = current[k];
3091: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3092: }
3093: } else {
3094: for (var k=changedVal; k<oldVal; k++) {
3095: var elementName = current[k];
3096: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3097: }
3098: }
3099: return;
3100: }
3101:
3102: // ]]>
3103: </script>
3104:
3105: ENDSCRIPT
3106: }
3107:
1.267 raeburn 3108: sub ltitools_javascript {
3109: my ($settings) = @_;
1.319 raeburn 3110: my $togglejs = <itools_toggle_js();
3111: unless (ref($settings) eq 'HASH') {
3112: return $togglejs;
3113: }
1.267 raeburn 3114: my (%ordered,$total,%jstext);
3115: $total = 0;
3116: foreach my $item (keys(%{$settings})) {
3117: if (ref($settings->{$item}) eq 'HASH') {
3118: my $num = $settings->{$item}{'order'};
3119: $ordered{$num} = $item;
3120: }
3121: }
3122: $total = scalar(keys(%{$settings}));
3123: my @jsarray = ();
3124: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3125: push(@jsarray,$ordered{$item});
3126: }
3127: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3128: return <<"ENDSCRIPT";
3129: <script type="text/javascript">
3130: // <![CDATA[
1.319 raeburn 3131: function reorderLTITools(form,item) {
1.267 raeburn 3132: var changedVal;
3133: $jstext
3134: var newpos = 'ltitools_add_pos';
3135: var maxh = 1 + $total;
3136: var current = new Array;
3137: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3138: if (item == newpos) {
3139: changedVal = newitemVal;
3140: } else {
3141: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3142: current[newitemVal] = newpos;
3143: }
3144: for (var i=0; i<ltitools.length; i++) {
3145: var elementName = 'ltitools_'+ltitools[i];
3146: if (elementName != item) {
3147: if (form.elements[elementName]) {
3148: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3149: current[currVal] = elementName;
3150: }
3151: }
3152: }
3153: var oldVal;
3154: for (var j=0; j<maxh; j++) {
3155: if (current[j] == undefined) {
3156: oldVal = j;
3157: }
3158: }
3159: if (oldVal < changedVal) {
3160: for (var k=oldVal+1; k<=changedVal ; k++) {
3161: var elementName = current[k];
3162: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3163: }
3164: } else {
3165: for (var k=changedVal; k<oldVal; k++) {
3166: var elementName = current[k];
3167: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3168: }
3169: }
3170: return;
3171: }
3172:
3173: // ]]>
3174: </script>
3175:
1.319 raeburn 3176: $togglejs
3177:
3178: ENDSCRIPT
3179: }
3180:
3181: sub ltitools_toggle_js {
3182: return <<"ENDSCRIPT";
3183: <script type="text/javascript">
3184: // <![CDATA[
3185:
3186: function toggleLTITools(form,setting,item) {
3187: var radioname = '';
3188: var divid = '';
3189: if ((setting == 'passback') || (setting == 'roster')) {
3190: radioname = 'ltitools_'+setting+'_'+item;
3191: divid = 'ltitools_'+setting+'time_'+item;
3192: var num = form.elements[radioname].length;
3193: if (num) {
3194: var setvis = '';
3195: for (var i=0; i<num; i++) {
3196: if (form.elements[radioname][i].checked) {
3197: if (form.elements[radioname][i].value == '1') {
3198: if (document.getElementById(divid)) {
3199: document.getElementById(divid).style.display = 'inline-block';
3200: }
3201: setvis = 1;
3202: }
3203: break;
3204: }
3205: }
3206: }
3207: if (!setvis) {
3208: if (document.getElementById(divid)) {
3209: document.getElementById(divid).style.display = 'none';
3210: }
3211: }
3212: }
1.324 raeburn 3213: if (setting == 'user') {
3214: divid = 'ltitools_'+setting+'_div_'+item;
3215: var checkid = 'ltitools_'+setting+'_field_'+item;
3216: if (document.getElementById(divid)) {
3217: if (document.getElementById(checkid)) {
3218: if (document.getElementById(checkid).checked) {
3219: document.getElementById(divid).style.display = 'inline-block';
3220: } else {
3221: document.getElementById(divid).style.display = 'none';
3222: }
3223: }
3224: }
3225: }
1.319 raeburn 3226: return;
3227: }
3228: // ]]>
3229: </script>
3230:
1.267 raeburn 3231: ENDSCRIPT
3232: }
3233:
1.381 raeburn 3234: sub wafproxy_javascript {
3235: my ($dom) = @_;
3236: return <<"ENDSCRIPT";
3237: <script type="text/javascript">
3238: // <![CDATA[
3239: function updateWAF() {
3240: if (document.getElementById('wafproxy_remoteip')) {
3241: var wafremote = 0;
3242: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3243: wafremote = 1;
3244: }
3245: var fields = new Array('header','trust');
3246: for (var i=0; i<fields.length; i++) {
3247: if (document.getElementById('wafproxy_'+fields[i])) {
3248: if (wafremote == 1) {
3249: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3250: }
3251: else {
3252: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3253: }
3254: }
3255: }
3256: if (document.getElementById('wafproxyranges_$dom')) {
3257: if (wafremote == 1) {
3258: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3259: } else {
3260: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3261: if (document.display.wafproxy_vpnaccess[i].checked) {
3262: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3263: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3264: }
3265: }
3266: }
3267: }
3268: }
3269: }
3270: return;
3271: }
3272:
3273: function checkWAF() {
3274: if (document.getElementById('wafproxy_remoteip')) {
3275: var wafvpn = 0;
3276: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3277: if (document.display.wafproxy_vpnaccess[i].checked) {
3278: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3279: wafvpn = 1;
3280: }
3281: break;
3282: }
3283: }
3284: var vpn = new Array('vpnint','vpnext');
3285: for (var i=0; i<vpn.length; i++) {
3286: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3287: if (wafvpn == 1) {
3288: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3289: }
3290: else {
3291: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3292: }
3293: }
3294: }
3295: if (document.getElementById('wafproxyranges_$dom')) {
3296: if (wafvpn == 1) {
3297: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3298: }
3299: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3300: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3301: }
3302: }
3303: }
3304: return;
3305: }
3306:
3307: function toggleWAF() {
3308: if (document.getElementById('wafproxy_table')) {
3309: var wafproxy = 0;
3310: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3311: if (document.display.wafproxy_${dom}[i].checked) {
3312: if (document.display.wafproxy_${dom}[i].value == 1) {
3313: wafproxy = 1;
3314: break;
3315: }
3316: }
3317: }
3318: if (wafproxy == 1) {
3319: document.getElementById('wafproxy_table').style.display='inline';
3320: }
3321: else {
3322: document.getElementById('wafproxy_table').style.display='none';
3323: }
3324: if (document.getElementById('wafproxyrow_${dom}')) {
3325: if (wafproxy == 1) {
3326: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3327: }
3328: else {
3329: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3330: }
3331: }
3332: if (document.getElementById('nowafproxyrow_$dom')) {
3333: if (wafproxy == 1) {
3334: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3335: }
3336: else {
3337: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3338: }
3339: }
3340: }
3341: return;
3342: }
3343: // ]]>
3344: </script>
3345:
3346: ENDSCRIPT
3347: }
3348:
1.372 raeburn 3349: sub proctoring_javascript {
3350: my ($settings) = @_;
3351: my (%ordered,$total,%jstext);
3352: $total = 0;
3353: if (ref($settings) eq 'HASH') {
3354: foreach my $item (keys(%{$settings})) {
3355: if (ref($settings->{$item}) eq 'HASH') {
3356: my $num = $settings->{$item}{'order'};
3357: $ordered{$num} = $item;
3358: }
3359: }
3360: $total = scalar(keys(%{$settings}));
3361: } else {
3362: %ordered = (
3363: 0 => 'proctorio',
3364: 1 => 'examity',
3365: );
3366: $total = 2;
3367: }
3368: my @jsarray = ();
3369: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3370: push(@jsarray,$ordered{$item});
3371: }
3372: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3373: return <<"ENDSCRIPT";
3374: <script type="text/javascript">
3375: // <![CDATA[
3376: function reorderProctoring(form,item) {
3377: var changedVal;
3378: $jstext
3379: var maxh = $total;
3380: var current = new Array;
3381: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3382: for (var i=0; i<proctors.length; i++) {
3383: var elementName = 'proctoring_pos_'+proctors[i];
3384: if (elementName != item) {
3385: if (form.elements[elementName]) {
3386: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3387: current[currVal] = elementName;
3388: }
3389: }
3390: }
3391: var oldVal;
3392: for (var j=0; j<maxh; j++) {
3393: if (current[j] == undefined) {
3394: oldVal = j;
3395: }
3396: }
3397: if (oldVal < changedVal) {
3398: for (var k=oldVal+1; k<=changedVal ; k++) {
3399: var elementName = current[k];
3400: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3401: }
3402: } else {
3403: for (var k=changedVal; k<oldVal; k++) {
3404: var elementName = current[k];
3405: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3406: }
3407: }
3408: return;
3409: }
3410:
3411: function toggleProctoring(form,item) {
3412: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3413: if (fieldsets.length) {
3414: var radioname = 'proctoring_available_'+item;
3415: var num = form.elements[radioname].length;
3416: if (num) {
3417: var setvis = '';
3418: for (var i=0; i<num; i++) {
3419: if (form.elements[radioname][i].checked) {
3420: if (form.elements[radioname][i].value == '1') {
3421: setvis = 1;
3422: break;
3423: }
3424: }
3425: }
3426: for (var j=0; j<fieldsets.length; j++) {
3427: if (setvis) {
3428: fieldsets[j].style.display = 'block';
3429: } else {
3430: fieldsets[j].style.display = 'none';
3431: }
3432: }
3433: }
3434: }
3435: return;
3436: }
3437:
3438: // ]]>
3439: </script>
3440:
3441: ENDSCRIPT
3442: }
3443:
3444:
1.320 raeburn 3445: sub lti_javascript {
1.405 raeburn 3446: my ($dom,$settings) = @_;
3447: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3448: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3449: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3450: return $togglejs.'
3451: <script type="text/javascript">
3452: // <![CDATA[
3453:
3454: '.$linkprot_js.'
3455:
3456: // ]]>
3457: </script>
3458: ';
1.320 raeburn 3459: }
3460: my (%ordered,$total,%jstext);
1.390 raeburn 3461: $total = scalar(keys(%{$settings}));
1.320 raeburn 3462: foreach my $item (keys(%{$settings})) {
3463: if (ref($settings->{$item}) eq 'HASH') {
3464: my $num = $settings->{$item}{'order'};
1.390 raeburn 3465: if ($num eq '') {
3466: $num = $total - 1;
3467: }
1.320 raeburn 3468: $ordered{$num} = $item;
3469: }
3470: }
3471: my @jsarray = ();
3472: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3473: push(@jsarray,$ordered{$item});
3474: }
3475: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3476: return <<"ENDSCRIPT";
3477: <script type="text/javascript">
3478: // <![CDATA[
3479: function reorderLTI(form,item) {
3480: var changedVal;
3481: $jstext
3482: var newpos = 'lti_pos_add';
3483: var maxh = 1 + $total;
3484: var current = new Array;
3485: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3486: if (item == newpos) {
3487: changedVal = newitemVal;
3488: } else {
3489: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3490: current[newitemVal] = newpos;
3491: }
3492: for (var i=0; i<lti.length; i++) {
3493: var elementName = 'lti_pos_'+lti[i];
3494: if (elementName != item) {
3495: if (form.elements[elementName]) {
3496: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3497: current[currVal] = elementName;
3498: }
3499: }
3500: }
3501: var oldVal;
3502: for (var j=0; j<maxh; j++) {
3503: if (current[j] == undefined) {
3504: oldVal = j;
3505: }
3506: }
3507: if (oldVal < changedVal) {
3508: for (var k=oldVal+1; k<=changedVal ; k++) {
3509: var elementName = current[k];
3510: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3511: }
3512: } else {
3513: for (var k=changedVal; k<oldVal; k++) {
3514: var elementName = current[k];
3515: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3516: }
3517: }
3518: return;
3519: }
1.406 raeburn 3520:
3521: $linkprot_js
3522:
1.320 raeburn 3523: // ]]>
3524: </script>
3525:
3526: $togglejs
3527:
3528: ENDSCRIPT
3529: }
3530:
3531: sub lti_toggle_js {
1.405 raeburn 3532: my ($dom) = @_;
1.325 raeburn 3533: my %lcauthparmtext = &Apache::lonlocal::texthash (
3534: localauth => 'Local auth argument',
3535: krb => 'Kerberos domain',
3536: );
1.391 raeburn 3537: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3538: &js_escape(\$crsincalert);
1.405 raeburn 3539: my %servers = &Apache::lonnet::get_servers($dom,'library');
3540: my $primary = &Apache::lonnet::domain($dom,'primary');
3541: my $course_servers = "'".join("','",keys(%servers))."'";
1.320 raeburn 3542: return <<"ENDSCRIPT";
3543: <script type="text/javascript">
3544: // <![CDATA[
3545:
3546: function toggleLTI(form,setting,item) {
1.391 raeburn 3547: if ((setting == 'requser') || (setting == 'crsinc')) {
3548: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3549: var setvis = '';
3550: var radioname = 'lti_requser_'+item;
3551: var num = form.elements[radioname].length;
3552: if (num) {
3553: for (var i=0; i<num; i++) {
3554: if (form.elements[radioname][i].checked) {
3555: if (form.elements[radioname][i].value == '1') {
3556: setvis = 1;
3557: break;
3558: }
3559: }
3560: }
3561: }
3562: if (usrfieldsets.length) {
3563: for (var j=0; j<usrfieldsets.length; j++) {
3564: if (setvis) {
3565: usrfieldsets[j].style.display = 'block';
3566: } else {
3567: usrfieldsets[j].style.display = 'none';
3568: }
3569: }
3570: }
3571: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3572: if (crsfieldsets.length) {
3573: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3574: var num = form.elements[radioname].length;
3575: if (num) {
1.391 raeburn 3576: var crsvis = '';
1.345 raeburn 3577: for (var i=0; i<num; i++) {
3578: if (form.elements[radioname][i].checked) {
3579: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3580: if (setvis == '') {
3581: if (setting == 'crsinc'){
3582: alert("$crsincalert");
3583: form.elements[radioname][0].checked = true;
3584: }
3585: } else {
3586: crsvis = 1;
3587: }
3588: break;
1.345 raeburn 3589: }
3590: }
3591: }
1.391 raeburn 3592: setvis = crsvis;
3593: }
3594: for (var j=0; j<crsfieldsets.length; j++) {
3595: if (setvis) {
3596: crsfieldsets[j].style.display = 'block';
3597: } else {
3598: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3599: }
3600: }
3601: }
1.363 raeburn 3602: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3603: var radioname = '';
3604: var divid = '';
3605: if (setting == 'user') {
3606: radioname = 'lti_mapuser_'+item;
3607: divid = 'lti_userfield_'+item;
1.343 raeburn 3608: } else if (setting == 'crs') {
1.320 raeburn 3609: radioname = 'lti_mapcrs_'+item;
3610: divid = 'lti_crsfield_'+item;
1.363 raeburn 3611: } else if (setting == 'callback') {
3612: radioname = 'lti_callback_'+item;
3613: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3614: } else {
1.351 raeburn 3615: radioname = 'lti_passback_'+item;
1.337 raeburn 3616: divid = 'lti_passback_'+item;
1.320 raeburn 3617: }
3618: var num = form.elements[radioname].length;
3619: if (num) {
3620: var setvis = '';
3621: for (var i=0; i<num; i++) {
3622: if (form.elements[radioname][i].checked) {
1.363 raeburn 3623: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3624: if (form.elements[radioname][i].value == '1') {
3625: if (document.getElementById(divid)) {
3626: document.getElementById(divid).style.display = 'inline-block';
3627: }
3628: setvis = 1;
3629: break;
3630: }
3631: } else {
3632: if (form.elements[radioname][i].value == 'other') {
3633: if (document.getElementById(divid)) {
3634: document.getElementById(divid).style.display = 'inline-block';
3635: }
3636: setvis = 1;
3637: break;
1.320 raeburn 3638: }
3639: }
1.425 raeburn 3640: }
1.320 raeburn 3641: }
3642: if (!setvis) {
3643: if (document.getElementById(divid)) {
3644: document.getElementById(divid).style.display = 'none';
3645: }
3646: }
3647: }
3648: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3649: var numsec = form.elements['lti_crssec_'+item].length;
3650: if (numsec) {
3651: var setvis = '';
3652: for (var i=0; i<numsec; i++) {
3653: if (form.elements['lti_crssec_'+item][i].checked) {
3654: if (form.elements['lti_crssec_'+item][i].value == '1') {
3655: if (document.getElementById('lti_crssecfield_'+item)) {
3656: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3657: setvis = 1;
3658: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3659: if (numsrcsec) {
3660: var setsrcvis = '';
3661: for (var j=0; j<numsrcsec; j++) {
3662: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3663: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3664: if (document.getElementById('lti_secsrcfield_'+item)) {
3665: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3666: setsrcvis = 1;
3667: }
3668: }
3669: }
3670: }
3671: if (!setsrcvis) {
3672: if (document.getElementById('lti_secsrcfield_'+item)) {
3673: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3674: }
3675: }
3676: }
3677: }
3678: }
3679: }
3680: }
3681: if (!setvis) {
3682: if (document.getElementById('lti_crssecfield_'+item)) {
3683: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3684: }
3685: if (document.getElementById('lti_secsrcfield_'+item)) {
3686: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3687: }
3688: }
3689: }
1.325 raeburn 3690: } else if (setting == 'lcauth') {
3691: var numauth = form.elements['lti_lcauth_'+item].length;
3692: if (numauth) {
3693: for (var i=0; i<numauth; i++) {
3694: if (form.elements['lti_lcauth_'+item][i].checked) {
3695: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3696: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3697: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3698: } else {
3699: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3700: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3701: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3702: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3703: } else {
3704: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3705: }
3706: }
3707: }
3708: }
3709: }
3710: }
3711: }
1.326 raeburn 3712: } else if (setting == 'lcmenu') {
3713: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3714: var divid = 'lti_menufield_'+item;
3715: var setvis = '';
3716: for (var i=0; i<menus.length; i++) {
1.425 raeburn 3717: var radioname = menus[i];
1.326 raeburn 3718: var num = form.elements[radioname].length;
3719: if (num) {
3720: for (var j=0; j<num; j++) {
3721: if (form.elements[radioname][j].checked) {
3722: if (form.elements[radioname][j].value == '1') {
3723: if (document.getElementById(divid)) {
3724: document.getElementById(divid).style.display = 'inline-block';
3725: }
3726: setvis = 1;
3727: break;
3728: }
3729: }
3730: }
3731: }
3732: if (setvis == 1) {
3733: break;
3734: }
3735: }
3736: if (!setvis) {
3737: if (document.getElementById(divid)) {
3738: document.getElementById(divid).style.display = 'none';
3739: }
3740: }
1.320 raeburn 3741: }
3742: return;
3743: }
1.405 raeburn 3744:
1.320 raeburn 3745: // ]]>
3746: </script>
3747:
3748: ENDSCRIPT
3749: }
3750:
1.385 raeburn 3751: sub autoupdate_javascript {
3752: return <<"ENDSCRIPT";
3753: <script type="text/javascript">
3754: // <![CDATA[
3755: function toggleLastActiveDays(form) {
3756: var radioname = 'lastactive';
3757: var divid = 'lastactive_div';
3758: var num = form.elements[radioname].length;
3759: if (num) {
3760: var setvis = '';
3761: for (var i=0; i<num; i++) {
3762: if (form.elements[radioname][i].checked) {
3763: if (form.elements[radioname][i].value == '1') {
3764: if (document.getElementById(divid)) {
3765: document.getElementById(divid).style.display = 'inline-block';
3766: }
3767: setvis = 1;
3768: }
3769: break;
3770: }
3771: }
3772: if (!setvis) {
3773: if (document.getElementById(divid)) {
3774: document.getElementById(divid).style.display = 'none';
3775: }
3776: }
3777: }
3778: return;
3779: }
3780: // ]]>
3781: </script>
3782:
3783: ENDSCRIPT
3784: }
3785:
1.399 raeburn 3786: sub autoenroll_javascript {
3787: return <<"ENDSCRIPT";
3788: <script type="text/javascript">
3789: // <![CDATA[
3790: function toggleFailsafe(form) {
3791: var radioname = 'autoenroll_failsafe';
3792: var divid = 'autoenroll_failsafe_div';
3793: var num = form.elements[radioname].length;
3794: if (num) {
3795: var setvis = '';
3796: for (var i=0; i<num; i++) {
3797: if (form.elements[radioname][i].checked) {
3798: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3799: if (document.getElementById(divid)) {
3800: document.getElementById(divid).style.display = 'inline-block';
3801: }
3802: setvis = 1;
3803: }
3804: break;
3805: }
3806: }
3807: if (!setvis) {
3808: if (document.getElementById(divid)) {
3809: document.getElementById(divid).style.display = 'none';
3810: }
3811: }
3812: }
3813: return;
3814: }
3815: // ]]>
3816: </script>
3817:
3818: ENDSCRIPT
3819: }
3820:
1.386 raeburn 3821: sub saml_javascript {
3822: return <<"ENDSCRIPT";
3823: <script type="text/javascript">
3824: // <![CDATA[
1.425 raeburn 3825: function toggleSamlOptions(form,hostid) {
1.386 raeburn 3826: var radioname = 'saml_'+hostid;
3827: var tablecellon = 'samloptionson_'+hostid;
3828: var tablecelloff = 'samloptionsoff_'+hostid;
3829: var num = form.elements[radioname].length;
3830: if (num) {
1.425 raeburn 3831: var setvis = '';
1.386 raeburn 3832: for (var i=0; i<num; i++) {
3833: if (form.elements[radioname][i].checked) {
1.425 raeburn 3834: if (form.elements[radioname][i].value == '1') {
1.386 raeburn 3835: if (document.getElementById(tablecellon)) {
3836: document.getElementById(tablecellon).style.display='';
3837: }
3838: if (document.getElementById(tablecelloff)) {
3839: document.getElementById(tablecelloff).style.display='none';
3840: }
3841: setvis = 1;
3842: }
3843: break;
3844: }
3845: }
3846: if (!setvis) {
3847: if (document.getElementById(tablecellon)) {
3848: document.getElementById(tablecellon).style.display='none';
3849: }
3850: if (document.getElementById(tablecelloff)) {
3851: document.getElementById(tablecelloff).style.display='';
3852: }
3853: }
3854: }
3855: return;
3856: }
3857: // ]]>
3858: </script>
3859:
3860: ENDSCRIPT
3861: }
3862:
1.394 raeburn 3863: sub ipaccess_javascript {
3864: my ($settings) = @_;
3865: my (%ordered,$total,%jstext);
3866: $total = 0;
3867: if (ref($settings) eq 'HASH') {
3868: foreach my $item (keys(%{$settings})) {
3869: if (ref($settings->{$item}) eq 'HASH') {
3870: my $num = $settings->{$item}{'order'};
3871: $ordered{$num} = $item;
3872: }
3873: }
3874: $total = scalar(keys(%{$settings}));
3875: }
3876: my @jsarray = ();
3877: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3878: push(@jsarray,$ordered{$item});
3879: }
3880: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3881: return <<"ENDSCRIPT";
3882: <script type="text/javascript">
3883: // <![CDATA[
3884: function reorderIPaccess(form,item) {
3885: var changedVal;
3886: $jstext
3887: var newpos = 'ipaccess_pos_add';
3888: var maxh = 1 + $total;
3889: var current = new Array;
3890: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3891: if (item == newpos) {
3892: changedVal = newitemVal;
3893: } else {
3894: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3895: current[newitemVal] = newpos;
3896: }
3897: for (var i=0; i<ipaccess.length; i++) {
3898: var elementName = 'ipaccess_pos_'+ipaccess[i];
3899: if (elementName != item) {
3900: if (form.elements[elementName]) {
3901: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3902: current[currVal] = elementName;
3903: }
3904: }
3905: }
3906: var oldVal;
3907: for (var j=0; j<maxh; j++) {
3908: if (current[j] == undefined) {
3909: oldVal = j;
3910: }
3911: }
3912: if (oldVal < changedVal) {
3913: for (var k=oldVal+1; k<=changedVal ; k++) {
3914: var elementName = current[k];
3915: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3916: }
3917: } else {
3918: for (var k=changedVal; k<oldVal; k++) {
3919: var elementName = current[k];
3920: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3921: }
3922: }
3923: return;
3924: }
3925: // ]]>
3926: </script>
3927:
3928: ENDSCRIPT
3929: }
3930:
1.429 raeburn 3931: sub authordefaults_javascript {
3932: my %alert = &Apache::lonlocal::texthash (
3933: reqd => 'Warning: at least one editor needs to be available.',
3934: rest => 'Unchecking this editor disallowed while others unchecked.',
3935: );
3936: &js_escape(\%alert);
3937: return <<"ENDSCRIPT";
3938: <script type="text/javascript">
3939: // <![CDATA[
3940:
3941: function checkEditors(form,checkbox,current) {
3942: if (form.elements[checkbox].length != undefined) {
3943: var count = 0;
3944: for (var i=0; i<form.elements[checkbox].length; i++) {
3945: if (form.elements[checkbox][i].checked) {
3946: count ++;
3947: }
3948: }
3949: if (count == 0) {
3950: if (current.type =='radio') {
3951: current.checked = true;
3952: alert('$alert{reqd}\\n$alert{rest}');
3953: }
3954: }
3955: }
3956: return;
3957: }
3958: // ]]>
3959: </script>
3960:
3961: ENDSCRIPT
3962: }
3963:
1.3 raeburn 3964: sub print_autoenroll {
1.30 raeburn 3965: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3966: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 3967: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3968: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3969: $failsafesty = 'none';
3970: %failsafechecked = (
3971: off => ' checked="checked"',
3972: );
1.3 raeburn 3973: if (ref($settings) eq 'HASH') {
3974: if (exists($settings->{'run'})) {
3975: if ($settings->{'run'} eq '0') {
3976: $runoff = ' checked="checked" ';
3977: $runon = ' ';
3978: } else {
3979: $runon = ' checked="checked" ';
3980: $runoff = ' ';
3981: }
3982: } else {
3983: if ($autorun) {
3984: $runon = ' checked="checked" ';
3985: $runoff = ' ';
3986: } else {
3987: $runoff = ' checked="checked" ';
3988: $runon = ' ';
3989: }
3990: }
1.129 raeburn 3991: if (exists($settings->{'co-owners'})) {
3992: if ($settings->{'co-owners'} eq '0') {
3993: $coownersoff = ' checked="checked" ';
3994: $coownerson = ' ';
3995: } else {
3996: $coownerson = ' checked="checked" ';
3997: $coownersoff = ' ';
3998: }
3999: } else {
4000: $coownersoff = ' checked="checked" ';
4001: $coownerson = ' ';
4002: }
1.3 raeburn 4003: if (exists($settings->{'sender_domain'})) {
4004: $defdom = $settings->{'sender_domain'};
4005: }
1.399 raeburn 4006: if (exists($settings->{'failsafe'})) {
4007: $failsafe = $settings->{'failsafe'};
4008: if ($failsafe eq 'zero') {
1.400 raeburn 4009: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 4010: $failsafechecked{'off'} = '';
4011: $failsafesty = 'inline-block';
4012: } elsif ($failsafe eq 'any') {
4013: $failsafechecked{'any'} = ' checked="checked"';
4014: $failsafechecked{'off'} = '';
4015: }
4016: $autofailsafe = $settings->{'autofailsafe'};
4017: } elsif (exists($settings->{'autofailsafe'})) {
4018: $autofailsafe = $settings->{'autofailsafe'};
4019: if ($autofailsafe ne '') {
4020: $failsafechecked{'zero'} = ' checked="checked"';
4021: $failsafe = 'zero';
1.400 raeburn 4022: $failsafechecked{'off'} = '';
1.399 raeburn 4023: }
1.274 raeburn 4024: }
1.14 raeburn 4025: } else {
4026: if ($autorun) {
4027: $runon = ' checked="checked" ';
4028: $runoff = ' ';
4029: } else {
4030: $runoff = ' checked="checked" ';
4031: $runon = ' ';
4032: }
1.3 raeburn 4033: }
4034: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4035: my $notif_sender;
4036: if (ref($settings) eq 'HASH') {
4037: $notif_sender = $settings->{'sender_uname'};
4038: }
1.3 raeburn 4039: my $datatable='<tr class="LC_odd_row">'.
4040: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4041: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4042: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4043: $runon.' value="1" />'.&mt('Yes').'</label> '.
4044: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4045: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4046: '</tr><tr>'.
4047: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4048: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4049: &mt('username').': '.
4050: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4051: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4052: ': '.$domform.'</span></td></tr>'.
4053: '<tr class="LC_odd_row">'.
4054: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4055: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4056: '<input type="radio" name="autoassign_coowners"'.
4057: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4058: '<label><input type="radio" name="autoassign_coowners"'.
4059: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4060: '</tr><tr>'.
4061: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4062: '<td class="LC_left_item"><span class="LC_nobreak">'.
4063: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="off" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'off'}.' />'.&mt('Not in use').'</label></span> '.
4064: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="zero" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'zero'}.' />'.&mt('Retrieved section enrollment is zero').'</label></span><br />'.
4065: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="any" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'any'}.' />'.&mt('Retrieved section enrollment is zero or greater').'</label></span>'.
1.399 raeburn 4066: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4067: '<span class="LC_nobreak">'.
4068: &mt('Threshold for number of students in section to drop: [_1]',
4069: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4070: '</span></div></td></tr>';
1.274 raeburn 4071: $$rowtotal += 4;
1.3 raeburn 4072: return $datatable;
4073: }
4074:
4075: sub print_autoupdate {
1.30 raeburn 4076: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4077: my ($enable,$datatable);
1.3 raeburn 4078: if ($position eq 'top') {
1.385 raeburn 4079: my %choices = &Apache::lonlocal::texthash (
4080: run => 'Auto-update active?',
4081: classlists => 'Update information in classlists?',
4082: unexpired => 'Skip updates for users without active or future roles?',
4083: lastactive => 'Skip updates for inactive users?',
4084: );
4085: my $itemcount = 0;
1.3 raeburn 4086: my $updateon = ' ';
4087: my $updateoff = ' checked="checked" ';
4088: if (ref($settings) eq 'HASH') {
4089: if ($settings->{'run'} eq '1') {
4090: $updateon = $updateoff;
4091: $updateoff = ' ';
4092: }
4093: }
1.385 raeburn 4094: $enable = '<tr class="LC_odd_row">'.
4095: '<td>'.$choices{'run'}.'</td>'.
4096: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4097: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4098: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4099: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4100: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4101: '</tr>';
1.385 raeburn 4102: my @toggles = ('classlists','unexpired');
4103: my %defaultchecked = ('classlists' => 'off',
4104: 'unexpired' => 'off'
4105: );
4106: $$rowtotal ++;
4107: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4108: \%choices,$itemcount,'','','left','no');
4109: $datatable = $enable.$datatable;
4110: $$rowtotal += $itemcount;
4111: my $lastactiveon = ' ';
4112: my $lastactiveoff = ' checked="checked" ';
4113: my $lastactivestyle = 'none';
4114: my $lastactivedays;
4115: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4116: if (ref($settings) eq 'HASH') {
4117: if ($settings->{'lastactive'} =~ /^\d+$/) {
4118: $lastactiveon = $lastactiveoff;
4119: $lastactiveoff = ' ';
4120: $lastactivestyle = 'inline-block';
4121: $lastactivedays = $settings->{'lastactive'};
4122: }
4123: }
4124: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4125: $datatable .= '<tr'.$css_class.'>'.
4126: '<td>'.$choices{'lastactive'}.'</td>'.
4127: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4128: '<input type="radio" name="lastactive"'.
4129: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4130: ' <label>'.
4131: '<input type="radio" name="lastactive"'.
4132: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4133: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4134: ': '.&mt('inactive = no activity in last [_1] days',
4135: '<input type="text" size="5" name="lastactivedays" value="'.
4136: $lastactivedays.'" />').
4137: '</span></td>'.
4138: '</tr>';
4139: $$rowtotal ++;
1.131 raeburn 4140: } elsif ($position eq 'middle') {
4141: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4142: my $numinrow = 3;
4143: my $locknamesettings;
4144: $datatable .= &insttypes_row($settings,$types,$usertypes,
4145: $dom,$numinrow,$othertitle,
1.305 raeburn 4146: 'lockablenames',$rowtotal);
1.131 raeburn 4147: $$rowtotal ++;
1.3 raeburn 4148: } else {
1.44 raeburn 4149: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4150: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4151: 'permanentemail','id');
1.33 raeburn 4152: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4153: my $numrows = 0;
1.26 raeburn 4154: if (ref($types) eq 'ARRAY') {
4155: if (@{$types} > 0) {
4156: $datatable =
4157: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4158: \@fields,$types,\$numrows);
1.30 raeburn 4159: $$rowtotal += @{$types};
1.26 raeburn 4160: }
1.3 raeburn 4161: }
4162: $datatable .=
4163: &usertype_update_row($settings,{'default' => $othertitle},
4164: \%fieldtitles,\@fields,['default'],
4165: \$numrows);
1.30 raeburn 4166: $$rowtotal ++;
1.3 raeburn 4167: }
4168: return $datatable;
4169: }
4170:
1.125 raeburn 4171: sub print_autocreate {
4172: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4173: my (%createon,%createoff,%currhash);
1.125 raeburn 4174: my @types = ('xml','req');
4175: if (ref($settings) eq 'HASH') {
4176: foreach my $item (@types) {
4177: $createoff{$item} = ' checked="checked" ';
4178: $createon{$item} = ' ';
4179: if (exists($settings->{$item})) {
4180: if ($settings->{$item}) {
4181: $createon{$item} = ' checked="checked" ';
4182: $createoff{$item} = ' ';
4183: }
4184: }
4185: }
1.210 raeburn 4186: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4187: $currhash{$settings->{'xmldc'}} = 1;
4188: }
1.125 raeburn 4189: } else {
4190: foreach my $item (@types) {
4191: $createoff{$item} = ' checked="checked" ';
4192: $createon{$item} = ' ';
4193: }
4194: }
4195: $$rowtotal += 2;
1.191 raeburn 4196: my $numinrow = 2;
1.125 raeburn 4197: my $datatable='<tr class="LC_odd_row">'.
4198: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4199: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4200: '<input type="radio" name="autocreate_xml"'.
4201: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4202: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4203: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4204: '</td></tr><tr>'.
4205: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4206: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4207: '<input type="radio" name="autocreate_req"'.
4208: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4209: '<label><input type="radio" name="autocreate_req"'.
4210: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4211: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4212: 'autocreate_xmldc',%currhash);
1.247 raeburn 4213: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4214: if ($numdc > 1) {
1.247 raeburn 4215: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4216: '</td><td class="LC_left_item">';
1.125 raeburn 4217: } else {
1.247 raeburn 4218: $datatable .= &mt('Course creation processed as:').
4219: '</td><td class="LC_right_item">';
1.125 raeburn 4220: }
1.247 raeburn 4221: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4222: $$rowtotal += $rows;
1.125 raeburn 4223: return $datatable;
4224: }
4225:
1.23 raeburn 4226: sub print_directorysrch {
1.277 raeburn 4227: my ($position,$dom,$settings,$rowtotal) = @_;
4228: my $datatable;
4229: if ($position eq 'top') {
4230: my $instsrchon = ' ';
4231: my $instsrchoff = ' checked="checked" ';
4232: my ($exacton,$containson,$beginson);
4233: my $instlocalon = ' ';
4234: my $instlocaloff = ' checked="checked" ';
4235: if (ref($settings) eq 'HASH') {
4236: if ($settings->{'available'} eq '1') {
4237: $instsrchon = $instsrchoff;
4238: $instsrchoff = ' ';
4239: }
4240: if ($settings->{'localonly'} eq '1') {
4241: $instlocalon = $instlocaloff;
4242: $instlocaloff = ' ';
4243: }
4244: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4245: foreach my $type (@{$settings->{'searchtypes'}}) {
4246: if ($type eq 'exact') {
4247: $exacton = ' checked="checked" ';
4248: } elsif ($type eq 'contains') {
4249: $containson = ' checked="checked" ';
4250: } elsif ($type eq 'begins') {
4251: $beginson = ' checked="checked" ';
4252: }
4253: }
4254: } else {
4255: if ($settings->{'searchtypes'} eq 'exact') {
4256: $exacton = ' checked="checked" ';
4257: } elsif ($settings->{'searchtypes'} eq 'contains') {
4258: $containson = ' checked="checked" ';
4259: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4260: $exacton = ' checked="checked" ';
4261: $containson = ' checked="checked" ';
4262: }
4263: }
1.277 raeburn 4264: }
4265: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4266: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4267:
4268: my $numinrow = 4;
4269: my $cansrchrow = 0;
4270: $datatable='<tr class="LC_odd_row">'.
4271: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4272: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4273: '<input type="radio" name="dirsrch_available"'.
4274: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4275: '<label><input type="radio" name="dirsrch_available"'.
4276: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4277: '</tr><tr>'.
4278: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4279: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4280: '<input type="radio" name="dirsrch_instlocalonly"'.
4281: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4282: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4283: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4284: '</tr>';
4285: $$rowtotal += 2;
4286: if (ref($usertypes) eq 'HASH') {
4287: if (keys(%{$usertypes}) > 0) {
4288: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4289: $numinrow,$othertitle,'cansearch',
4290: $rowtotal);
1.277 raeburn 4291: $cansrchrow = 1;
1.25 raeburn 4292: }
1.23 raeburn 4293: }
1.277 raeburn 4294: if ($cansrchrow) {
4295: $$rowtotal ++;
4296: $datatable .= '<tr>';
4297: } else {
4298: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4299: }
1.277 raeburn 4300: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4301: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4302: foreach my $title (@{$titleorder}) {
4303: if (defined($searchtitles->{$title})) {
4304: my $check = ' ';
4305: if (ref($settings) eq 'HASH') {
4306: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4307: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4308: $check = ' checked="checked" ';
4309: }
1.39 raeburn 4310: }
1.25 raeburn 4311: }
1.277 raeburn 4312: $datatable .= '<td class="LC_left_item">'.
4313: '<span class="LC_nobreak"><label>'.
4314: '<input type="checkbox" name="searchby" '.
4315: 'value="'.$title.'"'.$check.'/>'.
4316: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4317: }
4318: }
1.277 raeburn 4319: $datatable .= '</tr></table></td></tr>';
4320: $$rowtotal ++;
4321: if ($cansrchrow) {
4322: $datatable .= '<tr class="LC_odd_row">';
4323: } else {
4324: $datatable .= '<tr>';
4325: }
4326: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4327: '<td class="LC_left_item" colspan="2">'.
4328: '<span class="LC_nobreak"><label>'.
4329: '<input type="checkbox" name="searchtypes" '.
4330: $exacton.' value="exact" />'.&mt('Exact match').
4331: '</label> '.
4332: '<label><input type="checkbox" name="searchtypes" '.
4333: $beginson.' value="begins" />'.&mt('Begins with').
4334: '</label> '.
4335: '<label><input type="checkbox" name="searchtypes" '.
4336: $containson.' value="contains" />'.&mt('Contains').
4337: '</label></span></td></tr>';
4338: $$rowtotal ++;
1.26 raeburn 4339: } else {
1.277 raeburn 4340: my $domsrchon = ' checked="checked" ';
4341: my $domsrchoff = ' ';
4342: my $domlocalon = ' ';
4343: my $domlocaloff = ' checked="checked" ';
4344: if (ref($settings) eq 'HASH') {
4345: if ($settings->{'lclocalonly'} eq '1') {
4346: $domlocalon = $domlocaloff;
4347: $domlocaloff = ' ';
4348: }
4349: if ($settings->{'lcavailable'} eq '0') {
4350: $domsrchoff = $domsrchon;
4351: $domsrchon = ' ';
4352: }
4353: }
4354: $datatable='<tr class="LC_odd_row">'.
4355: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4356: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4357: '<input type="radio" name="dirsrch_domavailable"'.
4358: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4359: '<label><input type="radio" name="dirsrch_domavailable"'.
4360: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4361: '</tr><tr>'.
4362: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4363: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4364: '<input type="radio" name="dirsrch_domlocalonly"'.
4365: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4366: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4367: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4368: '</tr>';
4369: $$rowtotal += 2;
1.26 raeburn 4370: }
1.25 raeburn 4371: return $datatable;
4372: }
4373:
1.28 raeburn 4374: sub print_contacts {
1.286 raeburn 4375: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4376: my $datatable;
4377: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4378: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4379: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4380: if ($position eq 'top') {
4381: if (ref($settings) eq 'HASH') {
4382: foreach my $item (@contacts) {
4383: if (exists($settings->{$item})) {
4384: $to{$item} = $settings->{$item};
4385: }
4386: }
4387: }
4388: } elsif ($position eq 'middle') {
4389: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4390: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4391: foreach my $type (@mailings) {
4392: $otheremails{$type} = '';
4393: }
1.340 raeburn 4394: } elsif ($position eq 'lower') {
4395: if (ref($settings) eq 'HASH') {
4396: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4397: %lonstatus = %{$settings->{'lonstatus'}};
4398: }
4399: }
1.286 raeburn 4400: } else {
4401: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4402: foreach my $type (@mailings) {
4403: $otheremails{$type} = '';
4404: }
1.286 raeburn 4405: $bccemails{'helpdeskmail'} = '';
4406: $bccemails{'otherdomsmail'} = '';
4407: $includestr{'helpdeskmail'} = '';
4408: $includestr{'otherdomsmail'} = '';
4409: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4410: }
1.28 raeburn 4411: if (ref($settings) eq 'HASH') {
1.340 raeburn 4412: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4413: foreach my $type (@mailings) {
4414: if (exists($settings->{$type})) {
4415: if (ref($settings->{$type}) eq 'HASH') {
4416: foreach my $item (@contacts) {
4417: if ($settings->{$type}{$item}) {
4418: $checked{$type}{$item} = ' checked="checked" ';
4419: }
4420: }
4421: $otheremails{$type} = $settings->{$type}{'others'};
4422: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4423: $bccemails{$type} = $settings->{$type}{'bcc'};
4424: if ($settings->{$type}{'include'} ne '') {
4425: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4426: $includestr{$type} = &unescape($includestr{$type});
4427: }
4428: }
4429: }
4430: } elsif ($type eq 'lonstatusmail') {
4431: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4432: }
1.28 raeburn 4433: }
4434: }
1.286 raeburn 4435: if ($position eq 'bottom') {
4436: foreach my $type (@mailings) {
4437: $bccemails{$type} = $settings->{$type}{'bcc'};
4438: if ($settings->{$type}{'include'} ne '') {
4439: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4440: $includestr{$type} = &unescape($includestr{$type});
4441: }
4442: }
4443: if (ref($settings->{'helpform'}) eq 'HASH') {
4444: if (ref($fields) eq 'ARRAY') {
4445: foreach my $field (@{$fields}) {
4446: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4447: }
1.286 raeburn 4448: }
4449: if (exists($settings->{'helpform'}{'maxsize'})) {
4450: $maxsize = $settings->{'helpform'}{'maxsize'};
4451: } else {
1.289 raeburn 4452: $maxsize = '1.0';
1.286 raeburn 4453: }
4454: } else {
4455: if (ref($fields) eq 'ARRAY') {
4456: foreach my $field (@{$fields}) {
4457: $currfield{$field} = 'yes';
1.134 raeburn 4458: }
1.28 raeburn 4459: }
1.286 raeburn 4460: $maxsize = '1.0';
1.28 raeburn 4461: }
4462: }
4463: } else {
1.286 raeburn 4464: if ($position eq 'top') {
4465: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4466: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4467: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4468: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4469: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4470: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4471: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4472: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4473: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4474: } elsif ($position eq 'bottom') {
4475: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4476: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4477: if (ref($fields) eq 'ARRAY') {
4478: foreach my $field (@{$fields}) {
4479: $currfield{$field} = 'yes';
4480: }
4481: }
4482: $maxsize = '1.0';
4483: }
1.28 raeburn 4484: }
4485: my ($titles,$short_titles) = &contact_titles();
4486: my $rownum = 0;
4487: my $css_class;
1.286 raeburn 4488: if ($position eq 'top') {
4489: foreach my $item (@contacts) {
4490: $css_class = $rownum%2?' class="LC_odd_row"':'';
4491: $datatable .= '<tr'.$css_class.'>'.
4492: '<td><span class="LC_nobreak">'.$titles->{$item}.
4493: '</span></td><td class="LC_right_item">'.
4494: '<input type="text" name="'.$item.'" value="'.
4495: $to{$item}.'" /></td></tr>';
4496: $rownum ++;
4497: }
1.315 raeburn 4498: } elsif ($position eq 'bottom') {
4499: $css_class = $rownum%2?' class="LC_odd_row"':'';
4500: $datatable .= '<tr'.$css_class.'>'.
4501: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4502: &mt('(e-mail, subject, and description always shown)').
4503: '</td><td class="LC_left_item">';
4504: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4505: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4506: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4507: foreach my $field (@{$fields}) {
4508: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4509: if (($field eq 'screenshot') || ($field eq 'cc')) {
4510: $datatable .= ' '.&mt('(logged-in users)');
4511: }
4512: $datatable .='</td><td>';
4513: my $clickaction;
4514: if ($field eq 'screenshot') {
4515: $clickaction = ' onclick="screenshotSize(this);"';
4516: }
4517: if (ref($possoptions->{$field}) eq 'ARRAY') {
4518: foreach my $option (@{$possoptions->{$field}}) {
4519: my $checked;
4520: if ($currfield{$field} eq $option) {
4521: $checked = ' checked="checked"';
4522: }
4523: $datatable .= '<span class="LC_nobreak"><label>'.
4524: '<input type="radio" name="helpform_'.$field.'" '.
4525: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4526: '</label></span>'.(' 'x2);
4527: }
4528: }
4529: if ($field eq 'screenshot') {
4530: my $display;
4531: if ($currfield{$field} eq 'no') {
4532: $display = ' style="display:none"';
4533: }
1.334 raeburn 4534: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4535: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4536: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4537: }
4538: $datatable .= '</td></tr>';
4539: }
4540: $datatable .= '</table>';
4541: }
4542: $datatable .= '</td></tr>'."\n";
4543: $rownum ++;
4544: }
1.340 raeburn 4545: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4546: foreach my $type (@mailings) {
4547: $css_class = $rownum%2?' class="LC_odd_row"':'';
4548: $datatable .= '<tr'.$css_class.'>'.
4549: '<td><span class="LC_nobreak">'.
4550: $titles->{$type}.': </span></td>'.
4551: '<td class="LC_left_item">';
4552: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4553: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4554: }
4555: $datatable .= '<span class="LC_nobreak">';
4556: foreach my $item (@contacts) {
4557: $datatable .= '<label>'.
4558: '<input type="checkbox" name="'.$type.'"'.
4559: $checked{$type}{$item}.
4560: ' value="'.$item.'" />'.$short_titles->{$item}.
4561: '</label> ';
4562: }
4563: $datatable .= '</span><br />'.&mt('Others').': '.
4564: '<input type="text" name="'.$type.'_others" '.
4565: 'value="'.$otheremails{$type}.'" />';
4566: my %locchecked;
4567: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4568: foreach my $loc ('s','b') {
4569: if ($includeloc{$type} eq $loc) {
4570: $locchecked{$loc} = ' checked="checked"';
4571: last;
4572: }
4573: }
4574: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4575: '<input type="text" name="'.$type.'_bcc" '.
4576: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4577: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4578: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4579: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4580: '<span class="LC_nobreak">'.&mt('Location:').' '.
4581: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4582: (' 'x2).
4583: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4584: '</span></fieldset>';
4585: }
4586: $datatable .= '</td></tr>'."\n";
4587: $rownum ++;
4588: }
1.28 raeburn 4589: }
1.286 raeburn 4590: if ($position eq 'middle') {
4591: my %choices;
1.340 raeburn 4592: my $corelink = &core_link_msu();
4593: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4594: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4595: $corelink);
4596: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4597: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4598: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4599: 'reportupdates' => 'on',
4600: 'reportstatus' => 'on');
1.286 raeburn 4601: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4602: \%choices,$rownum);
4603: $datatable .= $reports;
1.340 raeburn 4604: } elsif ($position eq 'lower') {
1.378 raeburn 4605: my (%current,%excluded,%weights);
1.340 raeburn 4606: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4607: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4608: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4609: } else {
1.378 raeburn 4610: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4611: }
4612: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4613: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4614: } else {
1.378 raeburn 4615: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4616: }
4617: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4618: foreach my $type ('E','W','N','U') {
1.340 raeburn 4619: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4620: $weights{$type} = $lonstatus{'weights'}{$type};
4621: } else {
4622: $weights{$type} = $defaults->{$type};
4623: }
4624: }
4625: } else {
1.341 raeburn 4626: foreach my $type ('E','W','N','U') {
1.340 raeburn 4627: $weights{$type} = $defaults->{$type};
4628: }
4629: }
4630: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4631: if (@{$lonstatus{'excluded'}} > 0) {
4632: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4633: }
4634: }
1.425 raeburn 4635: foreach my $item ('errorthreshold','errorsysmail') {
1.378 raeburn 4636: $css_class = $rownum%2?' class="LC_odd_row"':'';
4637: $datatable .= '<tr'.$css_class.'>'.
4638: '<td class="LC_left_item"><span class="LC_nobreak">'.
4639: $titles->{$item}.
4640: '</span></td><td class="LC_left_item">'.
4641: '<input type="text" name="'.$item.'" value="'.
4642: $current{$item}.'" size="5" /></td></tr>';
4643: $rownum ++;
4644: }
1.340 raeburn 4645: $css_class = $rownum%2?' class="LC_odd_row"':'';
4646: $datatable .= '<tr'.$css_class.'>'.
4647: '<td class="LC_left_item">'.
4648: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4649: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4650: foreach my $type ('E','W','N','U') {
1.340 raeburn 4651: $datatable .= '<td>'.$names->{$type}.'<br />'.
4652: '<input type="text" name="errorweights_'.$type.'" value="'.
4653: $weights{$type}.'" size="5" /></td>';
4654: }
4655: $datatable .= '</tr></table></tr>';
4656: $rownum ++;
4657: $css_class = $rownum%2?' class="LC_odd_row"':'';
4658: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4659: $titles->{'errorexcluded'}.'</td>'.
4660: '<td class="LC_left_item"><table>';
4661: my $numinrow = 4;
4662: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4663: for (my $i=0; $i<@ids; $i++) {
4664: my $rem = $i%($numinrow);
4665: if ($rem == 0) {
4666: if ($i > 0) {
4667: $datatable .= '</tr>';
4668: }
4669: $datatable .= '<tr>';
4670: }
4671: my $check;
4672: if ($excluded{$ids[$i]}) {
4673: $check = ' checked="checked" ';
4674: }
4675: $datatable .= '<td class="LC_left_item">'.
4676: '<span class="LC_nobreak"><label>'.
4677: '<input type="checkbox" name="errorexcluded" '.
4678: 'value="'.$ids[$i].'"'.$check.' />'.
4679: $ids[$i].'</label></span></td>';
4680: }
4681: my $colsleft = $numinrow - @ids%($numinrow);
4682: if ($colsleft > 1 ) {
4683: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4684: ' </td>';
4685: } elsif ($colsleft == 1) {
4686: $datatable .= '<td class="LC_left_item"> </td>';
4687: }
4688: $datatable .= '</tr></table></td></tr>';
4689: $rownum ++;
1.286 raeburn 4690: } elsif ($position eq 'bottom') {
1.315 raeburn 4691: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4692: my (@posstypes,%usertypeshash);
4693: if (ref($types) eq 'ARRAY') {
4694: @posstypes = @{$types};
4695: }
4696: if (@posstypes) {
4697: if (ref($usertypes) eq 'HASH') {
4698: %usertypeshash = %{$usertypes};
4699: }
4700: my @overridden;
4701: my $numinrow = 4;
4702: if (ref($settings) eq 'HASH') {
4703: if (ref($settings->{'overrides'}) eq 'HASH') {
4704: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4705: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4706: push(@overridden,$key);
4707: foreach my $item (@contacts) {
4708: if ($settings->{'overrides'}{$key}{$item}) {
4709: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4710: }
4711: }
4712: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4713: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4714: $includeloc{'override_'.$key} = '';
4715: $includestr{'override_'.$key} = '';
4716: if ($settings->{'overrides'}{$key}{'include'} ne '') {
1.425 raeburn 4717: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
1.315 raeburn 4718: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4719: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4720: }
1.286 raeburn 4721: }
4722: }
4723: }
1.315 raeburn 4724: }
4725: my $customclass = 'LC_helpdesk_override';
4726: my $optionsprefix = 'LC_options_helpdesk_';
4727:
4728: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4729: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4730: $numinrow,$othertitle,'overrides',
4731: \$rownum,$onclicktypes,$customclass);
4732: $rownum ++;
4733: $usertypeshash{'default'} = $othertitle;
4734: foreach my $status (@posstypes) {
4735: my $css_class;
4736: if ($rownum%2) {
4737: $css_class = 'LC_odd_row ';
4738: }
4739: $css_class .= $customclass;
4740: my $rowid = $optionsprefix.$status;
4741: my $hidden = 1;
4742: my $currstyle = 'display:none';
4743: if (grep(/^\Q$status\E$/,@overridden)) {
4744: $currstyle = 'display:table-row';
4745: $hidden = 0;
4746: }
4747: my $key = 'override_'.$status;
4748: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4749: $includeloc{$key},$includestr{$key},$status,$rowid,
4750: $usertypeshash{$status},$css_class,$currstyle,
4751: \@contacts,$short_titles);
4752: unless ($hidden) {
4753: $rownum ++;
1.286 raeburn 4754: }
4755: }
1.134 raeburn 4756: }
1.28 raeburn 4757: }
1.30 raeburn 4758: $$rowtotal += $rownum;
1.28 raeburn 4759: return $datatable;
4760: }
4761:
1.340 raeburn 4762: sub core_link_msu {
4763: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4764: &mt('LON-CAPA core group - MSU'),600,500);
4765: }
4766:
1.315 raeburn 4767: sub overridden_helpdesk {
4768: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4769: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4770: my $class = 'LC_left_item';
4771: if ($css_class) {
4772: $css_class = ' class="'.$css_class.'"';
4773: }
4774: if ($rowid) {
4775: $rowid = ' id="'.$rowid.'"';
4776: }
4777: if ($rowstyle) {
4778: $rowstyle = ' style="'.$rowstyle.'"';
4779: }
4780: my ($output,$description);
4781: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4782: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4783: "<td>$description</td>\n".
4784: '<td class="'.$class.'" colspan="2">'.
4785: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4786: '<span class="LC_nobreak">';
4787: if (ref($contacts) eq 'ARRAY') {
4788: foreach my $item (@{$contacts}) {
4789: my $check;
4790: if (ref($checked) eq 'HASH') {
4791: $check = $checked->{$item};
4792: }
4793: my $title;
4794: if (ref($short_titles) eq 'HASH') {
1.425 raeburn 4795: $title = $short_titles->{$item};
1.315 raeburn 4796: }
4797: $output .= '<label>'.
4798: '<input type="checkbox" name="override_'.$type.'"'.$check.
4799: ' value="'.$item.'" />'.$title.'</label> ';
4800: }
4801: }
4802: $output .= '</span><br />'.&mt('Others').': '.
4803: '<input type="text" name="override_'.$type.'_others" '.
4804: 'value="'.$otheremails.'" />';
4805: my %locchecked;
4806: foreach my $loc ('s','b') {
4807: if ($includeloc eq $loc) {
4808: $locchecked{$loc} = ' checked="checked"';
4809: last;
4810: }
4811: }
4812: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4813: '<input type="text" name="override_'.$type.'_bcc" '.
4814: 'value="'.$bccemails.'" /></fieldset>'.
4815: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4816: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4817: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4818: '<span class="LC_nobreak">'.&mt('Location:').' '.
4819: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4820: (' 'x2).
4821: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4822: '</span></fieldset>'.
4823: '</td></tr>'."\n";
4824: return $output;
4825: }
4826:
1.286 raeburn 4827: sub contacts_javascript {
4828: return <<"ENDSCRIPT";
4829:
4830: <script type="text/javascript">
4831: // <![CDATA[
4832:
4833: function screenshotSize(field) {
4834: if (document.getElementById('help_screenshotsize')) {
4835: if (field.value == 'no') {
1.289 raeburn 4836: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4837: } else {
4838: document.getElementById('help_screenshotsize').style.display="";
4839: }
4840: }
4841: return;
4842: }
4843:
1.315 raeburn 4844: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4845: if (form.elements[checkbox].length != undefined) {
4846: var count = 0;
4847: if (docount) {
4848: for (var i=0; i<form.elements[checkbox].length; i++) {
4849: if (form.elements[checkbox][i].checked) {
4850: count ++;
4851: }
4852: }
4853: }
4854: for (var i=0; i<form.elements[checkbox].length; i++) {
4855: var type = form.elements[checkbox][i].value;
4856: if (document.getElementById(prefix+type)) {
4857: if (form.elements[checkbox][i].checked) {
4858: document.getElementById(prefix+type).style.display = 'table-row';
4859: if (count % 2 == 1) {
4860: document.getElementById(prefix+type).className = target+' LC_odd_row';
4861: } else {
4862: document.getElementById(prefix+type).className = target;
4863: }
4864: count ++;
4865: } else {
4866: document.getElementById(prefix+type).style.display = 'none';
4867: }
4868: }
4869: }
4870: }
4871: return;
4872: }
4873:
1.286 raeburn 4874: // ]]>
4875: </script>
4876:
4877: ENDSCRIPT
4878: }
4879:
1.118 jms 4880: sub print_helpsettings {
1.282 raeburn 4881: my ($position,$dom,$settings,$rowtotal) = @_;
4882: my $confname = $dom.'-domainconfig';
1.285 raeburn 4883: my $formname = 'display';
1.168 raeburn 4884: my ($datatable,$itemcount);
1.282 raeburn 4885: if ($position eq 'top') {
4886: $itemcount = 1;
4887: my (%choices,%defaultchecked,@toggles);
4888: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4889: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4890: &mt('LON-CAPA bug tracker'),600,500));
4891: %defaultchecked = ('submitbugs' => 'on');
4892: @toggles = ('submitbugs');
4893: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4894: \%choices,$itemcount);
4895: $$rowtotal ++;
4896: } else {
4897: my $css_class;
4898: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4899: my (%customroles,%ordered,%current);
1.301 raeburn 4900: if (ref($settings) eq 'HASH') {
4901: if (ref($settings->{'adhoc'}) eq 'HASH') {
4902: %current = %{$settings->{'adhoc'}};
4903: }
1.285 raeburn 4904: }
4905: my $count = 0;
4906: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4907: if ($key=~/^rolesdef\_(\w+)$/) {
4908: my $rolename = $1;
1.285 raeburn 4909: my (%privs,$order);
1.282 raeburn 4910: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4911: $customroles{$rolename} = \%privs;
1.285 raeburn 4912: if (ref($current{$rolename}) eq 'HASH') {
4913: $order = $current{$rolename}{'order'};
4914: }
4915: if ($order eq '') {
4916: $order = $count;
4917: }
4918: $ordered{$order} = $rolename;
4919: $count++;
4920: }
4921: }
4922: my $maxnum = scalar(keys(%ordered));
4923: my @roles_by_num = ();
4924: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4925: push(@roles_by_num,$item);
4926: }
4927: my $context = 'domprefs';
4928: my $crstype = 'Course';
4929: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4930: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4931: my ($numstatustypes,@jsarray);
4932: if (ref($types) eq 'ARRAY') {
4933: if (@{$types} > 0) {
4934: $numstatustypes = scalar(@{$types});
4935: push(@accesstypes,'status');
4936: @jsarray = ('bystatus');
1.282 raeburn 4937: }
4938: }
1.290 raeburn 4939: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4940: if (keys(%domhelpdesk)) {
4941: push(@accesstypes,('inc','exc'));
4942: push(@jsarray,('notinc','notexc'));
4943: }
4944: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4945: my $context = 'domprefs';
4946: my $crstype = 'Course';
1.285 raeburn 4947: my $prefix = 'helproles_';
4948: my $add_class = 'LC_hidden';
4949: foreach my $num (@roles_by_num) {
4950: my $role = $ordered{$num};
4951: my ($desc,$access,@statuses);
4952: if (ref($current{$role}) eq 'HASH') {
4953: $desc = $current{$role}{'desc'};
4954: $access = $current{$role}{'access'};
4955: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4956: @statuses = @{$current{$role}{'insttypes'}};
4957: }
4958: }
4959: if ($desc eq '') {
4960: $desc = $role;
4961: }
4962: my $identifier = 'custhelp'.$num;
1.282 raeburn 4963: my %full=();
4964: my %levels= (
4965: course => {},
4966: domain => {},
4967: system => {},
4968: );
4969: my %levelscurrent=(
4970: course => {},
4971: domain => {},
4972: system => {},
4973: );
4974: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4975: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4976: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4977: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4978: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4979: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4980: for (my $k=0; $k<=$maxnum; $k++) {
4981: my $vpos = $k+1;
4982: my $selstr;
4983: if ($k == $num) {
4984: $selstr = ' selected="selected" ';
4985: }
4986: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4987: }
4988: $datatable .= '</select>'.(' 'x2).
4989: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4990: '</td>'.
4991: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4992: &mt('Name shown to users:').
4993: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4994: '</fieldset>'.
4995: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4996: $othertitle,$usertypes,$types,\%domhelpdesk).
4997: '<fieldset>'.
4998: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4999: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 5000: \%levelscurrent,$identifier,
5001: 'LC_hidden',$prefix.$num.'_privs').
5002: '</fieldset></td>';
1.282 raeburn 5003: $itemcount ++;
5004: }
5005: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5006: my $newcust = 'custhelp'.$count;
5007: my (%privs,%levelscurrent);
5008: my %full=();
5009: my %levels= (
5010: course => {},
5011: domain => {},
5012: system => {},
5013: );
5014: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
5015: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5016: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5017: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5018: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5019: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5020: for (my $k=0; $k<$maxnum+1; $k++) {
5021: my $vpos = $k+1;
5022: my $selstr;
5023: if ($k == $maxnum) {
5024: $selstr = ' selected="selected" ';
5025: }
5026: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5027: }
5028: $datatable .= '</select> '."\n".
1.282 raeburn 5029: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5030: '</label></span></td>'.
1.285 raeburn 5031: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5032: '<span class="LC_nobreak">'.
5033: &mt('Internal name:').
5034: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5035: '</span>'.(' 'x4).
5036: '<span class="LC_nobreak">'.
5037: &mt('Name shown to users:').
5038: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5039: '</span></fieldset>'.
5040: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5041: $usertypes,$types,\%domhelpdesk).
5042: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5043: &Apache::lonuserutils::custom_role_header($context,$crstype,
5044: \@templateroles,$newcust).
5045: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5046: \%levelscurrent,$newcust).
1.334 raeburn 5047: '</fieldset>'.
5048: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5049: '</td></tr>';
1.282 raeburn 5050: $count ++;
5051: $$rowtotal += $count;
5052: }
1.166 raeburn 5053: return $datatable;
1.121 raeburn 5054: }
5055:
1.285 raeburn 5056: sub adhocbutton {
5057: my ($prefix,$num,$field,$visibility) = @_;
5058: my %lt = &Apache::lonlocal::texthash(
5059: show => 'Show details',
5060: hide => 'Hide details',
5061: );
5062: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5063: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5064: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5065: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5066: }
5067:
5068: sub helpsettings_javascript {
5069: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5070: return unless(ref($roles_by_num) eq 'ARRAY');
5071: my %html_js_lt = &Apache::lonlocal::texthash(
5072: show => 'Show details',
5073: hide => 'Hide details',
5074: );
5075: &html_escape(\%html_js_lt);
5076: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5077: return <<"ENDSCRIPT";
5078: <script type="text/javascript">
5079: // <![CDATA[
5080:
5081: function reorderHelpRoles(form,item) {
5082: var changedVal;
5083: $jstext
5084: var newpos = 'helproles_${total}_pos';
5085: var maxh = 1 + $total;
5086: var current = new Array();
5087: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5088: if (item == newpos) {
5089: changedVal = newitemVal;
5090: } else {
5091: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5092: current[newitemVal] = newpos;
5093: }
5094: for (var i=0; i<helproles.length; i++) {
5095: var elementName = 'helproles_'+helproles[i]+'_pos';
5096: if (elementName != item) {
5097: if (form.elements[elementName]) {
5098: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5099: current[currVal] = elementName;
5100: }
5101: }
5102: }
5103: var oldVal;
5104: for (var j=0; j<maxh; j++) {
5105: if (current[j] == undefined) {
5106: oldVal = j;
5107: }
5108: }
5109: if (oldVal < changedVal) {
5110: for (var k=oldVal+1; k<=changedVal ; k++) {
5111: var elementName = current[k];
5112: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5113: }
5114: } else {
5115: for (var k=changedVal; k<oldVal; k++) {
5116: var elementName = current[k];
5117: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5118: }
5119: }
5120: return;
5121: }
5122:
5123: function helpdeskAccess(num) {
5124: var curraccess = null;
5125: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5126: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5127: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5128: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5129: }
5130: }
5131: }
5132: var shown = Array();
5133: var hidden = Array();
5134: if (curraccess == 'none') {
5135: hidden = Array('$hiddenstr');
5136: } else {
5137: if (curraccess == 'status') {
5138: shown = Array('bystatus');
5139: hidden = Array('notinc','notexc');
5140: } else {
5141: if (curraccess == 'exc') {
5142: shown = Array('notexc');
5143: hidden = Array('notinc','bystatus');
5144: }
5145: if (curraccess == 'inc') {
5146: shown = Array('notinc');
5147: hidden = Array('notexc','bystatus');
5148: }
1.293 raeburn 5149: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5150: hidden = Array('notinc','notexc','bystatus');
5151: }
5152: }
5153: }
5154: if (hidden.length > 0) {
5155: for (var i=0; i<hidden.length; i++) {
5156: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5157: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5158: }
5159: }
5160: }
5161: if (shown.length > 0) {
5162: for (var i=0; i<shown.length; i++) {
5163: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5164: if (shown[i] == 'privs') {
5165: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5166: } else {
5167: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5168: }
5169: }
5170: }
5171: }
5172: return;
5173: }
5174:
5175: function toggleHelpdeskItem(num,field) {
5176: if (document.getElementById('helproles_'+num+'_'+field)) {
5177: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5178: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5179: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5180: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5181: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5182: }
5183: } else {
5184: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5185: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5186: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5187: }
5188: }
5189: }
5190: return;
5191: }
5192:
5193: // ]]>
5194: </script>
5195:
5196: ENDSCRIPT
5197: }
5198:
5199: sub helpdeskroles_access {
5200: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5201: $usertypes,$types,$domhelpdesk) = @_;
5202: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5203: my %lt = &Apache::lonlocal::texthash(
5204: 'rou' => 'Role usage',
5205: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5206: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5207: 'dh' => 'All with domain helpdesk role',
5208: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5209: 'none' => 'None',
5210: 'status' => 'Determined based on institutional status',
5211: 'inc' => 'Include all, but exclude specific personnel',
5212: 'exc' => 'Exclude all, but include specific personnel',
5213: );
5214: my %usecheck = (
5215: all => ' checked="checked"',
5216: );
5217: my %displaydiv = (
5218: status => 'none',
5219: inc => 'none',
5220: exc => 'none',
5221: priv => 'block',
5222: );
5223: my $output;
5224: if (ref($current) eq 'HASH') {
5225: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5226: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5227: $usecheck{$current->{access}} = $usecheck{'all'};
5228: delete($usecheck{'all'});
5229: if ($current->{access} =~ /^(status|inc|exc)$/) {
5230: my $access = $1;
5231: $displaydiv{$access} = 'inline';
5232: } elsif ($current->{access} eq 'none') {
5233: $displaydiv{'priv'} = 'none';
5234: }
5235: }
5236: }
5237: }
5238: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5239: '<p>'.$lt{'whi'}.'</p>';
5240: foreach my $access (@{$accesstypes}) {
5241: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5242: ' onclick="helpdeskAccess('."'$num'".');" />'.
5243: $lt{$access}.'</label>';
5244: if ($access eq 'status') {
5245: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5246: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5247: $othertitle,$usertypes,$types).
5248: '</div>';
5249: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5250: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5251: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5252: '</div>';
5253: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5254: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5255: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5256: '</div>';
5257: }
5258: $output .= '</p>';
5259: }
5260: $output .= '</fieldset>';
5261: return $output;
5262: }
5263:
1.121 raeburn 5264: sub radiobutton_prefs {
1.192 raeburn 5265: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5266: $additional,$align,$firstval) = @_;
1.121 raeburn 5267: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5268: (ref($choices) eq 'HASH'));
5269:
1.170 raeburn 5270: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5271:
5272: foreach my $item (@{$toggles}) {
5273: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5274: $checkedon{$item} = ' checked="checked" ';
5275: $checkedoff{$item} = ' ';
1.121 raeburn 5276: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5277: $checkedoff{$item} = ' checked="checked" ';
5278: $checkedon{$item} = ' ';
5279: }
5280: }
5281: if (ref($settings) eq 'HASH') {
1.121 raeburn 5282: foreach my $item (@{$toggles}) {
1.118 jms 5283: if ($settings->{$item} eq '1') {
5284: $checkedon{$item} = ' checked="checked" ';
5285: $checkedoff{$item} = ' ';
5286: } elsif ($settings->{$item} eq '0') {
5287: $checkedoff{$item} = ' checked="checked" ';
5288: $checkedon{$item} = ' ';
5289: }
5290: }
1.121 raeburn 5291: }
1.192 raeburn 5292: if ($onclick) {
5293: $onclick = ' onclick="'.$onclick.'"';
5294: }
1.121 raeburn 5295: foreach my $item (@{$toggles}) {
1.118 jms 5296: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5297: $datatable .=
1.306 raeburn 5298: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5299: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5300: '</span></td>';
5301: if ($align eq 'left') {
5302: $datatable .= '<td class="LC_left_item">';
5303: } else {
5304: $datatable .= '<td class="LC_right_item">';
5305: }
1.385 raeburn 5306: $datatable .= '<span class="LC_nobreak">';
5307: if ($firstval eq 'no') {
5308: $datatable .=
5309: '<label><input type="radio" name="'.
5310: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5311: '</label> <label><input type="radio" name="'.$item.'" '.
5312: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5313: } else {
5314: $datatable .=
5315: '<label><input type="radio" name="'.
5316: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5317: '</label> <label><input type="radio" name="'.$item.'" '.
5318: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5319: }
5320: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5321: $itemcount ++;
1.121 raeburn 5322: }
5323: return ($datatable,$itemcount);
5324: }
5325:
1.267 raeburn 5326: sub print_ltitools {
1.421 raeburn 5327: my ($position,$dom,$settings,$rowtotal) = @_;
5328: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5329: if (ref($settings) eq 'HASH') {
1.421 raeburn 5330: if ($position eq 'top') {
5331: if (exists($settings->{'encrypt'})) {
5332: if (ref($settings->{'encrypt'}) eq 'HASH') {
5333: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5334: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5335: }
5336: }
1.267 raeburn 5337: }
1.421 raeburn 5338: if (exists($settings->{'private'})) {
5339: if (ref($settings->{'private'}) eq 'HASH') {
5340: if (ref($settings->{'private'}) eq 'HASH') {
5341: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5342: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5343: }
5344: }
5345: }
5346: }
1.421 raeburn 5347: } elsif ($position eq 'middle') {
5348: if (exists($settings->{'rules'})) {
5349: if (ref($settings->{'rules'}) eq 'HASH') {
5350: %rules = %{$settings->{'rules'}};
1.273 raeburn 5351: }
5352: }
1.421 raeburn 5353: } else {
5354: foreach my $key ('encrypt','private','rules') {
5355: if (exists($settings->{$key})) {
5356: delete($settings->{$key});
1.267 raeburn 5357: }
5358: }
5359: }
5360: }
1.421 raeburn 5361: my $datatable;
5362: my $itemcount = 1;
5363: if ($position eq 'top') {
5364: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5365: } elsif ($position eq 'middle') {
5366: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5367: $$rowtotal += $itemcount;
5368: } else {
5369: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5370: }
5371: return $datatable;
5372: }
5373:
1.421 raeburn 5374: sub secrets_form {
5375: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5376: my @ids=&Apache::lonnet::current_machine_ids();
5377: my %servers = &Apache::lonnet::get_servers($dom,'library');
5378: my $primary = &Apache::lonnet::domain($dom,'primary');
5379: my ($css_class,$extra,$numshown,$itemcount,$output);
5380: $itemcount = 0;
5381: foreach my $hostid (sort(keys(%servers))) {
5382: my ($showextra,$divsty,$switch);
5383: if ($hostid eq $primary) {
5384: if ($context eq 'ltisec') {
5385: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5386: $showextra = 1;
5387: }
5388: if ($encrypt->{'ltisec_crslinkprot'}) {
5389: $showextra = 1;
5390: }
5391: } else {
5392: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5393: $showextra = 1;
5394: }
5395: }
5396: unless (grep(/^\Q$hostid\E$/,@ids)) {
5397: $switch = 1;
5398: }
5399: if ($showextra) {
5400: $numshown ++;
5401: $divsty = 'display:inline-block';
5402: } else {
5403: $divsty = 'display:none';
5404: }
5405: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5406: '<legend>'.$hostid.'</legend>';
5407: if ($switch) {
5408: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5409: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5410: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5411: if (exists($privkeys->{$hostid})) {
5412: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5413: '<span class="LC_nobreak">'.
5414: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5415: '<span class="LC_nobreak">'.&mt('Change?').
5416: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5417: (' 'x2).
5418: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5419: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5420: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5421: '</span></div>';
5422: } else {
5423: $extra .= '<span class="LC_nobreak">'.
5424: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5425: '</span>'."\n";
5426: }
5427: } elsif (exists($privkeys->{$hostid})) {
5428: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5429: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5430: '<span class="LC_nobreak">'.&mt('Change?').
5431: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5432: (' 'x2).
5433: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5434: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5435: '<span class="LC_nobreak">'.&mt('New Key').':'.
5436: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5437: '<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>'.
5438: '</span></div>';
5439: } else {
5440: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5441: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5442: '<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>';
5443: }
5444: $extra .= '</fieldset>';
5445: }
5446: }
5447: my (%choices,@toggles,%defaultchecked);
5448: if ($context eq 'ltisec') {
5449: %choices = &Apache::lonlocal::texthash (
5450: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5451: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5452: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5453: );
5454: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5455: %defaultchecked = (
5456: 'ltisec_crslinkprot' => 'off',
5457: 'ltisec_domlinkprot' => 'off',
5458: 'ltisec_consumers' => 'off',
5459: );
5460: } else {
5461: %choices = &Apache::lonlocal::texthash (
5462: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5463: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5464: );
5465: @toggles = qw(toolsec_crs toolsec_dom);
5466: %defaultchecked = (
5467: 'toolsec_crs' => 'off',
5468: 'toolsec_dom' => 'off',
5469: );
5470: }
5471: my ($onclick,$itemcount);
5472: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5473: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5474: \%choices,$itemcount,$onclick,'','left','no');
5475:
5476: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5477: my $noprivkeysty = 'display:inline-block';
5478: if ($numshown) {
5479: $noprivkeysty = 'display:none';
5480: }
5481: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5482: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5483: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5484: $extra.
5485: '</td></tr>';
5486: $itemcount ++;
5487: $$rowtotal += $itemcount;
5488: return $output;
5489: }
5490:
1.372 raeburn 5491: sub print_proctoring {
5492: my ($dom,$settings,$rowtotal) = @_;
5493: my $itemcount = 1;
5494: my (%ordered,%providernames,%current,%currentdef);
5495: my $confname = $dom.'-domainconfig';
5496: my $switchserver = &check_switchserver($dom,$confname);
5497: if (ref($settings) eq 'HASH') {
5498: foreach my $item (keys(%{$settings})) {
5499: if (ref($settings->{$item}) eq 'HASH') {
5500: my $num = $settings->{$item}{'order'};
5501: $ordered{$num} = $item;
5502: }
5503: }
5504: } else {
5505: %ordered = (
5506: 1 => 'proctorio',
5507: 2 => 'examity',
5508: );
5509: }
5510: %providernames = &proctoring_providernames();
5511: my $maxnum = scalar(keys(%ordered));
5512: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5513: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5514: if (ref($requref) eq 'HASH') {
5515: %requserfields = %{$requref};
5516: }
5517: if (ref($opturef) eq 'HASH') {
5518: %optuserfields = %{$opturef};
5519: }
5520: if (ref($defref) eq 'HASH') {
5521: %defaults = %{$defref};
5522: }
5523: if (ref($extref) eq 'HASH') {
5524: %extended = %{$extref};
5525: }
5526: if (ref($crsref) eq 'HASH') {
5527: %crsconf = %{$crsref};
5528: }
5529: if (ref($rolesref) eq 'ARRAY') {
5530: @courseroles = @{$rolesref};
5531: }
5532: if (ref($ltiref) eq 'ARRAY') {
5533: @ltiroles = @{$ltiref};
5534: }
5535: my $datatable;
5536: my $css_class;
5537: if (keys(%ordered)) {
5538: my @items = sort { $a <=> $b } keys(%ordered);
5539: for (my $i=0; $i<@items; $i++) {
5540: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5541: my $provider = $ordered{$items[$i]};
5542: my $optionsty = 'none';
5543: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5544: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5545: if (ref($settings) eq 'HASH') {
5546: if (ref($settings->{$provider}) eq 'HASH') {
5547: %current = %{$settings->{$provider}};
5548: if ($current{'available'}) {
5549: $optionsty = 'block';
5550: $available = 1;
5551: }
5552: if ($current{'lifetime'} =~ /^\d+$/) {
5553: $lifetime = $current{'lifetime'};
5554: }
5555: if ($current{'version'} =~ /^\d+\.\d+$/) {
5556: $version = $current{'version'};
5557: }
5558: if ($current{'image'} ne '') {
5559: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5560: }
5561: if (ref($current{'fields'}) eq 'ARRAY') {
5562: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5563: }
5564: $userincdom = $current{'incdom'};
5565: if (ref($current{'roles'}) eq 'HASH') {
5566: %rolemaps = %{$current{'roles'}};
5567: $checkedfields{'roles'} = 1;
5568: }
5569: if (ref($current{'defaults'}) eq 'ARRAY') {
5570: foreach my $val (@{$current{'defaults'}}) {
5571: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5572: $inuse{$val} = 1;
5573: } else {
5574: foreach my $poss (keys(%{$extended{$provider}})) {
5575: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5576: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5577: $inuse{$poss} = $val;
5578: last;
5579: }
5580: }
5581: }
5582: }
5583: }
5584: } elsif (ref($current{'defaults'}) eq 'HASH') {
5585: foreach my $key (keys(%{$current{'defaults'}})) {
5586: my $currval = $current{'defaults'}{$key};
5587: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5588: $inuse{$key} = 1;
5589: } else {
5590: my $match;
5591: foreach my $poss (keys(%{$extended{$provider}})) {
5592: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5593: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5594: $inuse{$poss} = $key;
5595: last;
5596: }
5597: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5598: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5599: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5600: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5601: $currentdef{$inner} = $currval;
5602: $match = 1;
5603: last;
5604: }
5605: } elsif ($inner eq $key) {
5606: $currentdef{$key} = $currval;
5607: $match = 1;
5608: last;
5609: }
5610: }
5611: }
5612: last if ($match);
5613: }
5614: }
5615: }
5616: }
5617: if (ref($current{'crsconf'}) eq 'ARRAY') {
5618: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5619: }
5620: }
5621: }
5622: my %lt = &proctoring_titles($provider);
5623: my %fieldtitles = &proctoring_fieldtitles($provider);
5624: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5625: my %checkedavailable = (
5626: yes => '',
5627: no => ' checked="checked"',
5628: );
5629: if ($available) {
5630: $checkedavailable{'yes'} = $checkedavailable{'no'};
5631: $checkedavailable{'no'} = '';
5632: }
5633: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5634: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5635: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5636: for (my $k=0; $k<$maxnum; $k++) {
5637: my $vpos = $k+1;
5638: my $selstr;
5639: if ($k == $i) {
5640: $selstr = ' selected="selected" ';
5641: }
5642: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5643: }
5644: if ($version eq '') {
5645: if ($provider eq 'proctorio') {
5646: $version = '1.0';
5647: } elsif ($provider eq 'examity') {
5648: $version = '1.1';
5649: }
5650: }
5651: if ($lifetime eq '') {
5652: $lifetime = '300';
5653: }
5654: $datatable .=
5655: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5656: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5657: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5658: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5659: '</td>'.
5660: '<td colspan="2">'.
5661: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5662: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5663: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5664: (' 'x2).
5665: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5666: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5667: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5668: (' 'x2).
5669: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5670: '<br />'.
5671: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5672: '<br />'.
5673: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5674: (' 'x2).
5675: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5676: '<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";
5677: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5678: if ($imgsrc) {
5679: $datatable .= $imgsrc.
5680: '<label><input type="checkbox" name="proctoring_image_del"'.
5681: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5682: '<span class="LC_nobreak"> '.&mt('Replace:');
5683: }
5684: $datatable .= ' ';
5685: if ($switchserver) {
5686: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5687: } else {
5688: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5689: }
5690: unless ($imgsrc) {
5691: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5692: }
5693: $datatable .= '</fieldset>'."\n";
5694: if (ref($requserfields{$provider}) eq 'ARRAY') {
5695: if (@{$requserfields{$provider}} > 0) {
5696: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5697: foreach my $field (@{$requserfields{$provider}}) {
5698: $datatable .= '<span class="LC_nobreak">'.
5699: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5700: $lt{$field}.'</label>';
5701: if ($field eq 'user') {
5702: my $seluserdom = '';
5703: my $unseluserdom = ' selected="selected"';
5704: if ($userincdom) {
5705: $seluserdom = $unseluserdom;
5706: $unseluserdom = '';
5707: }
5708: $datatable .= ': '.
5709: '<select name="proctoring_userincdom_'.$provider.'">'.
5710: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5711: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5712: '</select> ';
5713: } else {
5714: $datatable .= ' ';
5715: if ($field eq 'roles') {
5716: $showroles = 1;
5717: }
5718: }
5719: $datatable .= '</span> ';
5720: }
5721: }
5722: $datatable .= '</fieldset>'."\n";
5723: }
5724: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5725: if (@{$optuserfields{$provider}} > 0) {
5726: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5727: foreach my $field (@{$optuserfields{$provider}}) {
5728: my $checked;
5729: if ($checkedfields{$field}) {
5730: $checked = ' checked="checked"';
5731: }
5732: $datatable .= '<span class="LC_nobreak">'.
5733: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5734: }
5735: $datatable .= '</fieldset>'."\n";
5736: }
5737: }
5738: if (ref($defaults{$provider}) eq 'ARRAY') {
5739: if (@{$defaults{$provider}}) {
5740: my (%options,@selectboxes);
5741: if (ref($extended{$provider}) eq 'HASH') {
5742: %options = %{$extended{$provider}};
5743: }
5744: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5745: my ($rem,$numinrow,$dropdowns);
5746: if ($provider eq 'proctorio') {
5747: $datatable .= '<table>';
5748: $numinrow = 4;
5749: }
5750: my $i = 0;
5751: foreach my $field (@{$defaults{$provider}}) {
5752: my $checked;
5753: if ($inuse{$field}) {
5754: $checked = ' checked="checked"';
5755: }
5756: if ($provider eq 'examity') {
5757: if ($field eq 'display') {
5758: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5759: foreach my $option ('iframe','tab','window') {
5760: my $checkdisp;
5761: if ($currentdef{'target'} eq $option) {
5762: $checkdisp = ' checked="checked"';
5763: }
5764: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5765: $fieldtitles{$option}.'</label>'.(' 'x2);
5766: }
5767: $datatable .= (' 'x4);
5768: foreach my $dimen ('width','height') {
5769: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5770: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5771: 'value="'.$currentdef{$dimen}.'" /></label>'.
5772: (' 'x2);
5773: }
5774: $datatable .= '</span><br />'.
5775: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5776: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5777: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5778: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5779: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5780: $currentdef{'explanation'}.
5781: '</textarea></div><div style=""></div><br />';
5782: }
5783: } else {
5784: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5785: my ($output,$selnone);
5786: unless ($checked) {
5787: $selnone = ' selected="selected"';
5788: }
5789: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5790: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5791: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5792: foreach my $option (@{$options{$field}}) {
5793: my $sel;
5794: if ($inuse{$field} eq $option) {
5795: $sel = ' selected="selected"';
5796: }
5797: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5798: }
5799: $output .= '</select></span>';
5800: push(@selectboxes,$output);
5801: } else {
5802: $rem = $i%($numinrow);
5803: if ($rem == 0) {
5804: if ($i > 0) {
5805: $datatable .= '</tr>';
5806: }
5807: $datatable .= '<tr>';
5808: }
5809: $datatable .= '<td class="LC_left_item">'.
5810: '<span class="LC_nobreak">'.
5811: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5812: $fieldtitles{$field}.'</label></span></td>';
5813: $i++;
5814: }
5815: }
5816: }
5817: if ($provider eq 'proctorio') {
5818: if ($numinrow) {
5819: $rem = $i%$numinrow;
5820: }
5821: my $colsleft = $numinrow - $rem;
5822: if ($colsleft > 1) {
5823: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5824: } else {
5825: $datatable .= '<td class="LC_left_item">';
5826: }
5827: $datatable .= ' '.
5828: '</td></tr></table>';
5829: if (@selectboxes) {
5830: $datatable .= '<hr /><table>';
5831: $numinrow = 2;
5832: for (my $i=0; $i<@selectboxes; $i++) {
5833: $rem = $i%($numinrow);
5834: if ($rem == 0) {
5835: if ($i > 0) {
5836: $datatable .= '</tr>';
5837: }
5838: $datatable .= '<tr>';
5839: }
5840: $datatable .= '<td class="LC_left_item">'.
5841: $selectboxes[$i].'</td>';
5842: }
5843: if ($numinrow) {
5844: $rem = $i%$numinrow;
5845: }
5846: $colsleft = $numinrow - $rem;
5847: if ($colsleft > 1) {
5848: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5849: } else {
5850: $datatable .= '<td class="LC_left_item">';
5851: }
5852: $datatable .= ' '.
5853: '</td></tr></table>';
5854: }
5855: }
5856: $datatable .= '</fieldset>';
5857: }
5858: if (ref($crsconf{$provider}) eq 'ARRAY') {
5859: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5860: '<legend>'.&mt('Configurable in course').'</legend>';
5861: my ($rem,$numinrow);
5862: if ($provider eq 'proctorio') {
5863: $datatable .= '<table>';
5864: $numinrow = 4;
5865: }
5866: my $i = 0;
5867: foreach my $item (@{$crsconf{$provider}}) {
5868: my $name;
5869: if ($provider eq 'examity') {
5870: $name = $lt{'crs'.$item};
5871: } elsif ($provider eq 'proctorio') {
5872: $name = $fieldtitles{$item};
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: }
5882: my $checked;
5883: if ($crsconfig{$item}) {
5884: $checked = ' checked="checked"';
5885: }
5886: $datatable .= '<span class="LC_nobreak"><label>'.
5887: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5888: $name.'</label></span>';
5889: if ($provider eq 'examity') {
5890: $datatable .= ' ';
5891: }
5892: $datatable .= "\n";
5893: $i++;
5894: }
5895: if ($provider eq 'proctorio') {
5896: if ($numinrow) {
5897: $rem = $i%$numinrow;
5898: }
5899: my $colsleft = $numinrow - $rem;
5900: if ($colsleft > 1) {
5901: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5902: } else {
5903: $datatable .= '<td class="LC_left_item">';
5904: }
5905: $datatable .= ' '.
5906: '</td></tr></table>';
5907: }
5908: $datatable .= '</fieldset>';
5909: }
5910: if ($showroles) {
5911: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5912: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5913: foreach my $role (@courseroles) {
5914: my ($selected,$selectnone);
5915: if (!$rolemaps{$role}) {
5916: $selectnone = ' selected="selected"';
5917: }
5918: $datatable .= '<td style="text-align: center">'.
5919: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5920: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5921: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5922: foreach my $ltirole (@ltiroles) {
5923: unless ($selectnone) {
5924: if ($rolemaps{$role} eq $ltirole) {
5925: $selected = ' selected="selected"';
5926: } else {
5927: $selected = '';
5928: }
5929: }
5930: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5931: }
5932: $datatable .= '</select></td>';
5933: }
5934: $datatable .= '</tr></table></fieldset>'.
5935: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5936: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5937: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5938: '<tr><td></td><td>lms</td>'.
5939: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5940: ' value="Loncapa" disabled="disabled"/></td></tr>';
5941: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5942: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5943: my %custom = %{$settings->{$provider}->{'custom'}};
5944: if (keys(%custom) > 0) {
5945: foreach my $key (sort(keys(%custom))) {
5946: next if ($key eq 'lms');
5947: $datatable .= '<tr><td><span class="LC_nobreak">'.
5948: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5949: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5950: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
5951: ' value="'.$custom{$key}.'" /></td></tr>';
5952: }
5953: }
5954: }
5955: $datatable .= '<tr><td><span class="LC_nobreak">'.
5956: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
5957: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
5958: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
5959: '</table></fieldset></td></tr>'."\n";
5960: }
5961: $datatable .= '</td></tr>';
5962: }
5963: $itemcount ++;
5964: }
5965: }
5966: return $datatable;
5967: }
5968:
5969: sub proctoring_data {
5970: my $requserfields = {
5971: proctorio => ['user'],
5972: examity => ['roles','user'],
5973: };
5974: my $optuserfields = {
5975: proctorio => ['fullname'],
5976: examity => ['fullname','firstname','lastname','email'],
5977: };
5978: my $defaults = {
5979: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5980: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5981: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5982: 'closetabs','onescreen','print','downloads','cache','rightclick',
5983: 'reentry','calculator','whiteboard'],
5984: examity => ['display'],
5985: };
5986: my $extended = {
5987: proctorio => {
5988: verifyid => ['verifyidauto','verifyidlive'],
5989: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
5990: tabslinks => ['notabs','linksonly'],
5991: reentry => ['noreentry','agentreentry'],
5992: calculator => ['calculatorbasic','calculatorsci'],
5993: },
5994: examity => {
5995: display => {
5996: target => ['iframe','tab','window'],
5997: width => '',
5998: height => '',
5999: linktext => '',
6000: explanation => '',
6001: },
6002: },
6003: };
6004: my $crsconf = {
6005: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6006: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6007: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6008: 'closetabs','onescreen','print','downloads','cache','rightclick',
6009: 'reentry','calculator','whiteboard'],
6010: examity => ['label','title','target','linktext','explanation','append'],
6011: };
6012: my $courseroles = ['cc','in','ta','ep','st'];
6013: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6014: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6015: }
6016:
6017: sub proctoring_titles {
6018: my ($item) = @_;
6019: my (%common_lt,%custom_lt);
6020: %common_lt = &Apache::lonlocal::texthash (
6021: 'avai' => 'Available?',
6022: 'base' => 'Basic Settings',
6023: 'requ' => 'User data required to be sent on launch',
6024: 'optu' => 'User data optionally sent on launch',
6025: 'udsl' => 'User data sent on launch',
6026: 'defa' => 'Defaults for items configurable in course',
6027: 'sigmethod' => 'Signature Method',
6028: 'key' => 'Key',
6029: 'lifetime' => 'Nonce lifetime (s)',
6030: 'secret' => 'Secret',
6031: 'icon' => 'Icon',
6032: 'fullname' => 'Full Name',
6033: 'visible' => 'Visible input',
6034: 'username' => 'username',
6035: 'user' => 'User',
6036: );
6037: if ($item eq 'proctorio') {
6038: %custom_lt = &Apache::lonlocal::texthash (
6039: 'version' => 'OAuth version',
6040: 'url' => 'API URL',
6041: 'uname:dom' => 'username-domain',
6042: );
6043: } elsif ($item eq 'examity') {
6044: %custom_lt = &Apache::lonlocal::texthash (
6045: 'version' => 'LTI Version',
6046: 'url' => 'URL',
6047: 'uname:dom' => 'username:domain',
6048: 'msgtype' => 'Message Type',
6049: 'firstname' => 'First Name',
6050: 'lastname' => 'Last Name',
6051: 'email' => 'E-mail',
6052: 'roles' => 'Role',
6053: 'crstarget' => 'Display target',
6054: 'crslabel' => 'Course label',
6055: 'crstitle' => 'Course title',
6056: 'crslinktext' => 'Link Text',
6057: 'crsexplanation' => 'Explanation',
6058: 'crsappend' => 'Provider URL',
6059: );
6060: }
6061: my %lt = (%common_lt,%custom_lt);
6062: return %lt;
6063: }
6064:
6065: sub proctoring_fieldtitles {
6066: my ($item) = @_;
6067: if ($item eq 'proctorio') {
6068: return &Apache::lonlocal::texthash (
6069: 'recordvideo' => 'Record video',
6070: 'recordaudio' => 'Record audio',
6071: 'recordscreen' => 'Record screen',
6072: 'recordwebtraffic' => 'Record web traffic',
6073: 'recordroomstart' => 'Record room scan',
6074: 'verifyvideo' => 'Verify webcam',
6075: 'verifyaudio' => 'Verify microphone',
6076: 'verifydesktop' => 'Verify desktop recording',
6077: 'verifyid' => 'Photo ID verification',
6078: 'verifysignature' => 'Require signature',
6079: 'fullscreen' => 'Fullscreen',
6080: 'clipboard' => 'Disable copy/paste',
6081: 'tabslinks' => 'New tabs/windows',
6082: 'closetabs' => 'Close other tabs',
6083: 'onescreen' => 'Limit to single screen',
6084: 'print' => 'Disable Printing',
6085: 'downloads' => 'Disable Downloads',
6086: 'cache' => 'Empty cache after exam',
6087: 'rightclick' => 'Disable right click',
6088: 'reentry' => 'Re-entry to exam',
6089: 'calculator' => 'Onscreen calculator',
6090: 'whiteboard' => 'Onscreen whiteboard',
6091: 'verifyidauto' => 'Automated verification',
6092: 'verifyidlive' => 'Live agent verification',
6093: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6094: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6095: 'fullscreensever' => 'Forced, navigation away ends exam',
6096: 'notabs' => 'Disaallowed',
6097: 'linksonly' => 'Allowed from links in exam',
6098: 'noreentry' => 'Disallowed',
6099: 'agentreentry' => 'Agent required for re-entry',
6100: 'calculatorbasic' => 'Basic',
6101: 'calculatorsci' => 'Scientific',
6102: );
6103: } elsif ($item eq 'examity') {
6104: return &Apache::lonlocal::texthash (
6105: 'target' => 'Display target',
6106: 'window' => 'Window',
6107: 'tab' => 'Tab',
6108: 'iframe' => 'iFrame',
6109: 'height' => 'Height (pixels)',
6110: 'width' => 'Width (pixels)',
6111: 'linktext' => 'Default Link Text',
6112: 'explanation' => 'Default Explanation',
6113: 'append' => 'Provider URL',
6114: );
6115: }
6116: }
6117:
6118: sub proctoring_providernames {
6119: return (
6120: proctorio => 'Proctorio',
6121: examity => 'Examity',
6122: );
6123: }
6124:
1.320 raeburn 6125: sub print_lti {
1.405 raeburn 6126: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6127: my $itemcount = 1;
1.405 raeburn 6128: my ($datatable,$css_class);
1.434 raeburn 6129: my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
1.320 raeburn 6130: if (ref($settings) eq 'HASH') {
1.405 raeburn 6131: if ($position eq 'top') {
6132: if (exists($settings->{'encrypt'})) {
6133: if (ref($settings->{'encrypt'}) eq 'HASH') {
6134: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6135: if ($key eq 'consumers') {
6136: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6137: } else {
6138: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6139: }
6140: }
6141: }
6142: }
6143: if (exists($settings->{'private'})) {
6144: if (ref($settings->{'private'}) eq 'HASH') {
6145: if (ref($settings->{'private'}) eq 'HASH') {
6146: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6147: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6148: }
6149: }
6150: }
6151: }
1.434 raeburn 6152: } elsif ($position eq 'upper') {
1.405 raeburn 6153: if (exists($settings->{'rules'})) {
6154: if (ref($settings->{'rules'}) eq 'HASH') {
6155: %rules = %{$settings->{'rules'}};
6156: }
6157: }
1.434 raeburn 6158: } elsif ($position eq 'middle') {
6159: if (exists($settings->{'suggested'})) {
6160: if (ref($settings->{'suggested'}) eq 'HASH') {
6161: %suggestions = %{$settings->{'suggested'}};
6162: }
6163: }
1.405 raeburn 6164: } elsif ($position eq 'lower') {
6165: if (exists($settings->{'linkprot'})) {
6166: if (ref($settings->{'linkprot'}) eq 'HASH') {
6167: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6168: if ($linkprot{'lock'}) {
6169: delete($linkprot{'lock'});
6170: }
1.405 raeburn 6171: }
6172: }
6173: } else {
1.434 raeburn 6174: foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
1.405 raeburn 6175: if (exists($settings->{$key})) {
6176: delete($settings->{$key});
1.390 raeburn 6177: }
1.320 raeburn 6178: }
6179: }
6180: }
1.405 raeburn 6181: if ($position eq 'top') {
1.421 raeburn 6182: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
1.434 raeburn 6183: } elsif ($position eq 'upper') {
6184: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
6185: $$rowtotal += $itemcount;
1.421 raeburn 6186: } elsif ($position eq 'middle') {
1.434 raeburn 6187: $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
1.421 raeburn 6188: $$rowtotal += $itemcount;
6189: } elsif ($position eq 'lower') {
1.434 raeburn 6190: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
1.421 raeburn 6191: } else {
1.424 raeburn 6192: my ($switchserver,$switchmessage);
6193: $switchserver = &check_switchserver($dom);
6194: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.421 raeburn 6195: my $maxnum = 0;
6196: my %ordered;
6197: if (ref($settings) eq 'HASH') {
6198: foreach my $item (keys(%{$settings})) {
6199: if (ref($settings->{$item}) eq 'HASH') {
6200: my $num = $settings->{$item}{'order'};
6201: if ($num eq '') {
6202: $num = scalar(keys(%{$settings}));
6203: }
6204: $ordered{$num} = $item;
1.405 raeburn 6205: }
1.352 raeburn 6206: }
1.405 raeburn 6207: }
6208: $maxnum = scalar(keys(%ordered));
6209: my %lt = <i_names();
6210: if (keys(%ordered)) {
6211: my @items = sort { $a <=> $b } keys(%ordered);
6212: for (my $i=0; $i<@items; $i++) {
6213: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6214: my $item = $ordered{$items[$i]};
1.424 raeburn 6215: my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
1.405 raeburn 6216: if (ref($settings->{$item}) eq 'HASH') {
6217: $key = $settings->{$item}->{'key'};
1.424 raeburn 6218: $usable = $settings->{$item}->{'usable'};
1.405 raeburn 6219: $lifetime = $settings->{$item}->{'lifetime'};
6220: $consumer = $settings->{$item}->{'consumer'};
6221: $requser = $settings->{$item}->{'requser'};
6222: $crsinc = $settings->{$item}->{'crsinc'};
6223: $current = $settings->{$item};
6224: }
6225: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6226: my %checkedrequser = (
6227: yes => ' checked="checked"',
6228: no => '',
6229: );
6230: if (!$requser) {
6231: $checkedrequser{'no'} = $checkedrequser{'yes'};
6232: $checkedrequser{'yes'} = '';
6233: }
6234: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6235: my %checkedcrsinc = (
1.391 raeburn 6236: yes => ' checked="checked"',
6237: no => '',
1.405 raeburn 6238: );
6239: if (!$crsinc) {
6240: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6241: $checkedcrsinc{'yes'} = '';
6242: }
6243: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6244: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6245: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6246: for (my $k=0; $k<=$maxnum; $k++) {
6247: my $vpos = $k+1;
6248: my $selstr;
6249: if ($k == $i) {
6250: $selstr = ' selected="selected" ';
6251: }
6252: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6253: }
1.405 raeburn 6254: $datatable .= '</select>'.(' 'x2).
6255: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6256: &mt('Delete?').'</label></span></td>'.
6257: '<td colspan="2">'.
6258: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6259: '<span class="LC_nobreak">'.$lt{'consumer'}.
6260: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6261: (' 'x2).
6262: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6263: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6264: (' 'x2).
6265: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.424 raeburn 6266: 'value="'.$lifetime.'" size="3" /></span><br /><br />';
6267: if ($key ne '') {
6268: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6269: if ($switchserver) {
6270: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6271: } else {
6272: $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
6273: }
6274: $datatable .= '</span> '.(' 'x2);
6275: } elsif (!$switchserver) {
6276: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6277: '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
6278: '</span> '.(' 'x2);
6279: }
6280: if ($switchserver) {
6281: if ($usable ne '') {
6282: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6283: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6284: '<span class="LC_nobreak">'.&mt('Change secret?').
6285: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6286: (' 'x2).
6287: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
6288: '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6289: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6290: '</div>';
6291: } elsif ($key eq '') {
6292: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6293: } else {
6294: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6295: }
6296: } else {
6297: if ($usable ne '') {
6298: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6299: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6300: '<span class="LC_nobreak">'.&mt('Change?').
6301: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6302: (' 'x2).
6303: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
6304: '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6305: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6306: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6307: '<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>';
6308: } else {
6309: $datatable .=
6310: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6311: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6312: '<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>';
6313: }
6314: }
1.425 raeburn 6315: $datatable .= '<br /><br />'.
1.405 raeburn 6316: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6317: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6318: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6319: '<br /><br />'.
6320: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6321: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6322: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6323: (' 'x4).
6324: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6325: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6326: $itemcount ++;
1.320 raeburn 6327: }
6328: }
1.405 raeburn 6329: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6330: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6331: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6332: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6333: '<select name="lti_pos_add"'.$chgstr.'>';
6334: for (my $k=0; $k<$maxnum+1; $k++) {
6335: my $vpos = $k+1;
6336: my $selstr;
6337: if ($k == $maxnum) {
6338: $selstr = ' selected="selected" ';
6339: }
6340: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6341: }
1.405 raeburn 6342: $datatable .= '</select> '."\n".
6343: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6344: '<td colspan="2">'.
6345: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6346: '<span class="LC_nobreak">'.$lt{'consumer'}.
6347: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6348: (' 'x2).
6349: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6350: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6351: (' 'x2).
1.424 raeburn 6352: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
6353: if ($switchserver) {
6354: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6355: } else {
6356: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
6357: (' 'x2).
6358: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
6359: '<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";
6360: }
6361: $datatable .= '<br /><br />'.
1.405 raeburn 6362: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6363: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6364: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6365: '<br /><br />'.
6366: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6367: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6368: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6369: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6370: '</td>'."\n".
6371: '</tr>'."\n";
6372: $itemcount ++;
1.320 raeburn 6373: }
1.405 raeburn 6374: $$rowtotal += $itemcount;
6375: return $datatable;
1.320 raeburn 6376: }
6377:
6378: sub lti_names {
6379: my %lt = &Apache::lonlocal::texthash(
6380: 'version' => 'LTI Version',
6381: 'url' => 'URL',
6382: 'key' => 'Key',
1.322 raeburn 6383: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6384: 'consumer' => 'Consumer',
1.320 raeburn 6385: 'secret' => 'Secret',
1.345 raeburn 6386: 'requser' => "User's identity sent",
1.391 raeburn 6387: 'crsinc' => "Course's identity sent",
1.320 raeburn 6388: 'email' => 'Email address',
6389: 'sourcedid' => 'User ID',
6390: 'other' => 'Other',
6391: 'passback' => 'Can return grades to Consumer:',
6392: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6393: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6394: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6395: );
6396: return %lt;
6397: }
6398:
6399: sub lti_options {
1.325 raeburn 6400: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6401: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6402: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6403: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6404: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6405: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6406: $checked{'mapcrstype'} = {};
6407: $checked{'makeuser'} = {};
6408: $checked{'selfenroll'} = {};
6409: $checked{'crssec'} = {};
6410: $checked{'crssecsrc'} = {};
1.325 raeburn 6411: $checked{'lcauth'} = {};
1.326 raeburn 6412: $checked{'menuitem'} = {};
1.325 raeburn 6413: if ($num eq 'add') {
6414: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6415: }
1.320 raeburn 6416: my $userfieldsty = 'none';
6417: my $crsfieldsty = 'none';
6418: my $crssecfieldsty = 'none';
6419: my $secsrcfieldsty = 'none';
1.363 raeburn 6420: my $callbacksty = 'none';
1.337 raeburn 6421: my $passbacksty = 'none';
1.345 raeburn 6422: my $optionsty = 'block';
1.391 raeburn 6423: my $crssty = 'block';
1.325 raeburn 6424: my $lcauthparm;
6425: my $lcauthparmstyle = 'display:none';
6426: my $lcauthparmtext;
1.326 raeburn 6427: my $menusty;
1.325 raeburn 6428: my $numinrow = 4;
1.326 raeburn 6429: my %menutitles = <imenu_titles();
1.320 raeburn 6430:
6431: if (ref($current) eq 'HASH') {
1.345 raeburn 6432: if (!$current->{'requser'}) {
6433: $optionsty = 'none';
1.391 raeburn 6434: $crssty = 'none';
6435: } elsif (!$current->{'crsinc'}) {
6436: $crssty = 'none';
1.345 raeburn 6437: }
1.320 raeburn 6438: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6439: $checked{'mapuser'}{'sourcedid'} = '';
6440: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
1.425 raeburn 6441: $checked{'mapuser'}{'email'} = ' checked="checked"';
1.320 raeburn 6442: } else {
6443: $checked{'mapuser'}{'other'} = ' checked="checked"';
6444: $userfield = $current->{'mapuser'};
6445: $userfieldsty = 'inline-block';
6446: }
6447: }
6448: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6449: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6450: if ($current->{'mapcrs'} eq 'context_id') {
1.425 raeburn 6451: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
1.320 raeburn 6452: } else {
6453: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6454: $cidfield = $current->{'mapcrs'};
6455: $crsfieldsty = 'inline-block';
6456: }
6457: }
6458: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6459: foreach my $type (@{$current->{'mapcrstype'}}) {
6460: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6461: }
6462: }
1.392 raeburn 6463: if (!$current->{'storecrs'}) {
6464: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6465: $checked{'storecrs'}{'Y'} = '';
6466: }
1.345 raeburn 6467: if ($current->{'makecrs'}) {
1.320 raeburn 6468: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6469: }
1.320 raeburn 6470: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6471: foreach my $role (@{$current->{'makeuser'}}) {
6472: $checked{'makeuser'}{$role} = ' checked="checked"';
6473: }
6474: }
1.325 raeburn 6475: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6476: $checked{'lcauth'}{$1} = ' checked="checked"';
6477: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6478: $lcauthparm = $current->{'lcauthparm'};
1.425 raeburn 6479: $lcauthparmstyle = 'display:table-row';
1.325 raeburn 6480: if ($current->{'lcauth'} eq 'localauth') {
6481: $lcauthparmtext = &mt('Local auth argument');
6482: } else {
6483: $lcauthparmtext = &mt('Kerberos domain');
6484: }
6485: }
6486: }
1.320 raeburn 6487: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6488: foreach my $role (@{$current->{'selfenroll'}}) {
6489: $checked{'selfenroll'}{$role} = ' checked="checked"';
6490: }
6491: }
6492: if (ref($current->{'maproles'}) eq 'HASH') {
6493: %rolemaps = %{$current->{'maproles'}};
6494: }
6495: if ($current->{'section'} ne '') {
1.425 raeburn 6496: $checked{'crssec'}{'Y'} = ' checked="checked"';
1.320 raeburn 6497: $crssecfieldsty = 'inline-block';
6498: if ($current->{'section'} eq 'course_section_sourcedid') {
6499: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6500: } else {
6501: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6502: $crssecsrc = $current->{'section'};
6503: $secsrcfieldsty = 'inline-block';
6504: }
6505: } else {
6506: $checked{'crssec'}{'N'} = ' checked="checked"';
6507: }
1.363 raeburn 6508: if ($current->{'callback'} ne '') {
6509: $callback = $current->{'callback'};
6510: $checked{'callback'}{'Y'} = ' checked="checked"';
6511: $callbacksty = 'inline-block';
6512: } else {
6513: $checked{'callback'}{'N'} = ' checked="checked"';
6514: }
1.326 raeburn 6515: if ($current->{'topmenu'}) {
6516: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6517: } else {
6518: $checked{'topmenu'}{'N'} = ' checked="checked"';
6519: }
6520: if ($current->{'inlinemenu'}) {
6521: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6522: } else {
6523: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6524: }
6525: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6526: $menusty = 'inline-block';
6527: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6528: foreach my $item (@{$current->{'lcmenu'}}) {
6529: if (exists($menutitles{$item})) {
6530: $checked{'menuitem'}{$item} = ' checked="checked"';
6531: }
6532: }
6533: }
6534: } else {
6535: $menusty = 'none';
6536: }
1.320 raeburn 6537: } else {
6538: $checked{'makecrs'}{'N'} = ' checked="checked"';
6539: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6540: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6541: $checked{'topmenu'}{'N'} = ' checked="checked"';
1.425 raeburn 6542: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
1.326 raeburn 6543: $checked{'menuitem'}{'grades'} = ' checked="checked"';
1.425 raeburn 6544: $menusty = 'inline-block';
1.320 raeburn 6545: }
1.325 raeburn 6546: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6547: my %coursetypetitles = &Apache::lonlocal::texthash (
6548: official => 'Official',
6549: unofficial => 'Unofficial',
6550: community => 'Community',
6551: textbook => 'Textbook',
6552: placement => 'Placement Test',
1.325 raeburn 6553: lti => 'LTI Provider',
1.320 raeburn 6554: );
1.325 raeburn 6555: my @authtypes = ('internal','krb4','krb5','localauth');
6556: my %shortauth = (
6557: internal => 'int',
6558: krb4 => 'krb4',
6559: krb5 => 'krb5',
6560: localauth => 'loc'
6561: );
6562: my %authnames = &authtype_names();
1.320 raeburn 6563: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6564: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6565: my @courseroles = ('cc','in','ta','ep','st');
6566: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6567: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6568: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6569: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6570: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6571: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6572: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6573: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6574: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6575: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6576: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6577: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6578: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6579: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6580: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6581: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6582: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6583: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6584: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6585: foreach my $option ('sourcedid','email','other') {
6586: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6587: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6588: ($option eq 'other' ? '' : (' 'x2) );
6589: }
6590: $output .= '</span></div>'.
6591: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6592: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6593: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6594: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6595: foreach my $ltirole (@ltiroles) {
6596: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
1.425 raeburn 6597: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
1.320 raeburn 6598: }
6599: $output .= '</fieldset>'.
1.391 raeburn 6600: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6601: '<table>'.
6602: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6603: '</table>'.
6604: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6605: '<td class="LC_left_item">';
6606: foreach my $auth ('lti',@authtypes) {
6607: my $authtext;
6608: if ($auth eq 'lti') {
6609: $authtext = &mt('None');
6610: } else {
6611: $authtext = $authnames{$shortauth{$auth}};
6612: }
6613: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6614: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6615: $authtext.'</label></span> ';
6616: }
6617: $output .= '</td></tr>'.
6618: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6619: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6620: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6621: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6622: '</table></fieldset>'.
1.391 raeburn 6623: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6624: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6625: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6626: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6627: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6628: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6629: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6630: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6631: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6632: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6633: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6634: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6635: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6636: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6637: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6638: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6639: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6640: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6641: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6642: (' 'x2);
6643: }
6644: $output .= '</span></div></fieldset>'.
6645: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6646: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6647: &mt('Unique course identifier').': ';
6648: foreach my $option ('course_offering_sourcedid','context_id','other') {
6649: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6650: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6651: ($option eq 'other' ? '' : (' 'x2) );
6652: }
1.334 raeburn 6653: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6654: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6655: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6656: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6657: foreach my $type (@coursetypes) {
6658: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6659: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6660: (' 'x2);
6661: }
1.392 raeburn 6662: $output .= '</span><br /><br />'.
6663: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6664: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6665: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6666: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6667: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6668: '</fieldset>'.
1.391 raeburn 6669: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6670: foreach my $ltirole (@lticourseroles) {
6671: my ($selected,$selectnone);
6672: if ($rolemaps{$ltirole} eq '') {
6673: $selectnone = ' selected="selected"';
6674: }
6675: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6676: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6677: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6678: foreach my $role (@courseroles) {
6679: unless ($selectnone) {
6680: if ($rolemaps{$ltirole} eq $role) {
6681: $selected = ' selected="selected"';
6682: } else {
6683: $selected = '';
6684: }
6685: }
6686: $output .= '<option value="'.$role.'"'.$selected.'>'.
6687: &Apache::lonnet::plaintext($role,'Course').
6688: '</option>';
6689: }
6690: $output .= '</select></td>';
6691: }
6692: $output .= '</tr></table></fieldset>'.
6693: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6694: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6695: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6696: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6697: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6698: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6699: '</fieldset>'.
1.391 raeburn 6700: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6701: foreach my $lticrsrole (@lticourseroles) {
6702: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6703: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6704: }
6705: $output .= '</fieldset>'.
1.391 raeburn 6706: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6707: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6708: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6709: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6710: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6711: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6712: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6713: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6714: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6715: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6716: &mt('Standard field').'</label>'.(' 'x2).
6717: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6718: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6719: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6720: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6721: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6722: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6723: foreach my $extra ('roster','passback') {
1.320 raeburn 6724: my $checkedon = '';
6725: my $checkedoff = ' checked="checked"';
1.337 raeburn 6726: if ($extra eq 'passback') {
6727: $pb1p1chk = ' checked="checked"';
6728: $pb1p0chk = '';
1.425 raeburn 6729: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
1.337 raeburn 6730: } else {
1.425 raeburn 6731: $onclickpb = '';
1.337 raeburn 6732: }
1.320 raeburn 6733: if (ref($current) eq 'HASH') {
6734: if (($current->{$extra})) {
6735: $checkedon = $checkedoff;
6736: $checkedoff = '';
1.337 raeburn 6737: if ($extra eq 'passback') {
6738: $passbacksty = 'inline-block';
6739: }
6740: if ($current->{'passbackformat'} eq '1.0') {
6741: $pb1p0chk = ' checked="checked"';
6742: $pb1p1chk = '';
6743: }
1.320 raeburn 6744: }
6745: }
6746: $output .= $lt{$extra}.' '.
1.337 raeburn 6747: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6748: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6749: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6750: &mt('Yes').'</label><br />';
6751: }
1.337 raeburn 6752: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6753: '<span class="LC_nobreak">'.&mt('Grade format').
6754: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6755: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6756: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6757: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6758: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6759: $output .= '</span></div></fieldset>';
1.320 raeburn 6760: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6761: #
6762: # $output .= '</fieldset>'.
6763: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6764: return $output;
6765: }
6766:
1.326 raeburn 6767: sub ltimenu_titles {
6768: return &Apache::lonlocal::texthash(
6769: fullname => 'Full name',
6770: coursetitle => 'Course title',
6771: role => 'Role',
6772: logout => 'Logout',
6773: grades => 'Grades',
6774: );
6775: }
6776:
1.434 raeburn 6777: sub linkprot_suggestions {
6778: my ($suggested,$itemcount) = @_;
6779: my $count = 0;
6780: my $next = 1;
6781: my %lt = &Apache::lonlocal::texthash(
6782: 'name' => 'Suggested Launcher',
6783: 'info' => 'Recommendations',
6784: );
6785: my ($datatable,$css_class,$dest);
6786: if (ref($suggested) eq 'HASH') {
6787: my @current = sort { $a <=> $b } keys(%{$suggested});
6788: $next += $current[-1];
6789: for (my $i=0; $i<@current; $i++) {
6790: my $num = $current[$i];
6791: my %values;
6792: if (ref($suggested->{$num}) eq 'HASH') {
6793: %values = %{$suggested->{$num}};
6794: } else {
6795: next;
6796: }
6797: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6798: $datatable .=
6799: '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6800: '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
6801: &mt('Delete?').'</label></span></td><td>'."\n".
6802: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6803: '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
6804: '</fieldset></div>'.
6805: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6806: '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
6807: '</fieldset></div>'.
6808: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6809: '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
6810: $$itemcount ++;
6811: }
6812: }
6813: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6814: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6815: '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
6816: '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6817: '<td>'."\n".
6818: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6819: '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
6820: '</fieldset></div>'.
6821: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6822: '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
6823: '</fieldset></div>'.
6824: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6825: '</td></tr>'."\n";
6826: return $datatable;
6827: }
6828:
1.121 raeburn 6829: sub print_coursedefaults {
1.139 raeburn 6830: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6831: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6832: my $itemcount = 1;
1.192 raeburn 6833: my %choices = &Apache::lonlocal::texthash (
6834: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6835: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.432 raeburn 6836: coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.192 raeburn 6837: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6838: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6839: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6840: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6841: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6842: texengine => 'Default method to display mathematics',
1.257 raeburn 6843: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6844: canclone => "People who may clone a course (besides course's owner and coordinators)",
6845: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6846: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422 raeburn 6847: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6848: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
1.432 raeburn 6849: crsauthor => 'Standard LON-CAPA problems can be created within a course/community (by type)',
1.438 raeburn 6850: crseditors => 'Available editors for web pages and/or problems created in a course/community',
1.192 raeburn 6851: );
1.198 raeburn 6852: my %staticdefaults = (
6853: anonsurvey_threshold => 10,
6854: uploadquota => 500,
1.428 raeburn 6855: coursequota => 20,
1.257 raeburn 6856: postsubmit => 60,
1.276 raeburn 6857: mysqltables => 172800,
1.422 raeburn 6858: domexttool => 1,
6859: exttool => 0,
1.432 raeburn 6860: crsauthor => 1,
1.438 raeburn 6861: crseditors => ['edit','xml'],
1.198 raeburn 6862: );
1.139 raeburn 6863: if ($position eq 'top') {
1.257 raeburn 6864: %defaultchecked = (
6865: 'canuse_pdfforms' => 'off',
6866: 'uselcmath' => 'on',
6867: 'usejsme' => 'on',
1.398 raeburn 6868: 'inline_chem' => 'on',
1.289 raeburn 6869: 'canclone' => 'none',
1.257 raeburn 6870: );
1.398 raeburn 6871: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6872: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6873: if (ref($settings) eq 'HASH') {
6874: if ($settings->{'texengine'}) {
6875: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6876: $deftex = $settings->{'texengine'};
6877: }
6878: }
6879: }
6880: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6881: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6882: '<span class="LC_nobreak">'.$choices{'texengine'}.
6883: '</span></td><td class="LC_right_item">'.
6884: '<select name="texengine">'."\n";
6885: my %texoptions = (
6886: MathJax => 'MathJax',
6887: mimetex => &mt('Convert to Images'),
6888: tth => &mt('TeX to HTML'),
6889: );
6890: foreach my $renderer ('MathJax','mimetex','tth') {
6891: my $selected = '';
6892: if ($renderer eq $deftex) {
6893: $selected = ' selected="selected"';
6894: }
6895: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6896: }
6897: $mathdisp .= '</select></td></tr>'."\n";
6898: $itemcount ++;
1.139 raeburn 6899: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6900: \%choices,$itemcount);
1.314 raeburn 6901: $datatable = $mathdisp.$datatable;
1.264 raeburn 6902: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6903: $datatable .=
1.306 raeburn 6904: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6905: '<span class="LC_nobreak">'.$choices{'canclone'}.
6906: '</span></td><td class="LC_left_item">';
6907: my $currcanclone = 'none';
6908: my $onclick;
6909: my @cloneoptions = ('none','domain');
1.380 raeburn 6910: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6911: none => 'No additional course requesters',
6912: domain => "Any course requester in course's domain",
6913: instcode => 'Course requests for official courses ...',
6914: );
6915: my (%codedefaults,@code_order,@posscodes);
6916: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6917: \@code_order) eq 'ok') {
6918: if (@code_order > 0) {
6919: push(@cloneoptions,'instcode');
6920: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6921: }
6922: }
6923: if (ref($settings) eq 'HASH') {
6924: if ($settings->{'canclone'}) {
6925: if (ref($settings->{'canclone'}) eq 'HASH') {
6926: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6927: if (@code_order > 0) {
6928: $currcanclone = 'instcode';
6929: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6930: }
6931: }
6932: } elsif ($settings->{'canclone'} eq 'domain') {
6933: $currcanclone = $settings->{'canclone'};
6934: }
6935: }
1.289 raeburn 6936: }
1.264 raeburn 6937: foreach my $option (@cloneoptions) {
6938: my ($checked,$additional);
6939: if ($currcanclone eq $option) {
6940: $checked = ' checked="checked"';
6941: }
6942: if ($option eq 'instcode') {
6943: if (@code_order) {
6944: my $show = 'none';
6945: if ($checked) {
6946: $show = 'block';
6947: }
1.317 raeburn 6948: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6949: &mt('Institutional codes for new and cloned course have identical:').
6950: '<br />';
6951: foreach my $item (@code_order) {
6952: my $codechk;
6953: if ($checked) {
6954: if (grep(/^\Q$item\E$/,@posscodes)) {
6955: $codechk = ' checked="checked"';
6956: }
6957: }
6958: $additional .= '<label>'.
6959: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6960: $item.'</label>';
6961: }
6962: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6963: }
6964: }
6965: $datatable .=
6966: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6967: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6968: '</label> '.$additional.'</span><br />';
6969: }
6970: $datatable .= '</td>'.
6971: '</tr>';
6972: $itemcount ++;
1.139 raeburn 6973: } else {
6974: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 6975: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
6976: %deftimeout,%currmysql);
1.192 raeburn 6977: my $currusecredits = 0;
1.257 raeburn 6978: my $postsubmitclient = 1;
1.405 raeburn 6979: my $ltiauth = 0;
1.422 raeburn 6980: my %domexttool;
6981: my %exttool;
1.432 raeburn 6982: my %crsauthor;
1.438 raeburn 6983: my %crseditors;
1.271 raeburn 6984: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6985: if (ref($settings) eq 'HASH') {
1.404 raeburn 6986: if ($settings->{'ltiauth'}) {
6987: $ltiauth = 1;
1.405 raeburn 6988: }
1.422 raeburn 6989: if (ref($settings->{'domexttool'}) eq 'HASH') {
6990: foreach my $type (@types) {
6991: if ($settings->{'domexttool'}->{$type}) {
6992: $domexttool{$type} = ' checked="checked"';
6993: }
6994: }
6995: } else {
6996: foreach my $type (@types) {
6997: if ($staticdefaults{'domexttool'}) {
6998: $domexttool{$type} = ' checked="checked"';
6999: }
7000: }
7001: }
7002: if (ref($settings->{'exttool'}) eq 'HASH') {
7003: foreach my $type (@types) {
7004: if ($settings->{'exttool'}->{$type}) {
7005: $exttool{$type} = ' checked="checked"';
7006: }
7007: }
7008: }
1.432 raeburn 7009: if (ref($settings->{'crsauthor'}) eq 'HASH') {
7010: foreach my $type (@types) {
7011: if ($settings->{'crsauthor'}->{$type}) {
7012: $crsauthor{$type} = ' checked="checked"';
7013: }
7014: }
7015: } else {
7016: foreach my $type (@types) {
7017: if ($staticdefaults{'crsauthor'}) {
7018: $crsauthor{$type} = ' checked="checked"';
7019: }
7020: }
7021: }
1.438 raeburn 7022: if (ref($settings->{'crseditors'}) eq 'ARRAY') {
7023: foreach my $editor (@{$settings->{'crseditors'}}) {
7024: $crseditors{$editor} = ' checked="checked"';
7025: }
7026: } else {
7027: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7028: $crseditors{$editor} = ' checked="checked"';
7029: }
7030: }
1.139 raeburn 7031: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7032: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7033: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7034: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7035: }
7036: }
1.428 raeburn 7037: if (ref($settings->{'coursequota'}) eq 'HASH') {
7038: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7039: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7040: }
7041: }
1.192 raeburn 7042: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7043: foreach my $type (@types) {
7044: next if ($type eq 'community');
7045: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7046: if ($defcredits{$type} ne '') {
7047: $currusecredits = 1;
7048: }
7049: }
7050: }
7051: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7052: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7053: $postsubmitclient = 0;
7054: foreach my $type (@types) {
7055: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7056: }
7057: } else {
7058: foreach my $type (@types) {
7059: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7060: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7061: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7062: } else {
7063: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7064: }
7065: } else {
7066: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7067: }
7068: }
7069: }
7070: } else {
7071: foreach my $type (@types) {
7072: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7073: }
7074: }
1.276 raeburn 7075: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7076: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7077: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7078: }
7079: } else {
7080: foreach my $type (@types) {
7081: $currmysql{$type} = $staticdefaults{'mysqltables'};
7082: }
7083: }
1.258 raeburn 7084: } else {
7085: foreach my $type (@types) {
7086: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7087: if ($staticdefaults{'domexttool'}) {
7088: $domexttool{$type} = ' checked="checked"';
7089: }
1.432 raeburn 7090: if ($staticdefaults{'crsauthor'}) {
7091: $crsauthor{$type} = ' checked="checked"';
7092: }
1.258 raeburn 7093: }
1.438 raeburn 7094: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7095: $crseditors{$editor} = ' checked="checked"';
7096: }
1.139 raeburn 7097: }
7098: if (!$currdefresponder) {
1.198 raeburn 7099: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7100: } elsif ($currdefresponder < 1) {
7101: $currdefresponder = 1;
7102: }
1.198 raeburn 7103: foreach my $type (@types) {
7104: if ($curruploadquota{$type} eq '') {
7105: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7106: }
1.428 raeburn 7107: if ($currcoursequota{$type} eq '') {
7108: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7109: }
1.198 raeburn 7110: }
1.139 raeburn 7111: $datatable .=
1.192 raeburn 7112: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7113: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7114: '</span></td>'.
7115: '<td class="LC_right_item"><span class="LC_nobreak">'.
7116: '<input type="text" name="anonsurvey_threshold"'.
7117: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7118: '</td></tr>'."\n";
7119: $itemcount ++;
7120: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7121: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7122: $choices{'uploadquota'}.
7123: '</span></td>'.
1.306 raeburn 7124: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7125: '<table><tr>';
1.198 raeburn 7126: foreach my $type (@types) {
1.306 raeburn 7127: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7128: '<input type="text" name="uploadquota_'.$type.'"'.
7129: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7130: }
7131: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7132: $itemcount ++;
1.428 raeburn 7133: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7134: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7135: $choices{'coursequota'}.
7136: '</span></td>'.
7137: '<td style="text-align: right" class="LC_right_item">'.
7138: '<table><tr>';
7139: foreach my $type (@types) {
7140: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7141: '<input type="text" name="coursequota_'.$type.'"'.
7142: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7143: }
7144: $datatable .= '</tr></table></td></tr>'."\n";
7145: $itemcount ++;
1.236 raeburn 7146: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7147: my $display = 'none';
1.192 raeburn 7148: if ($currusecredits) {
7149: $display = 'block';
7150: }
7151: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7152: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7153: foreach my $type (@types) {
7154: next if ($type eq 'community');
1.306 raeburn 7155: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7156: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7157: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7158: }
7159: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7160: %defaultchecked = ('coursecredits' => 'off');
7161: @toggles = ('coursecredits');
7162: my $current = {
7163: 'coursecredits' => $currusecredits,
7164: };
7165: (my $table,$itemcount) =
7166: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7167: \%choices,$itemcount,$onclick,$additional,'left');
7168: $datatable .= $table;
7169: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7170: my $display = 'none';
7171: if ($postsubmitclient) {
7172: $display = 'block';
7173: }
7174: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7175: &mt('Number of seconds submit is disabled').'<br />'.
7176: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7177: '<table><tr>';
1.257 raeburn 7178: foreach my $type (@types) {
1.306 raeburn 7179: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7180: '<input type="text" name="'.$type.'_timeout" value="'.
7181: $deftimeout{$type}.'" size="5" /></td>';
7182: }
7183: $additional .= '</tr></table></div>'."\n";
7184: %defaultchecked = ('postsubmit' => 'on');
7185: @toggles = ('postsubmit');
1.280 raeburn 7186: $current = {
7187: 'postsubmit' => $postsubmitclient,
7188: };
1.257 raeburn 7189: ($table,$itemcount) =
7190: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7191: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7192: $datatable .= $table;
1.276 raeburn 7193: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7194: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7195: $choices{'mysqltables'}.
7196: '</span></td>'.
1.306 raeburn 7197: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7198: '<table><tr>';
7199: foreach my $type (@types) {
1.306 raeburn 7200: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7201: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7202: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7203: }
7204: $datatable .= '</tr></table></td></tr>'."\n";
7205: $itemcount ++;
1.404 raeburn 7206: %defaultchecked = ('ltiauth' => 'off');
7207: @toggles = ('ltiauth');
7208: $current = {
7209: 'ltiauth' => $ltiauth,
7210: };
7211: ($table,$itemcount) =
7212: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7213: \%choices,$itemcount,undef,undef,'left');
7214: $datatable .= $table;
1.422 raeburn 7215: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7216: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7217: $choices{'domexttool'}.
7218: '</span></td>'.
7219: '<td style="text-align: right" class="LC_right_item">'.
7220: '<table><tr>';
7221: foreach my $type (@types) {
7222: $datatable .= '<td style="text-align: left">'.
7223: '<span class="LC_nobreak">'.
1.438 raeburn 7224: '<label><input type="checkbox" name="domexttool"'.
1.422 raeburn 7225: ' value="'.$type.'"'.$domexttool{$type}.' />'.
1.438 raeburn 7226: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7227: }
7228: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7229: $itemcount ++;
1.422 raeburn 7230: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7231: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7232: $choices{'exttool'}.
7233: '</span></td>'.
7234: '<td style="text-align: right" class="LC_right_item">'.
7235: '<table><tr>';
7236: foreach my $type (@types) {
7237: $datatable .= '<td style="text-align: left">'.
7238: '<span class="LC_nobreak">'.
1.438 raeburn 7239: '<label><input type="checkbox" name="exttool"'.
1.422 raeburn 7240: ' value="'.$type.'"'.$exttool{$type}.' />'.
1.438 raeburn 7241: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7242: }
7243: $datatable .= '</tr></table></td></tr>'."\n";
1.432 raeburn 7244: $itemcount ++;
7245: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7246: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7247: $choices{'crsauthor'}.
7248: '</span></td>'.
7249: '<td style="text-align: right" class="LC_right_item">'.
7250: '<table><tr>';
7251: foreach my $type (@types) {
7252: $datatable .= '<td style="text-align: left">'.
7253: '<span class="LC_nobreak">'.
1.438 raeburn 7254: '<label><input type="checkbox" name="crsauthor"'.
1.432 raeburn 7255: ' value="'.$type.'"'.$crsauthor{$type}.' />'.
1.438 raeburn 7256: &mt($type).'</label></span></td>'."\n";
7257: }
7258: $datatable .= '</tr></table></td></tr>'."\n";
7259: $itemcount ++;
7260: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7261: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7262: $choices{'crseditors'}.
7263: '</span></td>'.
7264: '<td style="text-align: right" class="LC_right_item">'.
7265: '<table><tr>';
7266: my @editors = ('edit','xml','daxe');
7267: my %editornames = &crseditor_titles();
7268: foreach my $editor (@editors) {
7269: $datatable .= '<td style="text-align: left">'.
7270: '<span class="LC_nobreak">'.
7271: '<label><input type="checkbox" name="crseditors"'.
7272: ' value="'.$editor.'"'.$crseditors{$editor}.' />'.
7273: $editornames{$editor}.'</label></span></td>'."\n";
1.432 raeburn 7274: }
7275: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7276: }
1.192 raeburn 7277: $$rowtotal += $itemcount;
1.121 raeburn 7278: return $datatable;
1.118 jms 7279: }
7280:
1.438 raeburn 7281: sub crseditor_titles {
7282: return &Apache::lonlocal::texthash(
7283: edit => 'Standard editor (Edit)',
7284: xml => 'Text editor (EditXML)',
7285: daxe => 'Daxe editor (Daxe)',
7286: );
7287: }
7288:
1.429 raeburn 7289: sub print_authordefaults {
7290: my ($position,$dom,$settings,$rowtotal) = @_;
7291: my ($css_class,$datatable,%checkedon,%checkedoff);
7292: my $itemcount = 1;
7293: my %titles = &authordefaults_titles();
7294: if ($position eq 'top') {
7295: my %defaultchecked = (
7296: 'nocodemirror' => 'off',
1.437 raeburn 7297: 'daxecollapse' => 'off',
1.429 raeburn 7298: 'domcoordacc' => 'on',
7299: );
1.437 raeburn 7300: my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
1.429 raeburn 7301: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
7302: \%titles,$itemcount);
7303: my %staticdefaults = (
7304: 'copyright' => 'default',
7305: 'sourceavail' => 'closed',
7306: );
7307: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7308: my %currrights;
7309: foreach my $item ('copyright','sourceavail') {
7310: $currrights{$item} = $staticdefaults{$item};
7311: if (ref($settings) eq 'HASH') {
7312: if (exists($settings->{$item})) {
7313: $currrights{$item} = $settings->{$item};
7314: }
7315: }
7316: }
7317: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7318: '<span class="LC_nobreak">'.$titles{'copyright'}.
7319: '</span></td><td class="LC_right_item">'.
7320: &selectbox('copyright',$currrights{'copyright'},'',
7321: \&Apache::loncommon::copyrightdescription,
7322: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
7323: '</td></tr>'."\n";
7324: $itemcount ++;
7325: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7326: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7327: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
7328: '</span></td><td class="LC_right_item">'.
7329: &selectbox('sourceavail',$currrights{'sourceavail'},'',
7330: \&Apache::loncommon::source_copyrightdescription,
7331: (&Apache::loncommon::source_copyrightids)).
7332: '</td></tr>'."\n";
7333: } else {
7334: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7335: my $curreditors;
7336: my %staticdefaults = (
7337: editors => ['edit','xml'],
7338: authorquota => 500,
7339: webdav => 0,
7340: );
7341: my $curreditors = $staticdefaults{'editors'};
7342: if ((ref($settings) eq 'HASH') &&
7343: (ref($settings->{'editors'}) eq 'ARRAY')) {
7344: $curreditors = $settings->{'editors'};
7345: } else {
7346: $curreditors = $staticdefaults{'editors'};
7347: }
7348: my @editors = ('edit','xml','daxe');
7349: $datatable = '<tr'.$css_class.'>'."\n".
7350: '<td>'.$titles{'editors'}.'</td>'."\n".
7351: '<td class="LC_left_item">'."\n".
7352: '<span class="LC_nobreak">';
7353: foreach my $editor (@editors) {
7354: my $checked;
7355: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
7356: $checked = ' checked="checked"';
7357: }
7358: $datatable .= '<label>'.
7359: '<input type="checkbox" name="author_editors" '.
7360: $checked.' value="'.$editor.'" '.
7361: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
7362: $titles{$editor}.'</label> ';
7363: }
7364: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
7365: $itemcount ++;
7366: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7367: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7368: my @insttypes;
7369: if (ref($types) eq 'ARRAY') {
7370: @insttypes = @{$types};
7371: }
7372: my $typecount = 0;
7373: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
7374: my @items = ('webdav','authorquota');
7375: my %quotas;
7376: if (ref($domconf{'quotas'}) eq 'HASH') {
7377: %quotas = %{$domconf{'quotas'}};
7378: foreach my $item (@items) {
7379: if (ref($quotas{$item}) eq 'HASH') {
7380: foreach my $type (@insttypes,'default') {
7381: if ($item eq 'authorquota') {
7382: if ($quotas{$item}{$type} !~ /^\d+$/) {
7383: $quotas{$item}{$type} = $staticdefaults{$item};
7384: }
7385: } elsif ($item eq 'webdav') {
7386: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
7387: $quotas{$item}{$type} = $staticdefaults{$item};
7388: }
7389: }
7390: }
7391: } else {
7392: foreach my $type (@insttypes,'default') {
7393: $quotas{$item}{$type} = $staticdefaults{$item};
7394: }
7395: }
7396: }
7397: } else {
7398: foreach my $item (@items) {
7399: foreach my $type (@insttypes,'default') {
7400: $quotas{$item}{$type} = $staticdefaults{$item};
7401: }
7402: }
7403: }
7404: if (ref($usertypes) eq 'HASH') {
7405: my $numinrow = 4;
7406: my $onclick = '';
7407: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7408: $numinrow,$othertitle,'authorquota',
7409: \$itemcount,$onclick);
7410: $itemcount ++;
7411: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7412: $numinrow,$othertitle,'webdav',
7413: \$itemcount);
7414: $itemcount ++;
7415: }
7416: my $checkedno = ' checked="checked"';
7417: my ($checkedon,$checkedoff);
7418: if (ref($quotas{'webdav'}) eq 'HASH') {
1.436 raeburn 7419: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
1.429 raeburn 7420: if ($quotas{'webdav'}{'_LC_adv'}) {
7421: $checkedon = $checkedno;
7422: } else {
7423: $checkedoff = $checkedno;
7424: }
7425: undef($checkedno);
7426: }
7427: }
7428: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7429: $datatable .= '<tr'.$css_class.'>'.
7430: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
7431: $titles{'webdav_LC_adv_over'}.
7432: '</td>'.
7433: '<td class="LC_left_item">';
7434: foreach my $option ('none','off','on') {
7435: my ($text,$val,$checked);
7436: if ($option eq 'none') {
7437: $text = $titles{'none'};
7438: $val = '';
7439: $checked = $checkedno;
7440: } elsif ($option eq 'off') {
7441: $text = $titles{'overoff'};
7442: $val = 0;
7443: $checked = $checkedoff;
7444: } elsif ($option eq 'on') {
7445: $text = $titles{'overon'};
7446: $val = 1;
7447: $checked = $checkedon;
1.436 raeburn 7448: }
1.429 raeburn 7449: $datatable .= '<span class="LC_nobreak"><label>'.
7450: '<input type="radio" name="webdav_LC_adv"'.
7451: ' value="'.$val.'"'.$checked.' />'.
7452: $text.'</label></span> ';
7453: }
7454: $datatable .= '</td></tr>';
7455: $itemcount ++;
1.440 raeburn 7456: my %defchecked = (
7457: 'archive' => 'off',
7458: );
7459: my @toggles = ('archive');
7460: (my $archive,$itemcount) = &radiobutton_prefs($settings,['archive'],
7461: {'archive' => 'off'},
7462: \%titles,$itemcount);
7463: $datatable .= $archive."\n";
7464: $itemcount ++;
1.429 raeburn 7465: }
7466: $$rowtotal += $itemcount;
7467: return $datatable;
7468: }
7469:
7470: sub authordefaults_titles {
7471: return &Apache::lonlocal::texthash(
7472: copyright => 'Copyright/Distribution',
7473: sourceavail => ' Source Available',
7474: editors => 'Available Editors',
7475: webdav => 'WebDAV',
7476: authorquota => 'Authoring Space quotas (MB)',
7477: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
1.437 raeburn 7478: daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
1.429 raeburn 7479: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
7480: edit => 'Standard editor (Edit)',
7481: xml => 'Text editor (EditXML)',
7482: daxe => 'Daxe editor (Daxe)',
7483: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
7484: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
7485: none => 'No override set',
7486: overon => 'Override -- webDAV on',
1.436 raeburn 7487: overoff => 'Override -- webDAV off',
1.440 raeburn 7488: archive => 'Authors can download tar.gz file of Authoring Space',
1.429 raeburn 7489: );
7490: }
7491:
7492: sub selectbox {
7493: my ($name,$value,$readonly,$functionref,@idlist)=@_;
7494: my $selout = '<select name="'.$name.'">';
7495: foreach my $id (@idlist) {
7496: $selout.='<option value="'.$id.'"';
7497: if ($id eq $value) {
7498: $selout.=' selected="selected"';
7499: }
7500: if ($readonly) {
7501: $selout .= ' disabled="disabled"';
7502: }
7503: $selout.='>'.&{$functionref}($id).'</option>';
7504: }
7505: $selout.='</select>';
7506: return $selout;
7507: }
7508:
1.231 raeburn 7509: sub print_selfenrollment {
7510: my ($position,$dom,$settings,$rowtotal) = @_;
7511: my ($css_class,$datatable);
7512: my $itemcount = 1;
1.271 raeburn 7513: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7514: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7515: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7516: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7517: my @rows;
7518: my $key;
7519: if ($position eq 'top') {
7520: $key = 'admin';
7521: if (ref($rowsref) eq 'ARRAY') {
7522: @rows = @{$rowsref};
7523: }
7524: } elsif ($position eq 'middle') {
7525: $key = 'default';
7526: @rows = ('types','registered','approval','limit');
7527: }
7528: foreach my $row (@rows) {
7529: if (defined($titlesref->{$row})) {
7530: $itemcount ++;
7531: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7532: $datatable .= '<tr'.$css_class.'>'.
7533: '<td>'.$titlesref->{$row}.'</td>'.
7534: '<td class="LC_left_item">'.
7535: '<table><tr>';
7536: my (%current,%currentcap);
7537: if (ref($settings) eq 'HASH') {
7538: if (ref($settings->{$key}) eq 'HASH') {
7539: foreach my $type (@types) {
7540: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7541: $current{$type} = $settings->{$key}->{$type}->{$row};
7542: }
7543: if (($row eq 'limit') && ($key eq 'default')) {
7544: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7545: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7546: }
7547: }
7548: }
7549: }
7550: }
7551: my %roles = (
7552: '0' => &Apache::lonnet::plaintext('dc'),
7553: );
7554:
7555: foreach my $type (@types) {
7556: unless (($row eq 'registered') && ($key eq 'default')) {
7557: $datatable .= '<th>'.&mt($type).'</th>';
7558: }
7559: }
7560: unless (($row eq 'registered') && ($key eq 'default')) {
7561: $datatable .= '</tr><tr>';
7562: }
7563: foreach my $type (@types) {
7564: if ($type eq 'community') {
7565: $roles{'1'} = &mt('Community personnel');
7566: } else {
7567: $roles{'1'} = &mt('Course personnel');
7568: }
7569: $datatable .= '<td style="vertical-align: top">';
7570: if ($position eq 'top') {
7571: my %checked;
7572: if ($current{$type} eq '0') {
7573: $checked{'0'} = ' checked="checked"';
7574: } else {
7575: $checked{'1'} = ' checked="checked"';
7576: }
7577: foreach my $role ('1','0') {
7578: $datatable .= '<span class="LC_nobreak"><label>'.
7579: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7580: 'value="'.$role.'"'.$checked{$role}.' />'.
7581: $roles{$role}.'</label></span> ';
7582: }
7583: } else {
7584: if ($row eq 'types') {
7585: my %checked;
7586: if ($current{$type} =~ /^(all|dom)$/) {
7587: $checked{$1} = ' checked="checked"';
7588: } else {
7589: $checked{''} = ' checked="checked"';
7590: }
7591: foreach my $val ('','dom','all') {
7592: $datatable .= '<span class="LC_nobreak"><label>'.
7593: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7594: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7595: }
7596: } elsif ($row eq 'registered') {
7597: my %checked;
7598: if ($current{$type} eq '1') {
7599: $checked{'1'} = ' checked="checked"';
7600: } else {
7601: $checked{'0'} = ' checked="checked"';
7602: }
7603: foreach my $val ('0','1') {
7604: $datatable .= '<span class="LC_nobreak"><label>'.
7605: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7606: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7607: }
7608: } elsif ($row eq 'approval') {
7609: my %checked;
7610: if ($current{$type} =~ /^([12])$/) {
7611: $checked{$1} = ' checked="checked"';
7612: } else {
7613: $checked{'0'} = ' checked="checked"';
7614: }
7615: for my $val (0..2) {
7616: $datatable .= '<span class="LC_nobreak"><label>'.
7617: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7618: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7619: }
7620: } elsif ($row eq 'limit') {
7621: my %checked;
7622: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7623: $checked{$1} = ' checked="checked"';
7624: } else {
7625: $checked{'none'} = ' checked="checked"';
7626: }
7627: my $cap;
7628: if ($currentcap{$type} =~ /^\d+$/) {
7629: $cap = $currentcap{$type};
7630: }
7631: foreach my $val ('none','allstudents','selfenrolled') {
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: $datatable .= '<br />'.
7637: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7638: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7639: '</span>';
7640: }
7641: }
7642: $datatable .= '</td>';
7643: }
7644: $datatable .= '</tr>';
7645: }
7646: $datatable .= '</table></td></tr>';
7647: }
7648: } elsif ($position eq 'bottom') {
1.235 raeburn 7649: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7650: }
7651: $$rowtotal += $itemcount;
7652: return $datatable;
7653: }
7654:
7655: sub print_validation_rows {
7656: my ($caller,$dom,$settings,$rowtotal) = @_;
7657: my ($itemsref,$namesref,$fieldsref);
7658: if ($caller eq 'selfenroll') {
7659: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7660: } elsif ($caller eq 'requestcourses') {
7661: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7662: }
7663: my %currvalidation;
7664: if (ref($settings) eq 'HASH') {
7665: if (ref($settings->{'validation'}) eq 'HASH') {
7666: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7667: }
1.235 raeburn 7668: }
7669: my $datatable;
7670: my $itemcount = 0;
7671: foreach my $item (@{$itemsref}) {
7672: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7673: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7674: $namesref->{$item}.
7675: '</span></td>'.
7676: '<td class="LC_left_item">';
7677: if (($item eq 'url') || ($item eq 'button')) {
7678: $datatable .= '<span class="LC_nobreak">'.
7679: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7680: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7681: } elsif ($item eq 'fields') {
7682: my @currfields;
7683: if (ref($currvalidation{$item}) eq 'ARRAY') {
7684: @currfields = @{$currvalidation{$item}};
7685: }
7686: foreach my $field (@{$fieldsref}) {
7687: my $check = '';
7688: if (grep(/^\Q$field\E$/,@currfields)) {
7689: $check = ' checked="checked"';
7690: }
7691: $datatable .= '<span class="LC_nobreak"><label>'.
7692: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7693: ' value="'.$field.'"'.$check.' />'.$field.
7694: '</label></span> ';
7695: }
7696: } elsif ($item eq 'markup') {
1.334 raeburn 7697: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7698: $currvalidation{$item}.
1.231 raeburn 7699: '</textarea>';
1.235 raeburn 7700: }
7701: $datatable .= '</td></tr>'."\n";
7702: if (ref($rowtotal)) {
1.231 raeburn 7703: $itemcount ++;
7704: }
7705: }
1.235 raeburn 7706: if ($caller eq 'requestcourses') {
7707: my %currhash;
1.248 raeburn 7708: if (ref($settings) eq 'HASH') {
7709: if (ref($settings->{'validation'}) eq 'HASH') {
7710: if ($settings->{'validation'}{'dc'} ne '') {
7711: $currhash{$settings->{'validation'}{'dc'}} = 1;
7712: }
1.235 raeburn 7713: }
7714: }
7715: my $numinrow = 2;
7716: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7717: 'validationdc',%currhash);
1.247 raeburn 7718: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7719: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7720: if ($numdc > 1) {
1.247 raeburn 7721: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7722: } else {
1.247 raeburn 7723: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7724: }
1.247 raeburn 7725: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7726: $itemcount ++;
7727: }
7728: if (ref($rowtotal)) {
7729: $$rowtotal += $itemcount;
7730: }
1.231 raeburn 7731: return $datatable;
7732: }
7733:
1.357 raeburn 7734: sub print_privacy {
7735: my ($position,$dom,$settings,$rowtotal) = @_;
7736: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7737: my $itemcount = 0;
1.417 raeburn 7738: if ($position eq 'top') {
7739: $numinrow = 2;
7740: } else {
1.357 raeburn 7741: @items = ('domain','author','course','community');
7742: %names = &Apache::lonlocal::texthash (
7743: domain => 'Assigned domain role(s)',
7744: author => 'Assigned co-author role(s)',
7745: course => 'Assigned course role(s)',
1.416 raeburn 7746: community => 'Assigned community role(s)',
1.357 raeburn 7747: );
7748: $numinrow = 4;
7749: ($othertitle,$usertypes,$types) =
7750: &Apache::loncommon::sorted_inst_types($dom);
7751: }
1.447.2.4 raeburn 7752: if (($position eq 'top') || ($position eq 'bottom')) {
1.357 raeburn 7753: my (%by_ip,%by_location,@intdoms,@instdoms);
7754: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7755: if ($position eq 'top') {
7756: my %curr;
7757: my @options = ('none','user','domain','auto');
7758: my %titles = &Apache::lonlocal::texthash (
7759: none => 'Not allowed',
7760: user => 'User authorizes',
7761: domain => 'DC authorizes',
7762: auto => 'Unrestricted',
7763: instdom => 'Other domain shares institution/provider',
7764: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7765: notify => 'Notify when role needs authorization',
1.357 raeburn 7766: );
7767: my %names = &Apache::lonlocal::texthash (
7768: domain => 'Domain role',
7769: author => 'Co-author role',
7770: course => 'Course role',
7771: community => 'Community role',
7772: );
7773: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7774: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7775: foreach my $domtype ('instdom','extdom') {
7776: my (%checked,$skip);
7777: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7778: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7779: '<td class="LC_left_item">';
7780: if ($domtype eq 'instdom') {
7781: unless (@instdoms > 1) {
7782: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7783: $skip = 1;
7784: }
7785: } elsif ($domtype eq 'extdom') {
7786: if (keys(%by_location) == 0) {
7787: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7788: $skip = 1;
7789: }
7790: }
7791: unless ($skip) {
7792: foreach my $roletype ('domain','author','course','community') {
7793: $checked{'auto'} = ' checked="checked"';
7794: if (ref($settings) eq 'HASH') {
7795: if (ref($settings->{approval}) eq 'HASH') {
7796: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7797: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7798: $checked{$1} = ' checked="checked"';
7799: $checked{'auto'} = '';
7800: }
7801: }
7802: }
7803: }
7804: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7805: foreach my $option (@options) {
7806: $datatable .= '<span class="LC_nobreak"><label>'.
7807: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7808: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7809: '</label></span> ';
7810: }
7811: $datatable .= '</fieldset>';
7812: }
7813: }
7814: $datatable .= '</td></tr>';
7815: $itemcount ++;
7816: }
1.417 raeburn 7817: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7818: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7819: '<td class="LC_left_item">';
7820: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7821: my %curr;
7822: if (ref($settings) eq 'HASH') {
7823: if ($settings->{'notify'} ne '') {
7824: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7825: }
7826: }
7827: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7828: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7829: 'privacy_notify',%curr);
7830: if ($numdc > 0) {
7831: $datatable .= $table;
7832: } else {
7833: $datatable .= &mt('There are no active Domain Coordinators');
7834: }
7835: } else {
7836: $datatable .= &mt('Nothing to set here, as there are no other domains');
7837: }
7838: $datatable .='</td></tr>';
1.447.2.4 raeburn 7839: } elsif ($position eq 'bottom') {
1.357 raeburn 7840: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7841: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7842: foreach my $item (@{$types}) {
7843: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7844: $numinrow,$itemcount,'','','','','',
7845: '',$usertypes->{$item});
7846: $itemcount ++;
7847: }
7848: }
7849: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7850: $numinrow,$itemcount,'','','','','',
7851: '',$othertitle);
7852: $itemcount ++;
7853: } else {
1.360 raeburn 7854: my (@insttypes,%insttitles);
7855: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7856: @insttypes = @{$types};
7857: %insttitles = %{$usertypes};
7858: }
7859: foreach my $item (@insttypes,'default') {
7860: my $title;
7861: if ($item eq 'default') {
7862: $title = $othertitle;
7863: } else {
7864: $title = $insttitles{$item};
7865: }
7866: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7867: $datatable .= '<tr'.$css_class.'>'.
7868: '<td class="LC_left_item">'.$title.'</td>'.
7869: '<td class="LC_left_item">'.
7870: &mt('Nothing to set here, as there are no other domains').
7871: '</td></tr>';
7872: $itemcount ++;
7873: }
1.357 raeburn 7874: }
7875: }
7876: }
7877: if (ref($rowtotal)) {
7878: $$rowtotal += $itemcount;
7879: }
7880: return $datatable;
7881: }
7882:
1.354 raeburn 7883: sub print_passwords {
7884: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7885: my ($datatable,$css_class);
7886: my $itemcount = 0;
7887: my %titles = &Apache::lonlocal::texthash (
7888: captcha => '"Forgot Password" CAPTCHA validation',
7889: link => 'Reset link expiration (hours)',
7890: case => 'Case-sensitive usernames/e-mail',
7891: prelink => 'Information required (form 1)',
7892: postlink => 'Information required (form 2)',
7893: emailsrc => 'LON-CAPA e-mail address type(s)',
7894: customtext => 'Domain specific text (HTML)',
7895: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7896: intauth_check => 'Check bcrypt cost if authenticated',
7897: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7898: permanent => 'Permanent e-mail address',
7899: critical => 'Critical notification address',
7900: notify => 'Notification address',
7901: min => 'Minimum password length',
7902: max => 'Maximum password length',
7903: chars => 'Required characters',
1.356 raeburn 7904: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7905: );
7906: if ($position eq 'top') {
7907: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7908: my $shownlinklife = 2;
7909: my $prelink = 'both';
7910: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7911: if (ref($settings) eq 'HASH') {
7912: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7913: $shownlinklife = $settings->{resetlink};
7914: }
7915: if (ref($settings->{resetcase}) eq 'ARRAY') {
7916: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7917: }
7918: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7919: $prelink = $settings->{resetprelink};
7920: }
7921: if (ref($settings->{resetpostlink}) eq 'HASH') {
7922: %postlink = %{$settings->{resetpostlink}};
7923: }
7924: if (ref($settings->{resetemail}) eq 'ARRAY') {
7925: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7926: }
7927: if ($settings->{resetremove}) {
7928: $nostdtext = 1;
7929: }
7930: if ($settings->{resetcustom}) {
7931: $customurl = $settings->{resetcustom};
7932: }
7933: } else {
7934: if (ref($types) eq 'ARRAY') {
7935: foreach my $item (@{$types}) {
7936: $casesens{$item} = 1;
7937: $postlink{$item} = ['username','email'];
7938: }
7939: }
7940: $casesens{'default'} = 1;
7941: $postlink{'default'} = ['username','email'];
7942: $prelink = 'both';
7943: %emailsrc = (
7944: permanent => 1,
7945: critical => 1,
7946: notify => 1,
7947: );
7948: }
7949: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7950: $itemcount ++;
7951: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7952: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7953: '<td class="LC_left_item">'.
7954: '<input type="textbox" value="'.$shownlinklife.'" '.
7955: 'name="passwords_link" size="3" /></td></tr>';
7956: $itemcount ++;
7957: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7958: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7959: '<td class="LC_left_item">';
7960: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7961: foreach my $item (@{$types}) {
7962: my $checkedcase;
7963: if ($casesens{$item}) {
7964: $checkedcase = ' checked="checked"';
7965: }
7966: $datatable .= '<span class="LC_nobreak"><label>'.
7967: '<input type="checkbox" name="passwords_case_sensitive" value="'.
7968: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 7969: '</span> ';
1.354 raeburn 7970: }
7971: }
7972: my $checkedcase;
7973: if ($casesens{'default'}) {
7974: $checkedcase = ' checked="checked"';
7975: }
7976: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7977: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
7978: $othertitle.'</label></span></td>';
7979: $itemcount ++;
7980: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7981: my %checkedpre = (
7982: both => ' checked="checked"',
7983: either => '',
7984: );
7985: if ($prelink eq 'either') {
7986: $checkedpre{either} = ' checked="checked"';
7987: $checkedpre{both} = '';
7988: }
7989: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7990: '<td class="LC_left_item"><span class="LC_nobreak">'.
7991: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7992: &mt('Both username and e-mail address').'</label></span> '.
7993: '<span class="LC_nobreak"><label>'.
7994: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7995: &mt('Either username or e-mail address').'</label></span></td></tr>';
7996: $itemcount ++;
7997: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7998: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7999: '<td class="LC_left_item">';
8000: my %postlinked;
8001: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8002: foreach my $item (@{$types}) {
8003: undef(%postlinked);
8004: $datatable .= '<fieldset style="display: inline-block;">'.
8005: '<legend>'.$usertypes->{$item}.'</legend>';
8006: if (ref($postlink{$item}) eq 'ARRAY') {
8007: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
8008: }
8009: foreach my $field ('email','username') {
8010: my $checked;
8011: if ($postlinked{$field}) {
8012: $checked = ' checked="checked"';
8013: }
8014: $datatable .= '<span class="LC_nobreak"><label>'.
8015: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
8016: $field.'"'.$checked.' />'.$field.'</label>'.
8017: '<span> ';
8018: }
8019: $datatable .= '</fieldset>';
8020: }
8021: }
8022: if (ref($postlink{'default'}) eq 'ARRAY') {
8023: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
8024: }
8025: $datatable .= '<fieldset style="display: inline-block;">'.
8026: '<legend>'.$othertitle.'</legend>';
8027: foreach my $field ('email','username') {
8028: my $checked;
8029: if ($postlinked{$field}) {
8030: $checked = ' checked="checked"';
8031: }
8032: $datatable .= '<span class="LC_nobreak"><label>'.
8033: '<input type="checkbox" name="passwords_postlink_default" value="'.
8034: $field.'"'.$checked.' />'.$field.'</label>'.
8035: '<span> ';
8036: }
8037: $datatable .= '</fieldset></td></tr>';
8038: $itemcount ++;
8039: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8040: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
8041: '<td class="LC_left_item">';
8042: foreach my $type ('permanent','critical','notify') {
8043: my $checkedemail;
8044: if ($emailsrc{$type}) {
8045: $checkedemail = ' checked="checked"';
8046: }
8047: $datatable .= '<span class="LC_nobreak"><label>'.
8048: '<input type="checkbox" name="passwords_emailsrc" value="'.
8049: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8050: '<span> ';
8051: }
8052: $datatable .= '</td></tr>';
8053: $itemcount ++;
8054: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8055: my $switchserver = &check_switchserver($dom,$confname);
8056: my ($showstd,$noshowstd);
8057: if ($nostdtext) {
8058: $noshowstd = ' checked="checked"';
8059: } else {
8060: $showstd = ' checked="checked"';
8061: }
8062: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8063: '<td class="LC_left_item"><span class="LC_nobreak">'.
8064: &mt('Retain standard text:').
8065: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8066: &mt('Yes').'</label>'.' '.
8067: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8068: &mt('No').'</label></span><br />'.
8069: '<span class="LC_fontsize_small">'.
8070: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8071: &mt('Include custom text:');
8072: if ($customurl) {
1.369 raeburn 8073: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8074: undef,undef,undef,undef,'background-color:#ffffff');
8075: $datatable .= '<span class="LC_nobreak"> '.$link.
8076: '<label><input type="checkbox" name="passwords_custom_del"'.
8077: ' value="1" />'.&mt('Delete?').'</label></span>'.
8078: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8079: }
8080: if ($switchserver) {
8081: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8082: } else {
8083: $datatable .='<span class="LC_nobreak"> '.
8084: '<input type="file" name="passwords_customfile" /></span>';
8085: }
8086: $datatable .= '</td></tr>';
8087: } elsif ($position eq 'middle') {
8088: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8089: my @items = ('intauth_cost','intauth_check','intauth_switch');
8090: my %defaults;
8091: if (ref($domconf{'defaults'}) eq 'HASH') {
8092: %defaults = %{$domconf{'defaults'}};
8093: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8094: $defaults{'intauth_cost'} = 10;
8095: }
8096: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8097: $defaults{'intauth_check'} = 0;
8098: }
8099: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8100: $defaults{'intauth_switch'} = 0;
8101: }
8102: } else {
8103: %defaults = (
8104: 'intauth_cost' => 10,
8105: 'intauth_check' => 0,
8106: 'intauth_switch' => 0,
8107: );
8108: }
8109: foreach my $item (@items) {
8110: if ($itemcount%2) {
8111: $css_class = '';
8112: } else {
8113: $css_class = ' class="LC_odd_row" ';
8114: }
8115: $datatable .= '<tr'.$css_class.'>'.
8116: '<td><span class="LC_nobreak">'.$titles{$item}.
8117: '</span></td><td class="LC_left_item" colspan="3">';
8118: if ($item eq 'intauth_switch') {
8119: my @options = (0,1,2);
8120: my %optiondesc = &Apache::lonlocal::texthash (
8121: 0 => 'No',
8122: 1 => 'Yes',
8123: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8124: );
8125: $datatable .= '<table width="100%">';
8126: foreach my $option (@options) {
8127: my $checked = ' ';
8128: if ($defaults{$item} eq $option) {
8129: $checked = ' checked="checked"';
8130: }
8131: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8132: '<label><input type="radio" name="'.$item.
8133: '" value="'.$option.'"'.$checked.' />'.
8134: $optiondesc{$option}.'</label></span></td></tr>';
8135: }
8136: $datatable .= '</table>';
8137: } elsif ($item eq 'intauth_check') {
8138: my @options = (0,1,2);
8139: my %optiondesc = &Apache::lonlocal::texthash (
8140: 0 => 'No',
8141: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8142: 2 => 'Yes, disallow login if stored cost is less than domain default',
8143: );
8144: $datatable .= '<table width="100%">';
8145: foreach my $option (@options) {
8146: my $checked = ' ';
8147: my $onclick;
8148: if ($defaults{$item} eq $option) {
8149: $checked = ' checked="checked"';
8150: }
8151: if ($option == 2) {
8152: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8153: }
8154: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8155: '<label><input type="radio" name="'.$item.
8156: '" value="'.$option.'"'.$checked.$onclick.' />'.
8157: $optiondesc{$option}.'</label></span></td></tr>';
8158: }
8159: $datatable .= '</table>';
8160: } else {
8161: $datatable .= '<input type="text" name="'.$item.'" value="'.
8162: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8163: }
8164: $datatable .= '</td></tr>';
8165: $itemcount ++;
8166: }
8167: } elsif ($position eq 'lower') {
1.405 raeburn 8168: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8169: } else {
1.359 raeburn 8170: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8171: my %ownerchg = (
8172: by => {},
8173: for => {},
8174: );
8175: my %ownertitles = &Apache::lonlocal::texthash (
8176: by => 'Course owner status(es) allowed',
8177: for => 'Student status(es) allowed',
8178: );
1.354 raeburn 8179: if (ref($settings) eq 'HASH') {
1.359 raeburn 8180: if (ref($settings->{crsownerchg}) eq 'HASH') {
8181: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8182: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8183: }
8184: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8185: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8186: }
1.354 raeburn 8187: }
8188: }
8189: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8190: $datatable .= '<tr '.$css_class.'>'.
8191: '<td>'.
8192: &mt('Requirements').'<ul>'.
1.359 raeburn 8193: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8194: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8195: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8196: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8197: '</ul>'.
8198: '</td>'.
1.359 raeburn 8199: '<td class="LC_left_item">';
8200: foreach my $item ('by','for') {
8201: $datatable .= '<fieldset style="display: inline-block;">'.
8202: '<legend>'.$ownertitles{$item}.'</legend>';
8203: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8204: foreach my $type (@{$types}) {
8205: my $checked;
8206: if ($ownerchg{$item}{$type}) {
8207: $checked = ' checked="checked"';
8208: }
8209: $datatable .= '<span class="LC_nobreak"><label>'.
8210: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8211: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8212: '</span> ';
1.359 raeburn 8213: }
8214: }
8215: my $checked;
8216: if ($ownerchg{$item}{'default'}) {
8217: $checked = ' checked="checked"';
8218: }
8219: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8220: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8221: $othertitle.'</label></span></fieldset>';
8222: }
8223: $datatable .= '</td></tr>';
1.354 raeburn 8224: }
8225: return $datatable;
8226: }
8227:
1.405 raeburn 8228: sub password_rules {
8229: my ($prefix,$itemcountref,$settings) = @_;
1.447.2.5 raeburn 8230: my ($min,$max,%chars,$numsaved,$numinrow);
1.405 raeburn 8231: my %titles;
8232: if ($prefix eq 'passwords') {
8233: %titles = &Apache::lonlocal::texthash (
8234: min => 'Minimum password length',
8235: max => 'Maximum password length',
8236: chars => 'Required characters',
8237: );
1.421 raeburn 8238: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8239: %titles = &Apache::lonlocal::texthash (
8240: min => 'Minimum secret length',
8241: max => 'Maximum secret length',
8242: chars => 'Required characters',
8243: );
8244: }
8245: $min = $Apache::lonnet::passwdmin;
8246: my $datatable;
8247: my $itemcount;
8248: if (ref($itemcountref)) {
8249: $itemcount = $$itemcountref;
8250: }
8251: if (ref($settings) eq 'HASH') {
8252: if ($settings->{min}) {
8253: $min = $settings->{min};
8254: }
8255: if ($settings->{max}) {
8256: $max = $settings->{max};
8257: }
8258: if (ref($settings->{chars}) eq 'ARRAY') {
8259: map { $chars{$_} = 1; } (@{$settings->{chars}});
8260: }
1.425 raeburn 8261: if ($prefix eq 'passwords') {
1.405 raeburn 8262: if ($settings->{numsaved}) {
8263: $numsaved = $settings->{numsaved};
8264: }
8265: }
8266: }
8267: my %rulenames = &Apache::lonlocal::texthash(
8268: uc => 'At least one upper case letter',
8269: lc => 'At least one lower case letter',
8270: num => 'At least one number',
8271: spec => 'At least one non-alphanumeric',
8272: );
8273: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8274: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8275: '<td class="LC_left_item"><span class="LC_nobreak">'.
8276: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8277: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8278: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8279: '</span></td></tr>';
8280: $itemcount ++;
8281: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8282: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8283: '<td class="LC_left_item"><span class="LC_nobreak">'.
8284: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8285: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8286: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8287: '</span></td></tr>';
8288: $itemcount ++;
8289: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8290: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8291: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8292: '</span></td>';
8293: my $numinrow = 2;
8294: my @possrules = ('uc','lc','num','spec');
8295: $datatable .= '<td class="LC_left_item"><table>';
8296: for (my $i=0; $i<@possrules; $i++) {
8297: my ($rem,$checked);
8298: if ($chars{$possrules[$i]}) {
8299: $checked = ' checked="checked"';
8300: }
8301: $rem = $i%($numinrow);
8302: if ($rem == 0) {
8303: if ($i > 0) {
8304: $datatable .= '</tr>';
8305: }
8306: $datatable .= '<tr>';
8307: }
8308: $datatable .= '<td><span class="LC_nobreak"><label>'.
8309: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8310: $rulenames{$possrules[$i]}.'</label></span></td>';
8311: }
8312: my $rem = @possrules%($numinrow);
8313: my $colsleft = $numinrow - $rem;
8314: if ($colsleft > 1 ) {
8315: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8316: ' </td>';
8317: } elsif ($colsleft == 1) {
8318: $datatable .= '<td class="LC_left_item"> </td>';
8319: }
8320: $datatable .='</table></td></tr>';
8321: $itemcount ++;
8322: if ($prefix eq 'passwords') {
8323: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8324: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8325: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8326: '<td class="LC_left_item"><span class="LC_nobreak">'.
8327: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8328: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8329: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8330: '</span></td></tr>';
8331: $itemcount ++;
8332: }
8333: if (ref($itemcountref)) {
8334: $$itemcountref += $itemcount;
8335: }
8336: return $datatable;
8337: }
8338:
1.373 raeburn 8339: sub print_wafproxy {
8340: my ($position,$dom,$settings,$rowtotal) = @_;
8341: my $css_class;
8342: my $itemcount = 0;
8343: my $datatable;
8344: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8345: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8346: my %lt = &wafproxy_titles();
1.373 raeburn 8347: foreach my $server (sort(keys(%servers))) {
8348: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8349: next if ($serverhome eq '');
1.373 raeburn 8350: my $serverdom;
8351: if ($serverhome ne $server) {
8352: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8353: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8354: $othercontrol{$server} = $serverdom;
8355: }
1.373 raeburn 8356: } else {
8357: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8358: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8359: if ($serverdom ne $dom) {
8360: $othercontrol{$server} = $serverdom;
8361: } else {
8362: $setdom = 1;
8363: if (ref($settings) eq 'HASH') {
8364: if (ref($settings->{'alias'}) eq 'HASH') {
8365: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8366: if ($aliases{$dom} ne '') {
8367: $showdom = 1;
8368: }
1.373 raeburn 8369: }
1.388 raeburn 8370: if (ref($settings->{'saml'}) eq 'HASH') {
8371: $saml{$dom} = $settings->{'saml'};
8372: }
1.373 raeburn 8373: }
8374: }
8375: }
8376: }
1.381 raeburn 8377: if ($setdom) {
8378: %{$values{$dom}} = ();
8379: if (ref($settings) eq 'HASH') {
8380: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8381: $values{$dom}{$item} = $settings->{$item};
8382: }
8383: }
8384: }
1.373 raeburn 8385: if (keys(%othercontrol)) {
8386: %otherdoms = reverse(%othercontrol);
8387: foreach my $domain (keys(%otherdoms)) {
8388: %{$values{$domain}} = ();
8389: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8390: if (ref($config{'wafproxy'}) eq 'HASH') {
8391: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8392: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8393: $saml{$domain} = $config{'wafproxy'}{'saml'};
8394: }
1.383 raeburn 8395: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8396: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8397: }
8398: }
8399: }
8400: }
8401: if ($position eq 'top') {
8402: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8403: my %aliasinfo;
1.373 raeburn 8404: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8405: $itemcount ++;
8406: my $dom_in_effect;
8407: my $aliasrows = '<tr>'.
1.383 raeburn 8408: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.433 raeburn 8409: &mt('Hostname').': '.
8410: '<span class="LC_nobreak LC_cusr_emph">'.
8411: &Apache::lonnet::hostname($server).
8412: '</span></td><td> </td>';
1.373 raeburn 8413: if ($othercontrol{$server}) {
1.381 raeburn 8414: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8415: my ($current,$forsaml);
1.383 raeburn 8416: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8417: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8418: }
1.388 raeburn 8419: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8420: if ($saml{$dom_in_effect}{$server}) {
8421: $forsaml = 1;
8422: }
8423: }
1.383 raeburn 8424: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8425: &mt('Alias').': ';
1.373 raeburn 8426: if ($current) {
1.381 raeburn 8427: $aliasrows .= $current;
1.388 raeburn 8428: if ($forsaml) {
1.396 raeburn 8429: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8430: }
1.373 raeburn 8431: } else {
1.383 raeburn 8432: $aliasrows .= &mt('None');
1.373 raeburn 8433: }
1.383 raeburn 8434: $aliasrows .= ' <span class="LC_small">('.
8435: &mt('controlled by domain: [_1]',
8436: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8437: } else {
1.381 raeburn 8438: $dom_in_effect = $dom;
1.388 raeburn 8439: my ($current,$samlon,$samloff);
8440: $samloff = ' checked="checked"';
1.373 raeburn 8441: if (ref($aliases{$dom}) eq 'HASH') {
8442: if ($aliases{$dom}{$server}) {
8443: $current = $aliases{$dom}{$server};
8444: }
8445: }
1.388 raeburn 8446: if (ref($saml{$dom}) eq 'HASH') {
8447: if ($saml{$dom}{$server}) {
8448: $samlon = $samloff;
8449: undef($samloff);
8450: }
8451: }
1.383 raeburn 8452: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8453: &mt('Alias').': '.
1.381 raeburn 8454: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8455: 'value="'.$current.'" size="30" />'.
8456: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8457: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8458: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8459: &mt('No').'</label> <label>'.
1.388 raeburn 8460: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8461: &mt('Yes').'</label></span>'.
1.425 raeburn 8462: '</td>';
1.381 raeburn 8463: }
8464: $aliasrows .= '</tr>';
8465: $aliasinfo{$dom_in_effect} .= $aliasrows;
8466: }
8467: if ($aliasinfo{$dom}) {
8468: my ($onclick,$wafon,$wafoff,$showtable);
8469: $onclick = ' onclick="javascript:toggleWAF();"';
8470: $wafoff = ' checked="checked"';
8471: $showtable = ' style="display:none";';
8472: if ($showdom) {
8473: $wafon = $wafoff;
8474: $wafoff = '';
8475: $showtable = ' style="display:inline;"';
8476: }
8477: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8478: $datatable = '<tr'.$css_class.'>'.
8479: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8480: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8481: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8482: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8483: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8484: &mt('No').'</label></span></td>'.
8485: '<td class="LC_left_item">'.
8486: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8487: '</table></td></tr>';
8488: $itemcount++;
8489: }
1.383 raeburn 8490: if (keys(%otherdoms)) {
8491: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8492: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8493: $datatable .= '<tr'.$css_class.'>'.
8494: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8495: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8496: '</table></td></tr>';
1.381 raeburn 8497: $itemcount++;
1.373 raeburn 8498: }
8499: }
8500: } else {
1.383 raeburn 8501: my %ip_methods = &remoteip_methods();
1.373 raeburn 8502: if ($setdom) {
8503: $itemcount ++;
8504: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8505: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8506: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8507: $wafstyle = ' style="display:none;"';
8508: $nowafstyle = ' style="display:table-row;"';
8509: $currwafdisplay = ' style="display: none"';
8510: $wafrangestyle = ' style="display: none"';
8511: $curr_remotip = 'n';
1.382 raeburn 8512: $ssltossl = ' checked="checked"';
1.381 raeburn 8513: if ($showdom) {
8514: $wafstyle = ' style="display:table-row;"';
8515: $nowafstyle = ' style="display:none;"';
8516: if (keys(%{$values{$dom}})) {
8517: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8518: $curr_remotip = $values{$dom}{remoteip};
8519: }
8520: if ($curr_remotip eq 'h') {
8521: $currwafdisplay = ' style="display:table-row"';
8522: $wafrangestyle = ' style="display:inline-block;"';
8523: }
1.382 raeburn 8524: if ($values{$dom}{'sslopt'}) {
8525: $alltossl = ' checked="checked"';
8526: $ssltossl = '';
8527: }
1.381 raeburn 8528: }
8529: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8530: $vpndircheck = ' checked="checked"';
8531: $currwafvpn = ' style="display:table-row;"';
8532: $wafrangestyle = ' style="display:inline-block;"';
8533: } else {
8534: $vpnaliascheck = ' checked="checked"';
8535: $currwafvpn = ' style="display:none;"';
8536: }
8537: }
8538: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8539: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8540: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8541: '</tr>'.
8542: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8543: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8544: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8545: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8546: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8547: '<td class="LC_left_item"><table>'.
8548: '<tr>'.
8549: '<td valign="top">'.$lt{'remoteip'}.': '.
8550: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8551: foreach my $option ('m','h','n') {
8552: my $sel;
8553: if ($option eq $curr_remotip) {
8554: $sel = ' selected="selected"';
8555: }
8556: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8557: $ip_methods{$option}.'</option>';
8558: }
8559: $datatable .= '</select></td></tr>'."\n".
8560: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8561: $lt{'ipheader'}.': '.
8562: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8563: 'name="wafproxy_ipheader" />'.
8564: '</td></tr>'."\n".
8565: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8566: $lt{'trusted'}.':<br />'.
1.381 raeburn 8567: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8568: $values{$dom}{'trusted'}.'</textarea>'.
8569: '</td></tr>'."\n".
8570: '<tr><td><hr /></td></tr>'."\n".
8571: '<tr>'.
8572: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8573: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8574: $lt{'vpndirect'}.'</label>'.(' 'x2).
8575: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8576: $lt{'vpnaliased'}.'</label></span></td></tr>';
8577: foreach my $item ('vpnint','vpnext') {
8578: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8579: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8580: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8581: $values{$dom}{$item}.'</textarea>'.
8582: '</td></tr>'."\n";
1.373 raeburn 8583: }
1.382 raeburn 8584: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8585: '<tr>'.
8586: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8587: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8588: $lt{'alltossl'}.'</label>'.(' 'x2).
8589: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8590: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8591: '</table></td></tr>';
1.373 raeburn 8592: }
8593: if (keys(%otherdoms)) {
8594: foreach my $domain (sort(keys(%otherdoms))) {
8595: $itemcount ++;
8596: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8597: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8598: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8599: '<td class="LC_left_item"><table>';
1.382 raeburn 8600: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8601: my $showval = &mt('None');
1.382 raeburn 8602: if ($item eq 'ssl') {
8603: $showval = $lt{'ssltossl'};
8604: }
1.373 raeburn 8605: if ($values{$domain}{$item}) {
1.381 raeburn 8606: $showval = $values{$domain}{$item};
1.382 raeburn 8607: if ($item eq 'ssl') {
8608: $showval = $lt{'alltossl'};
1.383 raeburn 8609: } elsif ($item eq 'remoteip') {
8610: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8611: }
1.373 raeburn 8612: }
8613: $datatable .= '<tr>'.
8614: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8615: }
1.381 raeburn 8616: $datatable .= '</table></td></tr>';
1.373 raeburn 8617: }
8618: }
8619: }
8620: $$rowtotal += $itemcount;
8621: return $datatable;
8622: }
8623:
8624: sub wafproxy_titles {
8625: return &Apache::lonlocal::texthash(
1.381 raeburn 8626: remoteip => "Method for determining user's IP",
8627: ipheader => 'Request header containing remote IP',
8628: trusted => 'Trusted IP range(s)',
8629: vpnaccess => 'Access from institutional VPN',
8630: vpndirect => 'via regular hostname (no WAF)',
8631: vpnaliased => 'via aliased hostname (WAF)',
8632: vpnint => 'Internal IP Range(s) for VPN sessions',
8633: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8634: sslopt => 'Forwarding http/https',
1.381 raeburn 8635: alltossl => 'WAF forwards both http and https requests to https',
8636: ssltossl => 'WAF forwards http requests to http and https to https',
8637: );
8638: }
8639:
8640: sub remoteip_methods {
8641: return &Apache::lonlocal::texthash(
8642: m => 'Use Apache mod_remoteip',
8643: h => 'Use headers parsed by LON-CAPA',
8644: n => 'Not in use',
1.373 raeburn 8645: );
8646: }
8647:
1.137 raeburn 8648: sub print_usersessions {
8649: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8650: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8651: my (%by_ip,%by_location,@intdoms,@instdoms);
8652: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8653:
8654: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8655: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8656: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8657: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8658: if ($position eq 'top') {
1.152 raeburn 8659: if (keys(%serverhomes) > 1) {
1.145 raeburn 8660: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8661: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8662: if (ref($settings) eq 'HASH') {
8663: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8664: $curroffloadnow = $settings->{'offloadnow'};
8665: }
1.371 raeburn 8666: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8667: $curroffloadoth = $settings->{'offloadoth'};
8668: }
1.261 raeburn 8669: }
1.371 raeburn 8670: my $other_insts = scalar(keys(%by_location));
8671: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8672: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8673: } else {
1.140 raeburn 8674: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8675: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8676: '</td></tr>';
1.140 raeburn 8677: }
1.137 raeburn 8678: } else {
1.279 raeburn 8679: my %titles = &usersession_titles();
8680: my ($prefix,@types);
8681: if ($position eq 'bottom') {
8682: $prefix = 'remote';
8683: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8684: } else {
1.279 raeburn 8685: $prefix = 'hosted';
8686: @types = ('excludedomain','includedomain');
8687: }
8688: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8689: }
8690: $$rowtotal += $itemcount;
8691: return $datatable;
8692: }
8693:
8694: sub rules_by_location {
8695: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8696: my ($datatable,$itemcount,$css_class);
8697: if (keys(%{$by_location}) == 0) {
8698: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8699: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8700: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8701: '</td></tr>';
8702: $itemcount = 1;
8703: } else {
8704: $itemcount = 0;
8705: my $numinrow = 5;
8706: my (%current,%checkedon,%checkedoff);
8707: my @locations = sort(keys(%{$by_location}));
8708: foreach my $type (@{$types}) {
8709: $checkedon{$type} = '';
8710: $checkedoff{$type} = ' checked="checked"';
8711: }
8712: if (ref($settings) eq 'HASH') {
8713: if (ref($settings->{$prefix}) eq 'HASH') {
8714: foreach my $key (keys(%{$settings->{$prefix}})) {
8715: $current{$key} = $settings->{$prefix}{$key};
8716: if ($key eq 'version') {
8717: if ($current{$key} ne '') {
1.145 raeburn 8718: $checkedon{$key} = ' checked="checked"';
8719: $checkedoff{$key} = '';
8720: }
1.279 raeburn 8721: } elsif (ref($current{$key}) eq 'ARRAY') {
8722: $checkedon{$key} = ' checked="checked"';
8723: $checkedoff{$key} = '';
1.137 raeburn 8724: }
8725: }
8726: }
1.279 raeburn 8727: }
8728: foreach my $type (@{$types}) {
8729: next if ($type ne 'version' && !@locations);
8730: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8731: $datatable .= '<tr'.$css_class.'>
8732: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8733: <span class="LC_nobreak">
8734: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8735: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8736: if ($type eq 'version') {
8737: my @lcversions = &Apache::lonnet::all_loncaparevs();
8738: my $selector = '<select name="'.$prefix.'_version">';
8739: foreach my $version (@lcversions) {
8740: my $selected = '';
8741: if ($current{'version'} eq $version) {
8742: $selected = ' selected="selected"';
1.145 raeburn 8743: }
1.279 raeburn 8744: $selector .= ' <option value="'.$version.'"'.
8745: $selected.'>'.$version.'</option>';
8746: }
8747: $selector .= '</select> ';
8748: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8749: } else {
8750: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8751: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8752: ' />'.(' 'x2).
8753: '<input type="button" value="'.&mt('uncheck all').'" '.
8754: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8755: "\n".
8756: '</div><div><table>';
8757: my $rem;
8758: for (my $i=0; $i<@locations; $i++) {
8759: my ($showloc,$value,$checkedtype);
8760: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8761: my $ip = $by_location->{$locations[$i]}->[0];
8762: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8763: $value = join(':',@{$by_ip->{$ip}});
8764: $showloc = join(', ',@{$by_ip->{$ip}});
8765: if (ref($current{$type}) eq 'ARRAY') {
8766: foreach my $loc (@{$by_ip->{$ip}}) {
8767: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8768: $checkedtype = ' checked="checked"';
8769: last;
1.145 raeburn 8770: }
1.138 raeburn 8771: }
8772: }
8773: }
1.137 raeburn 8774: }
1.279 raeburn 8775: $rem = $i%($numinrow);
8776: if ($rem == 0) {
8777: if ($i > 0) {
8778: $datatable .= '</tr>';
8779: }
8780: $datatable .= '<tr>';
8781: }
8782: $datatable .= '<td class="LC_left_item">'.
8783: '<span class="LC_nobreak"><label>'.
8784: '<input type="checkbox" name="'.$prefix.'_'.$type.
8785: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8786: '</label></span></td>';
8787: }
8788: $rem = @locations%($numinrow);
8789: my $colsleft = $numinrow - $rem;
8790: if ($colsleft > 1 ) {
8791: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8792: ' </td>';
8793: } elsif ($colsleft == 1) {
8794: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8795: }
1.279 raeburn 8796: $datatable .= '</tr></table>';
1.137 raeburn 8797: }
1.279 raeburn 8798: $datatable .= '</td></tr>';
8799: $itemcount ++;
1.137 raeburn 8800: }
8801: }
1.279 raeburn 8802: return ($datatable,$itemcount);
1.137 raeburn 8803: }
8804:
1.275 raeburn 8805: sub print_ssl {
8806: my ($position,$dom,$settings,$rowtotal) = @_;
8807: my ($css_class,$datatable);
8808: my $itemcount = 1;
8809: if ($position eq 'top') {
1.281 raeburn 8810: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8811: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8812: my $same_institution;
8813: if ($intdom ne '') {
8814: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8815: if (ref($internet_names) eq 'ARRAY') {
8816: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8817: $same_institution = 1;
8818: }
8819: }
8820: }
1.275 raeburn 8821: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8822: $datatable = '<tr'.$css_class.'><td colspan="2">';
8823: if ($same_institution) {
8824: my %domservers = &Apache::lonnet::get_servers($dom);
8825: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8826: } else {
8827: $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.");
8828: }
8829: $datatable .= '</td></tr>';
1.275 raeburn 8830: $itemcount ++;
8831: } else {
8832: my %titles = &ssl_titles();
8833: my (%by_ip,%by_location,@intdoms,@instdoms);
8834: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8835: my @alldoms = &Apache::lonnet::all_domains();
8836: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8837: my @domservers = &Apache::lonnet::get_servers($dom);
8838: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8839: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8840: if (($position eq 'connto') || ($position eq 'connfrom')) {
8841: my $legacy;
8842: unless (ref($settings) eq 'HASH') {
8843: my $name;
8844: if ($position eq 'connto') {
8845: $name = 'loncAllowInsecure';
8846: } else {
8847: $name = 'londAllowInsecure';
8848: }
8849: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8850: my @ids=&Apache::lonnet::current_machine_ids();
8851: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8852: my %what = (
8853: $name => 1,
8854: );
8855: my ($result,$returnhash) =
8856: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8857: if ($result eq 'ok') {
8858: if (ref($returnhash) eq 'HASH') {
8859: $legacy = $returnhash->{$name};
8860: }
8861: }
8862: } else {
8863: $legacy = $Apache::lonnet::perlvar{$name};
8864: }
8865: }
1.275 raeburn 8866: foreach my $type ('dom','intdom','other') {
8867: my %checked;
8868: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8869: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8870: '<td class="LC_right_item">';
8871: my $skip;
8872: if ($type eq 'dom') {
8873: unless (keys(%servers) > 1) {
8874: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8875: $skip = 1;
8876: }
8877: }
8878: if ($type eq 'intdom') {
8879: unless (@instdoms > 1) {
8880: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8881: $skip = 1;
8882: }
8883: } elsif ($type eq 'other') {
8884: if (keys(%by_location) == 0) {
8885: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8886: $skip = 1;
8887: }
8888: }
8889: unless ($skip) {
8890: $checked{'yes'} = ' checked="checked"';
8891: if (ref($settings) eq 'HASH') {
1.293 raeburn 8892: if (ref($settings->{$position}) eq 'HASH') {
8893: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8894: $checked{$1} = $checked{'yes'};
8895: delete($checked{'yes'});
8896: }
8897: }
1.293 raeburn 8898: } else {
8899: if ($legacy == 0) {
8900: $checked{'req'} = $checked{'yes'};
8901: delete($checked{'yes'});
8902: }
1.275 raeburn 8903: }
8904: foreach my $option ('no','yes','req') {
8905: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8906: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8907: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8908: '</label></span>'.(' 'x2);
8909: }
8910: }
8911: $datatable .= '</td></tr>';
8912: $itemcount ++;
8913: }
8914: } else {
8915: my $prefix = 'replication';
8916: my @types = ('certreq','nocertreq');
1.279 raeburn 8917: if (keys(%by_location) == 0) {
8918: $datatable .= '<tr'.$css_class.'><td>'.
8919: &mt('Nothing to set here, as there are no other institutions').
8920: '</td></tr>';
8921: $itemcount ++;
1.275 raeburn 8922: } else {
1.279 raeburn 8923: ($datatable,$itemcount) =
8924: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8925: }
8926: }
8927: }
8928: $$rowtotal += $itemcount;
8929: return $datatable;
8930: }
8931:
8932: sub ssl_titles {
8933: return &Apache::lonlocal::texthash (
8934: dom => 'LON-CAPA servers/VMs from same domain',
8935: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8936: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8937: connto => 'Connections to other servers',
8938: connfrom => 'Connections from other servers',
1.275 raeburn 8939: replication => 'Replicating content to other institutions',
8940: certreq => 'Client certificate required, but specific domains exempt',
8941: nocertreq => 'No client certificate required, except for specific domains',
8942: no => 'SSL not used',
8943: yes => 'SSL Optional (used if available)',
8944: req => 'SSL Required',
8945: );
1.279 raeburn 8946: }
8947:
8948: sub print_trust {
8949: my ($prefix,$dom,$settings,$rowtotal) = @_;
8950: my ($css_class,$datatable,%checked,%choices);
8951: my (%by_ip,%by_location,@intdoms,@instdoms);
8952: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8953: my $itemcount = 1;
8954: my %titles = &trust_titles();
8955: my @types = ('exc','inc');
8956: if ($prefix eq 'top') {
8957: $prefix = 'content';
8958: } elsif ($prefix eq 'bottom') {
8959: $prefix = 'msg';
8960: }
8961: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8962: $$rowtotal += $itemcount;
8963: return $datatable;
8964: }
8965:
8966: sub trust_titles {
8967: return &Apache::lonlocal::texthash(
8968: content => "Access to this domain's content by others",
8969: shared => "Access to other domain's content by this domain",
8970: enroll => "Enrollment in this domain's courses by others",
8971: othcoau => "Co-author roles in this domain for others",
8972: coaurem => "Co-author roles for this domain's users elsewhere",
8973: domroles => "Domain roles in this domain assignable to others",
8974: catalog => "Course Catalog for this domain displayed elsewhere",
8975: reqcrs => "Requests for creation of courses in this domain by others",
8976: msg => "Users in other domains can send messages to this domain",
8977: exc => "Allow all, but exclude specific domains",
8978: inc => "Deny all, but include specific domains",
8979: );
1.275 raeburn 8980: }
8981:
1.138 raeburn 8982: sub build_location_hashes {
1.275 raeburn 8983: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 8984: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 8985: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 8986: my %iphost = &Apache::lonnet::get_iphost();
8987: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
8988: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
8989: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
8990: foreach my $id (@{$iphost{$primary_ip}}) {
8991: my $intdom = &Apache::lonnet::internet_dom($id);
8992: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
8993: push(@{$intdoms},$intdom);
8994: }
8995: }
8996: }
8997: foreach my $ip (keys(%iphost)) {
8998: if (ref($iphost{$ip}) eq 'ARRAY') {
8999: foreach my $id (@{$iphost{$ip}}) {
9000: my $location = &Apache::lonnet::internet_dom($id);
9001: if ($location) {
1.275 raeburn 9002: if (grep(/^\Q$location\E$/,@{$intdoms})) {
9003: my $dom = &Apache::lonnet::host_domain($id);
9004: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
9005: push(@{$instdoms},$dom);
9006: }
9007: next;
9008: }
1.138 raeburn 9009: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9010: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
9011: push(@{$by_ip->{$ip}},$location);
9012: }
9013: } else {
9014: $by_ip->{$ip} = [$location];
9015: }
9016: }
9017: }
9018: }
9019: }
9020: foreach my $ip (sort(keys(%{$by_ip}))) {
9021: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9022: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
9023: my $first = $by_ip->{$ip}->[0];
9024: if (ref($by_location->{$first}) eq 'ARRAY') {
9025: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
9026: push(@{$by_location->{$first}},$ip);
9027: }
9028: } else {
9029: $by_location->{$first} = [$ip];
9030: }
9031: }
9032: }
9033: return;
9034: }
9035:
1.145 raeburn 9036: sub current_offloads_to {
9037: my ($dom,$settings,$servers) = @_;
9038: my (%spareid,%otherdomconfigs);
1.152 raeburn 9039: if (ref($servers) eq 'HASH') {
1.145 raeburn 9040: foreach my $lonhost (sort(keys(%{$servers}))) {
9041: my $gotspares;
1.152 raeburn 9042: if (ref($settings) eq 'HASH') {
9043: if (ref($settings->{'spares'}) eq 'HASH') {
9044: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9045: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9046: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9047: $gotspares = 1;
9048: }
1.145 raeburn 9049: }
9050: }
9051: unless ($gotspares) {
9052: my $gotspares;
9053: my $serverhomeID =
9054: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9055: my $serverhomedom =
9056: &Apache::lonnet::host_domain($serverhomeID);
9057: if ($serverhomedom ne $dom) {
9058: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9059: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9060: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9061: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9062: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9063: $gotspares = 1;
9064: }
9065: }
9066: } else {
9067: $otherdomconfigs{$serverhomedom} =
9068: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9069: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9070: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9071: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9072: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9073: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9074: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9075: $gotspares = 1;
9076: }
9077: }
9078: }
9079: }
9080: }
9081: }
9082: }
9083: unless ($gotspares) {
9084: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9085: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9086: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9087: } else {
9088: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9089: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9090: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9091: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9092: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9093: } else {
1.150 raeburn 9094: my %what = (
9095: spareid => 1,
9096: );
9097: my ($result,$returnhash) =
9098: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9099: if ($result eq 'ok') {
9100: if (ref($returnhash) eq 'HASH') {
9101: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9102: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9103: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9104: }
9105: }
1.145 raeburn 9106: }
9107: }
9108: }
9109: }
9110: }
9111: }
9112: return %spareid;
9113: }
9114:
9115: sub spares_row {
1.371 raeburn 9116: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9117: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9118: my $css_class;
9119: my $numinrow = 4;
9120: my $itemcount = 1;
9121: my $datatable;
1.152 raeburn 9122: my %typetitles = &sparestype_titles();
9123: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9124: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9125: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9126: my ($othercontrol,$serverdom);
9127: if ($serverhome ne $server) {
9128: $serverdom = &Apache::lonnet::host_domain($serverhome);
9129: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9130: } else {
9131: $serverdom = &Apache::lonnet::host_domain($server);
9132: if ($serverdom ne $dom) {
9133: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9134: }
9135: }
9136: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9137: my ($checkednow,$checkedoth);
1.261 raeburn 9138: if (ref($curroffloadnow) eq 'HASH') {
9139: if ($curroffloadnow->{$server}) {
9140: $checkednow = ' checked="checked"';
9141: }
9142: }
1.371 raeburn 9143: if (ref($curroffloadoth) eq 'HASH') {
9144: if ($curroffloadoth->{$server}) {
9145: $checkedoth = ' checked="checked"';
9146: }
9147: }
1.145 raeburn 9148: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9149: $datatable .= '<tr'.$css_class.'>
9150: <td rowspan="2">
1.183 bisitz 9151: <span class="LC_nobreak">'.
9152: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9153: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9154: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9155: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9156: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9157: "\n";
1.371 raeburn 9158: if ($other_insts) {
9159: $datatable .= '<br />'.
9160: '<span class="LC_nobreak">'."\n".
9161: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9162: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9163: "\n";
9164: }
1.145 raeburn 9165: my (%current,%canselect);
1.152 raeburn 9166: my @choices =
9167: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9168: foreach my $type ('primary','default') {
9169: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9170: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9171: my @spares = @{$spareid->{$server}{$type}};
9172: if (@spares > 0) {
1.152 raeburn 9173: if ($othercontrol) {
9174: $current{$type} = join(', ',@spares);
9175: } else {
9176: $current{$type} .= '<table>';
9177: my $numspares = scalar(@spares);
9178: for (my $i=0; $i<@spares; $i++) {
9179: my $rem = $i%($numinrow);
9180: if ($rem == 0) {
9181: if ($i > 0) {
9182: $current{$type} .= '</tr>';
9183: }
9184: $current{$type} .= '<tr>';
1.145 raeburn 9185: }
1.152 raeburn 9186: $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'".');" /> '.
9187: $spareid->{$server}{$type}[$i].
9188: '</label></td>'."\n";
9189: }
9190: my $rem = @spares%($numinrow);
9191: my $colsleft = $numinrow - $rem;
9192: if ($colsleft > 1 ) {
9193: $current{$type} .= '<td colspan="'.$colsleft.
9194: '" class="LC_left_item">'.
9195: ' </td>';
9196: } elsif ($colsleft == 1) {
9197: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9198: }
1.152 raeburn 9199: $current{$type} .= '</tr></table>';
1.150 raeburn 9200: }
1.145 raeburn 9201: }
9202: }
9203: if ($current{$type} eq '') {
9204: $current{$type} = &mt('None specified');
9205: }
1.152 raeburn 9206: if ($othercontrol) {
9207: if ($type eq 'primary') {
9208: $canselect{$type} = $othercontrol;
9209: }
9210: } else {
9211: $canselect{$type} =
9212: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9213: '<select name="newspare_'.$type.'_'.$server.'" '.
9214: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9215: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9216: if (@choices > 0) {
9217: foreach my $lonhost (@choices) {
9218: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9219: }
9220: }
9221: $canselect{$type} .= '</select>'."\n";
9222: }
9223: } else {
9224: $current{$type} = &mt('Could not be determined');
9225: if ($type eq 'primary') {
9226: $canselect{$type} = $othercontrol;
9227: }
1.145 raeburn 9228: }
1.152 raeburn 9229: if ($type eq 'default') {
9230: $datatable .= '<tr'.$css_class.'>';
9231: }
9232: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9233: '<td>'.$current{$type}.'</td>'."\n".
9234: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9235: }
9236: $itemcount ++;
9237: }
9238: }
9239: $$rowtotal += $itemcount;
9240: return $datatable;
9241: }
9242:
1.152 raeburn 9243: sub possible_newspares {
9244: my ($server,$currspares,$serverhomes,$altids) = @_;
9245: my $serverhostname = &Apache::lonnet::hostname($server);
9246: my %excluded;
9247: if ($serverhostname ne '') {
9248: %excluded = (
9249: $serverhostname => 1,
9250: );
9251: }
9252: if (ref($currspares) eq 'HASH') {
9253: foreach my $type (keys(%{$currspares})) {
9254: if (ref($currspares->{$type}) eq 'ARRAY') {
9255: if (@{$currspares->{$type}} > 0) {
9256: foreach my $curr (@{$currspares->{$type}}) {
9257: my $hostname = &Apache::lonnet::hostname($curr);
9258: $excluded{$hostname} = 1;
9259: }
9260: }
9261: }
9262: }
9263: }
9264: my @choices;
9265: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9266: if (keys(%{$serverhomes}) > 1) {
9267: foreach my $name (sort(keys(%{$serverhomes}))) {
9268: unless ($excluded{$name}) {
9269: if (exists($altids->{$serverhomes->{$name}})) {
9270: push(@choices,$altids->{$serverhomes->{$name}});
9271: } else {
9272: push(@choices,$serverhomes->{$name});
1.145 raeburn 9273: }
9274: }
9275: }
9276: }
9277: }
1.152 raeburn 9278: return sort(@choices);
1.145 raeburn 9279: }
9280:
1.150 raeburn 9281: sub print_loadbalancing {
9282: my ($dom,$settings,$rowtotal) = @_;
9283: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9284: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9285: my $numinrow = 1;
9286: my $datatable;
9287: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9288: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9289: if (ref($settings) eq 'HASH') {
9290: %existing = %{$settings};
9291: }
9292: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9293: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9294: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9295: } else {
9296: return;
9297: }
9298: my ($othertitle,$usertypes,$types) =
9299: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9300: my $rownum = 8;
1.150 raeburn 9301: if (ref($types) eq 'ARRAY') {
9302: $rownum += scalar(@{$types});
9303: }
1.171 raeburn 9304: my @css_class = ('LC_odd_row','LC_even_row');
9305: my $balnum = 0;
9306: my $islast;
9307: my (@toshow,$disabledtext);
9308: if (keys(%currbalancer) > 0) {
9309: @toshow = sort(keys(%currbalancer));
9310: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9311: push(@toshow,'');
9312: }
9313: } else {
9314: @toshow = ('');
9315: $disabledtext = &mt('No existing load balancer');
9316: }
9317: foreach my $lonhost (@toshow) {
9318: if ($balnum == scalar(@toshow)-1) {
9319: $islast = 1;
9320: } else {
9321: $islast = 0;
9322: }
9323: my $cssidx = $balnum%2;
9324: my $targets_div_style = 'display: none';
9325: my $disabled_div_style = 'display: block';
9326: my $homedom_div_style = 'display: none';
9327: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9328: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9329: '<p>';
9330: if ($lonhost eq '') {
1.210 raeburn 9331: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9332: if (keys(%currbalancer) > 0) {
9333: $datatable .= &mt('Add balancer:');
9334: } else {
9335: $datatable .= &mt('Enable balancer:');
9336: }
9337: $datatable .= ' '.
9338: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9339: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9340: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9341: '<option value="" selected="selected">'.&mt('None').
9342: '</option>'."\n";
9343: foreach my $server (sort(keys(%servers))) {
9344: next if ($currbalancer{$server});
9345: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9346: }
1.210 raeburn 9347: $datatable .=
1.171 raeburn 9348: '</select>'."\n".
9349: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9350: } else {
9351: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9352: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9353: &mt('Stop balancing').'</label>'.
9354: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9355: $targets_div_style = 'display: block';
9356: $disabled_div_style = 'display: none';
9357: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9358: $homedom_div_style = 'display: block';
9359: }
9360: }
1.306 raeburn 9361: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9362: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9363: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9364: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9365: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9366: my @sparestypes = ('primary','default');
9367: my %typetitles = &sparestype_titles();
1.284 raeburn 9368: my %hostherechecked = (
9369: no => ' checked="checked"',
9370: );
1.342 raeburn 9371: my %balcookiechecked = (
1.425 raeburn 9372: no => ' checked="checked"',
1.342 raeburn 9373: );
1.171 raeburn 9374: foreach my $sparetype (@sparestypes) {
9375: my $targettable;
9376: for (my $i=0; $i<$numspares; $i++) {
9377: my $checked;
9378: if (ref($currtargets{$lonhost}) eq 'HASH') {
9379: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9380: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9381: $checked = ' checked="checked"';
9382: }
9383: }
9384: }
9385: my ($chkboxval,$disabled);
9386: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9387: $chkboxval = $spares[$i];
9388: }
9389: if (exists($currbalancer{$spares[$i]})) {
9390: $disabled = ' disabled="disabled"';
9391: }
1.210 raeburn 9392: $targettable .=
1.253 raeburn 9393: '<td><span class="LC_nobreak"><label>'.
9394: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9395: $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 9396: '</span></label></span></td>';
1.171 raeburn 9397: my $rem = $i%($numinrow);
9398: if ($rem == 0) {
9399: if (($i > 0) && ($i < $numspares-1)) {
9400: $targettable .= '</tr>';
9401: }
9402: if ($i < $numspares-1) {
9403: $targettable .= '<tr>';
1.150 raeburn 9404: }
9405: }
9406: }
1.171 raeburn 9407: if ($targettable ne '') {
9408: my $rem = $numspares%($numinrow);
9409: my $colsleft = $numinrow - $rem;
9410: if ($colsleft > 1 ) {
9411: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9412: ' </td>';
9413: } elsif ($colsleft == 1) {
9414: $targettable .= '<td class="LC_left_item"> </td>';
9415: }
9416: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9417: '<table><tr>'.$targettable.'</tr></table><br />';
9418: }
1.284 raeburn 9419: $hostherechecked{$sparetype} = '';
9420: if (ref($currtargets{$lonhost}) eq 'HASH') {
9421: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9422: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9423: $hostherechecked{$sparetype} = ' checked="checked"';
9424: $hostherechecked{'no'} = '';
9425: }
9426: }
9427: }
9428: }
1.342 raeburn 9429: if ($currcookies{$lonhost}) {
9430: %balcookiechecked = (
9431: yes => ' checked="checked"',
9432: );
9433: }
1.284 raeburn 9434: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9435: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9436: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9437: foreach my $sparetype (@sparestypes) {
9438: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9439: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9440: '</i></label><br />';
1.171 raeburn 9441: }
1.342 raeburn 9442: $datatable .= &mt('Use balancer cookie').'<br />'.
9443: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9444: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9445: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9446: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9447: '</div></td></tr>'.
1.171 raeburn 9448: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9449: $othertitle,$usertypes,$types,\%servers,
9450: \%currbalancer,$lonhost,
9451: $targets_div_style,$homedom_div_style,
9452: $css_class[$cssidx],$balnum,$islast);
9453: $$rowtotal += $rownum;
9454: $balnum ++;
9455: }
9456: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9457: return $datatable;
9458: }
9459:
9460: sub get_loadbalancers_config {
1.342 raeburn 9461: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9462: return unless ((ref($servers) eq 'HASH') &&
9463: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9464: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9465: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9466: if (keys(%{$existing}) > 0) {
9467: my $oldlonhost;
9468: foreach my $key (sort(keys(%{$existing}))) {
9469: if ($key eq 'lonhost') {
9470: $oldlonhost = $existing->{'lonhost'};
9471: $currbalancer->{$oldlonhost} = 1;
9472: } elsif ($key eq 'targets') {
9473: if ($oldlonhost) {
9474: $currtargets->{$oldlonhost} = $existing->{'targets'};
9475: }
9476: } elsif ($key eq 'rules') {
9477: if ($oldlonhost) {
9478: $currrules->{$oldlonhost} = $existing->{'rules'};
9479: }
9480: } elsif (ref($existing->{$key}) eq 'HASH') {
9481: $currbalancer->{$key} = 1;
9482: $currtargets->{$key} = $existing->{$key}{'targets'};
9483: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9484: if ($existing->{$key}{'cookie'}) {
9485: $currcookies->{$key} = 1;
9486: }
1.150 raeburn 9487: }
9488: }
1.171 raeburn 9489: } else {
9490: my ($balancerref,$targetsref) =
9491: &Apache::lonnet::get_lonbalancer_config($servers);
9492: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9493: foreach my $server (sort(keys(%{$balancerref}))) {
9494: $currbalancer->{$server} = 1;
9495: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9496: }
9497: }
9498: }
1.171 raeburn 9499: return;
1.150 raeburn 9500: }
9501:
9502: sub loadbalancing_rules {
9503: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9504: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9505: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9506: my $output;
1.171 raeburn 9507: my $num = 0;
1.210 raeburn 9508: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9509: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9510: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9511: foreach my $type (@{$alltypes}) {
1.171 raeburn 9512: $num ++;
1.150 raeburn 9513: my $current;
9514: if (ref($currrules) eq 'HASH') {
9515: $current = $currrules->{$type};
9516: }
1.253 raeburn 9517: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9518: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9519: $current = '';
9520: }
9521: }
9522: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9523: $servers,$currbalancer,$lonhost,$dom,
9524: $targets_div_style,$homedom_div_style,
9525: $css_class,$balnum,$num,$islast);
1.150 raeburn 9526: }
9527: }
9528: return $output;
9529: }
9530:
9531: sub loadbalancing_titles {
9532: my ($dom,$intdom,$usertypes,$types) = @_;
9533: my %othertypes = (
9534: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9535: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9536: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9537: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9538: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9539: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9540: );
1.209 raeburn 9541: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9542: my @available;
1.150 raeburn 9543: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9544: @available = @{$types};
1.150 raeburn 9545: }
1.302 raeburn 9546: unless (grep(/^default$/,@available)) {
9547: push(@available,'default');
9548: }
9549: unshift(@alltypes,@available);
1.150 raeburn 9550: my %titles;
9551: foreach my $type (@alltypes) {
9552: if ($type =~ /^_LC_/) {
9553: $titles{$type} = $othertypes{$type};
9554: } elsif ($type eq 'default') {
9555: $titles{$type} = &mt('All users from [_1]',$dom);
9556: if (ref($types) eq 'ARRAY') {
9557: if (@{$types} > 0) {
9558: $titles{$type} = &mt('Other users from [_1]',$dom);
9559: }
9560: }
9561: } elsif (ref($usertypes) eq 'HASH') {
9562: $titles{$type} = $usertypes->{$type};
9563: }
9564: }
9565: return (\@alltypes,\%othertypes,\%titles);
9566: }
9567:
9568: sub loadbalance_rule_row {
1.171 raeburn 9569: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9570: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9571: my @rulenames;
1.150 raeburn 9572: my %ruletitles = &offloadtype_text();
1.209 raeburn 9573: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9574: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9575: } else {
1.209 raeburn 9576: @rulenames = ('default','homeserver');
9577: if ($type eq '_LC_external') {
9578: push(@rulenames,'externalbalancer');
9579: } else {
9580: push(@rulenames,'specific');
9581: }
9582: push(@rulenames,'none');
1.150 raeburn 9583: }
9584: my $style = $targets_div_style;
1.253 raeburn 9585: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9586: $style = $homedom_div_style;
9587: }
1.171 raeburn 9588: my $space;
9589: if ($islast && $num == 1) {
1.317 raeburn 9590: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9591: }
1.210 raeburn 9592: my $output =
1.306 raeburn 9593: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9594: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9595: '<td valaign="top">'.$space.
9596: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9597: for (my $i=0; $i<@rulenames; $i++) {
9598: my $rule = $rulenames[$i];
9599: my ($checked,$extra);
9600: if ($rulenames[$i] eq 'default') {
9601: $rule = '';
9602: }
9603: if ($rulenames[$i] eq 'specific') {
9604: if (ref($servers) eq 'HASH') {
9605: my $default;
9606: if (($current ne '') && (exists($servers->{$current}))) {
9607: $checked = ' checked="checked"';
9608: }
9609: unless ($checked) {
9610: $default = ' selected="selected"';
9611: }
1.210 raeburn 9612: $extra =
1.171 raeburn 9613: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9614: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9615: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9616: '<option value=""'.$default.'></option>'."\n";
9617: foreach my $server (sort(keys(%{$servers}))) {
9618: if (ref($currbalancer) eq 'HASH') {
9619: next if (exists($currbalancer->{$server}));
9620: }
1.150 raeburn 9621: my $selected;
1.171 raeburn 9622: if ($server eq $current) {
1.150 raeburn 9623: $selected = ' selected="selected"';
9624: }
1.171 raeburn 9625: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9626: }
9627: $extra .= '</select>';
9628: }
9629: } elsif ($rule eq $current) {
9630: $checked = ' checked="checked"';
9631: }
9632: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9633: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9634: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9635: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9636: ')"'.$checked.' /> ';
9637: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9638: $output .= $ruletitles{'particular'};
9639: } else {
9640: $output .= $ruletitles{$rulenames[$i]};
9641: }
9642: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9643: }
9644: $output .= '</div></td></tr>'."\n";
9645: return $output;
9646: }
9647:
9648: sub offloadtype_text {
9649: my %ruletitles = &Apache::lonlocal::texthash (
9650: 'default' => 'Offloads to default destinations',
9651: 'homeserver' => "Offloads to user's home server",
9652: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9653: 'specific' => 'Offloads to specific server',
1.161 raeburn 9654: 'none' => 'No offload',
1.209 raeburn 9655: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9656: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9657: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9658: );
9659: return %ruletitles;
9660: }
9661:
9662: sub sparestype_titles {
9663: my %typestitles = &Apache::lonlocal::texthash (
9664: 'primary' => 'primary',
9665: 'default' => 'default',
9666: );
9667: return %typestitles;
9668: }
9669:
1.28 raeburn 9670: sub contact_titles {
9671: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9672: 'supportemail' => 'Support E-mail address',
9673: 'adminemail' => 'Default Server Admin E-mail address',
9674: 'errormail' => 'Error reports to be e-mailed to',
9675: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9676: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9677: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9678: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9679: 'requestsmail' => 'E-mail from course requests requiring approval',
9680: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9681: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9682: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9683: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9684: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9685: 'errorweights' => 'Weights used to compute error count',
9686: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9687: );
9688: my %short_titles = &Apache::lonlocal::texthash (
9689: adminemail => 'Admin E-mail address',
9690: supportemail => 'Support E-mail',
9691: );
9692: return (\%titles,\%short_titles);
9693: }
9694:
1.286 raeburn 9695: sub helpform_fields {
9696: my %titles = &Apache::lonlocal::texthash (
9697: 'username' => 'Name',
9698: 'user' => 'Username/domain',
9699: 'phone' => 'Phone',
9700: 'cc' => 'Cc e-mail',
9701: 'course' => 'Course Details',
9702: 'section' => 'Sections',
1.289 raeburn 9703: 'screenshot' => 'File upload',
1.286 raeburn 9704: );
9705: my @fields = ('username','phone','user','course','section','cc','screenshot');
9706: my %possoptions = (
9707: username => ['yes','no','req'],
1.289 raeburn 9708: phone => ['yes','no','req'],
1.286 raeburn 9709: user => ['yes','no'],
1.289 raeburn 9710: cc => ['yes','no'],
1.286 raeburn 9711: course => ['yes','no'],
9712: section => ['yes','no'],
9713: screenshot => ['yes','no'],
9714: );
9715: my %fieldoptions = &Apache::lonlocal::texthash (
9716: 'yes' => 'Optional',
9717: 'req' => 'Required',
9718: 'no' => "Not shown",
9719: );
9720: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9721: }
9722:
1.72 raeburn 9723: sub tool_titles {
9724: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9725: aboutme => 'Personal web page',
1.86 raeburn 9726: blog => 'Blog',
9727: portfolio => 'Portfolio',
1.430 raeburn 9728: portaccess => 'Share portfolio files',
1.413 raeburn 9729: timezone => 'Can set time zone',
1.88 bisitz 9730: official => 'Official courses (with institutional codes)',
9731: unofficial => 'Unofficial courses',
1.98 raeburn 9732: community => 'Communities',
1.216 raeburn 9733: textbook => 'Textbook courses',
1.271 raeburn 9734: placement => 'Placement tests',
1.86 raeburn 9735: );
1.72 raeburn 9736: return %titles;
9737: }
9738:
1.101 raeburn 9739: sub courserequest_titles {
9740: my %titles = &Apache::lonlocal::texthash (
9741: official => 'Official',
9742: unofficial => 'Unofficial',
9743: community => 'Communities',
1.216 raeburn 9744: textbook => 'Textbook',
1.271 raeburn 9745: placement => 'Placement tests',
1.325 raeburn 9746: lti => 'LTI Provider',
1.101 raeburn 9747: norequest => 'Not allowed',
1.325 raeburn 9748: approval => 'Approval by DC',
1.101 raeburn 9749: validate => 'With validation',
9750: autolimit => 'Numerical limit',
1.103 raeburn 9751: unlimited => '(blank for unlimited)',
1.101 raeburn 9752: );
9753: return %titles;
9754: }
9755:
1.163 raeburn 9756: sub authorrequest_titles {
9757: my %titles = &Apache::lonlocal::texthash (
9758: norequest => 'Not allowed',
9759: approval => 'Approval by Dom. Coord.',
9760: automatic => 'Automatic approval',
9761: );
9762: return %titles;
1.210 raeburn 9763: }
1.163 raeburn 9764:
1.101 raeburn 9765: sub courserequest_conditions {
9766: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9767: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9768: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9769: );
9770: return %conditions;
9771: }
9772:
9773:
1.27 raeburn 9774: sub print_usercreation {
1.30 raeburn 9775: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9776: my $numinrow = 4;
1.28 raeburn 9777: my $datatable;
9778: if ($position eq 'top') {
1.30 raeburn 9779: $$rowtotal ++;
1.34 raeburn 9780: my $rowcount = 0;
1.32 raeburn 9781: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9782: if (ref($rules) eq 'HASH') {
9783: if (keys(%{$rules}) > 0) {
1.32 raeburn 9784: $datatable .= &user_formats_row('username',$settings,$rules,
9785: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9786: $$rowtotal ++;
1.32 raeburn 9787: $rowcount ++;
9788: }
9789: }
9790: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9791: if (ref($idrules) eq 'HASH') {
9792: if (keys(%{$idrules}) > 0) {
9793: $datatable .= &user_formats_row('id',$settings,$idrules,
9794: $idruleorder,$numinrow,$rowcount);
9795: $$rowtotal ++;
9796: $rowcount ++;
1.28 raeburn 9797: }
9798: }
1.39 raeburn 9799: if ($rowcount == 0) {
9800: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9801: $$rowtotal ++;
9802: $rowcount ++;
9803: }
1.34 raeburn 9804: } elsif ($position eq 'middle') {
1.224 raeburn 9805: my @creators = ('author','course','requestcrs');
1.37 raeburn 9806: my ($rules,$ruleorder) =
9807: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9808: my %lt = &usercreation_types();
9809: my %checked;
9810: if (ref($settings) eq 'HASH') {
9811: if (ref($settings->{'cancreate'}) eq 'HASH') {
9812: foreach my $item (@creators) {
9813: $checked{$item} = $settings->{'cancreate'}{$item};
9814: }
9815: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9816: foreach my $item (@creators) {
9817: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9818: $checked{$item} = 'none';
9819: }
9820: }
9821: }
9822: }
9823: my $rownum = 0;
9824: foreach my $item (@creators) {
9825: $rownum ++;
1.224 raeburn 9826: if ($checked{$item} eq '') {
9827: $checked{$item} = 'any';
1.34 raeburn 9828: }
9829: my $css_class;
9830: if ($rownum%2) {
9831: $css_class = '';
9832: } else {
9833: $css_class = ' class="LC_odd_row" ';
9834: }
9835: $datatable .= '<tr'.$css_class.'>'.
9836: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9837: '</span></td><td style="text-align: right">';
1.224 raeburn 9838: my @options = ('any');
9839: if (ref($rules) eq 'HASH') {
9840: if (keys(%{$rules}) > 0) {
9841: push(@options,('official','unofficial'));
1.37 raeburn 9842: }
9843: }
1.224 raeburn 9844: push(@options,'none');
1.37 raeburn 9845: foreach my $option (@options) {
1.50 raeburn 9846: my $type = 'radio';
1.34 raeburn 9847: my $check = ' ';
1.224 raeburn 9848: if ($checked{$item} eq $option) {
9849: $check = ' checked="checked" ';
1.34 raeburn 9850: }
9851: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9852: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9853: $item.'" value="'.$option.'"'.$check.'/> '.
9854: $lt{$option}.'</label> </span>';
9855: }
9856: $datatable .= '</td></tr>';
9857: }
1.28 raeburn 9858: } else {
9859: my @contexts = ('author','course','domain');
1.325 raeburn 9860: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9861: my %checked;
9862: if (ref($settings) eq 'HASH') {
9863: if (ref($settings->{'authtypes'}) eq 'HASH') {
9864: foreach my $item (@contexts) {
9865: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9866: foreach my $auth (@authtypes) {
9867: if ($settings->{'authtypes'}{$item}{$auth}) {
9868: $checked{$item}{$auth} = ' checked="checked" ';
9869: }
9870: }
9871: }
9872: }
1.27 raeburn 9873: }
1.35 raeburn 9874: } else {
9875: foreach my $item (@contexts) {
1.36 raeburn 9876: foreach my $auth (@authtypes) {
1.35 raeburn 9877: $checked{$item}{$auth} = ' checked="checked" ';
9878: }
9879: }
1.27 raeburn 9880: }
1.28 raeburn 9881: my %title = &context_names();
9882: my %authname = &authtype_names();
9883: my $rownum = 0;
9884: my $css_class;
9885: foreach my $item (@contexts) {
9886: if ($rownum%2) {
9887: $css_class = '';
9888: } else {
9889: $css_class = ' class="LC_odd_row" ';
9890: }
1.30 raeburn 9891: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9892: '<td>'.$title{$item}.
9893: '</td><td class="LC_left_item">'.
9894: '<span class="LC_nobreak">';
9895: foreach my $auth (@authtypes) {
9896: $datatable .= '<label>'.
9897: '<input type="checkbox" name="'.$item.'_auth" '.
9898: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9899: $authname{$auth}.'</label> ';
9900: }
9901: $datatable .= '</span></td></tr>';
9902: $rownum ++;
1.27 raeburn 9903: }
1.30 raeburn 9904: $$rowtotal += $rownum;
1.27 raeburn 9905: }
9906: return $datatable;
9907: }
9908:
1.224 raeburn 9909: sub print_selfcreation {
9910: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9911: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9912: $emaildomain,$datatable);
1.224 raeburn 9913: if (ref($settings) eq 'HASH') {
9914: if (ref($settings->{'cancreate'}) eq 'HASH') {
9915: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9916: if (ref($createsettings) eq 'HASH') {
9917: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9918: @selfcreate = @{$createsettings->{'selfcreate'}};
9919: } elsif ($createsettings->{'selfcreate'} ne '') {
9920: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9921: @selfcreate = ('email','login','sso');
9922: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9923: @selfcreate = ($createsettings->{'selfcreate'});
9924: }
9925: }
9926: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9927: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9928: }
1.305 raeburn 9929: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9930: $emailoptions = $createsettings->{'emailoptions'};
9931: }
1.303 raeburn 9932: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9933: $emailverified = $createsettings->{'emailverified'};
9934: }
9935: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9936: $emaildomain = $createsettings->{'emaildomain'};
9937: }
1.224 raeburn 9938: }
9939: }
9940: }
9941: my %radiohash;
9942: my $numinrow = 4;
9943: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9944: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9945: if ($position eq 'top') {
9946: my %choices = &Apache::lonlocal::texthash (
9947: cancreate_login => 'Institutional Login',
9948: cancreate_sso => 'Institutional Single Sign On',
9949: );
9950: my @toggles = sort(keys(%choices));
9951: my %defaultchecked = (
9952: 'cancreate_login' => 'off',
9953: 'cancreate_sso' => 'off',
9954: );
1.228 raeburn 9955: my ($onclick,$itemcount);
1.224 raeburn 9956: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9957: \%choices,$itemcount,$onclick);
1.228 raeburn 9958: $$rowtotal += $itemcount;
1.425 raeburn 9959:
1.224 raeburn 9960: if (ref($usertypes) eq 'HASH') {
9961: if (keys(%{$usertypes}) > 0) {
9962: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9963: $dom,$numinrow,$othertitle,
1.305 raeburn 9964: 'statustocreate',$rowtotal);
1.224 raeburn 9965: $$rowtotal ++;
9966: }
9967: }
1.240 raeburn 9968: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
9969: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9970: $fieldtitles{'inststatus'} = &mt('Institutional status');
9971: my $rem;
9972: my $numperrow = 2;
9973: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
9974: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 9975: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 9976: '<td class="LC_left_item">'."\n".
1.334 raeburn 9977: '<table>'."\n";
1.240 raeburn 9978: for (my $i=0; $i<@fields; $i++) {
9979: $rem = $i%($numperrow);
9980: if ($rem == 0) {
9981: if ($i > 0) {
9982: $datatable .= '</tr>';
9983: }
9984: $datatable .= '<tr>';
9985: }
9986: my $currval;
1.248 raeburn 9987: if (ref($createsettings) eq 'HASH') {
9988: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
9989: $currval = $createsettings->{'shibenv'}{$fields[$i]};
9990: }
1.240 raeburn 9991: }
9992: $datatable .= '<td class="LC_left_item">'.
9993: '<span class="LC_nobreak">'.
9994: '<input type="text" name="shibenv_'.$fields[$i].'" '.
9995: 'value="'.$currval.'" size="10" /> '.
9996: $fieldtitles{$fields[$i]}.'</span></td>';
9997: }
9998: my $colsleft = $numperrow - $rem;
9999: if ($colsleft > 1 ) {
10000: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10001: ' </td>';
10002: } elsif ($colsleft == 1) {
10003: $datatable .= '<td class="LC_left_item"> </td>';
10004: }
10005: $datatable .= '</tr></table></td></tr>';
10006: $$rowtotal ++;
1.224 raeburn 10007: } elsif ($position eq 'middle') {
10008: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 10009: my @posstypes;
1.224 raeburn 10010: if (ref($types) eq 'ARRAY') {
1.302 raeburn 10011: @posstypes = @{$types};
10012: }
10013: unless (grep(/^default$/,@posstypes)) {
10014: push(@posstypes,'default');
10015: }
10016: my %usertypeshash;
10017: if (ref($usertypes) eq 'HASH') {
10018: %usertypeshash = %{$usertypes};
10019: }
10020: $usertypeshash{'default'} = $othertitle;
10021: foreach my $status (@posstypes) {
10022: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
10023: $numinrow,$$rowtotal,\%usertypeshash);
10024: $$rowtotal ++;
1.224 raeburn 10025: }
10026: } else {
1.236 raeburn 10027: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 10028: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 10029: );
10030: my @toggles = sort(keys(%choices));
10031: my %defaultchecked = (
10032: 'cancreate_email' => 'off',
10033: );
1.305 raeburn 10034: my $customclass = 'LC_selfcreate_email';
10035: my $classprefix = 'LC_canmodify_emailusername_';
10036: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10037: my $display = 'none';
1.305 raeburn 10038: my $rowstyle = 'display:none';
1.236 raeburn 10039: if (grep(/^\Qemail\E$/,@selfcreate)) {
10040: $display = 'block';
1.305 raeburn 10041: $rowstyle = 'display:table-row';
1.236 raeburn 10042: }
1.305 raeburn 10043: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10044: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10045: \%choices,$$rowtotal,$onclick);
10046: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10047: $rowstyle);
10048: $$rowtotal ++;
10049: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10050: $rowstyle);
10051: $$rowtotal ++;
10052: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10053: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10054: my ($emailrules,$emailruleorder) =
10055: &Apache::lonnet::inst_userrules($dom,'email');
10056: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10057: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10058: if (ref($types) eq 'ARRAY') {
10059: @posstypes = @{$types};
10060: }
10061: if (@posstypes) {
10062: unless (grep(/^default$/,@posstypes)) {
10063: push(@posstypes,'default');
1.302 raeburn 10064: }
10065: if (ref($usertypes) eq 'HASH') {
10066: %usertypeshash = %{$usertypes};
10067: }
1.305 raeburn 10068: my $currassign;
10069: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10070: $currassign = {
10071: selfassign => $domdefaults{'inststatusguest'},
10072: };
10073: @ordered = @{$domdefaults{'inststatusguest'}};
10074: } else {
10075: $currassign = { selfassign => [] };
10076: }
10077: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10078: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10079: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10080: $numinrow,$othertitle,'selfassign',
10081: $rowtotal,$onclicktypes,$customclass,
10082: $rowstyle);
10083: $$rowtotal ++;
1.302 raeburn 10084: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10085: foreach my $status (@posstypes) {
10086: my $css_class;
10087: if ($$rowtotal%2) {
10088: $css_class = 'LC_odd_row ';
10089: }
10090: $css_class .= $customclass;
10091: my $rowid = $optionsprefix.$status;
10092: my $hidden = 1;
10093: my $currstyle = 'display:none';
10094: if (grep(/^\Q$status\E$/,@ordered)) {
10095: $currstyle = $rowstyle;
1.425 raeburn 10096: $hidden = 0;
1.305 raeburn 10097: }
10098: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10099: $emailrules,$emailruleorder,$settings,$status,$rowid,
10100: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10101: unless ($hidden) {
10102: $$rowtotal ++;
10103: }
1.224 raeburn 10104: }
1.302 raeburn 10105: } else {
1.305 raeburn 10106: my $css_class;
10107: if ($$rowtotal%2) {
10108: $css_class = 'LC_odd_row ';
10109: }
10110: $css_class .= $customclass;
1.302 raeburn 10111: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10112: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10113: $emailrules,$emailruleorder,$settings,'default','',
10114: $othertitle,$css_class,$rowstyle,$intdom);
10115: $$rowtotal ++;
1.224 raeburn 10116: }
10117: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10118: $numinrow = 1;
1.305 raeburn 10119: if (@posstypes) {
10120: foreach my $status (@posstypes) {
10121: my $rowid = $classprefix.$status;
10122: my $datarowstyle = 'display:none';
1.425 raeburn 10123: if (grep(/^\Q$status\E$/,@ordered)) {
10124: $datarowstyle = $rowstyle;
1.305 raeburn 10125: }
10126: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10127: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10128: $infotitles,$rowid,$customclass,$datarowstyle);
10129: unless ($datarowstyle eq 'display:none') {
10130: $$rowtotal ++;
10131: }
1.224 raeburn 10132: }
1.305 raeburn 10133: } else {
10134: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10135: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10136: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10137: }
10138: }
10139: return $datatable;
10140: }
10141:
1.305 raeburn 10142: sub selfcreate_javascript {
10143: return <<"ENDSCRIPT";
10144:
10145: <script type="text/javascript">
10146: // <![CDATA[
10147:
10148: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10149: var x = document.getElementsByClassName(target);
10150: var insttypes = 0;
10151: var insttypeRegExp = new RegExp(prefix);
10152: if ((x.length != undefined) && (x.length > 0)) {
10153: if (form.elements[radio].length != undefined) {
10154: for (var i=0; i<form.elements[radio].length; i++) {
10155: if (form.elements[radio][i].checked) {
10156: if (form.elements[radio][i].value == 1) {
10157: for (var j=0; j<x.length; j++) {
10158: if (x[j].id == 'undefined') {
10159: x[j].style.display = 'table-row';
10160: } else if (insttypeRegExp.test(x[j].id)) {
10161: insttypes ++;
10162: } else {
10163: x[j].style.display = 'table-row';
10164: }
10165: }
10166: } else {
10167: for (var j=0; j<x.length; j++) {
10168: x[j].style.display = 'none';
10169: }
1.236 raeburn 10170: }
1.305 raeburn 10171: break;
10172: }
10173: }
10174: if (insttypes > 0) {
10175: toggleDataRow(form,checkbox,target,altprefix);
10176: toggleDataRow(form,checkbox,target,prefix,1);
10177: }
10178: }
10179: }
10180: return;
10181: }
10182:
10183: function toggleDataRow(form,checkbox,target,prefix,docount) {
10184: if (form.elements[checkbox].length != undefined) {
10185: var count = 0;
10186: if (docount) {
10187: for (var i=0; i<form.elements[checkbox].length; i++) {
10188: if (form.elements[checkbox][i].checked) {
10189: count ++;
1.236 raeburn 10190: }
1.305 raeburn 10191: }
10192: }
10193: for (var i=0; i<form.elements[checkbox].length; i++) {
10194: var type = form.elements[checkbox][i].value;
10195: if (document.getElementById(prefix+type)) {
10196: if (form.elements[checkbox][i].checked) {
10197: document.getElementById(prefix+type).style.display = 'table-row';
10198: if (count % 2 == 1) {
10199: document.getElementById(prefix+type).className = target+' LC_odd_row';
10200: } else {
10201: document.getElementById(prefix+type).className = target;
1.236 raeburn 10202: }
1.305 raeburn 10203: count ++;
1.236 raeburn 10204: } else {
1.305 raeburn 10205: document.getElementById(prefix+type).style.display = 'none';
10206: }
10207: }
10208: }
10209: }
10210: return;
10211: }
10212:
10213: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10214: var caller = radio+'_'+status;
10215: if (form.elements[caller].length != undefined) {
10216: for (var i=0; i<form.elements[caller].length; i++) {
10217: if (form.elements[caller][i].checked) {
10218: if (document.getElementById(altprefix+'_inst_'+status)) {
10219: var curr = form.elements[caller][i].value;
10220: if (prefix) {
10221: document.getElementById(prefix+'_'+status).style.display = 'none';
10222: }
10223: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10224: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10225: if (curr == 'custom') {
1.425 raeburn 10226: if (prefix) {
1.305 raeburn 10227: document.getElementById(prefix+'_'+status).style.display = 'inline';
10228: }
10229: } else if (curr == 'inst') {
10230: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10231: } else if (curr == 'noninst') {
10232: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10233: }
1.305 raeburn 10234: break;
1.236 raeburn 10235: }
10236: }
10237: }
10238: }
10239: }
10240:
1.305 raeburn 10241: // ]]>
10242: </script>
10243:
10244: ENDSCRIPT
10245: }
10246:
10247: sub noninst_users {
10248: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10249: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10250: my $class = 'LC_left_item';
10251: if ($css_class) {
1.425 raeburn 10252: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10253: }
10254: if ($rowid) {
10255: $rowid = ' id="'.$rowid.'"';
10256: }
10257: if ($rowstyle) {
10258: $rowstyle = ' style="'.$rowstyle.'"';
10259: }
10260: my ($output,$description);
10261: if ($type eq 'default') {
10262: $description = &mt('Requests for: [_1]',$typetitle);
10263: } else {
10264: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10265: }
10266: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10267: "<td>$description</td>\n".
1.305 raeburn 10268: '<td class="'.$class.'" colspan="2">'.
10269: '<table><tr>';
1.425 raeburn 10270: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10271: approve => 'Processing',
10272: email => 'E-mail',
10273: username => 'Username',
10274: );
10275: foreach my $item ('approve','email','username') {
10276: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10277: }
1.305 raeburn 10278: $output .= '</tr><tr>';
10279: foreach my $item ('approve','email','username') {
1.306 raeburn 10280: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10281: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10282: if ($item eq 'approve') {
10283: %choices = &Apache::lonlocal::texthash (
10284: automatic => 'Automatically approved',
10285: approval => 'Queued for approval',
10286: );
10287: @options = ('automatic','approval');
10288: $hashref = $processing;
10289: $defoption = 'automatic';
10290: $name = 'cancreate_emailprocess_'.$type;
10291: } elsif ($item eq 'email') {
10292: %choices = &Apache::lonlocal::texthash (
10293: any => 'Any e-mail',
10294: inst => 'Institutional only',
10295: noninst => 'Non-institutional only',
10296: custom => 'Custom restrictions',
10297: );
10298: @options = ('any','inst','noninst');
10299: my $showcustom;
10300: if (ref($emailrules) eq 'HASH') {
10301: if (keys(%{$emailrules}) > 0) {
10302: push(@options,'custom');
10303: $showcustom = 'cancreate_emailrule';
10304: if (ref($settings) eq 'HASH') {
10305: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10306: foreach my $rule (@{$settings->{'email_rule'}}) {
10307: if (exists($emailrules->{$rule})) {
10308: $hascustom ++;
10309: }
10310: }
10311: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10312: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10313: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10314: if (exists($emailrules->{$rule})) {
10315: $hascustom ++;
10316: }
10317: }
10318: }
10319: }
10320: }
10321: }
10322: }
10323: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10324: "'cancreate_emaildomain','$type'".');"';
10325: $hashref = $emailoptions;
10326: $defoption = 'any';
10327: $name = 'cancreate_emailoptions_'.$type;
10328: } elsif ($item eq 'username') {
10329: %choices = &Apache::lonlocal::texthash (
10330: all => 'Same as e-mail',
10331: first => 'Omit @domain',
10332: free => 'Free to choose',
10333: );
10334: @options = ('all','first','free');
10335: $hashref = $emailverified;
10336: $defoption = 'all';
10337: $name = 'cancreate_usernameoptions_'.$type;
10338: }
10339: foreach my $option (@options) {
10340: my $checked;
10341: if (ref($hashref) eq 'HASH') {
10342: if ($type eq '') {
10343: if (!exists($hashref->{'default'})) {
10344: if ($option eq $defoption) {
10345: $checked = ' checked="checked"';
10346: }
10347: } else {
10348: if ($hashref->{'default'} eq $option) {
10349: $checked = ' checked="checked"';
10350: }
1.303 raeburn 10351: }
10352: } else {
1.305 raeburn 10353: if (!exists($hashref->{$type})) {
10354: if ($option eq $defoption) {
10355: $checked = ' checked="checked"';
10356: }
10357: } else {
10358: if ($hashref->{$type} eq $option) {
10359: $checked = ' checked="checked"';
10360: }
1.303 raeburn 10361: }
10362: }
1.305 raeburn 10363: } elsif (($item eq 'email') && ($hascustom)) {
10364: if ($option eq 'custom') {
10365: $checked = ' checked="checked"';
10366: }
10367: } elsif ($option eq $defoption) {
10368: $checked = ' checked="checked"';
10369: }
10370: $output .= '<span class="LC_nobreak"><label>'.
10371: '<input type="radio" name="'.$name.'"'.
10372: $checked.' value="'.$option.'"'.$onclick.' />'.
10373: $choices{$option}.'</label></span><br />';
10374: if ($item eq 'email') {
10375: if ($option eq 'custom') {
10376: my $id = 'cancreate_emailrule_'.$type;
10377: my $display = 'none';
10378: if ($checked) {
10379: $display = 'inline';
1.303 raeburn 10380: }
1.305 raeburn 10381: my $numinrow = 2;
10382: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10383: '<legend>'.&mt('Disallow').'</legend><table>'.
10384: &user_formats_row('email',$settings,$emailrules,
10385: $emailruleorder,$numinrow,'',$type);
10386: '</table></fieldset>';
10387: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10388: my %text = &Apache::lonlocal::texthash (
10389: inst => 'must end:',
10390: noninst => 'cannot end:',
10391: );
10392: my $value;
10393: if (ref($emaildomain) eq 'HASH') {
10394: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10395: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10396: }
10397: }
1.305 raeburn 10398: if ($value eq '') {
10399: $value = '@'.$intdom;
10400: }
10401: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10402: my $display = 'none';
10403: if ($checked) {
10404: $display = 'inline';
10405: }
10406: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10407: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10408: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10409: '</div>';
1.303 raeburn 10410: }
10411: }
10412: }
1.305 raeburn 10413: $output .= '</td>'."\n";
1.303 raeburn 10414: }
1.305 raeburn 10415: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10416: return $output;
10417: }
10418:
1.165 raeburn 10419: sub captcha_choice {
1.305 raeburn 10420: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10421: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10422: $vertext,$currver);
1.165 raeburn 10423: my %lt = &captcha_phrases();
10424: $keyentry = 'hidden';
1.354 raeburn 10425: my $colspan=2;
1.165 raeburn 10426: if ($context eq 'cancreate') {
1.224 raeburn 10427: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10428: } elsif ($context eq 'login') {
10429: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10430: } elsif ($context eq 'passwords') {
10431: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10432: $colspan=1;
1.165 raeburn 10433: }
10434: if (ref($settings) eq 'HASH') {
10435: if ($settings->{'captcha'}) {
10436: $checked{$settings->{'captcha'}} = ' checked="checked"';
10437: } else {
10438: $checked{'original'} = ' checked="checked"';
10439: }
10440: if ($settings->{'captcha'} eq 'recaptcha') {
10441: $pubtext = $lt{'pub'};
10442: $privtext = $lt{'priv'};
10443: $keyentry = 'text';
1.269 raeburn 10444: $vertext = $lt{'ver'};
10445: $currver = $settings->{'recaptchaversion'};
10446: if ($currver ne '2') {
10447: $currver = 1;
10448: }
1.165 raeburn 10449: }
10450: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10451: $currpub = $settings->{'recaptchakeys'}{'public'};
10452: $currpriv = $settings->{'recaptchakeys'}{'private'};
10453: }
10454: } else {
10455: $checked{'original'} = ' checked="checked"';
10456: }
1.305 raeburn 10457: my $css_class;
10458: if ($itemcount%2) {
10459: $css_class = 'LC_odd_row';
10460: }
10461: if ($customcss) {
10462: $css_class .= " $customcss";
10463: }
10464: $css_class =~ s/^\s+//;
10465: if ($css_class) {
10466: $css_class = ' class="'.$css_class.'"';
10467: }
10468: if ($rowstyle) {
10469: $css_class .= ' style="'.$rowstyle.'"';
10470: }
1.169 raeburn 10471: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10472: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10473: '<table><tr><td>'."\n";
10474: foreach my $option ('original','recaptcha','notused') {
10475: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10476: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10477: $lt{$option}.'</label></span>';
10478: unless ($option eq 'notused') {
10479: $output .= (' 'x2)."\n";
10480: }
10481: }
10482: #
10483: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10484: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10485: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10486: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10487: #
1.165 raeburn 10488: $output .= '</td></tr>'."\n".
1.305 raeburn 10489: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10490: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10491: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10492: $currpub.'" size="40" /></span><br />'."\n".
10493: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10494: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10495: $currpriv.'" size="40" /></span><br />'.
10496: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10497: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10498: $currver.'" size="3" /></span><br />'.
10499: '</td></tr></table>'."\n".
1.165 raeburn 10500: '</td></tr>';
10501: return $output;
10502: }
10503:
1.32 raeburn 10504: sub user_formats_row {
1.305 raeburn 10505: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10506: my $output;
10507: my %text = (
10508: 'username' => 'new usernames',
10509: 'id' => 'IDs',
10510: );
1.409 raeburn 10511: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10512: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10513: $output = '<tr '.$css_class.'>'.
10514: '<td><span class="LC_nobreak">'.
10515: &mt("Format rules to check for $text{$type}: ").
10516: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10517: }
1.27 raeburn 10518: my $rem;
10519: if (ref($ruleorder) eq 'ARRAY') {
10520: for (my $i=0; $i<@{$ruleorder}; $i++) {
10521: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10522: my $rem = $i%($numinrow);
10523: if ($rem == 0) {
10524: if ($i > 0) {
10525: $output .= '</tr>';
10526: }
10527: $output .= '<tr>';
10528: }
10529: my $check = ' ';
1.39 raeburn 10530: if (ref($settings) eq 'HASH') {
10531: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10532: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10533: $check = ' checked="checked" ';
10534: }
1.305 raeburn 10535: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10536: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10537: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10538: $check = ' checked="checked" ';
10539: }
10540: }
1.27 raeburn 10541: }
10542: }
1.305 raeburn 10543: my $name = $type.'_rule';
10544: if ($type eq 'email') {
10545: $name .= '_'.$status;
10546: }
1.27 raeburn 10547: $output .= '<td class="LC_left_item">'.
10548: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10549: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10550: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10551: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10552: }
10553: }
10554: $rem = @{$ruleorder}%($numinrow);
10555: }
1.305 raeburn 10556: my $colsleft;
10557: if ($rem) {
10558: $colsleft = $numinrow - $rem;
10559: }
1.27 raeburn 10560: if ($colsleft > 1 ) {
10561: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10562: ' </td>';
10563: } elsif ($colsleft == 1) {
10564: $output .= '<td class="LC_left_item"> </td>';
10565: }
1.409 raeburn 10566: $output .= '</tr>';
10567: unless (($type eq 'email') || ($type eq 'unamemap')) {
10568: $output .= '</table></td></tr>';
1.305 raeburn 10569: }
1.27 raeburn 10570: return $output;
10571: }
10572:
1.34 raeburn 10573: sub usercreation_types {
10574: my %lt = &Apache::lonlocal::texthash (
10575: author => 'When adding a co-author',
10576: course => 'When adding a user to a course',
1.100 raeburn 10577: requestcrs => 'When requesting a course',
1.34 raeburn 10578: any => 'Any',
10579: official => 'Institutional only ',
10580: unofficial => 'Non-institutional only',
10581: none => 'None',
10582: );
10583: return %lt;
1.48 raeburn 10584: }
1.34 raeburn 10585:
1.224 raeburn 10586: sub selfcreation_types {
10587: my %lt = &Apache::lonlocal::texthash (
10588: selfcreate => 'User creates own account',
10589: any => 'Any',
10590: official => 'Institutional only ',
10591: unofficial => 'Non-institutional only',
10592: email => 'E-mail address',
10593: login => 'Institutional Login',
10594: sso => 'SSO',
10595: );
10596: }
10597:
1.28 raeburn 10598: sub authtype_names {
10599: my %lt = &Apache::lonlocal::texthash(
10600: int => 'Internal',
10601: krb4 => 'Kerberos 4',
10602: krb5 => 'Kerberos 5',
10603: loc => 'Local',
1.325 raeburn 10604: lti => 'LTI',
1.28 raeburn 10605: );
10606: return %lt;
10607: }
10608:
10609: sub context_names {
10610: my %context_title = &Apache::lonlocal::texthash(
10611: author => 'Creating users when an Author',
10612: course => 'Creating users when in a course',
10613: domain => 'Creating users when a Domain Coordinator',
10614: );
10615: return %context_title;
10616: }
10617:
1.33 raeburn 10618: sub print_usermodification {
10619: my ($position,$dom,$settings,$rowtotal) = @_;
10620: my $numinrow = 4;
10621: my ($context,$datatable,$rowcount);
10622: if ($position eq 'top') {
10623: $rowcount = 0;
10624: $context = 'author';
10625: foreach my $role ('ca','aa') {
10626: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10627: $numinrow,$rowcount);
10628: $$rowtotal ++;
10629: $rowcount ++;
10630: }
1.443 raeburn 10631: } elsif ($position eq 'middle') {
10632: $rowcount = 0;
10633: $context = 'coauthor';
10634: foreach my $role ('ca','aa') {
10635: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10636: $numinrow,$rowcount);
10637: $$rowtotal ++;
10638: $rowcount ++;
10639: }
1.230 raeburn 10640: } elsif ($position eq 'bottom') {
1.33 raeburn 10641: $context = 'course';
10642: $rowcount = 0;
10643: foreach my $role ('st','ep','ta','in','cr') {
10644: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10645: $numinrow,$rowcount);
10646: $$rowtotal ++;
10647: $rowcount ++;
10648: }
10649: }
10650: return $datatable;
10651: }
10652:
1.43 raeburn 10653: sub print_defaults {
1.236 raeburn 10654: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10655: my $rownum = 0;
1.294 raeburn 10656: my ($datatable,$css_class,$titles);
10657: unless ($position eq 'bottom') {
10658: $titles = &defaults_titles($dom);
10659: }
1.236 raeburn 10660: if ($position eq 'top') {
10661: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10662: 'datelocale_def','portal_def');
10663: my %defaults;
10664: if (ref($settings) eq 'HASH') {
10665: %defaults = %{$settings};
1.43 raeburn 10666: } else {
1.236 raeburn 10667: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10668: foreach my $item (@items) {
10669: $defaults{$item} = $domdefaults{$item};
10670: }
1.43 raeburn 10671: }
1.236 raeburn 10672: foreach my $item (@items) {
10673: if ($rownum%2) {
10674: $css_class = '';
10675: } else {
10676: $css_class = ' class="LC_odd_row" ';
10677: }
10678: $datatable .= '<tr'.$css_class.'>'.
10679: '<td><span class="LC_nobreak">'.$titles->{$item}.
10680: '</span></td><td class="LC_right_item" colspan="3">';
10681: if ($item eq 'auth_def') {
1.325 raeburn 10682: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10683: my %shortauth = (
10684: internal => 'int',
10685: krb4 => 'krb4',
10686: krb5 => 'krb5',
1.325 raeburn 10687: localauth => 'loc',
10688: lti => 'lti',
1.236 raeburn 10689: );
10690: my %authnames = &authtype_names();
10691: foreach my $auth (@authtypes) {
10692: my $checked = ' ';
10693: if ($defaults{$item} eq $auth) {
10694: $checked = ' checked="checked" ';
10695: }
10696: $datatable .= '<label><input type="radio" name="'.$item.
10697: '" value="'.$auth.'"'.$checked.'/>'.
10698: $authnames{$shortauth{$auth}}.'</label> ';
10699: }
10700: } elsif ($item eq 'timezone_def') {
10701: my $includeempty = 1;
10702: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10703: } elsif ($item eq 'datelocale_def') {
10704: my $includeempty = 1;
10705: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10706: } elsif ($item eq 'lang_def') {
1.263 raeburn 10707: my $includeempty = 1;
10708: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10709: } elsif ($item eq 'portal_def') {
10710: $datatable .= '<input type="text" name="'.$item.'" value="'.
10711: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10712: my $portalsty = 'none';
10713: if ($defaults{$item}) {
10714: $portalsty = 'block';
10715: }
10716: foreach my $field ('email','web') {
10717: my $checkedoff = ' checked="checked"';
10718: my $checkedon;
10719: if ($defaults{$item.'_'.$field}) {
10720: $checkedon = $checkedoff;
10721: $checkedoff = '';
1.425 raeburn 10722: }
1.414 raeburn 10723: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10724: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10725: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10726: (' 'x2).
10727: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10728: '</div>';
10729: }
1.236 raeburn 10730: } else {
1.414 raeburn 10731: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10732: }
1.236 raeburn 10733: $datatable .= '</td></tr>';
10734: $rownum ++;
10735: }
1.409 raeburn 10736: } elsif ($position eq 'middle') {
1.294 raeburn 10737: my %defaults;
10738: if (ref($settings) eq 'HASH') {
1.354 raeburn 10739: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10740: my $maxnum = @{$settings->{'inststatusorder'}};
10741: for (my $i=0; $i<$maxnum; $i++) {
10742: $css_class = $rownum%2?' class="LC_odd_row"':'';
10743: my $item = $settings->{'inststatusorder'}->[$i];
10744: my $title = $settings->{'inststatustypes'}->{$item};
10745: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10746: $datatable .= '<tr'.$css_class.'>'.
10747: '<td><span class="LC_nobreak">'.
10748: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10749: for (my $k=0; $k<=$maxnum; $k++) {
10750: my $vpos = $k+1;
10751: my $selstr;
10752: if ($k == $i) {
10753: $selstr = ' selected="selected" ';
10754: }
10755: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10756: }
10757: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10758: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10759: &mt('delete').'</span></td>'.
1.380 raeburn 10760: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10761: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10762: '</span></td></tr>';
10763: }
10764: $css_class = $rownum%2?' class="LC_odd_row"':'';
10765: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10766: $datatable .= '<tr '.$css_class.'>'.
10767: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10768: for (my $k=0; $k<=$maxnum; $k++) {
10769: my $vpos = $k+1;
10770: my $selstr;
10771: if ($k == $maxnum) {
10772: $selstr = ' selected="selected" ';
10773: }
10774: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10775: }
10776: $datatable .= '</select> '.&mt('Internal ID:').
10777: '<input type="text" size="10" name="addinststatus" value="" />'.
10778: ' '.&mt('(new)').
10779: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10780: &mt('Name displayed').':'.
1.354 raeburn 10781: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10782: '</tr>'."\n";
10783: $rownum ++;
1.294 raeburn 10784: }
1.354 raeburn 10785: }
1.409 raeburn 10786: } else {
10787: my ($unamemaprules,$ruleorder) =
10788: &Apache::lonnet::inst_userrules($dom,'unamemap');
10789: $css_class = $rownum%2?' class="LC_odd_row"':'';
10790: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10791: my $numinrow = 2;
10792: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10793: &user_formats_row('unamemap',$settings,$unamemaprules,
10794: $ruleorder,$numinrow).
10795: '</table></td></tr>';
10796: }
10797: if ($datatable eq '') {
10798: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10799: &mt('No rules set for domain in customized localenroll.pm').
10800: '</td></tr>';
10801: }
1.354 raeburn 10802: }
10803: $$rowtotal += $rownum;
1.43 raeburn 10804: return $datatable;
10805: }
10806:
1.168 raeburn 10807: sub get_languages_hash {
10808: my %langchoices;
10809: foreach my $id (&Apache::loncommon::languageids()) {
10810: my $code = &Apache::loncommon::supportedlanguagecode($id);
10811: if ($code ne '') {
10812: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10813: }
10814: }
10815: return %langchoices;
10816: }
10817:
1.43 raeburn 10818: sub defaults_titles {
1.141 raeburn 10819: my ($dom) = @_;
1.43 raeburn 10820: my %titles = &Apache::lonlocal::texthash (
10821: 'auth_def' => 'Default authentication type',
10822: 'auth_arg_def' => 'Default authentication argument',
10823: 'lang_def' => 'Default language',
1.54 raeburn 10824: 'timezone_def' => 'Default timezone',
1.68 raeburn 10825: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10826: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10827: 'email' => 'Email links use portal URL',
10828: 'web' => 'Public web links use portal URL',
1.294 raeburn 10829: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10830: 'intauth_check' => 'Check bcrypt cost if authenticated',
10831: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10832: );
1.141 raeburn 10833: if ($dom) {
10834: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10835: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10836: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10837: $protocol = 'http' if ($protocol ne 'https');
10838: if ($uint_dom) {
10839: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10840: $uint_dom);
10841: }
10842: }
1.43 raeburn 10843: return (\%titles);
10844: }
10845:
1.346 raeburn 10846: sub print_scantron {
10847: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10848: if ($position eq 'top') {
10849: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10850: } else {
10851: return &print_scantronconfig($dom,$settings,\$rowtotal);
10852: }
10853: }
10854:
10855: sub scantron_javascript {
10856: return <<"ENDSCRIPT";
10857:
10858: <script type="text/javascript">
10859: // <![CDATA[
10860:
10861: function toggleScantron(form) {
1.347 raeburn 10862: var csvfieldset = new Array();
1.346 raeburn 10863: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10864: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10865: }
10866: if (document.getElementById('scantroncsv_options')) {
10867: csvfieldset.push(document.getElementById('scantroncsv_options'));
10868: }
10869: if (csvfieldset.length) {
1.346 raeburn 10870: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10871: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10872: if (scantroncsv.checked) {
1.347 raeburn 10873: for (var i=0; i<csvfieldset.length; i++) {
10874: csvfieldset[i].style.display = 'block';
10875: }
1.346 raeburn 10876: } else {
1.347 raeburn 10877: for (var i=0; i<csvfieldset.length; i++) {
10878: csvfieldset[i].style.display = 'none';
10879: }
1.346 raeburn 10880: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10881: if (csvselects.length) {
10882: for (var j=0; j<csvselects.length; j++) {
10883: csvselects[j].selectedIndex = 0;
10884: }
10885: }
10886: }
10887: }
10888: }
10889: return;
10890: }
10891: // ]]>
10892: </script>
10893:
10894: ENDSCRIPT
10895:
10896: }
10897:
1.46 raeburn 10898: sub print_scantronformat {
10899: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10900: my $itemcount = 1;
1.60 raeburn 10901: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10902: %confhash);
1.46 raeburn 10903: my $switchserver = &check_switchserver($dom,$confname);
10904: my %lt = &Apache::lonlocal::texthash (
1.95 www 10905: default => 'Default bubblesheet format file error',
10906: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10907: );
10908: my %scantronfiles = (
10909: default => 'default.tab',
10910: custom => 'custom.tab',
10911: );
10912: foreach my $key (keys(%scantronfiles)) {
10913: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10914: .$scantronfiles{$key};
10915: }
10916: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10917: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10918: if (!$switchserver) {
10919: my $servadm = $r->dir_config('lonAdmEMail');
10920: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10921: if ($configuserok eq 'ok') {
10922: if ($author_ok eq 'ok') {
10923: my %legacyfile = (
1.346 raeburn 10924: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10925: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10926: );
10927: my %md5chk;
10928: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10929: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10930: chomp($md5chk{$type});
1.46 raeburn 10931: }
10932: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10933: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10934: ($scantronurls{$type},my $error) =
1.46 raeburn 10935: &legacy_scantronformat($r,$dom,$confname,
10936: $type,$legacyfile{$type},
10937: $scantronurls{$type},
10938: $scantronfiles{$type});
1.60 raeburn 10939: if ($error ne '') {
10940: $error{$type} = $error;
10941: }
10942: }
10943: if (keys(%error) == 0) {
10944: $is_custom = 1;
1.346 raeburn 10945: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10946: $scantronurls{'custom'};
1.346 raeburn 10947: my $putresult =
1.60 raeburn 10948: &Apache::lonnet::put_dom('configuration',
10949: \%confhash,$dom);
10950: if ($putresult ne 'ok') {
1.346 raeburn 10951: $error{'custom'} =
1.60 raeburn 10952: '<span class="LC_error">'.
10953: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10954: }
1.46 raeburn 10955: }
10956: } else {
1.60 raeburn 10957: ($scantronurls{'default'},my $error) =
1.46 raeburn 10958: &legacy_scantronformat($r,$dom,$confname,
10959: 'default',$legacyfile{'default'},
10960: $scantronurls{'default'},
10961: $scantronfiles{'default'});
1.60 raeburn 10962: if ($error eq '') {
10963: $confhash{'scantron'}{'scantronformat'} = '';
10964: my $putresult =
10965: &Apache::lonnet::put_dom('configuration',
10966: \%confhash,$dom);
10967: if ($putresult ne 'ok') {
10968: $error{'default'} =
10969: '<span class="LC_error">'.
10970: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10971: }
10972: } else {
10973: $error{'default'} = $error;
10974: }
1.46 raeburn 10975: }
10976: }
10977: }
10978: } else {
1.95 www 10979: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 10980: }
10981: }
10982: if (ref($settings) eq 'HASH') {
10983: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
10984: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
10985: if ((!@info) || ($info[0] eq 'no_such_dir')) {
10986: $scantronurl = '';
10987: } else {
10988: $scantronurl = $settings->{'scantronformat'};
10989: }
10990: $is_custom = 1;
10991: } else {
10992: $scantronurl = $scantronurls{'default'};
10993: }
10994: } else {
1.60 raeburn 10995: if ($is_custom) {
10996: $scantronurl = $scantronurls{'custom'};
10997: } else {
10998: $scantronurl = $scantronurls{'default'};
10999: }
1.46 raeburn 11000: }
11001: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11002: $datatable .= '<tr'.$css_class.'>';
11003: if (!$is_custom) {
1.65 raeburn 11004: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
11005: '<span class="LC_nobreak">';
1.46 raeburn 11006: if ($scantronurl) {
1.199 raeburn 11007: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
11008: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 11009: } else {
11010: $datatable = &mt('File unavailable for display');
11011: }
1.65 raeburn 11012: $datatable .= '</span></td>';
1.60 raeburn 11013: if (keys(%error) == 0) {
1.306 raeburn 11014: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 11015: if (!$switchserver) {
11016: $datatable .= &mt('Upload:').'<br />';
11017: }
11018: } else {
11019: my $errorstr;
11020: foreach my $key (sort(keys(%error))) {
11021: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11022: }
11023: $datatable .= '<td>'.$errorstr;
11024: }
1.46 raeburn 11025: } else {
11026: if (keys(%error) > 0) {
11027: my $errorstr;
11028: foreach my $key (sort(keys(%error))) {
11029: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11030: }
1.60 raeburn 11031: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 11032: } elsif ($scantronurl) {
1.199 raeburn 11033: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
11034: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 11035: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 11036: $link.
11037: '<label><input type="checkbox" name="scantronformat_del"'.
11038: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 11039: '<td><span class="LC_nobreak"> '.
11040: &mt('Replace:').'</span><br />';
1.46 raeburn 11041: }
11042: }
11043: if (keys(%error) == 0) {
11044: if ($switchserver) {
11045: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
11046: } else {
1.65 raeburn 11047: $datatable .='<span class="LC_nobreak"> '.
11048: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11049: }
11050: }
11051: $datatable .= '</td></tr>';
11052: $$rowtotal ++;
11053: return $datatable;
11054: }
11055:
11056: sub legacy_scantronformat {
11057: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11058: my ($url,$error);
11059: my @statinfo = &Apache::lonnet::stat_file($newurl);
11060: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 11061: my $modified = [];
1.46 raeburn 11062: (my $result,$url) =
1.421 raeburn 11063: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
11064: 'scantron','','',$newfile,$modified);
11065: if ($result eq 'ok') {
11066: &update_modify_urls($r,$modified);
11067: } else {
1.130 raeburn 11068: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11069: }
11070: }
11071: return ($url,$error);
11072: }
1.43 raeburn 11073:
1.346 raeburn 11074: sub print_scantronconfig {
11075: my ($dom,$settings,$rowtotal) = @_;
11076: my $itemcount = 2;
11077: my $is_checked = ' checked="checked"';
1.347 raeburn 11078: my %optionson = (
11079: hdr => ' checked="checked"',
11080: pad => ' checked="checked"',
11081: rem => ' checked="checked"',
11082: );
11083: my %optionsoff = (
11084: hdr => '',
11085: pad => '',
11086: rem => '',
11087: );
1.346 raeburn 11088: my $currcsvsty = 'none';
1.347 raeburn 11089: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11090: my @fields = &scantroncsv_fields();
11091: my %titles = &scantronconfig_titles();
11092: if (ref($settings) eq 'HASH') {
11093: if (ref($settings->{config}) eq 'HASH') {
11094: if ($settings->{config}->{dat}) {
11095: $checked{'dat'} = $is_checked;
11096: }
11097: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11098: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11099: %csvfields = %{$settings->{config}->{csv}->{fields}};
11100: if (keys(%csvfields) > 0) {
11101: $checked{'csv'} = $is_checked;
11102: $currcsvsty = 'block';
11103: }
11104: }
11105: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11106: %csvoptions = %{$settings->{config}->{csv}->{options}};
11107: foreach my $option (keys(%optionson)) {
11108: unless ($csvoptions{$option}) {
11109: $optionsoff{$option} = $optionson{$option};
11110: $optionson{$option} = '';
11111: }
11112: }
1.346 raeburn 11113: }
11114: }
11115: } else {
11116: $checked{'dat'} = $is_checked;
11117: }
11118: } else {
11119: $checked{'dat'} = $is_checked;
11120: }
11121: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11122: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11123: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11124: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11125: foreach my $item ('dat','csv') {
11126: my $id;
11127: if ($item eq 'csv') {
11128: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11129: }
1.346 raeburn 11130: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11131: $titles{$item}.'</label>'.(' 'x3);
11132: if ($item eq 'csv') {
11133: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11134: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11135: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11136: foreach my $col (@fields) {
11137: my $selnone;
11138: if ($csvfields{$col} eq '') {
11139: $selnone = ' selected="selected"';
11140: }
11141: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11142: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11143: '<option value=""'.$selnone.'></option>';
11144: for (my $i=0; $i<20; $i++) {
11145: my $shown = $i+1;
11146: my $sel;
11147: unless ($selnone) {
11148: if (exists($csvfields{$col})) {
11149: if ($csvfields{$col} == $i) {
11150: $sel = ' selected="selected"';
11151: }
11152: }
11153: }
11154: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11155: }
11156: $datatable .= '</select></td></tr>';
11157: }
1.347 raeburn 11158: $datatable .= '</table></fieldset>'.
11159: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11160: '<legend>'.&mt('CSV Options').'</legend>';
11161: foreach my $option ('hdr','pad','rem') {
11162: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11163: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11164: &mt('Yes').'</label>'.(' 'x2)."\n".
11165: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11166: }
11167: $datatable .= '</fieldset>';
1.346 raeburn 11168: $itemcount ++;
11169: }
11170: }
11171: $datatable .= '</td></tr>';
11172: $$rowtotal ++;
11173: return $datatable;
11174: }
11175:
11176: sub scantronconfig_titles {
11177: return &Apache::lonlocal::texthash(
11178: dat => 'Standard format (.dat)',
11179: csv => 'Comma separated values (.csv)',
1.347 raeburn 11180: hdr => 'Remove first line in file (contains column titles)',
11181: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11182: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11183: CODE => 'CODE',
11184: ID => 'Student ID',
11185: PaperID => 'Paper ID',
11186: FirstName => 'First Name',
11187: LastName => 'Last Name',
11188: FirstQuestion => 'First Question Response',
11189: Section => 'Section',
11190: );
11191: }
11192:
11193: sub scantroncsv_fields {
11194: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11195: }
11196:
1.49 raeburn 11197: sub print_coursecategories {
1.57 raeburn 11198: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11199: my $datatable;
11200: if ($position eq 'top') {
1.238 raeburn 11201: my (%checked);
11202: my @catitems = ('unauth','auth');
11203: my @cattypes = ('std','domonly','codesrch','none');
11204: $checked{'unauth'} = 'std';
11205: $checked{'auth'} = 'std';
11206: if (ref($settings) eq 'HASH') {
11207: foreach my $type (@cattypes) {
11208: if ($type eq $settings->{'unauth'}) {
11209: $checked{'unauth'} = $type;
11210: }
11211: if ($type eq $settings->{'auth'}) {
11212: $checked{'auth'} = $type;
11213: }
11214: }
11215: }
11216: my %lt = &Apache::lonlocal::texthash (
11217: unauth => 'Catalog type for unauthenticated users',
11218: auth => 'Catalog type for authenticated users',
11219: none => 'No catalog',
11220: std => 'Standard catalog',
11221: domonly => 'Domain-only catalog',
11222: codesrch => "Code search form",
11223: );
11224: my $itemcount = 0;
11225: foreach my $item (@catitems) {
11226: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11227: $datatable .= '<tr '.$css_class.'>'.
11228: '<td>'.$lt{$item}.'</td>'.
11229: '<td class="LC_right_item"><span class="LC_nobreak">';
11230: foreach my $type (@cattypes) {
11231: my $ischecked;
11232: if ($checked{$item} eq $type) {
11233: $ischecked=' checked="checked"';
11234: }
11235: $datatable .= '<label>'.
11236: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11237: ' />'.$lt{$type}.'</label> ';
11238: }
1.327 raeburn 11239: $datatable .= '</span></td></tr>';
1.238 raeburn 11240: $itemcount ++;
11241: }
11242: $$rowtotal += $itemcount;
11243: } elsif ($position eq 'middle') {
1.57 raeburn 11244: my $toggle_cats_crs = ' ';
11245: my $toggle_cats_dom = ' checked="checked" ';
11246: my $can_cat_crs = ' ';
11247: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11248: my $toggle_catscomm_comm = ' ';
11249: my $toggle_catscomm_dom = ' checked="checked" ';
11250: my $can_catcomm_comm = ' ';
11251: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11252: my $toggle_catsplace_place = ' ';
11253: my $toggle_catsplace_dom = ' checked="checked" ';
11254: my $can_catplace_place = ' ';
11255: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11256:
1.57 raeburn 11257: if (ref($settings) eq 'HASH') {
11258: if ($settings->{'togglecats'} eq 'crs') {
11259: $toggle_cats_crs = $toggle_cats_dom;
11260: $toggle_cats_dom = ' ';
11261: }
11262: if ($settings->{'categorize'} eq 'crs') {
11263: $can_cat_crs = $can_cat_dom;
11264: $can_cat_dom = ' ';
11265: }
1.120 raeburn 11266: if ($settings->{'togglecatscomm'} eq 'comm') {
11267: $toggle_catscomm_comm = $toggle_catscomm_dom;
11268: $toggle_catscomm_dom = ' ';
11269: }
11270: if ($settings->{'categorizecomm'} eq 'comm') {
11271: $can_catcomm_comm = $can_catcomm_dom;
11272: $can_catcomm_dom = ' ';
11273: }
1.272 raeburn 11274: if ($settings->{'togglecatsplace'} eq 'place') {
11275: $toggle_catsplace_place = $toggle_catsplace_dom;
11276: $toggle_catsplace_dom = ' ';
11277: }
11278: if ($settings->{'categorizeplace'} eq 'place') {
11279: $can_catplace_place = $can_catplace_dom;
11280: $can_catplace_dom = ' ';
11281: }
1.57 raeburn 11282: }
11283: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11284: togglecats => 'Show/Hide a course in catalog',
11285: togglecatscomm => 'Show/Hide a community in catalog',
11286: togglecatsplace => 'Show/Hide a placement test in catalog',
11287: categorize => 'Assign a category to a course',
11288: categorizecomm => 'Assign a category to a community',
11289: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11290: );
11291: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11292: dom => 'Set in Domain',
11293: crs => 'Set in Course',
11294: comm => 'Set in Community',
11295: place => 'Set in Placement Test',
1.57 raeburn 11296: );
11297: $datatable = '<tr class="LC_odd_row">'.
11298: '<td>'.$title{'togglecats'}.'</td>'.
11299: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11300: '<input type="radio" name="togglecats"'.
11301: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11302: '<label><input type="radio" name="togglecats"'.
11303: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11304: '</tr><tr>'.
11305: '<td>'.$title{'categorize'}.'</td>'.
11306: '<td class="LC_right_item"><span class="LC_nobreak">'.
11307: '<label><input type="radio" name="categorize"'.
11308: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11309: '<label><input type="radio" name="categorize"'.
11310: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11311: '</tr><tr class="LC_odd_row">'.
11312: '<td>'.$title{'togglecatscomm'}.'</td>'.
11313: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11314: '<input type="radio" name="togglecatscomm"'.
11315: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11316: '<label><input type="radio" name="togglecatscomm"'.
11317: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11318: '</tr><tr>'.
11319: '<td>'.$title{'categorizecomm'}.'</td>'.
11320: '<td class="LC_right_item"><span class="LC_nobreak">'.
11321: '<label><input type="radio" name="categorizecomm"'.
11322: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11323: '<label><input type="radio" name="categorizecomm"'.
11324: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11325: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11326: '<td>'.$title{'togglecatsplace'}.'</td>'.
11327: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11328: '<input type="radio" name="togglecatsplace"'.
11329: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11330: '<label><input type="radio" name="togglecatscomm"'.
11331: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11332: '</tr><tr>'.
11333: '<td>'.$title{'categorizeplace'}.'</td>'.
11334: '<td class="LC_right_item"><span class="LC_nobreak">'.
11335: '<label><input type="radio" name="categorizeplace"'.
11336: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11337: '<label><input type="radio" name="categorizeplace"'.
11338: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11339: '</tr>';
1.272 raeburn 11340: $$rowtotal += 6;
1.57 raeburn 11341: } else {
11342: my $css_class;
11343: my $itemcount = 1;
11344: my $cathash;
11345: if (ref($settings) eq 'HASH') {
11346: $cathash = $settings->{'cats'};
11347: }
11348: if (ref($cathash) eq 'HASH') {
11349: my (@cats,@trails,%allitems,%idx,@jsarray);
11350: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11351: \%allitems,\%idx,\@jsarray);
11352: my $maxdepth = scalar(@cats);
11353: my $colattrib = '';
11354: if ($maxdepth > 2) {
11355: $colattrib = ' colspan="2" ';
11356: }
11357: my @path;
11358: if (@cats > 0) {
11359: if (ref($cats[0]) eq 'ARRAY') {
11360: my $numtop = @{$cats[0]};
11361: my $maxnum = $numtop;
1.120 raeburn 11362: my %default_names = (
11363: instcode => &mt('Official courses'),
11364: communities => &mt('Communities'),
1.272 raeburn 11365: placement => &mt('Placement Tests'),
1.120 raeburn 11366: );
11367:
11368: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11369: ($cathash->{'instcode::0'} eq '') ||
11370: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11371: ($cathash->{'communities::0'} eq '') ||
11372: (!grep(/^placement$/,@{$cats[0]})) ||
11373: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11374: $maxnum ++;
11375: }
11376: my $lastidx;
11377: for (my $i=0; $i<$numtop; $i++) {
11378: my $parent = $cats[0][$i];
11379: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11380: my $item = &escape($parent).'::0';
11381: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11382: $lastidx = $idx{$item};
11383: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11384: .'<select name="'.$item.'"'.$chgstr.'>';
11385: for (my $k=0; $k<=$maxnum; $k++) {
11386: my $vpos = $k+1;
11387: my $selstr;
11388: if ($k == $i) {
11389: $selstr = ' selected="selected" ';
11390: }
11391: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11392: }
1.214 raeburn 11393: $datatable .= '</select></span></td><td>';
1.272 raeburn 11394: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11395: $datatable .= '<span class="LC_nobreak">'
11396: .$default_names{$parent}.'</span>';
11397: if ($parent eq 'instcode') {
11398: $datatable .= '<br /><span class="LC_nobreak">('
11399: .&mt('with institutional codes')
11400: .')</span></td><td'.$colattrib.'>';
11401: } else {
11402: $datatable .= '<table><tr><td>';
11403: }
11404: $datatable .= '<span class="LC_nobreak">'
11405: .'<label><input type="radio" name="'
11406: .$parent.'" value="1" checked="checked" />'
11407: .&mt('Display').'</label>';
11408: if ($parent eq 'instcode') {
11409: $datatable .= ' ';
11410: } else {
11411: $datatable .= '</span></td></tr><tr><td>'
11412: .'<span class="LC_nobreak">';
11413: }
11414: $datatable .= '<label><input type="radio" name="'
11415: .$parent.'" value="0" />'
11416: .&mt('Do not display').'</label></span>';
1.272 raeburn 11417: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11418: $datatable .= '</td></tr></table>';
11419: }
11420: $datatable .= '</td>';
1.57 raeburn 11421: } else {
11422: $datatable .= $parent
1.214 raeburn 11423: .' <span class="LC_nobreak"><label>'
11424: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11425: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11426: }
11427: my $depth = 1;
11428: push(@path,$parent);
11429: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11430: pop(@path);
11431: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11432: $itemcount ++;
11433: }
1.48 raeburn 11434: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11435: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11436: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11437: for (my $k=0; $k<=$maxnum; $k++) {
11438: my $vpos = $k+1;
11439: my $selstr;
1.57 raeburn 11440: if ($k == $numtop) {
1.48 raeburn 11441: $selstr = ' selected="selected" ';
11442: }
11443: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11444: }
1.59 bisitz 11445: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11446: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11447: .'</tr>'."\n";
1.48 raeburn 11448: $itemcount ++;
1.272 raeburn 11449: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11450: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11451: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11452: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11453: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11454: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11455: for (my $k=0; $k<=$maxnum; $k++) {
11456: my $vpos = $k+1;
11457: my $selstr;
11458: if ($k == $maxnum) {
11459: $selstr = ' selected="selected" ';
11460: }
11461: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11462: }
1.120 raeburn 11463: $datatable .= '</select></span></td>'.
11464: '<td><span class="LC_nobreak">'.
11465: $default_names{$default}.'</span>';
11466: if ($default eq 'instcode') {
11467: $datatable .= '<br /><span class="LC_nobreak">('
11468: .&mt('with institutional codes').')</span>';
11469: }
11470: $datatable .= '</td>'
11471: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11472: .&mt('Display').'</label> '
11473: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11474: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11475: }
11476: }
11477: }
1.57 raeburn 11478: } else {
11479: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11480: }
11481: } else {
1.327 raeburn 11482: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11483: .&initialize_categories($itemcount);
1.48 raeburn 11484: }
1.57 raeburn 11485: $$rowtotal += $itemcount;
1.48 raeburn 11486: }
11487: return $datatable;
11488: }
11489:
1.69 raeburn 11490: sub print_serverstatuses {
11491: my ($dom,$settings,$rowtotal) = @_;
11492: my $datatable;
11493: my @pages = &serverstatus_pages();
11494: my (%namedaccess,%machineaccess);
11495: foreach my $type (@pages) {
11496: $namedaccess{$type} = '';
11497: $machineaccess{$type}= '';
11498: }
11499: if (ref($settings) eq 'HASH') {
11500: foreach my $type (@pages) {
11501: if (exists($settings->{$type})) {
11502: if (ref($settings->{$type}) eq 'HASH') {
11503: foreach my $key (keys(%{$settings->{$type}})) {
11504: if ($key eq 'namedusers') {
11505: $namedaccess{$type} = $settings->{$type}->{$key};
11506: } elsif ($key eq 'machines') {
11507: $machineaccess{$type} = $settings->{$type}->{$key};
11508: }
11509: }
11510: }
11511: }
11512: }
11513: }
1.81 raeburn 11514: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11515: my $rownum = 0;
11516: my $css_class;
11517: foreach my $type (@pages) {
11518: $rownum ++;
11519: $css_class = $rownum%2?' class="LC_odd_row"':'';
11520: $datatable .= '<tr'.$css_class.'>'.
11521: '<td><span class="LC_nobreak">'.
11522: $titles->{$type}.'</span></td>'.
11523: '<td class="LC_left_item">'.
11524: '<input type="text" name="'.$type.'_namedusers" '.
11525: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11526: '<td class="LC_right_item">'.
11527: '<span class="LC_nobreak">'.
11528: '<input type="text" name="'.$type.'_machines" '.
11529: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11530: '</span></td></tr>'."\n";
1.69 raeburn 11531: }
11532: $$rowtotal += $rownum;
11533: return $datatable;
11534: }
11535:
11536: sub serverstatus_pages {
11537: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11538: 'checksums','clusterstatus','certstatus','metadata_keywords',
11539: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11540: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11541: }
11542:
1.236 raeburn 11543: sub defaults_javascript {
11544: my ($settings) = @_;
1.354 raeburn 11545: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11546: my $portal_js = <<"ENDPORTAL";
11547:
11548: function portalExtras(caller) {
11549: var x = caller.value;
11550: var y = new Array('email','web');
1.425 raeburn 11551: for (var i=0; i<y.length; i++) {
1.414 raeburn 11552: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11553: var z = document.getElementById('portal_def_'+y[i]+'_div');
11554: if (x.length > 0) {
11555: z.style.display = 'block';
11556: } else {
11557: z.style.display = 'none';
11558: }
11559: }
11560: }
11561: }
11562: ENDPORTAL
1.236 raeburn 11563: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11564: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11565: if ($maxnum eq '') {
11566: $maxnum = 0;
11567: }
11568: $maxnum ++;
1.249 raeburn 11569: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11570: return <<"ENDSCRIPT";
11571: <script type="text/javascript">
11572: // <![CDATA[
11573: function reorderTypes(form,caller) {
11574: var changedVal;
11575: $jstext
11576: var newpos = 'addinststatus_pos';
11577: var current = new Array;
11578: var maxh = $maxnum;
11579: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11580: var oldVal;
11581: if (caller == newpos) {
11582: changedVal = newitemVal;
11583: } else {
11584: var curritem = 'inststatus_pos_'+caller;
11585: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11586: current[newitemVal] = newpos;
11587: }
11588: for (var i=0; i<inststatuses.length; i++) {
11589: if (inststatuses[i] != caller) {
11590: var elementName = 'inststatus_pos_'+inststatuses[i];
11591: if (form.elements[elementName]) {
11592: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11593: current[currVal] = elementName;
11594: }
11595: }
11596: }
11597: for (var j=0; j<maxh; j++) {
11598: if (current[j] == undefined) {
11599: oldVal = j;
11600: }
11601: }
11602: if (oldVal < changedVal) {
11603: for (var k=oldVal+1; k<=changedVal ; k++) {
11604: var elementName = current[k];
11605: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11606: }
11607: } else {
11608: for (var k=changedVal; k<oldVal; k++) {
11609: var elementName = current[k];
11610: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11611: }
11612: }
11613: return;
11614: }
11615:
1.414 raeburn 11616: $portal_js
11617:
11618: // ]]>
11619: </script>
11620:
11621: ENDSCRIPT
11622: } else {
11623: return <<"ENDSCRIPT";
11624: <script type="text/javascript">
11625: // <![CDATA[
11626: $portal_js
1.236 raeburn 11627: // ]]>
11628: </script>
11629:
11630: ENDSCRIPT
11631: }
1.354 raeburn 11632: return;
11633: }
11634:
11635: sub passwords_javascript {
1.405 raeburn 11636: my ($prefix) = @_;
11637: my %intalert;
11638: if ($prefix eq 'passwords') {
11639: %intalert = &Apache::lonlocal::texthash (
11640: 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.',
11641: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11642: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11643: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11644: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11645: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11646: );
1.421 raeburn 11647: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11648: %intalert = &Apache::lonlocal::texthash (
11649: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11650: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11651: );
11652: }
1.365 raeburn 11653: &js_escape(\%intalert);
11654: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11655: my $intauthjs;
1.405 raeburn 11656: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11657:
11658: function warnIntAuth(field) {
11659: if (field.name == 'intauth_check') {
11660: if (field.value == '2') {
1.365 raeburn 11661: alert('$intalert{authcheck}');
1.354 raeburn 11662: }
11663: }
11664: if (field.name == 'intauth_cost') {
11665: field.value.replace(/\s/g,'');
11666: if (field.value != '') {
11667: var regexdigit=/^\\d+\$/;
11668: if (!regexdigit.test(field.value)) {
1.365 raeburn 11669: alert('$intalert{authcost}');
11670: }
11671: }
11672: }
11673: return;
11674: }
11675:
1.405 raeburn 11676: ENDSCRIPT
11677:
11678: }
11679:
11680: $intauthjs .= <<"ENDSCRIPT";
11681:
11682: function warnInt$prefix(field) {
1.365 raeburn 11683: field.value.replace(/^\s+/,'');
11684: field.value.replace(/\s+\$/,'');
11685: var regexdigit=/^\\d+\$/;
1.408 raeburn 11686: if (field.name == '${prefix}_min') {
1.365 raeburn 11687: if (field.value == '') {
11688: alert('$intalert{passmin}');
11689: field.value = '$defmin';
11690: } else {
11691: if (!regexdigit.test(field.value)) {
11692: alert('$intalert{passmin}');
11693: field.value = '$defmin';
11694: }
1.366 raeburn 11695: var minval = parseInt(field.value,10);
1.365 raeburn 11696: if (minval < $defmin) {
11697: alert('$intalert{passmin}');
11698: field.value = '$defmin';
11699: }
11700: }
11701: } else {
11702: if (field.value == '0') {
11703: field.value = '';
11704: }
11705: if (field.value != '') {
1.447.2.5 raeburn 11706: if (!regexdigit.test(field.value)) {
11707: if (field.name == '${prefix}_max') {
11708: alert('$intalert{passmax}');
1.365 raeburn 11709: } else {
1.447.2.5 raeburn 11710: if (field.name == '${prefix}_numsaved') {
11711: alert('$intalert{passnum}');
1.365 raeburn 11712: }
11713: }
1.447.2.5 raeburn 11714: field.value = '';
1.354 raeburn 11715: }
11716: }
11717: }
11718: return;
11719: }
11720:
11721: ENDSCRIPT
11722: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11723: }
11724:
1.49 raeburn 11725: sub coursecategories_javascript {
11726: my ($settings) = @_;
1.57 raeburn 11727: my ($output,$jstext,$cathash);
1.49 raeburn 11728: if (ref($settings) eq 'HASH') {
1.57 raeburn 11729: $cathash = $settings->{'cats'};
11730: }
11731: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11732: my (@cats,@jsarray,%idx);
1.57 raeburn 11733: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11734: if (@jsarray > 0) {
11735: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11736: for (my $i=0; $i<@jsarray; $i++) {
11737: if (ref($jsarray[$i]) eq 'ARRAY') {
11738: my $catstr = join('","',@{$jsarray[$i]});
11739: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11740: }
11741: }
11742: }
11743: } else {
11744: $jstext = ' var categories = Array(1);'."\n".
11745: ' categories[0] = Array("instcode_pos");'."\n";
11746: }
1.237 bisitz 11747: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11748: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11749: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11750: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11751: &js_escape(\$instcode_reserved);
11752: &js_escape(\$communities_reserved);
1.272 raeburn 11753: &js_escape(\$placement_reserved);
1.265 damieng 11754: &js_escape(\$choose_again);
1.49 raeburn 11755: $output = <<"ENDSCRIPT";
11756: <script type="text/javascript">
1.109 raeburn 11757: // <![CDATA[
1.49 raeburn 11758: function reorderCats(form,parent,item,idx) {
11759: var changedVal;
11760: $jstext
11761: var newpos = 'addcategory_pos';
11762: if (parent == '') {
11763: var has_instcode = 0;
11764: var maxtop = categories[idx].length;
11765: for (var j=0; j<maxtop; j++) {
11766: if (categories[idx][j] == 'instcode::0') {
11767: has_instcode == 1;
11768: }
11769: }
11770: if (has_instcode == 0) {
11771: categories[idx][maxtop] = 'instcode_pos';
11772: }
11773: } else {
11774: newpos += '_'+parent;
11775: }
11776: var maxh = 1 + categories[idx].length;
11777: var current = new Array;
11778: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11779: if (item == newpos) {
11780: changedVal = newitemVal;
11781: } else {
11782: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11783: current[newitemVal] = newpos;
11784: }
11785: for (var i=0; i<categories[idx].length; i++) {
11786: var elementName = categories[idx][i];
11787: if (elementName != item) {
11788: if (form.elements[elementName]) {
11789: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11790: current[currVal] = elementName;
11791: }
11792: }
11793: }
11794: var oldVal;
11795: for (var j=0; j<maxh; j++) {
11796: if (current[j] == undefined) {
11797: oldVal = j;
11798: }
11799: }
11800: if (oldVal < changedVal) {
11801: for (var k=oldVal+1; k<=changedVal ; k++) {
11802: var elementName = current[k];
11803: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11804: }
11805: } else {
11806: for (var k=changedVal; k<oldVal; k++) {
11807: var elementName = current[k];
11808: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11809: }
11810: }
11811: return;
11812: }
1.120 raeburn 11813:
11814: function categoryCheck(form) {
11815: if (form.elements['addcategory_name'].value == 'instcode') {
11816: alert('$instcode_reserved\\n$choose_again');
11817: return false;
11818: }
11819: if (form.elements['addcategory_name'].value == 'communities') {
11820: alert('$communities_reserved\\n$choose_again');
11821: return false;
11822: }
1.272 raeburn 11823: if (form.elements['addcategory_name'].value == 'placement') {
11824: alert('$placement_reserved\\n$choose_again');
11825: return false;
11826: }
1.120 raeburn 11827: return true;
11828: }
11829:
1.109 raeburn 11830: // ]]>
1.49 raeburn 11831: </script>
11832:
11833: ENDSCRIPT
11834: return $output;
11835: }
11836:
1.48 raeburn 11837: sub initialize_categories {
11838: my ($itemcount) = @_;
1.120 raeburn 11839: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11840: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11841: instcode => 'Official courses (with institutional codes)',
11842: communities => 'Communities',
1.272 raeburn 11843: placement => 'Placement Tests',
1.120 raeburn 11844: );
1.328 raeburn 11845: my %selnum = (
11846: instcode => '0',
11847: communities => '1',
11848: placement => '2',
11849: );
11850: my %selected;
1.272 raeburn 11851: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11852: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11853: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11854: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11855: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11856: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11857: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11858: .'<option value="0"'.$selected{'0'}.'>1</option>'
11859: .'<option value="1"'.$selected{'1'}.'>2</option>'
11860: .'<option value="2"'.$selected{'2'}.'>3</option>'
11861: .'<option value="3">4</option></select> '
1.120 raeburn 11862: .$default_names{$default}
11863: .'</span></td><td><span class="LC_nobreak">'
11864: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11865: .&mt('Display').'</label> <label>'
11866: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11867: .'</label></span></td></tr>';
1.120 raeburn 11868: $itemcount ++;
11869: }
1.48 raeburn 11870: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11871: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11872: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11873: .'<select name="addcategory_pos"'.$chgstr.'>'
11874: .'<option value="0">1</option>'
11875: .'<option value="1">2</option>'
1.328 raeburn 11876: .'<option value="2">3</option>'
11877: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11878: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11879: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11880: .'</td></tr>';
1.48 raeburn 11881: return $datatable;
11882: }
11883:
11884: sub build_category_rows {
1.49 raeburn 11885: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11886: my ($text,$name,$item,$chgstr);
1.48 raeburn 11887: if (ref($cats) eq 'ARRAY') {
11888: my $maxdepth = scalar(@{$cats});
11889: if (ref($cats->[$depth]) eq 'HASH') {
11890: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11891: my $numchildren = @{$cats->[$depth]{$parent}};
11892: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11893: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11894: my ($idxnum,$parent_name,$parent_item);
11895: my $higher = $depth - 1;
11896: if ($higher == 0) {
11897: $parent_name = &escape($parent).'::'.$higher;
11898: } else {
11899: if (ref($path) eq 'ARRAY') {
11900: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11901: }
11902: }
11903: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11904: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11905: if ($j < $numchildren) {
1.48 raeburn 11906: $name = $cats->[$depth]{$parent}[$j];
11907: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11908: $idxnum = $idx->{$item};
11909: } else {
11910: $name = $parent_name;
11911: $item = $parent_item;
1.48 raeburn 11912: }
1.49 raeburn 11913: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11914: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11915: for (my $i=0; $i<=$numchildren; $i++) {
11916: my $vpos = $i+1;
11917: my $selstr;
11918: if ($j == $i) {
11919: $selstr = ' selected="selected" ';
11920: }
11921: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11922: }
11923: $text .= '</select> ';
11924: if ($j < $numchildren) {
11925: my $deeper = $depth+1;
11926: $text .= $name.' '
11927: .'<label><input type="checkbox" name="deletecategory" value="'
11928: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11929: if(ref($path) eq 'ARRAY') {
11930: push(@{$path},$name);
1.49 raeburn 11931: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11932: pop(@{$path});
11933: }
11934: } else {
1.330 raeburn 11935: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11936: if ($j == $numchildren) {
11937: $text .= $name;
11938: } else {
11939: $text .= $item;
11940: }
11941: $text .= '" value="" />';
11942: }
11943: $text .= '</td></tr>';
11944: }
11945: $text .= '</table></td>';
11946: } else {
11947: my $higher = $depth-1;
11948: if ($higher == 0) {
11949: $name = &escape($parent).'::'.$higher;
11950: } else {
11951: if (ref($path) eq 'ARRAY') {
11952: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11953: }
11954: }
11955: my $colspan;
11956: if ($parent ne 'instcode') {
11957: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11958: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11959: }
11960: }
11961: }
11962: }
11963: return $text;
11964: }
11965:
1.33 raeburn 11966: sub modifiable_userdata_row {
1.305 raeburn 11967: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 11968: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 11969: my ($role,$rolename,$statustype);
11970: $role = $item;
1.224 raeburn 11971: if ($context eq 'cancreate') {
1.305 raeburn 11972: if ($item =~ /^(emailusername)_(.+)$/) {
11973: $role = $1;
11974: $statustype = $2;
1.228 raeburn 11975: if (ref($usertypes) eq 'HASH') {
11976: if ($usertypes->{$statustype}) {
11977: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
11978: } else {
11979: $rolename = &mt('Data provided by user');
11980: }
11981: }
1.224 raeburn 11982: }
11983: } elsif ($context eq 'selfcreate') {
1.63 raeburn 11984: if (ref($usertypes) eq 'HASH') {
11985: $rolename = $usertypes->{$role};
11986: } else {
11987: $rolename = $role;
11988: }
1.325 raeburn 11989: } elsif ($context eq 'lti') {
11990: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 11991: } elsif ($context eq 'privacy') {
11992: $rolename = $itemdesc;
1.33 raeburn 11993: } else {
1.63 raeburn 11994: if ($role eq 'cr') {
11995: $rolename = &mt('Custom role');
11996: } else {
11997: $rolename = &Apache::lonnet::plaintext($role);
11998: }
1.33 raeburn 11999: }
1.224 raeburn 12000: my (@fields,%fieldtitles);
12001: if (ref($fieldsref) eq 'ARRAY') {
12002: @fields = @{$fieldsref};
12003: } else {
12004: @fields = ('lastname','firstname','middlename','generation',
12005: 'permanentemail','id');
12006: }
12007: if ((ref($titlesref) eq 'HASH')) {
12008: %fieldtitles = %{$titlesref};
12009: } else {
12010: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12011: }
1.33 raeburn 12012: my $output;
1.305 raeburn 12013: my $css_class;
12014: if ($rowcount%2) {
12015: $css_class = 'LC_odd_row';
12016: }
12017: if ($customcss) {
12018: $css_class .= " $customcss";
12019: }
12020: $css_class =~ s/^\s+//;
12021: if ($css_class) {
12022: $css_class = ' class="'.$css_class.'"';
12023: }
12024: if ($rowstyle) {
12025: $css_class .= ' style="'.$rowstyle.'"';
12026: }
12027: if ($rowid) {
12028: $rowid = ' id="'.$rowid.'"';
12029: }
12030: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 12031: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
12032: '<td class="LC_left_item" colspan="2"><table>';
12033: my $rem;
12034: my %checks;
12035: if (ref($settings) eq 'HASH') {
1.325 raeburn 12036: my $hashref;
12037: if ($context eq 'lti') {
12038: if (ref($settings) eq 'HASH') {
1.447.2.2 raeburn 12039: my %instdata;
12040: if (ref($settings->{'instdata'}) eq 'ARRAY') {
12041: map { $instdata{$_} = 1; } @{$settings->{'instdata'}};
12042: }
12043: $hashref = \%instdata;
1.325 raeburn 12044: }
1.357 raeburn 12045: } elsif ($context eq 'privacy') {
12046: my ($key,$inner) = split(/_/,$role);
12047: if (ref($settings) eq 'HASH') {
12048: if (ref($settings->{$key}) eq 'HASH') {
12049: $hashref = $settings->{$key}->{$inner};
12050: }
12051: }
1.325 raeburn 12052: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12053: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.447.2.2 raeburn 12054: $hashref = $settings->{$context}->{$role};
1.325 raeburn 12055: }
12056: if ($role eq 'emailusername') {
12057: if ($statustype) {
12058: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12059: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12060: }
1.325 raeburn 12061: }
12062: }
12063: }
1.425 raeburn 12064: if (ref($hashref) eq 'HASH') {
1.325 raeburn 12065: foreach my $field (@fields) {
12066: if ($hashref->{$field}) {
12067: if ($role eq 'emailusername') {
12068: $checks{$field} = $hashref->{$field};
12069: } else {
12070: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12071: }
12072: }
12073: }
12074: }
12075: }
1.305 raeburn 12076: my $total = scalar(@fields);
12077: for (my $i=0; $i<$total; $i++) {
12078: $rem = $i%($numinrow);
1.33 raeburn 12079: if ($rem == 0) {
12080: if ($i > 0) {
12081: $output .= '</tr>';
12082: }
12083: $output .= '<tr>';
12084: }
12085: my $check = ' ';
1.228 raeburn 12086: unless ($role eq 'emailusername') {
12087: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12088: $check = $checks{$fields[$i]};
1.357 raeburn 12089: } elsif ($context eq 'privacy') {
12090: if ($role =~ /^priv_(domain|course)$/) {
12091: if (ref($settings) ne 'HASH') {
12092: $check = ' checked="checked" ';
12093: }
12094: } elsif ($role =~ /^priv_(author|community)$/) {
12095: if (ref($settings) ne 'HASH') {
12096: unless ($fields[$i] eq 'id') {
12097: $check = ' checked="checked" ';
12098: }
12099: }
12100: } elsif ($role =~ /^(unpriv|othdom)_/) {
12101: if (ref($settings) ne 'HASH') {
12102: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12103: $check = ' checked="checked" ';
12104: }
12105: }
12106: }
1.325 raeburn 12107: } elsif ($context ne 'lti') {
1.228 raeburn 12108: if ($role eq 'st') {
12109: if (ref($settings) ne 'HASH') {
12110: $check = ' checked="checked" ';
12111: }
1.33 raeburn 12112: }
12113: }
12114: }
12115: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12116: '<span class="LC_nobreak">';
1.325 raeburn 12117: my $prefix = 'canmodify';
1.228 raeburn 12118: if ($role eq 'emailusername') {
12119: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12120: $checks{$fields[$i]} = 'omit';
12121: }
12122: foreach my $option ('required','optional','omit') {
12123: my $checked='';
12124: if ($checks{$fields[$i]} eq $option) {
12125: $checked='checked="checked" ';
12126: }
12127: $output .= '<label>'.
1.325 raeburn 12128: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12129: &mt($option).'</label>'.(' ' x2);
12130: }
12131: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12132: } else {
1.325 raeburn 12133: if ($context eq 'lti') {
12134: $prefix = 'lti';
1.443 raeburn 12135: } elsif ($context eq 'coauthor') {
12136: $prefix = 'cacanmodify';
1.357 raeburn 12137: } elsif ($context eq 'privacy') {
12138: $prefix = 'privacy';
1.325 raeburn 12139: }
1.228 raeburn 12140: $output .= '<label>'.
1.325 raeburn 12141: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12142: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12143: '</label>';
12144: }
12145: $output .= '</span></td>';
1.33 raeburn 12146: }
1.305 raeburn 12147: $rem = $total%$numinrow;
12148: my $colsleft;
12149: if ($rem) {
12150: $colsleft = $numinrow - $rem;
12151: }
12152: if ($colsleft > 1) {
1.33 raeburn 12153: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12154: ' </td>';
12155: } elsif ($colsleft == 1) {
12156: $output .= '<td class="LC_left_item"> </td>';
12157: }
12158: $output .= '</tr></table></td></tr>';
12159: return $output;
12160: }
1.28 raeburn 12161:
1.93 raeburn 12162: sub insttypes_row {
1.305 raeburn 12163: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12164: $customcss,$rowstyle) = @_;
1.93 raeburn 12165: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12166: cansearch => 'Users allowed to search',
1.93 raeburn 12167: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12168: lockablenames => 'User preference to lock name',
12169: selfassign => 'Self-reportable affiliations',
12170: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12171: webdav => 'WebDAV access available',
12172: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12173: );
1.429 raeburn 12174: my ($showdom,$defaultquota);
1.93 raeburn 12175: if ($context eq 'cansearch') {
12176: $showdom = ' ('.$dom.')';
1.429 raeburn 12177: } elsif ($context eq 'authorquota') {
12178: $defaultquota = 500;
1.93 raeburn 12179: }
1.165 raeburn 12180: my $class = 'LC_left_item';
12181: if ($context eq 'statustocreate') {
12182: $class = 'LC_right_item';
12183: }
1.305 raeburn 12184: my $css_class;
12185: if ($$rowtotal%2) {
12186: $css_class = 'LC_odd_row';
12187: }
12188: if ($customcss) {
12189: $css_class .= ' '.$customcss;
12190: }
12191: $css_class =~ s/^\s+//;
12192: if ($css_class) {
12193: $css_class = ' class="'.$css_class.'"';
12194: }
12195: if ($rowstyle) {
12196: $css_class .= ' style="'.$rowstyle.'"';
12197: }
12198: if ($onclick) {
12199: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12200: }
12201: my $output = '<tr'.$css_class.'>'.
12202: '<td>'.$lt{$context}.$showdom.
12203: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12204: my $rem;
12205: if (ref($types) eq 'ARRAY') {
12206: for (my $i=0; $i<@{$types}; $i++) {
12207: if (defined($usertypes->{$types->[$i]})) {
12208: my $rem = $i%($numinrow);
12209: if ($rem == 0) {
12210: if ($i > 0) {
12211: $output .= '</tr>';
12212: }
12213: $output .= '<tr>';
1.23 raeburn 12214: }
1.429 raeburn 12215: if ($context eq 'authorquota') {
12216: my $currquota;
12217: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12218: $currquota = $settings->{$context}->{$types->[$i]};
12219: } else {
12220: $currquota = $defaultquota;
12221: }
12222: $output .= '<td class="LC_left_item">'."\n".
12223: '<label><span class="LC_nobreak">'."\n".
12224: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12225: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12226: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12227: '</label></td>';
12228: } else {
12229: my $check = ' ';
12230: if (ref($settings) eq 'HASH') {
12231: if (ref($settings->{$context}) eq 'ARRAY') {
12232: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12233: $check = ' checked="checked" ';
12234: }
12235: } elsif (ref($settings->{$context}) eq 'HASH') {
12236: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12237: $check = ' checked="checked" ';
12238: } elsif ($context eq 'webdav') {
12239: if ($settings->{$context}->{$types->[$i]}) {
12240: $check = ' checked="checked" ';
12241: }
12242: }
12243: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12244: $check = ' checked="checked" ';
12245: }
1.26 raeburn 12246: }
1.429 raeburn 12247: $output .= '<td class="LC_left_item">'.
12248: '<span class="LC_nobreak"><label>'.
12249: '<input type="checkbox" name="'.$context.'" '.
12250: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12251: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12252: }
12253: }
12254: }
1.26 raeburn 12255: $rem = @{$types}%($numinrow);
1.23 raeburn 12256: }
12257: my $colsleft = $numinrow - $rem;
1.315 raeburn 12258: if ($context eq 'overrides') {
12259: if ($colsleft > 1) {
12260: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12261: } else {
12262: $output .= '<td class="LC_left_item">';
12263: }
1.425 raeburn 12264: $output .= ' ';
1.23 raeburn 12265: } else {
1.334 raeburn 12266: if ($rem == 0) {
1.315 raeburn 12267: $output .= '<tr>';
12268: }
12269: if ($colsleft > 1) {
12270: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12271: } else {
12272: $output .= '<td class="LC_left_item">';
12273: }
1.429 raeburn 12274: if ($context eq 'authorquota') {
12275: my $currquota = 500;
12276: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12277: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12278: $currquota = $settings->{$context}{'default'};
12279: }
12280: }
12281: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12282: '<input type="text" name="'.$context.'_default" '.
12283: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12284: '</label>';
12285: } else {
12286: my $defcheck = ' ';
12287: if (ref($settings) eq 'HASH') {
12288: if (ref($settings->{$context}) eq 'ARRAY') {
12289: if (grep(/^default$/,@{$settings->{$context}})) {
12290: $defcheck = ' checked="checked" ';
12291: }
12292: } elsif (ref($settings->{$context}) eq 'HASH') {
12293: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12294: $defcheck = ' checked="checked" ';
12295: } elsif ($context eq 'webdav') {
12296: if ($settings->{$context}->{'default'}) {
12297: $defcheck = ' checked="checked" ';
12298: }
12299: }
12300: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12301: $defcheck = ' checked="checked" ';
12302: }
1.99 raeburn 12303: }
1.429 raeburn 12304: $output .= '<span class="LC_nobreak"><label>'.
12305: '<input type="checkbox" name="'.$context.'" '.
12306: 'value="default"'.$defcheck.$onclick.'/>'.
12307: $othertitle.'</label></span>';
1.26 raeburn 12308: }
1.23 raeburn 12309: }
1.315 raeburn 12310: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12311: return $output;
1.23 raeburn 12312: }
12313:
12314: sub sorted_searchtitles {
12315: my %searchtitles = &Apache::lonlocal::texthash(
12316: 'uname' => 'username',
12317: 'lastname' => 'last name',
12318: 'lastfirst' => 'last name, first name',
12319: );
12320: my @titleorder = ('uname','lastname','lastfirst');
12321: return (\%searchtitles,\@titleorder);
12322: }
12323:
1.25 raeburn 12324: sub sorted_searchtypes {
12325: my %srchtypes_desc = (
12326: exact => 'is exact match',
12327: contains => 'contains ..',
12328: begins => 'begins with ..',
12329: );
12330: my @srchtypeorder = ('exact','begins','contains');
12331: return (\%srchtypes_desc,\@srchtypeorder);
12332: }
12333:
1.3 raeburn 12334: sub usertype_update_row {
12335: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12336: my $datatable;
12337: my $numinrow = 4;
12338: foreach my $type (@{$types}) {
12339: if (defined($usertypes->{$type})) {
12340: $$rownums ++;
12341: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12342: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12343: '</td><td class="LC_left_item"><table>';
12344: for (my $i=0; $i<@{$fields}; $i++) {
12345: my $rem = $i%($numinrow);
12346: if ($rem == 0) {
12347: if ($i > 0) {
12348: $datatable .= '</tr>';
12349: }
12350: $datatable .= '<tr>';
12351: }
12352: my $check = ' ';
1.39 raeburn 12353: if (ref($settings) eq 'HASH') {
12354: if (ref($settings->{'fields'}) eq 'HASH') {
12355: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12356: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12357: $check = ' checked="checked" ';
12358: }
1.3 raeburn 12359: }
12360: }
12361: }
12362:
12363: if ($i == @{$fields}-1) {
12364: my $colsleft = $numinrow - $rem;
12365: if ($colsleft > 1) {
12366: $datatable .= '<td colspan="'.$colsleft.'">';
12367: } else {
12368: $datatable .= '<td>';
12369: }
12370: } else {
12371: $datatable .= '<td>';
12372: }
1.8 raeburn 12373: $datatable .= '<span class="LC_nobreak"><label>'.
12374: '<input type="checkbox" name="updateable_'.$type.
12375: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12376: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12377: }
12378: $datatable .= '</tr></table></td></tr>';
12379: }
12380: }
12381: return $datatable;
1.1 raeburn 12382: }
12383:
12384: sub modify_login {
1.205 raeburn 12385: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12386: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12387: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12388: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12389: %title = ( coursecatalog => 'Display course catalog',
12390: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12391: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12392: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12393: loginheader => 'Log-in box header',
12394: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12395: @offon = ('off','on');
1.112 raeburn 12396: if (ref($domconfig{login}) eq 'HASH') {
12397: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12398: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12399: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12400: }
12401: }
1.386 raeburn 12402: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12403: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12404: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12405: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12406: $saml{$lonhost} = 1;
12407: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12408: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12409: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12410: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12411: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12412: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12413: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12414: }
12415: }
12416: }
1.112 raeburn 12417: }
1.9 raeburn 12418: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12419: \%domconfig,\%loginhash);
1.188 raeburn 12420: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12421: foreach my $item (@toggles) {
12422: $loginhash{login}{$item} = $env{'form.'.$item};
12423: }
1.41 raeburn 12424: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12425: if (ref($colchanges{'login'}) eq 'HASH') {
12426: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12427: \%loginhash);
12428: }
1.110 raeburn 12429:
1.149 raeburn 12430: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12431: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12432: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12433: if (keys(%servers) > 1) {
12434: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12435: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12436: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12437: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12438: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12439: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12440: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12441: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12442: $changes{'loginvia'}{$lonhost} = 1;
12443: } else {
12444: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12445: $changes{'loginvia'}{$lonhost} = 1;
12446: }
12447: } else {
12448: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12449: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12450: $changes{'loginvia'}{$lonhost} = 1;
12451: }
12452: }
12453: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12454: foreach my $item (@loginvia_attribs) {
12455: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12456: }
12457: } else {
12458: foreach my $item (@loginvia_attribs) {
12459: my $new = $env{'form.'.$lonhost.'_'.$item};
12460: if (($item eq 'serverpath') && ($new eq 'custom')) {
12461: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12462: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12463: $new = '/';
12464: }
12465: }
12466: if (($item eq 'custompath') &&
12467: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12468: $new = '';
12469: }
12470: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12471: $changes{'loginvia'}{$lonhost} = 1;
12472: }
12473: if ($item eq 'exempt') {
1.256 raeburn 12474: $new = &check_exempt_addresses($new);
1.128 raeburn 12475: }
12476: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12477: }
12478: }
1.112 raeburn 12479: } else {
1.128 raeburn 12480: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12481: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12482: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12483: foreach my $item (@loginvia_attribs) {
12484: my $new = $env{'form.'.$lonhost.'_'.$item};
12485: if (($item eq 'serverpath') && ($new eq 'custom')) {
12486: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12487: $new = '/';
12488: }
12489: }
12490: if (($item eq 'custompath') &&
12491: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12492: $new = '';
12493: }
12494: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12495: }
1.110 raeburn 12496: }
12497: }
12498: }
12499: }
1.119 raeburn 12500:
1.168 raeburn 12501: my $servadm = $r->dir_config('lonAdmEMail');
12502: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12503: if (ref($domconfig{'login'}) eq 'HASH') {
12504: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12505: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12506: if ($lang eq 'nolang') {
12507: push(@currlangs,$lang);
12508: } elsif (defined($langchoices{$lang})) {
12509: push(@currlangs,$lang);
12510: } else {
12511: next;
12512: }
12513: }
12514: }
12515: }
12516: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12517: if (@currlangs > 0) {
12518: foreach my $lang (@currlangs) {
12519: if (grep(/^\Q$lang\E$/,@delurls)) {
12520: $changes{'helpurl'}{$lang} = 1;
12521: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12522: $changes{'helpurl'}{$lang} = 1;
12523: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12524: push(@newlangs,$lang);
12525: } else {
12526: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12527: }
12528: }
12529: }
12530: unless (grep(/^nolang$/,@currlangs)) {
12531: if ($env{'form.loginhelpurl_nolang.filename'}) {
12532: $changes{'helpurl'}{'nolang'} = 1;
12533: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12534: push(@newlangs,'nolang');
12535: }
12536: }
12537: if ($env{'form.loginhelpurl_add_lang'}) {
12538: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12539: ($env{'form.loginhelpurl_add_file.filename'})) {
12540: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12541: $addedfile = $env{'form.loginhelpurl_add_lang'};
12542: }
12543: }
12544: if ((@newlangs > 0) || ($addedfile)) {
12545: my $error;
12546: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12547: if ($configuserok eq 'ok') {
12548: if ($switchserver) {
12549: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12550: } elsif ($author_ok eq 'ok') {
12551: my @allnew = @newlangs;
12552: if ($addedfile ne '') {
12553: push(@allnew,$addedfile);
12554: }
1.421 raeburn 12555: my $modified = [];
1.168 raeburn 12556: foreach my $lang (@allnew) {
12557: my $formelem = 'loginhelpurl_'.$lang;
12558: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12559: $formelem = 'loginhelpurl_add_file';
12560: }
1.425 raeburn 12561: (my $result,$newurl{$lang}) =
1.421 raeburn 12562: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12563: "help/$lang",'','',$newfile{$lang},
12564: $modified);
1.168 raeburn 12565: if ($result eq 'ok') {
12566: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12567: $changes{'helpurl'}{$lang} = 1;
12568: } else {
12569: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12570: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12571: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12572: (!grep(/^\Q$lang\E$/,@delurls))) {
12573: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12574: }
12575: }
12576: }
1.421 raeburn 12577: &update_modify_urls($r,$modified);
1.168 raeburn 12578: } else {
12579: $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);
12580: }
12581: } else {
12582: $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);
12583: }
12584: if ($error) {
12585: &Apache::lonnet::logthis($error);
12586: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12587: }
12588: }
1.256 raeburn 12589:
12590: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12591: if (ref($domconfig{'login'}) eq 'HASH') {
12592: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12593: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12594: if ($domservers{$lonhost}) {
12595: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12596: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12597: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12598: }
12599: }
12600: }
12601: }
12602: }
12603: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12604: foreach my $lonhost (sort(keys(%domservers))) {
12605: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12606: $changes{'headtag'}{$lonhost} = 1;
12607: } else {
12608: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12609: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12610: }
12611: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12612: push(@newhosts,$lonhost);
12613: } elsif ($currheadtagurls{$lonhost}) {
12614: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12615: if ($currexempt{$lonhost}) {
1.289 raeburn 12616: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12617: $changes{'headtag'}{$lonhost} = 1;
12618: }
12619: } elsif ($possexempt{$lonhost}) {
12620: $changes{'headtag'}{$lonhost} = 1;
12621: }
12622: if ($possexempt{$lonhost}) {
12623: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12624: }
12625: }
12626: }
12627: }
12628: if (@newhosts) {
12629: my $error;
12630: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12631: if ($configuserok eq 'ok') {
12632: if ($switchserver) {
12633: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12634: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12635: my $modified = [];
1.256 raeburn 12636: foreach my $lonhost (@newhosts) {
12637: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12638: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12639: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12640: "login/headtag/$lonhost",'','',
12641: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12642: $modified);
1.256 raeburn 12643: if ($result eq 'ok') {
12644: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12645: $changes{'headtag'}{$lonhost} = 1;
12646: if ($possexempt{$lonhost}) {
12647: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12648: }
12649: } else {
12650: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12651: $newheadtagurls{$lonhost},$result);
12652: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12653: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12654: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12655: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12656: }
12657: }
12658: }
1.421 raeburn 12659: &update_modify_urls($r,$modified);
1.256 raeburn 12660: } else {
12661: $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);
12662: }
12663: } else {
12664: $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);
12665: }
12666: if ($error) {
12667: &Apache::lonnet::logthis($error);
12668: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12669: }
12670: }
1.386 raeburn 12671: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12672: my @newsamlimgs;
12673: foreach my $lonhost (keys(%domservers)) {
12674: if ($env{'form.saml_'.$lonhost}) {
12675: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12676: push(@newsamlimgs,$lonhost);
12677: }
1.412 raeburn 12678: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12679: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12680: }
12681: if ($saml{$lonhost}) {
1.412 raeburn 12682: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12683: $env{'form.saml_window_'.$lonhost} = '';
12684: }
1.386 raeburn 12685: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12686: #FIXME Need to obsolete published image
12687: delete($currsaml{$lonhost}{'img'});
12688: $changes{'saml'}{$lonhost} = 1;
12689: }
12690: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12691: $changes{'saml'}{$lonhost} = 1;
12692: }
12693: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12694: $changes{'saml'}{$lonhost} = 1;
12695: }
12696: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12697: $changes{'saml'}{$lonhost} = 1;
12698: }
12699: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12700: $changes{'saml'}{$lonhost} = 1;
12701: }
1.412 raeburn 12702: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12703: $changes{'saml'}{$lonhost} = 1;
12704: }
1.386 raeburn 12705: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12706: $changes{'saml'}{$lonhost} = 1;
12707: }
12708: } else {
12709: $changes{'saml'}{$lonhost} = 1;
12710: }
1.412 raeburn 12711: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12712: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12713: }
12714: } else {
1.425 raeburn 12715: if ($saml{$lonhost}) {
1.389 raeburn 12716: $changes{'saml'}{$lonhost} = 1;
12717: delete($currsaml{$lonhost});
12718: }
1.386 raeburn 12719: }
12720: }
12721: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12722: unless (exists($domservers{$posshost})) {
12723: delete($currsaml{$posshost});
1.386 raeburn 12724: }
12725: }
12726: %{$loginhash{'login'}{'saml'}} = %currsaml;
12727: if (@newsamlimgs) {
12728: my $error;
12729: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12730: if ($configuserok eq 'ok') {
12731: if ($switchserver) {
12732: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12733: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12734: my $modified = [];
1.386 raeburn 12735: foreach my $lonhost (@newsamlimgs) {
12736: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12737: my ($result,$imgurl) =
1.421 raeburn 12738: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12739: "login/saml/$lonhost",'','',
12740: $env{'form.saml_img_'.$lonhost.'.filename'},
12741: $modified);
1.386 raeburn 12742: if ($result eq 'ok') {
12743: $currsaml{$lonhost}{'img'} = $imgurl;
12744: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12745: $changes{'saml'}{$lonhost} = 1;
12746: } else {
12747: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12748: $lonhost,$result);
12749: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12750: }
12751: }
1.421 raeburn 12752: &update_modify_urls($r,$modified);
1.386 raeburn 12753: } else {
12754: $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);
12755: }
12756: } else {
12757: $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);
12758: }
12759: if ($error) {
12760: &Apache::lonnet::logthis($error);
12761: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12762: }
12763: }
1.169 raeburn 12764: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12765:
12766: my $defaulthelpfile = '/adm/loginproblems.html';
12767: my $defaulttext = &mt('Default in use');
12768:
1.1 raeburn 12769: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12770: $dom);
12771: if ($putresult eq 'ok') {
1.188 raeburn 12772: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12773: my %defaultchecked = (
12774: 'coursecatalog' => 'on',
1.188 raeburn 12775: 'helpdesk' => 'on',
1.42 raeburn 12776: 'adminmail' => 'off',
1.43 raeburn 12777: 'newuser' => 'off',
1.42 raeburn 12778: );
1.55 raeburn 12779: if (ref($domconfig{'login'}) eq 'HASH') {
12780: foreach my $item (@toggles) {
12781: if ($defaultchecked{$item} eq 'on') {
12782: if (($domconfig{'login'}{$item} eq '0') &&
12783: ($env{'form.'.$item} eq '1')) {
12784: $changes{$item} = 1;
12785: } elsif (($domconfig{'login'}{$item} eq '' ||
12786: $domconfig{'login'}{$item} eq '1') &&
12787: ($env{'form.'.$item} eq '0')) {
12788: $changes{$item} = 1;
12789: }
12790: } elsif ($defaultchecked{$item} eq 'off') {
12791: if (($domconfig{'login'}{$item} eq '1') &&
12792: ($env{'form.'.$item} eq '0')) {
12793: $changes{$item} = 1;
12794: } elsif (($domconfig{'login'}{$item} eq '' ||
12795: $domconfig{'login'}{$item} eq '0') &&
12796: ($env{'form.'.$item} eq '1')) {
12797: $changes{$item} = 1;
12798: }
1.42 raeburn 12799: }
12800: }
1.41 raeburn 12801: }
1.6 raeburn 12802: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12803: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12804: if (exists($changes{'saml'})) {
12805: my $hostid_in_use;
12806: my @hosts = &Apache::lonnet::current_machine_ids();
12807: if (@hosts > 1) {
12808: foreach my $hostid (@hosts) {
12809: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12810: $hostid_in_use = $hostid;
12811: last;
12812: }
12813: }
12814: } else {
12815: $hostid_in_use = $r->dir_config('lonHostID');
12816: }
12817: if (($hostid_in_use) &&
12818: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12819: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12820: }
12821: if (ref($lastactref) eq 'HASH') {
12822: if (ref($changes{'saml'}) eq 'HASH') {
12823: my %updates;
12824: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12825: $lastactref->{'samllanding'} = \%updates;
12826: }
12827: }
12828: }
1.212 raeburn 12829: if (ref($lastactref) eq 'HASH') {
12830: $lastactref->{'domainconfig'} = 1;
12831: }
1.1 raeburn 12832: $resulttext = &mt('Changes made:').'<ul>';
12833: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12834: if ($item eq 'loginvia') {
1.112 raeburn 12835: if (ref($changes{$item}) eq 'HASH') {
12836: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12837: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12838: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12839: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12840: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12841: $protocol = 'http' if ($protocol ne 'https');
12842: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12843:
12844: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12845: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12846: } else {
12847: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12848: }
12849: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12850: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12851: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12852: }
12853: $resulttext .= '</li>';
12854: } else {
12855: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12856: }
1.112 raeburn 12857: } else {
1.128 raeburn 12858: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12859: }
12860: }
1.128 raeburn 12861: $resulttext .= '</ul></li>';
1.112 raeburn 12862: }
1.168 raeburn 12863: } elsif ($item eq 'helpurl') {
12864: if (ref($changes{$item}) eq 'HASH') {
12865: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12866: if (grep(/^\Q$lang\E$/,@delurls)) {
12867: my ($chg,$link);
12868: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12869: if ($lang eq 'nolang') {
12870: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12871: } else {
12872: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12873: }
12874: $resulttext .= '<li>'.$chg.'</li>';
12875: } else {
12876: my $chg;
12877: if ($lang eq 'nolang') {
12878: $chg = &mt('custom log-in help file for no preferred language');
12879: } else {
12880: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12881: }
12882: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12883: $loginhash{'login'}{'helpurl'}{$lang}.
12884: '?inhibitmenu=yes',$chg,600,500).
12885: '</li>';
12886: }
12887: }
12888: }
1.256 raeburn 12889: } elsif ($item eq 'headtag') {
12890: if (ref($changes{$item}) eq 'HASH') {
12891: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12892: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12893: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12894: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12895: $resulttext .= '<li><a href="'.
12896: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12897: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12898: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12899: if ($possexempt{$lonhost}) {
12900: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12901: } else {
12902: $resulttext .= &mt('included for any client IP');
12903: }
12904: $resulttext .= '</li>';
12905: }
12906: }
12907: }
1.386 raeburn 12908: } elsif ($item eq 'saml') {
12909: if (ref($changes{$item}) eq 'HASH') {
12910: my %notlt = (
12911: text => 'Text for log-in by SSO',
12912: img => 'SSO button image',
12913: alt => 'Alt text for button image',
12914: url => 'SSO URL',
12915: title => 'Tooltip for SSO link',
1.412 raeburn 12916: window => 'Pop-up window if iframe',
1.386 raeburn 12917: notsso => 'Text for non-SSO log-in',
12918: );
12919: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12920: if (ref($currsaml{$lonhost}) eq 'HASH') {
12921: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12922: '<ul>';
1.412 raeburn 12923: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 12924: if ($currsaml{$lonhost}{$key} eq '') {
12925: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12926: } else {
12927: my $value = "'$currsaml{$lonhost}{$key}'";
12928: if ($key eq 'img') {
12929: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 12930: } elsif ($key eq 'window') {
12931: $value = 'On';
1.386 raeburn 12932: }
12933: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12934: $value).'</li>';
12935: }
12936: }
12937: $resulttext .= '</ul></li>';
12938: } else {
12939: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12940: }
12941: }
12942: }
1.169 raeburn 12943: } elsif ($item eq 'captcha') {
12944: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12945: my $chgtxt;
1.169 raeburn 12946: if ($loginhash{'login'}{$item} eq 'notused') {
12947: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12948: } else {
12949: my %captchas = &captcha_phrases();
12950: if ($captchas{$loginhash{'login'}{$item}}) {
12951: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12952: } else {
12953: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12954: }
12955: }
12956: $resulttext .= '<li>'.$chgtxt.'</li>';
12957: }
12958: } elsif ($item eq 'recaptchakeys') {
12959: if (ref($loginhash{'login'}) eq 'HASH') {
12960: my ($privkey,$pubkey);
12961: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
12962: $pubkey = $loginhash{'login'}{$item}{'public'};
12963: $privkey = $loginhash{'login'}{$item}{'private'};
12964: }
12965: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
12966: if (!$pubkey) {
12967: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
12968: } else {
12969: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12970: }
12971: if (!$privkey) {
12972: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
12973: } else {
1.251 raeburn 12974: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 12975: }
12976: $chgtxt .= '</ul>';
12977: $resulttext .= '<li>'.$chgtxt.'</li>';
12978: }
1.269 raeburn 12979: } elsif ($item eq 'recaptchaversion') {
12980: if (ref($loginhash{'login'}) eq 'HASH') {
12981: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 12982: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 12983: '</li>';
12984: }
12985: }
1.41 raeburn 12986: } else {
12987: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
12988: }
1.1 raeburn 12989: }
1.6 raeburn 12990: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 12991: } else {
12992: $resulttext = &mt('No changes made to log-in page settings');
12993: }
12994: } else {
1.11 albertel 12995: $resulttext = '<span class="LC_error">'.
12996: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12997: }
1.6 raeburn 12998: if ($errors) {
1.9 raeburn 12999: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 13000: $errors.'</ul>';
13001: }
13002: return $resulttext;
13003: }
13004:
1.256 raeburn 13005: sub check_exempt_addresses {
13006: my ($iplist) = @_;
13007: $iplist =~ s/^\s+//;
13008: $iplist =~ s/\s+$//;
13009: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
13010: my (@okips,$new);
13011: foreach my $ip (@poss_ips) {
13012: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
13013: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
13014: push(@okips,$ip);
13015: }
13016: }
13017: }
13018: if (@okips > 0) {
13019: $new = join(',',@okips);
13020: } else {
13021: $new = '';
13022: }
13023: return $new;
13024: }
13025:
1.6 raeburn 13026: sub color_font_choices {
13027: my %choices =
13028: &Apache::lonlocal::texthash (
13029: bgs => "Background colors",
13030: links => "Link colors",
1.55 raeburn 13031: images => "Images",
1.6 raeburn 13032: font => "Font color",
1.201 raeburn 13033: fontmenu => "Font menu",
1.76 raeburn 13034: pgbg => "Page",
1.6 raeburn 13035: tabbg => "Header",
13036: sidebg => "Border",
13037: link => "Link",
13038: alink => "Active link",
13039: vlink => "Visited link",
13040: );
13041: return %choices;
13042: }
13043:
1.394 raeburn 13044: sub modify_ipaccess {
13045: my ($dom,$lastactref,%domconfig) = @_;
13046: my (@allpos,%changes,%confhash,$errors,$resulttext);
13047: my (@items,%deletions,%itemids,@warnings);
13048: my ($typeorder,$types) = &commblocktype_text();
13049: if ($env{'form.ipaccess_add'}) {
13050: my $name = $env{'form.ipaccess_name_add'};
13051: my ($newid,$error) = &get_ipaccess_id($dom,$name);
13052: if ($newid) {
13053: $itemids{'add'} = $newid;
13054: push(@items,'add');
13055: $changes{$newid} = 1;
13056: } else {
13057: $error = &mt('Failed to acquire unique ID for new IP access control item');
13058: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13059: }
13060: }
13061: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13062: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13063: if (@todelete) {
13064: map { $deletions{$_} = 1; } @todelete;
13065: }
13066: my $maxnum = $env{'form.ipaccess_maxnum'};
13067: for (my $i=0; $i<$maxnum; $i++) {
13068: my $itemid = $env{'form.ipaccess_id_'.$i};
13069: $itemid =~ s/\D+//g;
13070: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13071: if ($deletions{$itemid}) {
13072: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13073: } else {
13074: push(@items,$i);
13075: $itemids{$i} = $itemid;
13076: }
13077: }
13078: }
13079: }
13080: foreach my $idx (@items) {
13081: my $itemid = $itemids{$idx};
13082: next unless ($itemid);
1.446 raeburn 13083: my ($position,%current);
13084: if ($idx eq 'add') {
13085: $position = $env{'form.ipaccess_pos_add'};
13086: } else {
13087: $position = $env{'form.ipaccess_pos_'.$itemid};
1.394 raeburn 13088: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13089: %current = %{$domconfig{'ipaccess'}{$itemid}};
13090: }
13091: }
13092: $position =~ s/\D+//g;
13093: if ($position ne '') {
13094: $allpos[$position] = $itemid;
13095: }
13096: my $name = $env{'form.ipaccess_name_'.$idx};
13097: $name =~ s/^\s+|\s+$//g;
13098: $confhash{$itemid}{'name'} = $name;
13099: my $possrange = $env{'form.ipaccess_range_'.$idx};
13100: $possrange =~ s/^\s+|\s+$//g;
13101: unless ($possrange eq '') {
13102: $possrange =~ s/[\r\n]+/\s/g;
13103: $possrange =~ s/\s*-\s*/-/g;
13104: $possrange =~ s/\s+/,/g;
13105: $possrange =~ s/,+/,/g;
13106: if ($possrange ne '') {
13107: my (@ok,$count);
1.425 raeburn 13108: $count = 0;
1.394 raeburn 13109: foreach my $poss (split(/\,/,$possrange)) {
13110: $count ++;
13111: $poss = &validate_ip_pattern($poss);
13112: if ($poss ne '') {
13113: push(@ok,$poss);
13114: }
13115: }
13116: my $diff = $count - scalar(@ok);
13117: if ($diff) {
13118: $errors .= '<li><span class="LC_error">'.
13119: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13120: $diff,$name).
13121: '</span></li>';
13122: }
13123: if (@ok) {
13124: my @cidr_list;
13125: foreach my $item (@ok) {
13126: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13127: }
13128: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13129: }
13130: }
13131: }
13132: foreach my $field ('name','ip') {
13133: unless (($idx eq 'add') || ($changes{$itemid})) {
13134: if ($current{$field} ne $confhash{$itemid}{$field}) {
13135: $changes{$itemid} = 1;
13136: last;
13137: }
13138: }
13139: }
13140: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13141:
1.394 raeburn 13142: my %commblocks;
1.425 raeburn 13143: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13144: foreach my $type (@{$typeorder}) {
13145: if ($commblocks{$type}) {
13146: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13147: }
13148: unless (($idx eq 'add') || ($changes{$itemid})) {
13149: if (ref($current{'commblocks'}) eq 'HASH') {
13150: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13151: $changes{$itemid} = 1;
13152: }
13153: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13154: $changes{$itemid} = 1;
13155: }
13156: }
13157: }
13158: $confhash{$itemid}{'courses'} = {};
13159: my %crsdeletions;
13160: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13161: if (@delcrs) {
13162: map { $crsdeletions{$_} = 1; } @delcrs;
13163: }
13164: if (ref($current{'courses'}) eq 'HASH') {
13165: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13166: if ($crsdeletions{$cid}) {
13167: $changes{$itemid} = 1;
13168: } else {
13169: $confhash{$itemid}{'courses'}{$cid} = 1;
13170: }
13171: }
13172: }
13173: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13174: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13175: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13176: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13177: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13178: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13179: $errors .= '<li><span class="LC_error">'.
13180: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13181: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13182: '</span></li>';
13183: } else {
13184: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13185: $changes{$itemid} = 1;
13186: }
13187: }
13188: }
13189: if (@allpos > 0) {
13190: my $idx = 0;
13191: foreach my $itemid (@allpos) {
13192: if ($itemid ne '') {
13193: $confhash{$itemid}{'order'} = $idx;
13194: unless ($changes{$itemid}) {
13195: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13196: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13197: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13198: $changes{$itemid} = 1;
13199: }
13200: }
13201: }
13202: }
13203: $idx ++;
13204: }
13205: }
13206: }
13207: if (keys(%changes)) {
13208: my %defaultshash = (
13209: ipaccess => \%confhash,
13210: );
13211: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13212: $dom);
13213: if ($putresult eq 'ok') {
13214: my $cachetime = 1800;
13215: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13216: if (ref($lastactref) eq 'HASH') {
13217: $lastactref->{'ipaccess'} = 1;
13218: }
13219: $resulttext = &mt('Changes made:').'<ul>';
13220: my %bynum;
13221: foreach my $itemid (sort(keys(%changes))) {
13222: if (ref($confhash{$itemid}) eq 'HASH') {
13223: my $position = $confhash{$itemid}{'order'};
13224: if ($position =~ /^\d+$/) {
13225: $bynum{$position} = $itemid;
13226: }
13227: }
13228: }
13229: if (keys(%deletions)) {
13230: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13231: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13232: }
13233: }
13234: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13235: my $itemid = $bynum{$pos};
13236: if (ref($confhash{$itemid}) eq 'HASH') {
13237: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13238: my $position = $pos + 1;
13239: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13240: if ($confhash{$itemid}{'ip'} eq '') {
13241: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13242: } else {
13243: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13244: }
13245: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13246: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13247: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13248: '</li>';
13249: } else {
13250: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13251: }
13252: if (keys(%{$confhash{$itemid}{'courses'}})) {
13253: my @courses;
13254: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13255: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13256: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13257: }
13258: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13259: join('</li><li>',@courses).'</li></ul>';
13260: } else {
13261: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13262: }
1.395 raeburn 13263: $resulttext .= '</ul></li>';
1.394 raeburn 13264: }
13265: }
1.395 raeburn 13266: $resulttext .= '</ul>';
1.394 raeburn 13267: } else {
13268: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13269: }
13270: } else {
13271: $resulttext = &mt('No changes made');
13272: }
13273: if ($errors) {
13274: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13275: $errors.'</ul></p>';
13276: }
13277: return $resulttext;
13278: }
13279:
13280: sub get_ipaccess_id {
13281: my ($domain,$location) = @_;
13282: # get lock on ipaccess db
13283: my $lockhash = {
13284: lock => $env{'user.name'}.
13285: ':'.$env{'user.domain'},
13286: };
13287: my $tries = 0;
13288: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13289: my ($id,$error);
13290:
13291: while (($gotlock ne 'ok') && ($tries<10)) {
13292: $tries ++;
13293: sleep (0.1);
13294: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13295: }
13296: if ($gotlock eq 'ok') {
13297: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13298: if ($currids{'lock'}) {
13299: delete($currids{'lock'});
13300: if (keys(%currids)) {
13301: my @curr = sort { $a <=> $b } keys(%currids);
13302: if ($curr[-1] =~ /^\d+$/) {
13303: $id = 1 + $curr[-1];
13304: }
13305: } else {
13306: $id = 1;
13307: }
13308: if ($id) {
13309: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13310: $error = 'nostore';
13311: }
13312: } else {
13313: $error = 'nonumber';
13314: }
13315: }
13316: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13317: } else {
13318: $error = 'nolock';
13319: }
13320: return ($id,$error);
13321: }
13322:
1.429 raeburn 13323: sub modify_authordefaults {
13324: my ($dom,$lastactref,%domconfig) = @_;
13325: #
13326: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13327: #
13328: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13329: if (ref($domconfig{'quotas'}) eq 'HASH') {
13330: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13331: if ($key =~ /^webdav|authorquota$/) {
13332: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13333: } else {
13334: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13335: }
13336: }
13337: }
13338: my %staticdefaults = (
13339: 'copyright' => 'default',
13340: 'sourceavail' => 'closed',
13341: 'nocodemirror' => 'off',
1.437 raeburn 13342: 'daxecollapse' => 'off',
1.429 raeburn 13343: 'domcoordacc' => 'on',
1.439 raeburn 13344: 'editors' => ['edit','xml'],
1.429 raeburn 13345: 'authorquota' => 500,
13346: 'webdav' => 0,
1.440 raeburn 13347: 'archive' => 'off',
1.429 raeburn 13348: );
13349: my %titles = &authordefaults_titles();
1.440 raeburn 13350: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.429 raeburn 13351: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13352: $confhash{$item} = $env{'form.'.$item};
13353: }
13354: }
13355: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13356: $confhash{'copyright'} = $1;
13357: }
13358: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13359: $confhash{'sourceavail'} = $1;
13360: }
13361: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13362: my @okeditors = ('edit','xml','daxe');
13363: my @editors;
13364: foreach my $item (@posseditors) {
13365: if (grep(/^\Q$item\E$/,@okeditors)) {
13366: push(@editors,$item);
13367: }
13368: }
13369: $confhash{'editors'} = \@editors;
1.436 raeburn 13370:
1.429 raeburn 13371: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13372: my @insttypes;
13373: if (ref($types) eq 'ARRAY') {
13374: @insttypes = @{$types};
13375: }
13376: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13377: my %webdav;
13378: map { $webdav{$_} = 1; } @webdavon;
13379: foreach my $type (@insttypes,'default') {
13380: my $possquota = $env{'form.authorquota_'.$type};
13381: if ($possquota =~ /^\d+$/) {
13382: $save_quotas{'authorquota'}{$type} = $possquota;
13383: }
13384: if ($webdav{$type}) {
13385: $save_quotas{'webdav'}{$type} = 1;
13386: } else {
13387: $save_quotas{'webdav'}{$type} = 0;
13388: }
13389: }
13390: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13391: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13392: }
13393: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
1.440 raeburn 13394: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail','archive') {
1.429 raeburn 13395: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13396: $changes{$item} = 1;
13397: }
13398: }
13399: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
1.436 raeburn 13400: my @diffs =
1.429 raeburn 13401: &Apache::loncommon::compare_arrays($confhash{'editors'},
13402: $domconfig{'authordefaults'}{'editors'});
13403: unless (@diffs == 0) {
13404: $changes{'editors'} = 1;
13405: }
13406: } else {
13407: my @diffs =
13408: &Apache::loncommon::compare_arrays($confhash{'editors'},
13409: $staticdefaults{'editors'});
13410: unless (@diffs == 0) {
13411: $changes{'editors'} = 1;
13412: }
13413: }
13414: } else {
13415: my @offon = ('off','on');
1.440 raeburn 13416: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.436 raeburn 13417: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
1.429 raeburn 13418: $changes{$item} = 1;
13419: }
13420: }
13421: foreach my $item ('copyright','sourceavail') {
13422: if ($confhash{$item} ne $staticdefaults{$item}) {
13423: $changes{$item} = 1;
13424: }
13425: }
1.439 raeburn 13426: my @diffs =
13427: &Apache::loncommon::compare_arrays($confhash{'editors'},
13428: $staticdefaults{'editors'});
13429: unless (@diffs == 0) {
13430: $changes{'editors'} = 1;
13431: }
1.429 raeburn 13432: }
13433: foreach my $key ('authorquota','webdav') {
13434: if (ref($curr_quotas{$key}) eq 'HASH') {
13435: foreach my $type (@insttypes,'default') {
13436: if (exists($save_quotas{$key}{$type})) {
13437: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13438: $changes{$key}{$type} = 1;
13439: }
13440: } elsif (exists($curr_quotas{$key}{$type})) {
13441: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13442: } else {
13443: $save_quotas{$key}{$type} = $staticdefaults{$key};
13444: }
13445: }
13446: } else {
13447: foreach my $type (@insttypes,'default') {
13448: if (exists($save_quotas{$key}{$type})) {
13449: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13450: $changes{$key}{$type} = 1;
13451: }
13452: } else {
13453: $save_quotas{$key}{$type} = $staticdefaults{$key};
13454: }
13455: }
13456: }
13457: }
13458: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13459: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
1.436 raeburn 13460: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
1.429 raeburn 13461: $changes{'webdav_LC_adv'} = 1;
13462: }
13463: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13464: $changes{'webdav_LC_adv'} = 1;
13465: }
13466: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13467: $changes{'webdav_LC_adv'} = 1;
13468: }
13469: my %confighash = (
13470: quotas => \%save_quotas,
13471: authordefaults => \%confhash,
13472: );
13473: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13474: $dom);
13475: my $resulttext;
13476: if ($putresult eq 'ok') {
13477: if (keys(%changes)) {
1.431 raeburn 13478: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13479: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
1.436 raeburn 13480: ($changes{'webdav_LC_adv'})) {
1.429 raeburn 13481: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13482: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13483: }
13484: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13485: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13486: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13487: }
13488: }
13489: $resulttext = &mt('Changes made:').'<ul>';
13490: my $authoroverride;
1.437 raeburn 13491: foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
1.429 raeburn 13492: if (exists($changes{$key})) {
1.431 raeburn 13493: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13494: my $shown;
13495: unless ($authoroverride) {
13496: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13497: $authoroverride = 1;
13498: }
1.437 raeburn 13499: if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
1.429 raeburn 13500: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13501: } elsif ($key eq 'copyright') {
13502: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13503: } elsif ($key eq 'sourceavail') {
13504: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13505: }
1.436 raeburn 13506: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.429 raeburn 13507: }
13508: }
13509: if ($authoroverride) {
13510: $resulttext .= '</ul></li>';
13511: }
13512: my $domcoordoverride;
1.440 raeburn 13513: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv','archive') {
1.429 raeburn 13514: if (exists($changes{$key})) {
13515: my $shown;
13516: unless ($domcoordoverride) {
13517: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13518: $domcoordoverride = 1;
13519: }
13520: if ($key eq 'editors') {
1.431 raeburn 13521: if (ref($confhash{'editors'}) eq 'ARRAY') {
13522: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
13523: if (@{$confhash{'editors'}}) {
13524: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
13525: } else {
13526: $shown = &mt('None');
13527: }
1.429 raeburn 13528: }
13529: } elsif ($key eq 'authorquota') {
13530: foreach my $type (@insttypes) {
13531: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13532: }
13533: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13534: } elsif ($key eq 'webdav') {
13535: foreach my $type (@insttypes) {
13536: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13537: }
13538: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13539: } elsif ($key eq 'webdav_LC_adv') {
13540: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13541: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13542: } else {
13543: $shown = $titles{'none'};
13544: }
1.440 raeburn 13545: } elsif ($key eq 'archive') {
1.441 raeburn 13546: $domdefaults{$key} = $confhash{$key};
1.440 raeburn 13547: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
1.429 raeburn 13548: }
13549: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.436 raeburn 13550: }
1.429 raeburn 13551: }
13552: if ($domcoordoverride) {
13553: $resulttext .= '</ul></li>';
13554: }
1.439 raeburn 13555: $resulttext .= '</ul>';
1.431 raeburn 13556: my $cachetime = 24*60*60;
13557: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13558: if (ref($lastactref) eq 'HASH') {
13559: $lastactref->{'domdefaults'} = 1;
13560: }
1.429 raeburn 13561: } else {
13562: $resulttext = &mt('No changes made to Authoring Space defaults');
13563: }
13564: }
13565: return $resulttext;
13566: }
13567:
1.6 raeburn 13568: sub modify_rolecolors {
1.205 raeburn 13569: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13570: my ($resulttext,%rolehash);
13571: $rolehash{'rolecolors'} = {};
1.55 raeburn 13572: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13573: if ($domconfig{'rolecolors'} eq '') {
13574: $domconfig{'rolecolors'} = {};
13575: }
13576: }
1.9 raeburn 13577: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13578: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13579: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13580: $dom);
13581: if ($putresult eq 'ok') {
13582: if (keys(%changes) > 0) {
1.41 raeburn 13583: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13584: if (ref($lastactref) eq 'HASH') {
13585: $lastactref->{'domainconfig'} = 1;
13586: }
1.6 raeburn 13587: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13588: $rolehash{'rolecolors'});
13589: } else {
13590: $resulttext = &mt('No changes made to default color schemes');
13591: }
13592: } else {
1.11 albertel 13593: $resulttext = '<span class="LC_error">'.
13594: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13595: }
13596: if ($errors) {
13597: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13598: $errors.'</ul>';
13599: }
13600: return $resulttext;
13601: }
13602:
13603: sub modify_colors {
1.9 raeburn 13604: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13605: my (%changes,%choices);
1.51 raeburn 13606: my @bgs;
1.6 raeburn 13607: my @links = ('link','alink','vlink');
1.41 raeburn 13608: my @logintext;
1.6 raeburn 13609: my @images;
13610: my $servadm = $r->dir_config('lonAdmEMail');
13611: my $errors;
1.200 raeburn 13612: my %defaults;
1.6 raeburn 13613: foreach my $role (@{$roles}) {
13614: if ($role eq 'login') {
1.12 raeburn 13615: %choices = &login_choices();
1.41 raeburn 13616: @logintext = ('textcol','bgcol');
1.12 raeburn 13617: } else {
13618: %choices = &color_font_choices();
13619: }
13620: if ($role eq 'login') {
1.41 raeburn 13621: @images = ('img','logo','domlogo','login');
1.51 raeburn 13622: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13623: } else {
1.445 raeburn 13624: @images = ();
1.200 raeburn 13625: @bgs = ('pgbg','tabbg','sidebg');
13626: }
13627: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
1.444 raeburn 13628: $env{'form.'.$role.'_font'} = lc($env{'form.'.$role.'_font'});
13629: if ($env{'form.'.$role.'_font'} =~ /^\w+/) {
13630: $env{'form.'.$role.'_font'} = '#'.$env{'form.'.$role.'_font'};
13631: }
13632: unless ($env{'form.'.$role.'_font'} eq lc($defaults{'font'})) {
1.200 raeburn 13633: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13634: }
13635: if ($role eq 'login') {
13636: foreach my $item (@logintext) {
1.234 raeburn 13637: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13638: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13639: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13640: }
13641: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13642: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13643: }
13644: }
13645: } else {
1.234 raeburn 13646: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13647: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13648: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13649: }
1.445 raeburn 13650: unless ($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13651: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13652: }
1.6 raeburn 13653: }
1.200 raeburn 13654: foreach my $item (@bgs) {
1.234 raeburn 13655: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13656: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13657: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13658: }
13659: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13660: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13661: }
13662: }
13663: foreach my $item (@links) {
1.234 raeburn 13664: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13665: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13666: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13667: }
13668: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13669: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13670: }
1.6 raeburn 13671: }
1.46 raeburn 13672: my ($configuserok,$author_ok,$switchserver) =
13673: &config_check($dom,$confname,$servadm);
1.9 raeburn 13674: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13675: if (ref($domconfig->{$role}) ne 'HASH') {
13676: $domconfig->{$role} = {};
13677: }
1.8 raeburn 13678: foreach my $img (@images) {
1.402 raeburn 13679: if ($role eq 'login') {
13680: if (($img eq 'img') || ($img eq 'logo')) {
13681: if (defined($env{'form.login_showlogo_'.$img})) {
13682: $confhash->{$role}{'showlogo'}{$img} = 1;
13683: } else {
13684: $confhash->{$role}{'showlogo'}{$img} = 0;
13685: }
13686: }
13687: if ($env{'form.login_alt_'.$img} ne '') {
13688: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13689: }
1.402 raeburn 13690: }
1.18 albertel 13691: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13692: && !defined($domconfig->{$role}{$img})
13693: && !$env{'form.'.$role.'_del_'.$img}
13694: && $env{'form.'.$role.'_import_'.$img}) {
13695: # import the old configured image from the .tab setting
13696: # if they haven't provided a new one
13697: $domconfig->{$role}{$img} =
13698: $env{'form.'.$role.'_import_'.$img};
13699: }
1.6 raeburn 13700: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13701: my $error;
1.6 raeburn 13702: if ($configuserok eq 'ok') {
1.9 raeburn 13703: if ($switchserver) {
1.12 raeburn 13704: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13705: } else {
13706: if ($author_ok eq 'ok') {
1.421 raeburn 13707: my $modified = [];
1.9 raeburn 13708: my ($result,$logourl) =
1.421 raeburn 13709: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13710: $dom,$confname,$img,$width,$height,
13711: '',$modified);
1.9 raeburn 13712: if ($result eq 'ok') {
13713: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13714: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13715: &update_modify_urls($r,$modified);
1.9 raeburn 13716: } else {
1.12 raeburn 13717: $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 13718: }
13719: } else {
1.46 raeburn 13720: $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 13721: }
13722: }
13723: } else {
1.46 raeburn 13724: $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 13725: }
13726: if ($error) {
1.8 raeburn 13727: &Apache::lonnet::logthis($error);
1.11 albertel 13728: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13729: }
13730: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13731: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13732: my $error;
13733: if ($configuserok eq 'ok') {
13734: # is confname an author?
13735: if ($switchserver eq '') {
13736: if ($author_ok eq 'ok') {
1.421 raeburn 13737: my $modified = [];
1.9 raeburn 13738: my ($result,$logourl) =
1.421 raeburn 13739: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13740: $dom,$confname,$img,$width,$height,
13741: '',$modified);
1.9 raeburn 13742: if ($result eq 'ok') {
13743: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13744: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13745: &update_modify_urls($r,$modified);
1.9 raeburn 13746: }
13747: }
13748: }
13749: }
1.6 raeburn 13750: }
13751: }
13752: }
13753: if (ref($domconfig) eq 'HASH') {
13754: if (ref($domconfig->{$role}) eq 'HASH') {
13755: foreach my $img (@images) {
13756: if ($domconfig->{$role}{$img} ne '') {
13757: if ($env{'form.'.$role.'_del_'.$img}) {
13758: $confhash->{$role}{$img} = '';
1.12 raeburn 13759: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13760: } else {
1.9 raeburn 13761: if ($confhash->{$role}{$img} eq '') {
13762: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13763: }
1.6 raeburn 13764: }
13765: } else {
13766: if ($env{'form.'.$role.'_del_'.$img}) {
13767: $confhash->{$role}{$img} = '';
1.12 raeburn 13768: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13769: }
13770: }
1.402 raeburn 13771: if ($role eq 'login') {
13772: if (($img eq 'logo') || ($img eq 'img')) {
13773: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13774: if ($confhash->{$role}{'showlogo'}{$img} ne
13775: $domconfig->{$role}{'showlogo'}{$img}) {
13776: $changes{$role}{'showlogo'}{$img} = 1;
13777: }
13778: } else {
13779: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13780: $changes{$role}{'showlogo'}{$img} = 1;
13781: }
1.70 raeburn 13782: }
1.402 raeburn 13783: }
13784: if ($img ne 'login') {
13785: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13786: if ($confhash->{$role}{'alttext'}{$img} ne
13787: $domconfig->{$role}{'alttext'}{$img}) {
13788: $changes{$role}{'alttext'}{$img} = 1;
13789: }
13790: } else {
13791: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13792: $changes{$role}{'alttext'}{$img} = 1;
13793: }
1.70 raeburn 13794: }
13795: }
13796: }
13797: }
1.6 raeburn 13798: if ($domconfig->{$role}{'font'} ne '') {
13799: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13800: $changes{$role}{'font'} = 1;
13801: }
13802: } else {
13803: if ($confhash->{$role}{'font'}) {
13804: $changes{$role}{'font'} = 1;
13805: }
13806: }
1.107 raeburn 13807: if ($role ne 'login') {
13808: if ($domconfig->{$role}{'fontmenu'} ne '') {
13809: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13810: $changes{$role}{'fontmenu'} = 1;
13811: }
13812: } else {
13813: if ($confhash->{$role}{'fontmenu'}) {
13814: $changes{$role}{'fontmenu'} = 1;
13815: }
1.97 tempelho 13816: }
13817: }
1.6 raeburn 13818: foreach my $item (@bgs) {
13819: if ($domconfig->{$role}{$item} ne '') {
13820: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13821: $changes{$role}{'bgs'}{$item} = 1;
13822: }
13823: } else {
13824: if ($confhash->{$role}{$item}) {
13825: $changes{$role}{'bgs'}{$item} = 1;
13826: }
13827: }
13828: }
13829: foreach my $item (@links) {
13830: if ($domconfig->{$role}{$item} ne '') {
13831: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13832: $changes{$role}{'links'}{$item} = 1;
13833: }
13834: } else {
13835: if ($confhash->{$role}{$item}) {
13836: $changes{$role}{'links'}{$item} = 1;
13837: }
13838: }
13839: }
1.41 raeburn 13840: foreach my $item (@logintext) {
13841: if ($domconfig->{$role}{$item} ne '') {
13842: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13843: $changes{$role}{'logintext'}{$item} = 1;
13844: }
13845: } else {
13846: if ($confhash->{$role}{$item}) {
13847: $changes{$role}{'logintext'}{$item} = 1;
13848: }
13849: }
13850: }
1.6 raeburn 13851: } else {
13852: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13853: \@logintext,$confhash,\%changes);
1.6 raeburn 13854: }
13855: } else {
13856: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13857: \@logintext,$confhash,\%changes);
1.6 raeburn 13858: }
13859: }
13860: return ($errors,%changes);
13861: }
13862:
1.46 raeburn 13863: sub config_check {
13864: my ($dom,$confname,$servadm) = @_;
13865: my ($configuserok,$author_ok,$switchserver,%currroles);
13866: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13867: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13868: $confname,$servadm);
13869: if ($configuserok eq 'ok') {
13870: $switchserver = &check_switchserver($dom,$confname);
13871: if ($switchserver eq '') {
13872: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13873: }
13874: }
13875: return ($configuserok,$author_ok,$switchserver);
13876: }
13877:
1.6 raeburn 13878: sub default_change_checker {
1.41 raeburn 13879: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13880: foreach my $item (@{$links}) {
13881: if ($confhash->{$role}{$item}) {
13882: $changes->{$role}{'links'}{$item} = 1;
13883: }
13884: }
13885: foreach my $item (@{$bgs}) {
13886: if ($confhash->{$role}{$item}) {
13887: $changes->{$role}{'bgs'}{$item} = 1;
13888: }
13889: }
1.41 raeburn 13890: foreach my $item (@{$logintext}) {
13891: if ($confhash->{$role}{$item}) {
13892: $changes->{$role}{'logintext'}{$item} = 1;
13893: }
13894: }
1.6 raeburn 13895: foreach my $img (@{$images}) {
13896: if ($env{'form.'.$role.'_del_'.$img}) {
13897: $confhash->{$role}{$img} = '';
1.12 raeburn 13898: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13899: }
1.70 raeburn 13900: if ($role eq 'login') {
13901: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13902: $changes->{$role}{'showlogo'}{$img} = 1;
13903: }
1.402 raeburn 13904: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13905: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13906: $changes->{$role}{'alttext'}{$img} = 1;
13907: }
13908: }
1.70 raeburn 13909: }
1.6 raeburn 13910: }
13911: if ($confhash->{$role}{'font'}) {
13912: $changes->{$role}{'font'} = 1;
13913: }
1.48 raeburn 13914: }
1.6 raeburn 13915:
13916: sub display_colorchgs {
13917: my ($dom,$changes,$roles,$confhash) = @_;
13918: my (%choices,$resulttext);
13919: if (!grep(/^login$/,@{$roles})) {
13920: $resulttext = &mt('Changes made:').'<br />';
13921: }
13922: foreach my $role (@{$roles}) {
13923: if ($role eq 'login') {
13924: %choices = &login_choices();
13925: } else {
13926: %choices = &color_font_choices();
13927: }
13928: if (ref($changes->{$role}) eq 'HASH') {
13929: if ($role ne 'login') {
13930: $resulttext .= '<h4>'.&mt($role).'</h4>';
13931: }
13932: foreach my $key (sort(keys(%{$changes->{$role}}))) {
13933: if ($role ne 'login') {
13934: $resulttext .= '<ul>';
13935: }
13936: if (ref($changes->{$role}{$key}) eq 'HASH') {
13937: if ($role ne 'login') {
13938: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
13939: }
13940: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 13941: if (($role eq 'login') && ($key eq 'showlogo')) {
13942: if ($confhash->{$role}{$key}{$item}) {
13943: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
13944: } else {
13945: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
13946: }
1.402 raeburn 13947: } elsif (($role eq 'login') && ($key eq 'alttext')) {
13948: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 13949: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 13950: $confhash->{$role}{$key}{$item}).'</li>';
13951: } else {
13952: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
13953: }
1.70 raeburn 13954: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 13955: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
13956: } else {
1.12 raeburn 13957: my $newitem = $confhash->{$role}{$item};
13958: if ($key eq 'images') {
1.306 raeburn 13959: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 13960: }
13961: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 13962: }
13963: }
13964: if ($role ne 'login') {
13965: $resulttext .= '</ul></li>';
13966: }
13967: } else {
13968: if ($confhash->{$role}{$key} eq '') {
13969: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
13970: } else {
13971: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
13972: }
13973: }
13974: if ($role ne 'login') {
13975: $resulttext .= '</ul>';
13976: }
13977: }
13978: }
13979: }
1.3 raeburn 13980: return $resulttext;
1.1 raeburn 13981: }
13982:
1.9 raeburn 13983: sub thumb_dimensions {
13984: return ('200','50');
13985: }
13986:
1.16 raeburn 13987: sub check_dimensions {
13988: my ($inputfile) = @_;
13989: my ($fullwidth,$fullheight);
13990: if ($inputfile =~ m|^[/\w.\-]+$|) {
13991: if (open(PIPE,"identify $inputfile 2>&1 |")) {
13992: my $imageinfo = <PIPE>;
13993: if (!close(PIPE)) {
13994: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
13995: }
13996: chomp($imageinfo);
13997: my ($fullsize) =
1.21 raeburn 13998: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 13999: if ($fullsize) {
14000: ($fullwidth,$fullheight) = split(/x/,$fullsize);
14001: }
14002: }
14003: }
14004: return ($fullwidth,$fullheight);
14005: }
14006:
1.9 raeburn 14007: sub check_configuser {
14008: my ($uhome,$dom,$confname,$servadm) = @_;
14009: my ($configuserok,%currroles);
14010: if ($uhome eq 'no_host') {
14011: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 14012: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 14013: $configuserok =
14014: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
14015: $configpass,'','','','','',undef,$servadm);
14016: } else {
14017: $configuserok = 'ok';
14018: %currroles =
14019: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
14020: }
14021: return ($configuserok,%currroles);
14022: }
14023:
14024: sub check_authorstatus {
14025: my ($dom,$confname,%currroles) = @_;
14026: my $author_ok;
1.40 raeburn 14027: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 14028: my $start = time;
14029: my $end = 0;
14030: $author_ok =
14031: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 14032: 'au',$end,$start,'','','domconfig');
1.9 raeburn 14033: } else {
14034: $author_ok = 'ok';
14035: }
14036: return $author_ok;
14037: }
14038:
1.421 raeburn 14039: sub update_modify_urls {
14040: my ($r,$modified) = @_;
14041: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
14042: push(@{$modified_urls},$modified);
14043: unless ($registered_cleanup) {
14044: my $handlers = $r->get_handlers('PerlCleanupHandler');
14045: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
14046: $registered_cleanup=1;
1.9 raeburn 14047: }
14048: }
1.155 raeburn 14049: }
14050:
14051: sub notifysubscribed {
14052: foreach my $targetsource (@{$modified_urls}){
14053: next unless (ref($targetsource) eq 'ARRAY');
14054: my ($target,$source)=@{$targetsource};
14055: if ($source ne '') {
1.316 raeburn 14056: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 14057: print $logfh "\nCleanup phase: Notifications\n";
14058: my @subscribed=&subscribed_hosts($target);
14059: foreach my $subhost (@subscribed) {
14060: print $logfh "\nNotifying host ".$subhost.':';
14061: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
14062: print $logfh $reply;
14063: }
14064: my @subscribedmeta=&subscribed_hosts("$target.meta");
14065: foreach my $subhost (@subscribedmeta) {
14066: print $logfh "\nNotifying host for metadata only ".$subhost.':';
14067: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
14068: $subhost);
14069: print $logfh $reply;
14070: }
14071: print $logfh "\n============ Done ============\n";
1.160 raeburn 14072: close($logfh);
1.155 raeburn 14073: }
14074: }
14075: }
14076: return OK;
14077: }
14078:
14079: sub subscribed_hosts {
14080: my ($target) = @_;
14081: my @subscribed;
1.316 raeburn 14082: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 14083: while (my $subline=<$fh>) {
14084: if ($subline =~ /^($match_lonid):/) {
14085: my $host = $1;
14086: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
14087: unless (grep(/^\Q$host\E$/,@subscribed)) {
14088: push(@subscribed,$host);
14089: }
14090: }
14091: }
14092: }
14093: }
14094: return @subscribed;
1.9 raeburn 14095: }
14096:
14097: sub check_switchserver {
14098: my ($dom,$confname) = @_;
1.424 raeburn 14099: my ($allowed,$switchserver,$home);
14100: if ($confname eq '') {
1.9 raeburn 14101: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14102: } else {
14103: $home = &Apache::lonnet::homeserver($confname,$dom);
14104: if ($home eq 'no_host') {
14105: $home = &Apache::lonnet::domain($dom,'primary');
14106: }
1.9 raeburn 14107: }
14108: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14109: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14110: if (!$allowed) {
1.426 raeburn 14111: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14112: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14113: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14114: }
14115: return $switchserver;
14116: }
14117:
1.1 raeburn 14118: sub modify_quotas {
1.216 raeburn 14119: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14120: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14121: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14122: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14123: $validationfieldsref);
1.86 raeburn 14124: if ($action eq 'quotas') {
1.429 raeburn 14125: $context = 'tools';
1.163 raeburn 14126: } else {
1.86 raeburn 14127: $context = $action;
14128: }
14129: if ($context eq 'requestcourses') {
1.325 raeburn 14130: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14131: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14132: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14133: %titles = &courserequest_titles();
14134: $toolregexp = join('|',@usertools);
14135: %conditions = &courserequest_conditions();
1.216 raeburn 14136: $confname = $dom.'-domainconfig';
14137: my $servadm = $r->dir_config('lonAdmEMail');
14138: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14139: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14140: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14141: } elsif ($context eq 'requestauthor') {
14142: @usertools = ('author');
14143: %titles = &authorrequest_titles();
1.86 raeburn 14144: } else {
1.430 raeburn 14145: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14146: %titles = &tool_titles();
1.86 raeburn 14147: }
1.212 raeburn 14148: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14149: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14150: foreach my $key (keys(%env)) {
1.101 raeburn 14151: if ($context eq 'requestcourses') {
14152: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14153: my $item = $1;
14154: my $type = $2;
14155: if ($type =~ /^limit_(.+)/) {
14156: $limithash{$item}{$1} = $env{$key};
14157: } else {
14158: $confhash{$item}{$type} = $env{$key};
14159: }
14160: }
1.163 raeburn 14161: } elsif ($context eq 'requestauthor') {
14162: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14163: $confhash{$1} = $env{$key};
14164: }
1.101 raeburn 14165: } else {
1.86 raeburn 14166: if ($key =~ /^form\.quota_(.+)$/) {
14167: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14168: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14169: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14170: }
1.72 raeburn 14171: }
14172: }
1.163 raeburn 14173: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14174: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14175: @approvalnotify = sort(@approvalnotify);
14176: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14177: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14178: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14179: foreach my $type (@hasuniquecode) {
14180: if (grep(/^\Q$type\E$/,@crstypes)) {
14181: $confhash{'uniquecode'}{$type} = 1;
14182: }
1.216 raeburn 14183: }
1.242 raeburn 14184: my (%newbook,%allpos);
1.216 raeburn 14185: if ($context eq 'requestcourses') {
1.242 raeburn 14186: foreach my $type ('textbooks','templates') {
14187: @{$allpos{$type}} = ();
14188: my $invalid;
14189: if ($type eq 'textbooks') {
14190: $invalid = &mt('Invalid LON-CAPA course for textbook');
14191: } else {
14192: $invalid = &mt('Invalid LON-CAPA course for template');
14193: }
14194: if ($env{'form.'.$type.'_addbook'}) {
14195: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14196: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14197: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14198: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14199: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14200: } else {
14201: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14202: my $position = $env{'form.'.$type.'_addbook_pos'};
14203: $position =~ s/\D+//g;
14204: if ($position ne '') {
14205: $allpos{$type}[$position] = $newbook{$type};
14206: }
1.216 raeburn 14207: }
1.242 raeburn 14208: } else {
14209: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14210: }
14211: }
1.242 raeburn 14212: }
1.216 raeburn 14213: }
1.102 raeburn 14214: if (ref($domconfig{$action}) eq 'HASH') {
14215: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14216: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14217: $changes{'notify'}{'approval'} = 1;
14218: }
14219: } else {
1.144 raeburn 14220: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14221: $changes{'notify'}{'approval'} = 1;
14222: }
14223: }
1.218 raeburn 14224: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14225: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14226: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14227: unless ($confhash{'uniquecode'}{$crstype}) {
14228: $changes{'uniquecode'} = 1;
14229: }
14230: }
14231: unless ($changes{'uniquecode'}) {
14232: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14233: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14234: $changes{'uniquecode'} = 1;
14235: }
14236: }
14237: }
14238: } else {
14239: $changes{'uniquecode'} = 1;
14240: }
14241: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14242: $changes{'uniquecode'} = 1;
1.216 raeburn 14243: }
14244: if ($context eq 'requestcourses') {
1.242 raeburn 14245: foreach my $type ('textbooks','templates') {
14246: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14247: my %deletions;
14248: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14249: if (@todelete) {
14250: map { $deletions{$_} = 1; } @todelete;
14251: }
14252: my %imgdeletions;
14253: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14254: if (@todeleteimages) {
14255: map { $imgdeletions{$_} = 1; } @todeleteimages;
14256: }
14257: my $maxnum = $env{'form.'.$type.'_maxnum'};
14258: for (my $i=0; $i<=$maxnum; $i++) {
14259: my $itemid = $env{'form.'.$type.'_id_'.$i};
14260: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14261: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14262: if ($deletions{$key}) {
14263: if ($domconfig{$action}{$type}{$key}{'image'}) {
14264: #FIXME need to obsolete item in RES space
14265: }
14266: next;
14267: } else {
14268: my $newpos = $env{'form.'.$itemid};
14269: $newpos =~ s/\D+//g;
1.243 raeburn 14270: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14271: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14272: ($type eq 'templates'));
1.242 raeburn 14273: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14274: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14275: $changes{$type}{$key} = 1;
14276: }
14277: }
14278: $allpos{$type}[$newpos] = $key;
14279: }
14280: if ($imgdeletions{$key}) {
14281: $changes{$type}{$key} = 1;
1.216 raeburn 14282: #FIXME need to obsolete item in RES space
1.242 raeburn 14283: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14284: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14285: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14286: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14287: } else {
14288: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14289: $cdom,$cnum,$type,$configuserok,
14290: $switchserver,$author_ok);
14291: if ($imgurl) {
14292: $confhash{$type}{$key}{'image'} = $imgurl;
14293: $changes{$type}{$key} = 1;
14294: }
14295: if ($error) {
14296: &Apache::lonnet::logthis($error);
14297: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14298: }
14299: }
1.242 raeburn 14300: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14301: $confhash{$type}{$key}{'image'} =
14302: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14303: }
14304: }
14305: }
14306: }
14307: }
14308: }
1.102 raeburn 14309: } else {
1.144 raeburn 14310: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14311: $changes{'notify'}{'approval'} = 1;
14312: }
1.218 raeburn 14313: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14314: $changes{'uniquecode'} = 1;
14315: }
14316: }
14317: if ($context eq 'requestcourses') {
1.242 raeburn 14318: foreach my $type ('textbooks','templates') {
14319: if ($newbook{$type}) {
14320: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14321: foreach my $item ('subject','title','publisher','author') {
14322: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14323: ($type eq 'template'));
1.242 raeburn 14324: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14325: if ($env{'form.'.$type.'_addbook_'.$item}) {
14326: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14327: }
14328: }
14329: if ($type eq 'textbooks') {
14330: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14331: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14332: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14333: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14334: } else {
14335: my ($imageurl,$error) =
14336: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14337: $configuserok,$switchserver,$author_ok);
14338: if ($imageurl) {
14339: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14340: }
14341: if ($error) {
14342: &Apache::lonnet::logthis($error);
14343: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14344: }
1.242 raeburn 14345: }
14346: }
1.216 raeburn 14347: }
14348: }
1.242 raeburn 14349: if (@{$allpos{$type}} > 0) {
14350: my $idx = 0;
14351: foreach my $item (@{$allpos{$type}}) {
14352: if ($item ne '') {
14353: $confhash{$type}{$item}{'order'} = $idx;
14354: if (ref($domconfig{$action}) eq 'HASH') {
14355: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14356: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14357: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14358: $changes{$type}{$item} = 1;
14359: }
1.216 raeburn 14360: }
14361: }
14362: }
1.242 raeburn 14363: $idx ++;
1.216 raeburn 14364: }
14365: }
14366: }
14367: }
1.235 raeburn 14368: if (ref($validationitemsref) eq 'ARRAY') {
14369: foreach my $item (@{$validationitemsref}) {
14370: if ($item eq 'fields') {
14371: my @changed;
14372: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14373: if (@{$confhash{'validation'}{$item}} > 0) {
14374: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14375: }
1.266 raeburn 14376: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14377: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14378: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14379: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14380: $domconfig{'requestcourses'}{'validation'}{$item});
14381: } else {
14382: @changed = @{$confhash{'validation'}{$item}};
14383: }
1.235 raeburn 14384: } else {
14385: @changed = @{$confhash{'validation'}{$item}};
14386: }
14387: } else {
14388: @changed = @{$confhash{'validation'}{$item}};
14389: }
14390: if (@changed) {
14391: if ($confhash{'validation'}{$item}) {
14392: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14393: } else {
14394: $changes{'validation'}{$item} = &mt('None');
14395: }
14396: }
14397: } else {
14398: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14399: if ($item eq 'markup') {
14400: if ($env{'form.requestcourses_validation_'.$item}) {
14401: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14402: }
14403: }
1.266 raeburn 14404: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14405: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14406: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14407: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14408: }
14409: } else {
14410: if ($confhash{'validation'}{$item} ne '') {
14411: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14412: }
1.235 raeburn 14413: }
14414: } else {
14415: if ($confhash{'validation'}{$item} ne '') {
14416: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14417: }
14418: }
14419: }
14420: }
14421: }
14422: if ($env{'form.validationdc'}) {
14423: my $newval = $env{'form.validationdc'};
1.285 raeburn 14424: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14425: if (exists($domcoords{$newval})) {
14426: $confhash{'validation'}{'dc'} = $newval;
14427: }
14428: }
14429: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14430: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14431: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14432: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14433: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14434: if ($confhash{'validation'}{'dc'} eq '') {
14435: $changes{'validation'}{'dc'} = &mt('None');
14436: } else {
14437: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14438: }
1.235 raeburn 14439: }
1.266 raeburn 14440: } elsif ($confhash{'validation'}{'dc'} ne '') {
14441: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14442: }
14443: } elsif ($confhash{'validation'}{'dc'} ne '') {
14444: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14445: }
14446: } elsif ($confhash{'validation'}{'dc'} ne '') {
14447: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14448: }
1.266 raeburn 14449: } else {
14450: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14451: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14452: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14453: $changes{'validation'}{'dc'} = &mt('None');
14454: }
14455: }
1.235 raeburn 14456: }
14457: }
1.102 raeburn 14458: }
14459: } else {
1.86 raeburn 14460: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14461: }
1.72 raeburn 14462: foreach my $item (@usertools) {
14463: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14464: my $unset;
1.101 raeburn 14465: if ($context eq 'requestcourses') {
1.104 raeburn 14466: $unset = '0';
14467: if ($type eq '_LC_adv') {
14468: $unset = '';
14469: }
1.101 raeburn 14470: if ($confhash{$item}{$type} eq 'autolimit') {
14471: $confhash{$item}{$type} .= '=';
14472: unless ($limithash{$item}{$type} =~ /\D/) {
14473: $confhash{$item}{$type} .= $limithash{$item}{$type};
14474: }
14475: }
1.163 raeburn 14476: } elsif ($context eq 'requestauthor') {
14477: $unset = '0';
14478: if ($type eq '_LC_adv') {
14479: $unset = '';
14480: }
1.72 raeburn 14481: } else {
1.101 raeburn 14482: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14483: $confhash{$item}{$type} = 1;
14484: } else {
14485: $confhash{$item}{$type} = 0;
14486: }
1.72 raeburn 14487: }
1.86 raeburn 14488: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14489: if ($action eq 'requestauthor') {
14490: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14491: $changes{$type} = 1;
14492: }
14493: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14494: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14495: $changes{$item}{$type} = 1;
14496: }
14497: } else {
14498: if ($context eq 'requestcourses') {
1.104 raeburn 14499: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14500: $changes{$item}{$type} = 1;
14501: }
14502: } else {
14503: if (!$confhash{$item}{$type}) {
14504: $changes{$item}{$type} = 1;
14505: }
14506: }
14507: }
14508: } else {
14509: if ($context eq 'requestcourses') {
1.104 raeburn 14510: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14511: $changes{$item}{$type} = 1;
14512: }
1.163 raeburn 14513: } elsif ($context eq 'requestauthor') {
14514: if ($confhash{$type} ne $unset) {
14515: $changes{$type} = 1;
14516: }
1.72 raeburn 14517: } else {
14518: if (!$confhash{$item}{$type}) {
14519: $changes{$item}{$type} = 1;
14520: }
14521: }
14522: }
1.1 raeburn 14523: }
14524: }
1.163 raeburn 14525: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14526: if (ref($domconfig{'quotas'}) eq 'HASH') {
14527: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14528: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14529: if (exists($confhash{'defaultquota'}{$key})) {
14530: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14531: $changes{'defaultquota'}{$key} = 1;
14532: }
14533: } else {
14534: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14535: }
14536: }
1.86 raeburn 14537: } else {
14538: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14539: if (exists($confhash{'defaultquota'}{$key})) {
14540: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14541: $changes{'defaultquota'}{$key} = 1;
14542: }
14543: } else {
14544: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14545: }
1.1 raeburn 14546: }
14547: }
1.197 raeburn 14548: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14549: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14550: }
14551: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14552: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14553: }
1.1 raeburn 14554: }
1.86 raeburn 14555: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14556: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14557: if (ref($domconfig{'quotas'}) eq 'HASH') {
14558: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14559: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14560: $changes{'defaultquota'}{$key} = 1;
14561: }
14562: } else {
14563: if (!exists($domconfig{'quotas'}{$key})) {
14564: $changes{'defaultquota'}{$key} = 1;
14565: }
1.72 raeburn 14566: }
14567: } else {
1.86 raeburn 14568: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14569: }
1.1 raeburn 14570: }
14571: }
14572: }
1.72 raeburn 14573:
1.163 raeburn 14574: if ($context eq 'requestauthor') {
14575: $domdefaults{'requestauthor'} = \%confhash;
14576: } else {
14577: foreach my $key (keys(%confhash)) {
1.242 raeburn 14578: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14579: $domdefaults{$key} = $confhash{$key};
14580: }
1.163 raeburn 14581: }
1.72 raeburn 14582: }
1.163 raeburn 14583:
1.1 raeburn 14584: my %quotahash = (
1.86 raeburn 14585: $action => { %confhash }
1.1 raeburn 14586: );
14587: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14588: $dom);
14589: if ($putresult eq 'ok') {
14590: if (keys(%changes) > 0) {
1.72 raeburn 14591: my $cachetime = 24*60*60;
14592: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14593: if (ref($lastactref) eq 'HASH') {
14594: $lastactref->{'domdefaults'} = 1;
14595: }
1.1 raeburn 14596: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14597: unless (($context eq 'requestcourses') ||
1.163 raeburn 14598: ($context eq 'requestauthor')) {
1.86 raeburn 14599: if (ref($changes{'defaultquota'}) eq 'HASH') {
14600: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14601: foreach my $type (@{$types},'default') {
14602: if (defined($changes{'defaultquota'}{$type})) {
14603: my $typetitle = $usertypes->{$type};
14604: if ($type eq 'default') {
14605: $typetitle = $othertitle;
14606: }
1.213 raeburn 14607: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14608: }
14609: }
1.86 raeburn 14610: $resulttext .= '</ul></li>';
1.72 raeburn 14611: }
14612: }
1.80 raeburn 14613: my %newenv;
1.72 raeburn 14614: foreach my $item (@usertools) {
1.163 raeburn 14615: my (%haschgs,%inconf);
14616: if ($context eq 'requestauthor') {
14617: %haschgs = %changes;
1.210 raeburn 14618: %inconf = %confhash;
1.163 raeburn 14619: } else {
14620: if (ref($changes{$item}) eq 'HASH') {
14621: %haschgs = %{$changes{$item}};
14622: }
14623: if (ref($confhash{$item}) eq 'HASH') {
14624: %inconf = %{$confhash{$item}};
14625: }
14626: }
14627: if (keys(%haschgs) > 0) {
1.80 raeburn 14628: my $newacc =
14629: &Apache::lonnet::usertools_access($env{'user.name'},
14630: $env{'user.domain'},
1.86 raeburn 14631: $item,'reload',$context);
1.210 raeburn 14632: if (($context eq 'requestcourses') ||
1.163 raeburn 14633: ($context eq 'requestauthor')) {
1.108 raeburn 14634: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14635: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14636: }
14637: } else {
14638: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14639: $newenv{'environment.availabletools.'.$item} = $newacc;
14640: }
1.80 raeburn 14641: }
1.163 raeburn 14642: unless ($context eq 'requestauthor') {
14643: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14644: }
1.72 raeburn 14645: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14646: if ($haschgs{$type}) {
1.72 raeburn 14647: my $typetitle = $usertypes->{$type};
14648: if ($type eq 'default') {
14649: $typetitle = $othertitle;
14650: } elsif ($type eq '_LC_adv') {
14651: $typetitle = 'LON-CAPA Advanced Users';
14652: }
1.163 raeburn 14653: if ($inconf{$type}) {
1.101 raeburn 14654: if ($context eq 'requestcourses') {
14655: my $cond;
1.163 raeburn 14656: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14657: if ($1 eq '') {
14658: $cond = &mt('(Automatic processing of any request).');
14659: } else {
14660: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14661: }
14662: } else {
1.163 raeburn 14663: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14664: }
14665: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14666: } elsif ($context eq 'requestauthor') {
14667: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14668: $titles{$inconf{$type}},$typetitle);
14669:
1.101 raeburn 14670: } else {
14671: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14672: }
1.72 raeburn 14673: } else {
1.104 raeburn 14674: if ($type eq '_LC_adv') {
1.163 raeburn 14675: if ($inconf{$type} eq '0') {
1.104 raeburn 14676: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14677: } else {
14678: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14679: }
14680: } else {
14681: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14682: }
1.72 raeburn 14683: }
14684: }
1.26 raeburn 14685: }
1.163 raeburn 14686: unless ($context eq 'requestauthor') {
14687: $resulttext .= '</ul></li>';
14688: }
1.26 raeburn 14689: }
1.1 raeburn 14690: }
1.163 raeburn 14691: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14692: if (ref($changes{'notify'}) eq 'HASH') {
14693: if ($changes{'notify'}{'approval'}) {
14694: if (ref($confhash{'notify'}) eq 'HASH') {
14695: if ($confhash{'notify'}{'approval'}) {
14696: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14697: } else {
1.163 raeburn 14698: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14699: }
14700: }
14701: }
14702: }
14703: }
1.216 raeburn 14704: if ($action eq 'requestcourses') {
14705: my @offon = ('off','on');
14706: if ($changes{'uniquecode'}) {
1.218 raeburn 14707: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14708: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14709: $resulttext .= '<li>'.
14710: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14711: '</li>';
14712: } else {
14713: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14714: '</li>';
14715: }
1.216 raeburn 14716: }
1.242 raeburn 14717: foreach my $type ('textbooks','templates') {
14718: if (ref($changes{$type}) eq 'HASH') {
14719: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14720: foreach my $key (sort(keys(%{$changes{$type}}))) {
14721: my %coursehash = &Apache::lonnet::coursedescription($key);
14722: my $coursetitle = $coursehash{'description'};
14723: my $position = $confhash{$type}{$key}{'order'} + 1;
14724: $resulttext .= '<li>';
1.243 raeburn 14725: foreach my $item ('subject','title','publisher','author') {
14726: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14727: ($type eq 'templates'));
1.242 raeburn 14728: my $name = $item.':';
14729: $name =~ s/^(\w)/\U$1/;
14730: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14731: }
14732: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14733: if ($type eq 'textbooks') {
14734: if ($confhash{$type}{$key}{'image'}) {
14735: $resulttext .= ' '.&mt('Image: [_1]',
14736: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14737: ' alt="Textbook cover" />').'<br />';
14738: }
14739: }
14740: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14741: }
1.242 raeburn 14742: $resulttext .= '</ul></li>';
1.216 raeburn 14743: }
14744: }
1.235 raeburn 14745: if (ref($changes{'validation'}) eq 'HASH') {
14746: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14747: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14748: foreach my $item (@{$validationitemsref}) {
14749: if (exists($changes{'validation'}{$item})) {
14750: if ($item eq 'markup') {
14751: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14752: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14753: } else {
14754: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14755: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14756: }
14757: }
14758: }
14759: if (exists($changes{'validation'}{'dc'})) {
14760: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14761: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14762: }
1.442 raeburn 14763: $resulttext .= '</ul></li>';
1.235 raeburn 14764: }
14765: }
1.216 raeburn 14766: }
1.1 raeburn 14767: $resulttext .= '</ul>';
1.80 raeburn 14768: if (keys(%newenv)) {
14769: &Apache::lonnet::appenv(\%newenv);
14770: }
1.1 raeburn 14771: } else {
1.86 raeburn 14772: if ($context eq 'requestcourses') {
14773: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14774: } elsif ($context eq 'requestauthor') {
14775: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14776: } else {
1.90 weissno 14777: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14778: }
1.1 raeburn 14779: }
14780: } else {
1.11 albertel 14781: $resulttext = '<span class="LC_error">'.
14782: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14783: }
1.216 raeburn 14784: if ($errors) {
14785: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14786: '<ul>'.$errors.'</ul></p>';
14787: }
1.3 raeburn 14788: return $resulttext;
1.1 raeburn 14789: }
14790:
1.216 raeburn 14791: sub process_textbook_image {
1.242 raeburn 14792: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14793: my $filename = $env{'form.'.$caller.'.filename'};
14794: my ($error,$url);
14795: my ($width,$height) = (50,50);
14796: if ($configuserok eq 'ok') {
14797: if ($switchserver) {
14798: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14799: $switchserver);
14800: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14801: my $modified = [];
1.216 raeburn 14802: my ($result,$imageurl) =
1.421 raeburn 14803: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14804: "$type/$cdom/$cnum/cover",$width,$height,
14805: '',$modified);
1.216 raeburn 14806: if ($result eq 'ok') {
14807: $url = $imageurl;
1.421 raeburn 14808: &update_modify_urls($r,$modified);
1.216 raeburn 14809: } else {
14810: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14811: }
14812: } else {
14813: $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);
14814: }
14815: } else {
14816: $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);
14817: }
14818: return ($url,$error);
14819: }
14820:
1.267 raeburn 14821: sub modify_ltitools {
14822: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14823: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14824: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14825:
1.267 raeburn 14826: my $confname = $dom.'-domainconfig';
14827: my $servadm = $r->dir_config('lonAdmEMail');
14828: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14829:
14830: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14831: my $toolserror =
14832: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14833: $lastactref,$configuserok,$switchserver,$author_ok);
14834:
14835: my $home = &Apache::lonnet::domain($dom,'primary');
14836: unless (($home eq 'no_host') || ($home eq '')) {
14837: my @ids=&Apache::lonnet::current_machine_ids();
14838: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14839: }
14840:
14841: if (keys(%ltitoolschg)) {
14842: foreach my $id (keys(%ltitoolschg)) {
14843: if (ref($ltitoolschg{$id}) eq 'HASH') {
14844: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14845: if (($inner eq 'secret') || ($inner eq 'key')) {
14846: if ($is_home) {
14847: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14848: }
14849: }
14850: }
1.267 raeburn 14851: }
1.421 raeburn 14852: }
14853: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14854: if (keys(%ltitoolschg)) {
14855: %newltitools = %ltitoolschg;
14856: }
14857: }
14858: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14859: foreach my $id (%{$domconfig{'ltitools'}}) {
14860: next if ($id !~ /^\d+$/);
14861: unless (exists($ltitoolschg{$id})) {
14862: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14863: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14864: if (($inner eq 'secret') || ($inner eq 'key')) {
14865: if ($is_home) {
14866: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14867: }
14868: } else {
14869: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14870: }
14871: }
14872: } else {
14873: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14874: }
1.421 raeburn 14875: }
14876: }
14877: }
14878: if ($toolserror) {
14879: $errors = '<li>'.$toolserror.'</li>';
14880: }
14881: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14882: $resulttext = &mt('No changes made.');
14883: if ($errors) {
14884: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14885: $errors.'</ul>';
14886: }
14887: return $resulttext;
14888: }
14889: my %ltitoolshash = (
14890: $action => { %newltitools }
14891: );
14892: if (keys(%secchanges)) {
14893: $ltitoolshash{'toolsec'} = \%newtoolsec;
14894: }
14895: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14896: if ($putresult eq 'ok') {
14897: my %keystore;
14898: if ($is_home) {
14899: my %toolsenchash = (
14900: $action => { %newtoolsenc }
14901: );
14902: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 14903: my $cachetime = 24*60*60;
14904: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 14905: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
14906: }
14907: $resulttext = &mt('Changes made:').'<ul>';
14908: if (keys(%secchanges) > 0) {
1.423 raeburn 14909: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 14910: }
14911: if (keys(%ltitoolschg) > 0) {
14912: $resulttext .= $ltitoolsoutput;
14913: }
1.423 raeburn 14914: my $cachetime = 24*60*60;
14915: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
14916: if (ref($lastactref) eq 'HASH') {
14917: $lastactref->{'ltitools'} = 1;
14918: }
1.421 raeburn 14919: } else {
14920: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14921: }
14922: if ($errors) {
14923: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14924: $errors.'</ul></p>';
14925: }
14926: return $resulttext;
14927: }
14928:
14929: sub fetch_secrets {
14930: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
14931: my %keyset;
14932: %{$currsec} = ();
14933: $newsec->{'private'}{'keys'} = [];
14934: $newsec->{'encrypt'} = {};
14935: $newsec->{'rules'} = {};
14936: if ($context eq 'ltisec') {
14937: $newsec->{'linkprot'} = {};
14938: }
14939: if (ref($domconfig->{$context}) eq 'HASH') {
14940: %{$currsec} = %{$domconfig->{$context}};
14941: if ($context eq 'ltisec') {
14942: if (ref($currsec->{'linkprot'}) eq 'HASH') {
14943: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
14944: unless ($id =~ /^\d+$/) {
14945: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 14946: }
1.267 raeburn 14947: }
14948: }
1.421 raeburn 14949: }
14950: if (ref($currsec->{'private'}) eq 'HASH') {
14951: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
14952: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
14953: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 14954: }
1.421 raeburn 14955: }
14956: }
14957: my @items= ('crs','dom');
14958: if ($context eq 'ltisec') {
14959: push(@items,'consumers');
14960: }
14961: foreach my $item (@items) {
14962: my $formelement;
14963: if (($context eq 'toolsec') || ($item eq 'consumers')) {
14964: $formelement = 'form.'.$context.'_'.$item;
14965: } else {
14966: $formelement = 'form.'.$context.'_'.$item.'linkprot';
14967: }
14968: if ($env{$formelement}) {
14969: $newsec->{'encrypt'}{$item} = 1;
14970: if (ref($currsec->{'encrypt'}) eq 'HASH') {
14971: unless ($currsec->{'encrypt'}{$item}) {
14972: $secchanges->{'encrypt'} = 1;
14973: }
14974: } else {
14975: $secchanges->{'encrypt'} = 1;
1.267 raeburn 14976: }
1.421 raeburn 14977: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
14978: if ($currsec->{'encrypt'}{$item}) {
14979: $secchanges->{'encrypt'} = 1;
1.323 raeburn 14980: }
1.421 raeburn 14981: }
14982: }
14983: my $secrets;
14984: if ($context eq 'ltisec') {
14985: $secrets = 'ltisecrets';
14986: } else {
14987: $secrets = 'toolsecrets';
14988: }
14989: unless (exists($currsec->{'rules'})) {
14990: $currsec->{'rules'} = {};
14991: }
14992: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
14993:
14994: my @ids=&Apache::lonnet::current_machine_ids();
14995: my %servers = &Apache::lonnet::get_servers($dom,'library');
14996:
14997: foreach my $hostid (keys(%servers)) {
14998: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
14999: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
15000: if (exists($env{$keyitem})) {
15001: $env{$keyitem} =~ s/(`)/'/g;
15002: if ($keyset{$hostid}) {
15003: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
15004: if ($env{$keyitem} ne '') {
15005: $secchanges->{'private'} = 1;
15006: $newkeyset->{$hostid} = $env{$keyitem};
15007: }
1.296 raeburn 15008: }
1.421 raeburn 15009: } elsif ($env{$keyitem} ne '') {
15010: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
15011: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 15012: }
1.421 raeburn 15013: $secchanges->{'private'} = 1;
15014: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 15015: }
15016: }
1.421 raeburn 15017: }
15018: }
15019: }
15020:
15021: sub store_security {
1.424 raeburn 15022: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 15023: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
15024: (ref($keystore) eq 'HASH'));
15025: if (keys(%{$secchanges})) {
15026: if ($secchanges->{'private'}) {
15027: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
15028: foreach my $hostid (keys(%{$newkeyset})) {
15029: my $storehash = {
15030: key => $newkeyset->{$hostid},
15031: who => $env{'user.name'}.':'.$env{'user.domain'},
15032: };
15033: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
15034: $dom,$hostid);
15035: }
15036: }
15037: }
15038: }
15039:
15040: sub lti_security_results {
1.423 raeburn 15041: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 15042: my $output;
1.423 raeburn 15043: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15044: my $needs_update;
1.421 raeburn 15045: foreach my $item (keys(%{$secchanges})) {
15046: if ($item eq 'encrypt') {
1.423 raeburn 15047: $needs_update = 1;
1.421 raeburn 15048: my %encrypted;
15049: if ($context eq 'lti') {
15050: %encrypted = (
15051: crs => {
15052: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
15053: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
15054: },
15055: dom => {
15056: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
15057: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
15058: },
15059: consumers => {
15060: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
15061: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
15062: },
15063: );
1.267 raeburn 15064: } else {
1.421 raeburn 15065: %encrypted = (
15066: crs => {
15067: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
15068: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
15069: },
15070: dom => {
15071: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
15072: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
15073: },
15074: );
15075: }
15076: my @types= ('crs','dom');
15077: if ($context eq 'lti') {
1.423 raeburn 15078: foreach my $type (@types) {
15079: undef($domdefaults{'linkprotenc_'.$type});
15080: }
1.421 raeburn 15081: push(@types,'consumers');
1.423 raeburn 15082: undef($domdefaults{'ltienc_consumers'});
15083: } elsif ($context eq 'ltitools') {
15084: foreach my $type (@types) {
15085: undef($domdefaults{'toolenc_'.$type});
15086: }
1.267 raeburn 15087: }
1.421 raeburn 15088: foreach my $type (@types) {
15089: my $shown = $encrypted{$type}{'off'};
15090: if (ref($newsec->{$item}) eq 'HASH') {
15091: if ($newsec->{$item}{$type}) {
1.423 raeburn 15092: if ($context eq 'lti') {
15093: if ($type eq 'consumers') {
15094: $domdefaults{'ltienc_consumers'} = 1;
15095: } else {
15096: $domdefaults{'linkprotenc_'.$type} = 1;
15097: }
15098: } elsif ($context eq 'ltitools') {
15099: $domdefaults{'toolenc_'.$type} = 1;
15100: }
1.421 raeburn 15101: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15102: }
1.267 raeburn 15103: }
1.421 raeburn 15104: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15105: }
1.421 raeburn 15106: } elsif ($item eq 'rules') {
15107: my %titles = &Apache::lonlocal::texthash(
15108: min => 'Minimum password length',
15109: max => 'Maximum password length',
15110: chars => 'Required characters',
15111: );
15112: foreach my $rule ('min','max') {
15113: if ($newsec->{rules}{$rule} eq '') {
15114: if ($rule eq 'min') {
15115: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15116: ' '.&mt('Default of [_1] will be used',
15117: $Apache::lonnet::passwdmin).'</li>';
15118: } else {
15119: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15120: }
15121: } else {
15122: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15123: }
15124: }
15125: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15126: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15127: my %rulenames = &Apache::lonlocal::texthash(
15128: uc => 'At least one upper case letter',
15129: lc => 'At least one lower case letter',
15130: num => 'At least one number',
15131: spec => 'At least one non-alphanumeric',
15132: );
15133: my $needed = '<ul><li>'.
15134: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15135: '</li></ul>';
15136: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15137: } else {
15138: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15139: }
1.421 raeburn 15140: } else {
15141: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15142: }
1.421 raeburn 15143: } elsif ($item eq 'private') {
1.423 raeburn 15144: $needs_update = 1;
15145: if ($context eq 'lti') {
15146: undef($domdefaults{'ltiprivhosts'});
15147: } elsif ($context eq 'ltitools') {
15148: undef($domdefaults{'toolprivhosts'});
15149: }
1.421 raeburn 15150: if (keys(%{$newkeyset})) {
1.423 raeburn 15151: my @privhosts;
1.421 raeburn 15152: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15153: if ($keystore->{$hostid} eq 'ok') {
15154: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15155: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15156: push(@privhosts,$hostid);
15157: }
15158: }
15159: }
15160: if (@privhosts) {
15161: if ($context eq 'lti') {
15162: $domdefaults{'ltiprivhosts'} = \@privhosts;
15163: } elsif ($context eq 'ltitools') {
15164: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15165: }
15166: }
15167: }
1.421 raeburn 15168: } elsif ($item eq 'linkprot') {
15169: next;
1.434 raeburn 15170: } elsif ($item eq 'suggested') {
15171: if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
15172: (ref($newsec->{'suggested'}) eq 'HASH')) {
15173: my $suggestions;
15174: foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
15175: if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
15176: my $name = $newsec->{'suggested'}->{$id}->{'name'};
15177: my $info = $newsec->{'suggested'}->{$id}->{'info'};
15178: $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
15179: &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
15180: '</li>';
15181: } else {
15182: $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
15183: $newsec->{'suggested'}->{$id}).'</li>';
15184: }
15185: }
15186: if ($suggestions) {
15187: $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
15188: '<ul>'.$suggestions.'</ul>'.
15189: '</li>';
15190: }
15191: }
1.267 raeburn 15192: }
15193: }
1.423 raeburn 15194: if ($needs_update) {
15195: my $cachetime = 24*60*60;
15196: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15197: }
1.421 raeburn 15198: return $output;
15199: }
15200:
15201: sub modify_proctoring {
15202: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15203: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15204: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15205: my $confname = $dom.'-domainconfig';
15206: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15207: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15208: my %providernames = &proctoring_providernames();
15209: my $maxnum = scalar(keys(%providernames));
15210:
15211: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15212: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15213: if (ref($requref) eq 'HASH') {
15214: %requserfields = %{$requref};
15215: }
15216: if (ref($opturef) eq 'HASH') {
15217: %optuserfields = %{$opturef};
15218: }
15219: if (ref($defref) eq 'HASH') {
15220: %defaults = %{$defref};
15221: }
15222: if (ref($extref) eq 'HASH') {
15223: %extended = %{$extref};
15224: }
15225: if (ref($crsref) eq 'HASH') {
15226: %crsconf = %{$crsref};
15227: }
15228: if (ref($rolesref) eq 'ARRAY') {
15229: @courseroles = @{$rolesref};
15230: }
15231: if (ref($ltiref) eq 'ARRAY') {
15232: @ltiroles = @{$ltiref};
15233: }
15234:
15235: if (ref($domconfig{$action}) eq 'HASH') {
15236: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15237: if (@todeleteimages) {
15238: map { $imgdeletions{$_} = 1; } @todeleteimages;
15239: }
15240: }
15241: my %customadds;
15242: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15243: if (@newcustom) {
15244: map { $customadds{$_} = 1; } @newcustom;
15245: }
15246: foreach my $provider (sort(keys(%providernames))) {
15247: $confhash{$provider} = {};
15248: my $pos = $env{'form.proctoring_pos_'.$provider};
15249: $pos =~ s/\D+//g;
15250: $allpos[$pos] = $provider;
15251: my (%current,%currentenc);
15252: my $showroles = 0;
15253: if (ref($domconfig{$action}) eq 'HASH') {
15254: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15255: %current = %{$domconfig{$action}{$provider}};
15256: foreach my $item ('key','secret') {
15257: $currentenc{$item} = $current{$item};
15258: delete($current{$item});
15259: }
15260: }
15261: }
15262: if ($env{'form.proctoring_available_'.$provider}) {
15263: $confhash{$provider}{'available'} = 1;
15264: unless ($current{'available'}) {
15265: $changes{$provider} = 1;
15266: }
15267: } else {
15268: %{$confhash{$provider}} = %current;
15269: %{$encconfhash{$provider}} = %currentenc;
15270: $confhash{$provider}{'available'} = 0;
15271: if ($current{'available'}) {
15272: $changes{$provider} = 1;
15273: }
15274: }
15275: if ($confhash{$provider}{'available'}) {
15276: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15277: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15278: if ($field eq 'lifetime') {
15279: if ($possval =~ /^\d+$/) {
15280: $confhash{$provider}{$field} = $possval;
15281: }
15282: } elsif ($field eq 'version') {
15283: if ($possval =~ /^\d+\.\d+$/) {
15284: $confhash{$provider}{$field} = $possval;
15285: }
15286: } elsif ($field eq 'sigmethod') {
15287: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15288: $confhash{$provider}{$field} = $possval;
15289: }
15290: } elsif ($field eq 'url') {
15291: $confhash{$provider}{$field} = $possval;
15292: } elsif (($field eq 'key') || ($field eq 'secret')) {
15293: $encconfhash{$provider}{$field} = $possval;
15294: unless ($currentenc{$field} eq $possval) {
15295: $changes{$provider} = 1;
15296: }
15297: }
15298: unless (($field eq 'key') || ($field eq 'secret')) {
15299: unless ($current{$field} eq $confhash{$provider}{$field}) {
15300: $changes{$provider} = 1;
15301: }
15302: }
15303: }
15304: if ($imgdeletions{$provider}) {
15305: $changes{$provider} = 1;
15306: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15307: my ($imageurl,$error) =
15308: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15309: $configuserok,$switchserver,$author_ok);
15310: if ($imageurl) {
15311: $confhash{$provider}{'image'} = $imageurl;
15312: $changes{$provider} = 1;
15313: }
15314: if ($error) {
15315: &Apache::lonnet::logthis($error);
15316: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15317: }
15318: } elsif (exists($current{'image'})) {
15319: $confhash{$provider}{'image'} = $current{'image'};
15320: }
15321: if (ref($requserfields{$provider}) eq 'ARRAY') {
15322: if (@{$requserfields{$provider}} > 0) {
15323: if (grep(/^user$/,@{$requserfields{$provider}})) {
15324: if ($env{'form.proctoring_userincdom_'.$provider}) {
15325: $confhash{$provider}{'incdom'} = 1;
15326: }
15327: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15328: $changes{$provider} = 1;
15329: }
15330: }
15331: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15332: $showroles = 1;
15333: }
15334: }
15335: }
15336: $confhash{$provider}{'fields'} = [];
15337: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15338: if (@{$optuserfields{$provider}} > 0) {
15339: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15340: foreach my $field (@{$optuserfields{$provider}}) {
15341: if (grep(/^\Q$field\E$/,@optfields)) {
15342: push(@{$confhash{$provider}{'fields'}},$field);
15343: }
15344: }
15345: }
15346: if (ref($current{'fields'}) eq 'ARRAY') {
15347: unless ($changes{$provider}) {
15348: my @new = sort(@{$confhash{$provider}{'fields'}});
15349: my @old = sort(@{$current{'fields'}});
15350: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15351: if (@diffs) {
15352: $changes{$provider} = 1;
15353: }
15354: }
15355: } elsif (@{$confhash{$provider}{'fields'}}) {
15356: $changes{$provider} = 1;
15357: }
15358: }
15359: if (ref($defaults{$provider}) eq 'ARRAY') {
15360: if (@{$defaults{$provider}} > 0) {
15361: my %options;
15362: if (ref($extended{$provider}) eq 'HASH') {
15363: %options = %{$extended{$provider}};
15364: }
15365: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15366: foreach my $field (@{$defaults{$provider}}) {
15367: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15368: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15369: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15370: push(@{$confhash{$provider}{'defaults'}},$poss);
15371: }
15372: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15373: foreach my $inner (keys(%{$options{$field}})) {
15374: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15375: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15376: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15377: $confhash{$provider}{'defaults'}{$inner} = $poss;
15378: }
15379: } else {
15380: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15381: }
15382: }
15383: } else {
15384: if (grep(/^\Q$field\E$/,@checked)) {
15385: push(@{$confhash{$provider}{'defaults'}},$field);
15386: }
15387: }
15388: }
15389: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15390: if (ref($current{'defaults'}) eq 'ARRAY') {
15391: unless ($changes{$provider}) {
15392: my @new = sort(@{$confhash{$provider}{'defaults'}});
15393: my @old = sort(@{$current{'defaults'}});
15394: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15395: if (@diffs) {
15396: $changes{$provider} = 1;
15397: }
15398: }
15399: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15400: if (@{$current{'defaults'}}) {
15401: $changes{$provider} = 1;
15402: }
15403: }
15404: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15405: if (ref($current{'defaults'}) eq 'HASH') {
15406: unless ($changes{$provider}) {
15407: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15408: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15409: $changes{$provider} = 1;
15410: last;
15411: }
15412: }
15413: }
15414: unless ($changes{$provider}) {
15415: foreach my $key (keys(%{$current{'defaults'}})) {
15416: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15417: $changes{$provider} = 1;
15418: last;
15419: }
15420: }
15421: }
15422: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15423: $changes{$provider} = 1;
15424: }
15425: }
15426: }
15427: }
15428: if (ref($crsconf{$provider}) eq 'ARRAY') {
15429: if (@{$crsconf{$provider}} > 0) {
15430: $confhash{$provider}{'crsconf'} = [];
15431: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15432: foreach my $crsfield (@{$crsconf{$provider}}) {
15433: if (grep(/^\Q$crsfield\E$/,@checked)) {
15434: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15435: }
15436: }
15437: if (ref($current{'crsconf'}) eq 'ARRAY') {
15438: unless ($changes{$provider}) {
15439: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15440: my @old = sort(@{$current{'crsconf'}});
15441: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15442: if (@diffs) {
15443: $changes{$provider} = 1;
15444: }
15445: }
15446: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15447: $changes{$provider} = 1;
15448: }
15449: }
15450: }
15451: if ($showroles) {
15452: $confhash{$provider}{'roles'} = {};
15453: foreach my $role (@courseroles) {
15454: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15455: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15456: $confhash{$provider}{'roles'}{$role} = $poss;
15457: }
15458: }
15459: unless ($changes{$provider}) {
15460: if (ref($current{'roles'}) eq 'HASH') {
15461: foreach my $role (keys(%{$current{'roles'}})) {
15462: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15463: $changes{$provider} = 1;
15464: last
15465: }
15466: }
15467: unless ($changes{$provider}) {
15468: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15469: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15470: $changes{$provider} = 1;
15471: last;
15472: }
15473: }
15474: }
15475: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15476: $changes{$provider} = 1;
15477: }
15478: }
15479: }
15480: if (ref($current{'custom'}) eq 'HASH') {
15481: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15482: foreach my $key (keys(%{$current{'custom'}})) {
15483: if (grep(/^\Q$key\E$/,@customdels)) {
15484: $changes{$provider} = 1;
15485: } else {
15486: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15487: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15488: $changes{$provider} = 1;
15489: }
15490: }
15491: }
15492: }
15493: if ($customadds{$provider}) {
15494: my $name = $env{'form.proctoring_custom_name_'.$provider};
15495: $name =~ s/(`)/'/g;
15496: $name =~ s/^\s+//;
15497: $name =~ s/\s+$//;
15498: my $value = $env{'form.proctoring_custom_value_'.$provider};
15499: $value =~ s/(`)/'/g;
15500: $value =~ s/^\s+//;
15501: $value =~ s/\s+$//;
15502: if ($name ne '') {
15503: $confhash{$provider}{'custom'}{$name} = $value;
15504: $changes{$provider} = 1;
15505: }
15506: }
15507: }
15508: }
15509: if (@allpos > 0) {
15510: my $idx = 0;
15511: foreach my $provider (@allpos) {
15512: if ($provider ne '') {
15513: $confhash{$provider}{'order'} = $idx;
15514: unless ($changes{$provider}) {
15515: if (ref($domconfig{$action}) eq 'HASH') {
15516: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15517: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15518: $changes{$provider} = 1;
15519: }
15520: }
15521: }
15522: }
15523: $idx ++;
15524: }
15525: }
15526: }
15527: my %proc_hash = (
15528: $action => { %confhash }
15529: );
15530: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15531: $dom);
15532: if ($putresult eq 'ok') {
15533: my %proc_enchash = (
15534: $action => { %encconfhash }
15535: );
1.384 raeburn 15536: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15537: if (keys(%changes) > 0) {
15538: my $cachetime = 24*60*60;
15539: my %procall = %confhash;
15540: foreach my $provider (keys(%procall)) {
15541: if (ref($encconfhash{$provider}) eq 'HASH') {
15542: foreach my $key ('key','secret') {
15543: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15544: }
15545: }
15546: }
15547: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15548: if (ref($lastactref) eq 'HASH') {
15549: $lastactref->{'proctoring'} = 1;
15550: }
15551: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15552: my %bynum;
15553: foreach my $provider (sort(keys(%changes))) {
15554: my $position = $confhash{$provider}{'order'};
15555: $bynum{$position} = $provider;
15556: }
15557: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15558: my $provider = $bynum{$pos};
15559: my %lt = &proctoring_titles($provider);
15560: my %fieldtitles = &proctoring_fieldtitles($provider);
15561: if (!$confhash{$provider}{'available'}) {
15562: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15563: } else {
15564: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15565: if ($confhash{$provider}{'image'}) {
15566: $resulttext .= ' '.
15567: '<img src="'.$confhash{$provider}{'image'}.'"'.
15568: ' alt="'.&mt('Proctoring icon').'" />';
15569: }
15570: $resulttext .= '<ul>';
15571: my $position = $pos + 1;
15572: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15573: foreach my $key ('version','sigmethod','url','lifetime') {
15574: if ($confhash{$provider}{$key} ne '') {
15575: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15576: }
15577: }
15578: if ($encconfhash{$provider}{'key'} ne '') {
15579: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15580: }
15581: if ($encconfhash{$provider}{'secret'} ne '') {
15582: $resulttext .= '<li>'.$lt{'secret'}.': ';
15583: my $num = length($encconfhash{$provider}{'secret'});
15584: $resulttext .= ('*'x$num).'</li>';
15585: }
15586: my (@fields,$showroles);
15587: if (ref($requserfields{$provider}) eq 'ARRAY') {
15588: push(@fields,@{$requserfields{$provider}});
15589: }
15590: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15591: push(@fields,@{$confhash{$provider}{'fields'}});
15592: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15593: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15594: }
15595: if (@fields) {
15596: if (grep(/^roles$/,@fields)) {
15597: $showroles = 1;
15598: }
15599: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15600: join('", "', map { $lt{$_}; } @fields).'"</li>';
15601: }
15602: if (ref($requserfields{$provider}) eq 'ARRAY') {
15603: if (grep(/^user$/,@{$requserfields{$provider}})) {
15604: if ($confhash{$provider}{'incdom'}) {
15605: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15606: } else {
15607: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15608: }
15609: }
15610: }
15611: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15612: if (@{$confhash{$provider}{'defaults'}} > 0) {
15613: $resulttext .= '<li>'.$lt{'defa'};
15614: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15615: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15616: }
15617: $resulttext =~ s/,$//;
15618: $resulttext .= '</li>';
15619: }
15620: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15621: if (keys(%{$confhash{$provider}{'defaults'}})) {
15622: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15623: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15624: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15625: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15626: }
15627: }
15628: $resulttext .= '</ul></li>';
15629: }
15630: }
15631: if (ref($crsconf{$provider}) eq 'ARRAY') {
15632: if (@{$crsconf{$provider}} > 0) {
15633: $resulttext .= '<li>'.&mt('Configurable in course:');
15634: my $numconfig = 0;
15635: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15636: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15637: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15638: $numconfig ++;
15639: if ($provider eq 'examity') {
15640: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15641: } else {
15642: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15643: }
15644: }
15645: $resulttext =~ s/,$//;
15646: }
15647: }
15648: if (!$numconfig) {
15649: $resulttext .= ' '.&mt('None');
15650: }
15651: $resulttext .= '</li>';
15652: }
15653: }
15654: if ($showroles) {
15655: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15656: my $rolemaps;
15657: foreach my $role (@courseroles) {
15658: if ($confhash{$provider}{'roles'}{$role}) {
15659: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15660: $confhash{$provider}{'roles'}{$role}.',';
15661: }
15662: }
15663: if ($rolemaps) {
15664: $rolemaps =~ s/,$//;
15665: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15666: }
15667: }
15668: }
15669: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15670: my $customlist;
15671: if (keys(%{$confhash{$provider}{'custom'}})) {
15672: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15673: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15674: }
15675: $customlist =~ s/,$//;
15676: }
15677: if ($customlist) {
15678: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15679: }
15680: }
15681: $resulttext .= '</ul></li>';
15682: }
15683: }
15684: $resulttext .= '</ul>';
15685: } else {
15686: $resulttext = &mt('No changes made.');
15687: }
15688: } else {
15689: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15690: }
15691: if ($errors) {
15692: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15693: $errors.'</ul>';
15694: }
15695: return $resulttext;
15696: }
15697:
15698: sub process_proctoring_image {
15699: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15700: my $filename = $env{'form.'.$caller.'.filename'};
15701: my ($error,$url);
15702: my ($width,$height) = (21,21);
15703: if ($configuserok eq 'ok') {
15704: if ($switchserver) {
15705: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15706: $switchserver);
15707: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15708: my $modified = [];
1.372 raeburn 15709: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15710: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15711: "proctoring/$provider/icon",$width,$height,
15712: '',$modified);
1.372 raeburn 15713: if ($result eq 'ok') {
15714: if ($madethumb) {
15715: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15716: my $imagethumb = "$path/tn-".$imagefile;
15717: $url = $imagethumb;
15718: } else {
15719: $url = $imageurl;
15720: }
1.421 raeburn 15721: &update_modify_urls($r,$modified);
1.372 raeburn 15722: } else {
15723: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15724: }
15725: } else {
15726: $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);
15727: }
15728: } else {
15729: $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);
15730: }
15731: return ($url,$error);
15732: }
15733:
1.320 raeburn 15734: sub modify_lti {
15735: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15736: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15737: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15738: my (%posslti,%posslticrs,%posscrstype);
15739: my @courseroles = ('cc','in','ta','ep','st');
15740: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15741: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15742: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15743: my %coursetypetitles = &Apache::lonlocal::texthash (
15744: official => 'Official',
15745: unofficial => 'Unofficial',
15746: community => 'Community',
15747: textbook => 'Textbook',
15748: placement => 'Placement Test',
1.392 raeburn 15749: lti => 'LTI Provider',
1.320 raeburn 15750: );
1.325 raeburn 15751: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15752: my %lt = <i_names();
15753: map { $posslti{$_} = 1; } @ltiroles;
15754: map { $posslticrs{$_} = 1; } @lticourseroles;
15755: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15756:
1.326 raeburn 15757: my %menutitles = <imenu_titles();
1.421 raeburn 15758: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15759:
1.421 raeburn 15760: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15761:
1.406 raeburn 15762: my (%linkprotchg,$linkprotoutput,$is_home);
15763: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15764: \%linkprotchg,'domain');
15765: my $home = &Apache::lonnet::domain($dom,'primary');
15766: unless (($home eq 'no_host') || ($home eq '')) {
15767: my @ids=&Apache::lonnet::current_machine_ids();
15768: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15769: }
15770:
15771: if (keys(%linkprotchg)) {
15772: $secchanges{'linkprot'} = 1;
15773: my %oldlinkprot;
15774: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15775: %oldlinkprot = %{$currltisec{'linkprot'}};
15776: }
15777: foreach my $id (keys(%linkprotchg)) {
15778: if (ref($linkprotchg{$id}) eq 'HASH') {
15779: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15780: if (($inner eq 'secret') || ($inner eq 'key')) {
15781: if ($is_home) {
15782: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15783: }
15784: }
15785: }
15786: } else {
15787: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15788: }
15789: }
15790: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15791: if (keys(%linkprotchg)) {
15792: %{$newltisec{'linkprot'}} = %linkprotchg;
15793: }
15794: }
15795: if (ref($currltisec{'linkprot'}) eq 'HASH') {
1.434 raeburn 15796: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
1.406 raeburn 15797: next if ($id !~ /^\d+$/);
15798: unless (exists($linkprotchg{$id})) {
15799: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15800: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15801: if (($inner eq 'secret') || ($inner eq 'key')) {
15802: if ($is_home) {
15803: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15804: }
15805: } else {
15806: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15807: }
15808: }
15809: } else {
15810: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15811: }
15812: }
15813: }
15814: }
15815: if ($proterror) {
15816: $errors .= '<li>'.$proterror.'</li>';
15817: }
1.434 raeburn 15818:
15819: my (%delsuggested,%suggids,@suggested);;
15820: if (ref($currltisec{'suggested'}) eq 'HASH') {
15821: my $maxnum = $env{'form.linkprot_suggested_maxnum'};
15822: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
15823: for (my $i=0; $i<$maxnum; $i++) {
15824: my $itemid = $env{'form.linkprot_suggested_id_'.$i};
15825: $itemid =~ s/\D+//g;
15826: if ($itemid) {
15827: if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
15828: push(@suggested,$i);
15829: $suggids{$i} = $itemid;
15830: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
15831: if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
15832: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15833: }
15834: } else {
15835: if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
15836: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15837: } else {
15838: $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
15839: $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
15840: $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
15841: $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
15842: if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
15843: ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
15844: $secchanges{'suggested'}{$itemid} = 1;
15845: }
15846: }
15847: }
15848: }
15849: }
15850: }
15851: }
15852: foreach my $key (keys(%delsuggested)) {
15853: $newltisec{'suggested'}{$key} = $delsuggested{$key};
15854: $secchanges{'suggested'}{$key} = 1;
15855: }
15856: if (($env{'form.linkprot_suggested_add'}) &&
15857: ($env{'form.linkprot_suggested_name_add'} ne '')) {
15858: $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
15859: $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
15860: my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
15861: if ($newsuggid) {
15862: $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
15863: $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
15864: $secchanges{'suggested'}{$newsuggid} = 1;
15865: } else {
15866: my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
15867: if ($errormsg) {
15868: $error .= ' ('.$errormsg.')';
15869: }
15870: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15871: }
15872: }
1.320 raeburn 15873: my (@items,%deletions,%itemids);
15874: if ($env{'form.lti_add'}) {
15875: my $consumer = $env{'form.lti_consumer_add'};
15876: $consumer =~ s/(`)/'/g;
1.434 raeburn 15877: ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
1.320 raeburn 15878: if ($newid) {
15879: $itemids{'add'} = $newid;
15880: push(@items,'add');
15881: $changes{$newid} = 1;
15882: } else {
15883: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
1.434 raeburn 15884: if ($errormsg) {
15885: $error .= ' ('.$errormsg.')';
15886: }
1.320 raeburn 15887: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15888: }
15889: }
15890: if (ref($domconfig{$action}) eq 'HASH') {
15891: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15892: if (@todelete) {
15893: map { $deletions{$_} = 1; } @todelete;
15894: }
15895: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15896: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15897: my $itemid = $env{'form.lti_id_'.$i};
15898: $itemid =~ s/\D+//g;
15899: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15900: if ($deletions{$itemid}) {
15901: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15902: } else {
1.390 raeburn 15903: push(@items,$i);
15904: $itemids{$i} = $itemid;
1.320 raeburn 15905: }
15906: }
15907: }
15908: }
1.424 raeburn 15909: my (%keystore,$secstored);
15910: if ($is_home) {
15911: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
15912: }
15913:
15914: my ($cipher,$privnum);
15915: if ((@items > 0) && ($is_home)) {
15916: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
15917: $newltisec{'encrypt'},$keystore{$home});
15918: }
1.320 raeburn 15919: foreach my $idx (@items) {
15920: my $itemid = $itemids{$idx};
15921: next unless ($itemid);
1.424 raeburn 15922: my %currlti;
15923: unless ($idx eq 'add') {
15924: if (ref($domconfig{$action}) eq 'HASH') {
15925: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15926: %currlti = %{$domconfig{$action}{$itemid}};
15927: }
15928: }
15929: }
1.390 raeburn 15930: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 15931: $position =~ s/\D+//g;
15932: if ($position ne '') {
15933: $allpos[$position] = $itemid;
15934: }
1.424 raeburn 15935: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 15936: my $formitem = 'form.lti_'.$item.'_'.$idx;
15937: $env{$formitem} =~ s/(`)/'/g;
15938: if ($item eq 'lifetime') {
15939: $env{$formitem} =~ s/[^\d.]//g;
15940: }
15941: if ($env{$formitem} ne '') {
1.424 raeburn 15942: $confhash{$itemid}{$item} = $env{$formitem};
15943: unless (($idx eq 'add') || ($changes{$itemid})) {
15944: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
15945: $changes{$itemid} = 1;
1.320 raeburn 15946: }
15947: }
15948: }
15949: }
15950: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
15951: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
15952: }
1.345 raeburn 15953: if ($confhash{$itemid}{'requser'}) {
15954: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 15955: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 15956: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
15957: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
15958: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
15959: my $mapuser = $env{'form.lti_customuser_'.$idx};
15960: $mapuser =~ s/(`)/'/g;
1.405 raeburn 15961: $mapuser =~ s/^\s+|\s+$//g;
15962: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 15963: }
15964: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
15965: my @makeuser;
15966: foreach my $ltirole (sort(@possmakeuser)) {
15967: if ($posslti{$ltirole}) {
15968: push(@makeuser,$ltirole);
15969: }
15970: }
15971: $confhash{$itemid}{'makeuser'} = \@makeuser;
15972: if (@makeuser) {
15973: my $lcauth = $env{'form.lti_lcauth_'.$idx};
15974: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
15975: $confhash{$itemid}{'lcauth'} = $lcauth;
15976: if ($lcauth ne 'internal') {
15977: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
15978: $lcauthparm =~ s/^(\s+|\s+)$//g;
15979: $lcauthparm =~ s/`//g;
15980: if ($lcauthparm ne '') {
15981: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
15982: }
15983: }
15984: } else {
15985: $confhash{$itemid}{'lcauth'} = 'lti';
15986: }
1.320 raeburn 15987: }
1.345 raeburn 15988: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
15989: if (@possinstdata) {
1.447.2.2 raeburn 15990: foreach my $field (sort(@possinstdata)) {
1.345 raeburn 15991: if (exists($fieldtitles{$field})) {
1.447.2.2 raeburn 15992: push(@{$confhash{$itemid}{'instdata'}},$field);
1.325 raeburn 15993: }
15994: }
15995: }
1.363 raeburn 15996: if ($env{'form.lti_callback_'.$idx}) {
15997: if ($env{'form.lti_callbackparam_'.$idx}) {
15998: my $callback = $env{'form.lti_callbackparam_'.$idx};
15999: $callback =~ s/^\s+|\s+$//g;
16000: $confhash{$itemid}{'callback'} = $callback;
16001: }
16002: }
1.391 raeburn 16003: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 16004: if ($env{'form.lti_'.$field.'_'.$idx}) {
16005: $confhash{$itemid}{$field} = 1;
16006: }
1.320 raeburn 16007: }
1.345 raeburn 16008: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
16009: $confhash{$itemid}{lcmenu} = [];
16010: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
16011: foreach my $field (@possmenu) {
16012: if (exists($menutitles{$field})) {
16013: if ($field eq 'grades') {
16014: next unless ($env{'form.lti_inlinemenu_'.$idx});
16015: }
16016: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 16017: }
16018: }
16019: }
1.391 raeburn 16020: if ($confhash{$itemid}{'crsinc'}) {
16021: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
16022: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
16023: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
16024: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
16025: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
16026: $mapcrs =~ s/(`)/'/g;
16027: $mapcrs =~ s/^\s+|\s+$//g;
16028: $confhash{$itemid}{'mapcrs'} = $mapcrs;
16029: }
16030: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
16031: my @crstypes;
16032: foreach my $type (sort(@posstypes)) {
16033: if ($posscrstype{$type}) {
16034: push(@crstypes,$type);
16035: }
16036: }
16037: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 16038: if ($env{'form.lti_storecrs_'.$idx}) {
16039: $confhash{$itemid}{'storecrs'} = 1;
16040: }
1.391 raeburn 16041: if ($env{'form.lti_makecrs_'.$idx}) {
16042: $confhash{$itemid}{'makecrs'} = 1;
16043: }
16044: foreach my $ltirole (@lticourseroles) {
16045: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
16046: if (grep(/^\Q$possrole\E$/,@courseroles)) {
16047: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
16048: }
16049: }
16050: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
16051: my @selfenroll;
16052: foreach my $type (sort(@possenroll)) {
16053: if ($posslticrs{$type}) {
16054: push(@selfenroll,$type);
16055: }
16056: }
16057: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
16058: if ($env{'form.lti_crssec_'.$idx}) {
16059: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
16060: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
16061: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
16062: my $section = $env{'form.lti_customsection_'.$idx};
16063: $section =~ s/(`)/'/g;
16064: $section =~ s/^\s+|\s+$//g;
16065: if ($section ne '') {
16066: $confhash{$itemid}{'section'} = $section;
16067: }
16068: }
16069: }
16070: foreach my $field ('passback','roster') {
16071: if ($env{'form.lti_'.$field.'_'.$idx}) {
16072: $confhash{$itemid}{$field} = 1;
16073: }
16074: }
16075: if ($env{'form.lti_passback_'.$idx}) {
16076: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
16077: $confhash{$itemid}{'passbackformat'} = '1.0';
16078: } else {
16079: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 16080: }
16081: }
1.391 raeburn 16082: }
16083: unless (($idx eq 'add') || ($changes{$itemid})) {
16084: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 16085: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 16086: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 16087: $changes{$itemid} = 1;
16088: }
1.345 raeburn 16089: }
16090: unless ($changes{$itemid}) {
1.424 raeburn 16091: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
16092: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 16093: $changes{$itemid} = 1;
16094: }
16095: }
1.345 raeburn 16096: }
1.391 raeburn 16097: foreach my $field ('mapcrstype','selfenroll') {
16098: unless ($changes{$itemid}) {
1.424 raeburn 16099: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16100: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16101: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16102: $confhash{$itemid}{$field});
16103: if (@diffs) {
16104: $changes{$itemid} = 1;
16105: }
1.424 raeburn 16106: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16107: $changes{$itemid} = 1;
16108: }
16109: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16110: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 16111: $changes{$itemid} = 1;
16112: }
16113: }
1.391 raeburn 16114: }
16115: }
16116: unless ($changes{$itemid}) {
1.424 raeburn 16117: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 16118: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 16119: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
16120: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 16121: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 16122: $changes{$itemid} = 1;
16123: last;
16124: }
16125: }
1.391 raeburn 16126: unless ($changes{$itemid}) {
16127: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
16128: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 16129: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 16130: $changes{$itemid} = 1;
16131: last;
16132: }
16133: }
16134: }
1.424 raeburn 16135: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 16136: $changes{$itemid} = 1;
1.345 raeburn 16137: }
1.391 raeburn 16138: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16139: unless ($changes{$itemid}) {
16140: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16141: $changes{$itemid} = 1;
16142: }
16143: }
16144: }
16145: }
16146: }
16147: unless ($changes{$itemid}) {
16148: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 16149: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16150: $changes{$itemid} = 1;
1.320 raeburn 16151: }
1.391 raeburn 16152: }
16153: unless ($changes{$itemid}) {
1.447.2.2 raeburn 16154: foreach my $field ('makeuser','lcmenu','instdata') {
1.424 raeburn 16155: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16156: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16157: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16158: $confhash{$itemid}{$field});
16159: if (@diffs) {
16160: $changes{$itemid} = 1;
16161: }
1.424 raeburn 16162: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16163: $changes{$itemid} = 1;
16164: }
16165: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16166: if (@{$confhash{$itemid}{$field}} > 0) {
16167: $changes{$itemid} = 1;
16168: }
1.345 raeburn 16169: }
1.320 raeburn 16170: }
16171: }
16172: }
16173: }
16174: }
1.424 raeburn 16175: if ($is_home) {
16176: my $keyitem = 'form.lti_key_'.$idx;
16177: $env{$keyitem} =~ s/(`)/'/g;
16178: if ($env{$keyitem} ne '') {
16179: $ltienc{$itemid}{'key'} = $env{$keyitem};
16180: unless ($changes{$itemid}) {
16181: if ($currlti{'key'} ne $env{$keyitem}) {
16182: $changes{$itemid} = 1;
16183: }
16184: }
16185: }
16186: my $secretitem = 'form.lti_secret_'.$idx;
16187: $env{$secretitem} =~ s/(`)/'/g;
16188: if ($currlti{'usable'}) {
16189: if ($env{'form.lti_changesecret_'.$idx}) {
16190: if ($env{$secretitem} ne '') {
16191: if ($privnum && $cipher) {
16192: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16193: $confhash{$itemid}{'cipher'} = $privnum;
16194: } else {
16195: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16196: }
16197: $changes{$itemid} = 1;
16198: }
16199: } else {
16200: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16201: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16202: }
16203: if (ref($ltienc{$itemid}) eq 'HASH') {
16204: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16205: $confhash{$itemid}{'usable'} = 1;
16206: }
16207: }
16208: } elsif ($env{$secretitem} ne '') {
16209: if ($privnum && $cipher) {
16210: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16211: $confhash{$itemid}{'cipher'} = $privnum;
16212: } else {
16213: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16214: }
16215: if (ref($ltienc{$itemid}) eq 'HASH') {
16216: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16217: $confhash{$itemid}{'usable'} = 1;
16218: }
16219: }
16220: $changes{$itemid} = 1;
16221: }
16222: }
16223: unless ($changes{$itemid}) {
16224: foreach my $key (keys(%currlti)) {
16225: if (ref($currlti{$key}) eq 'HASH') {
16226: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16227: foreach my $innerkey (keys(%{$currlti{$key}})) {
16228: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16229: $changes{$itemid} = 1;
16230: last;
16231: }
16232: }
16233: } elsif (keys(%{$currlti{$key}}) > 0) {
16234: $changes{$itemid} = 1;
16235: }
16236: }
16237: last if ($changes{$itemid});
16238: }
16239: }
1.320 raeburn 16240: }
16241: if (@allpos > 0) {
16242: my $idx = 0;
16243: foreach my $itemid (@allpos) {
16244: if ($itemid ne '') {
16245: $confhash{$itemid}{'order'} = $idx;
16246: if (ref($domconfig{$action}) eq 'HASH') {
16247: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16248: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16249: $changes{$itemid} = 1;
16250: }
16251: }
16252: }
16253: $idx ++;
16254: }
16255: }
16256: }
1.424 raeburn 16257:
16258: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16259: return &mt('No changes made.');
16260: }
16261:
1.320 raeburn 16262: my %ltihash = (
1.405 raeburn 16263: $action => { %confhash }
16264: );
1.424 raeburn 16265: my %ltienchash;
16266:
16267: if ($is_home) {
16268: %ltienchash = (
16269: $action => { %ltienc }
16270: );
16271: }
1.405 raeburn 16272: if (keys(%secchanges)) {
16273: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16274: if ($secchanges{'linkprot'}) {
16275: if ($is_home) {
16276: $ltienchash{'linkprot'} = \%newltienc;
16277: }
16278: }
1.405 raeburn 16279: }
16280: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16281: if ($putresult eq 'ok') {
1.424 raeburn 16282: if (keys(%ltienchash)) {
16283: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16284: }
16285: $resulttext = &mt('Changes made:').'<ul>';
16286: if (keys(%secchanges) > 0) {
1.423 raeburn 16287: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16288: if (exists($secchanges{'linkprot'})) {
16289: $resulttext .= $linkprotoutput;
1.405 raeburn 16290: }
16291: }
1.320 raeburn 16292: if (keys(%changes) > 0) {
16293: my $cachetime = 24*60*60;
1.424 raeburn 16294: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16295: if (ref($lastactref) eq 'HASH') {
16296: $lastactref->{'lti'} = 1;
16297: }
16298: my %bynum;
16299: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16300: if (ref($confhash{$itemid}) eq 'HASH') {
16301: my $position = $confhash{$itemid}{'order'};
16302: $bynum{$position} = $itemid;
16303: }
1.320 raeburn 16304: }
16305: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16306: my $itemid = $bynum{$pos};
1.424 raeburn 16307: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16308: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16309: my $position = $pos + 1;
16310: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16311: foreach my $item ('version','lifetime') {
16312: if ($confhash{$itemid}{$item} ne '') {
16313: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16314: }
16315: }
1.424 raeburn 16316: if ($ltienc{$itemid}{'key'} ne '') {
16317: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16318: }
1.424 raeburn 16319: if ($ltienc{$itemid}{'secret'} ne '') {
16320: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16321: }
1.345 raeburn 16322: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16323: if ($confhash{$itemid}{'callback'}) {
16324: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16325: } else {
1.392 raeburn 16326: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16327: }
1.345 raeburn 16328: if ($confhash{$itemid}{'mapuser'}) {
16329: my $shownmapuser;
16330: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16331: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16332: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16333: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16334: } else {
16335: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16336: }
1.345 raeburn 16337: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16338: }
1.345 raeburn 16339: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16340: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16341: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16342: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16343: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16344: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16345: } else {
16346: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16347: $confhash{$itemid}{'lcauth'});
16348: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16349: $resulttext .= '; '.&mt('a randomly generated password will be created');
16350: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16351: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16352: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16353: }
16354: } else {
16355: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16356: }
16357: }
16358: $resulttext .= '</li>';
16359: } else {
16360: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16361: }
1.320 raeburn 16362: }
1.345 raeburn 16363: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16364: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16365: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16366: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16367: } else {
1.447.2.2 raeburn 16368: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user').'</li>';
1.325 raeburn 16369: }
1.447.2.2 raeburn 16370: } else {
16371: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user').'</li>';
1.320 raeburn 16372: }
1.391 raeburn 16373: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16374: $resulttext .= '<li>'.$lt{$item}.': ';
16375: if ($confhash{$itemid}{$item}) {
16376: $resulttext .= &mt('Yes');
16377: } else {
16378: $resulttext .= &mt('No');
1.337 raeburn 16379: }
1.345 raeburn 16380: $resulttext .= '</li>';
1.320 raeburn 16381: }
1.345 raeburn 16382: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16383: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16384: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16385: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16386: } else {
16387: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16388: }
16389: }
16390: if ($confhash{$itemid}{'crsinc'}) {
16391: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16392: my $rolemaps;
16393: foreach my $role (@ltiroles) {
16394: if ($confhash{$itemid}{'maproles'}{$role}) {
16395: $rolemaps .= (' 'x2).$role.'='.
16396: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16397: 'Course').',';
16398: }
16399: }
16400: if ($rolemaps) {
16401: $rolemaps =~ s/,$//;
16402: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16403: }
16404: }
16405: if ($confhash{$itemid}{'mapcrs'}) {
16406: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16407: }
16408: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16409: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16410: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16411: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16412: '</li>';
16413: } else {
16414: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16415: }
16416: }
1.392 raeburn 16417: if ($confhash{$itemid}{'storecrs'}) {
16418: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16419: }
1.391 raeburn 16420: if ($confhash{$itemid}{'makecrs'}) {
16421: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16422: } else {
16423: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16424: }
16425: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16426: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16427: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16428: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16429: '</li>';
16430: } else {
16431: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16432: }
16433: }
16434: if ($confhash{$itemid}{'section'}) {
16435: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16436: $resulttext .= '<li>'.&mt('User section from standard field:').
16437: ' (course_section_sourcedid)'.'</li>';
16438: } else {
16439: $resulttext .= '<li>'.&mt('User section from:').' '.
16440: $confhash{$itemid}{'section'}.'</li>';
16441: }
1.345 raeburn 16442: } else {
1.391 raeburn 16443: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16444: }
16445: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16446: $resulttext .= '<li>'.$lt{$item}.': ';
16447: if ($confhash{$itemid}{$item}) {
16448: $resulttext .= &mt('Yes');
16449: if ($item eq 'passback') {
16450: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16451: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16452: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16453: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16454: }
16455: }
16456: } else {
16457: $resulttext .= &mt('No');
16458: }
16459: $resulttext .= '</li>';
16460: }
16461: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16462: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16463: $resulttext .= '<li>'.&mt('Menu items:').' '.
16464: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16465: } else {
16466: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16467: }
1.345 raeburn 16468: }
1.326 raeburn 16469: }
16470: }
1.320 raeburn 16471: $resulttext .= '</ul></li>';
16472: }
16473: }
1.424 raeburn 16474: if (keys(%deletions)) {
16475: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16476: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16477: }
16478: }
1.320 raeburn 16479: }
1.405 raeburn 16480: $resulttext .= '</ul>';
1.424 raeburn 16481: if (ref($lastactref) eq 'HASH') {
1.434 raeburn 16482: if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
16483: &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 16484: $lastactref->{'domdefaults'} = 1;
16485: }
16486: }
1.320 raeburn 16487: } else {
16488: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16489: }
16490: if ($errors) {
16491: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16492: $errors.'</ul>';
16493: }
16494: return $resulttext;
16495: }
16496:
1.424 raeburn 16497: sub get_priv_creds {
16498: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16499: my ($needenc,$cipher,$privnum);
16500: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16501: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16502: $needenc = $encrypt->{'consumers'}
16503: } else {
16504: $needenc = $domdefs{'ltienc_consumers'};
16505: }
16506: if ($needenc) {
16507: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16508: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16509: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16510: my $privkey = $privhash{'key'};
16511: $privnum = $privhash{'version'};
16512: if (($privnum) && ($privkey ne '')) {
16513: $cipher = Crypt::CBC->new({'key' => $privkey,
16514: 'cipher' => 'DES'});
16515: }
16516: }
16517: }
16518: return ($cipher,$privnum);
16519: }
16520:
1.320 raeburn 16521: sub get_lti_id {
1.434 raeburn 16522: my ($domain,$consumer,$dbname) = @_;
16523: unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
16524: return ('','invalid db');
16525: }
16526: # get lock on db
1.320 raeburn 16527: my $lockhash = {
16528: lock => $env{'user.name'}.
16529: ':'.$env{'user.domain'},
16530: };
16531: my $tries = 0;
1.434 raeburn 16532: my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16533: my ($id,$error);
16534:
16535: while (($gotlock ne 'ok') && ($tries<10)) {
16536: $tries ++;
16537: sleep (0.1);
1.434 raeburn 16538: $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16539: }
16540: if ($gotlock eq 'ok') {
1.434 raeburn 16541: my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1.320 raeburn 16542: if ($currids{'lock'}) {
16543: delete($currids{'lock'});
16544: if (keys(%currids)) {
16545: my @curr = sort { $a <=> $b } keys(%currids);
16546: if ($curr[-1] =~ /^\d+$/) {
16547: $id = 1 + $curr[-1];
16548: }
16549: } else {
16550: $id = 1;
16551: }
16552: if ($id) {
1.434 raeburn 16553: unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1.320 raeburn 16554: $error = 'nostore';
16555: }
16556: } else {
16557: $error = 'nonumber';
16558: }
16559: }
1.434 raeburn 16560: my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1.320 raeburn 16561: } else {
16562: $error = 'nolock';
16563: }
16564: return ($id,$error);
16565: }
16566:
1.3 raeburn 16567: sub modify_autoenroll {
1.205 raeburn 16568: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16569: my ($resulttext,%changes);
16570: my %currautoenroll;
16571: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16572: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16573: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16574: }
16575: }
16576: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16577: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16578: sender => 'Sender for notification messages',
1.274 raeburn 16579: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16580: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16581: my @offon = ('off','on');
1.17 raeburn 16582: my $sender_uname = $env{'form.sender_uname'};
16583: my $sender_domain = $env{'form.sender_domain'};
16584: if ($sender_domain eq '') {
16585: $sender_uname = '';
16586: } elsif ($sender_uname eq '') {
16587: $sender_domain = '';
16588: }
1.129 raeburn 16589: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16590: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16591: $autofailsafe =~ s{^\s+|\s+$}{}g;
16592: if ($autofailsafe =~ /\D/) {
16593: undef($autofailsafe);
16594: }
1.274 raeburn 16595: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16596: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16597: $failsafe = 'off';
1.400 raeburn 16598: undef($autofailsafe);
1.274 raeburn 16599: }
1.1 raeburn 16600: my %autoenrollhash = (
1.129 raeburn 16601: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16602: 'sender_uname' => $sender_uname,
16603: 'sender_domain' => $sender_domain,
16604: 'co-owners' => $coowners,
1.399 raeburn 16605: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16606: 'failsafe' => $failsafe,
1.1 raeburn 16607: }
16608: );
1.4 raeburn 16609: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16610: $dom);
1.1 raeburn 16611: if ($putresult eq 'ok') {
16612: if (exists($currautoenroll{'run'})) {
16613: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16614: $changes{'run'} = 1;
16615: }
16616: } elsif ($autorun) {
16617: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16618: $changes{'run'} = 1;
1.1 raeburn 16619: }
16620: }
1.17 raeburn 16621: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16622: $changes{'sender'} = 1;
16623: }
1.17 raeburn 16624: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16625: $changes{'sender'} = 1;
16626: }
1.129 raeburn 16627: if ($currautoenroll{'co-owners'} ne '') {
16628: if ($currautoenroll{'co-owners'} ne $coowners) {
16629: $changes{'coowners'} = 1;
16630: }
16631: } elsif ($coowners) {
16632: $changes{'coowners'} = 1;
1.274 raeburn 16633: }
1.399 raeburn 16634: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16635: $changes{'autofailsafe'} = 1;
16636: }
1.399 raeburn 16637: if ($currautoenroll{'failsafe'} ne $failsafe) {
16638: $changes{'failsafe'} = 1;
16639: }
1.1 raeburn 16640: if (keys(%changes) > 0) {
16641: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16642: if ($changes{'run'}) {
1.1 raeburn 16643: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16644: }
16645: if ($changes{'sender'}) {
1.17 raeburn 16646: if ($sender_uname eq '' || $sender_domain eq '') {
16647: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16648: } else {
16649: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16650: }
1.1 raeburn 16651: }
1.129 raeburn 16652: if ($changes{'coowners'}) {
16653: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16654: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16655: if (ref($lastactref) eq 'HASH') {
16656: $lastactref->{'domainconfig'} = 1;
16657: }
1.129 raeburn 16658: }
1.274 raeburn 16659: if ($changes{'autofailsafe'}) {
1.399 raeburn 16660: if ($autofailsafe ne '') {
16661: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16662: } else {
1.399 raeburn 16663: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16664: }
1.399 raeburn 16665: }
16666: if ($changes{'failsafe'}) {
16667: if ($failsafe eq 'off') {
16668: unless ($changes{'autofailsafe'}) {
16669: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16670: }
16671: } elsif ($failsafe eq 'zero') {
16672: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16673: } else {
16674: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16675: }
16676: }
16677: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16678: &Apache::lonnet::get_domain_defaults($dom,1);
16679: if (ref($lastactref) eq 'HASH') {
16680: $lastactref->{'domdefaults'} = 1;
16681: }
16682: }
1.1 raeburn 16683: $resulttext .= '</ul>';
16684: } else {
16685: $resulttext = &mt('No changes made to auto-enrollment settings');
16686: }
16687: } else {
1.11 albertel 16688: $resulttext = '<span class="LC_error">'.
16689: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16690: }
1.3 raeburn 16691: return $resulttext;
1.1 raeburn 16692: }
16693:
16694: sub modify_autoupdate {
1.3 raeburn 16695: my ($dom,%domconfig) = @_;
1.1 raeburn 16696: my ($resulttext,%currautoupdate,%fields,%changes);
16697: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16698: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16699: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16700: }
16701: }
16702: my @offon = ('off','on');
16703: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16704: run => 'Auto-update:',
16705: classlists => 'Updates to user information in classlists?',
16706: unexpired => 'Skip updates for users without active or future roles?',
16707: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16708: );
1.44 raeburn 16709: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16710: my %fieldtitles = &Apache::lonlocal::texthash (
16711: id => 'Student/Employee ID',
1.20 raeburn 16712: permanentemail => 'E-mail address',
1.1 raeburn 16713: lastname => 'Last Name',
16714: firstname => 'First Name',
16715: middlename => 'Middle Name',
1.132 raeburn 16716: generation => 'Generation',
1.1 raeburn 16717: );
1.142 raeburn 16718: $othertitle = &mt('All users');
1.1 raeburn 16719: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16720: $othertitle = &mt('Other users');
1.1 raeburn 16721: }
16722: foreach my $key (keys(%env)) {
16723: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16724: my ($usertype,$item) = ($1,$2);
16725: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16726: if ($usertype eq 'default') {
16727: push(@{$fields{$1}},$2);
16728: } elsif (ref($types) eq 'ARRAY') {
16729: if (grep(/^\Q$usertype\E$/,@{$types})) {
16730: push(@{$fields{$1}},$2);
16731: }
16732: }
16733: }
1.1 raeburn 16734: }
16735: }
1.131 raeburn 16736: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16737: @lockablenames = sort(@lockablenames);
16738: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16739: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16740: if (@changed) {
16741: $changes{'lockablenames'} = 1;
16742: }
16743: } else {
16744: if (@lockablenames) {
16745: $changes{'lockablenames'} = 1;
16746: }
16747: }
1.1 raeburn 16748: my %updatehash = (
16749: autoupdate => { run => $env{'form.autoupdate_run'},
16750: classlists => $env{'form.classlists'},
1.385 raeburn 16751: unexpired => $env{'form.unexpired'},
1.1 raeburn 16752: fields => {%fields},
1.131 raeburn 16753: lockablenames => \@lockablenames,
1.1 raeburn 16754: }
16755: );
1.385 raeburn 16756: my $lastactivedays;
16757: if ($env{'form.lastactive'}) {
16758: $lastactivedays = $env{'form.lastactivedays'};
16759: $lastactivedays =~ s/^\s+|\s+$//g;
16760: unless ($lastactivedays =~ /^\d+$/) {
16761: undef($lastactivedays);
16762: $env{'form.lastactive'} = 0;
16763: }
16764: }
16765: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16766: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16767: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16768: if (exists($updatehash{autoupdate}{$key})) {
16769: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16770: $changes{$key} = 1;
16771: }
16772: }
16773: } elsif ($key eq 'fields') {
16774: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16775: foreach my $item (@{$types},'default') {
1.1 raeburn 16776: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16777: my $change = 0;
16778: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16779: if (!exists($fields{$item})) {
16780: $change = 1;
1.132 raeburn 16781: last;
1.1 raeburn 16782: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16783: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16784: $change = 1;
1.132 raeburn 16785: last;
1.1 raeburn 16786: }
16787: }
16788: }
16789: if ($change) {
16790: push(@{$changes{$key}},$item);
16791: }
1.26 raeburn 16792: }
1.1 raeburn 16793: }
16794: }
1.131 raeburn 16795: } elsif ($key eq 'lockablenames') {
16796: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16797: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16798: if (@changed) {
16799: $changes{'lockablenames'} = 1;
16800: }
16801: } else {
16802: if (@lockablenames) {
16803: $changes{'lockablenames'} = 1;
16804: }
16805: }
16806: }
16807: }
16808: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16809: if (@lockablenames) {
16810: $changes{'lockablenames'} = 1;
1.1 raeburn 16811: }
16812: }
1.385 raeburn 16813: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16814: if ($updatehash{'autoupdate'}{'unexpired'}) {
16815: $changes{'unexpired'} = 1;
16816: }
16817: }
16818: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16819: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16820: $changes{'lastactive'} = 1;
16821: }
16822: }
1.26 raeburn 16823: foreach my $item (@{$types},'default') {
16824: if (defined($fields{$item})) {
16825: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16826: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16827: my $change = 0;
16828: if (ref($fields{$item}) eq 'ARRAY') {
16829: foreach my $type (@{$fields{$item}}) {
16830: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16831: $change = 1;
16832: last;
16833: }
16834: }
16835: }
16836: if ($change) {
16837: push(@{$changes{'fields'}},$item);
16838: }
16839: } else {
1.26 raeburn 16840: push(@{$changes{'fields'}},$item);
16841: }
16842: } else {
16843: push(@{$changes{'fields'}},$item);
1.1 raeburn 16844: }
16845: }
16846: }
16847: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16848: $dom);
16849: if ($putresult eq 'ok') {
16850: if (keys(%changes) > 0) {
16851: $resulttext = &mt('Changes made:').'<ul>';
16852: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16853: if ($key eq 'lockablenames') {
16854: $resulttext .= '<li>';
16855: if (@lockablenames) {
16856: $usertypes->{'default'} = $othertitle;
16857: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16858: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16859: } else {
16860: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16861: }
16862: $resulttext .= '</li>';
16863: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16864: foreach my $item (@{$changes{$key}}) {
16865: my @newvalues;
16866: foreach my $type (@{$fields{$item}}) {
16867: push(@newvalues,$fieldtitles{$type});
16868: }
1.3 raeburn 16869: my $newvaluestr;
16870: if (@newvalues > 0) {
16871: $newvaluestr = join(', ',@newvalues);
16872: } else {
16873: $newvaluestr = &mt('none');
1.6 raeburn 16874: }
1.1 raeburn 16875: if ($item eq 'default') {
1.26 raeburn 16876: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16877: } else {
1.26 raeburn 16878: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16879: }
16880: }
16881: } else {
16882: my $newvalue;
16883: if ($key eq 'run') {
16884: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16885: } elsif ($key eq 'lastactive') {
16886: $newvalue = $offon[$env{'form.lastactive'}];
16887: unless ($lastactivedays eq '') {
16888: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16889: }
1.1 raeburn 16890: } else {
16891: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16892: }
1.1 raeburn 16893: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16894: }
16895: }
16896: $resulttext .= '</ul>';
16897: } else {
1.3 raeburn 16898: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16899: }
16900: } else {
1.11 albertel 16901: $resulttext = '<span class="LC_error">'.
16902: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16903: }
1.3 raeburn 16904: return $resulttext;
1.1 raeburn 16905: }
16906:
1.125 raeburn 16907: sub modify_autocreate {
16908: my ($dom,%domconfig) = @_;
16909: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
16910: if (ref($domconfig{'autocreate'}) eq 'HASH') {
16911: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
16912: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
16913: }
16914: }
16915: my %title= ( xml => 'Auto-creation of courses in XML course description files',
16916: req => 'Auto-creation of validated requests for official courses',
16917: xmldc => 'Identity of course creator of courses from XML files',
16918: );
16919: my @types = ('xml','req');
16920: foreach my $item (@types) {
16921: $newvals{$item} = $env{'form.autocreate_'.$item};
16922: $newvals{$item} =~ s/\D//g;
16923: $newvals{$item} = 0 if ($newvals{$item} eq '');
16924: }
16925: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 16926: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 16927: unless (exists($domcoords{$newvals{'xmldc'}})) {
16928: $newvals{'xmldc'} = '';
16929: }
16930: %autocreatehash = (
16931: autocreate => { xml => $newvals{'xml'},
16932: req => $newvals{'req'},
16933: }
16934: );
16935: if ($newvals{'xmldc'} ne '') {
16936: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
16937: }
16938: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
16939: $dom);
16940: if ($putresult eq 'ok') {
16941: my @items = @types;
16942: if ($newvals{'xml'}) {
16943: push(@items,'xmldc');
16944: }
16945: foreach my $item (@items) {
16946: if (exists($currautocreate{$item})) {
16947: if ($currautocreate{$item} ne $newvals{$item}) {
16948: $changes{$item} = 1;
16949: }
16950: } elsif ($newvals{$item}) {
16951: $changes{$item} = 1;
16952: }
16953: }
16954: if (keys(%changes) > 0) {
16955: my @offon = ('off','on');
16956: $resulttext = &mt('Changes made:').'<ul>';
16957: foreach my $item (@types) {
16958: if ($changes{$item}) {
16959: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 16960: $resulttext .= '<li>'.
16961: &mt("$title{$item} set to [_1]$newtxt [_2]",
16962: '<b>','</b>').
16963: '</li>';
1.125 raeburn 16964: }
16965: }
16966: if ($changes{'xmldc'}) {
16967: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
16968: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 16969: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 16970: }
16971: $resulttext .= '</ul>';
16972: } else {
16973: $resulttext = &mt('No changes made to auto-creation settings');
16974: }
16975: } else {
16976: $resulttext = '<span class="LC_error">'.
16977: &mt('An error occurred: [_1]',$putresult).'</span>';
16978: }
16979: return $resulttext;
16980: }
16981:
1.23 raeburn 16982: sub modify_directorysrch {
1.295 raeburn 16983: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 16984: my ($resulttext,%changes);
16985: my %currdirsrch;
16986: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
16987: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
16988: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
16989: }
16990: }
1.277 raeburn 16991: my %title = ( available => 'Institutional directory search available',
16992: localonly => 'Other domains can search institution',
16993: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 16994: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 16995: searchby => 'Search types',
16996: searchtypes => 'Search latitude');
16997: my @offon = ('off','on');
1.24 raeburn 16998: my @otherdoms = ('Yes','No');
1.23 raeburn 16999:
1.25 raeburn 17000: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 17001: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
17002: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
17003:
1.44 raeburn 17004: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 17005: if (keys(%{$usertypes}) == 0) {
17006: @cansearch = ('default');
17007: } else {
17008: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
17009: foreach my $type (@{$currdirsrch{'cansearch'}}) {
17010: if (!grep(/^\Q$type\E$/,@cansearch)) {
17011: push(@{$changes{'cansearch'}},$type);
17012: }
1.23 raeburn 17013: }
1.26 raeburn 17014: foreach my $type (@cansearch) {
17015: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
17016: push(@{$changes{'cansearch'}},$type);
17017: }
1.23 raeburn 17018: }
1.26 raeburn 17019: } else {
17020: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 17021: }
17022: }
17023:
17024: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
17025: foreach my $by (@{$currdirsrch{'searchby'}}) {
17026: if (!grep(/^\Q$by\E$/,@searchby)) {
17027: push(@{$changes{'searchby'}},$by);
17028: }
17029: }
17030: foreach my $by (@searchby) {
17031: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
17032: push(@{$changes{'searchby'}},$by);
17033: }
17034: }
17035: } else {
17036: push(@{$changes{'searchby'}},@searchby);
17037: }
1.25 raeburn 17038:
17039: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
17040: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
17041: if (!grep(/^\Q$type\E$/,@searchtypes)) {
17042: push(@{$changes{'searchtypes'}},$type);
17043: }
17044: }
17045: foreach my $type (@searchtypes) {
17046: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
17047: push(@{$changes{'searchtypes'}},$type);
17048: }
17049: }
17050: } else {
17051: if (exists($currdirsrch{'searchtypes'})) {
17052: foreach my $type (@searchtypes) {
17053: if ($type ne $currdirsrch{'searchtypes'}) {
17054: push(@{$changes{'searchtypes'}},$type);
17055: }
17056: }
17057: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
17058: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
17059: }
17060: } else {
17061: push(@{$changes{'searchtypes'}},@searchtypes);
17062: }
17063: }
17064:
1.23 raeburn 17065: my %dirsrch_hash = (
17066: directorysrch => { available => $env{'form.dirsrch_available'},
17067: cansearch => \@cansearch,
1.277 raeburn 17068: localonly => $env{'form.dirsrch_instlocalonly'},
17069: lclocalonly => $env{'form.dirsrch_domlocalonly'},
17070: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 17071: searchby => \@searchby,
1.25 raeburn 17072: searchtypes => \@searchtypes,
1.23 raeburn 17073: }
17074: );
17075: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
17076: $dom);
17077: if ($putresult eq 'ok') {
17078: if (exists($currdirsrch{'available'})) {
17079: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
17080: $changes{'available'} = 1;
17081: }
17082: } else {
17083: if ($env{'form.dirsrch_available'} eq '1') {
17084: $changes{'available'} = 1;
17085: }
17086: }
1.277 raeburn 17087: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 17088: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
17089: $changes{'lcavailable'} = 1;
17090: }
1.277 raeburn 17091: } else {
17092: if ($env{'form.dirsrch_lcavailable'} eq '1') {
17093: $changes{'lcavailable'} = 1;
17094: }
17095: }
1.24 raeburn 17096: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 17097: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
17098: $changes{'localonly'} = 1;
17099: }
1.24 raeburn 17100: } else {
1.277 raeburn 17101: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 17102: $changes{'localonly'} = 1;
17103: }
17104: }
1.277 raeburn 17105: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 17106: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
17107: $changes{'lclocalonly'} = 1;
17108: }
1.277 raeburn 17109: } else {
17110: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
17111: $changes{'lclocalonly'} = 1;
17112: }
17113: }
1.23 raeburn 17114: if (keys(%changes) > 0) {
17115: $resulttext = &mt('Changes made:').'<ul>';
17116: if ($changes{'available'}) {
17117: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
17118: }
1.277 raeburn 17119: if ($changes{'lcavailable'}) {
17120: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
17121: }
1.24 raeburn 17122: if ($changes{'localonly'}) {
1.277 raeburn 17123: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 17124: }
1.277 raeburn 17125: if ($changes{'lclocalonly'}) {
17126: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 17127: }
1.23 raeburn 17128: if (ref($changes{'cansearch'}) eq 'ARRAY') {
17129: my $chgtext;
1.26 raeburn 17130: if (ref($usertypes) eq 'HASH') {
17131: if (keys(%{$usertypes}) > 0) {
17132: foreach my $type (@{$types}) {
17133: if (grep(/^\Q$type\E$/,@cansearch)) {
17134: $chgtext .= $usertypes->{$type}.'; ';
17135: }
17136: }
17137: if (grep(/^default$/,@cansearch)) {
17138: $chgtext .= $othertitle;
17139: } else {
17140: $chgtext =~ s/\; $//;
17141: }
1.210 raeburn 17142: $resulttext .=
1.178 raeburn 17143: '<li>'.
17144: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17145: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17146: '</li>';
1.23 raeburn 17147: }
17148: }
17149: }
17150: if (ref($changes{'searchby'}) eq 'ARRAY') {
17151: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17152: my $chgtext;
17153: foreach my $type (@{$titleorder}) {
17154: if (grep(/^\Q$type\E$/,@searchby)) {
17155: if (defined($searchtitles->{$type})) {
17156: $chgtext .= $searchtitles->{$type}.'; ';
17157: }
17158: }
17159: }
17160: $chgtext =~ s/\; $//;
17161: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17162: }
1.25 raeburn 17163: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17164: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17165: my $chgtext;
17166: foreach my $type (@{$srchtypeorder}) {
17167: if (grep(/^\Q$type\E$/,@searchtypes)) {
17168: if (defined($srchtypes_desc->{$type})) {
17169: $chgtext .= $srchtypes_desc->{$type}.'; ';
17170: }
17171: }
17172: }
17173: $chgtext =~ s/\; $//;
1.178 raeburn 17174: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17175: }
17176: $resulttext .= '</ul>';
1.295 raeburn 17177: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17178: if (ref($lastactref) eq 'HASH') {
17179: $lastactref->{'directorysrch'} = 1;
17180: }
1.23 raeburn 17181: } else {
1.277 raeburn 17182: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17183: }
17184: } else {
17185: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17186: &mt('An error occurred: [_1]',$putresult).'</span>';
17187: }
17188: return $resulttext;
17189: }
17190:
1.28 raeburn 17191: sub modify_contacts {
1.205 raeburn 17192: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17193: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17194: if (ref($domconfig{'contacts'}) eq 'HASH') {
17195: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17196: $currsetting{$key} = $domconfig{'contacts'}{$key};
17197: }
17198: }
1.286 raeburn 17199: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17200: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17201: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17202: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17203: my @toggles = ('reporterrors','reportupdates','reportstatus');
17204: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17205: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17206: foreach my $type (@mailings) {
17207: @{$newsetting{$type}} =
17208: &Apache::loncommon::get_env_multiple('form.'.$type);
17209: foreach my $item (@contacts) {
17210: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17211: $contacts_hash{contacts}{$type}{$item} = 1;
17212: } else {
17213: $contacts_hash{contacts}{$type}{$item} = 0;
17214: }
1.289 raeburn 17215: }
1.28 raeburn 17216: $others{$type} = $env{'form.'.$type.'_others'};
17217: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17218: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17219: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17220: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17221: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17222: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17223: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17224: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17225: }
1.134 raeburn 17226: }
1.28 raeburn 17227: }
17228: foreach my $item (@contacts) {
17229: $to{$item} = $env{'form.'.$item};
17230: $contacts_hash{'contacts'}{$item} = $to{$item};
17231: }
1.203 raeburn 17232: foreach my $item (@toggles) {
17233: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17234: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17235: }
17236: }
1.340 raeburn 17237: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17238: foreach my $item (@lonstatus) {
17239: if ($item eq 'excluded') {
17240: my (%serverhomes,@excluded);
17241: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17242: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17243: if (@possexcluded) {
17244: foreach my $id (sort(@possexcluded)) {
17245: if ($serverhomes{$id}) {
17246: push(@excluded,$id);
17247: }
17248: }
17249: }
17250: if (@excluded) {
17251: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17252: }
17253: } elsif ($item eq 'weights') {
1.377 raeburn 17254: foreach my $type ('E','W','N','U') {
1.340 raeburn 17255: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17256: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17257: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17258: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17259: $env{'form.error'.$item.'_'.$type};
17260: }
17261: }
17262: }
17263: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17264: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17265: if ($env{'form.error'.$item} =~ /^\d+$/) {
17266: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17267: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17268: }
17269: }
17270: }
17271: }
1.286 raeburn 17272: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17273: foreach my $field (@{$fields}) {
17274: if (ref($possoptions->{$field}) eq 'ARRAY') {
17275: my $value = $env{'form.helpform_'.$field};
17276: $value =~ s/^\s+|\s+$//g;
17277: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17278: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17279: if ($field eq 'screenshot') {
17280: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17281: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17282: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17283: }
17284: }
17285: }
17286: }
17287: }
17288: }
1.315 raeburn 17289: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17290: my (@statuses,%usertypeshash,@overrides);
17291: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17292: @statuses = @{$types};
17293: if (ref($usertypes) eq 'HASH') {
17294: %usertypeshash = %{$usertypes};
17295: }
17296: }
17297: if (@statuses) {
17298: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17299: foreach my $type (@possoverrides) {
17300: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17301: push(@overrides,$type);
17302: }
17303: }
17304: if (@overrides) {
17305: foreach my $type (@overrides) {
17306: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17307: foreach my $item (@contacts) {
17308: if (grep(/^\Q$item\E$/,@standard)) {
17309: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17310: $newsetting{'override_'.$type}{$item} = 1;
17311: } else {
17312: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17313: $newsetting{'override_'.$type}{$item} = 0;
17314: }
17315: }
17316: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17317: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17318: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17319: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17320: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17321: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17322: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17323: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17324: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17325: }
1.425 raeburn 17326: }
1.315 raeburn 17327: }
17328: }
1.28 raeburn 17329: if (keys(%currsetting) > 0) {
17330: foreach my $item (@contacts) {
17331: if ($to{$item} ne $currsetting{$item}) {
17332: $changes{$item} = 1;
17333: }
17334: }
17335: foreach my $type (@mailings) {
17336: foreach my $item (@contacts) {
17337: if (ref($currsetting{$type}) eq 'HASH') {
17338: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17339: push(@{$changes{$type}},$item);
17340: }
17341: } else {
17342: push(@{$changes{$type}},@{$newsetting{$type}});
17343: }
17344: }
17345: if ($others{$type} ne $currsetting{$type}{'others'}) {
17346: push(@{$changes{$type}},'others');
17347: }
1.289 raeburn 17348: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17349: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17350: push(@{$changes{$type}},'bcc');
17351: }
1.286 raeburn 17352: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17353: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17354: push(@{$changes{$type}},'include');
17355: }
17356: }
17357: }
17358: if (ref($fields) eq 'ARRAY') {
17359: if (ref($currsetting{'helpform'}) eq 'HASH') {
17360: foreach my $field (@{$fields}) {
17361: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17362: push(@{$changes{'helpform'}},$field);
17363: }
17364: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17365: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17366: push(@{$changes{'helpform'}},'maxsize');
17367: }
17368: }
17369: }
17370: } else {
17371: foreach my $field (@{$fields}) {
17372: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17373: push(@{$changes{'helpform'}},$field);
17374: }
17375: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17376: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17377: push(@{$changes{'helpform'}},'maxsize');
17378: }
17379: }
17380: }
1.134 raeburn 17381: }
1.28 raeburn 17382: }
1.315 raeburn 17383: if (@statuses) {
1.425 raeburn 17384: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17385: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17386: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17387: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17388: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17389: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17390: push(@{$changes{'overrides'}},$key);
17391: last;
17392: }
17393: }
17394: } else {
17395: push(@{$changes{'overrides'}},$key);
17396: }
17397: }
17398: }
17399: foreach my $key (@overrides) {
17400: unless (exists($currsetting{'overrides'}{$key})) {
17401: push(@{$changes{'overrides'}},$key);
17402: }
17403: }
17404: } else {
17405: foreach my $key (@overrides) {
1.425 raeburn 17406: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17407: }
17408: }
17409: }
1.340 raeburn 17410: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17411: foreach my $key ('excluded','weights','threshold','sysmail') {
17412: if ($key eq 'excluded') {
17413: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17414: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17415: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17416: (@{$currsetting{'lonstatus'}{$key}})) {
17417: my @diffs =
17418: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17419: $currsetting{'lonstatus'}{$key});
17420: if (@diffs) {
17421: push(@{$changes{'lonstatus'}},$key);
17422: }
17423: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17424: push(@{$changes{'lonstatus'}},$key);
17425: }
17426: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17427: (@{$currsetting{'lonstatus'}{$key}})) {
17428: push(@{$changes{'lonstatus'}},$key);
17429: }
17430: } elsif ($key eq 'weights') {
17431: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17432: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17433: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17434: foreach my $type ('E','W','N','U') {
1.340 raeburn 17435: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17436: $currsetting{'lonstatus'}{$key}{$type}) {
17437: push(@{$changes{'lonstatus'}},$key);
17438: last;
17439: }
17440: }
17441: } else {
1.341 raeburn 17442: foreach my $type ('E','W','N','U') {
1.340 raeburn 17443: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17444: push(@{$changes{'lonstatus'}},$key);
17445: last;
17446: }
17447: }
17448: }
17449: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17450: foreach my $type ('E','W','N','U') {
1.340 raeburn 17451: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17452: push(@{$changes{'lonstatus'}},$key);
17453: last;
17454: }
17455: }
17456: }
17457: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17458: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17459: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17460: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17461: push(@{$changes{'lonstatus'}},$key);
17462: }
17463: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17464: push(@{$changes{'lonstatus'}},$key);
17465: }
17466: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17467: push(@{$changes{'lonstatus'}},$key);
17468: }
17469: }
17470: }
17471: } else {
17472: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17473: foreach my $key ('excluded','weights','threshold','sysmail') {
17474: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17475: push(@{$changes{'lonstatus'}},$key);
17476: }
17477: }
17478: }
17479: }
1.28 raeburn 17480: } else {
17481: my %default;
17482: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17483: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17484: $default{'errormail'} = 'adminemail';
17485: $default{'packagesmail'} = 'adminemail';
17486: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17487: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17488: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17489: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17490: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17491: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17492: foreach my $item (@contacts) {
17493: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17494: $changes{$item} = 1;
1.203 raeburn 17495: }
1.28 raeburn 17496: }
17497: foreach my $type (@mailings) {
17498: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17499: push(@{$changes{$type}},@{$newsetting{$type}});
17500: }
17501: if ($others{$type} ne '') {
17502: push(@{$changes{$type}},'others');
1.134 raeburn 17503: }
1.286 raeburn 17504: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17505: if ($bcc{$type} ne '') {
17506: push(@{$changes{$type}},'bcc');
17507: }
1.286 raeburn 17508: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17509: push(@{$changes{$type}},'include');
17510: }
1.134 raeburn 17511: }
1.28 raeburn 17512: }
1.286 raeburn 17513: if (ref($fields) eq 'ARRAY') {
17514: foreach my $field (@{$fields}) {
17515: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17516: push(@{$changes{'helpform'}},$field);
17517: }
17518: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17519: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17520: push(@{$changes{'helpform'}},'maxsize');
17521: }
17522: }
17523: }
1.289 raeburn 17524: }
1.340 raeburn 17525: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17526: foreach my $key ('excluded','weights','threshold','sysmail') {
17527: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17528: push(@{$changes{'lonstatus'}},$key);
17529: }
17530: }
17531: }
1.28 raeburn 17532: }
1.203 raeburn 17533: foreach my $item (@toggles) {
17534: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17535: $changes{$item} = 1;
17536: } elsif ((!$env{'form.'.$item}) &&
17537: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17538: $changes{$item} = 1;
17539: }
17540: }
1.28 raeburn 17541: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17542: $dom);
17543: if ($putresult eq 'ok') {
17544: if (keys(%changes) > 0) {
1.205 raeburn 17545: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17546: if (ref($lastactref) eq 'HASH') {
17547: $lastactref->{'domainconfig'} = 1;
17548: }
1.28 raeburn 17549: my ($titles,$short_titles) = &contact_titles();
17550: $resulttext = &mt('Changes made:').'<ul>';
17551: foreach my $item (@contacts) {
17552: if ($changes{$item}) {
17553: $resulttext .= '<li>'.$titles->{$item}.
17554: &mt(' set to: ').
17555: '<span class="LC_cusr_emph">'.
17556: $to{$item}.'</span></li>';
17557: }
17558: }
17559: foreach my $type (@mailings) {
17560: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17561: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17562: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17563: } else {
17564: $resulttext .= '<li>'.$titles->{$type}.': ';
17565: }
1.28 raeburn 17566: my @text;
17567: foreach my $item (@{$newsetting{$type}}) {
17568: push(@text,$short_titles->{$item});
17569: }
17570: if ($others{$type} ne '') {
17571: push(@text,$others{$type});
17572: }
1.286 raeburn 17573: if (@text) {
17574: $resulttext .= '<span class="LC_cusr_emph">'.
17575: join(', ',@text).'</span>';
17576: }
17577: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17578: if ($bcc{$type} ne '') {
1.286 raeburn 17579: my $bcctext;
17580: if (@text) {
1.289 raeburn 17581: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17582: } else {
17583: $bcctext = '(Bcc)';
17584: }
17585: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17586: } elsif (!@text) {
17587: $resulttext .= &mt('No one');
1.425 raeburn 17588: }
1.289 raeburn 17589: if ($includestr{$type} ne '') {
1.286 raeburn 17590: if ($includeloc{$type} eq 'b') {
17591: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17592: } elsif ($includeloc{$type} eq 's') {
17593: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17594: }
1.134 raeburn 17595: }
1.286 raeburn 17596: } elsif (!@text) {
17597: $resulttext .= &mt('No recipients');
1.134 raeburn 17598: }
17599: $resulttext .= '</li>';
1.28 raeburn 17600: }
17601: }
1.315 raeburn 17602: if (ref($changes{'overrides'}) eq 'ARRAY') {
17603: my @deletions;
17604: foreach my $type (@{$changes{'overrides'}}) {
17605: if ($usertypeshash{$type}) {
17606: if (grep(/^\Q$type\E/,@overrides)) {
17607: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17608: $usertypeshash{$type}).'<ul><li>';
17609: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17610: my @text;
17611: foreach my $item (@contacts) {
1.425 raeburn 17612: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17613: push(@text,$short_titles->{$item});
17614: }
17615: }
17616: if ($newsetting{'override_'.$type}{'others'} ne '') {
17617: push(@text,$newsetting{'override_'.$type}{'others'});
17618: }
1.425 raeburn 17619:
1.315 raeburn 17620: if (@text) {
17621: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17622: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17623: }
17624: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17625: my $bcctext;
17626: if (@text) {
17627: $bcctext = ' '.&mt('with Bcc to');
17628: } else {
17629: $bcctext = '(Bcc)';
17630: }
17631: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17632: } elsif (!@text) {
17633: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17634: }
17635: $resulttext .= '</li>';
17636: if ($newsetting{'override_'.$type}{'include'} ne '') {
17637: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17638: if ($loc eq 'b') {
17639: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17640: } elsif ($loc eq 's') {
17641: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17642: }
17643: }
17644: }
17645: $resulttext .= '</li></ul></li>';
17646: } else {
17647: push(@deletions,$usertypeshash{$type});
17648: }
17649: }
17650: }
17651: if (@deletions) {
17652: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17653: join(', ',@deletions)).'</li>';
17654: }
17655: }
1.203 raeburn 17656: my @offon = ('off','on');
1.340 raeburn 17657: my $corelink = &core_link_msu();
1.203 raeburn 17658: if ($changes{'reporterrors'}) {
17659: $resulttext .= '<li>'.
17660: &mt('E-mail error reports to [_1] set to "'.
17661: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17662: $corelink).
1.203 raeburn 17663: '</li>';
17664: }
17665: if ($changes{'reportupdates'}) {
17666: $resulttext .= '<li>'.
17667: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17668: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17669: $corelink).
1.203 raeburn 17670: '</li>';
17671: }
1.340 raeburn 17672: if ($changes{'reportstatus'}) {
17673: $resulttext .= '<li>'.
17674: &mt('E-mail status if errors above threshold to [_1] set to "'.
17675: $offon[$env{'form.reportstatus'}].'".',
17676: $corelink).
17677: '</li>';
17678: }
17679: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17680: $resulttext .= '<li>'.
17681: &mt('Nightly status check e-mail settings').':<ul>';
17682: my (%defval,%use_def,%shown);
17683: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17684: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17685: $defval{'weights'} =
1.341 raeburn 17686: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17687: $defval{'excluded'} = &mt('None');
17688: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17689: foreach my $item ('threshold','sysmail','weights','excluded') {
17690: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17691: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17692: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17693: } elsif ($item eq 'weights') {
17694: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17695: foreach my $type ('E','W','N','U') {
1.340 raeburn 17696: $shown{$item} .= $lonstatus_names->{$type}.'=';
17697: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17698: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17699: } else {
17700: $shown{$item} .= $lonstatus_defs->{$type};
17701: }
17702: $shown{$item} .= ', ';
17703: }
17704: $shown{$item} =~ s/, $//;
17705: } else {
17706: $shown{$item} = $defval{$item};
17707: }
17708: } elsif ($item eq 'excluded') {
17709: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17710: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17711: } else {
17712: $shown{$item} = $defval{$item};
17713: }
17714: }
17715: } else {
17716: $shown{$item} = $defval{$item};
17717: }
17718: }
17719: } else {
17720: foreach my $item ('threshold','weights','excluded','sysmail') {
17721: $shown{$item} = $defval{$item};
17722: }
17723: }
17724: foreach my $item ('threshold','weights','excluded','sysmail') {
17725: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17726: $shown{$item}).'</li>';
17727: }
17728: $resulttext .= '</ul></li>';
17729: }
1.286 raeburn 17730: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17731: my (@optional,@required,@unused,$maxsizechg);
17732: foreach my $field (@{$changes{'helpform'}}) {
17733: if ($field eq 'maxsize') {
17734: $maxsizechg = 1;
17735: next;
17736: }
17737: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17738: push(@optional,$field);
1.286 raeburn 17739: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17740: push(@unused,$field);
17741: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17742: push(@required,$field);
1.286 raeburn 17743: }
17744: }
17745: if (@optional) {
17746: $resulttext .= '<li>'.
17747: &mt('Help form fields changed to "Optional": [_1].',
17748: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17749: '</li>';
17750: }
17751: if (@required) {
17752: $resulttext .= '<li>'.
17753: &mt('Help form fields changed to "Required": [_1].',
17754: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17755: '</li>';
17756: }
17757: if (@unused) {
17758: $resulttext .= '<li>'.
17759: &mt('Help form fields changed to "Not shown": [_1].',
17760: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17761: '</li>';
17762: }
17763: if ($maxsizechg) {
17764: $resulttext .= '<li>'.
17765: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17766: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17767: '</li>';
17768: }
17769: }
1.28 raeburn 17770: $resulttext .= '</ul>';
17771: } else {
1.288 raeburn 17772: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17773: }
17774: } else {
17775: $resulttext = '<span class="LC_error">'.
17776: &mt('An error occurred: [_1].',$putresult).'</span>';
17777: }
17778: return $resulttext;
17779: }
17780:
1.357 raeburn 17781: sub modify_privacy {
1.427 raeburn 17782: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17783: my ($resulttext,%current,%changes);
17784: if (ref($domconfig{'privacy'}) eq 'HASH') {
17785: %current = %{$domconfig{'privacy'}};
17786: }
17787: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17788: my @items = ('domain','author','course','community');
17789: my %names = &Apache::lonlocal::texthash (
17790: domain => 'Assigned domain role(s)',
17791: author => 'Assigned co-author role(s)',
17792: course => 'Assigned course role(s)',
1.416 raeburn 17793: community => 'Assigned community role(s)',
1.357 raeburn 17794: );
17795: my %roles = &Apache::lonlocal::texthash (
17796: domain => 'Domain role',
17797: author => 'Co-author role',
17798: course => 'Course role',
17799: community => 'Community role',
17800: );
17801: my %titles = &Apache::lonlocal::texthash (
17802: approval => 'Approval for role in different domain',
17803: othdom => 'User information available in other domain',
17804: priv => 'Information viewable by privileged user in same domain',
17805: unpriv => 'Information viewable by unprivileged user in same domain',
17806: instdom => 'Other domain shares institution/provider',
17807: extdom => 'Other domain has different institution/provider',
17808: none => 'Not allowed',
17809: user => 'User authorizes',
17810: domain => 'Domain Coordinator authorizes',
17811: auto => 'Unrestricted',
1.418 raeburn 17812: notify => 'Notify when role needs authorization',
1.357 raeburn 17813: );
17814: my %fieldnames = &Apache::lonlocal::texthash (
17815: id => 'Student/Employee ID',
17816: permanentemail => 'E-mail address',
17817: lastname => 'Last Name',
17818: firstname => 'First Name',
17819: middlename => 'Middle Name',
17820: generation => 'Generation',
17821: );
17822: my ($othertitle,$usertypes,$types) =
17823: &Apache::loncommon::sorted_inst_types($dom);
17824: my (%by_ip,%by_location,@intdoms,@instdoms);
17825: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17826:
17827: my %privacyhash = (
17828: 'approval' => {
17829: instdom => {},
17830: extdom => {},
17831: },
17832: 'othdom' => {},
17833: );
17834: foreach my $item (@items) {
17835: if (@instdoms > 1) {
1.416 raeburn 17836: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17837: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17838: }
17839: if (ref($current{'approval'}) eq 'HASH') {
17840: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17841: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17842: $changes{'approval'} = 1;
17843: }
17844: }
17845: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17846: $changes{'approval'} = 1;
17847: }
17848: }
17849: if (keys(%by_location) > 0) {
17850: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17851: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17852: }
17853: if (ref($current{'approval'}) eq 'HASH') {
17854: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17855: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17856: $changes{'approval'} = 1;
17857: }
17858: }
17859: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17860: $changes{'approval'} = 1;
17861: }
17862: }
17863: }
17864: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17865: my @statuses;
17866: if (ref($types) eq 'ARRAY') {
17867: @statuses = @{$types};
17868: }
17869: foreach my $type (@statuses,'default') {
17870: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17871: my @newvalues;
17872: foreach my $field (sort(@possfields)) {
17873: if (grep(/^\Q$field\E$/,@fields)) {
17874: $privacyhash{'othdom'}{$type}{$field} = 1;
17875: push(@newvalues,$field);
17876: }
17877: }
17878: @newvalues = sort(@newvalues);
17879: if (ref($current{'othdom'}) eq 'HASH') {
17880: if (ref($current{'othdom'}{$type}) eq 'HASH') {
17881: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
17882: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17883: if (@diffs > 0) {
17884: $changes{'othdom'} = 1;
17885: }
1.447.2.3 raeburn 17886: } elsif (@newvalues > 0) {
17887: $changes{'othdom'} = 1;
1.357 raeburn 17888: }
17889: } else {
17890: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
17891: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17892: if (@diffs > 0) {
17893: $changes{'othdom'} = 1;
17894: }
17895: }
17896: }
1.417 raeburn 17897: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
17898: my %notify;
17899: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
17900: if (exists($domcoords{$possdc})) {
17901: $notify{$possdc} = 1;
17902: }
17903: }
17904: my $notify = join(',',sort(keys(%notify)));
17905: if ($current{'notify'} ne $notify) {
17906: $changes{'notify'} = 1;
17907: }
17908: $privacyhash{'notify'} = $notify;
1.357 raeburn 17909: }
17910: my %confighash = (
17911: privacy => \%privacyhash,
17912: );
17913: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17914: if ($putresult eq 'ok') {
17915: if (keys(%changes) > 0) {
17916: $resulttext = &mt('Changes made: ').'<ul>';
1.447.2.4 raeburn 17917: foreach my $key ('approval','notify','othdom') {
1.357 raeburn 17918: if ($changes{$key}) {
17919: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17920: if ($key eq 'approval') {
17921: if (keys(%{$privacyhash{$key}{instdom}})) {
17922: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
17923: foreach my $item (@items) {
17924: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
17925: }
17926: $resulttext .= '</ul></li>';
17927: }
17928: if (keys(%{$privacyhash{$key}{extdom}})) {
17929: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
17930: foreach my $item (@items) {
17931: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
17932: }
17933: $resulttext .= '</ul></li>';
17934: }
1.417 raeburn 17935: } elsif ($key eq 'notify') {
17936: if ($privacyhash{$key}) {
17937: foreach my $dc (split(/,/,$privacyhash{$key})) {
17938: my ($dcname,$dcdom) = split(/:/,$dc);
17939: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
17940: }
17941: } else {
17942: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
17943: }
1.357 raeburn 17944: } elsif ($key eq 'othdom') {
17945: my @statuses;
17946: if (ref($types) eq 'ARRAY') {
17947: @statuses = @{$types};
17948: }
17949: if (ref($privacyhash{$key}) eq 'HASH') {
17950: foreach my $status (@statuses,'default') {
17951: if ($status eq 'default') {
17952: $resulttext .= '<li>'.$othertitle.': ';
17953: } elsif (ref($usertypes) eq 'HASH') {
17954: $resulttext .= '<li>'.$usertypes->{$status}.': ';
17955: } else {
17956: next;
17957: }
17958: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
17959: if (keys(%{$privacyhash{$key}{$status}})) {
17960: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
17961: } else {
17962: $resulttext .= &mt('none');
17963: }
17964: }
17965: $resulttext .= '</li>';
17966: }
17967: }
17968: }
17969: $resulttext .= '</ul></li>';
17970: }
17971: }
1.421 raeburn 17972: $resulttext .= '</ul>';
1.427 raeburn 17973: if ($changes{'approval'}) {
17974: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
17975: delete($domdefaults{'userapprovals'});
17976: if (ref($privacyhash{'approval'}) eq 'HASH') {
17977: foreach my $domtype ('instdom','extdom') {
17978: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
17979: foreach my $roletype ('domain','author','course','community') {
17980: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
17981: $domdefaults{'userapprovals'} = 1;
17982: last;
17983: }
17984: }
17985: }
17986: last if ($domdefaults{'userapprovals'});
17987: }
17988: }
17989: my $cachetime = 24*60*60;
17990: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17991: if (ref($lastactref) eq 'HASH') {
17992: $lastactref->{'domdefaults'} = 1;
17993: }
17994: }
1.357 raeburn 17995: } else {
17996: $resulttext = &mt('No changes made to user information settings');
17997: }
17998: } else {
17999: $resulttext = '<span class="LC_error">'.
18000: &mt('An error occurred: [_1]',$putresult).'</span>';
18001: }
18002: return $resulttext;
18003: }
18004:
1.354 raeburn 18005: sub modify_passwords {
18006: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18007: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18008: $updatedefaults,$updateconf);
1.354 raeburn 18009: my $customfn = 'resetpw.html';
18010: if (ref($domconfig{'passwords'}) eq 'HASH') {
18011: %current = %{$domconfig{'passwords'}};
18012: }
18013: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18014: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18015: if (ref($types) eq 'ARRAY') {
18016: @oktypes = @{$types};
18017: }
18018: push(@oktypes,'default');
18019:
18020: my %titles = &Apache::lonlocal::texthash (
18021: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18022: intauth_check => 'Check bcrypt cost if authenticated',
18023: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18024: permanent => 'Permanent e-mail address',
18025: critical => 'Critical notification address',
18026: notify => 'Notification address',
18027: min => 'Minimum password length',
18028: max => 'Maximum password length',
18029: chars => 'Required characters',
1.356 raeburn 18030: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18031: reset => 'Resetting Forgotten Password',
18032: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18033: rules => 'Rules for LON-CAPA Passwords',
18034: crsownerchg => 'Course Owner Changing Student Passwords',
18035: username => 'Username',
18036: email => 'E-mail address',
18037: );
18038:
18039: #
18040: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18041: #
18042: my (%curr_defaults,%save_defaults);
18043: if (ref($domconfig{'defaults'}) eq 'HASH') {
18044: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18045: if ($key =~ /^intauth_(cost|check|switch)$/) {
18046: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18047: } else {
18048: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18049: }
18050: }
18051: }
18052: my %staticdefaults = (
18053: 'resetlink' => 2,
18054: 'resetcase' => \@oktypes,
18055: 'resetprelink' => 'both',
18056: 'resetemail' => ['critical','notify','permanent'],
18057: 'intauth_cost' => 10,
18058: 'intauth_check' => 0,
18059: 'intauth_switch' => 0,
18060: );
1.365 raeburn 18061: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18062: foreach my $type (@oktypes) {
18063: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18064: }
18065: my $linklife = $env{'form.passwords_link'};
18066: $linklife =~ s/^\s+|\s+$//g;
18067: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18068: $newvalues{'resetlink'} = $linklife;
18069: if ($current{'resetlink'}) {
18070: if ($current{'resetlink'} ne $linklife) {
18071: $changes{'reset'} = 1;
18072: }
1.368 raeburn 18073: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18074: if ($staticdefaults{'resetlink'} ne $linklife) {
18075: $changes{'reset'} = 1;
18076: }
18077: }
18078: } elsif ($current{'resetlink'}) {
18079: $changes{'reset'} = 1;
18080: }
18081: my @casesens;
18082: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18083: foreach my $case (sort(@posscase)) {
18084: if (grep(/^\Q$case\E$/,@oktypes)) {
18085: push(@casesens,$case);
18086: }
18087: }
18088: $newvalues{'resetcase'} = \@casesens;
18089: if (ref($current{'resetcase'}) eq 'ARRAY') {
18090: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18091: if (@diffs > 0) {
18092: $changes{'reset'} = 1;
18093: }
1.368 raeburn 18094: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18095: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18096: if (@diffs > 0) {
18097: $changes{'reset'} = 1;
18098: }
18099: }
18100: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18101: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18102: if (exists($current{'resetprelink'})) {
18103: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18104: $changes{'reset'} = 1;
18105: }
1.368 raeburn 18106: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18107: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18108: $changes{'reset'} = 1;
18109: }
18110: }
18111: } elsif ($current{'resetprelink'}) {
18112: $changes{'reset'} = 1;
18113: }
18114: foreach my $type (@oktypes) {
18115: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18116: my @postlink;
18117: foreach my $item (sort(@possplink)) {
18118: if ($item =~ /^(email|username)$/) {
18119: push(@postlink,$item);
18120: }
18121: }
18122: $newvalues{'resetpostlink'}{$type} = \@postlink;
18123: unless ($changes{'reset'}) {
18124: if (ref($current{'resetpostlink'}) eq 'HASH') {
18125: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18126: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18127: if (@diffs > 0) {
18128: $changes{'reset'} = 1;
18129: }
18130: } else {
18131: $changes{'reset'} = 1;
18132: }
1.368 raeburn 18133: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18134: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18135: if (@diffs > 0) {
18136: $changes{'reset'} = 1;
18137: }
18138: }
18139: }
18140: }
18141: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18142: my @resetemail;
18143: foreach my $item (sort(@possemailsrc)) {
18144: if ($item =~ /^(permanent|critical|notify)$/) {
18145: push(@resetemail,$item);
18146: }
18147: }
18148: $newvalues{'resetemail'} = \@resetemail;
18149: unless ($changes{'reset'}) {
18150: if (ref($current{'resetemail'}) eq 'ARRAY') {
18151: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18152: if (@diffs > 0) {
18153: $changes{'reset'} = 1;
18154: }
1.368 raeburn 18155: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18156: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18157: if (@diffs > 0) {
18158: $changes{'reset'} = 1;
18159: }
18160: }
18161: }
18162: if ($env{'form.passwords_stdtext'} == 0) {
18163: $newvalues{'resetremove'} = 1;
18164: unless ($current{'resetremove'}) {
18165: $changes{'reset'} = 1;
18166: }
18167: } elsif ($current{'resetremove'}) {
18168: $changes{'reset'} = 1;
18169: }
18170: if ($env{'form.passwords_customfile.filename'} ne '') {
18171: my $servadm = $r->dir_config('lonAdmEMail');
18172: my ($configuserok,$author_ok,$switchserver) =
18173: &config_check($dom,$confname,$servadm);
18174: my $error;
18175: if ($configuserok eq 'ok') {
18176: if ($switchserver) {
18177: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18178: } else {
18179: if ($author_ok eq 'ok') {
1.421 raeburn 18180: my $modified = [];
1.354 raeburn 18181: my ($result,$customurl) =
1.421 raeburn 18182: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18183: $confname,'customtext/resetpw','','',$customfn,
18184: $modified);
1.354 raeburn 18185: if ($result eq 'ok') {
18186: $newvalues{'resetcustom'} = $customurl;
18187: $changes{'reset'} = 1;
1.421 raeburn 18188: &update_modify_urls($r,$modified);
1.354 raeburn 18189: } else {
18190: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18191: }
18192: } else {
18193: $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);
18194: }
18195: }
18196: } else {
18197: $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);
18198: }
18199: if ($error) {
18200: &Apache::lonnet::logthis($error);
18201: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18202: }
18203: } elsif ($current{'resetcustom'}) {
18204: if ($env{'form.passwords_custom_del'}) {
18205: $changes{'reset'} = 1;
18206: } else {
18207: $newvalues{'resetcustom'} = $current{'resetcustom'};
18208: }
18209: }
18210: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18211: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18212: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18213: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18214: $changes{'intauth'} = 1;
18215: }
18216: } else {
18217: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18218: }
18219: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18220: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18221: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18222: $changes{'intauth'} = 1;
18223: }
18224: } else {
18225: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18226: }
18227: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18228: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18229: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18230: $changes{'intauth'} = 1;
18231: }
18232: } else {
18233: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18234: }
18235: foreach my $item ('cost','check','switch') {
18236: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18237: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18238: $updatedefaults = 1;
18239: }
18240: }
1.405 raeburn 18241: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18242: my %crsownerchg = (
18243: by => [],
18244: for => [],
18245: );
18246: foreach my $item ('by','for') {
18247: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18248: foreach my $type (sort(@posstypes)) {
18249: if (grep(/^\Q$type\E$/,@oktypes)) {
18250: push(@{$crsownerchg{$item}},$type);
18251: }
18252: }
18253: }
18254: $newvalues{'crsownerchg'} = \%crsownerchg;
18255: if (ref($current{'crsownerchg'}) eq 'HASH') {
18256: foreach my $item ('by','for') {
18257: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18258: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18259: if (@diffs > 0) {
18260: $changes{'crsownerchg'} = 1;
18261: last;
18262: }
18263: }
18264: }
1.368 raeburn 18265: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18266: foreach my $item ('by','for') {
18267: if (@{$crsownerchg{$item}} > 0) {
18268: $changes{'crsownerchg'} = 1;
18269: last;
18270: }
1.354 raeburn 18271: }
18272: }
18273:
18274: my %confighash = (
18275: defaults => \%save_defaults,
18276: passwords => \%newvalues,
18277: );
18278: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18279:
18280: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18281: if ($putresult eq 'ok') {
18282: if (keys(%changes) > 0) {
18283: $resulttext = &mt('Changes made: ').'<ul>';
18284: foreach my $key ('reset','intauth','rules','crsownerchg') {
18285: if ($changes{$key}) {
1.355 raeburn 18286: unless ($key eq 'intauth') {
18287: $updateconf = 1;
18288: }
1.354 raeburn 18289: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18290: if ($key eq 'reset') {
18291: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18292: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18293: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18294: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18295: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18296: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18297: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18298: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18299: }
1.354 raeburn 18300: } else {
18301: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18302: }
18303: if ($confighash{'passwords'}{'resetlink'}) {
18304: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18305: } else {
18306: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18307: &mt('Will default to 2 hours').'</li>';
18308: }
18309: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18310: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18311: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18312: } else {
18313: my $casesens;
18314: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18315: if ($type eq 'default') {
18316: $casesens .= $othertitle.', ';
18317: } elsif ($usertypes->{$type} ne '') {
18318: $casesens .= $usertypes->{$type}.', ';
18319: }
18320: }
18321: $casesens =~ s/\Q, \E$//;
18322: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18323: }
18324: } else {
18325: $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>';
18326: }
18327: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18328: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18329: } else {
18330: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18331: }
18332: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18333: my $output;
18334: if (ref($types) eq 'ARRAY') {
18335: foreach my $type (@{$types}) {
18336: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18337: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18338: $output .= $usertypes->{$type}.' -- '.&mt('none');
18339: } else {
18340: $output .= $usertypes->{$type}.' -- '.
18341: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18342: }
18343: }
18344: }
18345: }
18346: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18347: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18348: $output .= $othertitle.' -- '.&mt('none');
18349: } else {
18350: $output .= $othertitle.' -- '.
18351: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18352: }
18353: }
18354: if ($output) {
18355: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18356: } else {
18357: $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>';
18358: }
18359: } else {
18360: $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>';
18361: }
18362: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18363: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18364: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18365: } else {
18366: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18367: }
18368: } else {
1.379 raeburn 18369: $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 18370: }
18371: if ($confighash{'passwords'}{'resetremove'}) {
18372: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18373: } else {
18374: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18375: }
18376: if ($confighash{'passwords'}{'resetcustom'}) {
18377: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18378: &mt('custom text'),600,500,undef,undef,
18379: undef,undef,'background-color:#ffffff');
18380: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18381: } else {
18382: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18383: }
18384: } elsif ($key eq 'intauth') {
18385: foreach my $item ('cost','switch','check') {
18386: my $value = $save_defaults{$key.'_'.$item};
18387: if ($item eq 'switch') {
18388: my %optiondesc = &Apache::lonlocal::texthash (
18389: 0 => 'No',
18390: 1 => 'Yes',
18391: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18392: );
18393: if ($value =~ /^(0|1|2)$/) {
18394: $value = $optiondesc{$value};
18395: } else {
18396: $value = &mt('none -- defaults to No');
18397: }
18398: } elsif ($item eq 'check') {
18399: my %optiondesc = &Apache::lonlocal::texthash (
18400: 0 => 'No',
18401: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18402: 2 => 'Yes, disallow login if stored cost is less than domain default',
18403: );
18404: if ($value =~ /^(0|1|2)$/) {
18405: $value = $optiondesc{$value};
18406: } else {
18407: $value = &mt('none -- defaults to No');
18408: }
18409: }
18410: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18411: }
18412: } elsif ($key eq 'rules') {
1.447.2.5 raeburn 18413: foreach my $rule ('min','max','numsaved') {
1.354 raeburn 18414: if ($confighash{'passwords'}{$rule} eq '') {
18415: if ($rule eq 'min') {
1.356 raeburn 18416: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18417: ' '.&mt('Default of [_1] will be used',
18418: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18419: } else {
18420: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18421: }
18422: } else {
18423: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18424: }
18425: }
1.370 raeburn 18426: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18427: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18428: my %rulenames = &Apache::lonlocal::texthash(
18429: uc => 'At least one upper case letter',
18430: lc => 'At least one lower case letter',
18431: num => 'At least one number',
18432: spec => 'At least one non-alphanumeric',
18433: );
18434: my $needed = '<ul><li>'.
18435: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18436: '</li></ul>';
1.370 raeburn 18437: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18438: } else {
18439: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18440: }
18441: } else {
18442: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18443: }
1.354 raeburn 18444: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18445: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18446: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18447: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18448: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18449: } else {
18450: my %crsownerstr;
18451: foreach my $item ('by','for') {
18452: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18453: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18454: if ($type eq 'default') {
18455: $crsownerstr{$item} .= $othertitle.', ';
18456: } elsif ($usertypes->{$type} ne '') {
18457: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18458: }
18459: }
18460: $crsownerstr{$item} =~ s/\Q, \E$//;
18461: }
18462: }
18463: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18464: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18465: }
1.354 raeburn 18466: } else {
1.359 raeburn 18467: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18468: }
18469: }
18470: $resulttext .= '</ul></li>';
18471: }
18472: }
18473: $resulttext .= '</ul>';
18474: } else {
18475: $resulttext = &mt('No changes made to password settings');
18476: }
1.355 raeburn 18477: my $cachetime = 24*60*60;
1.354 raeburn 18478: if ($updatedefaults) {
18479: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18480: if (ref($lastactref) eq 'HASH') {
18481: $lastactref->{'domdefaults'} = 1;
18482: }
18483: }
1.355 raeburn 18484: if ($updateconf) {
18485: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18486: if (ref($lastactref) eq 'HASH') {
18487: $lastactref->{'passwdconf'} = 1;
18488: }
18489: }
1.354 raeburn 18490: } else {
18491: $resulttext = '<span class="LC_error">'.
18492: &mt('An error occurred: [_1]',$putresult).'</span>';
18493: }
18494: if ($errors) {
18495: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18496: $errors.'</ul></p>';
18497: }
18498: return $resulttext;
18499: }
18500:
1.405 raeburn 18501: sub password_rule_changes {
18502: my ($prefix,$newvalues,$current,$changes) = @_;
18503: return unless ((ref($newvalues) eq 'HASH') &&
18504: (ref($current) eq 'HASH') &&
18505: (ref($changes) eq 'HASH'));
18506: my (@rules,%staticdefaults);
18507: if ($prefix eq 'passwords') {
1.447.2.5 raeburn 18508: @rules = ('min','max','numsaved');
1.421 raeburn 18509: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18510: @rules = ('min','max');
18511: }
18512: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18513: foreach my $rule (@rules) {
18514: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18515: my $ruleok;
1.447.2.5 raeburn 18516: if ($rule eq 'min') {
1.405 raeburn 18517: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18518: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18519: $ruleok = 1;
18520: }
18521: }
18522: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18523: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18524: $ruleok = 1;
18525: }
18526: if ($ruleok) {
18527: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18528: if (exists($current->{$rule})) {
18529: if ($newvalues->{$rule} ne $current->{$rule}) {
18530: $changes->{'rules'} = 1;
18531: }
18532: } elsif ($rule eq 'min') {
18533: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18534: $changes->{'rules'} = 1;
18535: }
18536: } else {
18537: $changes->{'rules'} = 1;
18538: }
18539: } elsif (exists($current->{$rule})) {
18540: $changes->{'rules'} = 1;
18541: }
18542: }
18543: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18544: my @chars;
18545: foreach my $item (sort(@posschars)) {
18546: if ($item =~ /^(uc|lc|num|spec)$/) {
18547: push(@chars,$item);
18548: }
18549: }
18550: $newvalues->{'chars'} = \@chars;
18551: unless ($changes->{'rules'}) {
18552: if (ref($current->{'chars'}) eq 'ARRAY') {
18553: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18554: if (@diffs > 0) {
18555: $changes->{'rules'} = 1;
18556: }
18557: } else {
18558: if (@chars > 0) {
18559: $changes->{'rules'} = 1;
18560: }
18561: }
18562: }
18563: return;
18564: }
18565:
1.28 raeburn 18566: sub modify_usercreation {
1.27 raeburn 18567: my ($dom,%domconfig) = @_;
1.224 raeburn 18568: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18569: my $warningmsg;
1.27 raeburn 18570: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18571: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18572: if ($key eq 'cancreate') {
18573: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18574: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18575: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18576: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18577: } else {
1.224 raeburn 18578: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18579: }
18580: }
18581: }
18582: } elsif ($key eq 'email_rule') {
18583: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18584: } else {
18585: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18586: }
1.27 raeburn 18587: }
18588: }
18589: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18590: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18591: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18592: foreach my $item(@contexts) {
1.224 raeburn 18593: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18594: }
1.34 raeburn 18595: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18596: foreach my $item (@contexts) {
1.224 raeburn 18597: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18598: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18599: }
1.27 raeburn 18600: }
1.34 raeburn 18601: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18602: foreach my $item (@contexts) {
1.43 raeburn 18603: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18604: if ($cancreate{$item} ne 'any') {
18605: push(@{$changes{'cancreate'}},$item);
18606: }
18607: } else {
18608: if ($cancreate{$item} ne 'none') {
18609: push(@{$changes{'cancreate'}},$item);
18610: }
1.27 raeburn 18611: }
18612: }
18613: } else {
1.43 raeburn 18614: foreach my $item (@contexts) {
1.34 raeburn 18615: push(@{$changes{'cancreate'}},$item);
18616: }
1.27 raeburn 18617: }
1.34 raeburn 18618:
1.27 raeburn 18619: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18620: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18621: if (!grep(/^\Q$type\E$/,@username_rule)) {
18622: push(@{$changes{'username_rule'}},$type);
18623: }
18624: }
18625: foreach my $type (@username_rule) {
18626: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18627: push(@{$changes{'username_rule'}},$type);
18628: }
18629: }
18630: } else {
18631: push(@{$changes{'username_rule'}},@username_rule);
18632: }
18633:
1.32 raeburn 18634: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18635: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18636: if (!grep(/^\Q$type\E$/,@id_rule)) {
18637: push(@{$changes{'id_rule'}},$type);
18638: }
18639: }
18640: foreach my $type (@id_rule) {
18641: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18642: push(@{$changes{'id_rule'}},$type);
18643: }
18644: }
18645: } else {
18646: push(@{$changes{'id_rule'}},@id_rule);
18647: }
18648:
1.43 raeburn 18649: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18650: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18651: my %authhash;
1.43 raeburn 18652: foreach my $item (@authen_contexts) {
1.28 raeburn 18653: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18654: foreach my $auth (@authtypes) {
18655: if (grep(/^\Q$auth\E$/,@authallowed)) {
18656: $authhash{$item}{$auth} = 1;
18657: } else {
18658: $authhash{$item}{$auth} = 0;
18659: }
18660: }
18661: }
18662: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18663: foreach my $item (@authen_contexts) {
1.28 raeburn 18664: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18665: foreach my $auth (@authtypes) {
18666: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18667: push(@{$changes{'authtypes'}},$item);
18668: last;
18669: }
18670: }
18671: }
18672: }
18673: } else {
1.43 raeburn 18674: foreach my $item (@authen_contexts) {
1.28 raeburn 18675: push(@{$changes{'authtypes'}},$item);
18676: }
18677: }
18678:
1.224 raeburn 18679: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18680: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18681: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18682: $save_usercreate{'id_rule'} = \@id_rule;
18683: $save_usercreate{'username_rule'} = \@username_rule,
18684: $save_usercreate{'authtypes'} = \%authhash;
18685:
1.27 raeburn 18686: my %usercreation_hash = (
1.224 raeburn 18687: usercreation => \%save_usercreate,
18688: );
1.27 raeburn 18689:
18690: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18691: $dom);
1.50 raeburn 18692:
1.224 raeburn 18693: if ($putresult eq 'ok') {
18694: if (keys(%changes) > 0) {
18695: $resulttext = &mt('Changes made:').'<ul>';
18696: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18697: my %lt = &usercreation_types();
18698: foreach my $type (@{$changes{'cancreate'}}) {
18699: my $chgtext = $lt{$type}.', ';
18700: if ($cancreate{$type} eq 'none') {
18701: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18702: } elsif ($cancreate{$type} eq 'any') {
18703: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18704: } elsif ($cancreate{$type} eq 'official') {
18705: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18706: } elsif ($cancreate{$type} eq 'unofficial') {
18707: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18708: }
18709: $resulttext .= '<li>'.$chgtext.'</li>';
18710: }
18711: }
18712: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18713: my ($rules,$ruleorder) =
18714: &Apache::lonnet::inst_userrules($dom,'username');
18715: my $chgtext = '<ul>';
18716: foreach my $type (@username_rule) {
18717: if (ref($rules->{$type}) eq 'HASH') {
18718: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18719: }
18720: }
18721: $chgtext .= '</ul>';
18722: if (@username_rule > 0) {
18723: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18724: } else {
18725: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18726: }
18727: }
18728: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18729: my ($idrules,$idruleorder) =
18730: &Apache::lonnet::inst_userrules($dom,'id');
18731: my $chgtext = '<ul>';
18732: foreach my $type (@id_rule) {
18733: if (ref($idrules->{$type}) eq 'HASH') {
18734: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18735: }
18736: }
18737: $chgtext .= '</ul>';
18738: if (@id_rule > 0) {
18739: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18740: } else {
18741: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18742: }
18743: }
18744: my %authname = &authtype_names();
18745: my %context_title = &context_names();
18746: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18747: my $chgtext = '<ul>';
18748: foreach my $type (@{$changes{'authtypes'}}) {
18749: my @allowed;
18750: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18751: foreach my $auth (@authtypes) {
18752: if ($authhash{$type}{$auth}) {
18753: push(@allowed,$authname{$auth});
18754: }
18755: }
18756: if (@allowed > 0) {
18757: $chgtext .= join(', ',@allowed).'</li>';
18758: } else {
18759: $chgtext .= &mt('none').'</li>';
18760: }
18761: }
18762: $chgtext .= '</ul>';
18763: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18764: $resulttext .= '</li>';
18765: }
18766: $resulttext .= '</ul>';
18767: } else {
18768: $resulttext = &mt('No changes made to user creation settings');
18769: }
18770: } else {
18771: $resulttext = '<span class="LC_error">'.
18772: &mt('An error occurred: [_1]',$putresult).'</span>';
18773: }
18774: if ($warningmsg ne '') {
18775: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18776: }
18777: return $resulttext;
18778: }
18779:
18780: sub modify_selfcreation {
1.305 raeburn 18781: my ($dom,$lastactref,%domconfig) = @_;
18782: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18783: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18784: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18785: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18786: if (ref($typesref) eq 'ARRAY') {
18787: @types = @{$typesref};
18788: }
18789: if (ref($usertypesref) eq 'HASH') {
18790: %usertypes = %{$usertypesref};
1.228 raeburn 18791: }
1.303 raeburn 18792: $usertypes{'default'} = $othertitle;
1.224 raeburn 18793: #
18794: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18795: #
18796: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18797: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18798: if ($key eq 'cancreate') {
18799: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18800: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18801: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18802: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18803: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18804: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18805: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18806: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18807: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18808: } else {
18809: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18810: }
18811: }
18812: }
18813: } elsif ($key eq 'email_rule') {
18814: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18815: } else {
18816: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18817: }
18818: }
18819: }
18820: #
18821: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18822: #
18823: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18824: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18825: if ($key eq 'selfcreate') {
18826: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18827: } else {
18828: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18829: }
18830: }
18831: }
1.305 raeburn 18832: #
18833: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18834: #
18835: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18836: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18837: if ($key eq 'inststatusguest') {
18838: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18839: } else {
18840: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18841: }
18842: }
18843: }
1.224 raeburn 18844:
18845: my @contexts = ('selfcreate');
18846: @{$cancreate{'selfcreate'}} = ();
18847: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18848: if (@types) {
18849: @{$cancreate{'statustocreate'}} = ();
18850: }
1.236 raeburn 18851: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18852: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18853: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18854: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18855: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18856: my %selfcreatetypes = (
18857: sso => 'users authenticated by institutional single sign on',
18858: login => 'users authenticated by institutional log-in',
1.303 raeburn 18859: email => 'users verified by e-mail',
1.50 raeburn 18860: );
1.224 raeburn 18861: #
18862: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18863: # is permitted.
18864: #
1.305 raeburn 18865: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 18866:
1.305 raeburn 18867: my (@statuses,%email_rule);
1.228 raeburn 18868: foreach my $item ('login','sso','email') {
1.224 raeburn 18869: if ($item eq 'email') {
1.236 raeburn 18870: if ($env{'form.cancreate_email'}) {
1.305 raeburn 18871: if (@types) {
18872: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
18873: foreach my $status (@poss_statuses) {
18874: if (grep(/^\Q$status\E$/,(@types,'default'))) {
18875: push(@statuses,$status);
18876: }
18877: }
18878: $save_inststatus{'inststatusguest'} = \@statuses;
18879: } else {
18880: push(@statuses,'default');
18881: }
18882: if (@statuses) {
18883: my %curr_rule;
18884: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
18885: foreach my $type (@statuses) {
18886: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 18887: }
1.305 raeburn 18888: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
18889: foreach my $type (@statuses) {
18890: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
18891: }
18892: }
18893: push(@{$cancreate{'selfcreate'}},'email');
18894: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
18895: my %curremaildom;
18896: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
18897: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
18898: }
18899: foreach my $type (@statuses) {
18900: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
18901: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
18902: }
18903: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
18904: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
18905: }
18906: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
18907: #
18908: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
18909: #
18910: my $chosen = $1;
18911: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
18912: my $emaildom;
18913: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 18914: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 18915: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
18916: if (ref($curremaildom{$type}) eq 'HASH') {
18917: if (exists($curremaildom{$type}{$chosen})) {
18918: if ($curremaildom{$type}{$chosen} ne $emaildom) {
18919: push(@{$changes{'cancreate'}},'emaildomain');
18920: }
18921: } elsif ($emaildom ne '') {
18922: push(@{$changes{'cancreate'}},'emaildomain');
18923: }
18924: } elsif ($emaildom ne '') {
18925: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 18926: }
1.305 raeburn 18927: }
18928: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18929: } elsif ($chosen eq 'custom') {
18930: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
18931: $email_rule{$type} = [];
18932: if (ref($emailrules) eq 'HASH') {
18933: foreach my $rule (@possemail_rules) {
18934: if (exists($emailrules->{$rule})) {
18935: push(@{$email_rule{$type}},$rule);
18936: }
18937: }
18938: }
18939: if (@{$email_rule{$type}}) {
18940: $cancreate{'emailoptions'}{$type} = 'custom';
18941: if (ref($curr_rule{$type}) eq 'ARRAY') {
18942: if (@{$curr_rule{$type}} > 0) {
18943: foreach my $rule (@{$curr_rule{$type}}) {
18944: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
18945: push(@{$changes{'email_rule'}},$type);
18946: }
18947: }
18948: }
18949: foreach my $type (@{$email_rule{$type}}) {
18950: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
18951: push(@{$changes{'email_rule'}},$type);
18952: }
18953: }
18954: } else {
18955: push(@{$changes{'email_rule'}},$type);
18956: }
18957: }
18958: } else {
18959: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18960: }
18961: }
18962: }
18963: if (@types) {
18964: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18965: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
18966: if (@changed) {
18967: push(@{$changes{'inststatus'}},'inststatusguest');
18968: }
18969: } else {
18970: push(@{$changes{'inststatus'}},'inststatusguest');
18971: }
18972: }
18973: } else {
18974: delete($env{'form.cancreate_email'});
18975: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18976: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18977: push(@{$changes{'inststatus'}},'inststatusguest');
18978: }
18979: }
18980: }
18981: } else {
18982: $save_inststatus{'inststatusguest'} = [];
18983: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18984: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18985: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 18986: }
18987: }
1.224 raeburn 18988: }
18989: } else {
18990: if ($env{'form.cancreate_'.$item}) {
18991: push(@{$cancreate{'selfcreate'}},$item);
18992: }
18993: }
18994: }
1.305 raeburn 18995: my (%userinfo,%savecaptcha);
1.224 raeburn 18996: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
18997: #
1.228 raeburn 18998: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
18999: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19000: #
1.236 raeburn 19001:
1.244 raeburn 19002: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19003: push(@contexts,'emailusername');
1.305 raeburn 19004: if (@statuses) {
19005: foreach my $type (@statuses) {
1.228 raeburn 19006: if (ref($infofields) eq 'ARRAY') {
19007: foreach my $field (@{$infofields}) {
19008: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19009: $cancreate{'emailusername'}{$type}{$field} = $1;
19010: }
19011: }
1.224 raeburn 19012: }
19013: }
19014: }
19015: #
19016: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19017: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19018: #
19019:
19020: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19021: @approvalnotify = sort(@approvalnotify);
19022: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19023: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19024: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19025: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19026: push(@{$changes{'cancreate'}},'notify');
19027: }
19028: } else {
19029: if ($cancreate{'notify'}{'approval'}) {
19030: push(@{$changes{'cancreate'}},'notify');
19031: }
19032: }
19033: } elsif ($cancreate{'notify'}{'approval'}) {
19034: push(@{$changes{'cancreate'}},'notify');
19035: }
19036:
19037: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19038: }
19039: #
1.236 raeburn 19040: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19041: # institutional log-in.
19042: #
19043: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19044: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19045: ($domdefaults{'auth_def'} eq 'localauth'))) {
19046: $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.').' '.
19047: &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.');
19048: }
19049: }
19050: my @fields = ('lastname','firstname','middlename','generation',
19051: 'permanentemail','id');
1.240 raeburn 19052: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19053: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19054: #
19055: # Where usernames may created for institutional log-in and/or institutional single sign on:
19056: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19057: # may self-create accounts
19058: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19059: # which the user may supply, if institutional data is unavailable.
19060: #
19061: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19062: if (@types) {
1.305 raeburn 19063: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19064: push(@contexts,'statustocreate');
1.303 raeburn 19065: foreach my $type (@types) {
1.224 raeburn 19066: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19067: foreach my $field (@fields) {
19068: if (grep(/^\Q$field\E$/,@modifiable)) {
19069: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19070: } else {
19071: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19072: }
19073: }
19074: }
19075: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19076: foreach my $type (@types) {
1.224 raeburn 19077: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19078: foreach my $field (@fields) {
19079: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19080: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19081: push(@{$changes{'selfcreate'}},$type);
19082: last;
19083: }
19084: }
19085: }
19086: }
19087: } else {
1.303 raeburn 19088: foreach my $type (@types) {
1.224 raeburn 19089: push(@{$changes{'selfcreate'}},$type);
19090: }
19091: }
19092: }
1.240 raeburn 19093: foreach my $field (@shibfields) {
19094: if ($env{'form.shibenv_'.$field} ne '') {
19095: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19096: }
19097: }
19098: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19099: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19100: foreach my $field (@shibfields) {
19101: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19102: push(@{$changes{'cancreate'}},'shibenv');
19103: }
19104: }
19105: } else {
19106: foreach my $field (@shibfields) {
19107: if ($env{'form.shibenv_'.$field}) {
19108: push(@{$changes{'cancreate'}},'shibenv');
19109: last;
19110: }
19111: }
19112: }
19113: }
1.224 raeburn 19114: }
19115: foreach my $item (@contexts) {
19116: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19117: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19118: if (ref($cancreate{$item}) eq 'ARRAY') {
19119: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19120: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19121: push(@{$changes{'cancreate'}},$item);
19122: }
19123: }
19124: }
19125: }
19126: if (ref($cancreate{$item}) eq 'ARRAY') {
19127: foreach my $type (@{$cancreate{$item}}) {
19128: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19129: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19130: push(@{$changes{'cancreate'}},$item);
19131: }
19132: }
19133: }
19134: }
19135: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19136: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19137: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19138: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19139: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19140: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19141: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19142: push(@{$changes{'cancreate'}},$item);
19143: }
19144: }
19145: }
1.305 raeburn 19146: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19147: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19148: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19149: push(@{$changes{'cancreate'}},$item);
19150: }
1.224 raeburn 19151: }
19152: }
19153: }
1.305 raeburn 19154: foreach my $type (keys(%{$cancreate{$item}})) {
19155: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19156: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19157: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19158: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19159: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19160: push(@{$changes{'cancreate'}},$item);
19161: }
19162: }
19163: } else {
19164: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19165: push(@{$changes{'cancreate'}},$item);
19166: }
19167: }
19168: }
1.305 raeburn 19169: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19170: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19171: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19172: push(@{$changes{'cancreate'}},$item);
19173: }
1.224 raeburn 19174: }
19175: }
19176: }
19177: }
19178: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19179: if (ref($cancreate{$item}) eq 'ARRAY') {
19180: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19181: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19182: push(@{$changes{'cancreate'}},$item);
19183: }
19184: }
1.305 raeburn 19185: }
19186: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19187: if (ref($cancreate{$item}) eq 'HASH') {
19188: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19189: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19190: }
19191: }
19192: } elsif ($item eq 'emailusername') {
1.228 raeburn 19193: if (ref($cancreate{$item}) eq 'HASH') {
19194: foreach my $type (keys(%{$cancreate{$item}})) {
19195: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19196: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19197: if ($cancreate{$item}{$type}{$field}) {
19198: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19199: push(@{$changes{'cancreate'}},$item);
19200: }
19201: last;
19202: }
19203: }
19204: }
19205: }
1.224 raeburn 19206: }
19207: }
19208: }
19209: #
19210: # Populate %save_usercreate hash with updates to self-creation configuration.
19211: #
19212: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19213: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19214: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19215: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19216: if (ref($cancreate{'notify'}) eq 'HASH') {
19217: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19218: }
1.236 raeburn 19219: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19220: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19221: }
1.303 raeburn 19222: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19223: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19224: }
1.305 raeburn 19225: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19226: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19227: }
1.303 raeburn 19228: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19229: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19230: }
1.224 raeburn 19231: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19232: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19233: }
1.240 raeburn 19234: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19235: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19236: }
1.224 raeburn 19237: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19238: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19239:
19240: my %userconfig_hash = (
19241: usercreation => \%save_usercreate,
19242: usermodification => \%save_usermodify,
1.305 raeburn 19243: inststatus => \%save_inststatus,
1.224 raeburn 19244: );
1.305 raeburn 19245:
1.224 raeburn 19246: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19247: $dom);
19248: #
1.305 raeburn 19249: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19250: #
1.27 raeburn 19251: if ($putresult eq 'ok') {
19252: if (keys(%changes) > 0) {
19253: $resulttext = &mt('Changes made:').'<ul>';
19254: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19255: my %lt = &selfcreation_types();
1.34 raeburn 19256: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19257: my $chgtext = '';
1.45 raeburn 19258: if ($type eq 'selfcreate') {
1.50 raeburn 19259: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19260: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19261: } else {
1.224 raeburn 19262: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19263: '<ul>';
1.50 raeburn 19264: foreach my $case (@{$cancreate{$type}}) {
19265: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19266: }
19267: $chgtext .= '</ul>';
1.100 raeburn 19268: if (ref($cancreate{$type}) eq 'ARRAY') {
19269: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19270: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19271: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19272: $chgtext .= '<span class="LC_warning">'.
19273: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19274: '</span><br />';
19275: }
19276: }
19277: }
19278: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19279: if (!@statuses) {
19280: $chgtext .= '<span class="LC_warning">'.
19281: &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.").
19282: '</span><br />';
1.303 raeburn 19283:
1.100 raeburn 19284: }
19285: }
19286: }
1.43 raeburn 19287: }
1.240 raeburn 19288: } elsif ($type eq 'shibenv') {
19289: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19290: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19291: } else {
19292: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19293: '<ul>';
19294: foreach my $field (@shibfields) {
19295: next if ($cancreate{$type}{$field} eq '');
19296: if ($field eq 'inststatus') {
19297: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19298: } else {
19299: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19300: }
19301: }
19302: $chgtext .= '</ul>';
1.303 raeburn 19303: }
1.93 raeburn 19304: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19305: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19306: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19307: if (@{$cancreate{'selfcreate'}} > 0) {
19308: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19309: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19310: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19311: $chgtext .= '<br />'.
19312: '<span class="LC_warning">'.
19313: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19314: '</span>';
19315: }
1.303 raeburn 19316: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19317: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19318: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19319: } else {
19320: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19321: }
19322: $chgtext .= '<ul>';
19323: foreach my $case (@{$cancreate{$type}}) {
19324: if ($case eq 'default') {
19325: $chgtext .= '<li>'.$othertitle.'</li>';
19326: } else {
1.303 raeburn 19327: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19328: }
19329: }
1.100 raeburn 19330: $chgtext .= '</ul>';
19331: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19332: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19333: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19334: '</span>';
1.100 raeburn 19335: }
19336: }
19337: } else {
19338: if (@{$cancreate{$type}} == 0) {
19339: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19340: } else {
19341: $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 19342: }
19343: }
1.303 raeburn 19344: $chgtext .= '<br />';
1.93 raeburn 19345: }
1.236 raeburn 19346: } elsif ($type eq 'selfcreateprocessing') {
19347: my %choices = &Apache::lonlocal::texthash (
19348: automatic => 'Automatic approval',
19349: approval => 'Queued for approval',
19350: );
1.305 raeburn 19351: if (@types) {
19352: if (@statuses) {
1.425 raeburn 19353: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19354: '<ul>';
1.305 raeburn 19355: foreach my $status (@statuses) {
19356: if ($status eq 'default') {
19357: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19358: } else {
1.305 raeburn 19359: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19360: }
19361: }
19362: $chgtext .= '</ul>';
19363: }
19364: } else {
19365: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19366: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19367: }
19368: } elsif ($type eq 'emailverified') {
19369: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19370: all => 'Same as e-mail',
19371: first => 'Omit @domain',
19372: free => 'Free to choose',
1.303 raeburn 19373: );
1.305 raeburn 19374: if (@types) {
19375: if (@statuses) {
1.303 raeburn 19376: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19377: '<ul>';
1.305 raeburn 19378: foreach my $status (@statuses) {
1.362 raeburn 19379: if ($status eq 'default') {
1.305 raeburn 19380: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19381: } else {
1.305 raeburn 19382: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19383: }
19384: }
19385: $chgtext .= '</ul>';
19386: }
19387: } else {
1.305 raeburn 19388: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19389: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19390: }
1.305 raeburn 19391: } elsif ($type eq 'emailoptions') {
19392: my %options = &Apache::lonlocal::texthash (
19393: any => 'Any e-mail',
19394: inst => 'Institutional only',
19395: noninst => 'Non-institutional only',
19396: custom => 'Custom restrictions',
19397: );
19398: if (@types) {
19399: if (@statuses) {
19400: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19401: '<ul>';
19402: foreach my $status (@statuses) {
19403: if ($type eq 'default') {
19404: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19405: } else {
19406: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19407: }
19408: }
1.305 raeburn 19409: $chgtext .= '</ul>';
19410: }
19411: } else {
19412: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19413: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19414: } else {
19415: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19416: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19417: }
1.305 raeburn 19418: }
19419: } elsif ($type eq 'emaildomain') {
19420: my $output;
19421: if (@statuses) {
19422: foreach my $type (@statuses) {
19423: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19424: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19425: if ($type eq 'default') {
19426: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19427: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19428: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19429: } else {
19430: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19431: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19432: }
1.303 raeburn 19433: } else {
1.305 raeburn 19434: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19435: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19436: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19437: } else {
19438: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19439: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19440: }
1.303 raeburn 19441: }
1.305 raeburn 19442: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19443: if ($type eq 'default') {
19444: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19445: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19446: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19447: } else {
19448: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19449: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19450: }
1.303 raeburn 19451: } else {
1.305 raeburn 19452: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19453: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19454: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19455: } else {
19456: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19457: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19458: }
1.303 raeburn 19459: }
19460: }
19461: }
19462: }
1.305 raeburn 19463: }
19464: if ($output ne '') {
19465: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19466: '<ul>'.$output.'</ul>';
1.236 raeburn 19467: }
1.165 raeburn 19468: } elsif ($type eq 'captcha') {
1.224 raeburn 19469: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19470: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19471: } else {
19472: my %captchas = &captcha_phrases();
1.224 raeburn 19473: if ($captchas{$savecaptcha{$type}}) {
19474: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19475: } else {
1.210 raeburn 19476: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19477: }
19478: }
19479: } elsif ($type eq 'recaptchakeys') {
19480: my ($privkey,$pubkey);
1.224 raeburn 19481: if (ref($savecaptcha{$type}) eq 'HASH') {
19482: $pubkey = $savecaptcha{$type}{'public'};
19483: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19484: }
19485: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19486: if (!$pubkey) {
19487: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19488: } else {
19489: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19490: }
19491: if (!$privkey) {
19492: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19493: } else {
19494: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19495: }
19496: $chgtext .= '</ul>';
1.269 raeburn 19497: } elsif ($type eq 'recaptchaversion') {
19498: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19499: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19500: }
1.224 raeburn 19501: } elsif ($type eq 'emailusername') {
19502: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19503: if (@statuses) {
19504: foreach my $type (@statuses) {
1.228 raeburn 19505: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19506: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19507: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19508: '<ul>';
19509: foreach my $field (@{$infofields}) {
19510: if ($cancreate{'emailusername'}{$type}{$field}) {
19511: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19512: }
19513: }
1.245 raeburn 19514: $chgtext .= '</ul>';
19515: } else {
1.303 raeburn 19516: $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 19517: }
19518: } else {
1.303 raeburn 19519: $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 19520: }
19521: }
19522: }
19523: }
19524: } elsif ($type eq 'notify') {
1.303 raeburn 19525: my $numapprove = 0;
1.224 raeburn 19526: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19527: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19528: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19529: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19530: $numapprove ++;
1.224 raeburn 19531: }
19532: }
1.43 raeburn 19533: }
1.303 raeburn 19534: unless ($numapprove) {
19535: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19536: }
1.34 raeburn 19537: }
1.224 raeburn 19538: if ($chgtext) {
19539: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19540: }
19541: }
19542: }
1.305 raeburn 19543: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19544: my ($emailrules,$emailruleorder) =
19545: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19546: foreach my $type (@{$changes{'email_rule'}}) {
19547: if (ref($email_rule{$type}) eq 'ARRAY') {
19548: my $chgtext = '<ul>';
19549: foreach my $rule (@{$email_rule{$type}}) {
19550: if (ref($emailrules->{$rule}) eq 'HASH') {
19551: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19552: }
19553: }
19554: $chgtext .= '</ul>';
1.310 raeburn 19555: my $typename;
1.305 raeburn 19556: if (@types) {
19557: if ($type eq 'default') {
19558: $typename = $othertitle;
19559: } else {
19560: $typename = $usertypes{$type};
1.425 raeburn 19561: }
1.305 raeburn 19562: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19563: }
19564: if (@{$email_rule{$type}} > 0) {
19565: $resulttext .= '<li>'.
19566: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19567: $usertypes{$type}).
19568: $chgtext.
19569: '</li>';
19570: } else {
19571: $resulttext .= '<li>'.
1.310 raeburn 19572: &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 19573: '</li>'.
1.310 raeburn 19574: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19575: }
1.43 raeburn 19576: }
19577: }
1.305 raeburn 19578: }
19579: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19580: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19581: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19582: my $chgtext = '<ul>';
19583: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19584: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19585: }
19586: $chgtext .= '</ul>';
19587: $resulttext .= '<li>'.
19588: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19589: $chgtext.
19590: '</li>';
19591: } else {
19592: $resulttext .= '<li>'.
19593: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19594: '</li>';
19595: }
1.43 raeburn 19596: }
19597: }
1.224 raeburn 19598: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19599: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19600: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19601: foreach my $type (@{$changes{'selfcreate'}}) {
19602: my $typename = $type;
1.303 raeburn 19603: if (keys(%usertypes) > 0) {
19604: if ($usertypes{$type} ne '') {
19605: $typename = $usertypes{$type};
1.224 raeburn 19606: }
19607: }
19608: my @modifiable;
19609: $resulttext .= '<li>'.
19610: &mt('Self-creation of account by users with status: [_1]',
19611: '<span class="LC_cusr_emph">'.$typename.'</span>').
19612: ' - '.&mt('modifiable fields (if institutional data blank): ');
19613: foreach my $field (@fields) {
19614: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19615: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19616: }
19617: }
1.224 raeburn 19618: if (@modifiable > 0) {
19619: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19620: } else {
1.224 raeburn 19621: $resulttext .= &mt('none');
1.43 raeburn 19622: }
1.224 raeburn 19623: $resulttext .= '</li>';
1.28 raeburn 19624: }
1.224 raeburn 19625: $resulttext .= '</ul></li>';
1.28 raeburn 19626: }
1.27 raeburn 19627: $resulttext .= '</ul>';
1.305 raeburn 19628: my $cachetime = 24*60*60;
19629: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19630: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19631: if (ref($lastactref) eq 'HASH') {
19632: $lastactref->{'domdefaults'} = 1;
19633: }
1.27 raeburn 19634: } else {
1.224 raeburn 19635: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19636: }
19637: } else {
19638: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19639: &mt('An error occurred: [_1]',$putresult).'</span>';
19640: }
1.43 raeburn 19641: if ($warningmsg ne '') {
19642: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19643: }
1.23 raeburn 19644: return $resulttext;
19645: }
19646:
1.165 raeburn 19647: sub process_captcha {
1.369 raeburn 19648: my ($container,$changes,$newsettings,$currsettings) = @_;
19649: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19650: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19651: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19652: $newsettings->{'captcha'} = 'original';
19653: }
1.369 raeburn 19654: my %current;
19655: if (ref($currsettings) eq 'HASH') {
19656: %current = %{$currsettings};
19657: }
19658: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19659: if ($container eq 'cancreate') {
1.169 raeburn 19660: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19661: push(@{$changes->{'cancreate'}},'captcha');
19662: } elsif (!defined($changes->{'cancreate'})) {
19663: $changes->{'cancreate'} = ['captcha'];
19664: }
1.368 raeburn 19665: } elsif ($container eq 'passwords') {
19666: $changes->{'reset'} = 1;
1.169 raeburn 19667: } else {
19668: $changes->{'captcha'} = 1;
1.165 raeburn 19669: }
19670: }
1.269 raeburn 19671: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19672: if ($newsettings->{'captcha'} eq 'recaptcha') {
19673: $newpub = $env{'form.'.$container.'_recaptchapub'};
19674: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19675: $newpub =~ s/[^\w\-]//g;
19676: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19677: $newsettings->{'recaptchakeys'} = {
19678: public => $newpub,
19679: private => $newpriv,
19680: };
1.269 raeburn 19681: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19682: $newversion =~ s/\D//g;
19683: if ($newversion ne '2') {
19684: $newversion = 1;
19685: }
19686: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19687: }
1.369 raeburn 19688: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19689: $currpub = $current{'recaptchakeys'}{'public'};
19690: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19691: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19692: $newsettings->{'recaptchakeys'} = {
19693: public => '',
19694: private => '',
19695: }
19696: }
1.165 raeburn 19697: }
1.369 raeburn 19698: if ($current{'captcha'} eq 'recaptcha') {
19699: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19700: if ($currversion ne '2') {
19701: $currversion = 1;
19702: }
19703: }
19704: if ($currversion ne $newversion) {
19705: if ($container eq 'cancreate') {
19706: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19707: push(@{$changes->{'cancreate'}},'recaptchaversion');
19708: } elsif (!defined($changes->{'cancreate'})) {
19709: $changes->{'cancreate'} = ['recaptchaversion'];
19710: }
1.368 raeburn 19711: } elsif ($container eq 'passwords') {
19712: $changes->{'reset'} = 1;
1.269 raeburn 19713: } else {
19714: $changes->{'recaptchaversion'} = 1;
19715: }
19716: }
1.165 raeburn 19717: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19718: if ($container eq 'cancreate') {
19719: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19720: push(@{$changes->{'cancreate'}},'recaptchakeys');
19721: } elsif (!defined($changes->{'cancreate'})) {
19722: $changes->{'cancreate'} = ['recaptchakeys'];
19723: }
1.368 raeburn 19724: } elsif ($container eq 'passwords') {
19725: $changes->{'reset'} = 1;
1.169 raeburn 19726: } else {
1.210 raeburn 19727: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19728: }
19729: }
19730: return;
19731: }
19732:
1.33 raeburn 19733: sub modify_usermodification {
19734: my ($dom,%domconfig) = @_;
1.224 raeburn 19735: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19736: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19737: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19738: if ($key eq 'selfcreate') {
19739: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19740: } else {
19741: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19742: }
1.33 raeburn 19743: }
19744: }
1.443 raeburn 19745: my @contexts = ('author','coauthor','course');
1.33 raeburn 19746: my %context_title = (
19747: author => 'In author context',
1.443 raeburn 19748: coauthor => 'As co-author manager',
1.33 raeburn 19749: course => 'In course context',
19750: );
19751: my @fields = ('lastname','firstname','middlename','generation',
19752: 'permanentemail','id');
19753: my %roles = (
19754: author => ['ca','aa'],
1.443 raeburn 19755: coauthor => ['ca','aa'],
1.33 raeburn 19756: course => ['st','ep','ta','in','cr'],
19757: );
19758: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19759: foreach my $context (@contexts) {
1.443 raeburn 19760: my $prefix = 'canmodify';
19761: if ($context eq 'coauthor') {
19762: $prefix = 'cacanmodify';
19763: }
1.33 raeburn 19764: foreach my $role (@{$roles{$context}}) {
1.443 raeburn 19765: my @modifiable = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$role);
1.33 raeburn 19766: foreach my $item (@fields) {
19767: if (grep(/^\Q$item\E$/,@modifiable)) {
19768: $modifyhash{$context}{$role}{$item} = 1;
19769: } else {
19770: $modifyhash{$context}{$role}{$item} = 0;
19771: }
19772: }
19773: }
19774: if (ref($curr_usermodification{$context}) eq 'HASH') {
19775: foreach my $role (@{$roles{$context}}) {
19776: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19777: foreach my $field (@fields) {
19778: if ($modifyhash{$context}{$role}{$field} ne
19779: $curr_usermodification{$context}{$role}{$field}) {
19780: push(@{$changes{$context}},$role);
19781: last;
19782: }
19783: }
19784: }
19785: }
19786: } else {
19787: foreach my $context (@contexts) {
19788: foreach my $role (@{$roles{$context}}) {
19789: push(@{$changes{$context}},$role);
19790: }
19791: }
19792: }
19793: }
19794: my %usermodification_hash = (
19795: usermodification => \%modifyhash,
19796: );
19797: my $putresult = &Apache::lonnet::put_dom('configuration',
19798: \%usermodification_hash,$dom);
19799: if ($putresult eq 'ok') {
19800: if (keys(%changes) > 0) {
19801: $resulttext = &mt('Changes made: ').'<ul>';
19802: foreach my $context (@contexts) {
19803: if (ref($changes{$context}) eq 'ARRAY') {
19804: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19805: if (ref($changes{$context}) eq 'ARRAY') {
19806: foreach my $role (@{$changes{$context}}) {
19807: my $rolename;
1.224 raeburn 19808: if ($role eq 'cr') {
19809: $rolename = &mt('Custom');
1.33 raeburn 19810: } else {
1.224 raeburn 19811: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19812: }
19813: my @modifiable;
1.224 raeburn 19814: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19815: foreach my $field (@fields) {
19816: if ($modifyhash{$context}{$role}{$field}) {
19817: push(@modifiable,$fieldtitles{$field});
19818: }
19819: }
19820: if (@modifiable > 0) {
19821: $resulttext .= join(', ',@modifiable);
19822: } else {
19823: $resulttext .= &mt('none');
19824: }
19825: $resulttext .= '</li>';
19826: }
19827: $resulttext .= '</ul></li>';
19828: }
19829: }
19830: }
19831: $resulttext .= '</ul>';
19832: } else {
19833: $resulttext = &mt('No changes made to user modification settings');
19834: }
19835: } else {
19836: $resulttext = '<span class="LC_error">'.
19837: &mt('An error occurred: [_1]',$putresult).'</span>';
19838: }
19839: return $resulttext;
19840: }
19841:
1.43 raeburn 19842: sub modify_defaults {
1.212 raeburn 19843: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19844: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19845: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19846: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19847: 'portal_def');
1.325 raeburn 19848: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19849: foreach my $item (@items) {
19850: $newvalues{$item} = $env{'form.'.$item};
19851: if ($item eq 'auth_def') {
19852: if ($newvalues{$item} ne '') {
19853: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19854: push(@errors,$item);
19855: }
19856: }
19857: } elsif ($item eq 'lang_def') {
19858: if ($newvalues{$item} ne '') {
19859: if ($newvalues{$item} =~ /^(\w+)/) {
19860: my $langcode = $1;
1.103 raeburn 19861: if ($langcode ne 'x_chef') {
19862: if (code2language($langcode) eq '') {
19863: push(@errors,$item);
19864: }
1.43 raeburn 19865: }
19866: } else {
19867: push(@errors,$item);
19868: }
19869: }
1.54 raeburn 19870: } elsif ($item eq 'timezone_def') {
19871: if ($newvalues{$item} ne '') {
1.62 raeburn 19872: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 19873: push(@errors,$item);
19874: }
19875: }
1.68 raeburn 19876: } elsif ($item eq 'datelocale_def') {
19877: if ($newvalues{$item} ne '') {
19878: my @datelocale_ids = DateTime::Locale->ids();
19879: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
19880: push(@errors,$item);
19881: }
19882: }
1.141 raeburn 19883: } elsif ($item eq 'portal_def') {
19884: if ($newvalues{$item} ne '') {
1.414 raeburn 19885: 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])\/?$/) {
19886: foreach my $field ('email','web') {
19887: if ($env{'form.'.$item.'_'.$field}) {
19888: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
19889: }
19890: }
19891: } else {
1.141 raeburn 19892: push(@errors,$item);
19893: }
19894: }
1.43 raeburn 19895: }
19896: if (grep(/^\Q$item\E$/,@errors)) {
19897: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 19898: if ($item eq 'portal_def') {
19899: if ($domdefaults{$item}) {
19900: foreach my $field ('email','web') {
19901: if (exists($domdefaults{$item.'_'.$field})) {
19902: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
19903: }
19904: }
19905: }
19906: }
1.43 raeburn 19907: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
19908: $changes{$item} = 1;
19909: }
1.414 raeburn 19910: if ($item eq 'portal_def') {
19911: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 19912: if ($newvalues{$item} eq '') {
1.414 raeburn 19913: foreach my $field ('email','web') {
19914: if (exists($domdefaults{$item.'_'.$field})) {
19915: delete($domdefaults{$item.'_'.$field});
19916: }
19917: }
19918: } else {
19919: unless ($changes{$item}) {
19920: foreach my $field ('email','web') {
19921: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
19922: $changes{$item} = 1;
19923: last;
19924: }
19925: }
19926: }
19927: foreach my $field ('email','web') {
19928: if ($newvalues{$item.'_'.$field}) {
19929: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
19930: } elsif (exists($domdefaults{$item.'_'.$field})) {
19931: delete($domdefaults{$item.'_'.$field});
19932: }
19933: }
19934: }
19935: }
19936: }
1.72 raeburn 19937: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 19938: }
1.354 raeburn 19939: my %staticdefaults = (
19940: 'intauth_cost' => 10,
19941: 'intauth_check' => 0,
19942: 'intauth_switch' => 0,
19943: );
19944: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
19945: if (exists($domdefaults{$item})) {
19946: $newvalues{$item} = $domdefaults{$item};
19947: } else {
19948: $newvalues{$item} = $staticdefaults{$item};
19949: }
19950: }
1.409 raeburn 19951: my ($unamemaprules,$ruleorder);
19952: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
19953: if (@possunamemaprules) {
19954: ($unamemaprules,$ruleorder) =
19955: &Apache::lonnet::inst_userrules($dom,'unamemap');
19956: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
19957: if (@{$ruleorder} > 0) {
19958: my %possrules;
19959: map { $possrules{$_} = 1; } @possunamemaprules;
19960: foreach my $rule (@{$ruleorder}) {
19961: if ($possrules{$rule}) {
19962: push(@{$newvalues{'unamemap_rule'}},$rule);
19963: }
19964: }
19965: }
19966: }
19967: }
19968: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
19969: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19970: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
19971: $newvalues{'unamemap_rule'});
19972: if (@rulediffs) {
19973: $changes{'unamemap_rule'} = 1;
19974: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
19975: }
19976: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
19977: $changes{'unamemap_rule'} = 1;
19978: delete($domdefaults{'unamemap_rule'});
19979: }
19980: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19981: if (@{$newvalues{'unamemap_rule'}} > 0) {
19982: $changes{'unamemap_rule'} = 1;
19983: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
19984: }
19985: }
1.43 raeburn 19986: my %defaults_hash = (
1.72 raeburn 19987: defaults => \%newvalues,
19988: );
1.43 raeburn 19989: my $title = &defaults_titles();
1.236 raeburn 19990:
19991: my $currinststatus;
19992: if (ref($domconfig{'inststatus'}) eq 'HASH') {
19993: $currinststatus = $domconfig{'inststatus'};
19994: } else {
19995: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
19996: $currinststatus = {
19997: inststatustypes => $usertypes,
19998: inststatusorder => $types,
19999: inststatusguest => [],
20000: };
20001: }
20002: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20003: my @allpos;
20004: my %alltypes;
1.305 raeburn 20005: my @inststatusguest;
20006: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20007: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20008: unless (grep(/^\Q$type\E$/,@todelete)) {
20009: push(@inststatusguest,$type);
20010: }
20011: }
20012: }
20013: my ($currtitles,$currorder);
1.236 raeburn 20014: if (ref($currinststatus) eq 'HASH') {
20015: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20016: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20017: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20018: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20019: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20020: }
20021: }
20022: unless (grep(/^\Q$type\E$/,@todelete)) {
20023: my $position = $env{'form.inststatus_pos_'.$type};
20024: $position =~ s/\D+//g;
20025: $allpos[$position] = $type;
20026: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20027: $alltypes{$type} =~ s/`//g;
20028: }
20029: }
20030: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20031: $currtitles =~ s/,$//;
20032: }
20033: }
20034: if ($env{'form.addinststatus'}) {
20035: my $newtype = $env{'form.addinststatus'};
20036: $newtype =~ s/\W//g;
20037: unless (exists($alltypes{$newtype})) {
20038: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20039: $alltypes{$newtype} =~ s/`//g;
20040: my $position = $env{'form.addinststatus_pos'};
20041: $position =~ s/\D+//g;
20042: if ($position ne '') {
20043: $allpos[$position] = $newtype;
20044: }
20045: }
20046: }
1.305 raeburn 20047: my @orderedstatus;
1.236 raeburn 20048: foreach my $type (@allpos) {
20049: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20050: push(@orderedstatus,$type);
20051: }
20052: }
20053: foreach my $type (keys(%alltypes)) {
20054: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20055: delete($alltypes{$type});
20056: }
20057: }
20058: $defaults_hash{'inststatus'} = {
20059: inststatustypes => \%alltypes,
20060: inststatusorder => \@orderedstatus,
1.305 raeburn 20061: inststatusguest => \@inststatusguest,
1.236 raeburn 20062: };
20063: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20064: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20065: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20066: }
20067: }
20068: if ($currorder ne join(',',@orderedstatus)) {
20069: $changes{'inststatus'}{'inststatusorder'} = 1;
20070: }
20071: my $newtitles;
20072: foreach my $item (@orderedstatus) {
20073: $newtitles .= $alltypes{$item}.',';
20074: }
20075: $newtitles =~ s/,$//;
20076: if ($currtitles ne $newtitles) {
20077: $changes{'inststatus'}{'inststatustypes'} = 1;
20078: }
1.43 raeburn 20079: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20080: $dom);
20081: if ($putresult eq 'ok') {
20082: if (keys(%changes) > 0) {
20083: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20084: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20085: 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";
20086: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20087: if ($item eq 'inststatus') {
20088: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20089: if (@orderedstatus) {
1.236 raeburn 20090: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20091: foreach my $type (@orderedstatus) {
20092: $resulttext .= $alltypes{$type}.', ';
20093: }
20094: $resulttext =~ s/, $//;
20095: $resulttext .= '</li>';
1.305 raeburn 20096: } else {
1.425 raeburn 20097: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20098: }
20099: }
1.409 raeburn 20100: } elsif ($item eq 'unamemap_rule') {
20101: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20102: my @rulenames;
20103: if (ref($unamemaprules) eq 'HASH') {
20104: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20105: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20106: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20107: }
20108: }
20109: }
20110: if (@rulenames) {
20111: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20112: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20113: '</li>';
20114: } else {
20115: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20116: }
20117: } else {
20118: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20119: }
1.236 raeburn 20120: } else {
20121: my $value = $env{'form.'.$item};
20122: if ($value eq '') {
20123: $value = &mt('none');
20124: } elsif ($item eq 'auth_def') {
20125: my %authnames = &authtype_names();
20126: my %shortauth = (
20127: internal => 'int',
20128: krb4 => 'krb4',
20129: krb5 => 'krb5',
20130: localauth => 'loc',
1.325 raeburn 20131: lti => 'lti',
1.236 raeburn 20132: );
20133: $value = $authnames{$shortauth{$value}};
20134: }
20135: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20136: $mailmsgtext .= "$title->{$item} set to $value\n";
20137: if ($item eq 'portal_def') {
20138: if ($env{'form.'.$item} ne '') {
20139: foreach my $field ('email','web') {
20140: $value = $env{'form.'.$item.'_'.$field};
20141: if ($value) {
20142: $value = &mt('Yes');
20143: } else {
20144: $value = &mt('No');
20145: }
20146: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20147: }
20148: }
20149: }
1.43 raeburn 20150: }
20151: }
20152: $resulttext .= '</ul>';
20153: $mailmsgtext .= "\n";
20154: my $cachetime = 24*60*60;
1.72 raeburn 20155: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20156: if (ref($lastactref) eq 'HASH') {
20157: $lastactref->{'domdefaults'} = 1;
20158: }
1.68 raeburn 20159: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20160: my $notify = 1;
20161: if (ref($domconfig{'contacts'}) eq 'HASH') {
20162: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20163: $notify = 0;
20164: }
20165: }
20166: if ($notify) {
20167: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20168: "LON-CAPA Domain Settings Change - $dom",
20169: $mailmsgtext);
20170: }
1.54 raeburn 20171: }
1.43 raeburn 20172: } else {
1.54 raeburn 20173: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20174: }
20175: } else {
20176: $resulttext = '<span class="LC_error">'.
20177: &mt('An error occurred: [_1]',$putresult).'</span>';
20178: }
20179: if (@errors > 0) {
20180: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20181: foreach my $item (@errors) {
20182: $resulttext .= ' "'.$title->{$item}.'",';
20183: }
20184: $resulttext =~ s/,$//;
20185: }
20186: return $resulttext;
20187: }
20188:
1.46 raeburn 20189: sub modify_scantron {
1.205 raeburn 20190: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20191: my ($resulttext,%confhash,%changes,$errors);
20192: my $custom = 'custom.tab';
20193: my $default = 'default.tab';
20194: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20195: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20196: &config_check($dom,$confname,$servadm);
20197: if ($env{'form.scantronformat.filename'} ne '') {
20198: my $error;
20199: if ($configuserok eq 'ok') {
20200: if ($switchserver) {
1.130 raeburn 20201: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20202: } else {
20203: if ($author_ok eq 'ok') {
1.421 raeburn 20204: my $modified = [];
1.46 raeburn 20205: my ($result,$scantronurl) =
1.421 raeburn 20206: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20207: $confname,'scantron','','',$custom,
20208: $modified);
1.46 raeburn 20209: if ($result eq 'ok') {
20210: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20211: $changes{'scantronformat'} = 1;
1.421 raeburn 20212: &update_modify_urls($r,$modified);
1.46 raeburn 20213: } else {
20214: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20215: }
20216: } else {
20217: $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);
20218: }
20219: }
20220: } else {
20221: $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);
20222: }
20223: if ($error) {
20224: &Apache::lonnet::logthis($error);
20225: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20226: }
20227: }
1.48 raeburn 20228: if (ref($domconfig{'scantron'}) eq 'HASH') {
20229: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20230: if ($env{'form.scantronformat_del'}) {
20231: $confhash{'scantron'}{'scantronformat'} = '';
20232: $changes{'scantronformat'} = 1;
1.347 raeburn 20233: } else {
20234: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20235: }
20236: }
20237: }
1.347 raeburn 20238: my @options = ('hdr','pad','rem');
1.346 raeburn 20239: my @fields = &scantroncsv_fields();
20240: my %titles = &scantronconfig_titles();
1.347 raeburn 20241: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20242: my ($newdat,$currdat,%newcol,%currcol);
20243: if (grep(/^dat$/,@formats)) {
20244: $confhash{'scantron'}{config}{dat} = 1;
20245: $newdat = 1;
20246: } else {
20247: $newdat = 0;
20248: }
20249: if (grep(/^csv$/,@formats)) {
20250: my %bynum;
20251: foreach my $field (@fields) {
20252: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20253: my $posscol = $1;
20254: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20255: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20256: $bynum{$posscol} = $field;
20257: $newcol{$field} = $posscol;
20258: }
20259: }
20260: }
1.347 raeburn 20261: if (keys(%newcol)) {
20262: foreach my $option (@options) {
20263: if ($env{'form.scantroncsv_'.$option}) {
20264: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20265: }
20266: }
20267: }
1.346 raeburn 20268: }
20269: $currdat = 1;
20270: if (ref($domconfig{'scantron'}) eq 'HASH') {
20271: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20272: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20273: $currdat = 0;
20274: }
20275: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20276: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20277: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20278: }
1.346 raeburn 20279: }
20280: }
20281: }
20282: if ($currdat != $newdat) {
20283: $changes{'config'} = 1;
20284: } else {
20285: foreach my $field (@fields) {
20286: if ($currcol{$field} ne '') {
20287: if ($currcol{$field} ne $newcol{$field}) {
20288: $changes{'config'} = 1;
20289: last;
1.347 raeburn 20290: }
1.346 raeburn 20291: } elsif ($newcol{$field} ne '') {
20292: $changes{'config'} = 1;
20293: last;
20294: }
20295: }
20296: }
1.46 raeburn 20297: if (keys(%confhash) > 0) {
20298: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20299: $dom);
20300: if ($putresult eq 'ok') {
20301: if (keys(%changes) > 0) {
1.48 raeburn 20302: if (ref($confhash{'scantron'}) eq 'HASH') {
20303: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20304: if ($changes{'scantronformat'}) {
20305: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20306: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20307: } else {
20308: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20309: }
20310: }
1.347 raeburn 20311: if ($changes{'config'}) {
1.346 raeburn 20312: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20313: if ($confhash{'scantron'}{'config'}{'dat'}) {
20314: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20315: }
20316: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20317: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20318: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20319: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20320: foreach my $field (@fields) {
20321: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20322: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20323: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20324: }
20325: }
20326: $resulttext .= '</ul></li>';
20327: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20328: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20329: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20330: foreach my $option (@options) {
20331: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20332: $resulttext .= '<li>'.$titles{$option}.'</li>';
20333: }
20334: }
20335: $resulttext .= '</ul></li>';
20336: }
1.346 raeburn 20337: }
20338: }
20339: }
20340: }
20341: } else {
20342: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20343: }
1.46 raeburn 20344: }
1.48 raeburn 20345: $resulttext .= '</ul>';
20346: } else {
1.130 raeburn 20347: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20348: }
20349: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20350: if (ref($lastactref) eq 'HASH') {
20351: $lastactref->{'domainconfig'} = 1;
20352: }
1.46 raeburn 20353: } else {
1.346 raeburn 20354: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20355: }
20356: } else {
20357: $resulttext = '<span class="LC_error">'.
20358: &mt('An error occurred: [_1]',$putresult).'</span>';
20359: }
20360: } else {
1.130 raeburn 20361: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20362: }
20363: if ($errors) {
1.353 raeburn 20364: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20365: $errors.'</ul></p>';
1.46 raeburn 20366: }
20367: return $resulttext;
20368: }
20369:
1.48 raeburn 20370: sub modify_coursecategories {
1.239 raeburn 20371: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20372: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20373: $cathash);
1.48 raeburn 20374: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20375: my @catitems = ('unauth','auth');
20376: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20377: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20378: $cathash = $domconfig{'coursecategories'}{'cats'};
20379: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20380: $changes{'togglecats'} = 1;
20381: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20382: }
20383: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20384: $changes{'categorize'} = 1;
20385: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20386: }
1.120 raeburn 20387: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20388: $changes{'togglecatscomm'} = 1;
20389: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20390: }
20391: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20392: $changes{'categorizecomm'} = 1;
20393: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20394:
20395: }
20396: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20397: $changes{'togglecatsplace'} = 1;
20398: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20399: }
20400: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20401: $changes{'categorizeplace'} = 1;
20402: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20403: }
1.238 raeburn 20404: foreach my $item (@catitems) {
20405: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20406: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20407: $changes{$item} = 1;
20408: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20409: }
20410: }
20411: }
1.57 raeburn 20412: } else {
20413: $changes{'togglecats'} = 1;
20414: $changes{'categorize'} = 1;
1.124 raeburn 20415: $changes{'togglecatscomm'} = 1;
20416: $changes{'categorizecomm'} = 1;
1.272 raeburn 20417: $changes{'togglecatsplace'} = 1;
20418: $changes{'categorizeplace'} = 1;
1.87 raeburn 20419: $domconfig{'coursecategories'} = {
20420: togglecats => $env{'form.togglecats'},
20421: categorize => $env{'form.categorize'},
1.124 raeburn 20422: togglecatscomm => $env{'form.togglecatscomm'},
20423: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20424: togglecatsplace => $env{'form.togglecatsplace'},
20425: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20426: };
1.238 raeburn 20427: foreach my $item (@catitems) {
20428: if ($env{'form.coursecat_'.$item} ne 'std') {
20429: $changes{$item} = 1;
20430: }
20431: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20432: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20433: }
20434: }
1.57 raeburn 20435: }
20436: if (ref($cathash) eq 'HASH') {
20437: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20438: push (@deletecategory,'instcode::0');
20439: }
1.120 raeburn 20440: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20441: push(@deletecategory,'communities::0');
20442: }
1.272 raeburn 20443: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20444: push(@deletecategory,'placement::0');
20445: }
1.48 raeburn 20446: }
1.57 raeburn 20447: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20448: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20449: if (@deletecategory > 0) {
20450: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20451: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20452: foreach my $item (@deletecategory) {
1.57 raeburn 20453: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20454: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20455: $deletions{$item} = 1;
1.57 raeburn 20456: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20457: }
20458: }
20459: }
1.57 raeburn 20460: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20461: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20462: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20463: $reorderings{$item} = 1;
1.57 raeburn 20464: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20465: }
20466: if ($env{'form.addcategory_name_'.$item} ne '') {
20467: my $newcat = $env{'form.addcategory_name_'.$item};
20468: my $newdepth = $depth+1;
20469: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20470: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20471: $adds{$newitem} = 1;
20472: }
20473: if ($env{'form.subcat_'.$item} ne '') {
20474: my $newcat = $env{'form.subcat_'.$item};
20475: my $newdepth = $depth+1;
20476: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20477: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20478: $adds{$newitem} = 1;
20479: }
20480: }
20481: }
20482: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20483: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20484: my $newitem = 'instcode::0';
1.57 raeburn 20485: if ($cathash->{$newitem} eq '') {
20486: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20487: $adds{$newitem} = 1;
20488: }
20489: } else {
20490: my $newitem = 'instcode::0';
1.57 raeburn 20491: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20492: $adds{$newitem} = 1;
20493: }
20494: }
1.120 raeburn 20495: if ($env{'form.communities'} eq '1') {
20496: if (ref($cathash) eq 'HASH') {
20497: my $newitem = 'communities::0';
20498: if ($cathash->{$newitem} eq '') {
20499: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20500: $adds{$newitem} = 1;
20501: }
20502: } else {
20503: my $newitem = 'communities::0';
20504: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20505: $adds{$newitem} = 1;
20506: }
20507: }
1.272 raeburn 20508: if ($env{'form.placement'} eq '1') {
20509: if (ref($cathash) eq 'HASH') {
20510: my $newitem = 'placement::0';
20511: if ($cathash->{$newitem} eq '') {
20512: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20513: $adds{$newitem} = 1;
20514: }
20515: } else {
20516: my $newitem = 'placement::0';
20517: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20518: $adds{$newitem} = 1;
20519: }
20520: }
1.48 raeburn 20521: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20522: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20523: ($env{'form.addcategory_name'} ne 'communities') &&
20524: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20525: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20526: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20527: $adds{$newitem} = 1;
20528: }
1.48 raeburn 20529: }
1.57 raeburn 20530: my $putresult;
1.48 raeburn 20531: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20532: if (keys(%deletions) > 0) {
20533: foreach my $key (keys(%deletions)) {
20534: if ($predelallitems{$key} ne '') {
20535: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20536: }
20537: }
20538: }
20539: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20540: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20541: if (ref($chkcats[0]) eq 'ARRAY') {
20542: my $depth = 0;
20543: my $chg = 0;
20544: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20545: my $name = $chkcats[0][$i];
20546: my $item;
20547: if ($name eq '') {
20548: $chg ++;
20549: } else {
20550: $item = &escape($name).'::0';
20551: if ($chg) {
1.57 raeburn 20552: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20553: }
20554: $depth ++;
1.57 raeburn 20555: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20556: $depth --;
20557: }
20558: }
20559: }
1.57 raeburn 20560: }
20561: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20562: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20563: if ($putresult eq 'ok') {
1.57 raeburn 20564: my %title = (
1.120 raeburn 20565: togglecats => 'Show/Hide a course in catalog',
20566: categorize => 'Assign a category to a course',
20567: togglecatscomm => 'Show/Hide a community in catalog',
20568: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20569: );
20570: my %level = (
1.120 raeburn 20571: dom => 'set in Domain ("Modify Course/Community")',
20572: crs => 'set in Course ("Course Configuration")',
20573: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20574: none => 'No catalog',
20575: std => 'Standard catalog',
20576: domonly => 'Domain-only catalog',
20577: codesrch => 'Code search form',
1.57 raeburn 20578: );
1.48 raeburn 20579: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20580: if ($changes{'togglecats'}) {
20581: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20582: }
20583: if ($changes{'categorize'}) {
20584: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20585: }
1.120 raeburn 20586: if ($changes{'togglecatscomm'}) {
20587: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20588: }
20589: if ($changes{'categorizecomm'}) {
20590: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20591: }
1.238 raeburn 20592: if ($changes{'unauth'}) {
20593: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20594: }
20595: if ($changes{'auth'}) {
20596: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20597: }
1.57 raeburn 20598: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20599: my $cathash;
20600: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20601: $cathash = $domconfig{'coursecategories'}{'cats'};
20602: } else {
20603: $cathash = {};
20604: }
20605: my (@cats,@trails,%allitems);
20606: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20607: if (keys(%deletions) > 0) {
20608: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20609: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20610: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20611: }
20612: $resulttext .= '</ul></li>';
20613: }
20614: if (keys(%reorderings) > 0) {
20615: my %sort_by_trail;
20616: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20617: foreach my $key (keys(%reorderings)) {
20618: if ($allitems{$key} ne '') {
20619: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20620: }
1.48 raeburn 20621: }
1.57 raeburn 20622: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20623: $resulttext .= '<li>'.$trails[$trail].'</li>';
20624: }
20625: $resulttext .= '</ul></li>';
1.48 raeburn 20626: }
1.57 raeburn 20627: if (keys(%adds) > 0) {
20628: my %sort_by_trail;
20629: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20630: foreach my $key (keys(%adds)) {
20631: if ($allitems{$key} ne '') {
20632: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20633: }
20634: }
20635: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20636: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20637: }
1.57 raeburn 20638: $resulttext .= '</ul></li>';
1.48 raeburn 20639: }
1.364 raeburn 20640: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20641: if (ref($lastactref) eq 'HASH') {
20642: $lastactref->{'cats'} = 1;
20643: }
1.48 raeburn 20644: }
20645: $resulttext .= '</ul>';
1.239 raeburn 20646: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20647: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20648: if ($changes{'auth'}) {
20649: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20650: }
20651: if ($changes{'unauth'}) {
20652: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20653: }
20654: my $cachetime = 24*60*60;
20655: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20656: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20657: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20658: }
20659: }
1.48 raeburn 20660: } else {
20661: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20662: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20663: }
20664: } else {
1.120 raeburn 20665: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20666: }
20667: return $resulttext;
20668: }
20669:
1.69 raeburn 20670: sub modify_serverstatuses {
20671: my ($dom,%domconfig) = @_;
20672: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20673: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20674: %currserverstatus = %{$domconfig{'serverstatuses'}};
20675: }
20676: my @pages = &serverstatus_pages();
20677: foreach my $type (@pages) {
20678: $newserverstatus{$type}{'namedusers'} = '';
20679: $newserverstatus{$type}{'machines'} = '';
20680: if (defined($env{'form.'.$type.'_namedusers'})) {
20681: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20682: my @okusers;
20683: foreach my $user (@users) {
20684: my ($uname,$udom) = split(/:/,$user);
20685: if (($udom =~ /^$match_domain$/) &&
20686: (&Apache::lonnet::domain($udom)) &&
20687: ($uname =~ /^$match_username$/)) {
20688: if (!grep(/^\Q$user\E/,@okusers)) {
20689: push(@okusers,$user);
20690: }
20691: }
20692: }
20693: if (@okusers > 0) {
20694: @okusers = sort(@okusers);
20695: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20696: }
20697: }
20698: if (defined($env{'form.'.$type.'_machines'})) {
20699: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20700: my @okmachines;
20701: foreach my $ip (@machines) {
20702: my @parts = split(/\./,$ip);
20703: next if (@parts < 4);
20704: my $badip = 0;
20705: for (my $i=0; $i<4; $i++) {
20706: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20707: $badip = 1;
20708: last;
20709: }
20710: }
20711: if (!$badip) {
20712: push(@okmachines,$ip);
20713: }
20714: }
20715: @okmachines = sort(@okmachines);
20716: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20717: }
20718: }
20719: my %serverstatushash = (
20720: serverstatuses => \%newserverstatus,
20721: );
20722: foreach my $type (@pages) {
1.83 raeburn 20723: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20724: my (@current,@new);
1.83 raeburn 20725: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20726: if ($currserverstatus{$type}{$setting} ne '') {
20727: @current = split(/,/,$currserverstatus{$type}{$setting});
20728: }
20729: }
20730: if ($newserverstatus{$type}{$setting} ne '') {
20731: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20732: }
20733: if (@current > 0) {
20734: if (@new > 0) {
20735: foreach my $item (@current) {
20736: if (!grep(/^\Q$item\E$/,@new)) {
20737: $changes{$type}{$setting} = 1;
1.82 raeburn 20738: last;
20739: }
20740: }
1.84 raeburn 20741: foreach my $item (@new) {
20742: if (!grep(/^\Q$item\E$/,@current)) {
20743: $changes{$type}{$setting} = 1;
20744: last;
1.82 raeburn 20745: }
20746: }
20747: } else {
1.83 raeburn 20748: $changes{$type}{$setting} = 1;
1.69 raeburn 20749: }
1.83 raeburn 20750: } elsif (@new > 0) {
20751: $changes{$type}{$setting} = 1;
1.69 raeburn 20752: }
20753: }
20754: }
20755: if (keys(%changes) > 0) {
1.81 raeburn 20756: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20757: my $putresult = &Apache::lonnet::put_dom('configuration',
20758: \%serverstatushash,$dom);
20759: if ($putresult eq 'ok') {
20760: $resulttext .= &mt('Changes made:').'<ul>';
20761: foreach my $type (@pages) {
1.84 raeburn 20762: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20763: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20764: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20765: if ($newserverstatus{$type}{'namedusers'} eq '') {
20766: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20767: } else {
20768: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20769: }
1.84 raeburn 20770: }
20771: if ($changes{$type}{'machines'}) {
1.69 raeburn 20772: if ($newserverstatus{$type}{'machines'} eq '') {
20773: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20774: } else {
20775: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20776: }
20777:
20778: }
20779: $resulttext .= '</ul></li>';
20780: }
20781: }
20782: $resulttext .= '</ul>';
20783: } else {
20784: $resulttext = '<span class="LC_error">'.
20785: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20786:
20787: }
20788: } else {
20789: $resulttext = &mt('No changes made to access to server status pages');
20790: }
20791: return $resulttext;
20792: }
20793:
1.118 jms 20794: sub modify_helpsettings {
1.285 raeburn 20795: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20796: my ($resulttext,$errors,%changes,%helphash);
20797: my %defaultchecked = ('submitbugs' => 'on');
20798: my @offon = ('off','on');
1.118 jms 20799: my @toggles = ('submitbugs');
1.285 raeburn 20800: my %current = ('submitbugs' => '',
20801: 'adhoc' => {},
20802: );
1.118 jms 20803: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20804: %current = %{$domconfig{'helpsettings'}};
20805: }
1.285 raeburn 20806: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20807: foreach my $item (@toggles) {
20808: if ($defaultchecked{$item} eq 'on') {
20809: if ($current{$item} eq '') {
20810: if ($env{'form.'.$item} eq '0') {
20811: $changes{$item} = 1;
20812: }
20813: } elsif ($current{$item} ne $env{'form.'.$item}) {
20814: $changes{$item} = 1;
20815: }
20816: } elsif ($defaultchecked{$item} eq 'off') {
20817: if ($current{$item} eq '') {
20818: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20819: $changes{$item} = 1;
20820: }
1.282 raeburn 20821: } elsif ($current{$item} ne $env{'form.'.$item}) {
20822: $changes{$item} = 1;
20823: }
20824: }
20825: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20826: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20827: }
20828: }
1.285 raeburn 20829: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20830: my $confname = $dom.'-domainconfig';
20831: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20832: my (@allpos,%newsettings,%changedprivs,$newrole);
20833: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20834: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20835: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20836: my %lt = &Apache::lonlocal::texthash(
20837: s => 'system',
20838: d => 'domain',
20839: order => 'Display order',
20840: access => 'Role usage',
1.291 raeburn 20841: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20842: dh => 'All with domain helpdesk role',
20843: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20844: none => 'None',
20845: status => 'Determined based on institutional status',
20846: inc => 'Include all, but exclude specific personnel',
20847: exc => 'Exclude all, but include specific personnel',
20848: );
20849: for (my $num=0; $num<=$maxnum; $num++) {
20850: my ($prefix,$identifier,$rolename,%curr);
20851: if ($num == $maxnum) {
20852: next unless ($env{'form.newcusthelp'} == $maxnum);
20853: $identifier = 'custhelp'.$num;
20854: $prefix = 'helproles_'.$num;
20855: $rolename = $env{'form.custhelpname'.$num};
20856: $rolename=~s/[^A-Za-z0-9]//gs;
20857: next if ($rolename eq '');
20858: next if (exists($existing{'rolesdef_'.$rolename}));
20859: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20860: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20861: $newprivs{'c'},$confname,$dom);
20862: if ($result ne 'ok') {
20863: $errors .= '<li><span class="LC_error">'.
20864: &mt('An error occurred storing the new custom role: [_1]',
20865: $result).'</span></li>';
20866: next;
20867: } else {
20868: $changedprivs{$rolename} = \%newprivs;
20869: $newrole = $rolename;
20870: }
20871: } else {
20872: $prefix = 'helproles_'.$num;
20873: $rolename = $env{'form.'.$prefix};
20874: next if ($rolename eq '');
20875: next unless (exists($existing{'rolesdef_'.$rolename}));
20876: $identifier = 'custhelp'.$num;
20877: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20878: my %currprivs;
1.289 raeburn 20879: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 20880: split(/\_/,$existing{'rolesdef_'.$rolename});
20881: foreach my $level ('c','d','s') {
20882: if ($newprivs{$level} ne $currprivs{$level}) {
20883: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20884: $newprivs{'c'},$confname,$dom);
20885: if ($result ne 'ok') {
20886: $errors .= '<li><span class="LC_error">'.
20887: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
20888: $rolename,$result).'</span></li>';
20889: } else {
20890: $changedprivs{$rolename} = \%newprivs;
20891: }
20892: last;
20893: }
20894: }
20895: if (ref($current{'adhoc'}) eq 'HASH') {
20896: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20897: %curr = %{$current{'adhoc'}{$rolename}};
20898: }
20899: }
20900: }
20901: my $newpos = $env{'form.'.$prefix.'_pos'};
20902: $newpos =~ s/\D+//g;
20903: $allpos[$newpos] = $rolename;
20904: my $newdesc = $env{'form.'.$prefix.'_desc'};
20905: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
20906: if ($curr{'desc'}) {
20907: if ($curr{'desc'} ne $newdesc) {
20908: $changes{'customrole'}{$rolename}{'desc'} = 1;
20909: $newsettings{$rolename}{'desc'} = $newdesc;
20910: }
20911: } elsif ($newdesc ne '') {
20912: $changes{'customrole'}{$rolename}{'desc'} = 1;
20913: $newsettings{$rolename}{'desc'} = $newdesc;
20914: }
20915: my $access = $env{'form.'.$prefix.'_access'};
20916: if (grep(/^\Q$access\E$/,@accesstypes)) {
20917: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
20918: if ($access eq 'status') {
20919: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
20920: if (scalar(@statuses) == 0) {
1.289 raeburn 20921: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 20922: } else {
20923: my (@shownstatus,$numtypes);
20924: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20925: if (ref($types) eq 'ARRAY') {
20926: $numtypes = scalar(@{$types});
20927: foreach my $type (sort(@statuses)) {
20928: if ($type eq 'default') {
20929: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20930: } elsif (grep(/^\Q$type\E$/,@{$types})) {
20931: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20932: push(@shownstatus,$usertypes->{$type});
20933: }
20934: }
20935: }
20936: if (grep(/^default$/,@statuses)) {
20937: push(@shownstatus,$othertitle);
20938: }
20939: if (scalar(@shownstatus) == 1+$numtypes) {
20940: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
20941: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
20942: } else {
20943: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
20944: if (ref($curr{'status'}) eq 'ARRAY') {
20945: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20946: if (@diffs) {
20947: $changes{'customrole'}{$rolename}{$access} = 1;
20948: }
20949: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20950: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 20951: }
1.166 raeburn 20952: }
20953: }
1.285 raeburn 20954: } elsif (($access eq 'inc') || ($access eq 'exc')) {
20955: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
20956: my @newspecstaff;
20957: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20958: foreach my $person (sort(@personnel)) {
20959: if ($domhelpdesk{$person}) {
20960: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
20961: }
20962: }
20963: if (ref($curr{$access}) eq 'ARRAY') {
20964: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20965: if (@diffs) {
20966: $changes{'customrole'}{$rolename}{$access} = 1;
20967: }
20968: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20969: $changes{'customrole'}{$rolename}{$access} = 1;
20970: }
20971: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20972: my ($uname,$udom) = split(/:/,$person);
20973: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
20974: }
20975: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 20976: }
1.285 raeburn 20977: } else {
20978: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
20979: }
20980: unless ($curr{'access'} eq $access) {
20981: $changes{'customrole'}{$rolename}{'access'} = 1;
20982: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 20983: }
20984: }
1.285 raeburn 20985: if (@allpos > 0) {
20986: my $idx = 0;
20987: foreach my $rolename (@allpos) {
20988: if ($rolename ne '') {
20989: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
20990: if (ref($current{'adhoc'}) eq 'HASH') {
20991: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20992: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
20993: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 20994: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 20995: }
20996: }
1.282 raeburn 20997: }
1.285 raeburn 20998: $idx ++;
1.166 raeburn 20999: }
21000: }
1.118 jms 21001: }
1.123 jms 21002: my $putresult;
21003: if (keys(%changes) > 0) {
1.166 raeburn 21004: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21005: if ($putresult eq 'ok') {
1.285 raeburn 21006: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21007: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21008: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21009: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21010: }
21011: }
21012: my $cachetime = 24*60*60;
21013: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21014: if (ref($lastactref) eq 'HASH') {
21015: $lastactref->{'domdefaults'} = 1;
21016: }
21017: } else {
21018: $errors .= '<li><span class="LC_error">'.
21019: &mt('An error occurred storing the settings: [_1]',
21020: $putresult).'</span></li>';
21021: }
21022: }
21023: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21024: $resulttext = &mt('Changes made:').'<ul>';
21025: my (%shownprivs,@levelorder);
21026: @levelorder = ('c','d','s');
21027: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21028: foreach my $item (sort(keys(%changes))) {
21029: if ($item eq 'submitbugs') {
21030: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21031: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21032: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21033: } elsif ($item eq 'customrole') {
21034: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21035: my @keyorder = ('order','desc','access','status','exc','inc');
21036: my %keytext = &Apache::lonlocal::texthash(
21037: order => 'Order',
21038: desc => 'Role description',
21039: access => 'Role usage',
1.300 droeschl 21040: status => 'Allowed institutional types',
1.285 raeburn 21041: exc => 'Allowed personnel',
21042: inc => 'Disallowed personnel',
21043: );
1.282 raeburn 21044: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21045: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21046: if ($role eq $newrole) {
21047: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21048: $role).'<ul>';
21049: } else {
21050: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21051: $role).'<ul>';
21052: }
21053: foreach my $key (@keyorder) {
21054: if ($changes{'customrole'}{$role}{$key}) {
21055: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21056: $keytext{$key},$newsettings{$role}{$key}).
21057: '</li>';
21058: }
21059: }
21060: if (ref($changedprivs{$role}) eq 'HASH') {
21061: $shownprivs{$role} = 1;
21062: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21063: foreach my $level (@levelorder) {
21064: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21065: next if ($item eq '');
21066: my ($priv) = split(/\&/,$item,2);
21067: if (&Apache::lonnet::plaintext($priv)) {
21068: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21069: unless ($level eq 'c') {
21070: $resulttext .= ' ('.$lt{$level}.')';
21071: }
21072: $resulttext .= '</li>';
21073: }
21074: }
21075: }
21076: $resulttext .= '</ul>';
21077: }
21078: $resulttext .= '</ul></li>';
21079: }
21080: }
21081: }
21082: }
21083: }
21084: }
21085: if (keys(%changedprivs)) {
21086: foreach my $role (sort(keys(%changedprivs))) {
21087: unless ($shownprivs{$role}) {
21088: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21089: $role).'<ul>'.
21090: '<li>'.&mt('Privileges set to :').'<ul>';
21091: foreach my $level (@levelorder) {
21092: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21093: next if ($item eq '');
21094: my ($priv) = split(/\&/,$item,2);
21095: if (&Apache::lonnet::plaintext($priv)) {
21096: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21097: unless ($level eq 'c') {
21098: $resulttext .= ' ('.$lt{$level}.')';
21099: }
21100: $resulttext .= '</li>';
21101: }
1.282 raeburn 21102: }
21103: }
1.285 raeburn 21104: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21105: }
21106: }
21107: }
1.285 raeburn 21108: $resulttext .= '</ul>';
21109: } else {
21110: $resulttext = &mt('No changes made to help settings');
1.118 jms 21111: }
21112: if ($errors) {
1.168 raeburn 21113: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21114: $errors.'</ul>';
1.118 jms 21115: }
21116: return $resulttext;
21117: }
21118:
1.121 raeburn 21119: sub modify_coursedefaults {
1.212 raeburn 21120: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21121: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21122: my %defaultchecked = (
21123: 'canuse_pdfforms' => 'off',
21124: 'uselcmath' => 'on',
1.398 raeburn 21125: 'usejsme' => 'on',
21126: 'inline_chem' => 'on',
1.404 raeburn 21127: 'ltiauth' => 'off',
1.257 raeburn 21128: );
1.404 raeburn 21129: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21130: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21131: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21132: 'coursequota_official','coursequota_unofficial','coursequota_community',
21133: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21134: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21135: 'mysqltables_placement');
1.271 raeburn 21136: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21137: my %staticdefaults = (
21138: anonsurvey_threshold => 10,
21139: uploadquota => 500,
1.428 raeburn 21140: coursequota => 20,
1.257 raeburn 21141: postsubmit => 60,
1.276 raeburn 21142: mysqltables => 172800,
1.422 raeburn 21143: domexttool => 1,
1.432 raeburn 21144: crsauthor => 1,
1.438 raeburn 21145: crseditors => ['edit','xml'],
1.198 raeburn 21146: );
1.314 raeburn 21147: my %texoptions = (
21148: MathJax => 'MathJax',
21149: mimetex => &mt('Convert to Images'),
21150: tth => &mt('TeX to HTML'),
21151: );
1.438 raeburn 21152:
21153: my @editors = ('edit','xml','daxe');
21154: my %editornames = &crseditor_titles();
21155:
1.121 raeburn 21156: $defaultshash{'coursedefaults'} = {};
21157:
21158: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21159: if ($domconfig{'coursedefaults'} eq '') {
21160: $domconfig{'coursedefaults'} = {};
21161: }
21162: }
21163:
21164: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21165: foreach my $item (@toggles) {
21166: if ($defaultchecked{$item} eq 'on') {
21167: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21168: ($env{'form.'.$item} eq '0')) {
21169: $changes{$item} = 1;
1.192 raeburn 21170: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21171: $changes{$item} = 1;
21172: }
21173: } elsif ($defaultchecked{$item} eq 'off') {
21174: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21175: ($env{'form.'.$item} eq '1')) {
21176: $changes{$item} = 1;
21177: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21178: $changes{$item} = 1;
21179: }
21180: }
21181: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21182: }
1.198 raeburn 21183: foreach my $item (@numbers) {
21184: my ($currdef,$newdef);
1.208 raeburn 21185: $newdef = $env{'form.'.$item};
1.198 raeburn 21186: if ($item eq 'anonsurvey_threshold') {
21187: $currdef = $domconfig{'coursedefaults'}{$item};
21188: $newdef =~ s/\D//g;
21189: if ($newdef eq '' || $newdef < 1) {
21190: $newdef = 1;
21191: }
21192: $defaultshash{'coursedefaults'}{$item} = $newdef;
21193: } else {
1.428 raeburn 21194: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21195: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21196: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21197: }
21198: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21199: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21200: }
21201: if ($currdef ne $newdef) {
21202: if ($item eq 'anonsurvey_threshold') {
21203: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21204: $changes{$item} = 1;
21205: }
1.428 raeburn 21206: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21207: my $setting = $1;
1.276 raeburn 21208: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21209: $changes{$setting} = 1;
1.198 raeburn 21210: }
21211: }
1.139 raeburn 21212: }
21213: }
1.314 raeburn 21214: my $texengine;
21215: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21216: $texengine = $env{'form.texengine'};
1.349 raeburn 21217: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21218: if ($currdef eq '') {
21219: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21220: $changes{'texengine'} = 1;
21221: }
1.349 raeburn 21222: } elsif ($currdef ne $texengine) {
1.314 raeburn 21223: $changes{'texengine'} = 1;
21224: }
21225: }
21226: if ($texengine ne '') {
21227: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21228: }
1.264 raeburn 21229: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21230: my @currclonecode;
21231: if (ref($currclone) eq 'HASH') {
21232: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21233: @currclonecode = @{$currclone->{'instcode'}};
21234: }
21235: }
21236: my $newclone;
1.289 raeburn 21237: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21238: $newclone = $env{'form.canclone'};
21239: }
21240: if ($newclone eq 'instcode') {
21241: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21242: my (%codedefaults,@code_order,@clonecode);
21243: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21244: \@code_order);
21245: foreach my $item (@code_order) {
21246: if (grep(/^\Q$item\E$/,@newcodes)) {
21247: push(@clonecode,$item);
21248: }
21249: }
21250: if (@clonecode) {
21251: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21252: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21253: if (@diffs) {
21254: $changes{'canclone'} = 1;
21255: }
21256: } else {
21257: $newclone eq '';
21258: }
21259: } elsif ($newclone ne '') {
1.289 raeburn 21260: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21261: }
1.264 raeburn 21262: if ($newclone ne $currclone) {
21263: $changes{'canclone'} = 1;
21264: }
1.257 raeburn 21265: my %credits;
21266: foreach my $type (@types) {
21267: unless ($type eq 'community') {
21268: $credits{$type} = $env{'form.'.$type.'_credits'};
21269: $credits{$type} =~ s/[^\d.]+//g;
21270: }
21271: }
21272: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21273: ($env{'form.coursecredits'} eq '1')) {
21274: $changes{'coursecredits'} = 1;
21275: foreach my $type (keys(%credits)) {
21276: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21277: }
21278: } else {
1.289 raeburn 21279: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21280: foreach my $type (@types) {
21281: unless ($type eq 'community') {
1.289 raeburn 21282: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21283: $changes{'coursecredits'} = 1;
21284: }
21285: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21286: }
21287: }
21288: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21289: foreach my $type (@types) {
21290: unless ($type eq 'community') {
21291: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21292: $changes{'coursecredits'} = 1;
21293: last;
21294: }
21295: }
21296: }
21297: }
21298: }
21299: if ($env{'form.postsubmit'} eq '1') {
21300: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21301: my %currtimeout;
21302: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21303: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21304: $changes{'postsubmit'} = 1;
21305: }
21306: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21307: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21308: }
21309: } else {
21310: $changes{'postsubmit'} = 1;
21311: }
21312: foreach my $type (@types) {
21313: my $timeout = $env{'form.'.$type.'_timeout'};
21314: $timeout =~ s/\D//g;
21315: if ($timeout == $staticdefaults{'postsubmit'}) {
21316: $timeout = '';
21317: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21318: $timeout = '0';
21319: }
21320: unless ($timeout eq '') {
21321: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21322: }
21323: if (exists($currtimeout{$type})) {
21324: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21325: $changes{'postsubmit'} = 1;
1.257 raeburn 21326: }
21327: } elsif ($timeout ne '') {
21328: $changes{'postsubmit'} = 1;
21329: }
21330: }
21331: } else {
21332: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21333: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21334: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21335: $changes{'postsubmit'} = 1;
21336: }
21337: } else {
21338: $changes{'postsubmit'} = 1;
21339: }
1.192 raeburn 21340: }
1.438 raeburn 21341: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor,
21342: %posscrseditors);
1.422 raeburn 21343: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21344: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 raeburn 21345: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.438 raeburn 21346: map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
1.422 raeburn 21347: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21348: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21349: } else {
21350: foreach my $type (@types) {
21351: if ($staticdefaults{'domexttool'}) {
21352: $olddomexttool{$type} = 1;
21353: } else {
21354: $olddomexttool{$type} = 0;
21355: }
21356: }
21357: }
21358: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21359: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21360: } else {
21361: foreach my $type (@types) {
21362: if ($staticdefaults{'exttool'}) {
21363: $oldexttool{$type} = 1;
21364: } else {
21365: $oldexttool{$type} = 0;
21366: }
21367: }
21368: }
1.432 raeburn 21369: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21370: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
21371: } else {
21372: foreach my $type (@types) {
21373: if ($staticdefaults{'crsauthor'}) {
21374: $oldcrsauthor{$type} = 1;
21375: } else {
21376: $oldcrsauthor{$type} = 0;
21377: }
21378: }
21379: }
1.438 raeburn 21380: my @newcrseditors = ();
21381: foreach my $editor (@editors) {
21382: if ($posscrseditors{$editor}) {
21383: push(@newcrseditors,$editor);
21384: }
21385: }
21386: if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21387: my @diffs =
21388: &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
21389: \@newcrseditors);
21390: if (@diffs) {
21391: $changes{'crseditors'} = 1;
21392: }
21393: } else {
21394: my @diffs =
21395: &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
21396: \@newcrseditors);
21397: unless (@diffs == 0) {
21398: $changes{'crseditors'} = 1;
21399: }
21400: }
1.422 raeburn 21401: foreach my $type (@types) {
21402: unless ($newdomexttool{$type}) {
21403: $newdomexttool{$type} = 0;
21404: }
21405: unless ($newexttool{$type}) {
21406: $newexttool{$type} = 0;
21407: }
1.432 raeburn 21408: unless ($newcrsauthor{$type}) {
21409: $newcrsauthor{$type} = 0;
21410: }
1.422 raeburn 21411: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21412: $changes{'domexttool'} = 1;
21413: }
21414: if ($newexttool{$type} != $oldexttool{$type}) {
21415: $changes{'exttool'} = 1;
21416: }
1.432 raeburn 21417: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
21418: $changes{'crsauthor'} = 1;
21419: }
1.422 raeburn 21420: }
21421: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21422: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 raeburn 21423: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.438 raeburn 21424: $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 21425: }
21426: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21427: $dom);
21428: if ($putresult eq 'ok') {
21429: if (keys(%changes) > 0) {
1.213 raeburn 21430: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21431: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21432: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21433: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21434: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 raeburn 21435: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21436: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21437: 'ltiauth') {
1.257 raeburn 21438: if ($changes{$item}) {
21439: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21440: }
1.289 raeburn 21441: }
1.192 raeburn 21442: if ($changes{'coursecredits'}) {
21443: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21444: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21445: $domdefaults{$type.'credits'} =
21446: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21447: }
21448: }
21449: }
21450: if ($changes{'postsubmit'}) {
21451: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21452: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21453: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21454: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21455: $domdefaults{$type.'postsubtimeout'} =
21456: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21457: }
21458: }
1.192 raeburn 21459: }
21460: }
1.198 raeburn 21461: if ($changes{'uploadquota'}) {
21462: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21463: foreach my $type (@types) {
21464: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21465: }
21466: }
21467: }
1.428 raeburn 21468: if ($changes{'coursequota'}) {
21469: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21470: foreach my $type (@types) {
21471: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21472: }
21473: }
21474: }
1.264 raeburn 21475: if ($changes{'canclone'}) {
21476: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21477: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21478: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21479: if (@clonecodes) {
21480: $domdefaults{'canclone'} = join('+',@clonecodes);
21481: }
21482: }
21483: } else {
21484: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21485: }
21486: }
1.422 raeburn 21487: if ($changes{'domexttool'}) {
21488: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21489: foreach my $type (@types) {
21490: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21491: }
21492: }
21493: }
21494: if ($changes{'exttool'}) {
21495: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21496: foreach my $type (@types) {
21497: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21498: }
21499: }
21500: }
1.432 raeburn 21501: if ($changes{'crsauthor'}) {
21502: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21503: foreach my $type (@types) {
21504: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
21505: }
21506: }
21507: }
1.438 raeburn 21508: if ($changes{'crseditors'}) {
21509: if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21510: $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
21511: }
21512: }
1.121 raeburn 21513: my $cachetime = 24*60*60;
21514: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21515: if (ref($lastactref) eq 'HASH') {
21516: $lastactref->{'domdefaults'} = 1;
21517: }
1.121 raeburn 21518: }
21519: $resulttext = &mt('Changes made:').'<ul>';
21520: foreach my $item (sort(keys(%changes))) {
21521: if ($item eq 'canuse_pdfforms') {
21522: if ($env{'form.'.$item} eq '1') {
21523: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21524: } else {
21525: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21526: }
1.257 raeburn 21527: } elsif ($item eq 'uselcmath') {
21528: if ($env{'form.'.$item} eq '1') {
21529: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21530: } else {
21531: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21532: }
21533: } elsif ($item eq 'usejsme') {
21534: if ($env{'form.'.$item} eq '1') {
21535: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21536: } else {
1.289 raeburn 21537: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21538: }
1.398 raeburn 21539: } elsif ($item eq 'inline_chem') {
21540: if ($env{'form.'.$item} eq '1') {
21541: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21542: } else {
21543: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21544: }
1.314 raeburn 21545: } elsif ($item eq 'texengine') {
21546: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21547: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21548: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21549: }
1.139 raeburn 21550: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21551: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21552: } elsif ($item eq 'uploadquota') {
21553: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21554: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21555: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21556: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21557: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21558: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21559: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21560: '</ul>'.
21561: '</li>';
21562: } else {
21563: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21564: }
1.428 raeburn 21565: } elsif ($item eq 'coursequota') {
21566: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21567: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21568: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21569: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21570: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21571: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21572: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21573: '</ul>'.
21574: '</li>';
21575: } else {
21576: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21577: }
1.276 raeburn 21578: } elsif ($item eq 'mysqltables') {
21579: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21580: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21581: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21582: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21583: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21584: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21585: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21586: '</ul>'.
21587: '</li>';
21588: } else {
21589: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21590: }
1.257 raeburn 21591: } elsif ($item eq 'postsubmit') {
21592: if ($domdefaults{'postsubmit'} eq 'off') {
21593: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21594: } else {
21595: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21596: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21597: $resulttext .= &mt('durations:').'<ul>';
21598: foreach my $type (@types) {
21599: $resulttext .= '<li>';
21600: my $timeout;
21601: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21602: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21603: }
21604: my $display;
21605: if ($timeout eq '0') {
21606: $display = &mt('unlimited');
21607: } elsif ($timeout eq '') {
21608: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21609: } else {
21610: $display = &mt('[quant,_1,second]',$timeout);
21611: }
21612: if ($type eq 'community') {
21613: $resulttext .= &mt('Communities');
21614: } elsif ($type eq 'official') {
21615: $resulttext .= &mt('Official courses');
21616: } elsif ($type eq 'unofficial') {
21617: $resulttext .= &mt('Unofficial courses');
21618: } elsif ($type eq 'textbook') {
21619: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21620: } elsif ($type eq 'placement') {
21621: $resulttext .= &mt('Placement tests');
1.257 raeburn 21622: }
21623: $resulttext .= ' -- '.$display.'</li>';
21624: }
21625: $resulttext .= '</ul>';
21626: }
1.289 raeburn 21627: $resulttext .= '</li>';
1.257 raeburn 21628: }
1.192 raeburn 21629: } elsif ($item eq 'coursecredits') {
21630: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21631: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21632: ($domdefaults{'unofficialcredits'} eq '') &&
21633: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21634: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21635: } else {
21636: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21637: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21638: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21639: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21640: '</ul>'.
21641: '</li>';
21642: }
21643: } else {
21644: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21645: }
1.264 raeburn 21646: } elsif ($item eq 'canclone') {
21647: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21648: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21649: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21650: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21651: }
21652: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21653: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21654: } else {
1.289 raeburn 21655: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21656: }
1.404 raeburn 21657: } elsif ($item eq 'ltiauth') {
21658: if ($env{'form.'.$item} eq '1') {
21659: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21660: } else {
21661: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21662: }
1.432 raeburn 21663: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21664: my @noyes = (&mt('no'),&mt('yes'));
1.432 raeburn 21665: my %status = (
21666: domexttool => {
21667: ishash => &mt('External Tools defined in the domain may be used as follows:'),
21668: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
21669: },
21670: exttool => {
21671: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
21672: default => &mt('External Tools can not be defined in any course types, by default'),
21673: },
21674: crsauthor => {
21675: ishash => &mt('Standard Problems can be created within course containers as follows:'),
21676: default => &mt('Standard Problems can be created within any course type, by default'),
21677: },
21678: );
21679:
21680: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
21681: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
21682: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
21683: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
21684: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
21685: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
21686: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21687: '</ul>'.
21688: '</li>';
21689: } else {
1.432 raeburn 21690: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21691: }
1.438 raeburn 21692: } elsif ($item eq 'crseditors') {
21693: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
21694: my $shown;
21695: if (@{$defaultshash{'coursedefaults'}{$item}}) {
21696: $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
21697: } else {
21698: $shown = &mt('None');
21699: }
21700: $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
21701: }
1.140 raeburn 21702: }
1.121 raeburn 21703: }
21704: $resulttext .= '</ul>';
21705: } else {
21706: $resulttext = &mt('No changes made to course defaults');
21707: }
21708: } else {
21709: $resulttext = '<span class="LC_error">'.
21710: &mt('An error occurred: [_1]',$putresult).'</span>';
21711: }
21712: return $resulttext;
21713: }
21714:
1.231 raeburn 21715: sub modify_selfenrollment {
21716: my ($dom,$lastactref,%domconfig) = @_;
21717: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21718: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21719: my %titles = &tool_titles();
1.232 raeburn 21720: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21721: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21722: $ordered{'default'} = ['types','registered','approval','limit'];
21723:
21724: my (%roles,%shown,%toplevel);
21725: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21726:
21727: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21728: if ($domconfig{'selfenrollment'} eq '') {
21729: $domconfig{'selfenrollment'} = {};
21730: }
21731: }
21732: %toplevel = (
21733: admin => 'Configuration Rights',
21734: default => 'Default settings',
21735: validation => 'Validation of self-enrollment requests',
21736: );
1.233 raeburn 21737: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21738:
21739: if (ref($ordered{'admin'}) eq 'ARRAY') {
21740: foreach my $item (@{$ordered{'admin'}}) {
21741: foreach my $type (@types) {
21742: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21743: $selfenrollhash{'admin'}{$type}{$item} = 1;
21744: } else {
21745: $selfenrollhash{'admin'}{$type}{$item} = 0;
21746: }
21747: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21748: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21749: if ($selfenrollhash{'admin'}{$type}{$item} ne
21750: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21751: push(@{$changes{'admin'}{$type}},$item);
21752: }
21753: } else {
21754: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21755: push(@{$changes{'admin'}{$type}},$item);
21756: }
21757: }
21758: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21759: push(@{$changes{'admin'}{$type}},$item);
21760: }
21761: }
21762: }
21763: }
21764:
21765: foreach my $item (@{$ordered{'default'}}) {
21766: foreach my $type (@types) {
21767: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21768: if ($item eq 'types') {
21769: unless (($value eq 'all') || ($value eq 'dom')) {
21770: $value = '';
21771: }
21772: } elsif ($item eq 'registered') {
21773: unless ($value eq '1') {
21774: $value = 0;
21775: }
21776: } elsif ($item eq 'approval') {
21777: unless ($value =~ /^[012]$/) {
21778: $value = 0;
21779: }
21780: } else {
21781: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21782: $value = 'none';
21783: }
21784: }
21785: $selfenrollhash{'default'}{$type}{$item} = $value;
21786: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21787: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21788: if ($selfenrollhash{'default'}{$type}{$item} ne
21789: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21790: push(@{$changes{'default'}{$type}},$item);
21791: }
21792: } else {
21793: push(@{$changes{'default'}{$type}},$item);
21794: }
21795: } else {
21796: push(@{$changes{'default'}{$type}},$item);
21797: }
21798: if ($item eq 'limit') {
21799: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21800: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21801: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21802: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21803: }
21804: } else {
21805: $selfenrollhash{'default'}{$type}{'cap'} = '';
21806: }
21807: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21808: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21809: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21810: push(@{$changes{'default'}{$type}},'cap');
21811: }
21812: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21813: push(@{$changes{'default'}{$type}},'cap');
21814: }
21815: }
21816: }
21817: }
21818:
21819: foreach my $item (@{$itemsref}) {
21820: if ($item eq 'fields') {
21821: my @changed;
21822: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21823: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21824: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21825: }
21826: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21827: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21828: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21829: $domconfig{'selfenrollment'}{'validation'}{$item});
21830: } else {
21831: @changed = @{$selfenrollhash{'validation'}{$item}};
21832: }
21833: } else {
21834: @changed = @{$selfenrollhash{'validation'}{$item}};
21835: }
21836: if (@changed) {
21837: if ($selfenrollhash{'validation'}{$item}) {
21838: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21839: } else {
21840: $changes{'validation'}{$item} = &mt('None');
21841: }
21842: }
21843: } else {
21844: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21845: if ($item eq 'markup') {
21846: if ($env{'form.selfenroll_validation_'.$item}) {
21847: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21848: }
21849: }
21850: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21851: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21852: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21853: }
21854: }
21855: }
21856: }
21857:
21858: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21859: $dom);
21860: if ($putresult eq 'ok') {
21861: if (keys(%changes) > 0) {
21862: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21863: $resulttext = &mt('Changes made:').'<ul>';
21864: foreach my $key ('admin','default','validation') {
21865: if (ref($changes{$key}) eq 'HASH') {
21866: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
21867: if ($key eq 'validation') {
21868: foreach my $item (@{$itemsref}) {
21869: if (exists($changes{$key}{$item})) {
21870: if ($item eq 'markup') {
21871: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21872: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
21873: } else {
21874: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21875: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
21876: }
21877: }
21878: }
21879: } else {
21880: foreach my $type (@types) {
21881: if ($type eq 'community') {
21882: $roles{'1'} = &mt('Community personnel');
21883: } else {
21884: $roles{'1'} = &mt('Course personnel');
21885: }
21886: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 21887: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21888: if ($key eq 'admin') {
21889: my @mgrdc = ();
21890: if (ref($ordered{$key}) eq 'ARRAY') {
21891: foreach my $item (@{$ordered{'admin'}}) {
21892: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21893: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
21894: push(@mgrdc,$item);
21895: }
21896: }
21897: }
21898: if (@mgrdc) {
21899: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
21900: } else {
21901: delete($domdefaults{$type.'selfenrolladmdc'});
21902: }
21903: }
21904: } else {
21905: if (ref($ordered{$key}) eq 'ARRAY') {
21906: foreach my $item (@{$ordered{$key}}) {
21907: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21908: $domdefaults{$type.'selfenroll'.$item} =
21909: $selfenrollhash{$key}{$type}{$item};
21910: }
21911: }
21912: }
21913: }
21914: }
1.231 raeburn 21915: $resulttext .= '<li>'.$titles{$type}.'<ul>';
21916: foreach my $item (@{$ordered{$key}}) {
21917: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21918: $resulttext .= '<li>';
21919: if ($key eq 'admin') {
21920: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
21921: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
21922: } else {
21923: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
21924: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
21925: }
21926: $resulttext .= '</li>';
21927: }
21928: }
21929: $resulttext .= '</ul></li>';
21930: }
21931: }
21932: $resulttext .= '</ul></li>';
21933: }
21934: }
1.305 raeburn 21935: }
21936: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
21937: my $cachetime = 24*60*60;
21938: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21939: if (ref($lastactref) eq 'HASH') {
21940: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 21941: }
1.231 raeburn 21942: }
21943: $resulttext .= '</ul>';
21944: } else {
21945: $resulttext = &mt('No changes made to self-enrollment settings');
21946: }
21947: } else {
21948: $resulttext = '<span class="LC_error">'.
21949: &mt('An error occurred: [_1]',$putresult).'</span>';
21950: }
21951: return $resulttext;
21952: }
21953:
1.373 raeburn 21954: sub modify_wafproxy {
21955: my ($dom,$action,$lastactref,%domconfig) = @_;
21956: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 21957: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
21958: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 21959: foreach my $server (sort(keys(%servers))) {
21960: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21961: if ($serverhome eq $server) {
21962: my $serverdom = &Apache::lonnet::host_domain($server);
21963: if ($serverdom eq $dom) {
21964: $canset{$server} = 1;
21965: }
21966: }
21967: }
1.381 raeburn 21968: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
21969: %{$values{$dom}} = ();
21970: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
21971: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
21972: }
1.388 raeburn 21973: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
21974: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
21975: }
1.382 raeburn 21976: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 21977: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
21978: }
21979: }
1.373 raeburn 21980: my $output;
21981: if (keys(%canset)) {
21982: %{$wafproxy{'alias'}} = ();
1.388 raeburn 21983: %{$wafproxy{'saml'}} = ();
1.373 raeburn 21984: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 21985: if ($env{'form.wafproxy_'.$dom}) {
21986: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
21987: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
21988: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
21989: $changes{'alias'} = 1;
21990: }
1.388 raeburn 21991: if ($env{'form.wafproxy_alias_saml_'.$key}) {
21992: $wafproxy{'saml'}{$key} = 1;
21993: }
21994: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
21995: $changes{'saml'} = 1;
21996: }
1.381 raeburn 21997: } else {
21998: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 21999: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 22000: if ($curralias{$key}) {
22001: $changes{'alias'} = 1;
22002: }
1.388 raeburn 22003: if ($currsaml{$key}) {
22004: $changes{'saml'} = 1;
22005: }
1.373 raeburn 22006: }
22007: if ($wafproxy{'alias'}{$key} eq '') {
22008: if ($curralias{$key}) {
22009: $expirecache{$key} = 1;
22010: }
22011: delete($wafproxy{'alias'}{$key});
22012: }
1.388 raeburn 22013: if ($wafproxy{'saml'}{$key} eq '') {
22014: if ($currsaml{$key}) {
22015: $expiresaml{$key} = 1;
22016: }
22017: delete($wafproxy{'saml'}{$key});
22018: }
1.373 raeburn 22019: }
22020: unless (keys(%{$wafproxy{'alias'}})) {
22021: delete($wafproxy{'alias'});
22022: }
1.388 raeburn 22023: unless (keys(%{$wafproxy{'saml'}})) {
22024: delete($wafproxy{'saml'});
22025: }
22026: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 22027: my %warn = (
22028: trusted => 'trusted IP range(s)',
1.381 raeburn 22029: vpnint => 'internal IP range(s) for VPN sessions(s)',
22030: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 22031: );
1.382 raeburn 22032: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22033: my $possible = $env{'form.wafproxy_'.$item};
22034: $possible =~ s/^\s+|\s+$//g;
22035: if ($possible ne '') {
1.381 raeburn 22036: if ($item eq 'remoteip') {
22037: if ($possible =~ /^[mhn]$/) {
22038: $wafproxy{$item} = $possible;
22039: }
22040: } elsif ($item eq 'ipheader') {
22041: if ($wafproxy{'remoteip'} eq 'h') {
22042: $wafproxy{$item} = $possible;
22043: }
1.382 raeburn 22044: } elsif ($item eq 'sslopt') {
22045: if ($possible =~ /^0|1$/) {
22046: $wafproxy{$item} = $possible;
22047: }
1.373 raeburn 22048: } else {
22049: my (@ok,$count);
1.381 raeburn 22050: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
22051: unless ($env{'form.wafproxy_vpnaccess'}) {
22052: $possible = '';
22053: }
22054: } elsif ($item eq 'trusted') {
22055: unless ($wafproxy{'remoteip'} eq 'h') {
22056: $possible = '';
22057: }
22058: }
22059: unless ($possible eq '') {
22060: $possible =~ s/[\r\n]+/\s/g;
22061: $possible =~ s/\s*-\s*/-/g;
22062: $possible =~ s/\s+/,/g;
1.393 raeburn 22063: $possible =~ s/,+/,/g;
1.381 raeburn 22064: }
1.373 raeburn 22065: $count = 0;
1.381 raeburn 22066: if ($possible ne '') {
1.373 raeburn 22067: foreach my $poss (split(/\,/,$possible)) {
22068: $count ++;
1.393 raeburn 22069: $poss = &validate_ip_pattern($poss);
22070: if ($poss ne '') {
1.373 raeburn 22071: push(@ok,$poss);
22072: }
22073: }
22074: my $diff = $count - scalar(@ok);
22075: if ($diff) {
22076: push(@warnings,'<li>'.
22077: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
22078: $diff,$warn{$item}).
22079: '</li>');
22080: }
1.393 raeburn 22081: if (@ok) {
22082: my @cidr_list;
22083: foreach my $item (@ok) {
22084: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
22085: }
22086: $wafproxy{$item} = join(',',@cidr_list);
22087: }
1.373 raeburn 22088: }
22089: }
1.381 raeburn 22090: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 22091: $changes{$item} = 1;
22092: }
1.381 raeburn 22093: } elsif ($currvalue{$item}) {
22094: $changes{$item} = 1;
1.425 raeburn 22095: }
1.381 raeburn 22096: }
22097: } else {
22098: if (keys(%curralias)) {
22099: $changes{'alias'} = 1;
1.388 raeburn 22100: }
22101: if (keys(%currsaml)) {
22102: $changes{'saml'} = 1;
1.425 raeburn 22103: }
1.381 raeburn 22104: if (keys(%currvalue)) {
22105: foreach my $key (keys(%currvalue)) {
22106: $changes{$key} = 1;
1.373 raeburn 22107: }
22108: }
22109: }
22110: if (keys(%changes)) {
22111: my %defaultshash = (
22112: wafproxy => \%wafproxy,
1.425 raeburn 22113: );
1.373 raeburn 22114: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22115: $dom);
22116: if ($putresult eq 'ok') {
22117: my $cachetime = 24*60*60;
22118: my (%domdefaults,$updatedomdefs);
1.382 raeburn 22119: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22120: if ($changes{$item}) {
22121: unless ($updatedomdefs) {
22122: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
22123: $updatedomdefs = 1;
22124: }
22125: if ($wafproxy{$item}) {
22126: $domdefaults{'waf_'.$item} = $wafproxy{$item};
22127: } elsif (exists($domdefaults{'waf_'.$item})) {
22128: delete($domdefaults{'waf_'.$item});
1.425 raeburn 22129: }
1.373 raeburn 22130: }
22131: }
22132: if ($updatedomdefs) {
22133: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22134: if (ref($lastactref) eq 'HASH') {
22135: $lastactref->{'domdefaults'} = 1;
22136: }
22137: }
22138: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22139: my %updates = %expirecache;
22140: foreach my $key (keys(%expirecache)) {
22141: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22142: }
22143: if (ref($wafproxy{'alias'}) eq 'HASH') {
22144: my $cachetime = 24*60*60;
22145: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22146: $updates{$key} = 1;
22147: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22148: $cachetime);
22149: }
22150: }
22151: if (ref($lastactref) eq 'HASH') {
22152: $lastactref->{'proxyalias'} = \%updates;
22153: }
22154: }
1.388 raeburn 22155: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22156: my %samlupdates = %expiresaml;
22157: foreach my $key (keys(%expiresaml)) {
22158: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22159: }
22160: if (ref($wafproxy{'saml'}) eq 'HASH') {
22161: my $cachetime = 24*60*60;
22162: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22163: $samlupdates{$key} = 1;
22164: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22165: $cachetime);
22166: }
22167: }
22168: if (ref($lastactref) eq 'HASH') {
22169: $lastactref->{'proxysaml'} = \%samlupdates;
22170: }
22171: }
1.373 raeburn 22172: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22173: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22174: if ($changes{$item}) {
22175: if ($item eq 'alias') {
22176: my $numaliased = 0;
22177: if (ref($wafproxy{'alias'}) eq 'HASH') {
22178: my $shown;
22179: if (keys(%{$wafproxy{'alias'}})) {
22180: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22181: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22182: &Apache::lonnet::hostname($server),
22183: $wafproxy{'alias'}{$server}).'</li>';
22184: $numaliased ++;
22185: }
22186: if ($numaliased) {
22187: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22188: '<ul>'.$shown.'</ul>').'</li>';
22189: }
22190: }
22191: }
22192: unless ($numaliased) {
22193: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22194: }
1.388 raeburn 22195: } elsif ($item eq 'saml') {
1.425 raeburn 22196: my $shown;
1.388 raeburn 22197: if (ref($wafproxy{'saml'}) eq 'HASH') {
22198: if (keys(%{$wafproxy{'saml'}})) {
22199: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22200: }
22201: }
22202: if ($shown) {
1.396 raeburn 22203: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22204: $shown).'</li>';
22205: } else {
1.396 raeburn 22206: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22207: }
1.373 raeburn 22208: } else {
1.381 raeburn 22209: if ($item eq 'remoteip') {
22210: my %ip_methods = &remoteip_methods();
22211: if ($wafproxy{$item} =~ /^[mh]$/) {
22212: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22213: $ip_methods{$wafproxy{$item}}).'</li>';
22214: } else {
22215: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22216: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22217: '</li>';
22218: } else {
22219: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22220: }
22221: }
22222: } elsif ($item eq 'ipheader') {
1.373 raeburn 22223: if ($wafproxy{$item}) {
1.381 raeburn 22224: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22225: $wafproxy{$item}).'</li>';
22226: } else {
1.381 raeburn 22227: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22228: }
22229: } elsif ($item eq 'trusted') {
22230: if ($wafproxy{$item}) {
1.381 raeburn 22231: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22232: $wafproxy{$item}).'</li>';
22233: } else {
22234: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22235: }
1.381 raeburn 22236: } elsif ($item eq 'vpnint') {
22237: if ($wafproxy{$item}) {
22238: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22239: $wafproxy{$item}).'</li>';
22240: } else {
22241: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22242: }
22243: } elsif ($item eq 'vpnext') {
1.373 raeburn 22244: if ($wafproxy{$item}) {
1.381 raeburn 22245: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22246: $wafproxy{$item}).'</li>';
22247: } else {
1.381 raeburn 22248: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22249: }
1.382 raeburn 22250: } elsif ($item eq 'sslopt') {
22251: if ($wafproxy{$item}) {
22252: $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>';
22253: } else {
22254: $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>';
22255: }
1.373 raeburn 22256: }
22257: }
22258: }
22259: }
1.420 raeburn 22260: $output .= '</ul>';
1.373 raeburn 22261: } else {
22262: $output = '<span class="LC_error">'.
22263: &mt('An error occurred: [_1]',$putresult).'</span>';
22264: }
22265: } elsif (keys(%canset)) {
22266: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22267: }
22268: if (@warnings) {
22269: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22270: join("\n",@warnings).'</ul>';
22271: }
22272: return $output;
22273: }
22274:
22275: sub validate_ip_pattern {
22276: my ($pattern) = @_;
22277: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22278: my ($start,$end) = ($1,$2);
22279: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22280: if (($start !~ m{/}) && ($end !~ m{/})) {
22281: return $start.'-'.$end;
22282: }
22283: }
22284: } elsif ($pattern ne '') {
22285: $pattern = &Net::CIDR::cidrvalidate($pattern);
22286: if ($pattern ne '') {
22287: return $pattern;
1.373 raeburn 22288: }
22289: }
1.393 raeburn 22290: return;
1.373 raeburn 22291: }
22292:
1.137 raeburn 22293: sub modify_usersessions {
1.212 raeburn 22294: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22295: my @hostingtypes = ('version','excludedomain','includedomain');
22296: my @offloadtypes = ('primary','default');
22297: my %types = (
22298: remote => \@hostingtypes,
22299: hosted => \@hostingtypes,
22300: spares => \@offloadtypes,
22301: );
22302: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22303: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22304: my (%by_ip,%by_location,@intdoms,@instdoms);
22305: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22306: my @locations = sort(keys(%by_location));
1.137 raeburn 22307: my (%defaultshash,%changes);
22308: foreach my $prefix (@prefixes) {
22309: $defaultshash{'usersessions'}{$prefix} = {};
22310: }
1.212 raeburn 22311: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22312: my $resulttext;
1.138 raeburn 22313: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22314: foreach my $prefix (@prefixes) {
1.145 raeburn 22315: next if ($prefix eq 'spares');
22316: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22317: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22318: if ($type eq 'version') {
22319: my $value = $env{'form.'.$prefix.'_'.$type};
22320: my $okvalue;
22321: if ($value ne '') {
22322: if (grep(/^\Q$value\E$/,@lcversions)) {
22323: $okvalue = $value;
22324: }
22325: }
22326: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22327: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22328: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22329: if ($inuse == 0) {
22330: $changes{$prefix}{$type} = 1;
22331: } else {
22332: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22333: $changes{$prefix}{$type} = 1;
22334: }
22335: if ($okvalue ne '') {
22336: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22337: }
22338: }
22339: } else {
22340: if (($inuse == 1) && ($okvalue ne '')) {
22341: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22342: $changes{$prefix}{$type} = 1;
22343: }
22344: }
22345: } else {
22346: if (($inuse == 1) && ($okvalue ne '')) {
22347: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22348: $changes{$prefix}{$type} = 1;
22349: }
22350: }
22351: } else {
22352: if (($inuse == 1) && ($okvalue ne '')) {
22353: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22354: $changes{$prefix}{$type} = 1;
22355: }
22356: }
22357: } else {
22358: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22359: my @okvals;
22360: foreach my $val (@vals) {
1.138 raeburn 22361: if ($val =~ /:/) {
22362: my @items = split(/:/,$val);
22363: foreach my $item (@items) {
22364: if (ref($by_location{$item}) eq 'ARRAY') {
22365: push(@okvals,$item);
22366: }
22367: }
22368: } else {
22369: if (ref($by_location{$val}) eq 'ARRAY') {
22370: push(@okvals,$val);
22371: }
1.137 raeburn 22372: }
22373: }
22374: @okvals = sort(@okvals);
22375: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22376: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22377: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22378: if ($inuse == 0) {
22379: $changes{$prefix}{$type} = 1;
22380: } else {
22381: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22382: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22383: if (@changed > 0) {
22384: $changes{$prefix}{$type} = 1;
22385: }
22386: }
22387: } else {
22388: if ($inuse == 1) {
22389: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22390: $changes{$prefix}{$type} = 1;
22391: }
22392: }
22393: } else {
22394: if ($inuse == 1) {
22395: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22396: $changes{$prefix}{$type} = 1;
22397: }
22398: }
22399: } else {
22400: if ($inuse == 1) {
22401: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22402: $changes{$prefix}{$type} = 1;
22403: }
22404: }
22405: }
22406: }
22407: }
1.145 raeburn 22408:
22409: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22410: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22411: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22412: my $savespares;
22413:
22414: foreach my $lonhost (sort(keys(%servers))) {
22415: my $serverhomeID =
22416: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22417: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22418: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22419: my %spareschg;
22420: foreach my $type (@{$types{'spares'}}) {
22421: my @okspares;
22422: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22423: foreach my $server (@checked) {
1.152 raeburn 22424: if (&Apache::lonnet::hostname($server) ne '') {
22425: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22426: unless (grep(/^\Q$server\E$/,@okspares)) {
22427: push(@okspares,$server);
22428: }
1.145 raeburn 22429: }
22430: }
22431: }
22432: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22433: my $newspare;
1.152 raeburn 22434: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22435: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22436: $newspare = $new;
22437: }
22438: }
1.152 raeburn 22439: my @spares;
22440: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22441: @spares = sort(@okspares,$newspare);
22442: } else {
22443: @spares = sort(@okspares);
22444: }
22445: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22446: if (ref($spareid{$lonhost}) eq 'HASH') {
22447: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22448: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22449: if (@diffs > 0) {
22450: $spareschg{$type} = 1;
22451: }
22452: }
22453: }
22454: }
22455: if (keys(%spareschg) > 0) {
22456: $changes{'spares'}{$lonhost} = \%spareschg;
22457: }
22458: }
1.261 raeburn 22459: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22460: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22461: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22462: my @okoffload;
22463: if (@offloadnow) {
22464: foreach my $server (@offloadnow) {
22465: if (&Apache::lonnet::hostname($server) ne '') {
22466: unless (grep(/^\Q$server\E$/,@okoffload)) {
22467: push(@okoffload,$server);
22468: }
22469: }
22470: }
22471: if (@okoffload) {
22472: foreach my $lonhost (@okoffload) {
22473: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22474: }
22475: }
22476: }
1.371 raeburn 22477: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22478: my @okoffloadoth;
22479: if (@offloadoth) {
22480: foreach my $server (@offloadoth) {
22481: if (&Apache::lonnet::hostname($server) ne '') {
22482: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22483: push(@okoffloadoth,$server);
22484: }
22485: }
22486: }
22487: if (@okoffloadoth) {
22488: foreach my $lonhost (@okoffloadoth) {
22489: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22490: }
22491: }
22492: }
1.145 raeburn 22493: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22494: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22495: if (ref($changes{'spares'}) eq 'HASH') {
22496: if (keys(%{$changes{'spares'}}) > 0) {
22497: $savespares = 1;
22498: }
22499: }
22500: } else {
22501: $savespares = 1;
22502: }
1.371 raeburn 22503: foreach my $offload ('offloadnow','offloadoth') {
22504: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22505: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22506: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22507: $changes{$offload} = 1;
22508: last;
22509: }
1.261 raeburn 22510: }
1.371 raeburn 22511: unless ($changes{$offload}) {
22512: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22513: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22514: $changes{$offload} = 1;
22515: last;
22516: }
1.261 raeburn 22517: }
22518: }
1.371 raeburn 22519: } else {
22520: if (($offload eq 'offloadnow') && (@okoffload)) {
22521: $changes{'offloadnow'} = 1;
22522: }
22523: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22524: $changes{'offloadoth'} = 1;
22525: }
1.425 raeburn 22526: }
1.371 raeburn 22527: }
22528: } else {
22529: if (@okoffload) {
1.261 raeburn 22530: $changes{'offloadnow'} = 1;
22531: }
1.371 raeburn 22532: if (@okoffloadoth) {
22533: $changes{'offloadoth'} = 1;
22534: }
1.145 raeburn 22535: }
1.147 raeburn 22536: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22537: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22538: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22539: $dom);
22540: if ($putresult eq 'ok') {
22541: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22542: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22543: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22544: }
22545: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22546: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22547: }
1.261 raeburn 22548: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22549: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22550: }
1.371 raeburn 22551: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22552: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22553: }
1.137 raeburn 22554: }
22555: my $cachetime = 24*60*60;
22556: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22557: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22558: if (ref($lastactref) eq 'HASH') {
22559: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22560: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22561: }
1.147 raeburn 22562: if (keys(%changes) > 0) {
22563: my %lt = &usersession_titles();
22564: $resulttext = &mt('Changes made:').'<ul>';
22565: foreach my $prefix (@prefixes) {
22566: if (ref($changes{$prefix}) eq 'HASH') {
22567: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22568: if ($prefix eq 'spares') {
22569: if (ref($changes{$prefix}) eq 'HASH') {
22570: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22571: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22572: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22573: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22574: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22575: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22576: foreach my $type (@{$types{$prefix}}) {
22577: if ($changes{$prefix}{$lonhost}{$type}) {
22578: my $offloadto = &mt('None');
22579: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22580: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22581: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22582: }
1.145 raeburn 22583: }
1.147 raeburn 22584: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22585: }
1.137 raeburn 22586: }
22587: }
1.147 raeburn 22588: $resulttext .= '</li>';
1.137 raeburn 22589: }
22590: }
1.147 raeburn 22591: } else {
22592: foreach my $type (@{$types{$prefix}}) {
22593: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22594: my ($newvalue,$notinuse);
1.147 raeburn 22595: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22596: if (ref($defaultshash{'usersessions'}{$prefix})) {
22597: if ($type eq 'version') {
22598: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22599: } else {
22600: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22601: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22602: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22603: }
22604: } else {
22605: $notinuse = 1;
1.147 raeburn 22606: }
1.145 raeburn 22607: }
22608: }
22609: }
1.147 raeburn 22610: if ($newvalue eq '') {
22611: if ($type eq 'version') {
22612: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22613: } elsif ($notinuse) {
22614: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22615: } else {
22616: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22617: }
1.145 raeburn 22618: } else {
1.147 raeburn 22619: if ($type eq 'version') {
1.344 raeburn 22620: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22621: }
22622: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22623: }
1.137 raeburn 22624: }
22625: }
22626: }
1.147 raeburn 22627: $resulttext .= '</ul>';
1.137 raeburn 22628: }
22629: }
1.261 raeburn 22630: if ($changes{'offloadnow'}) {
22631: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22632: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22633: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22634: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22635: $resulttext .= '<li>'.$lonhost.'</li>';
22636: }
22637: $resulttext .= '</ul>';
22638: } else {
1.371 raeburn 22639: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22640: }
22641: } else {
22642: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22643: }
22644: }
22645: if ($changes{'offloadoth'}) {
22646: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22647: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22648: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22649: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22650: $resulttext .= '<li>'.$lonhost.'</li>';
22651: }
22652: $resulttext .= '</ul>';
22653: } else {
22654: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22655: }
22656: } else {
1.371 raeburn 22657: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22658: }
22659: }
1.147 raeburn 22660: $resulttext .= '</ul>';
22661: } else {
22662: $resulttext = $nochgmsg;
1.137 raeburn 22663: }
22664: } else {
22665: $resulttext = '<span class="LC_error">'.
22666: &mt('An error occurred: [_1]',$putresult).'</span>';
22667: }
22668: } else {
1.147 raeburn 22669: $resulttext = $nochgmsg;
1.137 raeburn 22670: }
22671: return $resulttext;
22672: }
22673:
1.275 raeburn 22674: sub modify_ssl {
22675: my ($dom,$lastactref,%domconfig) = @_;
22676: my (%by_ip,%by_location,@intdoms,@instdoms);
22677: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22678: my @locations = sort(keys(%by_location));
22679: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22680: my (%defaultshash,%changes);
22681: my $action = 'ssl';
1.293 raeburn 22682: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22683: foreach my $prefix (@prefixes) {
22684: $defaultshash{$action}{$prefix} = {};
22685: }
22686: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22687: my $resulttext;
22688: my %iphost = &Apache::lonnet::get_iphost();
22689: my @reptypes = ('certreq','nocertreq');
22690: my @connecttypes = ('dom','intdom','other');
22691: my %types = (
1.293 raeburn 22692: connto => \@connecttypes,
22693: connfrom => \@connecttypes,
22694: replication => \@reptypes,
1.275 raeburn 22695: );
22696: foreach my $prefix (sort(keys(%types))) {
22697: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22698: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22699: my $value = 'yes';
22700: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22701: $value = $env{'form.'.$prefix.'_'.$type};
22702: }
1.335 raeburn 22703: if (ref($domconfig{$action}) eq 'HASH') {
22704: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22705: if ($domconfig{$action}{$prefix}{$type} ne '') {
22706: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22707: $changes{$prefix}{$type} = 1;
22708: }
22709: $defaultshash{$action}{$prefix}{$type} = $value;
22710: } else {
22711: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22712: $changes{$prefix}{$type} = 1;
22713: }
22714: } else {
22715: $defaultshash{$action}{$prefix}{$type} = $value;
22716: $changes{$prefix}{$type} = 1;
22717: }
22718: } else {
22719: $defaultshash{$action}{$prefix}{$type} = $value;
22720: $changes{$prefix}{$type} = 1;
22721: }
22722: if (($type eq 'dom') && (keys(%servers) == 1)) {
22723: delete($changes{$prefix}{$type});
22724: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22725: delete($changes{$prefix}{$type});
22726: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22727: delete($changes{$prefix}{$type});
22728: }
22729: } elsif ($prefix eq 'replication') {
22730: if (@locations > 0) {
22731: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22732: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22733: my @okvals;
22734: foreach my $val (@vals) {
22735: if ($val =~ /:/) {
22736: my @items = split(/:/,$val);
22737: foreach my $item (@items) {
22738: if (ref($by_location{$item}) eq 'ARRAY') {
22739: push(@okvals,$item);
22740: }
22741: }
22742: } else {
22743: if (ref($by_location{$val}) eq 'ARRAY') {
22744: push(@okvals,$val);
22745: }
22746: }
22747: }
22748: @okvals = sort(@okvals);
22749: if (ref($domconfig{$action}) eq 'HASH') {
22750: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22751: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22752: if ($inuse == 0) {
22753: $changes{$prefix}{$type} = 1;
22754: } else {
22755: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22756: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22757: if (@changed > 0) {
22758: $changes{$prefix}{$type} = 1;
22759: }
22760: }
22761: } else {
22762: if ($inuse == 1) {
22763: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22764: $changes{$prefix}{$type} = 1;
22765: }
22766: }
22767: } else {
22768: if ($inuse == 1) {
22769: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22770: $changes{$prefix}{$type} = 1;
22771: }
22772: }
22773: } else {
22774: if ($inuse == 1) {
22775: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22776: $changes{$prefix}{$type} = 1;
22777: }
22778: }
22779: }
22780: }
22781: }
22782: }
1.336 raeburn 22783: if (keys(%changes)) {
22784: foreach my $prefix (keys(%changes)) {
22785: if (ref($changes{$prefix}) eq 'HASH') {
22786: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22787: delete($changes{$prefix});
22788: }
22789: } else {
22790: delete($changes{$prefix});
22791: }
22792: }
22793: }
1.275 raeburn 22794: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22795: if (keys(%changes) > 0) {
22796: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22797: $dom);
22798: if ($putresult eq 'ok') {
22799: if (ref($defaultshash{$action}) eq 'HASH') {
22800: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22801: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22802: }
1.293 raeburn 22803: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22804: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22805: }
22806: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22807: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22808: }
22809: }
22810: my $cachetime = 24*60*60;
22811: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22812: if (ref($lastactref) eq 'HASH') {
22813: $lastactref->{'domdefaults'} = 1;
22814: }
22815: if (keys(%changes) > 0) {
22816: my %titles = &ssl_titles();
22817: $resulttext = &mt('Changes made:').'<ul>';
22818: foreach my $prefix (@prefixes) {
22819: if (ref($changes{$prefix}) eq 'HASH') {
22820: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22821: foreach my $type (@{$types{$prefix}}) {
22822: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22823: my ($newvalue,$notinuse);
1.275 raeburn 22824: if (ref($defaultshash{$action}) eq 'HASH') {
22825: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22826: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22827: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22828: } else {
22829: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22830: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22831: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22832: }
22833: } else {
22834: $notinuse = 1;
1.275 raeburn 22835: }
22836: }
22837: }
1.344 raeburn 22838: if ($notinuse) {
22839: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22840: } elsif ($newvalue eq '') {
1.275 raeburn 22841: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22842: } else {
22843: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22844: }
22845: }
22846: }
22847: }
22848: $resulttext .= '</ul>';
22849: }
22850: }
22851: } else {
22852: $resulttext = $nochgmsg;
22853: }
22854: } else {
22855: $resulttext = '<span class="LC_error">'.
22856: &mt('An error occurred: [_1]',$putresult).'</span>';
22857: }
22858: } else {
22859: $resulttext = $nochgmsg;
22860: }
22861: return $resulttext;
22862: }
22863:
1.279 raeburn 22864: sub modify_trust {
22865: my ($dom,$lastactref,%domconfig) = @_;
22866: my (%by_ip,%by_location,@intdoms,@instdoms);
22867: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22868: my @locations = sort(keys(%by_location));
22869: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
22870: my @types = ('exc','inc');
22871: my (%defaultshash,%changes);
22872: foreach my $prefix (@prefixes) {
22873: $defaultshash{'trust'}{$prefix} = {};
22874: }
22875: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22876: my $resulttext;
22877: foreach my $prefix (@prefixes) {
22878: foreach my $type (@types) {
22879: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22880: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22881: my @okvals;
22882: foreach my $val (@vals) {
22883: if ($val =~ /:/) {
22884: my @items = split(/:/,$val);
22885: foreach my $item (@items) {
22886: if (ref($by_location{$item}) eq 'ARRAY') {
22887: push(@okvals,$item);
22888: }
22889: }
22890: } else {
22891: if (ref($by_location{$val}) eq 'ARRAY') {
22892: push(@okvals,$val);
22893: }
22894: }
22895: }
22896: @okvals = sort(@okvals);
22897: if (ref($domconfig{'trust'}) eq 'HASH') {
22898: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
22899: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22900: if ($inuse == 0) {
22901: $changes{$prefix}{$type} = 1;
22902: } else {
22903: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22904: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
22905: if (@changed > 0) {
22906: $changes{$prefix}{$type} = 1;
22907: }
22908: }
22909: } else {
22910: if ($inuse == 1) {
22911: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22912: $changes{$prefix}{$type} = 1;
22913: }
22914: }
22915: } else {
22916: if ($inuse == 1) {
22917: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22918: $changes{$prefix}{$type} = 1;
22919: }
22920: }
22921: } else {
22922: if ($inuse == 1) {
22923: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22924: $changes{$prefix}{$type} = 1;
22925: }
22926: }
22927: }
22928: }
22929: my $nochgmsg = &mt('No changes made to trust settings.');
22930: if (keys(%changes) > 0) {
22931: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22932: $dom);
22933: if ($putresult eq 'ok') {
22934: if (ref($defaultshash{'trust'}) eq 'HASH') {
22935: foreach my $prefix (@prefixes) {
22936: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
22937: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
22938: }
22939: }
22940: }
22941: my $cachetime = 24*60*60;
22942: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 22943: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 22944: if (ref($lastactref) eq 'HASH') {
22945: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 22946: $lastactref->{'trust'} = 1;
1.279 raeburn 22947: }
22948: if (keys(%changes) > 0) {
22949: my %lt = &trust_titles();
22950: $resulttext = &mt('Changes made:').'<ul>';
22951: foreach my $prefix (@prefixes) {
22952: if (ref($changes{$prefix}) eq 'HASH') {
22953: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22954: foreach my $type (@types) {
22955: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22956: my ($newvalue,$notinuse);
1.279 raeburn 22957: if (ref($defaultshash{'trust'}) eq 'HASH') {
22958: if (ref($defaultshash{'trust'}{$prefix})) {
22959: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22960: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
22961: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
22962: }
1.344 raeburn 22963: } else {
22964: $notinuse = 1;
1.279 raeburn 22965: }
22966: }
22967: }
1.344 raeburn 22968: if ($notinuse) {
22969: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
22970: } elsif ($newvalue eq '') {
1.279 raeburn 22971: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22972: } else {
22973: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
22974: }
22975: }
22976: }
22977: $resulttext .= '</ul>';
22978: }
22979: }
22980: $resulttext .= '</ul>';
22981: } else {
22982: $resulttext = $nochgmsg;
22983: }
22984: } else {
22985: $resulttext = '<span class="LC_error">'.
22986: &mt('An error occurred: [_1]',$putresult).'</span>';
22987: }
22988: } else {
22989: $resulttext = $nochgmsg;
22990: }
22991: return $resulttext;
22992: }
22993:
1.150 raeburn 22994: sub modify_loadbalancing {
22995: my ($dom,%domconfig) = @_;
22996: my $primary_id = &Apache::lonnet::domain($dom,'primary');
22997: my $intdom = &Apache::lonnet::internet_dom($primary_id);
22998: my ($othertitle,$usertypes,$types) =
22999: &Apache::loncommon::sorted_inst_types($dom);
23000: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 23001: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 23002: my @sparestypes = ('primary','default');
23003: my %typetitles = &sparestype_titles();
23004: my $resulttext;
1.342 raeburn 23005: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23006: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23007: %existing = %{$domconfig{'loadbalancing'}};
23008: }
23009: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 23010: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 23011: my ($saveloadbalancing,%defaultshash,%changes);
23012: my ($alltypes,$othertypes,$titles) =
23013: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
23014: my %ruletitles = &offloadtype_text();
23015: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
23016: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
23017: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
23018: if ($balancer eq '') {
23019: next;
23020: }
1.210 raeburn 23021: if (!exists($servers{$balancer})) {
1.171 raeburn 23022: if (exists($currbalancer{$balancer})) {
23023: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 23024: }
1.171 raeburn 23025: next;
23026: }
23027: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
23028: push(@{$changes{'delete'}},$balancer);
23029: next;
23030: }
23031: if (!exists($currbalancer{$balancer})) {
23032: push(@{$changes{'add'}},$balancer);
23033: }
23034: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
23035: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
23036: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
23037: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23038: $saveloadbalancing = 1;
23039: }
23040: foreach my $sparetype (@sparestypes) {
23041: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
23042: my @offloadto;
23043: foreach my $target (@targets) {
23044: if (($servers{$target}) && ($target ne $balancer)) {
23045: if ($sparetype eq 'default') {
23046: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
23047: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 23048: }
23049: }
1.171 raeburn 23050: unless(grep(/^\Q$target\E$/,@offloadto)) {
23051: push(@offloadto,$target);
23052: }
1.150 raeburn 23053: }
23054: }
1.284 raeburn 23055: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
23056: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
23057: push(@offloadto,$balancer);
23058: }
23059: }
23060: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 23061: }
1.342 raeburn 23062: if ($env{'form.loadbalancing_cookie_'.$i}) {
23063: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 23064: if (exists($currbalancer{$balancer})) {
1.342 raeburn 23065: unless ($currcookies{$balancer}) {
23066: $changes{'curr'}{$balancer}{'cookie'} = 1;
23067: }
23068: }
23069: } elsif (exists($currbalancer{$balancer})) {
23070: if ($currcookies{$balancer}) {
23071: $changes{'curr'}{$balancer}{'cookie'} = 1;
23072: }
23073: }
1.171 raeburn 23074: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 23075: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23076: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
23077: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 23078: if (@targetdiffs > 0) {
1.171 raeburn 23079: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23080: }
1.171 raeburn 23081: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23082: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23083: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23084: }
23085: }
23086: }
23087: } else {
1.171 raeburn 23088: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 23089: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23090: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23091: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23092: $changes{'curr'}{$balancer}{'targets'} = 1;
23093: }
1.150 raeburn 23094: }
23095: }
1.210 raeburn 23096: }
1.150 raeburn 23097: }
23098: my $ishomedom;
1.171 raeburn 23099: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
23100: $ishomedom = 1;
1.150 raeburn 23101: }
23102: if (ref($alltypes) eq 'ARRAY') {
23103: foreach my $type (@{$alltypes}) {
23104: my $rule;
1.210 raeburn 23105: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 23106: (!$ishomedom)) {
1.171 raeburn 23107: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
23108: }
23109: if ($rule eq 'specific') {
1.255 raeburn 23110: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 23111: if (exists($servers{$specifiedhost})) {
1.255 raeburn 23112: $rule = $specifiedhost;
23113: }
1.150 raeburn 23114: }
1.171 raeburn 23115: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
23116: if (ref($currrules{$balancer}) eq 'HASH') {
23117: if ($rule ne $currrules{$balancer}{$type}) {
23118: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23119: }
23120: } elsif ($rule ne '') {
1.171 raeburn 23121: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23122: }
23123: }
23124: }
1.171 raeburn 23125: }
23126: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
23127: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
23128: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23129: $defaultshash{'loadbalancing'} = {};
23130: }
23131: my $putresult = &Apache::lonnet::put_dom('configuration',
23132: \%defaultshash,$dom);
23133: if ($putresult eq 'ok') {
23134: if (keys(%changes) > 0) {
1.252 raeburn 23135: my %toupdate;
1.171 raeburn 23136: if (ref($changes{'delete'}) eq 'ARRAY') {
23137: foreach my $balancer (sort(@{$changes{'delete'}})) {
23138: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23139: $toupdate{$balancer} = 1;
1.150 raeburn 23140: }
1.171 raeburn 23141: }
23142: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23143: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23144: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23145: $toupdate{$balancer} = 1;
1.171 raeburn 23146: }
23147: }
23148: if (ref($changes{'curr'}) eq 'HASH') {
23149: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23150: $toupdate{$balancer} = 1;
1.171 raeburn 23151: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23152: if ($changes{'curr'}{$balancer}{'targets'}) {
23153: my %offloadstr;
23154: foreach my $sparetype (@sparestypes) {
23155: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23156: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23157: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23158: }
23159: }
1.150 raeburn 23160: }
1.171 raeburn 23161: if (keys(%offloadstr) == 0) {
23162: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23163: } else {
1.171 raeburn 23164: my $showoffload;
23165: foreach my $sparetype (@sparestypes) {
23166: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23167: if (defined($offloadstr{$sparetype})) {
23168: $showoffload .= $offloadstr{$sparetype};
23169: } else {
23170: $showoffload .= &mt('None');
23171: }
23172: $showoffload .= (' 'x3);
23173: }
23174: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23175: }
23176: }
23177: }
1.171 raeburn 23178: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23179: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23180: foreach my $type (@{$alltypes}) {
23181: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23182: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23183: my $balancetext;
23184: if ($rule eq '') {
23185: $balancetext = $ruletitles{'default'};
1.209 raeburn 23186: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23187: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23188: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23189: foreach my $sparetype (@sparestypes) {
23190: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23191: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23192: }
23193: }
1.253 raeburn 23194: foreach my $item (@{$alltypes}) {
23195: next if ($item =~ /^_LC_ipchange/);
23196: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23197: if ($hasrule eq 'homeserver') {
23198: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23199: } else {
23200: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23201: if ($servers{$hasrule}) {
23202: $toupdate{$hasrule} = 1;
23203: }
23204: }
23205: }
23206: }
1.254 raeburn 23207: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23208: $balancetext = $ruletitles{$rule};
23209: } else {
23210: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23211: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23212: if ($receiver) {
23213: $toupdate{$receiver};
23214: }
23215: }
23216: } else {
23217: $balancetext = $ruletitles{$rule};
1.252 raeburn 23218: }
1.171 raeburn 23219: } else {
23220: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23221: }
1.210 raeburn 23222: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23223: }
23224: }
23225: }
23226: }
1.342 raeburn 23227: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23228: if ($currcookies{$balancer}) {
23229: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23230: $balancer).'</li>';
23231: } else {
23232: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23233: $balancer).'</li>';
23234: }
1.342 raeburn 23235: }
1.375 raeburn 23236: }
23237: }
23238: if (keys(%toupdate)) {
23239: my %thismachine;
23240: my $updatedhere;
23241: my $cachetime = 60*60*24;
23242: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23243: foreach my $lonhost (keys(%toupdate)) {
23244: if ($thismachine{$lonhost}) {
23245: unless ($updatedhere) {
23246: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23247: $defaultshash{'loadbalancing'},
23248: $cachetime);
23249: $updatedhere = 1;
1.252 raeburn 23250: }
1.375 raeburn 23251: } else {
23252: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23253: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23254: }
1.150 raeburn 23255: }
1.171 raeburn 23256: }
23257: if ($resulttext ne '') {
23258: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23259: } else {
23260: $resulttext = $nochgmsg;
23261: }
23262: } else {
1.171 raeburn 23263: $resulttext = $nochgmsg;
1.150 raeburn 23264: }
23265: } else {
1.171 raeburn 23266: $resulttext = '<span class="LC_error">'.
23267: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23268: }
23269: } else {
1.171 raeburn 23270: $resulttext = $nochgmsg;
1.150 raeburn 23271: }
23272: return $resulttext;
23273: }
23274:
1.48 raeburn 23275: sub recurse_check {
23276: my ($chkcats,$categories,$depth,$name) = @_;
23277: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23278: my $chg = 0;
23279: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23280: my $category = $chkcats->[$depth]{$name}[$j];
23281: my $item;
23282: if ($category eq '') {
23283: $chg ++;
23284: } else {
23285: my $deeper = $depth + 1;
23286: $item = &escape($category).':'.&escape($name).':'.$depth;
23287: if ($chg) {
23288: $categories->{$item} -= $chg;
23289: }
23290: &recurse_check($chkcats,$categories,$deeper,$category);
23291: $deeper --;
23292: }
23293: }
23294: }
23295: return;
23296: }
23297:
23298: sub recurse_cat_deletes {
23299: my ($item,$coursecategories,$deletions) = @_;
23300: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23301: my $subdepth = $depth + 1;
23302: if (ref($coursecategories) eq 'HASH') {
23303: foreach my $subitem (keys(%{$coursecategories})) {
23304: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23305: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23306: delete($coursecategories->{$subitem});
23307: $deletions->{$subitem} = 1;
23308: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23309: }
1.48 raeburn 23310: }
23311: }
23312: return;
23313: }
23314:
1.125 raeburn 23315: sub active_dc_picker {
1.191 raeburn 23316: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23317: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23318: my @domcoord = keys(%domcoords);
23319: if (keys(%currhash)) {
23320: foreach my $dc (keys(%currhash)) {
23321: unless (exists($domcoords{$dc})) {
23322: push(@domcoord,$dc);
23323: }
23324: }
23325: }
23326: @domcoord = sort(@domcoord);
1.210 raeburn 23327: my $numdcs = scalar(@domcoord);
1.191 raeburn 23328: my $rows = 0;
23329: my $table;
1.125 raeburn 23330: if ($numdcs > 1) {
1.191 raeburn 23331: $table = '<table>';
23332: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23333: my $rem = $i%($numinrow);
23334: if ($rem == 0) {
23335: if ($i > 0) {
1.191 raeburn 23336: $table .= '</tr>';
1.125 raeburn 23337: }
1.191 raeburn 23338: $table .= '<tr>';
23339: $rows ++;
1.125 raeburn 23340: }
1.191 raeburn 23341: my $check = '';
23342: if ($inputtype eq 'radio') {
23343: if (keys(%currhash) == 0) {
23344: if (!$i) {
23345: $check = ' checked="checked"';
23346: }
23347: } elsif (exists($currhash{$domcoord[$i]})) {
23348: $check = ' checked="checked"';
23349: }
23350: } else {
23351: if (exists($currhash{$domcoord[$i]})) {
23352: $check = ' checked="checked"';
1.125 raeburn 23353: }
23354: }
1.191 raeburn 23355: if ($i == @domcoord - 1) {
1.125 raeburn 23356: my $colsleft = $numinrow - $rem;
23357: if ($colsleft > 1) {
1.191 raeburn 23358: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23359: } else {
1.191 raeburn 23360: $table .= '<td class="LC_left_item">';
1.125 raeburn 23361: }
23362: } else {
1.191 raeburn 23363: $table .= '<td class="LC_left_item">';
23364: }
23365: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23366: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23367: $table .= '<span class="LC_nobreak"><label>'.
23368: '<input type="'.$inputtype.'" name="'.$name.'"'.
23369: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23370: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23371: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23372: }
1.219 raeburn 23373: $table .= '</label></span></td>';
1.191 raeburn 23374: }
23375: $table .= '</tr></table>';
23376: } elsif ($numdcs == 1) {
1.219 raeburn 23377: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23378: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23379: if ($inputtype eq 'radio') {
1.247 raeburn 23380: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23381: if ($user ne $dcname.':'.$dcdom) {
23382: $table .= ' ('.$dcname.':'.$dcdom.')';
23383: }
1.191 raeburn 23384: } else {
23385: my $check;
23386: if (exists($currhash{$domcoord[0]})) {
23387: $check = ' checked="checked"';
1.125 raeburn 23388: }
1.247 raeburn 23389: $table = '<span class="LC_nobreak"><label>'.
23390: '<input type="checkbox" name="'.$name.'" '.
23391: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23392: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23393: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23394: }
1.220 raeburn 23395: $table .= '</label></span>';
1.191 raeburn 23396: $rows ++;
1.125 raeburn 23397: }
23398: }
1.191 raeburn 23399: return ($numdcs,$table,$rows);
1.125 raeburn 23400: }
23401:
1.137 raeburn 23402: sub usersession_titles {
23403: return &Apache::lonlocal::texthash(
23404: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23405: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23406: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23407: version => 'LON-CAPA version requirement',
1.138 raeburn 23408: excludedomain => 'Allow all, but exclude specific domains',
23409: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23410: primary => 'Primary (checked first)',
1.154 raeburn 23411: default => 'Default',
1.137 raeburn 23412: );
23413: }
23414:
1.152 raeburn 23415: sub id_for_thisdom {
23416: my (%servers) = @_;
23417: my %altids;
23418: foreach my $server (keys(%servers)) {
23419: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23420: if ($serverhome ne $server) {
23421: $altids{$serverhome} = $server;
23422: }
23423: }
23424: return %altids;
23425: }
23426:
1.150 raeburn 23427: sub count_servers {
23428: my ($currbalancer,%servers) = @_;
23429: my (@spares,$numspares);
23430: foreach my $lonhost (sort(keys(%servers))) {
23431: next if ($currbalancer eq $lonhost);
23432: push(@spares,$lonhost);
23433: }
23434: if ($currbalancer) {
23435: $numspares = scalar(@spares);
23436: } else {
23437: $numspares = scalar(@spares) - 1;
23438: }
23439: return ($numspares,@spares);
23440: }
23441:
23442: sub lonbalance_targets_js {
1.171 raeburn 23443: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23444: my $select = &mt('Select');
23445: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23446: if (ref($servers) eq 'HASH') {
23447: $alltargets = join("','",sort(keys(%{$servers})));
23448: my @homedoms;
23449: foreach my $server (sort(keys(%{$servers}))) {
23450: if (&Apache::lonnet::host_domain($server) eq $dom) {
23451: push(@homedoms,'1');
23452: } else {
23453: push(@homedoms,'0');
23454: }
23455: }
23456: $allishome = join("','",@homedoms);
23457: }
23458: if (ref($types) eq 'ARRAY') {
23459: if (@{$types} > 0) {
23460: @alltypes = @{$types};
23461: }
23462: }
23463: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23464: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23465: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23466: if (ref($settings) eq 'HASH') {
23467: %existing = %{$settings};
23468: }
23469: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23470: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23471: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23472: return <<"END";
23473:
23474: <script type="text/javascript">
23475: // <![CDATA[
23476:
1.171 raeburn 23477: currBalancers = new Array('$balancers');
23478:
23479: function toggleTargets(balnum) {
23480: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23481: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23482: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23483: var prevbalancer = prevhostitem.value;
23484: var baltotal = document.getElementById('loadbalancing_total').value;
23485: prevhostitem.value = balancer;
23486: if (prevbalancer != '') {
23487: var prevIdx = currBalancers.indexOf(prevbalancer);
23488: if (prevIdx != -1) {
23489: currBalancers.splice(prevIdx,1);
23490: }
23491: }
1.150 raeburn 23492: if (balancer == '') {
1.171 raeburn 23493: hideSpares(balnum);
1.150 raeburn 23494: } else {
1.171 raeburn 23495: var currIdx = currBalancers.indexOf(balancer);
23496: if (currIdx == -1) {
23497: currBalancers.push(balancer);
23498: }
1.150 raeburn 23499: var homedoms = new Array('$allishome');
1.171 raeburn 23500: var ishomedom = homedoms[lonhostitem.selectedIndex];
23501: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23502: }
1.171 raeburn 23503: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23504: return;
23505: }
23506:
1.171 raeburn 23507: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23508: var alltargets = new Array('$alltargets');
23509: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23510: var offloadtypes = new Array('primary','default');
23511:
1.171 raeburn 23512: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23513: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23514:
1.151 raeburn 23515: for (var i=0; i<offloadtypes.length; i++) {
23516: var count = 0;
23517: for (var j=0; j<alltargets.length; j++) {
23518: if (alltargets[j] != balancer) {
1.171 raeburn 23519: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23520: item.value = alltargets[j];
23521: item.style.textAlign='left';
23522: item.style.textFace='normal';
23523: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23524: if (currBalancers.indexOf(alltargets[j]) == -1) {
23525: item.disabled = '';
23526: } else {
23527: item.disabled = 'disabled';
23528: item.checked = false;
23529: }
1.151 raeburn 23530: count ++;
23531: }
1.150 raeburn 23532: }
23533: }
1.151 raeburn 23534: for (var k=0; k<insttypes.length; k++) {
23535: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23536: if (ishomedom == 1) {
1.171 raeburn 23537: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23538: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23539: } else {
1.171 raeburn 23540: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23541: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23542: }
23543: } else {
1.171 raeburn 23544: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23545: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23546: }
1.151 raeburn 23547: if ((insttypes[k] != '_LC_external') &&
23548: ((insttypes[k] != '_LC_internetdom') ||
23549: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23550: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23551: item.options.length = 0;
23552: item.options[0] = new Option("","",true,true);
1.210 raeburn 23553: var idx = 0;
1.151 raeburn 23554: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23555: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23556: idx ++;
23557: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23558: }
23559: }
23560: }
23561: }
23562: return;
23563: }
23564:
1.171 raeburn 23565: function hideSpares(balnum) {
1.150 raeburn 23566: var alltargets = new Array('$alltargets');
23567: var insttypes = new Array('$allinsttypes');
23568: var offloadtypes = new Array('primary','default');
23569:
1.171 raeburn 23570: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23571: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23572:
23573: var total = alltargets.length - 1;
23574: for (var i=0; i<offloadtypes; i++) {
23575: for (var j=0; j<total; j++) {
1.171 raeburn 23576: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23577: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23578: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23579: }
1.150 raeburn 23580: }
23581: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23582: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23583: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23584: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23585: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23586: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23587: }
23588: }
23589: return;
23590: }
23591:
1.171 raeburn 23592: function checkOffloads(item,balnum,type) {
1.150 raeburn 23593: var alltargets = new Array('$alltargets');
23594: var offloadtypes = new Array('primary','default');
23595: if (item.checked) {
23596: var total = alltargets.length - 1;
23597: var other;
23598: if (type == offloadtypes[0]) {
1.151 raeburn 23599: other = offloadtypes[1];
1.150 raeburn 23600: } else {
1.151 raeburn 23601: other = offloadtypes[0];
1.150 raeburn 23602: }
23603: for (var i=0; i<total; i++) {
1.171 raeburn 23604: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23605: if (server == item.value) {
1.171 raeburn 23606: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23607: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23608: }
23609: }
23610: }
23611: }
23612: return;
23613: }
23614:
1.171 raeburn 23615: function singleServerToggle(balnum,type) {
23616: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23617: if (offloadtoSelIdx == 0) {
1.171 raeburn 23618: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23619: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23620:
23621: } else {
1.171 raeburn 23622: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23623: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23624: }
23625: return;
23626: }
23627:
1.171 raeburn 23628: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23629: if (type == '_LC_external') {
1.171 raeburn 23630: return;
1.150 raeburn 23631: }
1.171 raeburn 23632: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23633: for (var i=0; i<typesRules.length; i++) {
23634: if (formname.elements[typesRules[i]].checked) {
23635: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23636: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23637: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23638: } else {
1.171 raeburn 23639: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23640: }
23641: }
23642: }
23643: return;
23644: }
23645:
23646: function balancerDeleteChange(balnum) {
23647: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23648: var baltotal = document.getElementById('loadbalancing_total').value;
23649: var addtarget;
23650: var removetarget;
23651: var action = 'delete';
23652: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23653: var lonhost = hostitem.value;
23654: var currIdx = currBalancers.indexOf(lonhost);
23655: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23656: if (currIdx != -1) {
23657: currBalancers.splice(currIdx,1);
23658: }
23659: addtarget = lonhost;
23660: } else {
23661: if (currIdx == -1) {
23662: currBalancers.push(lonhost);
23663: }
23664: removetarget = lonhost;
23665: action = 'undelete';
23666: }
23667: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23668: }
23669: return;
23670: }
23671:
23672: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23673: if (baltotal > 1) {
23674: var offloadtypes = new Array('primary','default');
23675: var alltargets = new Array('$alltargets');
23676: var insttypes = new Array('$allinsttypes');
23677: for (var i=0; i<baltotal; i++) {
23678: if (i != balnum) {
23679: for (var j=0; j<offloadtypes.length; j++) {
23680: var total = alltargets.length - 1;
23681: for (var k=0; k<total; k++) {
23682: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23683: var server = serveritem.value;
23684: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23685: if (server == addtarget) {
23686: serveritem.disabled = '';
23687: }
23688: }
23689: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23690: if (server == removetarget) {
23691: serveritem.disabled = 'disabled';
23692: serveritem.checked = false;
23693: }
23694: }
23695: }
23696: }
23697: for (var j=0; j<insttypes.length; j++) {
23698: if (insttypes[j] != '_LC_external') {
23699: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23700: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23701: var currSel = singleserver.selectedIndex;
23702: var currVal = singleserver.options[currSel].value;
23703: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23704: var numoptions = singleserver.options.length;
23705: var needsnew = 1;
23706: for (var k=0; k<numoptions; k++) {
23707: if (singleserver.options[k] == addtarget) {
23708: needsnew = 0;
23709: break;
23710: }
23711: }
23712: if (needsnew == 1) {
23713: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23714: }
23715: }
23716: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23717: singleserver.options.length = 0;
23718: if ((currVal) && (currVal != removetarget)) {
23719: singleserver.options[0] = new Option("","",false,false);
23720: } else {
23721: singleserver.options[0] = new Option("","",true,true);
23722: }
23723: var idx = 0;
23724: for (var m=0; m<alltargets.length; m++) {
23725: if (currBalancers.indexOf(alltargets[m]) == -1) {
23726: idx ++;
23727: if (currVal == alltargets[m]) {
23728: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23729: } else {
23730: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23731: }
23732: }
23733: }
23734: }
23735: }
23736: }
23737: }
1.150 raeburn 23738: }
23739: }
23740: }
23741: return;
23742: }
23743:
1.152 raeburn 23744: // ]]>
23745: </script>
23746:
23747: END
23748: }
23749:
23750: sub new_spares_js {
23751: my @sparestypes = ('primary','default');
23752: my $types = join("','",@sparestypes);
23753: my $select = &mt('Select');
23754: return <<"END";
23755:
23756: <script type="text/javascript">
23757: // <![CDATA[
23758:
23759: function updateNewSpares(formname,lonhost) {
23760: var types = new Array('$types');
23761: var include = new Array();
23762: var exclude = new Array();
23763: for (var i=0; i<types.length; i++) {
23764: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23765: for (var j=0; j<spareboxes.length; j++) {
23766: if (formname.elements[spareboxes[j]].checked) {
23767: exclude.push(formname.elements[spareboxes[j]].value);
23768: } else {
23769: include.push(formname.elements[spareboxes[j]].value);
23770: }
23771: }
23772: }
23773: for (var i=0; i<types.length; i++) {
23774: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23775: var selIdx = newSpare.selectedIndex;
23776: var currnew = newSpare.options[selIdx].value;
23777: var okSpares = new Array();
23778: for (var j=0; j<newSpare.options.length; j++) {
23779: var possible = newSpare.options[j].value;
23780: if (possible != '') {
23781: if (exclude.indexOf(possible) == -1) {
23782: okSpares.push(possible);
23783: } else {
23784: if (currnew == possible) {
23785: selIdx = 0;
23786: }
23787: }
23788: }
23789: }
23790: for (var k=0; k<include.length; k++) {
23791: if (okSpares.indexOf(include[k]) == -1) {
23792: okSpares.push(include[k]);
23793: }
23794: }
23795: okSpares.sort();
23796: newSpare.options.length = 0;
23797: if (selIdx == 0) {
23798: newSpare.options[0] = new Option("$select","",true,true);
23799: } else {
23800: newSpare.options[0] = new Option("$select","",false,false);
23801: }
23802: for (var m=0; m<okSpares.length; m++) {
23803: var idx = m+1;
23804: var selThis = 0;
23805: if (selIdx != 0) {
23806: if (okSpares[m] == currnew) {
23807: selThis = 1;
23808: }
23809: }
23810: if (selThis == 1) {
23811: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23812: } else {
23813: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23814: }
23815: }
23816: }
23817: return;
23818: }
23819:
23820: function checkNewSpares(lonhost,type) {
23821: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23822: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23823: if (chosen != '') {
1.152 raeburn 23824: var othertype;
23825: var othernewSpare;
23826: if (type == 'primary') {
23827: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23828: }
23829: if (type == 'default') {
23830: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23831: }
23832: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23833: othernewSpare.selectedIndex = 0;
23834: }
23835: }
23836: return;
23837: }
23838:
23839: // ]]>
23840: </script>
23841:
23842: END
23843:
23844: }
23845:
23846: sub common_domprefs_js {
23847: return <<"END";
23848:
23849: <script type="text/javascript">
23850: // <![CDATA[
23851:
1.150 raeburn 23852: function getIndicesByName(formname,item) {
1.152 raeburn 23853: var group = new Array();
1.150 raeburn 23854: for (var i=0;i<formname.elements.length;i++) {
23855: if (formname.elements[i].name == item) {
1.152 raeburn 23856: group.push(formname.elements[i].id);
1.150 raeburn 23857: }
23858: }
1.152 raeburn 23859: return group;
1.150 raeburn 23860: }
23861:
23862: // ]]>
23863: </script>
23864:
23865: END
1.152 raeburn 23866:
1.150 raeburn 23867: }
23868:
1.165 raeburn 23869: sub recaptcha_js {
23870: my %lt = &captcha_phrases();
23871: return <<"END";
23872:
23873: <script type="text/javascript">
23874: // <![CDATA[
23875:
23876: function updateCaptcha(caller,context) {
23877: var privitem;
23878: var pubitem;
23879: var privtext;
23880: var pubtext;
1.269 raeburn 23881: var versionitem;
23882: var versiontext;
1.165 raeburn 23883: if (document.getElementById(context+'_recaptchapub')) {
23884: pubitem = document.getElementById(context+'_recaptchapub');
23885: } else {
23886: return;
23887: }
23888: if (document.getElementById(context+'_recaptchapriv')) {
23889: privitem = document.getElementById(context+'_recaptchapriv');
23890: } else {
23891: return;
23892: }
23893: if (document.getElementById(context+'_recaptchapubtxt')) {
23894: pubtext = document.getElementById(context+'_recaptchapubtxt');
23895: } else {
23896: return;
23897: }
23898: if (document.getElementById(context+'_recaptchaprivtxt')) {
23899: privtext = document.getElementById(context+'_recaptchaprivtxt');
23900: } else {
23901: return;
23902: }
1.269 raeburn 23903: if (document.getElementById(context+'_recaptchaversion')) {
23904: versionitem = document.getElementById(context+'_recaptchaversion');
23905: } else {
23906: return;
23907: }
23908: if (document.getElementById(context+'_recaptchavertxt')) {
23909: versiontext = document.getElementById(context+'_recaptchavertxt');
23910: } else {
23911: return;
23912: }
1.165 raeburn 23913: if (caller.checked) {
23914: if (caller.value == 'recaptcha') {
23915: pubitem.type = 'text';
23916: privitem.type = 'text';
23917: pubitem.size = '40';
23918: privitem.size = '40';
23919: pubtext.innerHTML = "$lt{'pub'}";
23920: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 23921: versionitem.type = 'text';
23922: versionitem.size = '3';
1.289 raeburn 23923: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 23924: } else {
23925: pubitem.type = 'hidden';
23926: privitem.type = 'hidden';
1.269 raeburn 23927: versionitem.type = 'hidden';
1.165 raeburn 23928: pubtext.innerHTML = '';
23929: privtext.innerHTML = '';
1.269 raeburn 23930: versiontext.innerHTML = '';
1.165 raeburn 23931: }
23932: }
23933: return;
23934: }
23935:
23936: // ]]>
23937: </script>
23938:
23939: END
23940:
23941: }
23942:
1.236 raeburn 23943: sub toggle_display_js {
1.192 raeburn 23944: return <<"END";
23945:
23946: <script type="text/javascript">
23947: // <![CDATA[
23948:
1.236 raeburn 23949: function toggleDisplay(domForm,caller) {
23950: if (document.getElementById(caller)) {
23951: var divitem = document.getElementById(caller);
23952: var optionsElement = domForm.coursecredits;
1.264 raeburn 23953: var checkval = 1;
23954: var dispval = 'block';
1.303 raeburn 23955: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 23956: if (caller == 'emailoptions') {
1.372 raeburn 23957: optionsElement = domForm.cancreate_email;
1.236 raeburn 23958: }
1.257 raeburn 23959: if (caller == 'studentsubmission') {
23960: optionsElement = domForm.postsubmit;
23961: }
1.264 raeburn 23962: if (caller == 'cloneinstcode') {
23963: optionsElement = domForm.canclone;
23964: checkval = 'instcode';
23965: }
1.303 raeburn 23966: if (selfcreateRegExp.test(caller)) {
23967: optionsElement = domForm.elements[caller];
23968: checkval = 'other';
23969: dispval = 'inline'
23970: }
1.236 raeburn 23971: if (optionsElement.length) {
1.192 raeburn 23972: var currval;
1.236 raeburn 23973: for (var i=0; i<optionsElement.length; i++) {
23974: if (optionsElement[i].checked) {
23975: currval = optionsElement[i].value;
1.192 raeburn 23976: }
23977: }
1.264 raeburn 23978: if (currval == checkval) {
23979: divitem.style.display = dispval;
1.192 raeburn 23980: } else {
1.236 raeburn 23981: divitem.style.display = 'none';
1.192 raeburn 23982: }
23983: }
23984: }
23985: return;
23986: }
23987:
23988: // ]]>
23989: </script>
23990:
23991: END
23992:
23993: }
23994:
1.165 raeburn 23995: sub captcha_phrases {
23996: return &Apache::lonlocal::texthash (
23997: priv => 'Private key',
23998: pub => 'Public key',
23999: original => 'original (CAPTCHA)',
24000: recaptcha => 'successor (ReCAPTCHA)',
24001: notused => 'unused',
1.289 raeburn 24002: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 24003: );
24004: }
24005:
1.205 raeburn 24006: sub devalidate_remote_domconfs {
1.212 raeburn 24007: my ($dom,$cachekeys) = @_;
24008: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 24009: my %servers = &Apache::lonnet::internet_dom_servers($dom);
24010: my %thismachine;
24011: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 24012: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 24013: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 24014: 'ipaccess','trust');
1.386 raeburn 24015: my %cache_by_lonhost;
24016: if (exists($cachekeys->{'samllanding'})) {
24017: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
24018: my %landing = %{$cachekeys->{'samllanding'}};
24019: my %domservers = &Apache::lonnet::get_servers($dom);
24020: if (keys(%domservers)) {
24021: foreach my $server (keys(%domservers)) {
24022: my @cached;
24023: next if ($thismachine{$server});
24024: if ($landing{$server}) {
24025: push(@cached,&escape('samllanding').':'.&escape($server));
24026: }
24027: if (@cached) {
24028: $cache_by_lonhost{$server} = \@cached;
24029: }
24030: }
24031: }
24032: }
24033: }
1.260 raeburn 24034: if (keys(%servers)) {
1.205 raeburn 24035: foreach my $server (keys(%servers)) {
24036: next if ($thismachine{$server});
1.212 raeburn 24037: my @cached;
24038: foreach my $name (@posscached) {
24039: if ($cachekeys->{$name}) {
1.388 raeburn 24040: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 24041: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 24042: foreach my $key (keys(%{$cachekeys->{$name}})) {
24043: push(@cached,&escape($name).':'.&escape($key));
24044: }
24045: }
24046: } else {
24047: push(@cached,&escape($name).':'.&escape($dom));
24048: }
1.212 raeburn 24049: }
24050: }
1.386 raeburn 24051: if ((exists($cache_by_lonhost{$server})) &&
24052: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
24053: push(@cached,@{$cache_by_lonhost{$server}});
24054: }
1.212 raeburn 24055: if (@cached) {
24056: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
24057: }
1.205 raeburn 24058: }
24059: }
24060: return;
24061: }
24062:
1.3 raeburn 24063: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>