Annotation of loncom/interface/domainprefs.pm, revision 1.447.2.3
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.447.2.3! raeburn 4: # $Id: domainprefs.pm,v 1.447.2.2 2025/01/12 18:26:16 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.429 raeburn 98: used by course owners to request creation of a course.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 106: (official, unofficial, community, textbook, placement, and lti).
1.425 raeburn 107: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.232 raeburn 167: use Apache::lonuserutils();
1.235 raeburn 168: use Apache::loncoursequeueadmin();
1.419 raeburn 169: use Apache::courseprefs();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.373 raeburn 179: use Net::CIDR;
1.424 raeburn 180: use Crypt::CBC;
1.1 raeburn 181:
1.155 raeburn 182: my $registered_cleanup;
183: my $modified_urls;
184:
1.1 raeburn 185: sub handler {
186: my $r=shift;
187: if ($r->header_only) {
188: &Apache::loncommon::content_type($r,'text/html');
189: $r->send_http_header;
190: return OK;
191: }
192:
1.91 raeburn 193: my $context = 'domain';
1.1 raeburn 194: my $dom = $env{'request.role.domain'};
1.5 albertel 195: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 196: if (&Apache::lonnet::allowed('mau',$dom)) {
197: &Apache::loncommon::content_type($r,'text/html');
198: $r->send_http_header;
199: } else {
200: $env{'user.error.msg'}=
201: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
202: return HTTP_NOT_ACCEPTABLE;
203: }
1.155 raeburn 204:
205: $registered_cleanup=0;
206: @{$modified_urls}=();
207:
1.1 raeburn 208: &Apache::lonhtmlcommon::clear_breadcrumbs();
209: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 210: ['phase','actions']);
1.30 raeburn 211: my $phase = 'pickactions';
1.3 raeburn 212: if ( exists($env{'form.phase'}) ) {
213: $phase = $env{'form.phase'};
214: }
1.150 raeburn 215: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 216: my %domconfig =
1.6 raeburn 217: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 218: 'quotas','autoenroll','autoupdate','autocreate',
219: 'directorysrch','usercreation','usermodification',
220: 'contacts','defaults','scantron','coursecategories',
221: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 222: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 223: 'requestauthor','selfenrollment','inststatus',
1.421 raeburn 224: 'ltitools','toolsec','ssl','trust','lti','ltisec',
1.447.2.1 raeburn 225: 'privacy','passwords','wafproxy',
1.429 raeburn 226: 'ipaccess','authordefaults'],$dom);
1.320 raeburn 227: my %encconfig =
1.447.2.1 raeburn 228: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','linkprot'],$dom,undef,1);
1.424 raeburn 229: my ($checked_is_home,$is_home);
1.297 raeburn 230: if (ref($domconfig{'ltitools'}) eq 'HASH') {
231: if (ref($encconfig{'ltitools'}) eq 'HASH') {
1.423 raeburn 232: my $home = &Apache::lonnet::domain($dom,'primary');
233: unless (($home eq 'no_host') || ($home eq '')) {
234: my @ids=&Apache::lonnet::current_machine_ids();
235: if (grep(/^\Q$home\E$/,@ids)) {
236: $is_home = 1;
237: }
238: }
1.425 raeburn 239: $checked_is_home = 1;
1.297 raeburn 240: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 241: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
242: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.421 raeburn 243: $domconfig{'ltitools'}{$id}{'key'} = $encconfig{'ltitools'}{$id}{'key'};
1.423 raeburn 244: if (($is_home) && ($phase eq 'process')) {
245: $domconfig{'ltitools'}{$id}{'secret'} = $encconfig{'ltitools'}{$id}{'secret'};
246: }
1.297 raeburn 247: }
248: }
249: }
250: }
1.320 raeburn 251: if (ref($domconfig{'lti'}) eq 'HASH') {
252: if (ref($encconfig{'lti'}) eq 'HASH') {
1.424 raeburn 253: unless ($checked_is_home) {
254: my $home = &Apache::lonnet::domain($dom,'primary');
255: unless (($home eq 'no_host') || ($home eq '')) {
256: my @ids=&Apache::lonnet::current_machine_ids();
257: if (grep(/^\Q$home\E$/,@ids)) {
258: $is_home = 1;
259: }
260: }
261: $checked_is_home = 1;
262: }
1.320 raeburn 263: foreach my $id (keys(%{$domconfig{'lti'}})) {
264: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
265: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
1.424 raeburn 266: $domconfig{'lti'}{$id}{'key'} = $encconfig{'lti'}{$id}{'key'};
267: if (($is_home) && ($phase eq 'process')) {
268: $domconfig{'lti'}{$id}{'secret'} = $encconfig{'lti'}{$id}{'secret'};
1.320 raeburn 269: }
270: }
271: }
272: }
273: }
1.405 raeburn 274: if (ref($domconfig{'ltisec'}) eq 'HASH') {
1.406 raeburn 275: if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
1.405 raeburn 276: if (ref($encconfig{'linkprot'}) eq 'HASH') {
1.406 raeburn 277: foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
278: unless ($id =~ /^\d+$/) {
279: delete($domconfig{'ltisec'}{'linkprot'}{$id});
280: }
281: if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
1.405 raeburn 282: (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
283: foreach my $item ('key','secret') {
1.406 raeburn 284: $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
1.405 raeburn 285: }
286: }
287: }
288: }
289: }
290: }
1.394 raeburn 291: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
292: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373 raeburn 293: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 294: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 295: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.447.2.1 raeburn 296: 'authordefaults','ltitools','selfenrollment',
1.429 raeburn 297: 'usersessions','ssl','trust','lti');
1.171 raeburn 298: my %existing;
299: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
300: %existing = %{$domconfig{'loadbalancing'}};
301: }
302: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 303: push(@prefs_order,'loadbalancing');
304: }
1.30 raeburn 305: my %prefs = (
306: 'rolecolors' =>
307: { text => 'Default color schemes',
1.67 raeburn 308: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 309: header => [{col1 => 'Student Settings',
310: col2 => '',},
311: {col1 => 'Coordinator Settings',
312: col2 => '',},
313: {col1 => 'Author Settings',
314: col2 => '',},
315: {col1 => 'Administrator Settings',
316: col2 => '',}],
1.230 raeburn 317: print => \&print_rolecolors,
318: modify => \&modify_rolecolors,
1.30 raeburn 319: },
1.110 raeburn 320: 'login' =>
1.30 raeburn 321: { text => 'Log-in page options',
1.67 raeburn 322: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 323: header => [{col1 => 'Log-in Page Items',
324: col2 => '',},
325: {col1 => 'Log-in Help',
1.256 raeburn 326: col2 => 'Value'},
327: {col1 => 'Custom HTML in document head',
1.386 raeburn 328: col2 => 'Value'},
329: {col1 => 'SSO',
330: col2 => 'Dual login: SSO and non-SSO options'},
331: ],
1.230 raeburn 332: print => \&print_login,
333: modify => \&modify_login,
1.30 raeburn 334: },
1.43 raeburn 335: 'defaults' =>
1.236 raeburn 336: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 337: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 338: header => [{col1 => 'Setting',
1.236 raeburn 339: col2 => 'Value'},
340: {col1 => 'Institutional user types',
1.409 raeburn 341: col2 => 'Name displayed'},
342: {col1 => 'Mapping for missing usernames via standard log-in',
343: col2 => 'Rules in use'}],
1.230 raeburn 344: print => \&print_defaults,
345: modify => \&modify_defaults,
1.43 raeburn 346: },
1.381 raeburn 347: 'wafproxy' =>
348: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 349: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 350: header => [{col1 => 'Domain(s)',
351: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 352: },
1.381 raeburn 353: {col1 => 'Domain(s)',
354: col2 => 'WAF Configuration',}],
1.373 raeburn 355: print => \&print_wafproxy,
1.381 raeburn 356: modify => \&modify_wafproxy,
1.373 raeburn 357: },
1.354 raeburn 358: 'passwords' =>
359: { text => 'Passwords (Internal authentication)',
360: help => 'Domain_Configuration_Passwords',
361: header => [{col1 => 'Resetting Forgotten Password',
362: col2 => 'Settings'},
363: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
364: col2 => 'Settings'},
365: {col1 => 'Rules for LON-CAPA Passwords',
366: col2 => 'Settings'},
367: {col1 => 'Course Owner Changing Student Passwords',
368: col2 => 'Settings'}],
369: print => \&print_passwords,
370: modify => \&modify_passwords,
371: },
1.30 raeburn 372: 'quotas' =>
1.429 raeburn 373: { text => 'Blogs, personal pages/timezones, portfolio/quotas',
1.67 raeburn 374: help => 'Domain_Configuration_Quotas',
1.77 raeburn 375: header => [{col1 => 'User affiliation',
1.72 raeburn 376: col2 => 'Available tools',
1.435 raeburn 377: col3 => 'Portfolio quota (MB)',}],
1.230 raeburn 378: print => \&print_quotas,
379: modify => \&modify_quotas,
1.30 raeburn 380: },
381: 'autoenroll' =>
382: { text => 'Auto-enrollment settings',
1.67 raeburn 383: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 384: header => [{col1 => 'Configuration setting',
385: col2 => 'Value(s)'}],
1.230 raeburn 386: print => \&print_autoenroll,
387: modify => \&modify_autoenroll,
1.30 raeburn 388: },
389: 'autoupdate' =>
390: { text => 'Auto-update settings',
1.67 raeburn 391: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 392: header => [{col1 => 'Setting',
393: col2 => 'Value',},
1.131 raeburn 394: {col1 => 'Setting',
395: col2 => 'Affiliation'},
1.43 raeburn 396: {col1 => 'User population',
1.227 bisitz 397: col2 => 'Updatable user data'}],
1.230 raeburn 398: print => \&print_autoupdate,
399: modify => \&modify_autoupdate,
1.30 raeburn 400: },
1.125 raeburn 401: 'autocreate' =>
402: { text => 'Auto-course creation settings',
403: help => 'Domain_Configuration_Auto_Creation',
404: header => [{col1 => 'Configuration Setting',
405: col2 => 'Value',}],
1.230 raeburn 406: print => \&print_autocreate,
407: modify => \&modify_autocreate,
1.125 raeburn 408: },
1.30 raeburn 409: 'directorysrch' =>
1.277 raeburn 410: { text => 'Directory searches',
1.67 raeburn 411: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 412: header => [{col1 => 'Institutional Directory Setting',
413: col2 => 'Value',},
414: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 415: col2 => 'Value',}],
1.230 raeburn 416: print => \&print_directorysrch,
417: modify => \&modify_directorysrch,
1.30 raeburn 418: },
419: 'contacts' =>
1.286 raeburn 420: { text => 'E-mail addresses and helpform',
1.67 raeburn 421: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 422: header => [{col1 => 'Default e-mail addresses',
423: col2 => 'Value',},
424: {col1 => 'Recipient(s) for notifications',
425: col2 => 'Value',},
1.340 raeburn 426: {col1 => 'Nightly status check e-mail',
427: col2 => 'Settings',},
1.286 raeburn 428: {col1 => 'Ask helpdesk form settings',
429: col2 => 'Value',},],
1.230 raeburn 430: print => \&print_contacts,
431: modify => \&modify_contacts,
1.30 raeburn 432: },
433: 'usercreation' =>
434: { text => 'User creation',
1.67 raeburn 435: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 436: header => [{col1 => 'Format rule type',
437: col2 => 'Format rules in force'},
1.34 raeburn 438: {col1 => 'User account creation',
439: col2 => 'Usernames which may be created',},
1.30 raeburn 440: {col1 => 'Context',
1.43 raeburn 441: col2 => 'Assignable authentication types'}],
1.230 raeburn 442: print => \&print_usercreation,
443: modify => \&modify_usercreation,
1.30 raeburn 444: },
1.224 raeburn 445: 'selfcreation' =>
446: { text => 'Users self-creating accounts',
447: help => 'Domain_Configuration_Self_Creation',
448: header => [{col1 => 'Self-creation with institutional username',
449: col2 => 'Enabled?'},
450: {col1 => 'Institutional user type (login/SSO self-creation)',
451: col2 => 'Information user can enter'},
1.303 raeburn 452: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 453: col2 => 'Settings'}],
1.230 raeburn 454: print => \&print_selfcreation,
455: modify => \&modify_selfcreation,
1.224 raeburn 456: },
1.69 raeburn 457: 'usermodification' =>
1.33 raeburn 458: { text => 'User modification',
1.67 raeburn 459: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 460: header => [{col1 => 'Target user has role',
1.227 bisitz 461: col2 => 'User information updatable in author context'},
1.33 raeburn 462: {col1 => 'Target user has role',
1.443 raeburn 463: col2 => 'User information updatable by co-author manager'},
464: {col1 => 'Target user has role',
1.227 bisitz 465: col2 => 'User information updatable in course context'}],
1.230 raeburn 466: print => \&print_usermodification,
467: modify => \&modify_usermodification,
1.33 raeburn 468: },
1.69 raeburn 469: 'scantron' =>
1.346 raeburn 470: { text => 'Bubblesheet format',
1.67 raeburn 471: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 472: header => [ {col1 => 'Bubblesheet format file',
473: col2 => ''},
474: {col1 => 'Bubblesheet data upload formats',
475: col2 => 'Settings'}],
1.230 raeburn 476: print => \&print_scantron,
477: modify => \&modify_scantron,
1.46 raeburn 478: },
1.86 raeburn 479: 'requestcourses' =>
480: {text => 'Request creation of courses',
481: help => 'Domain_Configuration_Request_Courses',
482: header => [{col1 => 'User affiliation',
1.102 raeburn 483: col2 => 'Availability/Processing of requests',},
484: {col1 => 'Setting',
1.216 raeburn 485: col2 => 'Value'},
486: {col1 => 'Available textbooks',
1.235 raeburn 487: col2 => ''},
1.242 raeburn 488: {col1 => 'Available templates',
489: col2 => ''},
1.235 raeburn 490: {col1 => 'Validation (not official courses)',
491: col2 => 'Value'},],
1.230 raeburn 492: print => \&print_quotas,
493: modify => \&modify_quotas,
1.86 raeburn 494: },
1.163 raeburn 495: 'requestauthor' =>
1.223 bisitz 496: {text => 'Request Authoring Space',
1.163 raeburn 497: help => 'Domain_Configuration_Request_Author',
498: header => [{col1 => 'User affiliation',
499: col2 => 'Availability/Processing of requests',},
500: {col1 => 'Setting',
501: col2 => 'Value'}],
1.230 raeburn 502: print => \&print_quotas,
503: modify => \&modify_quotas,
1.163 raeburn 504: },
1.69 raeburn 505: 'coursecategories' =>
1.120 raeburn 506: { text => 'Cataloging of courses/communities',
1.67 raeburn 507: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 508: header => [{col1 => 'Catalog type/availability',
509: col2 => '',},
510: {col1 => 'Category settings for standard catalog',
1.57 raeburn 511: col2 => '',},
512: {col1 => 'Categories',
513: col2 => '',
514: }],
1.230 raeburn 515: print => \&print_coursecategories,
516: modify => \&modify_coursecategories,
1.69 raeburn 517: },
518: 'serverstatuses' =>
1.77 raeburn 519: {text => 'Access to server status pages',
1.69 raeburn 520: help => 'Domain_Configuration_Server_Status',
521: header => [{col1 => 'Status Page',
522: col2 => 'Other named users',
523: col3 => 'Specific IPs',
524: }],
1.230 raeburn 525: print => \&print_serverstatuses,
526: modify => \&modify_serverstatuses,
1.69 raeburn 527: },
1.118 jms 528: 'helpsettings' =>
1.282 raeburn 529: {text => 'Support settings',
1.118 jms 530: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 531: header => [{col1 => 'Help Page Settings (logged-in users)',
532: col2 => 'Value'},
533: {col1 => 'Helpdesk Roles',
534: col2 => 'Settings'},],
1.230 raeburn 535: print => \&print_helpsettings,
536: modify => \&modify_helpsettings,
1.118 jms 537: },
1.121 raeburn 538: 'coursedefaults' =>
539: {text => 'Course/Community defaults',
540: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 541: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
542: col2 => 'Value',},
543: {col1 => 'Defaults which can be overridden for each course by a DC',
544: col2 => 'Value',},],
1.230 raeburn 545: print => \&print_coursedefaults,
546: modify => \&modify_coursedefaults,
1.121 raeburn 547: },
1.231 raeburn 548: 'selfenrollment' =>
549: {text => 'Self-enrollment in Course/Community',
550: help => 'Domain_Configuration_Selfenrollment',
551: header => [{col1 => 'Configuration Rights',
552: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
553: {col1 => 'Defaults',
554: col2 => 'Value'},
555: {col1 => 'Self-enrollment validation (optional)',
556: col2 => 'Value'},],
557: print => \&print_selfenrollment,
558: modify => \&modify_selfenrollment,
559: },
1.120 raeburn 560: 'privacy' =>
1.427 raeburn 561: {text => 'Role assignments and user privacy',
1.120 raeburn 562: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 563: header => [{col1 => 'Role assigned in different domain',
564: col2 => 'Approval options'},
565: {col1 => 'Role assigned in different domain to user of type',
566: col2 => 'User information available in that domain'},
567: {col1 => "Role assigned in user's domain",
568: col2 => 'Information viewable by privileged user'},
569: {col1 => "Role assigned in user's domain",
570: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 571: print => \&print_privacy,
572: modify => \&modify_privacy,
1.120 raeburn 573: },
1.141 raeburn 574: 'usersessions' =>
1.145 raeburn 575: {text => 'User session hosting/offloading',
1.137 raeburn 576: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 577: header => [{col1 => 'Domain server',
578: col2 => 'Servers to offload sessions to when busy'},
579: {col1 => 'Hosting of users from other domains',
1.137 raeburn 580: col2 => 'Rules'},
581: {col1 => "Hosting domain's own users elsewhere",
582: col2 => 'Rules'}],
1.230 raeburn 583: print => \&print_usersessions,
584: modify => \&modify_usersessions,
1.137 raeburn 585: },
1.279 raeburn 586: 'loadbalancing' =>
1.185 raeburn 587: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 588: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 589: header => [{col1 => 'Balancers',
1.150 raeburn 590: col2 => 'Default destinations',
1.183 bisitz 591: col3 => 'User affiliation',
1.150 raeburn 592: col4 => 'Overrides'},
593: ],
1.230 raeburn 594: print => \&print_loadbalancing,
595: modify => \&modify_loadbalancing,
1.150 raeburn 596: },
1.425 raeburn 597: 'ltitools' =>
1.267 raeburn 598: {text => 'External Tools (LTI)',
1.296 raeburn 599: help => 'Domain_Configuration_LTI_Tools',
1.421 raeburn 600: header => [{col1 => 'Encryption of shared secrets',
601: col2 => 'Settings'},
602: {col1 => 'Rules for shared secrets',
603: col2 => 'Settings'},
604: {col1 => 'Providers',
605: col2 => 'Settings',}],
1.267 raeburn 606: print => \&print_ltitools,
607: modify => \&modify_ltitools,
608: },
1.279 raeburn 609: 'ssl' =>
1.275 raeburn 610: {text => 'LON-CAPA Network (SSL)',
611: help => 'Domain_Configuration_Network_SSL',
612: header => [{col1 => 'Server',
613: col2 => 'Certificate Status'},
614: {col1 => 'Connections to other servers',
615: col2 => 'Rules'},
1.293 raeburn 616: {col1 => 'Connections from other servers',
617: col2 => 'Rules'},
1.275 raeburn 618: {col1 => "Replicating domain's published content",
619: col2 => 'Rules'}],
620: print => \&print_ssl,
621: modify => \&modify_ssl,
622: },
1.279 raeburn 623: 'trust' =>
624: {text => 'Trust Settings',
625: help => 'Domain_Configuration_Trust',
626: header => [{col1 => "Access to this domain's content by others",
627: col2 => 'Rules'},
628: {col1 => "Access to other domain's content by this domain",
629: col2 => 'Rules'},
630: {col1 => "Enrollment in this domain's courses by others",
631: col2 => 'Rules',},
632: {col1 => "Co-author roles in this domain for others",
633: col2 => 'Rules',},
634: {col1 => "Co-author roles for this domain's users elsewhere",
635: col2 => 'Rules',},
636: {col1 => "Domain roles in this domain assignable to others",
637: col2 => 'Rules'},
638: {col1 => "Course catalog for this domain displayed elsewhere",
639: col2 => 'Rules'},
640: {col1 => "Requests for creation of courses in this domain by others",
641: col2 => 'Rules'},
642: {col1 => "Users in other domains can send messages to this domain",
643: col2 => 'Rules'},],
644: print => \&print_trust,
645: modify => \&modify_trust,
646: },
1.425 raeburn 647: 'lti' =>
1.405 raeburn 648: {text => 'LTI Link Protection and LTI Consumers',
1.320 raeburn 649: help => 'Domain_Configuration_LTI_Provider',
1.405 raeburn 650: header => [{col1 => 'Encryption of shared secrets',
651: col2 => 'Settings'},
1.425 raeburn 652: {col1 => 'Rules for shared secrets',
1.405 raeburn 653: col2 => 'Settings'},
1.434 raeburn 654: {col1 => 'Link Protectors in Courses',
1.436 raeburn 655: col2 => 'Values'},
1.406 raeburn 656: {col1 => 'Link Protectors',
1.405 raeburn 657: col2 => 'Settings'},
658: {col1 => 'Consumers',
659: col2 => 'Settings'},],
1.320 raeburn 660: print => \&print_lti,
661: modify => \&modify_lti,
662: },
1.425 raeburn 663: 'ipaccess' =>
1.394 raeburn 664: {text => 'IP-based access control',
665: help => 'Domain_Configuration_IP_Access',
666: header => [{col1 => 'Setting',
667: col2 => 'Value'},],
668: print => \&print_ipaccess,
669: modify => \&modify_ipaccess,
670: },
1.436 raeburn 671: 'authordefaults' =>
1.429 raeburn 672: {text => 'Authoring Space defaults',
673: help => 'Domain_Configuration_Author_Defaults',
674: header => [{col1 => 'Defaults which can be overridden by Author',
675: col2 => 'Settings',},
676: {col1 => 'Defaults which can be overridden by a Dom. Coord.',
677: col2 => 'Settings',},],
678: print => \&print_authordefaults,
679: modify => \&modify_authordefaults,
680: },
1.3 raeburn 681: );
1.110 raeburn 682: if (keys(%servers) > 1) {
683: $prefs{'login'} = { text => 'Log-in page options',
684: help => 'Domain_Configuration_Login_Page',
685: header => [{col1 => 'Log-in Service',
686: col2 => 'Server Setting',},
687: {col1 => 'Log-in Page Items',
1.405 raeburn 688: col2 => 'Settings'},
1.168 raeburn 689: {col1 => 'Log-in Help',
1.256 raeburn 690: col2 => 'Value'},
691: {col1 => 'Custom HTML in document head',
1.386 raeburn 692: col2 => 'Value'},
693: {col1 => 'SSO',
694: col2 => 'Dual login: SSO and non-SSO options'},
695: ],
1.230 raeburn 696: print => \&print_login,
697: modify => \&modify_login,
1.110 raeburn 698: };
699: }
1.174 foxr 700:
1.6 raeburn 701: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 702: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 703: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 704: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 705: text=>"Settings to display/modify"});
1.9 raeburn 706: my $confname = $dom.'-domainconfig';
1.174 foxr 707:
1.3 raeburn 708: if ($phase eq 'process') {
1.212 raeburn 709: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
710: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 711: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 712: $r->rflush();
1.212 raeburn 713: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 714: }
1.30 raeburn 715: } elsif ($phase eq 'display') {
1.192 raeburn 716: my $js = &recaptcha_js().
1.236 raeburn 717: &toggle_display_js();
1.171 raeburn 718: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 719: my ($othertitle,$usertypes,$types) =
720: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 721: $js .= &lonbalance_targets_js($dom,$types,\%servers,
722: $domconfig{'loadbalancing'}).
1.170 raeburn 723: &new_spares_js().
724: &common_domprefs_js().
725: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 726: }
1.216 raeburn 727: if (grep(/^requestcourses$/,@actions)) {
728: my $javascript_validations;
729: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
730: $js .= <<END;
731: <script type="text/javascript">
732: $javascript_validations
733: </script>
734: $coursebrowserjs
735: END
1.394 raeburn 736: } elsif (grep(/^ipaccess$/,@actions)) {
737: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 738: }
1.305 raeburn 739: if (grep(/^selfcreation$/,@actions)) {
740: $js .= &selfcreate_javascript();
741: }
1.286 raeburn 742: if (grep(/^contacts$/,@actions)) {
743: $js .= &contacts_javascript();
744: }
1.346 raeburn 745: if (grep(/^scantron$/,@actions)) {
746: $js .= &scantron_javascript();
747: }
1.150 raeburn 748: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 749: } else {
1.180 raeburn 750: # check if domconfig user exists for the domain.
751: my $servadm = $r->dir_config('lonAdmEMail');
752: my ($configuserok,$author_ok,$switchserver) =
753: &config_check($dom,$confname,$servadm);
754: unless ($configuserok eq 'ok') {
1.181 raeburn 755: &Apache::lonconfigsettings::print_header($r,$phase,$context);
756: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 757: $confname).
1.181 raeburn 758: '<br />'
759: );
1.180 raeburn 760: if ($switchserver) {
1.181 raeburn 761: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
762: '<br />'.
763: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
764: '<br />'.
765: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
766: '<br />'.
767: &mt('To do that now, use the following link: [_1]',$switchserver)
768: );
769: } else {
770: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
771: '<br />'.
772: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
773: );
1.180 raeburn 774: }
775: $r->print(&Apache::loncommon::end_page());
776: return OK;
777: }
1.21 raeburn 778: if (keys(%domconfig) == 0) {
779: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 780: my @ids=&Apache::lonnet::current_machine_ids();
781: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 782: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 783: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 784: my $custom_img_count = 0;
785: foreach my $img (@loginimages) {
786: if ($designhash{$dom.'.login.'.$img} ne '') {
787: $custom_img_count ++;
788: }
789: }
790: foreach my $role (@roles) {
791: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
792: $custom_img_count ++;
793: }
794: }
795: if ($custom_img_count > 0) {
1.94 raeburn 796: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 797: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 798: $r->print(
799: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
800: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
801: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
802: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
803: if ($switch_server) {
1.30 raeburn 804: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 805: }
1.91 raeburn 806: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 807: return OK;
808: }
809: }
810: }
1.91 raeburn 811: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 812: }
813: return OK;
814: }
815:
816: sub process_changes {
1.205 raeburn 817: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 818: my %domconfig;
819: if (ref($values) eq 'HASH') {
820: %domconfig = %{$values};
821: }
1.3 raeburn 822: my $output;
823: if ($action eq 'login') {
1.205 raeburn 824: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 825: } elsif ($action eq 'rolecolors') {
1.9 raeburn 826: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 827: $lastactref,%domconfig);
1.3 raeburn 828: } elsif ($action eq 'quotas') {
1.216 raeburn 829: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 830: } elsif ($action eq 'autoenroll') {
1.205 raeburn 831: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 832: } elsif ($action eq 'autoupdate') {
833: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 834: } elsif ($action eq 'autocreate') {
835: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 836: } elsif ($action eq 'directorysrch') {
1.295 raeburn 837: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 838: } elsif ($action eq 'usercreation') {
1.28 raeburn 839: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 840: } elsif ($action eq 'selfcreation') {
1.305 raeburn 841: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 842: } elsif ($action eq 'usermodification') {
843: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 844: } elsif ($action eq 'contacts') {
1.205 raeburn 845: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 846: } elsif ($action eq 'defaults') {
1.212 raeburn 847: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 848: } elsif ($action eq 'scantron') {
1.205 raeburn 849: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 850: } elsif ($action eq 'coursecategories') {
1.239 raeburn 851: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 852: } elsif ($action eq 'serverstatuses') {
853: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 854: } elsif ($action eq 'requestcourses') {
1.216 raeburn 855: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 856: } elsif ($action eq 'requestauthor') {
1.216 raeburn 857: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 858: } elsif ($action eq 'helpsettings') {
1.285 raeburn 859: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 860: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 861: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 862: } elsif ($action eq 'selfenrollment') {
863: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 864: } elsif ($action eq 'usersessions') {
1.212 raeburn 865: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 866: } elsif ($action eq 'loadbalancing') {
867: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 868: } elsif ($action eq 'ltitools') {
869: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 870: } elsif ($action eq 'ssl') {
871: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 872: } elsif ($action eq 'trust') {
873: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 874: } elsif ($action eq 'lti') {
875: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 876: } elsif ($action eq 'privacy') {
1.427 raeburn 877: $output = &modify_privacy($dom,$lastactref,%domconfig);
1.354 raeburn 878: } elsif ($action eq 'passwords') {
879: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 880: } elsif ($action eq 'wafproxy') {
881: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 882: } elsif ($action eq 'ipaccess') {
883: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.429 raeburn 884: } elsif ($action eq 'authordefaults') {
885: $output = &modify_authordefaults($dom,$lastactref,%domconfig);
1.3 raeburn 886: }
887: return $output;
888: }
889:
890: sub print_config_box {
1.9 raeburn 891: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 892: my $rowtotal = 0;
1.49 raeburn 893: my $output;
894: if ($action eq 'coursecategories') {
895: $output = &coursecategories_javascript($settings);
1.236 raeburn 896: } elsif ($action eq 'defaults') {
897: $output = &defaults_javascript($settings);
1.354 raeburn 898: } elsif ($action eq 'passwords') {
1.405 raeburn 899: $output = &passwords_javascript($action);
1.282 raeburn 900: } elsif ($action eq 'helpsettings') {
901: my (%privs,%levelscurrent);
902: my %full=();
903: my %levels=(
904: course => {},
905: domain => {},
906: system => {},
907: );
908: my $context = 'domain';
909: my $crstype = 'Course';
910: my $formname = 'display';
911: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
912: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
913: $output =
1.425 raeburn 914: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
1.282 raeburn 915: \@templateroles);
1.334 raeburn 916: } elsif ($action eq 'ltitools') {
1.421 raeburn 917: $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
1.334 raeburn 918: } elsif ($action eq 'lti') {
1.421 raeburn 919: $output .= &passwords_javascript('ltisecrets')."\n".
1.405 raeburn 920: <i_javascript($dom,$settings);
1.381 raeburn 921: } elsif ($action eq 'wafproxy') {
922: $output .= &wafproxy_javascript($dom);
1.385 raeburn 923: } elsif ($action eq 'autoupdate') {
924: $output .= &autoupdate_javascript();
1.399 raeburn 925: } elsif ($action eq 'autoenroll') {
926: $output .= &autoenroll_javascript();
1.386 raeburn 927: } elsif ($action eq 'login') {
928: $output .= &saml_javascript();
1.394 raeburn 929: } elsif ($action eq 'ipaccess') {
930: $output .= &ipaccess_javascript($settings);
1.429 raeburn 931: } elsif ($action eq 'authordefaults') {
932: $output .= &authordefaults_javascript();
1.91 raeburn 933: }
1.236 raeburn 934: $output .=
1.30 raeburn 935: '<table class="LC_nested_outer">
1.3 raeburn 936: <tr>
1.306 raeburn 937: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 938: &mt($item->{text}).' '.
939: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
940: '</tr>';
1.30 raeburn 941: $rowtotal ++;
1.110 raeburn 942: my $numheaders = 1;
943: if (ref($item->{'header'}) eq 'ARRAY') {
944: $numheaders = scalar(@{$item->{'header'}});
945: }
946: if ($numheaders > 1) {
1.64 raeburn 947: my $colspan = '';
1.145 raeburn 948: my $rightcolspan = '';
1.369 raeburn 949: my $leftnobr = '';
1.238 raeburn 950: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 951: ($action eq 'directorysrch') ||
1.386 raeburn 952: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 953: $colspan = ' colspan="2"';
954: }
1.145 raeburn 955: if ($action eq 'usersessions') {
956: $rightcolspan = ' colspan="3"';
957: }
1.369 raeburn 958: if ($action eq 'passwords') {
959: $leftnobr = ' LC_nobreak';
960: }
1.30 raeburn 961: $output .= '
1.3 raeburn 962: <tr>
963: <td>
964: <table class="LC_nested">
965: <tr class="LC_info_row">
1.369 raeburn 966: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 967: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 968: </tr>';
1.69 raeburn 969: $rowtotal ++;
1.230 raeburn 970: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 971: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 972: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 973: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.421 raeburn 974: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') ||
1.429 raeburn 975: ($action eq 'lti') || ($action eq 'ltitools') || ($action eq 'authordefaults')) {
1.230 raeburn 976: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 977: } elsif ($action eq 'passwords') {
978: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 979: } elsif ($action eq 'coursecategories') {
1.230 raeburn 980: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 981: } elsif ($action eq 'scantron') {
982: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 983: } elsif ($action eq 'login') {
1.386 raeburn 984: if ($numheaders == 5) {
1.168 raeburn 985: $colspan = ' colspan="2"';
986: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
987: } else {
988: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
989: }
1.230 raeburn 990: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 991: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 992: } elsif ($action eq 'rolecolors') {
1.30 raeburn 993: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 994: }
1.30 raeburn 995: $output .= '
1.6 raeburn 996: </table>
997: </td>
998: </tr>
999: <tr>
1000: <td>
1001: <table class="LC_nested">
1002: <tr class="LC_info_row">
1.230 raeburn 1003: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 1004: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 1005: </tr>';
1006: $rowtotal ++;
1.230 raeburn 1007: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
1008: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 1009: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 1010: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.421 raeburn 1011: ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti') ||
1.443 raeburn 1012: ($action eq 'ltitools') || ($action eq 'usermodification')) {
1.238 raeburn 1013: if ($action eq 'coursecategories') {
1014: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
1015: $colspan = ' colspan="2"';
1.279 raeburn 1016: } elsif ($action eq 'trust') {
1017: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 1018: } elsif ($action eq 'passwords') {
1019: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.434 raeburn 1020: } elsif ($action eq 'lti') {
1021: $output .= $item->{'print'}->('upper',$dom,$settings,\$rowtotal).'
1022: </table>
1023: </td>
1024: </tr>
1025: <tr>
1026: <td>
1027: <table class="LC_nested">
1028: <tr class="LC_info_row">
1029: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1030: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1031: </tr>'."\n".
1032: $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1.238 raeburn 1033: } else {
1034: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1035: }
1.279 raeburn 1036: if ($action eq 'trust') {
1037: $output .= '
1038: </table>
1039: </td>
1040: </tr>';
1041: my @trusthdrs = qw(2 3 4 5 6 7);
1042: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1043: for (my $i=0; $i<@trusthdrs; $i++) {
1044: $output .= '
1045: <tr>
1046: <td>
1047: <table class="LC_nested">
1048: <tr class="LC_info_row">
1049: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1050: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1051: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1052: </table>
1053: </td>
1054: </tr>';
1055: }
1056: $output .= '
1057: <tr>
1058: <td>
1059: <table class="LC_nested">
1060: <tr class="LC_info_row">
1061: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1062: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1063: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1064: } else {
1.434 raeburn 1065: my $hdridx = 2;
1066: if ($action eq 'lti') {
1067: $hdridx = 3;
1068: }
1.279 raeburn 1069: $output .= '
1.63 raeburn 1070: </table>
1071: </td>
1072: </tr>
1073: <tr>
1074: <td>
1075: <table class="LC_nested">
1076: <tr class="LC_info_row">
1.434 raeburn 1077: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1078: <td class="LC_right_item">'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td>
1.238 raeburn 1079: </tr>'."\n";
1.279 raeburn 1080: if ($action eq 'coursecategories') {
1081: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405 raeburn 1082: } elsif (($action eq 'contacts') || ($action eq 'privacy') ||
1083: ($action eq 'passwords') || ($action eq 'lti')) {
1.354 raeburn 1084: if ($action eq 'passwords') {
1085: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1086: } else {
1087: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1088: }
1.434 raeburn 1089: $hdridx ++;
1.354 raeburn 1090: $output .= '
1.340 raeburn 1091: </tr>
1092: </table>
1093: </td>
1094: </tr>
1095: <tr>
1096: <td>
1097: <table class="LC_nested">
1098: <tr class="LC_info_row">
1.434 raeburn 1099: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1100: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td></tr>'."\n";
1.354 raeburn 1101: if ($action eq 'passwords') {
1102: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1103: } else {
1104: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1105: }
1106: $output .= '
1.340 raeburn 1107: </table>
1108: </td>
1109: </tr>
1110: <tr>';
1.279 raeburn 1111: } else {
1112: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1113: }
1.238 raeburn 1114: }
1.63 raeburn 1115: $rowtotal ++;
1.443 raeburn 1116: } elsif (($action eq 'coursedefaults') || ($action eq 'authordefaults') ||
1.409 raeburn 1117: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1.443 raeburn 1118: ($action eq 'wafproxy')) {
1.230 raeburn 1119: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1120: } elsif ($action eq 'scantron') {
1121: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1122: } elsif ($action eq 'ssl') {
1123: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1124: </table>
1125: </td>
1126: </tr>
1127: <tr>
1128: <td>
1129: <table class="LC_nested">
1130: <tr class="LC_info_row">
1131: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1132: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1133: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1134: </table>
1135: </td>
1136: </tr>
1137: <tr>
1138: <td>
1139: <table class="LC_nested">
1140: <tr class="LC_info_row">
1141: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1142: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1143: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1144: } elsif ($action eq 'login') {
1.386 raeburn 1145: if ($numheaders == 5) {
1.168 raeburn 1146: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1147: </table>
1148: </td>
1149: </tr>
1150: <tr>
1151: <td>
1152: <table class="LC_nested">
1153: <tr class="LC_info_row">
1154: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1155: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1156: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1157: $rowtotal ++;
1158: } else {
1159: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1160: }
1.256 raeburn 1161: $output .= '
1162: </table>
1163: </td>
1164: </tr>
1165: <tr>
1166: <td>
1167: <table class="LC_nested">
1168: <tr class="LC_info_row">';
1.386 raeburn 1169: if ($numheaders == 5) {
1.256 raeburn 1170: $output .= '
1171: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1172: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1173: </tr>';
1174: } else {
1175: $output .= '
1176: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1177: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1178: </tr>';
1179: }
1180: $rowtotal ++;
1.386 raeburn 1181: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1182: </table>
1183: </td>
1184: </tr>
1185: <tr>
1186: <td>
1187: <table class="LC_nested">
1188: <tr class="LC_info_row">';
1189: if ($numheaders == 5) {
1190: $output .= '
1191: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1192: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1193: </tr>';
1194: } else {
1195: $output .= '
1196: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1197: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1198: </tr>';
1199: }
1200: $rowtotal ++;
1201: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1202: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1203: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1204: $rowtotal ++;
1205: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1206: </table>
1207: </td>
1208: </tr>
1209: <tr>
1210: <td>
1211: <table class="LC_nested">
1212: <tr class="LC_info_row">
1213: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1214: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1215: &textbookcourses_javascript($settings).
1216: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1217: </table>
1218: </td>
1219: </tr>
1220: <tr>
1221: <td>
1222: <table class="LC_nested">
1223: <tr class="LC_info_row">
1224: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1225: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1226: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1227: </table>
1228: </td>
1229: </tr>
1230: <tr>
1231: <td>
1232: <table class="LC_nested">
1233: <tr class="LC_info_row">
1.306 raeburn 1234: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1235: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1236: </tr>'.
1237: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1238: } elsif ($action eq 'requestauthor') {
1239: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1240: $rowtotal ++;
1.122 jms 1241: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1242: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1243: </table>
1244: </td>
1245: </tr>
1246: <tr>
1247: <td>
1248: <table class="LC_nested">
1249: <tr class="LC_info_row">
1.306 raeburn 1250: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1251: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1252: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1253: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1254: </tr>'.
1.30 raeburn 1255: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1256: </table>
1257: </td>
1258: </tr>
1259: <tr>
1260: <td>
1261: <table class="LC_nested">
1262: <tr class="LC_info_row">
1.59 bisitz 1263: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1264: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1265: </tr>'.
1.30 raeburn 1266: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1267: $rowtotal += 2;
1.6 raeburn 1268: }
1.3 raeburn 1269: } else {
1.30 raeburn 1270: $output .= '
1.3 raeburn 1271: <tr>
1272: <td>
1273: <table class="LC_nested">
1.30 raeburn 1274: <tr class="LC_info_row">';
1.277 raeburn 1275: if ($action eq 'login') {
1.30 raeburn 1276: $output .= '
1.59 bisitz 1277: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1278: } elsif ($action eq 'serverstatuses') {
1279: $output .= '
1.306 raeburn 1280: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1281: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1282:
1.6 raeburn 1283: } else {
1.30 raeburn 1284: $output .= '
1.306 raeburn 1285: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1286: }
1.72 raeburn 1287: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1288: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1289: &mt($item->{'header'}->[0]->{'col2'});
1290: if ($action eq 'serverstatuses') {
1291: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1292: }
1.69 raeburn 1293: } else {
1.306 raeburn 1294: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1295: &mt($item->{'header'}->[0]->{'col2'});
1296: }
1297: $output .= '</td>';
1298: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1299: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1300: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1301: &mt($item->{'header'}->[0]->{'col3'});
1302: } else {
1.306 raeburn 1303: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1304: &mt($item->{'header'}->[0]->{'col3'});
1305: }
1.69 raeburn 1306: if ($action eq 'serverstatuses') {
1307: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1308: }
1309: $output .= '</td>';
1.6 raeburn 1310: }
1.150 raeburn 1311: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1312: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1313: &mt($item->{'header'}->[0]->{'col4'});
1314: }
1.69 raeburn 1315: $output .= '</tr>';
1.48 raeburn 1316: $rowtotal ++;
1.168 raeburn 1317: if ($action eq 'quotas') {
1.86 raeburn 1318: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1319: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1320: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.447.2.1 raeburn 1321: ($action eq 'ipaccess')) {
1.230 raeburn 1322: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1323: }
1.3 raeburn 1324: }
1.30 raeburn 1325: $output .= '
1.3 raeburn 1326: </table>
1327: </td>
1328: </tr>
1.30 raeburn 1329: </table><br />';
1330: return ($output,$rowtotal);
1.1 raeburn 1331: }
1332:
1.3 raeburn 1333: sub print_login {
1.168 raeburn 1334: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1335: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1336: my %choices = &login_choices();
1.386 raeburn 1337: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1338: %lt = &login_file_options();
1339: $switchserver = &check_switchserver($dom,$confname);
1340: }
1.168 raeburn 1341: if ($caller eq 'service') {
1.149 raeburn 1342: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1343: my $choice = $choices{'disallowlogin'};
1344: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1345: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1346: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1347: '<th>'.$choices{'server'}.'</th>'.
1348: '<th>'.$choices{'serverpath'}.'</th>'.
1349: '<th>'.$choices{'custompath'}.'</th>'.
1350: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1351: my %disallowed;
1352: if (ref($settings) eq 'HASH') {
1353: if (ref($settings->{'loginvia'}) eq 'HASH') {
1354: %disallowed = %{$settings->{'loginvia'}};
1355: }
1356: }
1357: foreach my $lonhost (sort(keys(%servers))) {
1358: my $direct = 'selected="selected"';
1.128 raeburn 1359: if (ref($disallowed{$lonhost}) eq 'HASH') {
1360: if ($disallowed{$lonhost}{'server'} ne '') {
1361: $direct = '';
1362: }
1.110 raeburn 1363: }
1.115 raeburn 1364: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1365: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1366: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1367: '</option>';
1.184 raeburn 1368: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1369: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1370: my $selected = '';
1.128 raeburn 1371: if (ref($disallowed{$lonhost}) eq 'HASH') {
1372: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1373: $selected = 'selected="selected"';
1374: }
1.110 raeburn 1375: }
1376: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1377: $servers{$hostid}.'</option>';
1378: }
1.128 raeburn 1379: $datatable .= '</select></td>'.
1380: '<td><select name="'.$lonhost.'_serverpath">';
1381: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1382: my $pathname = $path;
1383: if ($path eq 'custom') {
1384: $pathname = &mt('Custom Path').' ->';
1385: }
1386: my $selected = '';
1387: if (ref($disallowed{$lonhost}) eq 'HASH') {
1388: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1389: $selected = 'selected="selected"';
1390: }
1391: } elsif ($path eq '') {
1392: $selected = 'selected="selected"';
1393: }
1394: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1395: }
1396: $datatable .= '</select></td>';
1397: my ($custom,$exempt);
1398: if (ref($disallowed{$lonhost}) eq 'HASH') {
1399: $custom = $disallowed{$lonhost}{'custompath'};
1400: $exempt = $disallowed{$lonhost}{'exempt'};
1401: }
1402: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1403: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1404: '</tr>';
1.110 raeburn 1405: }
1406: $datatable .= '</table></td></tr>';
1407: return $datatable;
1.168 raeburn 1408: } elsif ($caller eq 'page') {
1409: my %defaultchecked = (
1410: 'coursecatalog' => 'on',
1.188 raeburn 1411: 'helpdesk' => 'on',
1.168 raeburn 1412: 'adminmail' => 'off',
1413: 'newuser' => 'off',
1414: );
1.188 raeburn 1415: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1416: my (%checkedon,%checkedoff);
1.42 raeburn 1417: foreach my $item (@toggles) {
1.168 raeburn 1418: if ($defaultchecked{$item} eq 'on') {
1419: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1420: $checkedoff{$item} = ' ';
1.168 raeburn 1421: } elsif ($defaultchecked{$item} eq 'off') {
1422: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1423: $checkedon{$item} = ' ';
1424: }
1.1 raeburn 1425: }
1.168 raeburn 1426: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1427: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1428: my @logintext = ('textcol','bgcol');
1429: my @bgs = ('pgbg','mainbg','sidebg');
1430: my @links = ('link','alink','vlink');
1431: my %designhash = &Apache::loncommon::get_domainconf($dom);
1432: my %defaultdesign = %Apache::loncommon::defaultdesign;
1433: my (%is_custom,%designs);
1434: my %defaults = (
1435: font => $defaultdesign{'login.font'},
1436: );
1.6 raeburn 1437: foreach my $item (@images) {
1.168 raeburn 1438: $defaults{$item} = $defaultdesign{'login.'.$item};
1439: $defaults{'showlogo'}{$item} = 1;
1440: }
1441: foreach my $item (@bgs) {
1442: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1443: }
1.41 raeburn 1444: foreach my $item (@logintext) {
1.168 raeburn 1445: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1446: }
1.168 raeburn 1447: foreach my $item (@links) {
1448: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1449: }
1.168 raeburn 1450: if (ref($settings) eq 'HASH') {
1451: foreach my $item (@toggles) {
1452: if ($settings->{$item} eq '1') {
1453: $checkedon{$item} = ' checked="checked" ';
1454: $checkedoff{$item} = ' ';
1455: } elsif ($settings->{$item} eq '0') {
1456: $checkedoff{$item} = ' checked="checked" ';
1457: $checkedon{$item} = ' ';
1458: }
1459: }
1460: foreach my $item (@images) {
1461: if (defined($settings->{$item})) {
1462: $designs{$item} = $settings->{$item};
1463: $is_custom{$item} = 1;
1464: }
1465: if (defined($settings->{'showlogo'}{$item})) {
1466: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1467: }
1468: }
1.402 raeburn 1469: foreach my $item (@alttext) {
1470: if (ref($settings->{'alttext'}) eq 'HASH') {
1471: if ($settings->{'alttext'}->{$item} ne '') {
1472: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1473: }
1474: }
1475: }
1.168 raeburn 1476: foreach my $item (@logintext) {
1477: if ($settings->{$item} ne '') {
1478: $designs{'logintext'}{$item} = $settings->{$item};
1479: $is_custom{$item} = 1;
1480: }
1481: }
1482: if ($settings->{'font'} ne '') {
1483: $designs{'font'} = $settings->{'font'};
1484: $is_custom{'font'} = 1;
1485: }
1486: foreach my $item (@bgs) {
1487: if ($settings->{$item} ne '') {
1488: $designs{'bgs'}{$item} = $settings->{$item};
1489: $is_custom{$item} = 1;
1490: }
1491: }
1492: foreach my $item (@links) {
1493: if ($settings->{$item} ne '') {
1494: $designs{'links'}{$item} = $settings->{$item};
1495: $is_custom{$item} = 1;
1496: }
1497: }
1498: } else {
1499: if ($designhash{$dom.'.login.font'} ne '') {
1500: $designs{'font'} = $designhash{$dom.'.login.font'};
1501: $is_custom{'font'} = 1;
1502: }
1503: foreach my $item (@images) {
1504: if ($designhash{$dom.'.login.'.$item} ne '') {
1505: $designs{$item} = $designhash{$dom.'.login.'.$item};
1506: $is_custom{$item} = 1;
1507: }
1508: }
1509: foreach my $item (@bgs) {
1510: if ($designhash{$dom.'.login.'.$item} ne '') {
1511: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1512: $is_custom{$item} = 1;
1513: }
1.6 raeburn 1514: }
1.168 raeburn 1515: foreach my $item (@links) {
1516: if ($designhash{$dom.'.login.'.$item} ne '') {
1517: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1518: $is_custom{$item} = 1;
1519: }
1.6 raeburn 1520: }
1521: }
1.168 raeburn 1522: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1523: logo => 'Institution Logo',
1524: domlogo => 'Domain Logo',
1525: login => 'Login box');
1526: my $itemcount = 1;
1527: foreach my $item (@toggles) {
1528: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1529: $datatable .=
1530: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1531: '</td><td>'.
1532: '<span class="LC_nobreak"><label><input type="radio" name="'.
1533: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1534: '</label> <label><input type="radio" name="'.$item.'"'.
1535: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1536: '</tr>';
1537: $itemcount ++;
1.6 raeburn 1538: }
1.168 raeburn 1539: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1540: $datatable .= '</tr></table></td></tr>';
1541: } elsif ($caller eq 'help') {
1.386 raeburn 1542: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1543: my $itemcount = 1;
1544: $defaulturl = '/adm/loginproblems.html';
1545: $defaulttype = 'default';
1546: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1547: my @currlangs;
1548: if (ref($settings) eq 'HASH') {
1549: if (ref($settings->{'helpurl'}) eq 'HASH') {
1550: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1551: next if ($settings->{'helpurl'}{$key} eq '');
1552: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1553: $type{$key} = 'custom';
1554: unless ($key eq 'nolang') {
1555: push(@currlangs,$key);
1556: }
1557: }
1558: } elsif ($settings->{'helpurl'} ne '') {
1559: $type{'nolang'} = 'custom';
1560: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1561: }
1562: }
1.168 raeburn 1563: foreach my $lang ('nolang',sort(@currlangs)) {
1564: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1565: $datatable .= '<tr'.$css_class.'>';
1566: if ($url{$lang} eq '') {
1567: $url{$lang} = $defaulturl;
1568: }
1569: if ($type{$lang} eq '') {
1570: $type{$lang} = $defaulttype;
1571: }
1572: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1573: if ($lang eq 'nolang') {
1574: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1575: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1576: } else {
1577: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1578: $langchoices{$lang},
1579: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1580: }
1581: $datatable .= '</span></td>'."\n".
1582: '<td class="LC_left_item">';
1583: if ($type{$lang} eq 'custom') {
1584: $datatable .= '<span class="LC_nobreak"><label>'.
1585: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1586: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1587: } else {
1588: $datatable .= $lt{'upl'};
1589: }
1590: $datatable .='<br />';
1591: if ($switchserver) {
1592: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1593: } else {
1594: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1595: }
1.168 raeburn 1596: $datatable .= '</td></tr>';
1597: $itemcount ++;
1.6 raeburn 1598: }
1.168 raeburn 1599: my @addlangs;
1600: foreach my $lang (sort(keys(%langchoices))) {
1601: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1602: push(@addlangs,$lang);
1603: }
1604: if (@addlangs > 0) {
1605: my %toadd;
1606: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1607: $toadd{''} = &mt('Select');
1608: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1609: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1610: &mt('Add log-in help page for a specific language:').' '.
1611: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1612: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1613: if ($switchserver) {
1614: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1615: } else {
1616: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1617: }
1.168 raeburn 1618: $datatable .= '</td></tr>';
1.169 raeburn 1619: $itemcount ++;
1.6 raeburn 1620: }
1.169 raeburn 1621: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1622: } elsif ($caller eq 'headtag') {
1623: my %domservers = &Apache::lonnet::get_servers($dom);
1624: my $choice = $choices{'headtag'};
1625: $css_class = ' class="LC_odd_row"';
1626: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1627: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1628: '<th>'.$choices{'current'}.'</th>'.
1629: '<th>'.$choices{'action'}.'</th>'.
1630: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1631: my (%currurls,%currexempt);
1632: if (ref($settings) eq 'HASH') {
1633: if (ref($settings->{'headtag'}) eq 'HASH') {
1634: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1635: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1636: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1637: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1638: }
1639: }
1640: }
1641: }
1642: foreach my $lonhost (sort(keys(%domservers))) {
1643: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1644: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1645: if ($currurls{$lonhost}) {
1646: $datatable .= '<td class="LC_right_item"><a href="'.
1647: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1648: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1649: '">'.$lt{'curr'}.'</a></td>'.
1650: '<td><span class="LC_nobreak"><label>'.
1651: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1652: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1653: } else {
1654: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1655: }
1656: $datatable .='<br />';
1657: if ($switchserver) {
1658: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1659: } else {
1660: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1661: }
1.330 raeburn 1662: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1663: }
1664: $datatable .= '</table></td></tr>';
1.386 raeburn 1665: } elsif ($caller eq 'saml') {
1666: my %domservers = &Apache::lonnet::get_servers($dom);
1667: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1668: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1669: '<th>'.$choices{'samllanding'}.'</th>'.
1670: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1671: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1672: foreach my $lonhost (keys(%domservers)) {
1673: $samlurl{$lonhost} = '/adm/sso';
1674: $styleon{$lonhost} = 'display:none';
1675: $styleoff{$lonhost} = '';
1676: }
1.411 raeburn 1677: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1678: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1679: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1680: $saml{$lonhost} = 1;
1681: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1682: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1683: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1684: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1685: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1686: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1687: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1688: $styleon{$lonhost} = '';
1689: $styleoff{$lonhost} = 'display:none';
1690: } else {
1691: $styleon{$lonhost} = 'display:none';
1692: $styleoff{$lonhost} = '';
1693: }
1694: }
1695: }
1696: my $itemcount = 1;
1697: foreach my $lonhost (sort(keys(%domservers))) {
1698: my $samlon = ' ';
1699: my $samloff = ' checked="checked" ';
1700: if ($saml{$lonhost}) {
1701: $samlon = $samloff;
1702: $samloff = ' ';
1703: }
1.412 raeburn 1704: my $samlwinon = '';
1705: my $samlwinoff = ' checked="checked"';
1706: if ($samlwindow{$lonhost}) {
1707: $samlwinon = $samlwinoff;
1708: $samlwinoff = '';
1709: }
1.386 raeburn 1710: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1711: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1712: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1713: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1714: &mt('No').'</label>'.(' 'x2).
1715: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1716: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1717: &mt('Yes').'</label></span></td>'.
1718: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1719: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1720: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1721: '<th>'.&mt('Alt Text').'</th></tr>'.
1722: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1723: $samltext{$lonhost}.'" /></td><td>';
1724: if ($samlimg{$lonhost}) {
1725: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1726: '<span class="LC_nobreak"><label>'.
1727: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1728: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1729: } else {
1730: $datatable .= $lt{'upl'};
1731: }
1732: $datatable .='<br />';
1733: if ($switchserver) {
1734: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1735: } else {
1736: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1737: }
1738: $datatable .= '</td>'.
1.412 raeburn 1739: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1740: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1741: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1742: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1743: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1744: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1745: '<tr'.$css_class.'>'.
1746: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1747: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1748: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1749: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1750: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1751: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1752: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1753: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1754: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1755: '</table></td>'.
1756: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1757: $itemcount ++;
1758: }
1759: $datatable .= '</table></td></tr>';
1.1 raeburn 1760: }
1.6 raeburn 1761: return $datatable;
1762: }
1763:
1764: sub login_choices {
1765: my %choices =
1766: &Apache::lonlocal::texthash (
1.116 bisitz 1767: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1768: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1769: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1770: disallowlogin => "Login page requests redirected",
1771: hostid => "Server",
1.128 raeburn 1772: server => "Redirect to:",
1773: serverpath => "Path",
1774: custompath => "Custom",
1775: exempt => "Exempt IP(s)",
1.110 raeburn 1776: directlogin => "No redirect",
1777: newuser => "Link to create a user account",
1778: img => "Header",
1779: logo => "Main Logo",
1780: domlogo => "Domain Logo",
1781: login => "Log-in Header",
1782: textcol => "Text color",
1783: bgcol => "Box color",
1784: bgs => "Background colors",
1785: links => "Link colors",
1786: font => "Font color",
1787: pgbg => "Header",
1788: mainbg => "Page",
1789: sidebg => "Login box",
1790: link => "Link",
1791: alink => "Active link",
1792: vlink => "Visited link",
1.256 raeburn 1793: headtag => "Custom markup",
1794: action => "Action",
1795: current => "Current",
1.386 raeburn 1796: samllanding => "Dual login?",
1797: samloptions => "Options",
1.402 raeburn 1798: alttext => "Alt text",
1.6 raeburn 1799: );
1800: return %choices;
1801: }
1802:
1.386 raeburn 1803: sub login_file_options {
1804: return &Apache::lonlocal::texthash(
1805: del => 'Delete?',
1806: rep => 'Replace:',
1807: upl => 'Upload:',
1808: curr => 'View contents',
1809: default => 'Default',
1810: custom => 'Custom',
1811: none => 'None',
1812: );
1813: }
1814:
1.394 raeburn 1815: sub print_ipaccess {
1816: my ($dom,$settings,$rowtotal) = @_;
1817: my $css_class;
1818: my $itemcount = 0;
1819: my $datatable;
1820: my %ordered;
1821: if (ref($settings) eq 'HASH') {
1822: foreach my $item (keys(%{$settings})) {
1823: if (ref($settings->{$item}) eq 'HASH') {
1824: my $num = $settings->{$item}{'order'};
1825: if ($num eq '') {
1826: $num = scalar(keys(%{$settings}));
1827: }
1828: $ordered{$num} = $item;
1829: }
1830: }
1831: }
1832: my $maxnum = scalar(keys(%ordered));
1833: if (keys(%ordered)) {
1834: my @items = sort { $a <=> $b } keys(%ordered);
1835: for (my $i=0; $i<@items; $i++) {
1836: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1837: my $item = $ordered{$items[$i]};
1838: my ($name,$ipranges,%commblocks,%courses);
1839: if (ref($settings->{$item}) eq 'HASH') {
1840: $name = $settings->{$item}->{'name'};
1841: $ipranges = $settings->{$item}->{'ip'};
1842: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1843: %commblocks = %{$settings->{$item}->{'commblocks'}};
1844: }
1845: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1846: %courses = %{$settings->{$item}->{'courses'}};
1847: }
1848: }
1849: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1850: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1851: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1852: for (my $k=0; $k<=$maxnum; $k++) {
1853: my $vpos = $k+1;
1854: my $selstr;
1855: if ($k == $i) {
1856: $selstr = ' selected="selected" ';
1857: }
1858: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1859: }
1860: $datatable .= '</select>'.(' 'x2).
1861: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1862: &mt('Delete?').'</label></span></td>'.
1863: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1864: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1865: '</td></tr>';
1866: $itemcount ++;
1867: }
1868: }
1869: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1870: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1871: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1872: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1873: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1874: for (my $k=0; $k<$maxnum+1; $k++) {
1875: my $vpos = $k+1;
1876: my $selstr;
1877: if ($k == $maxnum) {
1878: $selstr = ' selected="selected" ';
1879: }
1880: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1881: }
1882: $datatable .= '</select> '."\n".
1883: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1884: '<td colspan="2">'.
1885: &ipaccess_options('add',$itemcount,$dom).
1886: '</td>'."\n".
1887: '</tr>'."\n";
1888: $$rowtotal ++;
1889: return $datatable;
1890: }
1891:
1892: sub ipaccess_options {
1893: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1894: my (%currblocks,%currcourses,$output);
1895: if (ref($blocksref) eq 'HASH') {
1896: %currblocks = %{$blocksref};
1897: }
1898: if (ref($coursesref) eq 'HASH') {
1899: %currcourses = %{$coursesref};
1900: }
1901: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1902: '<span class="LC_nobreak">'.&mt('Name').': '.
1903: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1904: '</span></fieldset>'.
1905: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1906: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1907: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1908: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1909: $ipranges.'</textarea></fieldset>'.
1910: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1911: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1912: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1913: '<table>';
1914: foreach my $cid (sort(keys(%currcourses))) {
1915: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1916: $output .= '<tr><td><span class="LC_nobreak">'.
1917: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1918: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1919: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1920: }
1921: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1922: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1923: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1924: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1925: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1926: '</span></td></tr></table>'."\n".
1927: '</fieldset>';
1928: return $output;
1929: }
1930:
1931: sub blocker_checkboxes {
1932: my ($num,$blocks) = @_;
1933: my ($typeorder,$types) = &commblocktype_text();
1934: my $numinrow = 6;
1935: my $output = '<table>';
1936: for (my $i=0; $i<@{$typeorder}; $i++) {
1937: my $block = $typeorder->[$i];
1938: my $blockstatus;
1939: if (ref($blocks) eq 'HASH') {
1940: if ($blocks->{$block} eq 'on') {
1941: $blockstatus = 'checked="checked"';
1942: }
1943: }
1944: my $rem = $i%($numinrow);
1945: if ($rem == 0) {
1946: if ($i > 0) {
1947: $output .= '</tr>';
1948: }
1949: $output .= '<tr>';
1950: }
1951: if ($i == scalar(@{$typeorder})-1) {
1952: my $colsleft = $numinrow-$rem;
1953: if ($colsleft > 1) {
1954: $output .= '<td colspan="'.$colsleft.'">';
1955: } else {
1956: $output .= '<td>';
1957: }
1958: } else {
1959: $output .= '<td>';
1960: }
1961: my $item = 'ipaccess_block_'.$num;
1962: if ($blockstatus) {
1963: $blockstatus = ' '.$blockstatus;
1964: }
1965: $output .= '<span class="LC_nobreak"><label>'."\n".
1966: '<input type="checkbox" name="'.$item.'"'.
1967: $blockstatus.' value="'.$block.'"'.' />'.
1968: $types->{$block}.'</label></span>'."\n".
1969: '<br /></td>';
1970: }
1971: $output .= '</tr></table>';
1972: return $output;
1973: }
1974:
1975: sub commblocktype_text {
1976: my %types = &Apache::lonlocal::texthash(
1977: 'com' => 'Messaging',
1978: 'chat' => 'Chat Room',
1979: 'boards' => 'Discussion',
1980: 'port' => 'Portfolio',
1981: 'groups' => 'Groups',
1982: 'blogs' => 'Blogs',
1983: 'about' => 'User Information',
1984: 'printout' => 'Printouts',
1985: 'passwd' => 'Change Password',
1986: 'grades' => 'Gradebook',
1.397 raeburn 1987: 'search' => 'Course search',
1.447 raeburn 1988: 'index' => 'Course content index',
1.397 raeburn 1989: 'wishlist' => 'Stored links',
1990: 'annotate' => 'Annotations',
1.394 raeburn 1991: );
1.447 raeburn 1992: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','index','annotate','passwd'];
1.394 raeburn 1993: return ($typeorder,\%types);
1994: }
1995:
1.6 raeburn 1996: sub print_rolecolors {
1.30 raeburn 1997: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1998: my %choices = &color_font_choices();
1999: my @bgs = ('pgbg','tabbg','sidebg');
2000: my @links = ('link','alink','vlink');
1.445 raeburn 2001: my @images = ();
1.6 raeburn 2002: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 2003: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 2004: my %defaultdesign = %Apache::loncommon::defaultdesign;
2005: my (%is_custom,%designs);
1.200 raeburn 2006: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 2007: if (ref($settings) eq 'HASH') {
2008: if (ref($settings->{$role}) eq 'HASH') {
2009: if ($settings->{$role}->{'font'} ne '') {
2010: $designs{'font'} = $settings->{$role}->{'font'};
2011: $is_custom{'font'} = 1;
2012: }
1.97 tempelho 2013: if ($settings->{$role}->{'fontmenu'} ne '') {
2014: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
2015: $is_custom{'fontmenu'} = 1;
2016: }
1.6 raeburn 2017: foreach my $item (@bgs) {
2018: if ($settings->{$role}->{$item} ne '') {
2019: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
2020: $is_custom{$item} = 1;
2021: }
2022: }
2023: foreach my $item (@links) {
2024: if ($settings->{$role}->{$item} ne '') {
2025: $designs{'links'}{$item} = $settings->{$role}->{$item};
2026: $is_custom{$item} = 1;
2027: }
2028: }
2029: }
2030: } else {
1.97 tempelho 2031: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2032: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2033: $is_custom{'fontmenu'} = 1;
2034: }
1.6 raeburn 2035: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2036: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2037: $is_custom{'font'} = 1;
2038: }
2039: foreach my $item (@bgs) {
2040: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2041: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2042: $is_custom{$item} = 1;
2043:
2044: }
2045: }
2046: foreach my $item (@links) {
2047: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2048: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2049: $is_custom{$item} = 1;
2050: }
2051: }
2052: }
2053: my $itemcount = 1;
1.30 raeburn 2054: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2055: $datatable .= '</tr></table></td></tr>';
2056: return $datatable;
2057: }
2058:
1.200 raeburn 2059: sub role_defaults {
2060: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2061: my %defaults;
2062: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2063: return %defaults;
2064: }
2065: my %defaultdesign = %Apache::loncommon::defaultdesign;
2066: if ($role eq 'login') {
2067: %defaults = (
2068: font => $defaultdesign{$role.'.font'},
2069: );
2070: if (ref($logintext) eq 'ARRAY') {
2071: foreach my $item (@{$logintext}) {
2072: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2073: }
2074: }
2075: foreach my $item (@{$images}) {
2076: $defaults{'showlogo'}{$item} = 1;
2077: }
2078: } else {
2079: %defaults = (
2080: font => $defaultdesign{$role.'.font'},
2081: fontmenu => $defaultdesign{$role.'.fontmenu'},
2082: );
2083: }
2084: foreach my $item (@{$bgs}) {
2085: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2086: }
2087: foreach my $item (@{$links}) {
2088: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2089: }
2090: foreach my $item (@{$images}) {
2091: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2092: }
2093: return %defaults;
2094: }
2095:
1.6 raeburn 2096: sub display_color_options {
1.9 raeburn 2097: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2098: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2099: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2100: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2101: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2102: '<td>'.$choices->{'font'}.'</td>';
2103: if (!$is_custom->{'font'}) {
1.329 raeburn 2104: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2105: } else {
2106: $datatable .= '<td> </td>';
2107: }
1.174 foxr 2108: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2109:
1.8 raeburn 2110: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2111: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2112: ' value="'.$current_color.'" /> '.
1.329 raeburn 2113: ' </span></td></tr>';
1.107 raeburn 2114: unless ($role eq 'login') {
2115: $datatable .= '<tr'.$css_class.'>'.
2116: '<td>'.$choices->{'fontmenu'}.'</td>';
2117: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2118: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2119: } else {
2120: $datatable .= '<td> </td>';
2121: }
1.202 raeburn 2122: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2123: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2124: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2125: '<input class="colorchooser" type="text" size="10" name="'
2126: .$role.'_fontmenu"'.
2127: ' value="'.$current_color.'" /> '.
1.329 raeburn 2128: ' </span></td></tr>';
1.97 tempelho 2129: }
1.9 raeburn 2130: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2131: foreach my $img (@{$images}) {
1.18 albertel 2132: $itemcount ++;
1.6 raeburn 2133: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2134: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2135: '<td>'.$choices->{$img};
1.402 raeburn 2136: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2137: if ($role eq 'login') {
2138: if ($img eq 'login') {
2139: $login_hdr_pick =
1.135 bisitz 2140: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2141: $logincolors =
2142: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2143: $designs,$defaults);
1.402 raeburn 2144: } else {
2145: if ($img ne 'domlogo') {
2146: $datatable.= &logo_display_options($img,$defaults,$designs);
2147: }
2148: if (ref($designs->{'alttext'}) eq 'HASH') {
2149: $alttext = $designs->{'alttext'}{$img};
2150: }
1.70 raeburn 2151: }
2152: }
2153: $datatable .= '</td>';
1.6 raeburn 2154: if ($designs->{$img} ne '') {
2155: $imgfile = $designs->{$img};
1.18 albertel 2156: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2157: } else {
2158: $imgfile = $defaults->{$img};
2159: }
2160: if ($imgfile) {
1.9 raeburn 2161: my ($showfile,$fullsize);
2162: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2163: my $urldir = $1;
2164: my $filename = $2;
2165: my @info = &Apache::lonnet::stat_file($designs->{$img});
2166: if (@info) {
2167: my $thumbfile = 'tn-'.$filename;
2168: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2169: if (@thumb) {
2170: $showfile = $urldir.'/'.$thumbfile;
2171: } else {
2172: $showfile = $imgfile;
2173: }
2174: } else {
2175: $showfile = '';
2176: }
2177: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2178: $showfile = $imgfile;
1.6 raeburn 2179: my $imgdir = $1;
2180: my $filename = $2;
1.159 raeburn 2181: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2182: $showfile = "/$imgdir/tn-".$filename;
2183: } else {
1.159 raeburn 2184: my $input = $londocroot.$imgfile;
2185: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2186: if (!-e $output) {
1.9 raeburn 2187: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2188: my ($fullwidth,$fullheight) = &check_dimensions($input);
2189: if ($fullwidth ne '' && $fullheight ne '') {
2190: if ($fullwidth > $width && $fullheight > $height) {
2191: my $size = $width.'x'.$height;
1.316 raeburn 2192: my @args = ('convert','-sample',$size,$input,$output);
2193: system({$args[0]} @args);
1.159 raeburn 2194: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2195: }
2196: }
1.6 raeburn 2197: }
2198: }
1.16 raeburn 2199: }
1.6 raeburn 2200: if ($showfile) {
1.40 raeburn 2201: if ($showfile =~ m{^/(adm|res)/}) {
2202: if ($showfile =~ m{^/res/}) {
2203: my $local_showfile =
2204: &Apache::lonnet::filelocation('',$showfile);
2205: &Apache::lonnet::repcopy($local_showfile);
2206: }
2207: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2208: }
2209: if ($imgfile) {
2210: if ($imgfile =~ m{^/(adm|res)/}) {
2211: if ($imgfile =~ m{^/res/}) {
2212: my $local_imgfile =
2213: &Apache::lonnet::filelocation('',$imgfile);
2214: &Apache::lonnet::repcopy($local_imgfile);
2215: }
2216: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2217: } else {
2218: $fullsize = $imgfile;
2219: }
2220: }
1.41 raeburn 2221: $datatable .= '<td>';
2222: if ($img eq 'login') {
1.135 bisitz 2223: $datatable .= $login_hdr_pick;
2224: }
1.41 raeburn 2225: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2226: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2227: } else {
1.201 raeburn 2228: $datatable .= '<td> </td><td class="LC_left_item">'.
2229: &mt('Upload:').'<br />';
1.6 raeburn 2230: }
2231: } else {
1.201 raeburn 2232: $datatable .= '<td> </td><td class="LC_left_item">'.
2233: &mt('Upload:').'<br />';
1.6 raeburn 2234: }
1.9 raeburn 2235: if ($switchserver) {
2236: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2237: } else {
1.135 bisitz 2238: if ($img ne 'login') { # suppress file selection for Log-in header
2239: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2240: }
1.9 raeburn 2241: }
1.402 raeburn 2242: if (($role eq 'login') && ($img ne 'login')) {
2243: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2244: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2245: '</label></span>';
2246: }
1.9 raeburn 2247: $datatable .= '</td></tr>';
1.6 raeburn 2248: }
2249: $itemcount ++;
2250: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2251: $datatable .= '<tr'.$css_class.'>'.
2252: '<td>'.$choices->{'bgs'}.'</td>';
2253: my $bgs_def;
2254: foreach my $item (@{$bgs}) {
2255: if (!$is_custom->{$item}) {
1.329 raeburn 2256: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 2257: }
2258: }
2259: if ($bgs_def) {
1.8 raeburn 2260: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2261: } else {
2262: $datatable .= '<td> </td>';
2263: }
2264: $datatable .= '<td class="LC_right_item">'.
2265: '<table border="0"><tr>';
1.174 foxr 2266:
1.6 raeburn 2267: foreach my $item (@{$bgs}) {
1.306 raeburn 2268: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2269: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2270: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2271: $datatable .= ' ';
1.6 raeburn 2272: }
1.174 foxr 2273: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2274: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2275: }
2276: $datatable .= '</tr></table></td></tr>';
2277: $itemcount ++;
2278: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2279: $datatable .= '<tr'.$css_class.'>'.
2280: '<td>'.$choices->{'links'}.'</td>';
2281: my $links_def;
2282: foreach my $item (@{$links}) {
2283: if (!$is_custom->{$item}) {
1.329 raeburn 2284: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 2285: }
2286: }
2287: if ($links_def) {
1.8 raeburn 2288: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2289: } else {
2290: $datatable .= '<td> </td>';
2291: }
2292: $datatable .= '<td class="LC_right_item">'.
2293: '<table border="0"><tr>';
2294: foreach my $item (@{$links}) {
1.234 raeburn 2295: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2296: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2297: if ($designs->{'links'}{$item}) {
1.174 foxr 2298: $datatable.=' ';
1.6 raeburn 2299: }
1.174 foxr 2300: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2301: '" /></td>';
2302: }
1.30 raeburn 2303: $$rowtotal += $itemcount;
1.3 raeburn 2304: return $datatable;
2305: }
2306:
1.70 raeburn 2307: sub logo_display_options {
2308: my ($img,$defaults,$designs) = @_;
2309: my $checkedon;
2310: if (ref($defaults) eq 'HASH') {
2311: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2312: if ($defaults->{'showlogo'}{$img}) {
2313: $checkedon = 'checked="checked" ';
2314: }
2315: }
2316: }
2317: if (ref($designs) eq 'HASH') {
2318: if (ref($designs->{'showlogo'}) eq 'HASH') {
2319: if (defined($designs->{'showlogo'}{$img})) {
2320: if ($designs->{'showlogo'}{$img} == 0) {
2321: $checkedon = '';
2322: } elsif ($designs->{'showlogo'}{$img} == 1) {
2323: $checkedon = 'checked="checked" ';
2324: }
2325: }
2326: }
2327: }
2328: return '<br /><label> <input type="checkbox" name="'.
2329: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2330: &mt('show').'</label>'."\n";
2331: }
2332:
1.41 raeburn 2333: sub login_header_options {
1.135 bisitz 2334: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2335: my $output = '';
1.41 raeburn 2336: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2337: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2338: if (!$is_custom->{'textcol'}) {
2339: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2340: ' ';
2341: }
2342: if (!$is_custom->{'bgcol'}) {
2343: $output .= $choices->{'bgcol'}.': '.
2344: '<span id="css_'.$role.'_font" style="background-color: '.
2345: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2346: }
2347: $output .= '<br />';
2348: }
2349: $output .='<br />';
2350: return $output;
2351: }
2352:
2353: sub login_text_colors {
1.201 raeburn 2354: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2355: my $color_menu = '<table border="0"><tr>';
2356: foreach my $item (@{$logintext}) {
1.306 raeburn 2357: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2358: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2359: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2360: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2361: }
2362: $color_menu .= '</tr></table><br />';
2363: return $color_menu;
2364: }
2365:
2366: sub image_changes {
2367: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2368: my $output;
1.135 bisitz 2369: if ($img eq 'login') {
1.331 raeburn 2370: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2371: } elsif (!$is_custom) {
1.70 raeburn 2372: if ($img ne 'domlogo') {
1.331 raeburn 2373: $output = &mt('Default image:').'<br />';
1.41 raeburn 2374: } else {
1.331 raeburn 2375: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2376: }
2377: }
1.331 raeburn 2378: if ($img ne 'login') {
1.135 bisitz 2379: if ($img_import) {
2380: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2381: }
2382: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2383: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2384: if ($is_custom) {
2385: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2386: '<input type="checkbox" name="'.
2387: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2388: '</label> '.&mt('Replace:').'</span><br />';
2389: } else {
1.306 raeburn 2390: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2391: }
1.41 raeburn 2392: }
2393: return $output;
2394: }
2395:
1.3 raeburn 2396: sub print_quotas {
1.86 raeburn 2397: my ($dom,$settings,$rowtotal,$action) = @_;
2398: my $context;
2399: if ($action eq 'quotas') {
2400: $context = 'tools';
2401: } else {
2402: $context = $action;
2403: }
1.429 raeburn 2404: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2405: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2406: my $typecount = 0;
1.101 raeburn 2407: my ($css_class,%titles);
1.86 raeburn 2408: if ($context eq 'requestcourses') {
1.325 raeburn 2409: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2410: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2411: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2412: %titles = &courserequest_titles();
1.163 raeburn 2413: } elsif ($context eq 'requestauthor') {
2414: @usertools = ('author');
2415: @options = ('norequest','approval','automatic');
1.210 raeburn 2416: %titles = &authorrequest_titles();
1.86 raeburn 2417: } else {
1.430 raeburn 2418: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 2419: %titles = &tool_titles();
1.86 raeburn 2420: }
1.26 raeburn 2421: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2422: foreach my $type (@{$types}) {
1.429 raeburn 2423: my $currdefquota;
1.163 raeburn 2424: unless (($context eq 'requestcourses') ||
2425: ($context eq 'requestauthor')) {
1.86 raeburn 2426: if (ref($settings) eq 'HASH') {
2427: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2428: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2429: } else {
2430: $currdefquota = $settings->{$type};
2431: }
1.78 raeburn 2432: }
1.72 raeburn 2433: }
1.3 raeburn 2434: if (defined($usertypes->{$type})) {
2435: $typecount ++;
2436: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2437: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2438: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2439: '<td class="LC_left_item">';
1.101 raeburn 2440: if ($context eq 'requestcourses') {
2441: $datatable .= '<table><tr>';
2442: }
2443: my %cell;
1.72 raeburn 2444: foreach my $item (@usertools) {
1.101 raeburn 2445: if ($context eq 'requestcourses') {
2446: my ($curroption,$currlimit);
2447: if (ref($settings) eq 'HASH') {
2448: if (ref($settings->{$item}) eq 'HASH') {
2449: $curroption = $settings->{$item}->{$type};
2450: if ($curroption =~ /^autolimit=(\d*)$/) {
2451: $currlimit = $1;
2452: }
2453: }
2454: }
2455: if (!$curroption) {
2456: $curroption = 'norequest';
2457: }
2458: $datatable .= '<th>'.$titles{$item}.'</th>';
2459: foreach my $option (@options) {
2460: my $val = $option;
2461: if ($option eq 'norequest') {
2462: $val = 0;
2463: }
2464: if ($option eq 'validate') {
2465: my $canvalidate = 0;
2466: if (ref($validations{$item}) eq 'HASH') {
2467: if ($validations{$item}{$type}) {
2468: $canvalidate = 1;
2469: }
2470: }
2471: next if (!$canvalidate);
2472: }
2473: my $checked = '';
2474: if ($option eq $curroption) {
2475: $checked = ' checked="checked"';
2476: } elsif ($option eq 'autolimit') {
2477: if ($curroption =~ /^autolimit/) {
2478: $checked = ' checked="checked"';
2479: }
2480: }
2481: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2482: '<input type="radio" name="crsreq_'.$item.
2483: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2484: $titles{$option}.'</label>';
1.101 raeburn 2485: if ($option eq 'autolimit') {
1.127 raeburn 2486: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2487: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2488: 'value="'.$currlimit.'" />';
1.101 raeburn 2489: }
1.127 raeburn 2490: $cell{$item} .= '</span> ';
1.103 raeburn 2491: if ($option eq 'autolimit') {
1.127 raeburn 2492: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2493: }
1.101 raeburn 2494: }
1.163 raeburn 2495: } elsif ($context eq 'requestauthor') {
2496: my $curroption;
2497: if (ref($settings) eq 'HASH') {
2498: $curroption = $settings->{$type};
2499: }
2500: if (!$curroption) {
2501: $curroption = 'norequest';
2502: }
2503: foreach my $option (@options) {
2504: my $val = $option;
2505: if ($option eq 'norequest') {
2506: $val = 0;
2507: }
2508: my $checked = '';
2509: if ($option eq $curroption) {
2510: $checked = ' checked="checked"';
2511: }
2512: $datatable .= '<span class="LC_nobreak"><label>'.
2513: '<input type="radio" name="authorreq_'.$type.
2514: '" value="'.$val.'"'.$checked.' />'.
2515: $titles{$option}.'</label></span> ';
2516: }
1.101 raeburn 2517: } else {
2518: my $checked = 'checked="checked" ';
1.413 raeburn 2519: if ($item eq 'timezone') {
2520: $checked = '';
2521: }
1.101 raeburn 2522: if (ref($settings) eq 'HASH') {
2523: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2524: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2525: $checked = '';
2526: } elsif ($settings->{$item}->{$type} == 1) {
2527: $checked = 'checked="checked" ';
2528: }
1.78 raeburn 2529: }
1.72 raeburn 2530: }
1.101 raeburn 2531: $datatable .= '<span class="LC_nobreak"><label>'.
2532: '<input type="checkbox" name="'.$context.'_'.$item.
2533: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2534: '</label></span> ';
1.72 raeburn 2535: }
1.101 raeburn 2536: }
2537: if ($context eq 'requestcourses') {
2538: $datatable .= '</tr><tr>';
2539: foreach my $item (@usertools) {
1.106 raeburn 2540: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2541: }
2542: $datatable .= '</tr></table>';
1.72 raeburn 2543: }
1.86 raeburn 2544: $datatable .= '</td>';
1.163 raeburn 2545: unless (($context eq 'requestcourses') ||
2546: ($context eq 'requestauthor')) {
1.86 raeburn 2547: $datatable .=
1.197 raeburn 2548: '<td class="LC_right_item">'.
1.429 raeburn 2549: '<span class="LC_nobreak">'.
1.3 raeburn 2550: '<input type="text" name="quota_'.$type.
1.72 raeburn 2551: '" value="'.$currdefquota.
1.197 raeburn 2552: '" size="5" /></span></td>';
1.86 raeburn 2553: }
2554: $datatable .= '</tr>';
1.3 raeburn 2555: }
2556: }
2557: }
1.163 raeburn 2558: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2559: $defaultquota = '20';
2560: if (ref($settings) eq 'HASH') {
2561: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2562: $defaultquota = $settings->{'defaultquota'}->{'default'};
2563: } elsif (defined($settings->{'default'})) {
2564: $defaultquota = $settings->{'default'};
2565: }
1.3 raeburn 2566: }
2567: }
2568: $typecount ++;
2569: $css_class = $typecount%2?' class="LC_odd_row"':'';
2570: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2571: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2572: '<td class="LC_left_item">';
1.101 raeburn 2573: if ($context eq 'requestcourses') {
2574: $datatable .= '<table><tr>';
2575: }
2576: my %defcell;
1.72 raeburn 2577: foreach my $item (@usertools) {
1.101 raeburn 2578: if ($context eq 'requestcourses') {
2579: my ($curroption,$currlimit);
2580: if (ref($settings) eq 'HASH') {
2581: if (ref($settings->{$item}) eq 'HASH') {
2582: $curroption = $settings->{$item}->{'default'};
2583: if ($curroption =~ /^autolimit=(\d*)$/) {
2584: $currlimit = $1;
2585: }
2586: }
2587: }
2588: if (!$curroption) {
2589: $curroption = 'norequest';
2590: }
2591: $datatable .= '<th>'.$titles{$item}.'</th>';
2592: foreach my $option (@options) {
2593: my $val = $option;
2594: if ($option eq 'norequest') {
2595: $val = 0;
2596: }
2597: if ($option eq 'validate') {
2598: my $canvalidate = 0;
2599: if (ref($validations{$item}) eq 'HASH') {
2600: if ($validations{$item}{'default'}) {
2601: $canvalidate = 1;
2602: }
2603: }
2604: next if (!$canvalidate);
2605: }
2606: my $checked = '';
2607: if ($option eq $curroption) {
2608: $checked = ' checked="checked"';
2609: } elsif ($option eq 'autolimit') {
2610: if ($curroption =~ /^autolimit/) {
2611: $checked = ' checked="checked"';
2612: }
2613: }
2614: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2615: '<input type="radio" name="crsreq_'.$item.
2616: '_default" value="'.$val.'"'.$checked.' />'.
2617: $titles{$option}.'</label>';
2618: if ($option eq 'autolimit') {
1.127 raeburn 2619: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2620: $item.'_limit_default" size="1" '.
2621: 'value="'.$currlimit.'" />';
2622: }
1.127 raeburn 2623: $defcell{$item} .= '</span> ';
1.104 raeburn 2624: if ($option eq 'autolimit') {
1.127 raeburn 2625: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2626: }
1.101 raeburn 2627: }
1.163 raeburn 2628: } elsif ($context eq 'requestauthor') {
2629: my $curroption;
2630: if (ref($settings) eq 'HASH') {
1.172 raeburn 2631: $curroption = $settings->{'default'};
1.163 raeburn 2632: }
2633: if (!$curroption) {
2634: $curroption = 'norequest';
2635: }
2636: foreach my $option (@options) {
2637: my $val = $option;
2638: if ($option eq 'norequest') {
2639: $val = 0;
2640: }
2641: my $checked = '';
2642: if ($option eq $curroption) {
2643: $checked = ' checked="checked"';
2644: }
2645: $datatable .= '<span class="LC_nobreak"><label>'.
2646: '<input type="radio" name="authorreq_default"'.
2647: ' value="'.$val.'"'.$checked.' />'.
2648: $titles{$option}.'</label></span> ';
2649: }
1.101 raeburn 2650: } else {
2651: my $checked = 'checked="checked" ';
2652: if (ref($settings) eq 'HASH') {
2653: if (ref($settings->{$item}) eq 'HASH') {
2654: if ($settings->{$item}->{'default'} == 0) {
2655: $checked = '';
2656: } elsif ($settings->{$item}->{'default'} == 1) {
2657: $checked = 'checked="checked" ';
2658: }
1.78 raeburn 2659: }
1.72 raeburn 2660: }
1.101 raeburn 2661: $datatable .= '<span class="LC_nobreak"><label>'.
2662: '<input type="checkbox" name="'.$context.'_'.$item.
2663: '" value="default" '.$checked.'/>'.$titles{$item}.
2664: '</label></span> ';
2665: }
2666: }
2667: if ($context eq 'requestcourses') {
2668: $datatable .= '</tr><tr>';
2669: foreach my $item (@usertools) {
1.106 raeburn 2670: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2671: }
1.101 raeburn 2672: $datatable .= '</tr></table>';
1.72 raeburn 2673: }
1.86 raeburn 2674: $datatable .= '</td>';
1.163 raeburn 2675: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2676: $datatable .= '<td class="LC_right_item">'.
1.429 raeburn 2677: '<span class="LC_nobreak">'.
1.86 raeburn 2678: '<input type="text" name="defaultquota" value="'.
1.429 raeburn 2679: $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2680: }
2681: $datatable .= '</tr>';
1.72 raeburn 2682: $typecount ++;
2683: $css_class = $typecount%2?' class="LC_odd_row"':'';
2684: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2685: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2686: if ($context eq 'requestcourses') {
1.109 raeburn 2687: $datatable .= &mt('(overrides affiliation, if set)').
2688: '</td>'.
2689: '<td class="LC_left_item">'.
2690: '<table><tr>';
1.101 raeburn 2691: } else {
1.109 raeburn 2692: $datatable .= &mt('(overrides affiliation, if checked)').
2693: '</td>'.
2694: '<td class="LC_left_item" colspan="2">'.
2695: '<br />';
1.101 raeburn 2696: }
2697: my %advcell;
1.72 raeburn 2698: foreach my $item (@usertools) {
1.101 raeburn 2699: if ($context eq 'requestcourses') {
2700: my ($curroption,$currlimit);
2701: if (ref($settings) eq 'HASH') {
2702: if (ref($settings->{$item}) eq 'HASH') {
2703: $curroption = $settings->{$item}->{'_LC_adv'};
2704: if ($curroption =~ /^autolimit=(\d*)$/) {
2705: $currlimit = $1;
2706: }
2707: }
2708: }
2709: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2710: my $checked = '';
2711: if ($curroption eq '') {
2712: $checked = ' checked="checked"';
2713: }
2714: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2715: '<input type="radio" name="crsreq_'.$item.
2716: '__LC_adv" value=""'.$checked.' />'.
2717: &mt('No override set').'</label></span> ';
1.101 raeburn 2718: foreach my $option (@options) {
2719: my $val = $option;
2720: if ($option eq 'norequest') {
2721: $val = 0;
2722: }
2723: if ($option eq 'validate') {
2724: my $canvalidate = 0;
2725: if (ref($validations{$item}) eq 'HASH') {
2726: if ($validations{$item}{'_LC_adv'}) {
2727: $canvalidate = 1;
2728: }
2729: }
2730: next if (!$canvalidate);
2731: }
2732: my $checked = '';
1.104 raeburn 2733: if ($val eq $curroption) {
1.101 raeburn 2734: $checked = ' checked="checked"';
2735: } elsif ($option eq 'autolimit') {
2736: if ($curroption =~ /^autolimit/) {
2737: $checked = ' checked="checked"';
2738: }
2739: }
2740: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2741: '<input type="radio" name="crsreq_'.$item.
2742: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2743: $titles{$option}.'</label>';
2744: if ($option eq 'autolimit') {
1.127 raeburn 2745: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2746: $item.'_limit__LC_adv" size="1" '.
2747: 'value="'.$currlimit.'" />';
2748: }
1.127 raeburn 2749: $advcell{$item} .= '</span> ';
1.104 raeburn 2750: if ($option eq 'autolimit') {
1.127 raeburn 2751: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2752: }
1.101 raeburn 2753: }
1.163 raeburn 2754: } elsif ($context eq 'requestauthor') {
2755: my $curroption;
2756: if (ref($settings) eq 'HASH') {
2757: $curroption = $settings->{'_LC_adv'};
2758: }
2759: my $checked = '';
2760: if ($curroption eq '') {
2761: $checked = ' checked="checked"';
2762: }
2763: $datatable .= '<span class="LC_nobreak"><label>'.
2764: '<input type="radio" name="authorreq__LC_adv"'.
2765: ' value=""'.$checked.' />'.
2766: &mt('No override set').'</label></span> ';
2767: foreach my $option (@options) {
2768: my $val = $option;
2769: if ($option eq 'norequest') {
2770: $val = 0;
2771: }
2772: my $checked = '';
2773: if ($val eq $curroption) {
2774: $checked = ' checked="checked"';
2775: }
2776: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2777: '<input type="radio" name="authorreq__LC_adv"'.
2778: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2779: $titles{$option}.'</label></span> ';
2780: }
1.101 raeburn 2781: } else {
2782: my $checked = 'checked="checked" ';
2783: if (ref($settings) eq 'HASH') {
2784: if (ref($settings->{$item}) eq 'HASH') {
2785: if ($settings->{$item}->{'_LC_adv'} == 0) {
2786: $checked = '';
2787: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2788: $checked = 'checked="checked" ';
2789: }
1.79 raeburn 2790: }
1.72 raeburn 2791: }
1.101 raeburn 2792: $datatable .= '<span class="LC_nobreak"><label>'.
2793: '<input type="checkbox" name="'.$context.'_'.$item.
2794: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2795: '</label></span> ';
2796: }
2797: }
2798: if ($context eq 'requestcourses') {
2799: $datatable .= '</tr><tr>';
2800: foreach my $item (@usertools) {
1.106 raeburn 2801: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2802: }
1.101 raeburn 2803: $datatable .= '</tr></table>';
1.72 raeburn 2804: }
1.98 raeburn 2805: $datatable .= '</td></tr>';
1.30 raeburn 2806: $$rowtotal += $typecount;
1.3 raeburn 2807: return $datatable;
2808: }
2809:
1.163 raeburn 2810: sub print_requestmail {
1.305 raeburn 2811: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2812: my ($now,$datatable,%currapp);
1.102 raeburn 2813: $now = time;
2814: if (ref($settings) eq 'HASH') {
2815: if (ref($settings->{'notify'}) eq 'HASH') {
2816: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2817: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2818: }
2819: }
2820: }
1.191 raeburn 2821: my $numinrow = 2;
1.224 raeburn 2822: my $css_class;
1.305 raeburn 2823: if ($$rowtotal%2) {
2824: $css_class = 'LC_odd_row';
2825: }
2826: if ($customcss) {
2827: $css_class .= " $customcss";
2828: }
2829: $css_class =~ s/^\s+//;
2830: if ($css_class) {
2831: $css_class = ' class="'.$css_class.'"';
2832: }
2833: if ($rowstyle) {
2834: $css_class .= ' style="'.$rowstyle.'"';
2835: }
1.163 raeburn 2836: my $text;
2837: if ($action eq 'requestcourses') {
2838: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2839: } elsif ($action eq 'requestauthor') {
2840: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2841: } else {
1.224 raeburn 2842: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2843: }
1.224 raeburn 2844: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2845: ' <td>'.$text.'</td>'.
1.102 raeburn 2846: ' <td class="LC_left_item">';
1.191 raeburn 2847: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2848: $action.'notifyapproval',%currapp);
1.191 raeburn 2849: if ($numdc > 0) {
2850: $datatable .= $table;
1.102 raeburn 2851: } else {
2852: $datatable .= &mt('There are no active Domain Coordinators');
2853: }
2854: $datatable .='</td></tr>';
2855: return $datatable;
2856: }
2857:
1.216 raeburn 2858: sub print_studentcode {
2859: my ($settings,$rowtotal) = @_;
2860: my $rownum = 0;
1.218 raeburn 2861: my ($output,%current);
1.325 raeburn 2862: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2863: if (ref($settings) eq 'HASH') {
2864: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2865: foreach my $type (@crstypes) {
2866: $current{$type} = $settings->{'uniquecode'}{$type};
2867: }
1.218 raeburn 2868: }
2869: }
2870: $output .= '<tr>'.
2871: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2872: '<td class="LC_left_item">';
2873: foreach my $type (@crstypes) {
2874: my $check = ' ';
2875: if ($current{$type}) {
2876: $check = ' checked="checked" ';
2877: }
2878: $output .= '<span class="LC_nobreak"><label>'.
2879: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2880: &mt($type).'</label></span>'.(' 'x2).' ';
2881: }
2882: $output .= '</td></tr>';
2883: $$rowtotal ++;
2884: return $output;
1.216 raeburn 2885: }
2886:
2887: sub print_textbookcourses {
1.242 raeburn 2888: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2889: my $rownum = 0;
2890: my $css_class;
2891: my $itemcount = 1;
2892: my $maxnum = 0;
2893: my $bookshash;
2894: if (ref($settings) eq 'HASH') {
1.242 raeburn 2895: $bookshash = $settings->{$type};
1.216 raeburn 2896: }
2897: my %ordered;
2898: if (ref($bookshash) eq 'HASH') {
2899: foreach my $item (keys(%{$bookshash})) {
2900: if (ref($bookshash->{$item}) eq 'HASH') {
2901: my $num = $bookshash->{$item}{'order'};
2902: $ordered{$num} = $item;
2903: }
2904: }
2905: }
2906: my $confname = $dom.'-domainconfig';
2907: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2908: my $maxnum = scalar(keys(%ordered));
2909: my $datatable;
1.216 raeburn 2910: if (keys(%ordered)) {
2911: my @items = sort { $a <=> $b } keys(%ordered);
2912: for (my $i=0; $i<@items; $i++) {
2913: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2914: my $key = $ordered{$items[$i]};
2915: my %coursehash=&Apache::lonnet::coursedescription($key);
2916: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2917: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2918: if (ref($bookshash->{$key}) eq 'HASH') {
2919: $subject = $bookshash->{$key}->{'subject'};
2920: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2921: if ($type eq 'textbooks') {
1.243 raeburn 2922: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2923: $author = $bookshash->{$key}->{'author'};
2924: $image = $bookshash->{$key}->{'image'};
2925: if ($image ne '') {
2926: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2927: my $imagethumb = "$path/tn-".$imagefile;
2928: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2929: }
1.216 raeburn 2930: }
2931: }
1.242 raeburn 2932: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2933: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2934: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2935: for (my $k=0; $k<=$maxnum; $k++) {
2936: my $vpos = $k+1;
2937: my $selstr;
2938: if ($k == $i) {
2939: $selstr = ' selected="selected" ';
2940: }
2941: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2942: }
2943: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2944: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2945: &mt('Delete?').'</label></span></td>'.
2946: '<td colspan="2">'.
1.242 raeburn 2947: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2948: (' 'x2).
1.242 raeburn 2949: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2950: if ($type eq 'textbooks') {
2951: $datatable .= (' 'x2).
1.243 raeburn 2952: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2953: (' 'x2).
1.242 raeburn 2954: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2955: (' 'x2).
2956: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2957: if ($image) {
1.267 raeburn 2958: $datatable .= $imgsrc.
1.242 raeburn 2959: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2960: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2961: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2962: }
2963: if ($switchserver) {
2964: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2965: } else {
2966: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2967: }
1.216 raeburn 2968: }
1.242 raeburn 2969: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2970: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2971: $coursetitle.'</span></td></tr>'."\n";
2972: $itemcount ++;
2973: }
2974: }
2975: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2976: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2977: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2978: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2979: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2980: for (my $k=0; $k<$maxnum+1; $k++) {
2981: my $vpos = $k+1;
2982: my $selstr;
2983: if ($k == $maxnum) {
2984: $selstr = ' selected="selected" ';
2985: }
2986: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2987: }
2988: $datatable .= '</select> '."\n".
1.334 raeburn 2989: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2990: '<td colspan="2">'.
1.242 raeburn 2991: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2992: (' 'x2).
1.242 raeburn 2993: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2994: (' 'x2);
2995: if ($type eq 'textbooks') {
1.243 raeburn 2996: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2997: (' 'x2).
2998: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2999: (' 'x2).
3000: '<span class="LC_nobreak">'.&mt('Image:').' ';
3001: if ($switchserver) {
3002: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3003: } else {
3004: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
3005: }
1.334 raeburn 3006: $datatable .= '</span>'."\n";
1.216 raeburn 3007: }
1.334 raeburn 3008: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 3009: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
3010: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 3011: &Apache::loncommon::selectcourse_link
1.334 raeburn 3012: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 3013: '</span></td>'."\n".
3014: '</tr>'."\n";
3015: $itemcount ++;
3016: return $datatable;
3017: }
3018:
1.217 raeburn 3019: sub textbookcourses_javascript {
1.242 raeburn 3020: my ($settings) = @_;
3021: return unless(ref($settings) eq 'HASH');
3022: my (%ordered,%total,%jstext);
3023: foreach my $type ('textbooks','templates') {
3024: $total{$type} = 0;
3025: if (ref($settings->{$type}) eq 'HASH') {
3026: foreach my $item (keys(%{$settings->{$type}})) {
3027: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3028: my $num = $settings->{$type}->{$item}{'order'};
3029: $ordered{$type}{$num} = $item;
3030: }
3031: }
3032: $total{$type} = scalar(keys(%{$settings->{$type}}));
3033: }
3034: my @jsarray = ();
3035: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3036: push(@jsarray,$ordered{$type}{$item});
3037: }
3038: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3039: }
3040: return <<"ENDSCRIPT";
3041: <script type="text/javascript">
3042: // <![CDATA[
1.242 raeburn 3043: function reorderBooks(form,item,caller) {
1.217 raeburn 3044: var changedVal;
1.242 raeburn 3045: $jstext{'textbooks'};
3046: $jstext{'templates'};
3047: var newpos;
3048: var maxh;
3049: if (caller == 'textbooks') {
3050: newpos = 'textbooks_addbook_pos';
3051: maxh = 1 + $total{'textbooks'};
3052: } else {
3053: newpos = 'templates_addbook_pos';
3054: maxh = 1 + $total{'templates'};
3055: }
1.217 raeburn 3056: var current = new Array;
3057: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3058: if (item == newpos) {
3059: changedVal = newitemVal;
3060: } else {
3061: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3062: current[newitemVal] = newpos;
3063: }
1.242 raeburn 3064: if (caller == 'textbooks') {
3065: for (var i=0; i<textbooks.length; i++) {
3066: var elementName = 'textbooks_'+textbooks[i];
3067: if (elementName != item) {
3068: if (form.elements[elementName]) {
3069: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3070: current[currVal] = elementName;
3071: }
3072: }
3073: }
3074: }
3075: if (caller == 'templates') {
3076: for (var i=0; i<templates.length; i++) {
3077: var elementName = 'templates_'+templates[i];
3078: if (elementName != item) {
3079: if (form.elements[elementName]) {
3080: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3081: current[currVal] = elementName;
3082: }
1.217 raeburn 3083: }
3084: }
3085: }
3086: var oldVal;
3087: for (var j=0; j<maxh; j++) {
3088: if (current[j] == undefined) {
3089: oldVal = j;
3090: }
3091: }
3092: if (oldVal < changedVal) {
3093: for (var k=oldVal+1; k<=changedVal ; k++) {
3094: var elementName = current[k];
3095: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3096: }
3097: } else {
3098: for (var k=changedVal; k<oldVal; k++) {
3099: var elementName = current[k];
3100: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3101: }
3102: }
3103: return;
3104: }
3105:
3106: // ]]>
3107: </script>
3108:
3109: ENDSCRIPT
3110: }
3111:
1.267 raeburn 3112: sub ltitools_javascript {
3113: my ($settings) = @_;
1.319 raeburn 3114: my $togglejs = <itools_toggle_js();
3115: unless (ref($settings) eq 'HASH') {
3116: return $togglejs;
3117: }
1.267 raeburn 3118: my (%ordered,$total,%jstext);
3119: $total = 0;
3120: foreach my $item (keys(%{$settings})) {
3121: if (ref($settings->{$item}) eq 'HASH') {
3122: my $num = $settings->{$item}{'order'};
3123: $ordered{$num} = $item;
3124: }
3125: }
3126: $total = scalar(keys(%{$settings}));
3127: my @jsarray = ();
3128: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3129: push(@jsarray,$ordered{$item});
3130: }
3131: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3132: return <<"ENDSCRIPT";
3133: <script type="text/javascript">
3134: // <![CDATA[
1.319 raeburn 3135: function reorderLTITools(form,item) {
1.267 raeburn 3136: var changedVal;
3137: $jstext
3138: var newpos = 'ltitools_add_pos';
3139: var maxh = 1 + $total;
3140: var current = new Array;
3141: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3142: if (item == newpos) {
3143: changedVal = newitemVal;
3144: } else {
3145: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3146: current[newitemVal] = newpos;
3147: }
3148: for (var i=0; i<ltitools.length; i++) {
3149: var elementName = 'ltitools_'+ltitools[i];
3150: if (elementName != item) {
3151: if (form.elements[elementName]) {
3152: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3153: current[currVal] = elementName;
3154: }
3155: }
3156: }
3157: var oldVal;
3158: for (var j=0; j<maxh; j++) {
3159: if (current[j] == undefined) {
3160: oldVal = j;
3161: }
3162: }
3163: if (oldVal < changedVal) {
3164: for (var k=oldVal+1; k<=changedVal ; k++) {
3165: var elementName = current[k];
3166: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3167: }
3168: } else {
3169: for (var k=changedVal; k<oldVal; k++) {
3170: var elementName = current[k];
3171: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3172: }
3173: }
3174: return;
3175: }
3176:
3177: // ]]>
3178: </script>
3179:
1.319 raeburn 3180: $togglejs
3181:
3182: ENDSCRIPT
3183: }
3184:
3185: sub ltitools_toggle_js {
3186: return <<"ENDSCRIPT";
3187: <script type="text/javascript">
3188: // <![CDATA[
3189:
3190: function toggleLTITools(form,setting,item) {
3191: var radioname = '';
3192: var divid = '';
3193: if ((setting == 'passback') || (setting == 'roster')) {
3194: radioname = 'ltitools_'+setting+'_'+item;
3195: divid = 'ltitools_'+setting+'time_'+item;
3196: var num = form.elements[radioname].length;
3197: if (num) {
3198: var setvis = '';
3199: for (var i=0; i<num; i++) {
3200: if (form.elements[radioname][i].checked) {
3201: if (form.elements[radioname][i].value == '1') {
3202: if (document.getElementById(divid)) {
3203: document.getElementById(divid).style.display = 'inline-block';
3204: }
3205: setvis = 1;
3206: }
3207: break;
3208: }
3209: }
3210: }
3211: if (!setvis) {
3212: if (document.getElementById(divid)) {
3213: document.getElementById(divid).style.display = 'none';
3214: }
3215: }
3216: }
1.324 raeburn 3217: if (setting == 'user') {
3218: divid = 'ltitools_'+setting+'_div_'+item;
3219: var checkid = 'ltitools_'+setting+'_field_'+item;
3220: if (document.getElementById(divid)) {
3221: if (document.getElementById(checkid)) {
3222: if (document.getElementById(checkid).checked) {
3223: document.getElementById(divid).style.display = 'inline-block';
3224: } else {
3225: document.getElementById(divid).style.display = 'none';
3226: }
3227: }
3228: }
3229: }
1.319 raeburn 3230: return;
3231: }
3232: // ]]>
3233: </script>
3234:
1.267 raeburn 3235: ENDSCRIPT
3236: }
3237:
1.381 raeburn 3238: sub wafproxy_javascript {
3239: my ($dom) = @_;
3240: return <<"ENDSCRIPT";
3241: <script type="text/javascript">
3242: // <![CDATA[
3243: function updateWAF() {
3244: if (document.getElementById('wafproxy_remoteip')) {
3245: var wafremote = 0;
3246: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3247: wafremote = 1;
3248: }
3249: var fields = new Array('header','trust');
3250: for (var i=0; i<fields.length; i++) {
3251: if (document.getElementById('wafproxy_'+fields[i])) {
3252: if (wafremote == 1) {
3253: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3254: }
3255: else {
3256: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3257: }
3258: }
3259: }
3260: if (document.getElementById('wafproxyranges_$dom')) {
3261: if (wafremote == 1) {
3262: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3263: } else {
3264: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3265: if (document.display.wafproxy_vpnaccess[i].checked) {
3266: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3267: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3268: }
3269: }
3270: }
3271: }
3272: }
3273: }
3274: return;
3275: }
3276:
3277: function checkWAF() {
3278: if (document.getElementById('wafproxy_remoteip')) {
3279: var wafvpn = 0;
3280: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3281: if (document.display.wafproxy_vpnaccess[i].checked) {
3282: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3283: wafvpn = 1;
3284: }
3285: break;
3286: }
3287: }
3288: var vpn = new Array('vpnint','vpnext');
3289: for (var i=0; i<vpn.length; i++) {
3290: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3291: if (wafvpn == 1) {
3292: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3293: }
3294: else {
3295: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3296: }
3297: }
3298: }
3299: if (document.getElementById('wafproxyranges_$dom')) {
3300: if (wafvpn == 1) {
3301: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3302: }
3303: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3304: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3305: }
3306: }
3307: }
3308: return;
3309: }
3310:
3311: function toggleWAF() {
3312: if (document.getElementById('wafproxy_table')) {
3313: var wafproxy = 0;
3314: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3315: if (document.display.wafproxy_${dom}[i].checked) {
3316: if (document.display.wafproxy_${dom}[i].value == 1) {
3317: wafproxy = 1;
3318: break;
3319: }
3320: }
3321: }
3322: if (wafproxy == 1) {
3323: document.getElementById('wafproxy_table').style.display='inline';
3324: }
3325: else {
3326: document.getElementById('wafproxy_table').style.display='none';
3327: }
3328: if (document.getElementById('wafproxyrow_${dom}')) {
3329: if (wafproxy == 1) {
3330: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3331: }
3332: else {
3333: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3334: }
3335: }
3336: if (document.getElementById('nowafproxyrow_$dom')) {
3337: if (wafproxy == 1) {
3338: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3339: }
3340: else {
3341: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3342: }
3343: }
3344: }
3345: return;
3346: }
3347: // ]]>
3348: </script>
3349:
3350: ENDSCRIPT
3351: }
3352:
1.372 raeburn 3353: sub proctoring_javascript {
3354: my ($settings) = @_;
3355: my (%ordered,$total,%jstext);
3356: $total = 0;
3357: if (ref($settings) eq 'HASH') {
3358: foreach my $item (keys(%{$settings})) {
3359: if (ref($settings->{$item}) eq 'HASH') {
3360: my $num = $settings->{$item}{'order'};
3361: $ordered{$num} = $item;
3362: }
3363: }
3364: $total = scalar(keys(%{$settings}));
3365: } else {
3366: %ordered = (
3367: 0 => 'proctorio',
3368: 1 => 'examity',
3369: );
3370: $total = 2;
3371: }
3372: my @jsarray = ();
3373: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3374: push(@jsarray,$ordered{$item});
3375: }
3376: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3377: return <<"ENDSCRIPT";
3378: <script type="text/javascript">
3379: // <![CDATA[
3380: function reorderProctoring(form,item) {
3381: var changedVal;
3382: $jstext
3383: var maxh = $total;
3384: var current = new Array;
3385: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3386: for (var i=0; i<proctors.length; i++) {
3387: var elementName = 'proctoring_pos_'+proctors[i];
3388: if (elementName != item) {
3389: if (form.elements[elementName]) {
3390: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3391: current[currVal] = elementName;
3392: }
3393: }
3394: }
3395: var oldVal;
3396: for (var j=0; j<maxh; j++) {
3397: if (current[j] == undefined) {
3398: oldVal = j;
3399: }
3400: }
3401: if (oldVal < changedVal) {
3402: for (var k=oldVal+1; k<=changedVal ; k++) {
3403: var elementName = current[k];
3404: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3405: }
3406: } else {
3407: for (var k=changedVal; k<oldVal; k++) {
3408: var elementName = current[k];
3409: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3410: }
3411: }
3412: return;
3413: }
3414:
3415: function toggleProctoring(form,item) {
3416: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3417: if (fieldsets.length) {
3418: var radioname = 'proctoring_available_'+item;
3419: var num = form.elements[radioname].length;
3420: if (num) {
3421: var setvis = '';
3422: for (var i=0; i<num; i++) {
3423: if (form.elements[radioname][i].checked) {
3424: if (form.elements[radioname][i].value == '1') {
3425: setvis = 1;
3426: break;
3427: }
3428: }
3429: }
3430: for (var j=0; j<fieldsets.length; j++) {
3431: if (setvis) {
3432: fieldsets[j].style.display = 'block';
3433: } else {
3434: fieldsets[j].style.display = 'none';
3435: }
3436: }
3437: }
3438: }
3439: return;
3440: }
3441:
3442: // ]]>
3443: </script>
3444:
3445: ENDSCRIPT
3446: }
3447:
3448:
1.320 raeburn 3449: sub lti_javascript {
1.405 raeburn 3450: my ($dom,$settings) = @_;
3451: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3452: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3453: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3454: return $togglejs.'
3455: <script type="text/javascript">
3456: // <![CDATA[
3457:
3458: '.$linkprot_js.'
3459:
3460: // ]]>
3461: </script>
3462: ';
1.320 raeburn 3463: }
3464: my (%ordered,$total,%jstext);
1.390 raeburn 3465: $total = scalar(keys(%{$settings}));
1.320 raeburn 3466: foreach my $item (keys(%{$settings})) {
3467: if (ref($settings->{$item}) eq 'HASH') {
3468: my $num = $settings->{$item}{'order'};
1.390 raeburn 3469: if ($num eq '') {
3470: $num = $total - 1;
3471: }
1.320 raeburn 3472: $ordered{$num} = $item;
3473: }
3474: }
3475: my @jsarray = ();
3476: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3477: push(@jsarray,$ordered{$item});
3478: }
3479: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3480: return <<"ENDSCRIPT";
3481: <script type="text/javascript">
3482: // <![CDATA[
3483: function reorderLTI(form,item) {
3484: var changedVal;
3485: $jstext
3486: var newpos = 'lti_pos_add';
3487: var maxh = 1 + $total;
3488: var current = new Array;
3489: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3490: if (item == newpos) {
3491: changedVal = newitemVal;
3492: } else {
3493: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3494: current[newitemVal] = newpos;
3495: }
3496: for (var i=0; i<lti.length; i++) {
3497: var elementName = 'lti_pos_'+lti[i];
3498: if (elementName != item) {
3499: if (form.elements[elementName]) {
3500: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3501: current[currVal] = elementName;
3502: }
3503: }
3504: }
3505: var oldVal;
3506: for (var j=0; j<maxh; j++) {
3507: if (current[j] == undefined) {
3508: oldVal = j;
3509: }
3510: }
3511: if (oldVal < changedVal) {
3512: for (var k=oldVal+1; k<=changedVal ; k++) {
3513: var elementName = current[k];
3514: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3515: }
3516: } else {
3517: for (var k=changedVal; k<oldVal; k++) {
3518: var elementName = current[k];
3519: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3520: }
3521: }
3522: return;
3523: }
1.406 raeburn 3524:
3525: $linkprot_js
3526:
1.320 raeburn 3527: // ]]>
3528: </script>
3529:
3530: $togglejs
3531:
3532: ENDSCRIPT
3533: }
3534:
3535: sub lti_toggle_js {
1.405 raeburn 3536: my ($dom) = @_;
1.325 raeburn 3537: my %lcauthparmtext = &Apache::lonlocal::texthash (
3538: localauth => 'Local auth argument',
3539: krb => 'Kerberos domain',
3540: );
1.391 raeburn 3541: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3542: &js_escape(\$crsincalert);
1.405 raeburn 3543: my %servers = &Apache::lonnet::get_servers($dom,'library');
3544: my $primary = &Apache::lonnet::domain($dom,'primary');
3545: my $course_servers = "'".join("','",keys(%servers))."'";
1.320 raeburn 3546: return <<"ENDSCRIPT";
3547: <script type="text/javascript">
3548: // <![CDATA[
3549:
3550: function toggleLTI(form,setting,item) {
1.391 raeburn 3551: if ((setting == 'requser') || (setting == 'crsinc')) {
3552: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3553: var setvis = '';
3554: var radioname = 'lti_requser_'+item;
3555: var num = form.elements[radioname].length;
3556: if (num) {
3557: for (var i=0; i<num; i++) {
3558: if (form.elements[radioname][i].checked) {
3559: if (form.elements[radioname][i].value == '1') {
3560: setvis = 1;
3561: break;
3562: }
3563: }
3564: }
3565: }
3566: if (usrfieldsets.length) {
3567: for (var j=0; j<usrfieldsets.length; j++) {
3568: if (setvis) {
3569: usrfieldsets[j].style.display = 'block';
3570: } else {
3571: usrfieldsets[j].style.display = 'none';
3572: }
3573: }
3574: }
3575: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3576: if (crsfieldsets.length) {
3577: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3578: var num = form.elements[radioname].length;
3579: if (num) {
1.391 raeburn 3580: var crsvis = '';
1.345 raeburn 3581: for (var i=0; i<num; i++) {
3582: if (form.elements[radioname][i].checked) {
3583: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3584: if (setvis == '') {
3585: if (setting == 'crsinc'){
3586: alert("$crsincalert");
3587: form.elements[radioname][0].checked = true;
3588: }
3589: } else {
3590: crsvis = 1;
3591: }
3592: break;
1.345 raeburn 3593: }
3594: }
3595: }
1.391 raeburn 3596: setvis = crsvis;
3597: }
3598: for (var j=0; j<crsfieldsets.length; j++) {
3599: if (setvis) {
3600: crsfieldsets[j].style.display = 'block';
3601: } else {
3602: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3603: }
3604: }
3605: }
1.363 raeburn 3606: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3607: var radioname = '';
3608: var divid = '';
3609: if (setting == 'user') {
3610: radioname = 'lti_mapuser_'+item;
3611: divid = 'lti_userfield_'+item;
1.343 raeburn 3612: } else if (setting == 'crs') {
1.320 raeburn 3613: radioname = 'lti_mapcrs_'+item;
3614: divid = 'lti_crsfield_'+item;
1.363 raeburn 3615: } else if (setting == 'callback') {
3616: radioname = 'lti_callback_'+item;
3617: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3618: } else {
1.351 raeburn 3619: radioname = 'lti_passback_'+item;
1.337 raeburn 3620: divid = 'lti_passback_'+item;
1.320 raeburn 3621: }
3622: var num = form.elements[radioname].length;
3623: if (num) {
3624: var setvis = '';
3625: for (var i=0; i<num; i++) {
3626: if (form.elements[radioname][i].checked) {
1.363 raeburn 3627: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3628: if (form.elements[radioname][i].value == '1') {
3629: if (document.getElementById(divid)) {
3630: document.getElementById(divid).style.display = 'inline-block';
3631: }
3632: setvis = 1;
3633: break;
3634: }
3635: } else {
3636: if (form.elements[radioname][i].value == 'other') {
3637: if (document.getElementById(divid)) {
3638: document.getElementById(divid).style.display = 'inline-block';
3639: }
3640: setvis = 1;
3641: break;
1.320 raeburn 3642: }
3643: }
1.425 raeburn 3644: }
1.320 raeburn 3645: }
3646: if (!setvis) {
3647: if (document.getElementById(divid)) {
3648: document.getElementById(divid).style.display = 'none';
3649: }
3650: }
3651: }
3652: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3653: var numsec = form.elements['lti_crssec_'+item].length;
3654: if (numsec) {
3655: var setvis = '';
3656: for (var i=0; i<numsec; i++) {
3657: if (form.elements['lti_crssec_'+item][i].checked) {
3658: if (form.elements['lti_crssec_'+item][i].value == '1') {
3659: if (document.getElementById('lti_crssecfield_'+item)) {
3660: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3661: setvis = 1;
3662: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3663: if (numsrcsec) {
3664: var setsrcvis = '';
3665: for (var j=0; j<numsrcsec; j++) {
3666: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3667: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3668: if (document.getElementById('lti_secsrcfield_'+item)) {
3669: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3670: setsrcvis = 1;
3671: }
3672: }
3673: }
3674: }
3675: if (!setsrcvis) {
3676: if (document.getElementById('lti_secsrcfield_'+item)) {
3677: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3678: }
3679: }
3680: }
3681: }
3682: }
3683: }
3684: }
3685: if (!setvis) {
3686: if (document.getElementById('lti_crssecfield_'+item)) {
3687: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3688: }
3689: if (document.getElementById('lti_secsrcfield_'+item)) {
3690: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3691: }
3692: }
3693: }
1.325 raeburn 3694: } else if (setting == 'lcauth') {
3695: var numauth = form.elements['lti_lcauth_'+item].length;
3696: if (numauth) {
3697: for (var i=0; i<numauth; i++) {
3698: if (form.elements['lti_lcauth_'+item][i].checked) {
3699: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3700: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3701: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3702: } else {
3703: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3704: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3705: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3706: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3707: } else {
3708: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3709: }
3710: }
3711: }
3712: }
3713: }
3714: }
3715: }
1.326 raeburn 3716: } else if (setting == 'lcmenu') {
3717: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3718: var divid = 'lti_menufield_'+item;
3719: var setvis = '';
3720: for (var i=0; i<menus.length; i++) {
1.425 raeburn 3721: var radioname = menus[i];
1.326 raeburn 3722: var num = form.elements[radioname].length;
3723: if (num) {
3724: for (var j=0; j<num; j++) {
3725: if (form.elements[radioname][j].checked) {
3726: if (form.elements[radioname][j].value == '1') {
3727: if (document.getElementById(divid)) {
3728: document.getElementById(divid).style.display = 'inline-block';
3729: }
3730: setvis = 1;
3731: break;
3732: }
3733: }
3734: }
3735: }
3736: if (setvis == 1) {
3737: break;
3738: }
3739: }
3740: if (!setvis) {
3741: if (document.getElementById(divid)) {
3742: document.getElementById(divid).style.display = 'none';
3743: }
3744: }
1.320 raeburn 3745: }
3746: return;
3747: }
1.405 raeburn 3748:
1.320 raeburn 3749: // ]]>
3750: </script>
3751:
3752: ENDSCRIPT
3753: }
3754:
1.385 raeburn 3755: sub autoupdate_javascript {
3756: return <<"ENDSCRIPT";
3757: <script type="text/javascript">
3758: // <![CDATA[
3759: function toggleLastActiveDays(form) {
3760: var radioname = 'lastactive';
3761: var divid = 'lastactive_div';
3762: var num = form.elements[radioname].length;
3763: if (num) {
3764: var setvis = '';
3765: for (var i=0; i<num; i++) {
3766: if (form.elements[radioname][i].checked) {
3767: if (form.elements[radioname][i].value == '1') {
3768: if (document.getElementById(divid)) {
3769: document.getElementById(divid).style.display = 'inline-block';
3770: }
3771: setvis = 1;
3772: }
3773: break;
3774: }
3775: }
3776: if (!setvis) {
3777: if (document.getElementById(divid)) {
3778: document.getElementById(divid).style.display = 'none';
3779: }
3780: }
3781: }
3782: return;
3783: }
3784: // ]]>
3785: </script>
3786:
3787: ENDSCRIPT
3788: }
3789:
1.399 raeburn 3790: sub autoenroll_javascript {
3791: return <<"ENDSCRIPT";
3792: <script type="text/javascript">
3793: // <![CDATA[
3794: function toggleFailsafe(form) {
3795: var radioname = 'autoenroll_failsafe';
3796: var divid = 'autoenroll_failsafe_div';
3797: var num = form.elements[radioname].length;
3798: if (num) {
3799: var setvis = '';
3800: for (var i=0; i<num; i++) {
3801: if (form.elements[radioname][i].checked) {
3802: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3803: if (document.getElementById(divid)) {
3804: document.getElementById(divid).style.display = 'inline-block';
3805: }
3806: setvis = 1;
3807: }
3808: break;
3809: }
3810: }
3811: if (!setvis) {
3812: if (document.getElementById(divid)) {
3813: document.getElementById(divid).style.display = 'none';
3814: }
3815: }
3816: }
3817: return;
3818: }
3819: // ]]>
3820: </script>
3821:
3822: ENDSCRIPT
3823: }
3824:
1.386 raeburn 3825: sub saml_javascript {
3826: return <<"ENDSCRIPT";
3827: <script type="text/javascript">
3828: // <![CDATA[
1.425 raeburn 3829: function toggleSamlOptions(form,hostid) {
1.386 raeburn 3830: var radioname = 'saml_'+hostid;
3831: var tablecellon = 'samloptionson_'+hostid;
3832: var tablecelloff = 'samloptionsoff_'+hostid;
3833: var num = form.elements[radioname].length;
3834: if (num) {
1.425 raeburn 3835: var setvis = '';
1.386 raeburn 3836: for (var i=0; i<num; i++) {
3837: if (form.elements[radioname][i].checked) {
1.425 raeburn 3838: if (form.elements[radioname][i].value == '1') {
1.386 raeburn 3839: if (document.getElementById(tablecellon)) {
3840: document.getElementById(tablecellon).style.display='';
3841: }
3842: if (document.getElementById(tablecelloff)) {
3843: document.getElementById(tablecelloff).style.display='none';
3844: }
3845: setvis = 1;
3846: }
3847: break;
3848: }
3849: }
3850: if (!setvis) {
3851: if (document.getElementById(tablecellon)) {
3852: document.getElementById(tablecellon).style.display='none';
3853: }
3854: if (document.getElementById(tablecelloff)) {
3855: document.getElementById(tablecelloff).style.display='';
3856: }
3857: }
3858: }
3859: return;
3860: }
3861: // ]]>
3862: </script>
3863:
3864: ENDSCRIPT
3865: }
3866:
1.394 raeburn 3867: sub ipaccess_javascript {
3868: my ($settings) = @_;
3869: my (%ordered,$total,%jstext);
3870: $total = 0;
3871: if (ref($settings) eq 'HASH') {
3872: foreach my $item (keys(%{$settings})) {
3873: if (ref($settings->{$item}) eq 'HASH') {
3874: my $num = $settings->{$item}{'order'};
3875: $ordered{$num} = $item;
3876: }
3877: }
3878: $total = scalar(keys(%{$settings}));
3879: }
3880: my @jsarray = ();
3881: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3882: push(@jsarray,$ordered{$item});
3883: }
3884: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3885: return <<"ENDSCRIPT";
3886: <script type="text/javascript">
3887: // <![CDATA[
3888: function reorderIPaccess(form,item) {
3889: var changedVal;
3890: $jstext
3891: var newpos = 'ipaccess_pos_add';
3892: var maxh = 1 + $total;
3893: var current = new Array;
3894: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3895: if (item == newpos) {
3896: changedVal = newitemVal;
3897: } else {
3898: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3899: current[newitemVal] = newpos;
3900: }
3901: for (var i=0; i<ipaccess.length; i++) {
3902: var elementName = 'ipaccess_pos_'+ipaccess[i];
3903: if (elementName != item) {
3904: if (form.elements[elementName]) {
3905: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3906: current[currVal] = elementName;
3907: }
3908: }
3909: }
3910: var oldVal;
3911: for (var j=0; j<maxh; j++) {
3912: if (current[j] == undefined) {
3913: oldVal = j;
3914: }
3915: }
3916: if (oldVal < changedVal) {
3917: for (var k=oldVal+1; k<=changedVal ; k++) {
3918: var elementName = current[k];
3919: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3920: }
3921: } else {
3922: for (var k=changedVal; k<oldVal; k++) {
3923: var elementName = current[k];
3924: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3925: }
3926: }
3927: return;
3928: }
3929: // ]]>
3930: </script>
3931:
3932: ENDSCRIPT
3933: }
3934:
1.429 raeburn 3935: sub authordefaults_javascript {
3936: my %alert = &Apache::lonlocal::texthash (
3937: reqd => 'Warning: at least one editor needs to be available.',
3938: rest => 'Unchecking this editor disallowed while others unchecked.',
3939: );
3940: &js_escape(\%alert);
3941: return <<"ENDSCRIPT";
3942: <script type="text/javascript">
3943: // <![CDATA[
3944:
3945: function checkEditors(form,checkbox,current) {
3946: if (form.elements[checkbox].length != undefined) {
3947: var count = 0;
3948: for (var i=0; i<form.elements[checkbox].length; i++) {
3949: if (form.elements[checkbox][i].checked) {
3950: count ++;
3951: }
3952: }
3953: if (count == 0) {
3954: if (current.type =='radio') {
3955: current.checked = true;
3956: alert('$alert{reqd}\\n$alert{rest}');
3957: }
3958: }
3959: }
3960: return;
3961: }
3962: // ]]>
3963: </script>
3964:
3965: ENDSCRIPT
3966: }
3967:
1.3 raeburn 3968: sub print_autoenroll {
1.30 raeburn 3969: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3970: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 3971: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3972: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3973: $failsafesty = 'none';
3974: %failsafechecked = (
3975: off => ' checked="checked"',
3976: );
1.3 raeburn 3977: if (ref($settings) eq 'HASH') {
3978: if (exists($settings->{'run'})) {
3979: if ($settings->{'run'} eq '0') {
3980: $runoff = ' checked="checked" ';
3981: $runon = ' ';
3982: } else {
3983: $runon = ' checked="checked" ';
3984: $runoff = ' ';
3985: }
3986: } else {
3987: if ($autorun) {
3988: $runon = ' checked="checked" ';
3989: $runoff = ' ';
3990: } else {
3991: $runoff = ' checked="checked" ';
3992: $runon = ' ';
3993: }
3994: }
1.129 raeburn 3995: if (exists($settings->{'co-owners'})) {
3996: if ($settings->{'co-owners'} eq '0') {
3997: $coownersoff = ' checked="checked" ';
3998: $coownerson = ' ';
3999: } else {
4000: $coownerson = ' checked="checked" ';
4001: $coownersoff = ' ';
4002: }
4003: } else {
4004: $coownersoff = ' checked="checked" ';
4005: $coownerson = ' ';
4006: }
1.3 raeburn 4007: if (exists($settings->{'sender_domain'})) {
4008: $defdom = $settings->{'sender_domain'};
4009: }
1.399 raeburn 4010: if (exists($settings->{'failsafe'})) {
4011: $failsafe = $settings->{'failsafe'};
4012: if ($failsafe eq 'zero') {
1.400 raeburn 4013: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 4014: $failsafechecked{'off'} = '';
4015: $failsafesty = 'inline-block';
4016: } elsif ($failsafe eq 'any') {
4017: $failsafechecked{'any'} = ' checked="checked"';
4018: $failsafechecked{'off'} = '';
4019: }
4020: $autofailsafe = $settings->{'autofailsafe'};
4021: } elsif (exists($settings->{'autofailsafe'})) {
4022: $autofailsafe = $settings->{'autofailsafe'};
4023: if ($autofailsafe ne '') {
4024: $failsafechecked{'zero'} = ' checked="checked"';
4025: $failsafe = 'zero';
1.400 raeburn 4026: $failsafechecked{'off'} = '';
1.399 raeburn 4027: }
1.274 raeburn 4028: }
1.14 raeburn 4029: } else {
4030: if ($autorun) {
4031: $runon = ' checked="checked" ';
4032: $runoff = ' ';
4033: } else {
4034: $runoff = ' checked="checked" ';
4035: $runon = ' ';
4036: }
1.3 raeburn 4037: }
4038: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4039: my $notif_sender;
4040: if (ref($settings) eq 'HASH') {
4041: $notif_sender = $settings->{'sender_uname'};
4042: }
1.3 raeburn 4043: my $datatable='<tr class="LC_odd_row">'.
4044: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4045: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4046: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4047: $runon.' value="1" />'.&mt('Yes').'</label> '.
4048: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4049: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4050: '</tr><tr>'.
4051: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4052: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4053: &mt('username').': '.
4054: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4055: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4056: ': '.$domform.'</span></td></tr>'.
4057: '<tr class="LC_odd_row">'.
4058: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4059: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4060: '<input type="radio" name="autoassign_coowners"'.
4061: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4062: '<label><input type="radio" name="autoassign_coowners"'.
4063: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4064: '</tr><tr>'.
4065: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4066: '<td class="LC_left_item"><span class="LC_nobreak">'.
4067: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="off" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'off'}.' />'.&mt('Not in use').'</label></span> '.
4068: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="zero" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'zero'}.' />'.&mt('Retrieved section enrollment is zero').'</label></span><br />'.
4069: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="any" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'any'}.' />'.&mt('Retrieved section enrollment is zero or greater').'</label></span>'.
1.399 raeburn 4070: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4071: '<span class="LC_nobreak">'.
4072: &mt('Threshold for number of students in section to drop: [_1]',
4073: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4074: '</span></div></td></tr>';
1.274 raeburn 4075: $$rowtotal += 4;
1.3 raeburn 4076: return $datatable;
4077: }
4078:
4079: sub print_autoupdate {
1.30 raeburn 4080: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4081: my ($enable,$datatable);
1.3 raeburn 4082: if ($position eq 'top') {
1.385 raeburn 4083: my %choices = &Apache::lonlocal::texthash (
4084: run => 'Auto-update active?',
4085: classlists => 'Update information in classlists?',
4086: unexpired => 'Skip updates for users without active or future roles?',
4087: lastactive => 'Skip updates for inactive users?',
4088: );
4089: my $itemcount = 0;
1.3 raeburn 4090: my $updateon = ' ';
4091: my $updateoff = ' checked="checked" ';
4092: if (ref($settings) eq 'HASH') {
4093: if ($settings->{'run'} eq '1') {
4094: $updateon = $updateoff;
4095: $updateoff = ' ';
4096: }
4097: }
1.385 raeburn 4098: $enable = '<tr class="LC_odd_row">'.
4099: '<td>'.$choices{'run'}.'</td>'.
4100: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4101: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4102: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4103: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4104: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4105: '</tr>';
1.385 raeburn 4106: my @toggles = ('classlists','unexpired');
4107: my %defaultchecked = ('classlists' => 'off',
4108: 'unexpired' => 'off'
4109: );
4110: $$rowtotal ++;
4111: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4112: \%choices,$itemcount,'','','left','no');
4113: $datatable = $enable.$datatable;
4114: $$rowtotal += $itemcount;
4115: my $lastactiveon = ' ';
4116: my $lastactiveoff = ' checked="checked" ';
4117: my $lastactivestyle = 'none';
4118: my $lastactivedays;
4119: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4120: if (ref($settings) eq 'HASH') {
4121: if ($settings->{'lastactive'} =~ /^\d+$/) {
4122: $lastactiveon = $lastactiveoff;
4123: $lastactiveoff = ' ';
4124: $lastactivestyle = 'inline-block';
4125: $lastactivedays = $settings->{'lastactive'};
4126: }
4127: }
4128: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4129: $datatable .= '<tr'.$css_class.'>'.
4130: '<td>'.$choices{'lastactive'}.'</td>'.
4131: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4132: '<input type="radio" name="lastactive"'.
4133: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4134: ' <label>'.
4135: '<input type="radio" name="lastactive"'.
4136: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4137: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4138: ': '.&mt('inactive = no activity in last [_1] days',
4139: '<input type="text" size="5" name="lastactivedays" value="'.
4140: $lastactivedays.'" />').
4141: '</span></td>'.
4142: '</tr>';
4143: $$rowtotal ++;
1.131 raeburn 4144: } elsif ($position eq 'middle') {
4145: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4146: my $numinrow = 3;
4147: my $locknamesettings;
4148: $datatable .= &insttypes_row($settings,$types,$usertypes,
4149: $dom,$numinrow,$othertitle,
1.305 raeburn 4150: 'lockablenames',$rowtotal);
1.131 raeburn 4151: $$rowtotal ++;
1.3 raeburn 4152: } else {
1.44 raeburn 4153: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4154: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4155: 'permanentemail','id');
1.33 raeburn 4156: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4157: my $numrows = 0;
1.26 raeburn 4158: if (ref($types) eq 'ARRAY') {
4159: if (@{$types} > 0) {
4160: $datatable =
4161: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4162: \@fields,$types,\$numrows);
1.30 raeburn 4163: $$rowtotal += @{$types};
1.26 raeburn 4164: }
1.3 raeburn 4165: }
4166: $datatable .=
4167: &usertype_update_row($settings,{'default' => $othertitle},
4168: \%fieldtitles,\@fields,['default'],
4169: \$numrows);
1.30 raeburn 4170: $$rowtotal ++;
1.3 raeburn 4171: }
4172: return $datatable;
4173: }
4174:
1.125 raeburn 4175: sub print_autocreate {
4176: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4177: my (%createon,%createoff,%currhash);
1.125 raeburn 4178: my @types = ('xml','req');
4179: if (ref($settings) eq 'HASH') {
4180: foreach my $item (@types) {
4181: $createoff{$item} = ' checked="checked" ';
4182: $createon{$item} = ' ';
4183: if (exists($settings->{$item})) {
4184: if ($settings->{$item}) {
4185: $createon{$item} = ' checked="checked" ';
4186: $createoff{$item} = ' ';
4187: }
4188: }
4189: }
1.210 raeburn 4190: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4191: $currhash{$settings->{'xmldc'}} = 1;
4192: }
1.125 raeburn 4193: } else {
4194: foreach my $item (@types) {
4195: $createoff{$item} = ' checked="checked" ';
4196: $createon{$item} = ' ';
4197: }
4198: }
4199: $$rowtotal += 2;
1.191 raeburn 4200: my $numinrow = 2;
1.125 raeburn 4201: my $datatable='<tr class="LC_odd_row">'.
4202: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4203: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4204: '<input type="radio" name="autocreate_xml"'.
4205: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4206: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4207: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4208: '</td></tr><tr>'.
4209: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4210: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4211: '<input type="radio" name="autocreate_req"'.
4212: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4213: '<label><input type="radio" name="autocreate_req"'.
4214: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4215: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4216: 'autocreate_xmldc',%currhash);
1.247 raeburn 4217: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4218: if ($numdc > 1) {
1.247 raeburn 4219: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4220: '</td><td class="LC_left_item">';
1.125 raeburn 4221: } else {
1.247 raeburn 4222: $datatable .= &mt('Course creation processed as:').
4223: '</td><td class="LC_right_item">';
1.125 raeburn 4224: }
1.247 raeburn 4225: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4226: $$rowtotal += $rows;
1.125 raeburn 4227: return $datatable;
4228: }
4229:
1.23 raeburn 4230: sub print_directorysrch {
1.277 raeburn 4231: my ($position,$dom,$settings,$rowtotal) = @_;
4232: my $datatable;
4233: if ($position eq 'top') {
4234: my $instsrchon = ' ';
4235: my $instsrchoff = ' checked="checked" ';
4236: my ($exacton,$containson,$beginson);
4237: my $instlocalon = ' ';
4238: my $instlocaloff = ' checked="checked" ';
4239: if (ref($settings) eq 'HASH') {
4240: if ($settings->{'available'} eq '1') {
4241: $instsrchon = $instsrchoff;
4242: $instsrchoff = ' ';
4243: }
4244: if ($settings->{'localonly'} eq '1') {
4245: $instlocalon = $instlocaloff;
4246: $instlocaloff = ' ';
4247: }
4248: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4249: foreach my $type (@{$settings->{'searchtypes'}}) {
4250: if ($type eq 'exact') {
4251: $exacton = ' checked="checked" ';
4252: } elsif ($type eq 'contains') {
4253: $containson = ' checked="checked" ';
4254: } elsif ($type eq 'begins') {
4255: $beginson = ' checked="checked" ';
4256: }
4257: }
4258: } else {
4259: if ($settings->{'searchtypes'} eq 'exact') {
4260: $exacton = ' checked="checked" ';
4261: } elsif ($settings->{'searchtypes'} eq 'contains') {
4262: $containson = ' checked="checked" ';
4263: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4264: $exacton = ' checked="checked" ';
4265: $containson = ' checked="checked" ';
4266: }
4267: }
1.277 raeburn 4268: }
4269: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4270: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4271:
4272: my $numinrow = 4;
4273: my $cansrchrow = 0;
4274: $datatable='<tr class="LC_odd_row">'.
4275: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4276: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4277: '<input type="radio" name="dirsrch_available"'.
4278: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4279: '<label><input type="radio" name="dirsrch_available"'.
4280: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4281: '</tr><tr>'.
4282: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4283: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4284: '<input type="radio" name="dirsrch_instlocalonly"'.
4285: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4286: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4287: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4288: '</tr>';
4289: $$rowtotal += 2;
4290: if (ref($usertypes) eq 'HASH') {
4291: if (keys(%{$usertypes}) > 0) {
4292: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4293: $numinrow,$othertitle,'cansearch',
4294: $rowtotal);
1.277 raeburn 4295: $cansrchrow = 1;
1.25 raeburn 4296: }
1.23 raeburn 4297: }
1.277 raeburn 4298: if ($cansrchrow) {
4299: $$rowtotal ++;
4300: $datatable .= '<tr>';
4301: } else {
4302: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4303: }
1.277 raeburn 4304: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4305: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4306: foreach my $title (@{$titleorder}) {
4307: if (defined($searchtitles->{$title})) {
4308: my $check = ' ';
4309: if (ref($settings) eq 'HASH') {
4310: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4311: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4312: $check = ' checked="checked" ';
4313: }
1.39 raeburn 4314: }
1.25 raeburn 4315: }
1.277 raeburn 4316: $datatable .= '<td class="LC_left_item">'.
4317: '<span class="LC_nobreak"><label>'.
4318: '<input type="checkbox" name="searchby" '.
4319: 'value="'.$title.'"'.$check.'/>'.
4320: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4321: }
4322: }
1.277 raeburn 4323: $datatable .= '</tr></table></td></tr>';
4324: $$rowtotal ++;
4325: if ($cansrchrow) {
4326: $datatable .= '<tr class="LC_odd_row">';
4327: } else {
4328: $datatable .= '<tr>';
4329: }
4330: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4331: '<td class="LC_left_item" colspan="2">'.
4332: '<span class="LC_nobreak"><label>'.
4333: '<input type="checkbox" name="searchtypes" '.
4334: $exacton.' value="exact" />'.&mt('Exact match').
4335: '</label> '.
4336: '<label><input type="checkbox" name="searchtypes" '.
4337: $beginson.' value="begins" />'.&mt('Begins with').
4338: '</label> '.
4339: '<label><input type="checkbox" name="searchtypes" '.
4340: $containson.' value="contains" />'.&mt('Contains').
4341: '</label></span></td></tr>';
4342: $$rowtotal ++;
1.26 raeburn 4343: } else {
1.277 raeburn 4344: my $domsrchon = ' checked="checked" ';
4345: my $domsrchoff = ' ';
4346: my $domlocalon = ' ';
4347: my $domlocaloff = ' checked="checked" ';
4348: if (ref($settings) eq 'HASH') {
4349: if ($settings->{'lclocalonly'} eq '1') {
4350: $domlocalon = $domlocaloff;
4351: $domlocaloff = ' ';
4352: }
4353: if ($settings->{'lcavailable'} eq '0') {
4354: $domsrchoff = $domsrchon;
4355: $domsrchon = ' ';
4356: }
4357: }
4358: $datatable='<tr class="LC_odd_row">'.
4359: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4360: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4361: '<input type="radio" name="dirsrch_domavailable"'.
4362: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4363: '<label><input type="radio" name="dirsrch_domavailable"'.
4364: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4365: '</tr><tr>'.
4366: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4367: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4368: '<input type="radio" name="dirsrch_domlocalonly"'.
4369: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4370: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4371: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4372: '</tr>';
4373: $$rowtotal += 2;
1.26 raeburn 4374: }
1.25 raeburn 4375: return $datatable;
4376: }
4377:
1.28 raeburn 4378: sub print_contacts {
1.286 raeburn 4379: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4380: my $datatable;
4381: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4382: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4383: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4384: if ($position eq 'top') {
4385: if (ref($settings) eq 'HASH') {
4386: foreach my $item (@contacts) {
4387: if (exists($settings->{$item})) {
4388: $to{$item} = $settings->{$item};
4389: }
4390: }
4391: }
4392: } elsif ($position eq 'middle') {
4393: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4394: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4395: foreach my $type (@mailings) {
4396: $otheremails{$type} = '';
4397: }
1.340 raeburn 4398: } elsif ($position eq 'lower') {
4399: if (ref($settings) eq 'HASH') {
4400: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4401: %lonstatus = %{$settings->{'lonstatus'}};
4402: }
4403: }
1.286 raeburn 4404: } else {
4405: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4406: foreach my $type (@mailings) {
4407: $otheremails{$type} = '';
4408: }
1.286 raeburn 4409: $bccemails{'helpdeskmail'} = '';
4410: $bccemails{'otherdomsmail'} = '';
4411: $includestr{'helpdeskmail'} = '';
4412: $includestr{'otherdomsmail'} = '';
4413: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4414: }
1.28 raeburn 4415: if (ref($settings) eq 'HASH') {
1.340 raeburn 4416: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4417: foreach my $type (@mailings) {
4418: if (exists($settings->{$type})) {
4419: if (ref($settings->{$type}) eq 'HASH') {
4420: foreach my $item (@contacts) {
4421: if ($settings->{$type}{$item}) {
4422: $checked{$type}{$item} = ' checked="checked" ';
4423: }
4424: }
4425: $otheremails{$type} = $settings->{$type}{'others'};
4426: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4427: $bccemails{$type} = $settings->{$type}{'bcc'};
4428: if ($settings->{$type}{'include'} ne '') {
4429: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4430: $includestr{$type} = &unescape($includestr{$type});
4431: }
4432: }
4433: }
4434: } elsif ($type eq 'lonstatusmail') {
4435: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4436: }
1.28 raeburn 4437: }
4438: }
1.286 raeburn 4439: if ($position eq 'bottom') {
4440: foreach my $type (@mailings) {
4441: $bccemails{$type} = $settings->{$type}{'bcc'};
4442: if ($settings->{$type}{'include'} ne '') {
4443: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4444: $includestr{$type} = &unescape($includestr{$type});
4445: }
4446: }
4447: if (ref($settings->{'helpform'}) eq 'HASH') {
4448: if (ref($fields) eq 'ARRAY') {
4449: foreach my $field (@{$fields}) {
4450: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4451: }
1.286 raeburn 4452: }
4453: if (exists($settings->{'helpform'}{'maxsize'})) {
4454: $maxsize = $settings->{'helpform'}{'maxsize'};
4455: } else {
1.289 raeburn 4456: $maxsize = '1.0';
1.286 raeburn 4457: }
4458: } else {
4459: if (ref($fields) eq 'ARRAY') {
4460: foreach my $field (@{$fields}) {
4461: $currfield{$field} = 'yes';
1.134 raeburn 4462: }
1.28 raeburn 4463: }
1.286 raeburn 4464: $maxsize = '1.0';
1.28 raeburn 4465: }
4466: }
4467: } else {
1.286 raeburn 4468: if ($position eq 'top') {
4469: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4470: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4471: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4472: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4473: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4474: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4475: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4476: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4477: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4478: } elsif ($position eq 'bottom') {
4479: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4480: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4481: if (ref($fields) eq 'ARRAY') {
4482: foreach my $field (@{$fields}) {
4483: $currfield{$field} = 'yes';
4484: }
4485: }
4486: $maxsize = '1.0';
4487: }
1.28 raeburn 4488: }
4489: my ($titles,$short_titles) = &contact_titles();
4490: my $rownum = 0;
4491: my $css_class;
1.286 raeburn 4492: if ($position eq 'top') {
4493: foreach my $item (@contacts) {
4494: $css_class = $rownum%2?' class="LC_odd_row"':'';
4495: $datatable .= '<tr'.$css_class.'>'.
4496: '<td><span class="LC_nobreak">'.$titles->{$item}.
4497: '</span></td><td class="LC_right_item">'.
4498: '<input type="text" name="'.$item.'" value="'.
4499: $to{$item}.'" /></td></tr>';
4500: $rownum ++;
4501: }
1.315 raeburn 4502: } elsif ($position eq 'bottom') {
4503: $css_class = $rownum%2?' class="LC_odd_row"':'';
4504: $datatable .= '<tr'.$css_class.'>'.
4505: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4506: &mt('(e-mail, subject, and description always shown)').
4507: '</td><td class="LC_left_item">';
4508: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4509: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4510: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4511: foreach my $field (@{$fields}) {
4512: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4513: if (($field eq 'screenshot') || ($field eq 'cc')) {
4514: $datatable .= ' '.&mt('(logged-in users)');
4515: }
4516: $datatable .='</td><td>';
4517: my $clickaction;
4518: if ($field eq 'screenshot') {
4519: $clickaction = ' onclick="screenshotSize(this);"';
4520: }
4521: if (ref($possoptions->{$field}) eq 'ARRAY') {
4522: foreach my $option (@{$possoptions->{$field}}) {
4523: my $checked;
4524: if ($currfield{$field} eq $option) {
4525: $checked = ' checked="checked"';
4526: }
4527: $datatable .= '<span class="LC_nobreak"><label>'.
4528: '<input type="radio" name="helpform_'.$field.'" '.
4529: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4530: '</label></span>'.(' 'x2);
4531: }
4532: }
4533: if ($field eq 'screenshot') {
4534: my $display;
4535: if ($currfield{$field} eq 'no') {
4536: $display = ' style="display:none"';
4537: }
1.334 raeburn 4538: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4539: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4540: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4541: }
4542: $datatable .= '</td></tr>';
4543: }
4544: $datatable .= '</table>';
4545: }
4546: $datatable .= '</td></tr>'."\n";
4547: $rownum ++;
4548: }
1.340 raeburn 4549: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4550: foreach my $type (@mailings) {
4551: $css_class = $rownum%2?' class="LC_odd_row"':'';
4552: $datatable .= '<tr'.$css_class.'>'.
4553: '<td><span class="LC_nobreak">'.
4554: $titles->{$type}.': </span></td>'.
4555: '<td class="LC_left_item">';
4556: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4557: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4558: }
4559: $datatable .= '<span class="LC_nobreak">';
4560: foreach my $item (@contacts) {
4561: $datatable .= '<label>'.
4562: '<input type="checkbox" name="'.$type.'"'.
4563: $checked{$type}{$item}.
4564: ' value="'.$item.'" />'.$short_titles->{$item}.
4565: '</label> ';
4566: }
4567: $datatable .= '</span><br />'.&mt('Others').': '.
4568: '<input type="text" name="'.$type.'_others" '.
4569: 'value="'.$otheremails{$type}.'" />';
4570: my %locchecked;
4571: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4572: foreach my $loc ('s','b') {
4573: if ($includeloc{$type} eq $loc) {
4574: $locchecked{$loc} = ' checked="checked"';
4575: last;
4576: }
4577: }
4578: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4579: '<input type="text" name="'.$type.'_bcc" '.
4580: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4581: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4582: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4583: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4584: '<span class="LC_nobreak">'.&mt('Location:').' '.
4585: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4586: (' 'x2).
4587: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4588: '</span></fieldset>';
4589: }
4590: $datatable .= '</td></tr>'."\n";
4591: $rownum ++;
4592: }
1.28 raeburn 4593: }
1.286 raeburn 4594: if ($position eq 'middle') {
4595: my %choices;
1.340 raeburn 4596: my $corelink = &core_link_msu();
4597: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4598: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4599: $corelink);
4600: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4601: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4602: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4603: 'reportupdates' => 'on',
4604: 'reportstatus' => 'on');
1.286 raeburn 4605: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4606: \%choices,$rownum);
4607: $datatable .= $reports;
1.340 raeburn 4608: } elsif ($position eq 'lower') {
1.378 raeburn 4609: my (%current,%excluded,%weights);
1.340 raeburn 4610: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4611: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4612: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4613: } else {
1.378 raeburn 4614: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4615: }
4616: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4617: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4618: } else {
1.378 raeburn 4619: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4620: }
4621: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4622: foreach my $type ('E','W','N','U') {
1.340 raeburn 4623: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4624: $weights{$type} = $lonstatus{'weights'}{$type};
4625: } else {
4626: $weights{$type} = $defaults->{$type};
4627: }
4628: }
4629: } else {
1.341 raeburn 4630: foreach my $type ('E','W','N','U') {
1.340 raeburn 4631: $weights{$type} = $defaults->{$type};
4632: }
4633: }
4634: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4635: if (@{$lonstatus{'excluded'}} > 0) {
4636: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4637: }
4638: }
1.425 raeburn 4639: foreach my $item ('errorthreshold','errorsysmail') {
1.378 raeburn 4640: $css_class = $rownum%2?' class="LC_odd_row"':'';
4641: $datatable .= '<tr'.$css_class.'>'.
4642: '<td class="LC_left_item"><span class="LC_nobreak">'.
4643: $titles->{$item}.
4644: '</span></td><td class="LC_left_item">'.
4645: '<input type="text" name="'.$item.'" value="'.
4646: $current{$item}.'" size="5" /></td></tr>';
4647: $rownum ++;
4648: }
1.340 raeburn 4649: $css_class = $rownum%2?' class="LC_odd_row"':'';
4650: $datatable .= '<tr'.$css_class.'>'.
4651: '<td class="LC_left_item">'.
4652: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4653: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4654: foreach my $type ('E','W','N','U') {
1.340 raeburn 4655: $datatable .= '<td>'.$names->{$type}.'<br />'.
4656: '<input type="text" name="errorweights_'.$type.'" value="'.
4657: $weights{$type}.'" size="5" /></td>';
4658: }
4659: $datatable .= '</tr></table></tr>';
4660: $rownum ++;
4661: $css_class = $rownum%2?' class="LC_odd_row"':'';
4662: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4663: $titles->{'errorexcluded'}.'</td>'.
4664: '<td class="LC_left_item"><table>';
4665: my $numinrow = 4;
4666: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4667: for (my $i=0; $i<@ids; $i++) {
4668: my $rem = $i%($numinrow);
4669: if ($rem == 0) {
4670: if ($i > 0) {
4671: $datatable .= '</tr>';
4672: }
4673: $datatable .= '<tr>';
4674: }
4675: my $check;
4676: if ($excluded{$ids[$i]}) {
4677: $check = ' checked="checked" ';
4678: }
4679: $datatable .= '<td class="LC_left_item">'.
4680: '<span class="LC_nobreak"><label>'.
4681: '<input type="checkbox" name="errorexcluded" '.
4682: 'value="'.$ids[$i].'"'.$check.' />'.
4683: $ids[$i].'</label></span></td>';
4684: }
4685: my $colsleft = $numinrow - @ids%($numinrow);
4686: if ($colsleft > 1 ) {
4687: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4688: ' </td>';
4689: } elsif ($colsleft == 1) {
4690: $datatable .= '<td class="LC_left_item"> </td>';
4691: }
4692: $datatable .= '</tr></table></td></tr>';
4693: $rownum ++;
1.286 raeburn 4694: } elsif ($position eq 'bottom') {
1.315 raeburn 4695: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4696: my (@posstypes,%usertypeshash);
4697: if (ref($types) eq 'ARRAY') {
4698: @posstypes = @{$types};
4699: }
4700: if (@posstypes) {
4701: if (ref($usertypes) eq 'HASH') {
4702: %usertypeshash = %{$usertypes};
4703: }
4704: my @overridden;
4705: my $numinrow = 4;
4706: if (ref($settings) eq 'HASH') {
4707: if (ref($settings->{'overrides'}) eq 'HASH') {
4708: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4709: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4710: push(@overridden,$key);
4711: foreach my $item (@contacts) {
4712: if ($settings->{'overrides'}{$key}{$item}) {
4713: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4714: }
4715: }
4716: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4717: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4718: $includeloc{'override_'.$key} = '';
4719: $includestr{'override_'.$key} = '';
4720: if ($settings->{'overrides'}{$key}{'include'} ne '') {
1.425 raeburn 4721: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
1.315 raeburn 4722: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4723: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4724: }
1.286 raeburn 4725: }
4726: }
4727: }
1.315 raeburn 4728: }
4729: my $customclass = 'LC_helpdesk_override';
4730: my $optionsprefix = 'LC_options_helpdesk_';
4731:
4732: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4733: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4734: $numinrow,$othertitle,'overrides',
4735: \$rownum,$onclicktypes,$customclass);
4736: $rownum ++;
4737: $usertypeshash{'default'} = $othertitle;
4738: foreach my $status (@posstypes) {
4739: my $css_class;
4740: if ($rownum%2) {
4741: $css_class = 'LC_odd_row ';
4742: }
4743: $css_class .= $customclass;
4744: my $rowid = $optionsprefix.$status;
4745: my $hidden = 1;
4746: my $currstyle = 'display:none';
4747: if (grep(/^\Q$status\E$/,@overridden)) {
4748: $currstyle = 'display:table-row';
4749: $hidden = 0;
4750: }
4751: my $key = 'override_'.$status;
4752: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4753: $includeloc{$key},$includestr{$key},$status,$rowid,
4754: $usertypeshash{$status},$css_class,$currstyle,
4755: \@contacts,$short_titles);
4756: unless ($hidden) {
4757: $rownum ++;
1.286 raeburn 4758: }
4759: }
1.134 raeburn 4760: }
1.28 raeburn 4761: }
1.30 raeburn 4762: $$rowtotal += $rownum;
1.28 raeburn 4763: return $datatable;
4764: }
4765:
1.340 raeburn 4766: sub core_link_msu {
4767: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4768: &mt('LON-CAPA core group - MSU'),600,500);
4769: }
4770:
1.315 raeburn 4771: sub overridden_helpdesk {
4772: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4773: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4774: my $class = 'LC_left_item';
4775: if ($css_class) {
4776: $css_class = ' class="'.$css_class.'"';
4777: }
4778: if ($rowid) {
4779: $rowid = ' id="'.$rowid.'"';
4780: }
4781: if ($rowstyle) {
4782: $rowstyle = ' style="'.$rowstyle.'"';
4783: }
4784: my ($output,$description);
4785: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4786: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4787: "<td>$description</td>\n".
4788: '<td class="'.$class.'" colspan="2">'.
4789: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4790: '<span class="LC_nobreak">';
4791: if (ref($contacts) eq 'ARRAY') {
4792: foreach my $item (@{$contacts}) {
4793: my $check;
4794: if (ref($checked) eq 'HASH') {
4795: $check = $checked->{$item};
4796: }
4797: my $title;
4798: if (ref($short_titles) eq 'HASH') {
1.425 raeburn 4799: $title = $short_titles->{$item};
1.315 raeburn 4800: }
4801: $output .= '<label>'.
4802: '<input type="checkbox" name="override_'.$type.'"'.$check.
4803: ' value="'.$item.'" />'.$title.'</label> ';
4804: }
4805: }
4806: $output .= '</span><br />'.&mt('Others').': '.
4807: '<input type="text" name="override_'.$type.'_others" '.
4808: 'value="'.$otheremails.'" />';
4809: my %locchecked;
4810: foreach my $loc ('s','b') {
4811: if ($includeloc eq $loc) {
4812: $locchecked{$loc} = ' checked="checked"';
4813: last;
4814: }
4815: }
4816: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4817: '<input type="text" name="override_'.$type.'_bcc" '.
4818: 'value="'.$bccemails.'" /></fieldset>'.
4819: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4820: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4821: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4822: '<span class="LC_nobreak">'.&mt('Location:').' '.
4823: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4824: (' 'x2).
4825: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4826: '</span></fieldset>'.
4827: '</td></tr>'."\n";
4828: return $output;
4829: }
4830:
1.286 raeburn 4831: sub contacts_javascript {
4832: return <<"ENDSCRIPT";
4833:
4834: <script type="text/javascript">
4835: // <![CDATA[
4836:
4837: function screenshotSize(field) {
4838: if (document.getElementById('help_screenshotsize')) {
4839: if (field.value == 'no') {
1.289 raeburn 4840: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4841: } else {
4842: document.getElementById('help_screenshotsize').style.display="";
4843: }
4844: }
4845: return;
4846: }
4847:
1.315 raeburn 4848: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4849: if (form.elements[checkbox].length != undefined) {
4850: var count = 0;
4851: if (docount) {
4852: for (var i=0; i<form.elements[checkbox].length; i++) {
4853: if (form.elements[checkbox][i].checked) {
4854: count ++;
4855: }
4856: }
4857: }
4858: for (var i=0; i<form.elements[checkbox].length; i++) {
4859: var type = form.elements[checkbox][i].value;
4860: if (document.getElementById(prefix+type)) {
4861: if (form.elements[checkbox][i].checked) {
4862: document.getElementById(prefix+type).style.display = 'table-row';
4863: if (count % 2 == 1) {
4864: document.getElementById(prefix+type).className = target+' LC_odd_row';
4865: } else {
4866: document.getElementById(prefix+type).className = target;
4867: }
4868: count ++;
4869: } else {
4870: document.getElementById(prefix+type).style.display = 'none';
4871: }
4872: }
4873: }
4874: }
4875: return;
4876: }
4877:
1.286 raeburn 4878: // ]]>
4879: </script>
4880:
4881: ENDSCRIPT
4882: }
4883:
1.118 jms 4884: sub print_helpsettings {
1.282 raeburn 4885: my ($position,$dom,$settings,$rowtotal) = @_;
4886: my $confname = $dom.'-domainconfig';
1.285 raeburn 4887: my $formname = 'display';
1.168 raeburn 4888: my ($datatable,$itemcount);
1.282 raeburn 4889: if ($position eq 'top') {
4890: $itemcount = 1;
4891: my (%choices,%defaultchecked,@toggles);
4892: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4893: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4894: &mt('LON-CAPA bug tracker'),600,500));
4895: %defaultchecked = ('submitbugs' => 'on');
4896: @toggles = ('submitbugs');
4897: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4898: \%choices,$itemcount);
4899: $$rowtotal ++;
4900: } else {
4901: my $css_class;
4902: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4903: my (%customroles,%ordered,%current);
1.301 raeburn 4904: if (ref($settings) eq 'HASH') {
4905: if (ref($settings->{'adhoc'}) eq 'HASH') {
4906: %current = %{$settings->{'adhoc'}};
4907: }
1.285 raeburn 4908: }
4909: my $count = 0;
4910: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4911: if ($key=~/^rolesdef\_(\w+)$/) {
4912: my $rolename = $1;
1.285 raeburn 4913: my (%privs,$order);
1.282 raeburn 4914: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4915: $customroles{$rolename} = \%privs;
1.285 raeburn 4916: if (ref($current{$rolename}) eq 'HASH') {
4917: $order = $current{$rolename}{'order'};
4918: }
4919: if ($order eq '') {
4920: $order = $count;
4921: }
4922: $ordered{$order} = $rolename;
4923: $count++;
4924: }
4925: }
4926: my $maxnum = scalar(keys(%ordered));
4927: my @roles_by_num = ();
4928: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4929: push(@roles_by_num,$item);
4930: }
4931: my $context = 'domprefs';
4932: my $crstype = 'Course';
4933: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4934: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4935: my ($numstatustypes,@jsarray);
4936: if (ref($types) eq 'ARRAY') {
4937: if (@{$types} > 0) {
4938: $numstatustypes = scalar(@{$types});
4939: push(@accesstypes,'status');
4940: @jsarray = ('bystatus');
1.282 raeburn 4941: }
4942: }
1.290 raeburn 4943: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4944: if (keys(%domhelpdesk)) {
4945: push(@accesstypes,('inc','exc'));
4946: push(@jsarray,('notinc','notexc'));
4947: }
4948: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4949: my $context = 'domprefs';
4950: my $crstype = 'Course';
1.285 raeburn 4951: my $prefix = 'helproles_';
4952: my $add_class = 'LC_hidden';
4953: foreach my $num (@roles_by_num) {
4954: my $role = $ordered{$num};
4955: my ($desc,$access,@statuses);
4956: if (ref($current{$role}) eq 'HASH') {
4957: $desc = $current{$role}{'desc'};
4958: $access = $current{$role}{'access'};
4959: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4960: @statuses = @{$current{$role}{'insttypes'}};
4961: }
4962: }
4963: if ($desc eq '') {
4964: $desc = $role;
4965: }
4966: my $identifier = 'custhelp'.$num;
1.282 raeburn 4967: my %full=();
4968: my %levels= (
4969: course => {},
4970: domain => {},
4971: system => {},
4972: );
4973: my %levelscurrent=(
4974: course => {},
4975: domain => {},
4976: system => {},
4977: );
4978: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4979: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4980: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4981: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4982: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4983: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4984: for (my $k=0; $k<=$maxnum; $k++) {
4985: my $vpos = $k+1;
4986: my $selstr;
4987: if ($k == $num) {
4988: $selstr = ' selected="selected" ';
4989: }
4990: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4991: }
4992: $datatable .= '</select>'.(' 'x2).
4993: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4994: '</td>'.
4995: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4996: &mt('Name shown to users:').
4997: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4998: '</fieldset>'.
4999: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
5000: $othertitle,$usertypes,$types,\%domhelpdesk).
5001: '<fieldset>'.
5002: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 5003: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 5004: \%levelscurrent,$identifier,
5005: 'LC_hidden',$prefix.$num.'_privs').
5006: '</fieldset></td>';
1.282 raeburn 5007: $itemcount ++;
5008: }
5009: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5010: my $newcust = 'custhelp'.$count;
5011: my (%privs,%levelscurrent);
5012: my %full=();
5013: my %levels= (
5014: course => {},
5015: domain => {},
5016: system => {},
5017: );
5018: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
5019: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5020: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5021: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5022: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5023: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5024: for (my $k=0; $k<$maxnum+1; $k++) {
5025: my $vpos = $k+1;
5026: my $selstr;
5027: if ($k == $maxnum) {
5028: $selstr = ' selected="selected" ';
5029: }
5030: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5031: }
5032: $datatable .= '</select> '."\n".
1.282 raeburn 5033: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5034: '</label></span></td>'.
1.285 raeburn 5035: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5036: '<span class="LC_nobreak">'.
5037: &mt('Internal name:').
5038: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5039: '</span>'.(' 'x4).
5040: '<span class="LC_nobreak">'.
5041: &mt('Name shown to users:').
5042: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5043: '</span></fieldset>'.
5044: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5045: $usertypes,$types,\%domhelpdesk).
5046: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5047: &Apache::lonuserutils::custom_role_header($context,$crstype,
5048: \@templateroles,$newcust).
5049: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5050: \%levelscurrent,$newcust).
1.334 raeburn 5051: '</fieldset>'.
5052: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5053: '</td></tr>';
1.282 raeburn 5054: $count ++;
5055: $$rowtotal += $count;
5056: }
1.166 raeburn 5057: return $datatable;
1.121 raeburn 5058: }
5059:
1.285 raeburn 5060: sub adhocbutton {
5061: my ($prefix,$num,$field,$visibility) = @_;
5062: my %lt = &Apache::lonlocal::texthash(
5063: show => 'Show details',
5064: hide => 'Hide details',
5065: );
5066: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5067: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5068: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5069: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5070: }
5071:
5072: sub helpsettings_javascript {
5073: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5074: return unless(ref($roles_by_num) eq 'ARRAY');
5075: my %html_js_lt = &Apache::lonlocal::texthash(
5076: show => 'Show details',
5077: hide => 'Hide details',
5078: );
5079: &html_escape(\%html_js_lt);
5080: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5081: return <<"ENDSCRIPT";
5082: <script type="text/javascript">
5083: // <![CDATA[
5084:
5085: function reorderHelpRoles(form,item) {
5086: var changedVal;
5087: $jstext
5088: var newpos = 'helproles_${total}_pos';
5089: var maxh = 1 + $total;
5090: var current = new Array();
5091: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5092: if (item == newpos) {
5093: changedVal = newitemVal;
5094: } else {
5095: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5096: current[newitemVal] = newpos;
5097: }
5098: for (var i=0; i<helproles.length; i++) {
5099: var elementName = 'helproles_'+helproles[i]+'_pos';
5100: if (elementName != item) {
5101: if (form.elements[elementName]) {
5102: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5103: current[currVal] = elementName;
5104: }
5105: }
5106: }
5107: var oldVal;
5108: for (var j=0; j<maxh; j++) {
5109: if (current[j] == undefined) {
5110: oldVal = j;
5111: }
5112: }
5113: if (oldVal < changedVal) {
5114: for (var k=oldVal+1; k<=changedVal ; k++) {
5115: var elementName = current[k];
5116: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5117: }
5118: } else {
5119: for (var k=changedVal; k<oldVal; k++) {
5120: var elementName = current[k];
5121: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5122: }
5123: }
5124: return;
5125: }
5126:
5127: function helpdeskAccess(num) {
5128: var curraccess = null;
5129: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5130: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5131: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5132: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5133: }
5134: }
5135: }
5136: var shown = Array();
5137: var hidden = Array();
5138: if (curraccess == 'none') {
5139: hidden = Array('$hiddenstr');
5140: } else {
5141: if (curraccess == 'status') {
5142: shown = Array('bystatus');
5143: hidden = Array('notinc','notexc');
5144: } else {
5145: if (curraccess == 'exc') {
5146: shown = Array('notexc');
5147: hidden = Array('notinc','bystatus');
5148: }
5149: if (curraccess == 'inc') {
5150: shown = Array('notinc');
5151: hidden = Array('notexc','bystatus');
5152: }
1.293 raeburn 5153: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5154: hidden = Array('notinc','notexc','bystatus');
5155: }
5156: }
5157: }
5158: if (hidden.length > 0) {
5159: for (var i=0; i<hidden.length; i++) {
5160: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5161: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5162: }
5163: }
5164: }
5165: if (shown.length > 0) {
5166: for (var i=0; i<shown.length; i++) {
5167: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5168: if (shown[i] == 'privs') {
5169: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5170: } else {
5171: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5172: }
5173: }
5174: }
5175: }
5176: return;
5177: }
5178:
5179: function toggleHelpdeskItem(num,field) {
5180: if (document.getElementById('helproles_'+num+'_'+field)) {
5181: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5182: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5183: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5184: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5185: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5186: }
5187: } else {
5188: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5189: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5190: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5191: }
5192: }
5193: }
5194: return;
5195: }
5196:
5197: // ]]>
5198: </script>
5199:
5200: ENDSCRIPT
5201: }
5202:
5203: sub helpdeskroles_access {
5204: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5205: $usertypes,$types,$domhelpdesk) = @_;
5206: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5207: my %lt = &Apache::lonlocal::texthash(
5208: 'rou' => 'Role usage',
5209: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5210: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5211: 'dh' => 'All with domain helpdesk role',
5212: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5213: 'none' => 'None',
5214: 'status' => 'Determined based on institutional status',
5215: 'inc' => 'Include all, but exclude specific personnel',
5216: 'exc' => 'Exclude all, but include specific personnel',
5217: );
5218: my %usecheck = (
5219: all => ' checked="checked"',
5220: );
5221: my %displaydiv = (
5222: status => 'none',
5223: inc => 'none',
5224: exc => 'none',
5225: priv => 'block',
5226: );
5227: my $output;
5228: if (ref($current) eq 'HASH') {
5229: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5230: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5231: $usecheck{$current->{access}} = $usecheck{'all'};
5232: delete($usecheck{'all'});
5233: if ($current->{access} =~ /^(status|inc|exc)$/) {
5234: my $access = $1;
5235: $displaydiv{$access} = 'inline';
5236: } elsif ($current->{access} eq 'none') {
5237: $displaydiv{'priv'} = 'none';
5238: }
5239: }
5240: }
5241: }
5242: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5243: '<p>'.$lt{'whi'}.'</p>';
5244: foreach my $access (@{$accesstypes}) {
5245: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5246: ' onclick="helpdeskAccess('."'$num'".');" />'.
5247: $lt{$access}.'</label>';
5248: if ($access eq 'status') {
5249: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5250: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5251: $othertitle,$usertypes,$types).
5252: '</div>';
5253: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5254: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5255: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5256: '</div>';
5257: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5258: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5259: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5260: '</div>';
5261: }
5262: $output .= '</p>';
5263: }
5264: $output .= '</fieldset>';
5265: return $output;
5266: }
5267:
1.121 raeburn 5268: sub radiobutton_prefs {
1.192 raeburn 5269: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5270: $additional,$align,$firstval) = @_;
1.121 raeburn 5271: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5272: (ref($choices) eq 'HASH'));
5273:
1.170 raeburn 5274: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5275:
5276: foreach my $item (@{$toggles}) {
5277: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5278: $checkedon{$item} = ' checked="checked" ';
5279: $checkedoff{$item} = ' ';
1.121 raeburn 5280: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5281: $checkedoff{$item} = ' checked="checked" ';
5282: $checkedon{$item} = ' ';
5283: }
5284: }
5285: if (ref($settings) eq 'HASH') {
1.121 raeburn 5286: foreach my $item (@{$toggles}) {
1.118 jms 5287: if ($settings->{$item} eq '1') {
5288: $checkedon{$item} = ' checked="checked" ';
5289: $checkedoff{$item} = ' ';
5290: } elsif ($settings->{$item} eq '0') {
5291: $checkedoff{$item} = ' checked="checked" ';
5292: $checkedon{$item} = ' ';
5293: }
5294: }
1.121 raeburn 5295: }
1.192 raeburn 5296: if ($onclick) {
5297: $onclick = ' onclick="'.$onclick.'"';
5298: }
1.121 raeburn 5299: foreach my $item (@{$toggles}) {
1.118 jms 5300: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5301: $datatable .=
1.306 raeburn 5302: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5303: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5304: '</span></td>';
5305: if ($align eq 'left') {
5306: $datatable .= '<td class="LC_left_item">';
5307: } else {
5308: $datatable .= '<td class="LC_right_item">';
5309: }
1.385 raeburn 5310: $datatable .= '<span class="LC_nobreak">';
5311: if ($firstval eq 'no') {
5312: $datatable .=
5313: '<label><input type="radio" name="'.
5314: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5315: '</label> <label><input type="radio" name="'.$item.'" '.
5316: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5317: } else {
5318: $datatable .=
5319: '<label><input type="radio" name="'.
5320: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5321: '</label> <label><input type="radio" name="'.$item.'" '.
5322: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5323: }
5324: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5325: $itemcount ++;
1.121 raeburn 5326: }
5327: return ($datatable,$itemcount);
5328: }
5329:
1.267 raeburn 5330: sub print_ltitools {
1.421 raeburn 5331: my ($position,$dom,$settings,$rowtotal) = @_;
5332: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5333: if (ref($settings) eq 'HASH') {
1.421 raeburn 5334: if ($position eq 'top') {
5335: if (exists($settings->{'encrypt'})) {
5336: if (ref($settings->{'encrypt'}) eq 'HASH') {
5337: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5338: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5339: }
5340: }
1.267 raeburn 5341: }
1.421 raeburn 5342: if (exists($settings->{'private'})) {
5343: if (ref($settings->{'private'}) eq 'HASH') {
5344: if (ref($settings->{'private'}) eq 'HASH') {
5345: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5346: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5347: }
5348: }
5349: }
5350: }
1.421 raeburn 5351: } elsif ($position eq 'middle') {
5352: if (exists($settings->{'rules'})) {
5353: if (ref($settings->{'rules'}) eq 'HASH') {
5354: %rules = %{$settings->{'rules'}};
1.273 raeburn 5355: }
5356: }
1.421 raeburn 5357: } else {
5358: foreach my $key ('encrypt','private','rules') {
5359: if (exists($settings->{$key})) {
5360: delete($settings->{$key});
1.267 raeburn 5361: }
5362: }
5363: }
5364: }
1.421 raeburn 5365: my $datatable;
5366: my $itemcount = 1;
5367: if ($position eq 'top') {
5368: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5369: } elsif ($position eq 'middle') {
5370: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5371: $$rowtotal += $itemcount;
5372: } else {
5373: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5374: }
5375: return $datatable;
5376: }
5377:
5378: sub ltitools_names {
5379: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5380: 'title' => 'Title',
5381: 'version' => 'Version',
5382: 'msgtype' => 'Message Type',
1.323 raeburn 5383: 'sigmethod' => 'Signature Method',
1.296 raeburn 5384: 'url' => 'URL',
5385: 'key' => 'Key',
1.322 raeburn 5386: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5387: 'secret' => 'Secret',
1.425 raeburn 5388: 'icon' => 'Icon',
1.324 raeburn 5389: 'user' => 'User',
1.296 raeburn 5390: 'fullname' => 'Full Name',
5391: 'firstname' => 'First Name',
5392: 'lastname' => 'Last Name',
5393: 'email' => 'E-mail',
5394: 'roles' => 'Role',
1.298 raeburn 5395: 'window' => 'Window',
5396: 'tab' => 'Tab',
1.296 raeburn 5397: 'iframe' => 'iFrame',
5398: 'height' => 'Height',
5399: 'width' => 'Width',
5400: 'linktext' => 'Default Link Text',
5401: 'explanation' => 'Default Explanation',
5402: 'passback' => 'Tool can return grades:',
5403: 'roster' => 'Tool can retrieve roster:',
5404: 'crstarget' => 'Display target',
5405: 'crslabel' => 'Course label',
1.425 raeburn 5406: 'crstitle' => 'Course title',
1.296 raeburn 5407: 'crslinktext' => 'Link Text',
5408: 'crsexplanation' => 'Explanation',
1.318 raeburn 5409: 'crsappend' => 'Provider URL',
1.267 raeburn 5410: );
5411: return %lt;
5412: }
5413:
1.421 raeburn 5414: sub secrets_form {
5415: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5416: my @ids=&Apache::lonnet::current_machine_ids();
5417: my %servers = &Apache::lonnet::get_servers($dom,'library');
5418: my $primary = &Apache::lonnet::domain($dom,'primary');
5419: my ($css_class,$extra,$numshown,$itemcount,$output);
5420: $itemcount = 0;
5421: foreach my $hostid (sort(keys(%servers))) {
5422: my ($showextra,$divsty,$switch);
5423: if ($hostid eq $primary) {
5424: if ($context eq 'ltisec') {
5425: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5426: $showextra = 1;
5427: }
5428: if ($encrypt->{'ltisec_crslinkprot'}) {
5429: $showextra = 1;
5430: }
5431: } else {
5432: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5433: $showextra = 1;
5434: }
5435: }
5436: unless (grep(/^\Q$hostid\E$/,@ids)) {
5437: $switch = 1;
5438: }
5439: if ($showextra) {
5440: $numshown ++;
5441: $divsty = 'display:inline-block';
5442: } else {
5443: $divsty = 'display:none';
5444: }
5445: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5446: '<legend>'.$hostid.'</legend>';
5447: if ($switch) {
5448: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5449: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5450: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5451: if (exists($privkeys->{$hostid})) {
5452: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5453: '<span class="LC_nobreak">'.
5454: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5455: '<span class="LC_nobreak">'.&mt('Change?').
5456: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5457: (' 'x2).
5458: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5459: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5460: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5461: '</span></div>';
5462: } else {
5463: $extra .= '<span class="LC_nobreak">'.
5464: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5465: '</span>'."\n";
5466: }
5467: } elsif (exists($privkeys->{$hostid})) {
5468: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5469: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5470: '<span class="LC_nobreak">'.&mt('Change?').
5471: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5472: (' 'x2).
5473: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5474: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5475: '<span class="LC_nobreak">'.&mt('New Key').':'.
5476: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5477: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
5478: '</span></div>';
5479: } else {
5480: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5481: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5482: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
5483: }
5484: $extra .= '</fieldset>';
5485: }
5486: }
5487: my (%choices,@toggles,%defaultchecked);
5488: if ($context eq 'ltisec') {
5489: %choices = &Apache::lonlocal::texthash (
5490: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5491: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5492: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5493: );
5494: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5495: %defaultchecked = (
5496: 'ltisec_crslinkprot' => 'off',
5497: 'ltisec_domlinkprot' => 'off',
5498: 'ltisec_consumers' => 'off',
5499: );
5500: } else {
5501: %choices = &Apache::lonlocal::texthash (
5502: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5503: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5504: );
5505: @toggles = qw(toolsec_crs toolsec_dom);
5506: %defaultchecked = (
5507: 'toolsec_crs' => 'off',
5508: 'toolsec_dom' => 'off',
5509: );
5510: }
5511: my ($onclick,$itemcount);
5512: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5513: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5514: \%choices,$itemcount,$onclick,'','left','no');
5515:
5516: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5517: my $noprivkeysty = 'display:inline-block';
5518: if ($numshown) {
5519: $noprivkeysty = 'display:none';
5520: }
5521: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5522: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5523: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5524: $extra.
5525: '</td></tr>';
5526: $itemcount ++;
5527: $$rowtotal += $itemcount;
5528: return $output;
5529: }
5530:
1.372 raeburn 5531: sub print_proctoring {
5532: my ($dom,$settings,$rowtotal) = @_;
5533: my $itemcount = 1;
5534: my (%ordered,%providernames,%current,%currentdef);
5535: my $confname = $dom.'-domainconfig';
5536: my $switchserver = &check_switchserver($dom,$confname);
5537: if (ref($settings) eq 'HASH') {
5538: foreach my $item (keys(%{$settings})) {
5539: if (ref($settings->{$item}) eq 'HASH') {
5540: my $num = $settings->{$item}{'order'};
5541: $ordered{$num} = $item;
5542: }
5543: }
5544: } else {
5545: %ordered = (
5546: 1 => 'proctorio',
5547: 2 => 'examity',
5548: );
5549: }
5550: %providernames = &proctoring_providernames();
5551: my $maxnum = scalar(keys(%ordered));
5552: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5553: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5554: if (ref($requref) eq 'HASH') {
5555: %requserfields = %{$requref};
5556: }
5557: if (ref($opturef) eq 'HASH') {
5558: %optuserfields = %{$opturef};
5559: }
5560: if (ref($defref) eq 'HASH') {
5561: %defaults = %{$defref};
5562: }
5563: if (ref($extref) eq 'HASH') {
5564: %extended = %{$extref};
5565: }
5566: if (ref($crsref) eq 'HASH') {
5567: %crsconf = %{$crsref};
5568: }
5569: if (ref($rolesref) eq 'ARRAY') {
5570: @courseroles = @{$rolesref};
5571: }
5572: if (ref($ltiref) eq 'ARRAY') {
5573: @ltiroles = @{$ltiref};
5574: }
5575: my $datatable;
5576: my $css_class;
5577: if (keys(%ordered)) {
5578: my @items = sort { $a <=> $b } keys(%ordered);
5579: for (my $i=0; $i<@items; $i++) {
5580: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5581: my $provider = $ordered{$items[$i]};
5582: my $optionsty = 'none';
5583: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5584: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5585: if (ref($settings) eq 'HASH') {
5586: if (ref($settings->{$provider}) eq 'HASH') {
5587: %current = %{$settings->{$provider}};
5588: if ($current{'available'}) {
5589: $optionsty = 'block';
5590: $available = 1;
5591: }
5592: if ($current{'lifetime'} =~ /^\d+$/) {
5593: $lifetime = $current{'lifetime'};
5594: }
5595: if ($current{'version'} =~ /^\d+\.\d+$/) {
5596: $version = $current{'version'};
5597: }
5598: if ($current{'image'} ne '') {
5599: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5600: }
5601: if (ref($current{'fields'}) eq 'ARRAY') {
5602: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5603: }
5604: $userincdom = $current{'incdom'};
5605: if (ref($current{'roles'}) eq 'HASH') {
5606: %rolemaps = %{$current{'roles'}};
5607: $checkedfields{'roles'} = 1;
5608: }
5609: if (ref($current{'defaults'}) eq 'ARRAY') {
5610: foreach my $val (@{$current{'defaults'}}) {
5611: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5612: $inuse{$val} = 1;
5613: } else {
5614: foreach my $poss (keys(%{$extended{$provider}})) {
5615: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5616: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5617: $inuse{$poss} = $val;
5618: last;
5619: }
5620: }
5621: }
5622: }
5623: }
5624: } elsif (ref($current{'defaults'}) eq 'HASH') {
5625: foreach my $key (keys(%{$current{'defaults'}})) {
5626: my $currval = $current{'defaults'}{$key};
5627: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5628: $inuse{$key} = 1;
5629: } else {
5630: my $match;
5631: foreach my $poss (keys(%{$extended{$provider}})) {
5632: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5633: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5634: $inuse{$poss} = $key;
5635: last;
5636: }
5637: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5638: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5639: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5640: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5641: $currentdef{$inner} = $currval;
5642: $match = 1;
5643: last;
5644: }
5645: } elsif ($inner eq $key) {
5646: $currentdef{$key} = $currval;
5647: $match = 1;
5648: last;
5649: }
5650: }
5651: }
5652: last if ($match);
5653: }
5654: }
5655: }
5656: }
5657: if (ref($current{'crsconf'}) eq 'ARRAY') {
5658: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5659: }
5660: }
5661: }
5662: my %lt = &proctoring_titles($provider);
5663: my %fieldtitles = &proctoring_fieldtitles($provider);
5664: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5665: my %checkedavailable = (
5666: yes => '',
5667: no => ' checked="checked"',
5668: );
5669: if ($available) {
5670: $checkedavailable{'yes'} = $checkedavailable{'no'};
5671: $checkedavailable{'no'} = '';
5672: }
5673: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5674: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5675: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5676: for (my $k=0; $k<$maxnum; $k++) {
5677: my $vpos = $k+1;
5678: my $selstr;
5679: if ($k == $i) {
5680: $selstr = ' selected="selected" ';
5681: }
5682: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5683: }
5684: if ($version eq '') {
5685: if ($provider eq 'proctorio') {
5686: $version = '1.0';
5687: } elsif ($provider eq 'examity') {
5688: $version = '1.1';
5689: }
5690: }
5691: if ($lifetime eq '') {
5692: $lifetime = '300';
5693: }
5694: $datatable .=
5695: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5696: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5697: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5698: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5699: '</td>'.
5700: '<td colspan="2">'.
5701: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5702: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5703: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5704: (' 'x2).
5705: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5706: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5707: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5708: (' 'x2).
5709: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5710: '<br />'.
5711: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5712: '<br />'.
5713: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5714: (' 'x2).
5715: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5716: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.proctoring_'.$provider.'_secret.type='."'text'".' } else { this.form.proctoring_'.$provider.'_secret.type='."'password'".' }" />'.$lt{'visible'}.'</label></span><br />'."\n";
5717: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5718: if ($imgsrc) {
5719: $datatable .= $imgsrc.
5720: '<label><input type="checkbox" name="proctoring_image_del"'.
5721: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5722: '<span class="LC_nobreak"> '.&mt('Replace:');
5723: }
5724: $datatable .= ' ';
5725: if ($switchserver) {
5726: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5727: } else {
5728: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5729: }
5730: unless ($imgsrc) {
5731: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5732: }
5733: $datatable .= '</fieldset>'."\n";
5734: if (ref($requserfields{$provider}) eq 'ARRAY') {
5735: if (@{$requserfields{$provider}} > 0) {
5736: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5737: foreach my $field (@{$requserfields{$provider}}) {
5738: $datatable .= '<span class="LC_nobreak">'.
5739: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5740: $lt{$field}.'</label>';
5741: if ($field eq 'user') {
5742: my $seluserdom = '';
5743: my $unseluserdom = ' selected="selected"';
5744: if ($userincdom) {
5745: $seluserdom = $unseluserdom;
5746: $unseluserdom = '';
5747: }
5748: $datatable .= ': '.
5749: '<select name="proctoring_userincdom_'.$provider.'">'.
5750: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5751: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5752: '</select> ';
5753: } else {
5754: $datatable .= ' ';
5755: if ($field eq 'roles') {
5756: $showroles = 1;
5757: }
5758: }
5759: $datatable .= '</span> ';
5760: }
5761: }
5762: $datatable .= '</fieldset>'."\n";
5763: }
5764: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5765: if (@{$optuserfields{$provider}} > 0) {
5766: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5767: foreach my $field (@{$optuserfields{$provider}}) {
5768: my $checked;
5769: if ($checkedfields{$field}) {
5770: $checked = ' checked="checked"';
5771: }
5772: $datatable .= '<span class="LC_nobreak">'.
5773: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5774: }
5775: $datatable .= '</fieldset>'."\n";
5776: }
5777: }
5778: if (ref($defaults{$provider}) eq 'ARRAY') {
5779: if (@{$defaults{$provider}}) {
5780: my (%options,@selectboxes);
5781: if (ref($extended{$provider}) eq 'HASH') {
5782: %options = %{$extended{$provider}};
5783: }
5784: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5785: my ($rem,$numinrow,$dropdowns);
5786: if ($provider eq 'proctorio') {
5787: $datatable .= '<table>';
5788: $numinrow = 4;
5789: }
5790: my $i = 0;
5791: foreach my $field (@{$defaults{$provider}}) {
5792: my $checked;
5793: if ($inuse{$field}) {
5794: $checked = ' checked="checked"';
5795: }
5796: if ($provider eq 'examity') {
5797: if ($field eq 'display') {
5798: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5799: foreach my $option ('iframe','tab','window') {
5800: my $checkdisp;
5801: if ($currentdef{'target'} eq $option) {
5802: $checkdisp = ' checked="checked"';
5803: }
5804: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5805: $fieldtitles{$option}.'</label>'.(' 'x2);
5806: }
5807: $datatable .= (' 'x4);
5808: foreach my $dimen ('width','height') {
5809: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5810: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5811: 'value="'.$currentdef{$dimen}.'" /></label>'.
5812: (' 'x2);
5813: }
5814: $datatable .= '</span><br />'.
5815: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5816: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5817: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5818: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5819: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5820: $currentdef{'explanation'}.
5821: '</textarea></div><div style=""></div><br />';
5822: }
5823: } else {
5824: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5825: my ($output,$selnone);
5826: unless ($checked) {
5827: $selnone = ' selected="selected"';
5828: }
5829: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5830: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5831: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5832: foreach my $option (@{$options{$field}}) {
5833: my $sel;
5834: if ($inuse{$field} eq $option) {
5835: $sel = ' selected="selected"';
5836: }
5837: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5838: }
5839: $output .= '</select></span>';
5840: push(@selectboxes,$output);
5841: } else {
5842: $rem = $i%($numinrow);
5843: if ($rem == 0) {
5844: if ($i > 0) {
5845: $datatable .= '</tr>';
5846: }
5847: $datatable .= '<tr>';
5848: }
5849: $datatable .= '<td class="LC_left_item">'.
5850: '<span class="LC_nobreak">'.
5851: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5852: $fieldtitles{$field}.'</label></span></td>';
5853: $i++;
5854: }
5855: }
5856: }
5857: if ($provider eq 'proctorio') {
5858: if ($numinrow) {
5859: $rem = $i%$numinrow;
5860: }
5861: my $colsleft = $numinrow - $rem;
5862: if ($colsleft > 1) {
5863: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5864: } else {
5865: $datatable .= '<td class="LC_left_item">';
5866: }
5867: $datatable .= ' '.
5868: '</td></tr></table>';
5869: if (@selectboxes) {
5870: $datatable .= '<hr /><table>';
5871: $numinrow = 2;
5872: for (my $i=0; $i<@selectboxes; $i++) {
5873: $rem = $i%($numinrow);
5874: if ($rem == 0) {
5875: if ($i > 0) {
5876: $datatable .= '</tr>';
5877: }
5878: $datatable .= '<tr>';
5879: }
5880: $datatable .= '<td class="LC_left_item">'.
5881: $selectboxes[$i].'</td>';
5882: }
5883: if ($numinrow) {
5884: $rem = $i%$numinrow;
5885: }
5886: $colsleft = $numinrow - $rem;
5887: if ($colsleft > 1) {
5888: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5889: } else {
5890: $datatable .= '<td class="LC_left_item">';
5891: }
5892: $datatable .= ' '.
5893: '</td></tr></table>';
5894: }
5895: }
5896: $datatable .= '</fieldset>';
5897: }
5898: if (ref($crsconf{$provider}) eq 'ARRAY') {
5899: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5900: '<legend>'.&mt('Configurable in course').'</legend>';
5901: my ($rem,$numinrow);
5902: if ($provider eq 'proctorio') {
5903: $datatable .= '<table>';
5904: $numinrow = 4;
5905: }
5906: my $i = 0;
5907: foreach my $item (@{$crsconf{$provider}}) {
5908: my $name;
5909: if ($provider eq 'examity') {
5910: $name = $lt{'crs'.$item};
5911: } elsif ($provider eq 'proctorio') {
5912: $name = $fieldtitles{$item};
5913: $rem = $i%($numinrow);
5914: if ($rem == 0) {
5915: if ($i > 0) {
5916: $datatable .= '</tr>';
5917: }
5918: $datatable .= '<tr>';
5919: }
5920: $datatable .= '<td class="LC_left_item>';
5921: }
5922: my $checked;
5923: if ($crsconfig{$item}) {
5924: $checked = ' checked="checked"';
5925: }
5926: $datatable .= '<span class="LC_nobreak"><label>'.
5927: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5928: $name.'</label></span>';
5929: if ($provider eq 'examity') {
5930: $datatable .= ' ';
5931: }
5932: $datatable .= "\n";
5933: $i++;
5934: }
5935: if ($provider eq 'proctorio') {
5936: if ($numinrow) {
5937: $rem = $i%$numinrow;
5938: }
5939: my $colsleft = $numinrow - $rem;
5940: if ($colsleft > 1) {
5941: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5942: } else {
5943: $datatable .= '<td class="LC_left_item">';
5944: }
5945: $datatable .= ' '.
5946: '</td></tr></table>';
5947: }
5948: $datatable .= '</fieldset>';
5949: }
5950: if ($showroles) {
5951: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5952: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5953: foreach my $role (@courseroles) {
5954: my ($selected,$selectnone);
5955: if (!$rolemaps{$role}) {
5956: $selectnone = ' selected="selected"';
5957: }
5958: $datatable .= '<td style="text-align: center">'.
5959: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5960: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5961: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5962: foreach my $ltirole (@ltiroles) {
5963: unless ($selectnone) {
5964: if ($rolemaps{$role} eq $ltirole) {
5965: $selected = ' selected="selected"';
5966: } else {
5967: $selected = '';
5968: }
5969: }
5970: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5971: }
5972: $datatable .= '</select></td>';
5973: }
5974: $datatable .= '</tr></table></fieldset>'.
5975: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5976: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5977: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5978: '<tr><td></td><td>lms</td>'.
5979: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5980: ' value="Loncapa" disabled="disabled"/></td></tr>';
5981: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5982: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5983: my %custom = %{$settings->{$provider}->{'custom'}};
5984: if (keys(%custom) > 0) {
5985: foreach my $key (sort(keys(%custom))) {
5986: next if ($key eq 'lms');
5987: $datatable .= '<tr><td><span class="LC_nobreak">'.
5988: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5989: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5990: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
5991: ' value="'.$custom{$key}.'" /></td></tr>';
5992: }
5993: }
5994: }
5995: $datatable .= '<tr><td><span class="LC_nobreak">'.
5996: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
5997: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
5998: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
5999: '</table></fieldset></td></tr>'."\n";
6000: }
6001: $datatable .= '</td></tr>';
6002: }
6003: $itemcount ++;
6004: }
6005: }
6006: return $datatable;
6007: }
6008:
6009: sub proctoring_data {
6010: my $requserfields = {
6011: proctorio => ['user'],
6012: examity => ['roles','user'],
6013: };
6014: my $optuserfields = {
6015: proctorio => ['fullname'],
6016: examity => ['fullname','firstname','lastname','email'],
6017: };
6018: my $defaults = {
6019: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6020: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6021: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6022: 'closetabs','onescreen','print','downloads','cache','rightclick',
6023: 'reentry','calculator','whiteboard'],
6024: examity => ['display'],
6025: };
6026: my $extended = {
6027: proctorio => {
6028: verifyid => ['verifyidauto','verifyidlive'],
6029: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6030: tabslinks => ['notabs','linksonly'],
6031: reentry => ['noreentry','agentreentry'],
6032: calculator => ['calculatorbasic','calculatorsci'],
6033: },
6034: examity => {
6035: display => {
6036: target => ['iframe','tab','window'],
6037: width => '',
6038: height => '',
6039: linktext => '',
6040: explanation => '',
6041: },
6042: },
6043: };
6044: my $crsconf = {
6045: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6046: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6047: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6048: 'closetabs','onescreen','print','downloads','cache','rightclick',
6049: 'reentry','calculator','whiteboard'],
6050: examity => ['label','title','target','linktext','explanation','append'],
6051: };
6052: my $courseroles = ['cc','in','ta','ep','st'];
6053: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6054: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6055: }
6056:
6057: sub proctoring_titles {
6058: my ($item) = @_;
6059: my (%common_lt,%custom_lt);
6060: %common_lt = &Apache::lonlocal::texthash (
6061: 'avai' => 'Available?',
6062: 'base' => 'Basic Settings',
6063: 'requ' => 'User data required to be sent on launch',
6064: 'optu' => 'User data optionally sent on launch',
6065: 'udsl' => 'User data sent on launch',
6066: 'defa' => 'Defaults for items configurable in course',
6067: 'sigmethod' => 'Signature Method',
6068: 'key' => 'Key',
6069: 'lifetime' => 'Nonce lifetime (s)',
6070: 'secret' => 'Secret',
6071: 'icon' => 'Icon',
6072: 'fullname' => 'Full Name',
6073: 'visible' => 'Visible input',
6074: 'username' => 'username',
6075: 'user' => 'User',
6076: );
6077: if ($item eq 'proctorio') {
6078: %custom_lt = &Apache::lonlocal::texthash (
6079: 'version' => 'OAuth version',
6080: 'url' => 'API URL',
6081: 'uname:dom' => 'username-domain',
6082: );
6083: } elsif ($item eq 'examity') {
6084: %custom_lt = &Apache::lonlocal::texthash (
6085: 'version' => 'LTI Version',
6086: 'url' => 'URL',
6087: 'uname:dom' => 'username:domain',
6088: 'msgtype' => 'Message Type',
6089: 'firstname' => 'First Name',
6090: 'lastname' => 'Last Name',
6091: 'email' => 'E-mail',
6092: 'roles' => 'Role',
6093: 'crstarget' => 'Display target',
6094: 'crslabel' => 'Course label',
6095: 'crstitle' => 'Course title',
6096: 'crslinktext' => 'Link Text',
6097: 'crsexplanation' => 'Explanation',
6098: 'crsappend' => 'Provider URL',
6099: );
6100: }
6101: my %lt = (%common_lt,%custom_lt);
6102: return %lt;
6103: }
6104:
6105: sub proctoring_fieldtitles {
6106: my ($item) = @_;
6107: if ($item eq 'proctorio') {
6108: return &Apache::lonlocal::texthash (
6109: 'recordvideo' => 'Record video',
6110: 'recordaudio' => 'Record audio',
6111: 'recordscreen' => 'Record screen',
6112: 'recordwebtraffic' => 'Record web traffic',
6113: 'recordroomstart' => 'Record room scan',
6114: 'verifyvideo' => 'Verify webcam',
6115: 'verifyaudio' => 'Verify microphone',
6116: 'verifydesktop' => 'Verify desktop recording',
6117: 'verifyid' => 'Photo ID verification',
6118: 'verifysignature' => 'Require signature',
6119: 'fullscreen' => 'Fullscreen',
6120: 'clipboard' => 'Disable copy/paste',
6121: 'tabslinks' => 'New tabs/windows',
6122: 'closetabs' => 'Close other tabs',
6123: 'onescreen' => 'Limit to single screen',
6124: 'print' => 'Disable Printing',
6125: 'downloads' => 'Disable Downloads',
6126: 'cache' => 'Empty cache after exam',
6127: 'rightclick' => 'Disable right click',
6128: 'reentry' => 'Re-entry to exam',
6129: 'calculator' => 'Onscreen calculator',
6130: 'whiteboard' => 'Onscreen whiteboard',
6131: 'verifyidauto' => 'Automated verification',
6132: 'verifyidlive' => 'Live agent verification',
6133: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6134: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6135: 'fullscreensever' => 'Forced, navigation away ends exam',
6136: 'notabs' => 'Disaallowed',
6137: 'linksonly' => 'Allowed from links in exam',
6138: 'noreentry' => 'Disallowed',
6139: 'agentreentry' => 'Agent required for re-entry',
6140: 'calculatorbasic' => 'Basic',
6141: 'calculatorsci' => 'Scientific',
6142: );
6143: } elsif ($item eq 'examity') {
6144: return &Apache::lonlocal::texthash (
6145: 'target' => 'Display target',
6146: 'window' => 'Window',
6147: 'tab' => 'Tab',
6148: 'iframe' => 'iFrame',
6149: 'height' => 'Height (pixels)',
6150: 'width' => 'Width (pixels)',
6151: 'linktext' => 'Default Link Text',
6152: 'explanation' => 'Default Explanation',
6153: 'append' => 'Provider URL',
6154: );
6155: }
6156: }
6157:
6158: sub proctoring_providernames {
6159: return (
6160: proctorio => 'Proctorio',
6161: examity => 'Examity',
6162: );
6163: }
6164:
1.320 raeburn 6165: sub print_lti {
1.405 raeburn 6166: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6167: my $itemcount = 1;
1.405 raeburn 6168: my ($datatable,$css_class);
1.434 raeburn 6169: my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
1.320 raeburn 6170: if (ref($settings) eq 'HASH') {
1.405 raeburn 6171: if ($position eq 'top') {
6172: if (exists($settings->{'encrypt'})) {
6173: if (ref($settings->{'encrypt'}) eq 'HASH') {
6174: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6175: if ($key eq 'consumers') {
6176: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6177: } else {
6178: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6179: }
6180: }
6181: }
6182: }
6183: if (exists($settings->{'private'})) {
6184: if (ref($settings->{'private'}) eq 'HASH') {
6185: if (ref($settings->{'private'}) eq 'HASH') {
6186: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6187: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6188: }
6189: }
6190: }
6191: }
1.434 raeburn 6192: } elsif ($position eq 'upper') {
1.405 raeburn 6193: if (exists($settings->{'rules'})) {
6194: if (ref($settings->{'rules'}) eq 'HASH') {
6195: %rules = %{$settings->{'rules'}};
6196: }
6197: }
1.434 raeburn 6198: } elsif ($position eq 'middle') {
6199: if (exists($settings->{'suggested'})) {
6200: if (ref($settings->{'suggested'}) eq 'HASH') {
6201: %suggestions = %{$settings->{'suggested'}};
6202: }
6203: }
1.405 raeburn 6204: } elsif ($position eq 'lower') {
6205: if (exists($settings->{'linkprot'})) {
6206: if (ref($settings->{'linkprot'}) eq 'HASH') {
6207: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6208: if ($linkprot{'lock'}) {
6209: delete($linkprot{'lock'});
6210: }
1.405 raeburn 6211: }
6212: }
6213: } else {
1.434 raeburn 6214: foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
1.405 raeburn 6215: if (exists($settings->{$key})) {
6216: delete($settings->{$key});
1.390 raeburn 6217: }
1.320 raeburn 6218: }
6219: }
6220: }
1.405 raeburn 6221: if ($position eq 'top') {
1.421 raeburn 6222: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
1.434 raeburn 6223: } elsif ($position eq 'upper') {
6224: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
6225: $$rowtotal += $itemcount;
1.421 raeburn 6226: } elsif ($position eq 'middle') {
1.434 raeburn 6227: $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
1.421 raeburn 6228: $$rowtotal += $itemcount;
6229: } elsif ($position eq 'lower') {
1.434 raeburn 6230: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
1.421 raeburn 6231: } else {
1.424 raeburn 6232: my ($switchserver,$switchmessage);
6233: $switchserver = &check_switchserver($dom);
6234: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.421 raeburn 6235: my $maxnum = 0;
6236: my %ordered;
6237: if (ref($settings) eq 'HASH') {
6238: foreach my $item (keys(%{$settings})) {
6239: if (ref($settings->{$item}) eq 'HASH') {
6240: my $num = $settings->{$item}{'order'};
6241: if ($num eq '') {
6242: $num = scalar(keys(%{$settings}));
6243: }
6244: $ordered{$num} = $item;
1.405 raeburn 6245: }
1.352 raeburn 6246: }
1.405 raeburn 6247: }
6248: $maxnum = scalar(keys(%ordered));
6249: my %lt = <i_names();
6250: if (keys(%ordered)) {
6251: my @items = sort { $a <=> $b } keys(%ordered);
6252: for (my $i=0; $i<@items; $i++) {
6253: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6254: my $item = $ordered{$items[$i]};
1.424 raeburn 6255: my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
1.405 raeburn 6256: if (ref($settings->{$item}) eq 'HASH') {
6257: $key = $settings->{$item}->{'key'};
1.424 raeburn 6258: $usable = $settings->{$item}->{'usable'};
1.405 raeburn 6259: $lifetime = $settings->{$item}->{'lifetime'};
6260: $consumer = $settings->{$item}->{'consumer'};
6261: $requser = $settings->{$item}->{'requser'};
6262: $crsinc = $settings->{$item}->{'crsinc'};
6263: $current = $settings->{$item};
6264: }
6265: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6266: my %checkedrequser = (
6267: yes => ' checked="checked"',
6268: no => '',
6269: );
6270: if (!$requser) {
6271: $checkedrequser{'no'} = $checkedrequser{'yes'};
6272: $checkedrequser{'yes'} = '';
6273: }
6274: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6275: my %checkedcrsinc = (
1.391 raeburn 6276: yes => ' checked="checked"',
6277: no => '',
1.405 raeburn 6278: );
6279: if (!$crsinc) {
6280: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6281: $checkedcrsinc{'yes'} = '';
6282: }
6283: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6284: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6285: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6286: for (my $k=0; $k<=$maxnum; $k++) {
6287: my $vpos = $k+1;
6288: my $selstr;
6289: if ($k == $i) {
6290: $selstr = ' selected="selected" ';
6291: }
6292: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6293: }
1.405 raeburn 6294: $datatable .= '</select>'.(' 'x2).
6295: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6296: &mt('Delete?').'</label></span></td>'.
6297: '<td colspan="2">'.
6298: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6299: '<span class="LC_nobreak">'.$lt{'consumer'}.
6300: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6301: (' 'x2).
6302: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6303: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6304: (' 'x2).
6305: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.424 raeburn 6306: 'value="'.$lifetime.'" size="3" /></span><br /><br />';
6307: if ($key ne '') {
6308: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6309: if ($switchserver) {
6310: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6311: } else {
6312: $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
6313: }
6314: $datatable .= '</span> '.(' 'x2);
6315: } elsif (!$switchserver) {
6316: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6317: '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
6318: '</span> '.(' 'x2);
6319: }
6320: if ($switchserver) {
6321: if ($usable ne '') {
6322: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6323: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6324: '<span class="LC_nobreak">'.&mt('Change secret?').
6325: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6326: (' 'x2).
6327: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
6328: '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6329: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6330: '</div>';
6331: } elsif ($key eq '') {
6332: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6333: } else {
6334: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6335: }
6336: } else {
6337: if ($usable ne '') {
6338: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6339: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6340: '<span class="LC_nobreak">'.&mt('Change?').
6341: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6342: (' 'x2).
6343: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
6344: '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6345: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6346: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6347: '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label></span></div>';
6348: } else {
6349: $datatable .=
6350: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6351: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6352: '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
6353: }
6354: }
1.425 raeburn 6355: $datatable .= '<br /><br />'.
1.405 raeburn 6356: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6357: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6358: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6359: '<br /><br />'.
6360: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6361: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6362: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6363: (' 'x4).
6364: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6365: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6366: $itemcount ++;
1.320 raeburn 6367: }
6368: }
1.405 raeburn 6369: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6370: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6371: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6372: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6373: '<select name="lti_pos_add"'.$chgstr.'>';
6374: for (my $k=0; $k<$maxnum+1; $k++) {
6375: my $vpos = $k+1;
6376: my $selstr;
6377: if ($k == $maxnum) {
6378: $selstr = ' selected="selected" ';
6379: }
6380: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6381: }
1.405 raeburn 6382: $datatable .= '</select> '."\n".
6383: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6384: '<td colspan="2">'.
6385: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6386: '<span class="LC_nobreak">'.$lt{'consumer'}.
6387: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6388: (' 'x2).
6389: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6390: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6391: (' 'x2).
1.424 raeburn 6392: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
6393: if ($switchserver) {
6394: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6395: } else {
6396: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
6397: (' 'x2).
6398: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
6399: '<label><input type="checkbox" name="lti_add_visible" id="lti_add_visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n";
6400: }
6401: $datatable .= '<br /><br />'.
1.405 raeburn 6402: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6403: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6404: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6405: '<br /><br />'.
6406: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6407: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6408: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6409: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6410: '</td>'."\n".
6411: '</tr>'."\n";
6412: $itemcount ++;
1.320 raeburn 6413: }
1.405 raeburn 6414: $$rowtotal += $itemcount;
6415: return $datatable;
1.320 raeburn 6416: }
6417:
6418: sub lti_names {
6419: my %lt = &Apache::lonlocal::texthash(
6420: 'version' => 'LTI Version',
6421: 'url' => 'URL',
6422: 'key' => 'Key',
1.322 raeburn 6423: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6424: 'consumer' => 'Consumer',
1.320 raeburn 6425: 'secret' => 'Secret',
1.345 raeburn 6426: 'requser' => "User's identity sent",
1.391 raeburn 6427: 'crsinc' => "Course's identity sent",
1.320 raeburn 6428: 'email' => 'Email address',
6429: 'sourcedid' => 'User ID',
6430: 'other' => 'Other',
6431: 'passback' => 'Can return grades to Consumer:',
6432: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6433: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6434: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6435: );
6436: return %lt;
6437: }
6438:
6439: sub lti_options {
1.325 raeburn 6440: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6441: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6442: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6443: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6444: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6445: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6446: $checked{'mapcrstype'} = {};
6447: $checked{'makeuser'} = {};
6448: $checked{'selfenroll'} = {};
6449: $checked{'crssec'} = {};
6450: $checked{'crssecsrc'} = {};
1.325 raeburn 6451: $checked{'lcauth'} = {};
1.326 raeburn 6452: $checked{'menuitem'} = {};
1.325 raeburn 6453: if ($num eq 'add') {
6454: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6455: }
1.320 raeburn 6456: my $userfieldsty = 'none';
6457: my $crsfieldsty = 'none';
6458: my $crssecfieldsty = 'none';
6459: my $secsrcfieldsty = 'none';
1.363 raeburn 6460: my $callbacksty = 'none';
1.337 raeburn 6461: my $passbacksty = 'none';
1.345 raeburn 6462: my $optionsty = 'block';
1.391 raeburn 6463: my $crssty = 'block';
1.325 raeburn 6464: my $lcauthparm;
6465: my $lcauthparmstyle = 'display:none';
6466: my $lcauthparmtext;
1.326 raeburn 6467: my $menusty;
1.325 raeburn 6468: my $numinrow = 4;
1.326 raeburn 6469: my %menutitles = <imenu_titles();
1.320 raeburn 6470:
6471: if (ref($current) eq 'HASH') {
1.345 raeburn 6472: if (!$current->{'requser'}) {
6473: $optionsty = 'none';
1.391 raeburn 6474: $crssty = 'none';
6475: } elsif (!$current->{'crsinc'}) {
6476: $crssty = 'none';
1.345 raeburn 6477: }
1.320 raeburn 6478: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6479: $checked{'mapuser'}{'sourcedid'} = '';
6480: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
1.425 raeburn 6481: $checked{'mapuser'}{'email'} = ' checked="checked"';
1.320 raeburn 6482: } else {
6483: $checked{'mapuser'}{'other'} = ' checked="checked"';
6484: $userfield = $current->{'mapuser'};
6485: $userfieldsty = 'inline-block';
6486: }
6487: }
6488: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6489: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6490: if ($current->{'mapcrs'} eq 'context_id') {
1.425 raeburn 6491: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
1.320 raeburn 6492: } else {
6493: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6494: $cidfield = $current->{'mapcrs'};
6495: $crsfieldsty = 'inline-block';
6496: }
6497: }
6498: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6499: foreach my $type (@{$current->{'mapcrstype'}}) {
6500: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6501: }
6502: }
1.392 raeburn 6503: if (!$current->{'storecrs'}) {
6504: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6505: $checked{'storecrs'}{'Y'} = '';
6506: }
1.345 raeburn 6507: if ($current->{'makecrs'}) {
1.320 raeburn 6508: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6509: }
1.320 raeburn 6510: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6511: foreach my $role (@{$current->{'makeuser'}}) {
6512: $checked{'makeuser'}{$role} = ' checked="checked"';
6513: }
6514: }
1.325 raeburn 6515: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6516: $checked{'lcauth'}{$1} = ' checked="checked"';
6517: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6518: $lcauthparm = $current->{'lcauthparm'};
1.425 raeburn 6519: $lcauthparmstyle = 'display:table-row';
1.325 raeburn 6520: if ($current->{'lcauth'} eq 'localauth') {
6521: $lcauthparmtext = &mt('Local auth argument');
6522: } else {
6523: $lcauthparmtext = &mt('Kerberos domain');
6524: }
6525: }
6526: }
1.320 raeburn 6527: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6528: foreach my $role (@{$current->{'selfenroll'}}) {
6529: $checked{'selfenroll'}{$role} = ' checked="checked"';
6530: }
6531: }
6532: if (ref($current->{'maproles'}) eq 'HASH') {
6533: %rolemaps = %{$current->{'maproles'}};
6534: }
6535: if ($current->{'section'} ne '') {
1.425 raeburn 6536: $checked{'crssec'}{'Y'} = ' checked="checked"';
1.320 raeburn 6537: $crssecfieldsty = 'inline-block';
6538: if ($current->{'section'} eq 'course_section_sourcedid') {
6539: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6540: } else {
6541: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6542: $crssecsrc = $current->{'section'};
6543: $secsrcfieldsty = 'inline-block';
6544: }
6545: } else {
6546: $checked{'crssec'}{'N'} = ' checked="checked"';
6547: }
1.363 raeburn 6548: if ($current->{'callback'} ne '') {
6549: $callback = $current->{'callback'};
6550: $checked{'callback'}{'Y'} = ' checked="checked"';
6551: $callbacksty = 'inline-block';
6552: } else {
6553: $checked{'callback'}{'N'} = ' checked="checked"';
6554: }
1.326 raeburn 6555: if ($current->{'topmenu'}) {
6556: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6557: } else {
6558: $checked{'topmenu'}{'N'} = ' checked="checked"';
6559: }
6560: if ($current->{'inlinemenu'}) {
6561: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6562: } else {
6563: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6564: }
6565: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6566: $menusty = 'inline-block';
6567: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6568: foreach my $item (@{$current->{'lcmenu'}}) {
6569: if (exists($menutitles{$item})) {
6570: $checked{'menuitem'}{$item} = ' checked="checked"';
6571: }
6572: }
6573: }
6574: } else {
6575: $menusty = 'none';
6576: }
1.320 raeburn 6577: } else {
6578: $checked{'makecrs'}{'N'} = ' checked="checked"';
6579: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6580: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6581: $checked{'topmenu'}{'N'} = ' checked="checked"';
1.425 raeburn 6582: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
1.326 raeburn 6583: $checked{'menuitem'}{'grades'} = ' checked="checked"';
1.425 raeburn 6584: $menusty = 'inline-block';
1.320 raeburn 6585: }
1.325 raeburn 6586: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6587: my %coursetypetitles = &Apache::lonlocal::texthash (
6588: official => 'Official',
6589: unofficial => 'Unofficial',
6590: community => 'Community',
6591: textbook => 'Textbook',
6592: placement => 'Placement Test',
1.325 raeburn 6593: lti => 'LTI Provider',
1.320 raeburn 6594: );
1.325 raeburn 6595: my @authtypes = ('internal','krb4','krb5','localauth');
6596: my %shortauth = (
6597: internal => 'int',
6598: krb4 => 'krb4',
6599: krb5 => 'krb5',
6600: localauth => 'loc'
6601: );
6602: my %authnames = &authtype_names();
1.320 raeburn 6603: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6604: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6605: my @courseroles = ('cc','in','ta','ep','st');
6606: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6607: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6608: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6609: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6610: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6611: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6612: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6613: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6614: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6615: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6616: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6617: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6618: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6619: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6620: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6621: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6622: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6623: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6624: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6625: foreach my $option ('sourcedid','email','other') {
6626: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6627: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6628: ($option eq 'other' ? '' : (' 'x2) );
6629: }
6630: $output .= '</span></div>'.
6631: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6632: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6633: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6634: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6635: foreach my $ltirole (@ltiroles) {
6636: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
1.425 raeburn 6637: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
1.320 raeburn 6638: }
6639: $output .= '</fieldset>'.
1.391 raeburn 6640: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6641: '<table>'.
6642: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6643: '</table>'.
6644: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6645: '<td class="LC_left_item">';
6646: foreach my $auth ('lti',@authtypes) {
6647: my $authtext;
6648: if ($auth eq 'lti') {
6649: $authtext = &mt('None');
6650: } else {
6651: $authtext = $authnames{$shortauth{$auth}};
6652: }
6653: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6654: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6655: $authtext.'</label></span> ';
6656: }
6657: $output .= '</td></tr>'.
6658: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6659: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6660: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6661: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6662: '</table></fieldset>'.
1.391 raeburn 6663: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6664: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6665: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6666: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6667: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6668: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6669: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6670: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6671: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6672: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6673: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6674: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6675: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6676: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6677: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6678: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6679: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6680: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6681: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6682: (' 'x2);
6683: }
6684: $output .= '</span></div></fieldset>'.
6685: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6686: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6687: &mt('Unique course identifier').': ';
6688: foreach my $option ('course_offering_sourcedid','context_id','other') {
6689: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6690: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6691: ($option eq 'other' ? '' : (' 'x2) );
6692: }
1.334 raeburn 6693: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6694: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6695: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6696: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6697: foreach my $type (@coursetypes) {
6698: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6699: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6700: (' 'x2);
6701: }
1.392 raeburn 6702: $output .= '</span><br /><br />'.
6703: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6704: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6705: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6706: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6707: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6708: '</fieldset>'.
1.391 raeburn 6709: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6710: foreach my $ltirole (@lticourseroles) {
6711: my ($selected,$selectnone);
6712: if ($rolemaps{$ltirole} eq '') {
6713: $selectnone = ' selected="selected"';
6714: }
6715: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6716: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6717: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6718: foreach my $role (@courseroles) {
6719: unless ($selectnone) {
6720: if ($rolemaps{$ltirole} eq $role) {
6721: $selected = ' selected="selected"';
6722: } else {
6723: $selected = '';
6724: }
6725: }
6726: $output .= '<option value="'.$role.'"'.$selected.'>'.
6727: &Apache::lonnet::plaintext($role,'Course').
6728: '</option>';
6729: }
6730: $output .= '</select></td>';
6731: }
6732: $output .= '</tr></table></fieldset>'.
6733: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6734: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6735: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6736: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6737: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6738: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6739: '</fieldset>'.
1.391 raeburn 6740: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6741: foreach my $lticrsrole (@lticourseroles) {
6742: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6743: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6744: }
6745: $output .= '</fieldset>'.
1.391 raeburn 6746: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6747: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6748: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6749: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6750: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6751: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6752: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6753: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6754: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6755: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6756: &mt('Standard field').'</label>'.(' 'x2).
6757: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6758: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6759: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6760: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6761: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6762: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6763: foreach my $extra ('roster','passback') {
1.320 raeburn 6764: my $checkedon = '';
6765: my $checkedoff = ' checked="checked"';
1.337 raeburn 6766: if ($extra eq 'passback') {
6767: $pb1p1chk = ' checked="checked"';
6768: $pb1p0chk = '';
1.425 raeburn 6769: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
1.337 raeburn 6770: } else {
1.425 raeburn 6771: $onclickpb = '';
1.337 raeburn 6772: }
1.320 raeburn 6773: if (ref($current) eq 'HASH') {
6774: if (($current->{$extra})) {
6775: $checkedon = $checkedoff;
6776: $checkedoff = '';
1.337 raeburn 6777: if ($extra eq 'passback') {
6778: $passbacksty = 'inline-block';
6779: }
6780: if ($current->{'passbackformat'} eq '1.0') {
6781: $pb1p0chk = ' checked="checked"';
6782: $pb1p1chk = '';
6783: }
1.320 raeburn 6784: }
6785: }
6786: $output .= $lt{$extra}.' '.
1.337 raeburn 6787: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6788: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6789: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6790: &mt('Yes').'</label><br />';
6791: }
1.337 raeburn 6792: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6793: '<span class="LC_nobreak">'.&mt('Grade format').
6794: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6795: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6796: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6797: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6798: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6799: $output .= '</span></div></fieldset>';
1.320 raeburn 6800: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6801: #
6802: # $output .= '</fieldset>'.
6803: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6804: return $output;
6805: }
6806:
1.326 raeburn 6807: sub ltimenu_titles {
6808: return &Apache::lonlocal::texthash(
6809: fullname => 'Full name',
6810: coursetitle => 'Course title',
6811: role => 'Role',
6812: logout => 'Logout',
6813: grades => 'Grades',
6814: );
6815: }
6816:
1.434 raeburn 6817: sub linkprot_suggestions {
6818: my ($suggested,$itemcount) = @_;
6819: my $count = 0;
6820: my $next = 1;
6821: my %lt = &Apache::lonlocal::texthash(
6822: 'name' => 'Suggested Launcher',
6823: 'info' => 'Recommendations',
6824: );
6825: my ($datatable,$css_class,$dest);
6826: if (ref($suggested) eq 'HASH') {
6827: my @current = sort { $a <=> $b } keys(%{$suggested});
6828: $next += $current[-1];
6829: for (my $i=0; $i<@current; $i++) {
6830: my $num = $current[$i];
6831: my %values;
6832: if (ref($suggested->{$num}) eq 'HASH') {
6833: %values = %{$suggested->{$num}};
6834: } else {
6835: next;
6836: }
6837: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6838: $datatable .=
6839: '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6840: '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
6841: &mt('Delete?').'</label></span></td><td>'."\n".
6842: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6843: '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
6844: '</fieldset></div>'.
6845: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6846: '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
6847: '</fieldset></div>'.
6848: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6849: '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
6850: $$itemcount ++;
6851: }
6852: }
6853: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6854: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6855: '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
6856: '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6857: '<td>'."\n".
6858: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6859: '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
6860: '</fieldset></div>'.
6861: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6862: '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
6863: '</fieldset></div>'.
6864: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6865: '</td></tr>'."\n";
6866: return $datatable;
6867: }
6868:
1.121 raeburn 6869: sub print_coursedefaults {
1.139 raeburn 6870: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6871: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6872: my $itemcount = 1;
1.192 raeburn 6873: my %choices = &Apache::lonlocal::texthash (
6874: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6875: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.432 raeburn 6876: coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.192 raeburn 6877: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6878: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6879: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6880: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6881: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6882: texengine => 'Default method to display mathematics',
1.257 raeburn 6883: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6884: canclone => "People who may clone a course (besides course's owner and coordinators)",
6885: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6886: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422 raeburn 6887: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6888: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
1.432 raeburn 6889: crsauthor => 'Standard LON-CAPA problems can be created within a course/community (by type)',
1.438 raeburn 6890: crseditors => 'Available editors for web pages and/or problems created in a course/community',
1.192 raeburn 6891: );
1.198 raeburn 6892: my %staticdefaults = (
6893: anonsurvey_threshold => 10,
6894: uploadquota => 500,
1.428 raeburn 6895: coursequota => 20,
1.257 raeburn 6896: postsubmit => 60,
1.276 raeburn 6897: mysqltables => 172800,
1.422 raeburn 6898: domexttool => 1,
6899: exttool => 0,
1.432 raeburn 6900: crsauthor => 1,
1.438 raeburn 6901: crseditors => ['edit','xml'],
1.198 raeburn 6902: );
1.139 raeburn 6903: if ($position eq 'top') {
1.257 raeburn 6904: %defaultchecked = (
6905: 'canuse_pdfforms' => 'off',
6906: 'uselcmath' => 'on',
6907: 'usejsme' => 'on',
1.398 raeburn 6908: 'inline_chem' => 'on',
1.289 raeburn 6909: 'canclone' => 'none',
1.257 raeburn 6910: );
1.398 raeburn 6911: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6912: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6913: if (ref($settings) eq 'HASH') {
6914: if ($settings->{'texengine'}) {
6915: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6916: $deftex = $settings->{'texengine'};
6917: }
6918: }
6919: }
6920: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6921: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6922: '<span class="LC_nobreak">'.$choices{'texengine'}.
6923: '</span></td><td class="LC_right_item">'.
6924: '<select name="texengine">'."\n";
6925: my %texoptions = (
6926: MathJax => 'MathJax',
6927: mimetex => &mt('Convert to Images'),
6928: tth => &mt('TeX to HTML'),
6929: );
6930: foreach my $renderer ('MathJax','mimetex','tth') {
6931: my $selected = '';
6932: if ($renderer eq $deftex) {
6933: $selected = ' selected="selected"';
6934: }
6935: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6936: }
6937: $mathdisp .= '</select></td></tr>'."\n";
6938: $itemcount ++;
1.139 raeburn 6939: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6940: \%choices,$itemcount);
1.314 raeburn 6941: $datatable = $mathdisp.$datatable;
1.264 raeburn 6942: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6943: $datatable .=
1.306 raeburn 6944: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6945: '<span class="LC_nobreak">'.$choices{'canclone'}.
6946: '</span></td><td class="LC_left_item">';
6947: my $currcanclone = 'none';
6948: my $onclick;
6949: my @cloneoptions = ('none','domain');
1.380 raeburn 6950: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6951: none => 'No additional course requesters',
6952: domain => "Any course requester in course's domain",
6953: instcode => 'Course requests for official courses ...',
6954: );
6955: my (%codedefaults,@code_order,@posscodes);
6956: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6957: \@code_order) eq 'ok') {
6958: if (@code_order > 0) {
6959: push(@cloneoptions,'instcode');
6960: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6961: }
6962: }
6963: if (ref($settings) eq 'HASH') {
6964: if ($settings->{'canclone'}) {
6965: if (ref($settings->{'canclone'}) eq 'HASH') {
6966: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6967: if (@code_order > 0) {
6968: $currcanclone = 'instcode';
6969: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6970: }
6971: }
6972: } elsif ($settings->{'canclone'} eq 'domain') {
6973: $currcanclone = $settings->{'canclone'};
6974: }
6975: }
1.289 raeburn 6976: }
1.264 raeburn 6977: foreach my $option (@cloneoptions) {
6978: my ($checked,$additional);
6979: if ($currcanclone eq $option) {
6980: $checked = ' checked="checked"';
6981: }
6982: if ($option eq 'instcode') {
6983: if (@code_order) {
6984: my $show = 'none';
6985: if ($checked) {
6986: $show = 'block';
6987: }
1.317 raeburn 6988: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6989: &mt('Institutional codes for new and cloned course have identical:').
6990: '<br />';
6991: foreach my $item (@code_order) {
6992: my $codechk;
6993: if ($checked) {
6994: if (grep(/^\Q$item\E$/,@posscodes)) {
6995: $codechk = ' checked="checked"';
6996: }
6997: }
6998: $additional .= '<label>'.
6999: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
7000: $item.'</label>';
7001: }
7002: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
7003: }
7004: }
7005: $datatable .=
7006: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
7007: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
7008: '</label> '.$additional.'</span><br />';
7009: }
7010: $datatable .= '</td>'.
7011: '</tr>';
7012: $itemcount ++;
1.139 raeburn 7013: } else {
7014: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 7015: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
7016: %deftimeout,%currmysql);
1.192 raeburn 7017: my $currusecredits = 0;
1.257 raeburn 7018: my $postsubmitclient = 1;
1.405 raeburn 7019: my $ltiauth = 0;
1.422 raeburn 7020: my %domexttool;
7021: my %exttool;
1.432 raeburn 7022: my %crsauthor;
1.438 raeburn 7023: my %crseditors;
1.271 raeburn 7024: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 7025: if (ref($settings) eq 'HASH') {
1.404 raeburn 7026: if ($settings->{'ltiauth'}) {
7027: $ltiauth = 1;
1.405 raeburn 7028: }
1.422 raeburn 7029: if (ref($settings->{'domexttool'}) eq 'HASH') {
7030: foreach my $type (@types) {
7031: if ($settings->{'domexttool'}->{$type}) {
7032: $domexttool{$type} = ' checked="checked"';
7033: }
7034: }
7035: } else {
7036: foreach my $type (@types) {
7037: if ($staticdefaults{'domexttool'}) {
7038: $domexttool{$type} = ' checked="checked"';
7039: }
7040: }
7041: }
7042: if (ref($settings->{'exttool'}) eq 'HASH') {
7043: foreach my $type (@types) {
7044: if ($settings->{'exttool'}->{$type}) {
7045: $exttool{$type} = ' checked="checked"';
7046: }
7047: }
7048: }
1.432 raeburn 7049: if (ref($settings->{'crsauthor'}) eq 'HASH') {
7050: foreach my $type (@types) {
7051: if ($settings->{'crsauthor'}->{$type}) {
7052: $crsauthor{$type} = ' checked="checked"';
7053: }
7054: }
7055: } else {
7056: foreach my $type (@types) {
7057: if ($staticdefaults{'crsauthor'}) {
7058: $crsauthor{$type} = ' checked="checked"';
7059: }
7060: }
7061: }
1.438 raeburn 7062: if (ref($settings->{'crseditors'}) eq 'ARRAY') {
7063: foreach my $editor (@{$settings->{'crseditors'}}) {
7064: $crseditors{$editor} = ' checked="checked"';
7065: }
7066: } else {
7067: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7068: $crseditors{$editor} = ' checked="checked"';
7069: }
7070: }
1.139 raeburn 7071: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7072: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7073: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7074: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7075: }
7076: }
1.428 raeburn 7077: if (ref($settings->{'coursequota'}) eq 'HASH') {
7078: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7079: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7080: }
7081: }
1.192 raeburn 7082: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7083: foreach my $type (@types) {
7084: next if ($type eq 'community');
7085: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7086: if ($defcredits{$type} ne '') {
7087: $currusecredits = 1;
7088: }
7089: }
7090: }
7091: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7092: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7093: $postsubmitclient = 0;
7094: foreach my $type (@types) {
7095: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7096: }
7097: } else {
7098: foreach my $type (@types) {
7099: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7100: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7101: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7102: } else {
7103: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7104: }
7105: } else {
7106: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7107: }
7108: }
7109: }
7110: } else {
7111: foreach my $type (@types) {
7112: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7113: }
7114: }
1.276 raeburn 7115: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7116: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7117: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7118: }
7119: } else {
7120: foreach my $type (@types) {
7121: $currmysql{$type} = $staticdefaults{'mysqltables'};
7122: }
7123: }
1.258 raeburn 7124: } else {
7125: foreach my $type (@types) {
7126: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7127: if ($staticdefaults{'domexttool'}) {
7128: $domexttool{$type} = ' checked="checked"';
7129: }
1.432 raeburn 7130: if ($staticdefaults{'crsauthor'}) {
7131: $crsauthor{$type} = ' checked="checked"';
7132: }
1.258 raeburn 7133: }
1.438 raeburn 7134: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7135: $crseditors{$editor} = ' checked="checked"';
7136: }
1.139 raeburn 7137: }
7138: if (!$currdefresponder) {
1.198 raeburn 7139: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7140: } elsif ($currdefresponder < 1) {
7141: $currdefresponder = 1;
7142: }
1.198 raeburn 7143: foreach my $type (@types) {
7144: if ($curruploadquota{$type} eq '') {
7145: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7146: }
1.428 raeburn 7147: if ($currcoursequota{$type} eq '') {
7148: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7149: }
1.198 raeburn 7150: }
1.139 raeburn 7151: $datatable .=
1.192 raeburn 7152: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7153: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7154: '</span></td>'.
7155: '<td class="LC_right_item"><span class="LC_nobreak">'.
7156: '<input type="text" name="anonsurvey_threshold"'.
7157: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7158: '</td></tr>'."\n";
7159: $itemcount ++;
7160: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7161: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7162: $choices{'uploadquota'}.
7163: '</span></td>'.
1.306 raeburn 7164: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7165: '<table><tr>';
1.198 raeburn 7166: foreach my $type (@types) {
1.306 raeburn 7167: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7168: '<input type="text" name="uploadquota_'.$type.'"'.
7169: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7170: }
7171: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7172: $itemcount ++;
1.428 raeburn 7173: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7174: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7175: $choices{'coursequota'}.
7176: '</span></td>'.
7177: '<td style="text-align: right" class="LC_right_item">'.
7178: '<table><tr>';
7179: foreach my $type (@types) {
7180: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7181: '<input type="text" name="coursequota_'.$type.'"'.
7182: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7183: }
7184: $datatable .= '</tr></table></td></tr>'."\n";
7185: $itemcount ++;
1.236 raeburn 7186: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7187: my $display = 'none';
1.192 raeburn 7188: if ($currusecredits) {
7189: $display = 'block';
7190: }
7191: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7192: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7193: foreach my $type (@types) {
7194: next if ($type eq 'community');
1.306 raeburn 7195: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7196: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7197: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7198: }
7199: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7200: %defaultchecked = ('coursecredits' => 'off');
7201: @toggles = ('coursecredits');
7202: my $current = {
7203: 'coursecredits' => $currusecredits,
7204: };
7205: (my $table,$itemcount) =
7206: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7207: \%choices,$itemcount,$onclick,$additional,'left');
7208: $datatable .= $table;
7209: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7210: my $display = 'none';
7211: if ($postsubmitclient) {
7212: $display = 'block';
7213: }
7214: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7215: &mt('Number of seconds submit is disabled').'<br />'.
7216: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7217: '<table><tr>';
1.257 raeburn 7218: foreach my $type (@types) {
1.306 raeburn 7219: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7220: '<input type="text" name="'.$type.'_timeout" value="'.
7221: $deftimeout{$type}.'" size="5" /></td>';
7222: }
7223: $additional .= '</tr></table></div>'."\n";
7224: %defaultchecked = ('postsubmit' => 'on');
7225: @toggles = ('postsubmit');
1.280 raeburn 7226: $current = {
7227: 'postsubmit' => $postsubmitclient,
7228: };
1.257 raeburn 7229: ($table,$itemcount) =
7230: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7231: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7232: $datatable .= $table;
1.276 raeburn 7233: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7234: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7235: $choices{'mysqltables'}.
7236: '</span></td>'.
1.306 raeburn 7237: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7238: '<table><tr>';
7239: foreach my $type (@types) {
1.306 raeburn 7240: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7241: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7242: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7243: }
7244: $datatable .= '</tr></table></td></tr>'."\n";
7245: $itemcount ++;
1.404 raeburn 7246: %defaultchecked = ('ltiauth' => 'off');
7247: @toggles = ('ltiauth');
7248: $current = {
7249: 'ltiauth' => $ltiauth,
7250: };
7251: ($table,$itemcount) =
7252: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7253: \%choices,$itemcount,undef,undef,'left');
7254: $datatable .= $table;
1.422 raeburn 7255: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7256: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7257: $choices{'domexttool'}.
7258: '</span></td>'.
7259: '<td style="text-align: right" class="LC_right_item">'.
7260: '<table><tr>';
7261: foreach my $type (@types) {
7262: $datatable .= '<td style="text-align: left">'.
7263: '<span class="LC_nobreak">'.
1.438 raeburn 7264: '<label><input type="checkbox" name="domexttool"'.
1.422 raeburn 7265: ' value="'.$type.'"'.$domexttool{$type}.' />'.
1.438 raeburn 7266: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7267: }
7268: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7269: $itemcount ++;
1.422 raeburn 7270: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7271: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7272: $choices{'exttool'}.
7273: '</span></td>'.
7274: '<td style="text-align: right" class="LC_right_item">'.
7275: '<table><tr>';
7276: foreach my $type (@types) {
7277: $datatable .= '<td style="text-align: left">'.
7278: '<span class="LC_nobreak">'.
1.438 raeburn 7279: '<label><input type="checkbox" name="exttool"'.
1.422 raeburn 7280: ' value="'.$type.'"'.$exttool{$type}.' />'.
1.438 raeburn 7281: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7282: }
7283: $datatable .= '</tr></table></td></tr>'."\n";
1.432 raeburn 7284: $itemcount ++;
7285: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7286: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7287: $choices{'crsauthor'}.
7288: '</span></td>'.
7289: '<td style="text-align: right" class="LC_right_item">'.
7290: '<table><tr>';
7291: foreach my $type (@types) {
7292: $datatable .= '<td style="text-align: left">'.
7293: '<span class="LC_nobreak">'.
1.438 raeburn 7294: '<label><input type="checkbox" name="crsauthor"'.
1.432 raeburn 7295: ' value="'.$type.'"'.$crsauthor{$type}.' />'.
1.438 raeburn 7296: &mt($type).'</label></span></td>'."\n";
7297: }
7298: $datatable .= '</tr></table></td></tr>'."\n";
7299: $itemcount ++;
7300: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7301: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7302: $choices{'crseditors'}.
7303: '</span></td>'.
7304: '<td style="text-align: right" class="LC_right_item">'.
7305: '<table><tr>';
7306: my @editors = ('edit','xml','daxe');
7307: my %editornames = &crseditor_titles();
7308: foreach my $editor (@editors) {
7309: $datatable .= '<td style="text-align: left">'.
7310: '<span class="LC_nobreak">'.
7311: '<label><input type="checkbox" name="crseditors"'.
7312: ' value="'.$editor.'"'.$crseditors{$editor}.' />'.
7313: $editornames{$editor}.'</label></span></td>'."\n";
1.432 raeburn 7314: }
7315: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7316: }
1.192 raeburn 7317: $$rowtotal += $itemcount;
1.121 raeburn 7318: return $datatable;
1.118 jms 7319: }
7320:
1.438 raeburn 7321: sub crseditor_titles {
7322: return &Apache::lonlocal::texthash(
7323: edit => 'Standard editor (Edit)',
7324: xml => 'Text editor (EditXML)',
7325: daxe => 'Daxe editor (Daxe)',
7326: );
7327: }
7328:
1.429 raeburn 7329: sub print_authordefaults {
7330: my ($position,$dom,$settings,$rowtotal) = @_;
7331: my ($css_class,$datatable,%checkedon,%checkedoff);
7332: my $itemcount = 1;
7333: my %titles = &authordefaults_titles();
7334: if ($position eq 'top') {
7335: my %defaultchecked = (
7336: 'nocodemirror' => 'off',
1.437 raeburn 7337: 'daxecollapse' => 'off',
1.429 raeburn 7338: 'domcoordacc' => 'on',
7339: );
1.437 raeburn 7340: my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
1.429 raeburn 7341: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
7342: \%titles,$itemcount);
7343: my %staticdefaults = (
7344: 'copyright' => 'default',
7345: 'sourceavail' => 'closed',
7346: );
7347: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7348: my %currrights;
7349: foreach my $item ('copyright','sourceavail') {
7350: $currrights{$item} = $staticdefaults{$item};
7351: if (ref($settings) eq 'HASH') {
7352: if (exists($settings->{$item})) {
7353: $currrights{$item} = $settings->{$item};
7354: }
7355: }
7356: }
7357: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7358: '<span class="LC_nobreak">'.$titles{'copyright'}.
7359: '</span></td><td class="LC_right_item">'.
7360: &selectbox('copyright',$currrights{'copyright'},'',
7361: \&Apache::loncommon::copyrightdescription,
7362: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
7363: '</td></tr>'."\n";
7364: $itemcount ++;
7365: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7366: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7367: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
7368: '</span></td><td class="LC_right_item">'.
7369: &selectbox('sourceavail',$currrights{'sourceavail'},'',
7370: \&Apache::loncommon::source_copyrightdescription,
7371: (&Apache::loncommon::source_copyrightids)).
7372: '</td></tr>'."\n";
7373: } else {
7374: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7375: my $curreditors;
7376: my %staticdefaults = (
7377: editors => ['edit','xml'],
7378: authorquota => 500,
7379: webdav => 0,
7380: );
7381: my $curreditors = $staticdefaults{'editors'};
7382: if ((ref($settings) eq 'HASH') &&
7383: (ref($settings->{'editors'}) eq 'ARRAY')) {
7384: $curreditors = $settings->{'editors'};
7385: } else {
7386: $curreditors = $staticdefaults{'editors'};
7387: }
7388: my @editors = ('edit','xml','daxe');
7389: $datatable = '<tr'.$css_class.'>'."\n".
7390: '<td>'.$titles{'editors'}.'</td>'."\n".
7391: '<td class="LC_left_item">'."\n".
7392: '<span class="LC_nobreak">';
7393: foreach my $editor (@editors) {
7394: my $checked;
7395: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
7396: $checked = ' checked="checked"';
7397: }
7398: $datatable .= '<label>'.
7399: '<input type="checkbox" name="author_editors" '.
7400: $checked.' value="'.$editor.'" '.
7401: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
7402: $titles{$editor}.'</label> ';
7403: }
7404: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
7405: $itemcount ++;
7406: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7407: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7408: my @insttypes;
7409: if (ref($types) eq 'ARRAY') {
7410: @insttypes = @{$types};
7411: }
7412: my $typecount = 0;
7413: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
7414: my @items = ('webdav','authorquota');
7415: my %quotas;
7416: if (ref($domconf{'quotas'}) eq 'HASH') {
7417: %quotas = %{$domconf{'quotas'}};
7418: foreach my $item (@items) {
7419: if (ref($quotas{$item}) eq 'HASH') {
7420: foreach my $type (@insttypes,'default') {
7421: if ($item eq 'authorquota') {
7422: if ($quotas{$item}{$type} !~ /^\d+$/) {
7423: $quotas{$item}{$type} = $staticdefaults{$item};
7424: }
7425: } elsif ($item eq 'webdav') {
7426: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
7427: $quotas{$item}{$type} = $staticdefaults{$item};
7428: }
7429: }
7430: }
7431: } else {
7432: foreach my $type (@insttypes,'default') {
7433: $quotas{$item}{$type} = $staticdefaults{$item};
7434: }
7435: }
7436: }
7437: } else {
7438: foreach my $item (@items) {
7439: foreach my $type (@insttypes,'default') {
7440: $quotas{$item}{$type} = $staticdefaults{$item};
7441: }
7442: }
7443: }
7444: if (ref($usertypes) eq 'HASH') {
7445: my $numinrow = 4;
7446: my $onclick = '';
7447: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7448: $numinrow,$othertitle,'authorquota',
7449: \$itemcount,$onclick);
7450: $itemcount ++;
7451: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7452: $numinrow,$othertitle,'webdav',
7453: \$itemcount);
7454: $itemcount ++;
7455: }
7456: my $checkedno = ' checked="checked"';
7457: my ($checkedon,$checkedoff);
7458: if (ref($quotas{'webdav'}) eq 'HASH') {
1.436 raeburn 7459: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
1.429 raeburn 7460: if ($quotas{'webdav'}{'_LC_adv'}) {
7461: $checkedon = $checkedno;
7462: } else {
7463: $checkedoff = $checkedno;
7464: }
7465: undef($checkedno);
7466: }
7467: }
7468: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7469: $datatable .= '<tr'.$css_class.'>'.
7470: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
7471: $titles{'webdav_LC_adv_over'}.
7472: '</td>'.
7473: '<td class="LC_left_item">';
7474: foreach my $option ('none','off','on') {
7475: my ($text,$val,$checked);
7476: if ($option eq 'none') {
7477: $text = $titles{'none'};
7478: $val = '';
7479: $checked = $checkedno;
7480: } elsif ($option eq 'off') {
7481: $text = $titles{'overoff'};
7482: $val = 0;
7483: $checked = $checkedoff;
7484: } elsif ($option eq 'on') {
7485: $text = $titles{'overon'};
7486: $val = 1;
7487: $checked = $checkedon;
1.436 raeburn 7488: }
1.429 raeburn 7489: $datatable .= '<span class="LC_nobreak"><label>'.
7490: '<input type="radio" name="webdav_LC_adv"'.
7491: ' value="'.$val.'"'.$checked.' />'.
7492: $text.'</label></span> ';
7493: }
7494: $datatable .= '</td></tr>';
7495: $itemcount ++;
1.440 raeburn 7496: my %defchecked = (
7497: 'archive' => 'off',
7498: );
7499: my @toggles = ('archive');
7500: (my $archive,$itemcount) = &radiobutton_prefs($settings,['archive'],
7501: {'archive' => 'off'},
7502: \%titles,$itemcount);
7503: $datatable .= $archive."\n";
7504: $itemcount ++;
1.429 raeburn 7505: }
7506: $$rowtotal += $itemcount;
7507: return $datatable;
7508: }
7509:
7510: sub authordefaults_titles {
7511: return &Apache::lonlocal::texthash(
7512: copyright => 'Copyright/Distribution',
7513: sourceavail => ' Source Available',
7514: editors => 'Available Editors',
7515: webdav => 'WebDAV',
7516: authorquota => 'Authoring Space quotas (MB)',
7517: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
1.437 raeburn 7518: daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
1.429 raeburn 7519: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
7520: edit => 'Standard editor (Edit)',
7521: xml => 'Text editor (EditXML)',
7522: daxe => 'Daxe editor (Daxe)',
7523: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
7524: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
7525: none => 'No override set',
7526: overon => 'Override -- webDAV on',
1.436 raeburn 7527: overoff => 'Override -- webDAV off',
1.440 raeburn 7528: archive => 'Authors can download tar.gz file of Authoring Space',
1.429 raeburn 7529: );
7530: }
7531:
7532: sub selectbox {
7533: my ($name,$value,$readonly,$functionref,@idlist)=@_;
7534: my $selout = '<select name="'.$name.'">';
7535: foreach my $id (@idlist) {
7536: $selout.='<option value="'.$id.'"';
7537: if ($id eq $value) {
7538: $selout.=' selected="selected"';
7539: }
7540: if ($readonly) {
7541: $selout .= ' disabled="disabled"';
7542: }
7543: $selout.='>'.&{$functionref}($id).'</option>';
7544: }
7545: $selout.='</select>';
7546: return $selout;
7547: }
7548:
1.231 raeburn 7549: sub print_selfenrollment {
7550: my ($position,$dom,$settings,$rowtotal) = @_;
7551: my ($css_class,$datatable);
7552: my $itemcount = 1;
1.271 raeburn 7553: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7554: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7555: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7556: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7557: my @rows;
7558: my $key;
7559: if ($position eq 'top') {
7560: $key = 'admin';
7561: if (ref($rowsref) eq 'ARRAY') {
7562: @rows = @{$rowsref};
7563: }
7564: } elsif ($position eq 'middle') {
7565: $key = 'default';
7566: @rows = ('types','registered','approval','limit');
7567: }
7568: foreach my $row (@rows) {
7569: if (defined($titlesref->{$row})) {
7570: $itemcount ++;
7571: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7572: $datatable .= '<tr'.$css_class.'>'.
7573: '<td>'.$titlesref->{$row}.'</td>'.
7574: '<td class="LC_left_item">'.
7575: '<table><tr>';
7576: my (%current,%currentcap);
7577: if (ref($settings) eq 'HASH') {
7578: if (ref($settings->{$key}) eq 'HASH') {
7579: foreach my $type (@types) {
7580: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7581: $current{$type} = $settings->{$key}->{$type}->{$row};
7582: }
7583: if (($row eq 'limit') && ($key eq 'default')) {
7584: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7585: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7586: }
7587: }
7588: }
7589: }
7590: }
7591: my %roles = (
7592: '0' => &Apache::lonnet::plaintext('dc'),
7593: );
7594:
7595: foreach my $type (@types) {
7596: unless (($row eq 'registered') && ($key eq 'default')) {
7597: $datatable .= '<th>'.&mt($type).'</th>';
7598: }
7599: }
7600: unless (($row eq 'registered') && ($key eq 'default')) {
7601: $datatable .= '</tr><tr>';
7602: }
7603: foreach my $type (@types) {
7604: if ($type eq 'community') {
7605: $roles{'1'} = &mt('Community personnel');
7606: } else {
7607: $roles{'1'} = &mt('Course personnel');
7608: }
7609: $datatable .= '<td style="vertical-align: top">';
7610: if ($position eq 'top') {
7611: my %checked;
7612: if ($current{$type} eq '0') {
7613: $checked{'0'} = ' checked="checked"';
7614: } else {
7615: $checked{'1'} = ' checked="checked"';
7616: }
7617: foreach my $role ('1','0') {
7618: $datatable .= '<span class="LC_nobreak"><label>'.
7619: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7620: 'value="'.$role.'"'.$checked{$role}.' />'.
7621: $roles{$role}.'</label></span> ';
7622: }
7623: } else {
7624: if ($row eq 'types') {
7625: my %checked;
7626: if ($current{$type} =~ /^(all|dom)$/) {
7627: $checked{$1} = ' checked="checked"';
7628: } else {
7629: $checked{''} = ' checked="checked"';
7630: }
7631: foreach my $val ('','dom','all') {
7632: $datatable .= '<span class="LC_nobreak"><label>'.
7633: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7634: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7635: }
7636: } elsif ($row eq 'registered') {
7637: my %checked;
7638: if ($current{$type} eq '1') {
7639: $checked{'1'} = ' checked="checked"';
7640: } else {
7641: $checked{'0'} = ' checked="checked"';
7642: }
7643: foreach my $val ('0','1') {
7644: $datatable .= '<span class="LC_nobreak"><label>'.
7645: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7646: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7647: }
7648: } elsif ($row eq 'approval') {
7649: my %checked;
7650: if ($current{$type} =~ /^([12])$/) {
7651: $checked{$1} = ' checked="checked"';
7652: } else {
7653: $checked{'0'} = ' checked="checked"';
7654: }
7655: for my $val (0..2) {
7656: $datatable .= '<span class="LC_nobreak"><label>'.
7657: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7658: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7659: }
7660: } elsif ($row eq 'limit') {
7661: my %checked;
7662: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7663: $checked{$1} = ' checked="checked"';
7664: } else {
7665: $checked{'none'} = ' checked="checked"';
7666: }
7667: my $cap;
7668: if ($currentcap{$type} =~ /^\d+$/) {
7669: $cap = $currentcap{$type};
7670: }
7671: foreach my $val ('none','allstudents','selfenrolled') {
7672: $datatable .= '<span class="LC_nobreak"><label>'.
7673: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7674: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7675: }
7676: $datatable .= '<br />'.
7677: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7678: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7679: '</span>';
7680: }
7681: }
7682: $datatable .= '</td>';
7683: }
7684: $datatable .= '</tr>';
7685: }
7686: $datatable .= '</table></td></tr>';
7687: }
7688: } elsif ($position eq 'bottom') {
1.235 raeburn 7689: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7690: }
7691: $$rowtotal += $itemcount;
7692: return $datatable;
7693: }
7694:
7695: sub print_validation_rows {
7696: my ($caller,$dom,$settings,$rowtotal) = @_;
7697: my ($itemsref,$namesref,$fieldsref);
7698: if ($caller eq 'selfenroll') {
7699: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7700: } elsif ($caller eq 'requestcourses') {
7701: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7702: }
7703: my %currvalidation;
7704: if (ref($settings) eq 'HASH') {
7705: if (ref($settings->{'validation'}) eq 'HASH') {
7706: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7707: }
1.235 raeburn 7708: }
7709: my $datatable;
7710: my $itemcount = 0;
7711: foreach my $item (@{$itemsref}) {
7712: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7713: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7714: $namesref->{$item}.
7715: '</span></td>'.
7716: '<td class="LC_left_item">';
7717: if (($item eq 'url') || ($item eq 'button')) {
7718: $datatable .= '<span class="LC_nobreak">'.
7719: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7720: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7721: } elsif ($item eq 'fields') {
7722: my @currfields;
7723: if (ref($currvalidation{$item}) eq 'ARRAY') {
7724: @currfields = @{$currvalidation{$item}};
7725: }
7726: foreach my $field (@{$fieldsref}) {
7727: my $check = '';
7728: if (grep(/^\Q$field\E$/,@currfields)) {
7729: $check = ' checked="checked"';
7730: }
7731: $datatable .= '<span class="LC_nobreak"><label>'.
7732: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7733: ' value="'.$field.'"'.$check.' />'.$field.
7734: '</label></span> ';
7735: }
7736: } elsif ($item eq 'markup') {
1.334 raeburn 7737: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7738: $currvalidation{$item}.
1.231 raeburn 7739: '</textarea>';
1.235 raeburn 7740: }
7741: $datatable .= '</td></tr>'."\n";
7742: if (ref($rowtotal)) {
1.231 raeburn 7743: $itemcount ++;
7744: }
7745: }
1.235 raeburn 7746: if ($caller eq 'requestcourses') {
7747: my %currhash;
1.248 raeburn 7748: if (ref($settings) eq 'HASH') {
7749: if (ref($settings->{'validation'}) eq 'HASH') {
7750: if ($settings->{'validation'}{'dc'} ne '') {
7751: $currhash{$settings->{'validation'}{'dc'}} = 1;
7752: }
1.235 raeburn 7753: }
7754: }
7755: my $numinrow = 2;
7756: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7757: 'validationdc',%currhash);
1.247 raeburn 7758: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7759: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7760: if ($numdc > 1) {
1.247 raeburn 7761: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7762: } else {
1.247 raeburn 7763: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7764: }
1.247 raeburn 7765: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7766: $itemcount ++;
7767: }
7768: if (ref($rowtotal)) {
7769: $$rowtotal += $itemcount;
7770: }
1.231 raeburn 7771: return $datatable;
7772: }
7773:
1.357 raeburn 7774: sub print_privacy {
7775: my ($position,$dom,$settings,$rowtotal) = @_;
7776: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7777: my $itemcount = 0;
1.417 raeburn 7778: if ($position eq 'top') {
7779: $numinrow = 2;
7780: } else {
1.357 raeburn 7781: @items = ('domain','author','course','community');
7782: %names = &Apache::lonlocal::texthash (
7783: domain => 'Assigned domain role(s)',
7784: author => 'Assigned co-author role(s)',
7785: course => 'Assigned course role(s)',
1.416 raeburn 7786: community => 'Assigned community role(s)',
1.357 raeburn 7787: );
7788: $numinrow = 4;
7789: ($othertitle,$usertypes,$types) =
7790: &Apache::loncommon::sorted_inst_types($dom);
7791: }
7792: if (($position eq 'top') || ($position eq 'middle')) {
7793: my (%by_ip,%by_location,@intdoms,@instdoms);
7794: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7795: if ($position eq 'top') {
7796: my %curr;
7797: my @options = ('none','user','domain','auto');
7798: my %titles = &Apache::lonlocal::texthash (
7799: none => 'Not allowed',
7800: user => 'User authorizes',
7801: domain => 'DC authorizes',
7802: auto => 'Unrestricted',
7803: instdom => 'Other domain shares institution/provider',
7804: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7805: notify => 'Notify when role needs authorization',
1.357 raeburn 7806: );
7807: my %names = &Apache::lonlocal::texthash (
7808: domain => 'Domain role',
7809: author => 'Co-author role',
7810: course => 'Course role',
7811: community => 'Community role',
7812: );
7813: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7814: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7815: foreach my $domtype ('instdom','extdom') {
7816: my (%checked,$skip);
7817: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7818: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7819: '<td class="LC_left_item">';
7820: if ($domtype eq 'instdom') {
7821: unless (@instdoms > 1) {
7822: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7823: $skip = 1;
7824: }
7825: } elsif ($domtype eq 'extdom') {
7826: if (keys(%by_location) == 0) {
7827: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7828: $skip = 1;
7829: }
7830: }
7831: unless ($skip) {
7832: foreach my $roletype ('domain','author','course','community') {
7833: $checked{'auto'} = ' checked="checked"';
7834: if (ref($settings) eq 'HASH') {
7835: if (ref($settings->{approval}) eq 'HASH') {
7836: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7837: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7838: $checked{$1} = ' checked="checked"';
7839: $checked{'auto'} = '';
7840: }
7841: }
7842: }
7843: }
7844: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7845: foreach my $option (@options) {
7846: $datatable .= '<span class="LC_nobreak"><label>'.
7847: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7848: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7849: '</label></span> ';
7850: }
7851: $datatable .= '</fieldset>';
7852: }
7853: }
7854: $datatable .= '</td></tr>';
7855: $itemcount ++;
7856: }
1.417 raeburn 7857: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7858: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7859: '<td class="LC_left_item">';
7860: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7861: my %curr;
7862: if (ref($settings) eq 'HASH') {
7863: if ($settings->{'notify'} ne '') {
7864: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7865: }
7866: }
7867: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7868: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7869: 'privacy_notify',%curr);
7870: if ($numdc > 0) {
7871: $datatable .= $table;
7872: } else {
7873: $datatable .= &mt('There are no active Domain Coordinators');
7874: }
7875: } else {
7876: $datatable .= &mt('Nothing to set here, as there are no other domains');
7877: }
7878: $datatable .='</td></tr>';
1.357 raeburn 7879: } elsif ($position eq 'middle') {
7880: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7881: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7882: foreach my $item (@{$types}) {
7883: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7884: $numinrow,$itemcount,'','','','','',
7885: '',$usertypes->{$item});
7886: $itemcount ++;
7887: }
7888: }
7889: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7890: $numinrow,$itemcount,'','','','','',
7891: '',$othertitle);
7892: $itemcount ++;
7893: } else {
1.360 raeburn 7894: my (@insttypes,%insttitles);
7895: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7896: @insttypes = @{$types};
7897: %insttitles = %{$usertypes};
7898: }
7899: foreach my $item (@insttypes,'default') {
7900: my $title;
7901: if ($item eq 'default') {
7902: $title = $othertitle;
7903: } else {
7904: $title = $insttitles{$item};
7905: }
7906: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7907: $datatable .= '<tr'.$css_class.'>'.
7908: '<td class="LC_left_item">'.$title.'</td>'.
7909: '<td class="LC_left_item">'.
7910: &mt('Nothing to set here, as there are no other domains').
7911: '</td></tr>';
7912: $itemcount ++;
7913: }
1.357 raeburn 7914: }
7915: }
7916: } else {
7917: my $prefix;
7918: if ($position eq 'lower') {
7919: $prefix = 'priv';
7920: } else {
7921: $prefix = 'unpriv';
7922: }
7923: foreach my $item (@items) {
7924: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7925: $numinrow,$itemcount,'','','','','',
7926: '',$names{$item});
7927: $itemcount ++;
7928: }
7929: }
7930: if (ref($rowtotal)) {
7931: $$rowtotal += $itemcount;
7932: }
7933: return $datatable;
7934: }
7935:
1.354 raeburn 7936: sub print_passwords {
7937: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7938: my ($datatable,$css_class);
7939: my $itemcount = 0;
7940: my %titles = &Apache::lonlocal::texthash (
7941: captcha => '"Forgot Password" CAPTCHA validation',
7942: link => 'Reset link expiration (hours)',
7943: case => 'Case-sensitive usernames/e-mail',
7944: prelink => 'Information required (form 1)',
7945: postlink => 'Information required (form 2)',
7946: emailsrc => 'LON-CAPA e-mail address type(s)',
7947: customtext => 'Domain specific text (HTML)',
7948: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7949: intauth_check => 'Check bcrypt cost if authenticated',
7950: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7951: permanent => 'Permanent e-mail address',
7952: critical => 'Critical notification address',
7953: notify => 'Notification address',
7954: min => 'Minimum password length',
7955: max => 'Maximum password length',
7956: chars => 'Required characters',
7957: expire => 'Password expiration (days)',
1.356 raeburn 7958: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7959: );
7960: if ($position eq 'top') {
7961: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7962: my $shownlinklife = 2;
7963: my $prelink = 'both';
7964: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7965: if (ref($settings) eq 'HASH') {
7966: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7967: $shownlinklife = $settings->{resetlink};
7968: }
7969: if (ref($settings->{resetcase}) eq 'ARRAY') {
7970: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7971: }
7972: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7973: $prelink = $settings->{resetprelink};
7974: }
7975: if (ref($settings->{resetpostlink}) eq 'HASH') {
7976: %postlink = %{$settings->{resetpostlink}};
7977: }
7978: if (ref($settings->{resetemail}) eq 'ARRAY') {
7979: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7980: }
7981: if ($settings->{resetremove}) {
7982: $nostdtext = 1;
7983: }
7984: if ($settings->{resetcustom}) {
7985: $customurl = $settings->{resetcustom};
7986: }
7987: } else {
7988: if (ref($types) eq 'ARRAY') {
7989: foreach my $item (@{$types}) {
7990: $casesens{$item} = 1;
7991: $postlink{$item} = ['username','email'];
7992: }
7993: }
7994: $casesens{'default'} = 1;
7995: $postlink{'default'} = ['username','email'];
7996: $prelink = 'both';
7997: %emailsrc = (
7998: permanent => 1,
7999: critical => 1,
8000: notify => 1,
8001: );
8002: }
8003: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
8004: $itemcount ++;
8005: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8006: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
8007: '<td class="LC_left_item">'.
8008: '<input type="textbox" value="'.$shownlinklife.'" '.
8009: 'name="passwords_link" size="3" /></td></tr>';
8010: $itemcount ++;
8011: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8012: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
8013: '<td class="LC_left_item">';
8014: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8015: foreach my $item (@{$types}) {
8016: my $checkedcase;
8017: if ($casesens{$item}) {
8018: $checkedcase = ' checked="checked"';
8019: }
8020: $datatable .= '<span class="LC_nobreak"><label>'.
8021: '<input type="checkbox" name="passwords_case_sensitive" value="'.
8022: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 8023: '</span> ';
1.354 raeburn 8024: }
8025: }
8026: my $checkedcase;
8027: if ($casesens{'default'}) {
8028: $checkedcase = ' checked="checked"';
8029: }
8030: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8031: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
8032: $othertitle.'</label></span></td>';
8033: $itemcount ++;
8034: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8035: my %checkedpre = (
8036: both => ' checked="checked"',
8037: either => '',
8038: );
8039: if ($prelink eq 'either') {
8040: $checkedpre{either} = ' checked="checked"';
8041: $checkedpre{both} = '';
8042: }
8043: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
8044: '<td class="LC_left_item"><span class="LC_nobreak">'.
8045: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
8046: &mt('Both username and e-mail address').'</label></span> '.
8047: '<span class="LC_nobreak"><label>'.
8048: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
8049: &mt('Either username or e-mail address').'</label></span></td></tr>';
8050: $itemcount ++;
8051: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8052: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
8053: '<td class="LC_left_item">';
8054: my %postlinked;
8055: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8056: foreach my $item (@{$types}) {
8057: undef(%postlinked);
8058: $datatable .= '<fieldset style="display: inline-block;">'.
8059: '<legend>'.$usertypes->{$item}.'</legend>';
8060: if (ref($postlink{$item}) eq 'ARRAY') {
8061: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
8062: }
8063: foreach my $field ('email','username') {
8064: my $checked;
8065: if ($postlinked{$field}) {
8066: $checked = ' checked="checked"';
8067: }
8068: $datatable .= '<span class="LC_nobreak"><label>'.
8069: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
8070: $field.'"'.$checked.' />'.$field.'</label>'.
8071: '<span> ';
8072: }
8073: $datatable .= '</fieldset>';
8074: }
8075: }
8076: if (ref($postlink{'default'}) eq 'ARRAY') {
8077: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
8078: }
8079: $datatable .= '<fieldset style="display: inline-block;">'.
8080: '<legend>'.$othertitle.'</legend>';
8081: foreach my $field ('email','username') {
8082: my $checked;
8083: if ($postlinked{$field}) {
8084: $checked = ' checked="checked"';
8085: }
8086: $datatable .= '<span class="LC_nobreak"><label>'.
8087: '<input type="checkbox" name="passwords_postlink_default" value="'.
8088: $field.'"'.$checked.' />'.$field.'</label>'.
8089: '<span> ';
8090: }
8091: $datatable .= '</fieldset></td></tr>';
8092: $itemcount ++;
8093: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8094: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
8095: '<td class="LC_left_item">';
8096: foreach my $type ('permanent','critical','notify') {
8097: my $checkedemail;
8098: if ($emailsrc{$type}) {
8099: $checkedemail = ' checked="checked"';
8100: }
8101: $datatable .= '<span class="LC_nobreak"><label>'.
8102: '<input type="checkbox" name="passwords_emailsrc" value="'.
8103: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8104: '<span> ';
8105: }
8106: $datatable .= '</td></tr>';
8107: $itemcount ++;
8108: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8109: my $switchserver = &check_switchserver($dom,$confname);
8110: my ($showstd,$noshowstd);
8111: if ($nostdtext) {
8112: $noshowstd = ' checked="checked"';
8113: } else {
8114: $showstd = ' checked="checked"';
8115: }
8116: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8117: '<td class="LC_left_item"><span class="LC_nobreak">'.
8118: &mt('Retain standard text:').
8119: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8120: &mt('Yes').'</label>'.' '.
8121: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8122: &mt('No').'</label></span><br />'.
8123: '<span class="LC_fontsize_small">'.
8124: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8125: &mt('Include custom text:');
8126: if ($customurl) {
1.369 raeburn 8127: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8128: undef,undef,undef,undef,'background-color:#ffffff');
8129: $datatable .= '<span class="LC_nobreak"> '.$link.
8130: '<label><input type="checkbox" name="passwords_custom_del"'.
8131: ' value="1" />'.&mt('Delete?').'</label></span>'.
8132: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8133: }
8134: if ($switchserver) {
8135: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8136: } else {
8137: $datatable .='<span class="LC_nobreak"> '.
8138: '<input type="file" name="passwords_customfile" /></span>';
8139: }
8140: $datatable .= '</td></tr>';
8141: } elsif ($position eq 'middle') {
8142: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8143: my @items = ('intauth_cost','intauth_check','intauth_switch');
8144: my %defaults;
8145: if (ref($domconf{'defaults'}) eq 'HASH') {
8146: %defaults = %{$domconf{'defaults'}};
8147: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8148: $defaults{'intauth_cost'} = 10;
8149: }
8150: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8151: $defaults{'intauth_check'} = 0;
8152: }
8153: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8154: $defaults{'intauth_switch'} = 0;
8155: }
8156: } else {
8157: %defaults = (
8158: 'intauth_cost' => 10,
8159: 'intauth_check' => 0,
8160: 'intauth_switch' => 0,
8161: );
8162: }
8163: foreach my $item (@items) {
8164: if ($itemcount%2) {
8165: $css_class = '';
8166: } else {
8167: $css_class = ' class="LC_odd_row" ';
8168: }
8169: $datatable .= '<tr'.$css_class.'>'.
8170: '<td><span class="LC_nobreak">'.$titles{$item}.
8171: '</span></td><td class="LC_left_item" colspan="3">';
8172: if ($item eq 'intauth_switch') {
8173: my @options = (0,1,2);
8174: my %optiondesc = &Apache::lonlocal::texthash (
8175: 0 => 'No',
8176: 1 => 'Yes',
8177: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8178: );
8179: $datatable .= '<table width="100%">';
8180: foreach my $option (@options) {
8181: my $checked = ' ';
8182: if ($defaults{$item} eq $option) {
8183: $checked = ' checked="checked"';
8184: }
8185: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8186: '<label><input type="radio" name="'.$item.
8187: '" value="'.$option.'"'.$checked.' />'.
8188: $optiondesc{$option}.'</label></span></td></tr>';
8189: }
8190: $datatable .= '</table>';
8191: } elsif ($item eq 'intauth_check') {
8192: my @options = (0,1,2);
8193: my %optiondesc = &Apache::lonlocal::texthash (
8194: 0 => 'No',
8195: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8196: 2 => 'Yes, disallow login if stored cost is less than domain default',
8197: );
8198: $datatable .= '<table width="100%">';
8199: foreach my $option (@options) {
8200: my $checked = ' ';
8201: my $onclick;
8202: if ($defaults{$item} eq $option) {
8203: $checked = ' checked="checked"';
8204: }
8205: if ($option == 2) {
8206: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8207: }
8208: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8209: '<label><input type="radio" name="'.$item.
8210: '" value="'.$option.'"'.$checked.$onclick.' />'.
8211: $optiondesc{$option}.'</label></span></td></tr>';
8212: }
8213: $datatable .= '</table>';
8214: } else {
8215: $datatable .= '<input type="text" name="'.$item.'" value="'.
8216: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8217: }
8218: $datatable .= '</td></tr>';
8219: $itemcount ++;
8220: }
8221: } elsif ($position eq 'lower') {
1.405 raeburn 8222: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8223: } else {
1.359 raeburn 8224: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8225: my %ownerchg = (
8226: by => {},
8227: for => {},
8228: );
8229: my %ownertitles = &Apache::lonlocal::texthash (
8230: by => 'Course owner status(es) allowed',
8231: for => 'Student status(es) allowed',
8232: );
1.354 raeburn 8233: if (ref($settings) eq 'HASH') {
1.359 raeburn 8234: if (ref($settings->{crsownerchg}) eq 'HASH') {
8235: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8236: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8237: }
8238: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8239: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8240: }
1.354 raeburn 8241: }
8242: }
8243: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8244: $datatable .= '<tr '.$css_class.'>'.
8245: '<td>'.
8246: &mt('Requirements').'<ul>'.
1.359 raeburn 8247: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8248: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8249: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8250: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8251: '</ul>'.
8252: '</td>'.
1.359 raeburn 8253: '<td class="LC_left_item">';
8254: foreach my $item ('by','for') {
8255: $datatable .= '<fieldset style="display: inline-block;">'.
8256: '<legend>'.$ownertitles{$item}.'</legend>';
8257: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8258: foreach my $type (@{$types}) {
8259: my $checked;
8260: if ($ownerchg{$item}{$type}) {
8261: $checked = ' checked="checked"';
8262: }
8263: $datatable .= '<span class="LC_nobreak"><label>'.
8264: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8265: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8266: '</span> ';
1.359 raeburn 8267: }
8268: }
8269: my $checked;
8270: if ($ownerchg{$item}{'default'}) {
8271: $checked = ' checked="checked"';
8272: }
8273: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8274: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8275: $othertitle.'</label></span></fieldset>';
8276: }
8277: $datatable .= '</td></tr>';
1.354 raeburn 8278: }
8279: return $datatable;
8280: }
8281:
1.405 raeburn 8282: sub password_rules {
8283: my ($prefix,$itemcountref,$settings) = @_;
8284: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8285: my %titles;
8286: if ($prefix eq 'passwords') {
8287: %titles = &Apache::lonlocal::texthash (
8288: min => 'Minimum password length',
8289: max => 'Maximum password length',
8290: chars => 'Required characters',
8291: );
1.421 raeburn 8292: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8293: %titles = &Apache::lonlocal::texthash (
8294: min => 'Minimum secret length',
8295: max => 'Maximum secret length',
8296: chars => 'Required characters',
8297: );
8298: }
8299: $min = $Apache::lonnet::passwdmin;
8300: my $datatable;
8301: my $itemcount;
8302: if (ref($itemcountref)) {
8303: $itemcount = $$itemcountref;
8304: }
8305: if (ref($settings) eq 'HASH') {
8306: if ($settings->{min}) {
8307: $min = $settings->{min};
8308: }
8309: if ($settings->{max}) {
8310: $max = $settings->{max};
8311: }
8312: if (ref($settings->{chars}) eq 'ARRAY') {
8313: map { $chars{$_} = 1; } (@{$settings->{chars}});
8314: }
1.425 raeburn 8315: if ($prefix eq 'passwords') {
1.405 raeburn 8316: if ($settings->{expire}) {
8317: $expire = $settings->{expire};
8318: }
8319: if ($settings->{numsaved}) {
8320: $numsaved = $settings->{numsaved};
8321: }
8322: }
8323: }
8324: my %rulenames = &Apache::lonlocal::texthash(
8325: uc => 'At least one upper case letter',
8326: lc => 'At least one lower case letter',
8327: num => 'At least one number',
8328: spec => 'At least one non-alphanumeric',
8329: );
8330: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8331: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8332: '<td class="LC_left_item"><span class="LC_nobreak">'.
8333: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8334: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8335: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8336: '</span></td></tr>';
8337: $itemcount ++;
8338: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8339: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8340: '<td class="LC_left_item"><span class="LC_nobreak">'.
8341: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8342: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8343: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8344: '</span></td></tr>';
8345: $itemcount ++;
8346: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8347: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8348: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8349: '</span></td>';
8350: my $numinrow = 2;
8351: my @possrules = ('uc','lc','num','spec');
8352: $datatable .= '<td class="LC_left_item"><table>';
8353: for (my $i=0; $i<@possrules; $i++) {
8354: my ($rem,$checked);
8355: if ($chars{$possrules[$i]}) {
8356: $checked = ' checked="checked"';
8357: }
8358: $rem = $i%($numinrow);
8359: if ($rem == 0) {
8360: if ($i > 0) {
8361: $datatable .= '</tr>';
8362: }
8363: $datatable .= '<tr>';
8364: }
8365: $datatable .= '<td><span class="LC_nobreak"><label>'.
8366: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8367: $rulenames{$possrules[$i]}.'</label></span></td>';
8368: }
8369: my $rem = @possrules%($numinrow);
8370: my $colsleft = $numinrow - $rem;
8371: if ($colsleft > 1 ) {
8372: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8373: ' </td>';
8374: } elsif ($colsleft == 1) {
8375: $datatable .= '<td class="LC_left_item"> </td>';
8376: }
8377: $datatable .='</table></td></tr>';
8378: $itemcount ++;
8379: if ($prefix eq 'passwords') {
8380: $titles{'expire'} = &mt('Password expiration (days)');
8381: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8382: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8383: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8384: '<td class="LC_left_item"><span class="LC_nobreak">'.
8385: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8386: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8387: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8388: '</span></td></tr>';
8389: $itemcount ++;
8390: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8391: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8392: '<td class="LC_left_item"><span class="LC_nobreak">'.
8393: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8394: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8395: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8396: '</span></td></tr>';
8397: $itemcount ++;
8398: }
8399: if (ref($itemcountref)) {
8400: $$itemcountref += $itemcount;
8401: }
8402: return $datatable;
8403: }
8404:
1.373 raeburn 8405: sub print_wafproxy {
8406: my ($position,$dom,$settings,$rowtotal) = @_;
8407: my $css_class;
8408: my $itemcount = 0;
8409: my $datatable;
8410: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8411: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8412: my %lt = &wafproxy_titles();
1.373 raeburn 8413: foreach my $server (sort(keys(%servers))) {
8414: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8415: next if ($serverhome eq '');
1.373 raeburn 8416: my $serverdom;
8417: if ($serverhome ne $server) {
8418: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8419: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8420: $othercontrol{$server} = $serverdom;
8421: }
1.373 raeburn 8422: } else {
8423: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8424: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8425: if ($serverdom ne $dom) {
8426: $othercontrol{$server} = $serverdom;
8427: } else {
8428: $setdom = 1;
8429: if (ref($settings) eq 'HASH') {
8430: if (ref($settings->{'alias'}) eq 'HASH') {
8431: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8432: if ($aliases{$dom} ne '') {
8433: $showdom = 1;
8434: }
1.373 raeburn 8435: }
1.388 raeburn 8436: if (ref($settings->{'saml'}) eq 'HASH') {
8437: $saml{$dom} = $settings->{'saml'};
8438: }
1.373 raeburn 8439: }
8440: }
8441: }
8442: }
1.381 raeburn 8443: if ($setdom) {
8444: %{$values{$dom}} = ();
8445: if (ref($settings) eq 'HASH') {
8446: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8447: $values{$dom}{$item} = $settings->{$item};
8448: }
8449: }
8450: }
1.373 raeburn 8451: if (keys(%othercontrol)) {
8452: %otherdoms = reverse(%othercontrol);
8453: foreach my $domain (keys(%otherdoms)) {
8454: %{$values{$domain}} = ();
8455: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8456: if (ref($config{'wafproxy'}) eq 'HASH') {
8457: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8458: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8459: $saml{$domain} = $config{'wafproxy'}{'saml'};
8460: }
1.383 raeburn 8461: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8462: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8463: }
8464: }
8465: }
8466: }
8467: if ($position eq 'top') {
8468: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8469: my %aliasinfo;
1.373 raeburn 8470: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8471: $itemcount ++;
8472: my $dom_in_effect;
8473: my $aliasrows = '<tr>'.
1.383 raeburn 8474: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.433 raeburn 8475: &mt('Hostname').': '.
8476: '<span class="LC_nobreak LC_cusr_emph">'.
8477: &Apache::lonnet::hostname($server).
8478: '</span></td><td> </td>';
1.373 raeburn 8479: if ($othercontrol{$server}) {
1.381 raeburn 8480: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8481: my ($current,$forsaml);
1.383 raeburn 8482: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8483: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8484: }
1.388 raeburn 8485: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8486: if ($saml{$dom_in_effect}{$server}) {
8487: $forsaml = 1;
8488: }
8489: }
1.383 raeburn 8490: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8491: &mt('Alias').': ';
1.373 raeburn 8492: if ($current) {
1.381 raeburn 8493: $aliasrows .= $current;
1.388 raeburn 8494: if ($forsaml) {
1.396 raeburn 8495: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8496: }
1.373 raeburn 8497: } else {
1.383 raeburn 8498: $aliasrows .= &mt('None');
1.373 raeburn 8499: }
1.383 raeburn 8500: $aliasrows .= ' <span class="LC_small">('.
8501: &mt('controlled by domain: [_1]',
8502: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8503: } else {
1.381 raeburn 8504: $dom_in_effect = $dom;
1.388 raeburn 8505: my ($current,$samlon,$samloff);
8506: $samloff = ' checked="checked"';
1.373 raeburn 8507: if (ref($aliases{$dom}) eq 'HASH') {
8508: if ($aliases{$dom}{$server}) {
8509: $current = $aliases{$dom}{$server};
8510: }
8511: }
1.388 raeburn 8512: if (ref($saml{$dom}) eq 'HASH') {
8513: if ($saml{$dom}{$server}) {
8514: $samlon = $samloff;
8515: undef($samloff);
8516: }
8517: }
1.383 raeburn 8518: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8519: &mt('Alias').': '.
1.381 raeburn 8520: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8521: 'value="'.$current.'" size="30" />'.
8522: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8523: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8524: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8525: &mt('No').'</label> <label>'.
1.388 raeburn 8526: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8527: &mt('Yes').'</label></span>'.
1.425 raeburn 8528: '</td>';
1.381 raeburn 8529: }
8530: $aliasrows .= '</tr>';
8531: $aliasinfo{$dom_in_effect} .= $aliasrows;
8532: }
8533: if ($aliasinfo{$dom}) {
8534: my ($onclick,$wafon,$wafoff,$showtable);
8535: $onclick = ' onclick="javascript:toggleWAF();"';
8536: $wafoff = ' checked="checked"';
8537: $showtable = ' style="display:none";';
8538: if ($showdom) {
8539: $wafon = $wafoff;
8540: $wafoff = '';
8541: $showtable = ' style="display:inline;"';
8542: }
8543: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8544: $datatable = '<tr'.$css_class.'>'.
8545: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8546: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8547: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8548: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8549: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8550: &mt('No').'</label></span></td>'.
8551: '<td class="LC_left_item">'.
8552: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8553: '</table></td></tr>';
8554: $itemcount++;
8555: }
1.383 raeburn 8556: if (keys(%otherdoms)) {
8557: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8558: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8559: $datatable .= '<tr'.$css_class.'>'.
8560: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8561: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8562: '</table></td></tr>';
1.381 raeburn 8563: $itemcount++;
1.373 raeburn 8564: }
8565: }
8566: } else {
1.383 raeburn 8567: my %ip_methods = &remoteip_methods();
1.373 raeburn 8568: if ($setdom) {
8569: $itemcount ++;
8570: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8571: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8572: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8573: $wafstyle = ' style="display:none;"';
8574: $nowafstyle = ' style="display:table-row;"';
8575: $currwafdisplay = ' style="display: none"';
8576: $wafrangestyle = ' style="display: none"';
8577: $curr_remotip = 'n';
1.382 raeburn 8578: $ssltossl = ' checked="checked"';
1.381 raeburn 8579: if ($showdom) {
8580: $wafstyle = ' style="display:table-row;"';
8581: $nowafstyle = ' style="display:none;"';
8582: if (keys(%{$values{$dom}})) {
8583: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8584: $curr_remotip = $values{$dom}{remoteip};
8585: }
8586: if ($curr_remotip eq 'h') {
8587: $currwafdisplay = ' style="display:table-row"';
8588: $wafrangestyle = ' style="display:inline-block;"';
8589: }
1.382 raeburn 8590: if ($values{$dom}{'sslopt'}) {
8591: $alltossl = ' checked="checked"';
8592: $ssltossl = '';
8593: }
1.381 raeburn 8594: }
8595: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8596: $vpndircheck = ' checked="checked"';
8597: $currwafvpn = ' style="display:table-row;"';
8598: $wafrangestyle = ' style="display:inline-block;"';
8599: } else {
8600: $vpnaliascheck = ' checked="checked"';
8601: $currwafvpn = ' style="display:none;"';
8602: }
8603: }
8604: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8605: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8606: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8607: '</tr>'.
8608: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8609: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8610: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8611: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8612: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8613: '<td class="LC_left_item"><table>'.
8614: '<tr>'.
8615: '<td valign="top">'.$lt{'remoteip'}.': '.
8616: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8617: foreach my $option ('m','h','n') {
8618: my $sel;
8619: if ($option eq $curr_remotip) {
8620: $sel = ' selected="selected"';
8621: }
8622: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8623: $ip_methods{$option}.'</option>';
8624: }
8625: $datatable .= '</select></td></tr>'."\n".
8626: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8627: $lt{'ipheader'}.': '.
8628: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8629: 'name="wafproxy_ipheader" />'.
8630: '</td></tr>'."\n".
8631: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8632: $lt{'trusted'}.':<br />'.
1.381 raeburn 8633: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8634: $values{$dom}{'trusted'}.'</textarea>'.
8635: '</td></tr>'."\n".
8636: '<tr><td><hr /></td></tr>'."\n".
8637: '<tr>'.
8638: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8639: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8640: $lt{'vpndirect'}.'</label>'.(' 'x2).
8641: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8642: $lt{'vpnaliased'}.'</label></span></td></tr>';
8643: foreach my $item ('vpnint','vpnext') {
8644: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8645: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8646: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8647: $values{$dom}{$item}.'</textarea>'.
8648: '</td></tr>'."\n";
1.373 raeburn 8649: }
1.382 raeburn 8650: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8651: '<tr>'.
8652: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8653: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8654: $lt{'alltossl'}.'</label>'.(' 'x2).
8655: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8656: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8657: '</table></td></tr>';
1.373 raeburn 8658: }
8659: if (keys(%otherdoms)) {
8660: foreach my $domain (sort(keys(%otherdoms))) {
8661: $itemcount ++;
8662: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8663: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8664: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8665: '<td class="LC_left_item"><table>';
1.382 raeburn 8666: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8667: my $showval = &mt('None');
1.382 raeburn 8668: if ($item eq 'ssl') {
8669: $showval = $lt{'ssltossl'};
8670: }
1.373 raeburn 8671: if ($values{$domain}{$item}) {
1.381 raeburn 8672: $showval = $values{$domain}{$item};
1.382 raeburn 8673: if ($item eq 'ssl') {
8674: $showval = $lt{'alltossl'};
1.383 raeburn 8675: } elsif ($item eq 'remoteip') {
8676: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8677: }
1.373 raeburn 8678: }
8679: $datatable .= '<tr>'.
8680: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8681: }
1.381 raeburn 8682: $datatable .= '</table></td></tr>';
1.373 raeburn 8683: }
8684: }
8685: }
8686: $$rowtotal += $itemcount;
8687: return $datatable;
8688: }
8689:
8690: sub wafproxy_titles {
8691: return &Apache::lonlocal::texthash(
1.381 raeburn 8692: remoteip => "Method for determining user's IP",
8693: ipheader => 'Request header containing remote IP',
8694: trusted => 'Trusted IP range(s)',
8695: vpnaccess => 'Access from institutional VPN',
8696: vpndirect => 'via regular hostname (no WAF)',
8697: vpnaliased => 'via aliased hostname (WAF)',
8698: vpnint => 'Internal IP Range(s) for VPN sessions',
8699: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8700: sslopt => 'Forwarding http/https',
1.381 raeburn 8701: alltossl => 'WAF forwards both http and https requests to https',
8702: ssltossl => 'WAF forwards http requests to http and https to https',
8703: );
8704: }
8705:
8706: sub remoteip_methods {
8707: return &Apache::lonlocal::texthash(
8708: m => 'Use Apache mod_remoteip',
8709: h => 'Use headers parsed by LON-CAPA',
8710: n => 'Not in use',
1.373 raeburn 8711: );
8712: }
8713:
1.137 raeburn 8714: sub print_usersessions {
8715: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8716: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8717: my (%by_ip,%by_location,@intdoms,@instdoms);
8718: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8719:
8720: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8721: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8722: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8723: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8724: if ($position eq 'top') {
1.152 raeburn 8725: if (keys(%serverhomes) > 1) {
1.145 raeburn 8726: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8727: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8728: if (ref($settings) eq 'HASH') {
8729: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8730: $curroffloadnow = $settings->{'offloadnow'};
8731: }
1.371 raeburn 8732: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8733: $curroffloadoth = $settings->{'offloadoth'};
8734: }
1.261 raeburn 8735: }
1.371 raeburn 8736: my $other_insts = scalar(keys(%by_location));
8737: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8738: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8739: } else {
1.140 raeburn 8740: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8741: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8742: '</td></tr>';
1.140 raeburn 8743: }
1.137 raeburn 8744: } else {
1.279 raeburn 8745: my %titles = &usersession_titles();
8746: my ($prefix,@types);
8747: if ($position eq 'bottom') {
8748: $prefix = 'remote';
8749: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8750: } else {
1.279 raeburn 8751: $prefix = 'hosted';
8752: @types = ('excludedomain','includedomain');
8753: }
8754: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8755: }
8756: $$rowtotal += $itemcount;
8757: return $datatable;
8758: }
8759:
8760: sub rules_by_location {
8761: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8762: my ($datatable,$itemcount,$css_class);
8763: if (keys(%{$by_location}) == 0) {
8764: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8765: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8766: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8767: '</td></tr>';
8768: $itemcount = 1;
8769: } else {
8770: $itemcount = 0;
8771: my $numinrow = 5;
8772: my (%current,%checkedon,%checkedoff);
8773: my @locations = sort(keys(%{$by_location}));
8774: foreach my $type (@{$types}) {
8775: $checkedon{$type} = '';
8776: $checkedoff{$type} = ' checked="checked"';
8777: }
8778: if (ref($settings) eq 'HASH') {
8779: if (ref($settings->{$prefix}) eq 'HASH') {
8780: foreach my $key (keys(%{$settings->{$prefix}})) {
8781: $current{$key} = $settings->{$prefix}{$key};
8782: if ($key eq 'version') {
8783: if ($current{$key} ne '') {
1.145 raeburn 8784: $checkedon{$key} = ' checked="checked"';
8785: $checkedoff{$key} = '';
8786: }
1.279 raeburn 8787: } elsif (ref($current{$key}) eq 'ARRAY') {
8788: $checkedon{$key} = ' checked="checked"';
8789: $checkedoff{$key} = '';
1.137 raeburn 8790: }
8791: }
8792: }
1.279 raeburn 8793: }
8794: foreach my $type (@{$types}) {
8795: next if ($type ne 'version' && !@locations);
8796: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8797: $datatable .= '<tr'.$css_class.'>
8798: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8799: <span class="LC_nobreak">
8800: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8801: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8802: if ($type eq 'version') {
8803: my @lcversions = &Apache::lonnet::all_loncaparevs();
8804: my $selector = '<select name="'.$prefix.'_version">';
8805: foreach my $version (@lcversions) {
8806: my $selected = '';
8807: if ($current{'version'} eq $version) {
8808: $selected = ' selected="selected"';
1.145 raeburn 8809: }
1.279 raeburn 8810: $selector .= ' <option value="'.$version.'"'.
8811: $selected.'>'.$version.'</option>';
8812: }
8813: $selector .= '</select> ';
8814: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8815: } else {
8816: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8817: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8818: ' />'.(' 'x2).
8819: '<input type="button" value="'.&mt('uncheck all').'" '.
8820: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8821: "\n".
8822: '</div><div><table>';
8823: my $rem;
8824: for (my $i=0; $i<@locations; $i++) {
8825: my ($showloc,$value,$checkedtype);
8826: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8827: my $ip = $by_location->{$locations[$i]}->[0];
8828: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8829: $value = join(':',@{$by_ip->{$ip}});
8830: $showloc = join(', ',@{$by_ip->{$ip}});
8831: if (ref($current{$type}) eq 'ARRAY') {
8832: foreach my $loc (@{$by_ip->{$ip}}) {
8833: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8834: $checkedtype = ' checked="checked"';
8835: last;
1.145 raeburn 8836: }
1.138 raeburn 8837: }
8838: }
8839: }
1.137 raeburn 8840: }
1.279 raeburn 8841: $rem = $i%($numinrow);
8842: if ($rem == 0) {
8843: if ($i > 0) {
8844: $datatable .= '</tr>';
8845: }
8846: $datatable .= '<tr>';
8847: }
8848: $datatable .= '<td class="LC_left_item">'.
8849: '<span class="LC_nobreak"><label>'.
8850: '<input type="checkbox" name="'.$prefix.'_'.$type.
8851: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8852: '</label></span></td>';
8853: }
8854: $rem = @locations%($numinrow);
8855: my $colsleft = $numinrow - $rem;
8856: if ($colsleft > 1 ) {
8857: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8858: ' </td>';
8859: } elsif ($colsleft == 1) {
8860: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8861: }
1.279 raeburn 8862: $datatable .= '</tr></table>';
1.137 raeburn 8863: }
1.279 raeburn 8864: $datatable .= '</td></tr>';
8865: $itemcount ++;
1.137 raeburn 8866: }
8867: }
1.279 raeburn 8868: return ($datatable,$itemcount);
1.137 raeburn 8869: }
8870:
1.275 raeburn 8871: sub print_ssl {
8872: my ($position,$dom,$settings,$rowtotal) = @_;
8873: my ($css_class,$datatable);
8874: my $itemcount = 1;
8875: if ($position eq 'top') {
1.281 raeburn 8876: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8877: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8878: my $same_institution;
8879: if ($intdom ne '') {
8880: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8881: if (ref($internet_names) eq 'ARRAY') {
8882: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8883: $same_institution = 1;
8884: }
8885: }
8886: }
1.275 raeburn 8887: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8888: $datatable = '<tr'.$css_class.'><td colspan="2">';
8889: if ($same_institution) {
8890: my %domservers = &Apache::lonnet::get_servers($dom);
8891: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8892: } else {
8893: $datatable .= &mt("You need to be logged into one of your own domain's servers to display information about the status of LON-CAPA SSL certificates.");
8894: }
8895: $datatable .= '</td></tr>';
1.275 raeburn 8896: $itemcount ++;
8897: } else {
8898: my %titles = &ssl_titles();
8899: my (%by_ip,%by_location,@intdoms,@instdoms);
8900: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8901: my @alldoms = &Apache::lonnet::all_domains();
8902: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8903: my @domservers = &Apache::lonnet::get_servers($dom);
8904: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8905: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8906: if (($position eq 'connto') || ($position eq 'connfrom')) {
8907: my $legacy;
8908: unless (ref($settings) eq 'HASH') {
8909: my $name;
8910: if ($position eq 'connto') {
8911: $name = 'loncAllowInsecure';
8912: } else {
8913: $name = 'londAllowInsecure';
8914: }
8915: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8916: my @ids=&Apache::lonnet::current_machine_ids();
8917: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8918: my %what = (
8919: $name => 1,
8920: );
8921: my ($result,$returnhash) =
8922: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8923: if ($result eq 'ok') {
8924: if (ref($returnhash) eq 'HASH') {
8925: $legacy = $returnhash->{$name};
8926: }
8927: }
8928: } else {
8929: $legacy = $Apache::lonnet::perlvar{$name};
8930: }
8931: }
1.275 raeburn 8932: foreach my $type ('dom','intdom','other') {
8933: my %checked;
8934: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8935: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8936: '<td class="LC_right_item">';
8937: my $skip;
8938: if ($type eq 'dom') {
8939: unless (keys(%servers) > 1) {
8940: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8941: $skip = 1;
8942: }
8943: }
8944: if ($type eq 'intdom') {
8945: unless (@instdoms > 1) {
8946: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8947: $skip = 1;
8948: }
8949: } elsif ($type eq 'other') {
8950: if (keys(%by_location) == 0) {
8951: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8952: $skip = 1;
8953: }
8954: }
8955: unless ($skip) {
8956: $checked{'yes'} = ' checked="checked"';
8957: if (ref($settings) eq 'HASH') {
1.293 raeburn 8958: if (ref($settings->{$position}) eq 'HASH') {
8959: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8960: $checked{$1} = $checked{'yes'};
8961: delete($checked{'yes'});
8962: }
8963: }
1.293 raeburn 8964: } else {
8965: if ($legacy == 0) {
8966: $checked{'req'} = $checked{'yes'};
8967: delete($checked{'yes'});
8968: }
1.275 raeburn 8969: }
8970: foreach my $option ('no','yes','req') {
8971: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8972: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8973: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8974: '</label></span>'.(' 'x2);
8975: }
8976: }
8977: $datatable .= '</td></tr>';
8978: $itemcount ++;
8979: }
8980: } else {
8981: my $prefix = 'replication';
8982: my @types = ('certreq','nocertreq');
1.279 raeburn 8983: if (keys(%by_location) == 0) {
8984: $datatable .= '<tr'.$css_class.'><td>'.
8985: &mt('Nothing to set here, as there are no other institutions').
8986: '</td></tr>';
8987: $itemcount ++;
1.275 raeburn 8988: } else {
1.279 raeburn 8989: ($datatable,$itemcount) =
8990: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8991: }
8992: }
8993: }
8994: $$rowtotal += $itemcount;
8995: return $datatable;
8996: }
8997:
8998: sub ssl_titles {
8999: return &Apache::lonlocal::texthash (
9000: dom => 'LON-CAPA servers/VMs from same domain',
9001: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
9002: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 9003: connto => 'Connections to other servers',
9004: connfrom => 'Connections from other servers',
1.275 raeburn 9005: replication => 'Replicating content to other institutions',
9006: certreq => 'Client certificate required, but specific domains exempt',
9007: nocertreq => 'No client certificate required, except for specific domains',
9008: no => 'SSL not used',
9009: yes => 'SSL Optional (used if available)',
9010: req => 'SSL Required',
9011: );
1.279 raeburn 9012: }
9013:
9014: sub print_trust {
9015: my ($prefix,$dom,$settings,$rowtotal) = @_;
9016: my ($css_class,$datatable,%checked,%choices);
9017: my (%by_ip,%by_location,@intdoms,@instdoms);
9018: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
9019: my $itemcount = 1;
9020: my %titles = &trust_titles();
9021: my @types = ('exc','inc');
9022: if ($prefix eq 'top') {
9023: $prefix = 'content';
9024: } elsif ($prefix eq 'bottom') {
9025: $prefix = 'msg';
9026: }
9027: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
9028: $$rowtotal += $itemcount;
9029: return $datatable;
9030: }
9031:
9032: sub trust_titles {
9033: return &Apache::lonlocal::texthash(
9034: content => "Access to this domain's content by others",
9035: shared => "Access to other domain's content by this domain",
9036: enroll => "Enrollment in this domain's courses by others",
9037: othcoau => "Co-author roles in this domain for others",
9038: coaurem => "Co-author roles for this domain's users elsewhere",
9039: domroles => "Domain roles in this domain assignable to others",
9040: catalog => "Course Catalog for this domain displayed elsewhere",
9041: reqcrs => "Requests for creation of courses in this domain by others",
9042: msg => "Users in other domains can send messages to this domain",
9043: exc => "Allow all, but exclude specific domains",
9044: inc => "Deny all, but include specific domains",
9045: );
1.275 raeburn 9046: }
9047:
1.138 raeburn 9048: sub build_location_hashes {
1.275 raeburn 9049: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 9050: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 9051: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 9052: my %iphost = &Apache::lonnet::get_iphost();
9053: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
9054: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
9055: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
9056: foreach my $id (@{$iphost{$primary_ip}}) {
9057: my $intdom = &Apache::lonnet::internet_dom($id);
9058: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
9059: push(@{$intdoms},$intdom);
9060: }
9061: }
9062: }
9063: foreach my $ip (keys(%iphost)) {
9064: if (ref($iphost{$ip}) eq 'ARRAY') {
9065: foreach my $id (@{$iphost{$ip}}) {
9066: my $location = &Apache::lonnet::internet_dom($id);
9067: if ($location) {
1.275 raeburn 9068: if (grep(/^\Q$location\E$/,@{$intdoms})) {
9069: my $dom = &Apache::lonnet::host_domain($id);
9070: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
9071: push(@{$instdoms},$dom);
9072: }
9073: next;
9074: }
1.138 raeburn 9075: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9076: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
9077: push(@{$by_ip->{$ip}},$location);
9078: }
9079: } else {
9080: $by_ip->{$ip} = [$location];
9081: }
9082: }
9083: }
9084: }
9085: }
9086: foreach my $ip (sort(keys(%{$by_ip}))) {
9087: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9088: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
9089: my $first = $by_ip->{$ip}->[0];
9090: if (ref($by_location->{$first}) eq 'ARRAY') {
9091: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
9092: push(@{$by_location->{$first}},$ip);
9093: }
9094: } else {
9095: $by_location->{$first} = [$ip];
9096: }
9097: }
9098: }
9099: return;
9100: }
9101:
1.145 raeburn 9102: sub current_offloads_to {
9103: my ($dom,$settings,$servers) = @_;
9104: my (%spareid,%otherdomconfigs);
1.152 raeburn 9105: if (ref($servers) eq 'HASH') {
1.145 raeburn 9106: foreach my $lonhost (sort(keys(%{$servers}))) {
9107: my $gotspares;
1.152 raeburn 9108: if (ref($settings) eq 'HASH') {
9109: if (ref($settings->{'spares'}) eq 'HASH') {
9110: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9111: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9112: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9113: $gotspares = 1;
9114: }
1.145 raeburn 9115: }
9116: }
9117: unless ($gotspares) {
9118: my $gotspares;
9119: my $serverhomeID =
9120: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9121: my $serverhomedom =
9122: &Apache::lonnet::host_domain($serverhomeID);
9123: if ($serverhomedom ne $dom) {
9124: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9125: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9126: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9127: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9128: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9129: $gotspares = 1;
9130: }
9131: }
9132: } else {
9133: $otherdomconfigs{$serverhomedom} =
9134: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9135: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9136: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9137: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9138: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9139: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9140: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9141: $gotspares = 1;
9142: }
9143: }
9144: }
9145: }
9146: }
9147: }
9148: }
9149: unless ($gotspares) {
9150: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9151: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9152: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9153: } else {
9154: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9155: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9156: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9157: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9158: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9159: } else {
1.150 raeburn 9160: my %what = (
9161: spareid => 1,
9162: );
9163: my ($result,$returnhash) =
9164: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9165: if ($result eq 'ok') {
9166: if (ref($returnhash) eq 'HASH') {
9167: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9168: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9169: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9170: }
9171: }
1.145 raeburn 9172: }
9173: }
9174: }
9175: }
9176: }
9177: }
9178: return %spareid;
9179: }
9180:
9181: sub spares_row {
1.371 raeburn 9182: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9183: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9184: my $css_class;
9185: my $numinrow = 4;
9186: my $itemcount = 1;
9187: my $datatable;
1.152 raeburn 9188: my %typetitles = &sparestype_titles();
9189: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9190: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9191: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9192: my ($othercontrol,$serverdom);
9193: if ($serverhome ne $server) {
9194: $serverdom = &Apache::lonnet::host_domain($serverhome);
9195: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9196: } else {
9197: $serverdom = &Apache::lonnet::host_domain($server);
9198: if ($serverdom ne $dom) {
9199: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9200: }
9201: }
9202: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9203: my ($checkednow,$checkedoth);
1.261 raeburn 9204: if (ref($curroffloadnow) eq 'HASH') {
9205: if ($curroffloadnow->{$server}) {
9206: $checkednow = ' checked="checked"';
9207: }
9208: }
1.371 raeburn 9209: if (ref($curroffloadoth) eq 'HASH') {
9210: if ($curroffloadoth->{$server}) {
9211: $checkedoth = ' checked="checked"';
9212: }
9213: }
1.145 raeburn 9214: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9215: $datatable .= '<tr'.$css_class.'>
9216: <td rowspan="2">
1.183 bisitz 9217: <span class="LC_nobreak">'.
9218: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9219: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9220: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9221: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9222: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9223: "\n";
1.371 raeburn 9224: if ($other_insts) {
9225: $datatable .= '<br />'.
9226: '<span class="LC_nobreak">'."\n".
9227: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9228: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9229: "\n";
9230: }
1.145 raeburn 9231: my (%current,%canselect);
1.152 raeburn 9232: my @choices =
9233: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9234: foreach my $type ('primary','default') {
9235: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9236: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9237: my @spares = @{$spareid->{$server}{$type}};
9238: if (@spares > 0) {
1.152 raeburn 9239: if ($othercontrol) {
9240: $current{$type} = join(', ',@spares);
9241: } else {
9242: $current{$type} .= '<table>';
9243: my $numspares = scalar(@spares);
9244: for (my $i=0; $i<@spares; $i++) {
9245: my $rem = $i%($numinrow);
9246: if ($rem == 0) {
9247: if ($i > 0) {
9248: $current{$type} .= '</tr>';
9249: }
9250: $current{$type} .= '<tr>';
1.145 raeburn 9251: }
1.152 raeburn 9252: $current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" id="spare_'.$type.'_'.$server.'_'.$i.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" onclick="updateNewSpares(this.form,'."'$server'".');" /> '.
9253: $spareid->{$server}{$type}[$i].
9254: '</label></td>'."\n";
9255: }
9256: my $rem = @spares%($numinrow);
9257: my $colsleft = $numinrow - $rem;
9258: if ($colsleft > 1 ) {
9259: $current{$type} .= '<td colspan="'.$colsleft.
9260: '" class="LC_left_item">'.
9261: ' </td>';
9262: } elsif ($colsleft == 1) {
9263: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9264: }
1.152 raeburn 9265: $current{$type} .= '</tr></table>';
1.150 raeburn 9266: }
1.145 raeburn 9267: }
9268: }
9269: if ($current{$type} eq '') {
9270: $current{$type} = &mt('None specified');
9271: }
1.152 raeburn 9272: if ($othercontrol) {
9273: if ($type eq 'primary') {
9274: $canselect{$type} = $othercontrol;
9275: }
9276: } else {
9277: $canselect{$type} =
9278: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9279: '<select name="newspare_'.$type.'_'.$server.'" '.
9280: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9281: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9282: if (@choices > 0) {
9283: foreach my $lonhost (@choices) {
9284: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9285: }
9286: }
9287: $canselect{$type} .= '</select>'."\n";
9288: }
9289: } else {
9290: $current{$type} = &mt('Could not be determined');
9291: if ($type eq 'primary') {
9292: $canselect{$type} = $othercontrol;
9293: }
1.145 raeburn 9294: }
1.152 raeburn 9295: if ($type eq 'default') {
9296: $datatable .= '<tr'.$css_class.'>';
9297: }
9298: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9299: '<td>'.$current{$type}.'</td>'."\n".
9300: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9301: }
9302: $itemcount ++;
9303: }
9304: }
9305: $$rowtotal += $itemcount;
9306: return $datatable;
9307: }
9308:
1.152 raeburn 9309: sub possible_newspares {
9310: my ($server,$currspares,$serverhomes,$altids) = @_;
9311: my $serverhostname = &Apache::lonnet::hostname($server);
9312: my %excluded;
9313: if ($serverhostname ne '') {
9314: %excluded = (
9315: $serverhostname => 1,
9316: );
9317: }
9318: if (ref($currspares) eq 'HASH') {
9319: foreach my $type (keys(%{$currspares})) {
9320: if (ref($currspares->{$type}) eq 'ARRAY') {
9321: if (@{$currspares->{$type}} > 0) {
9322: foreach my $curr (@{$currspares->{$type}}) {
9323: my $hostname = &Apache::lonnet::hostname($curr);
9324: $excluded{$hostname} = 1;
9325: }
9326: }
9327: }
9328: }
9329: }
9330: my @choices;
9331: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9332: if (keys(%{$serverhomes}) > 1) {
9333: foreach my $name (sort(keys(%{$serverhomes}))) {
9334: unless ($excluded{$name}) {
9335: if (exists($altids->{$serverhomes->{$name}})) {
9336: push(@choices,$altids->{$serverhomes->{$name}});
9337: } else {
9338: push(@choices,$serverhomes->{$name});
1.145 raeburn 9339: }
9340: }
9341: }
9342: }
9343: }
1.152 raeburn 9344: return sort(@choices);
1.145 raeburn 9345: }
9346:
1.150 raeburn 9347: sub print_loadbalancing {
9348: my ($dom,$settings,$rowtotal) = @_;
9349: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9350: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9351: my $numinrow = 1;
9352: my $datatable;
9353: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9354: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9355: if (ref($settings) eq 'HASH') {
9356: %existing = %{$settings};
9357: }
9358: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9359: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9360: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9361: } else {
9362: return;
9363: }
9364: my ($othertitle,$usertypes,$types) =
9365: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9366: my $rownum = 8;
1.150 raeburn 9367: if (ref($types) eq 'ARRAY') {
9368: $rownum += scalar(@{$types});
9369: }
1.171 raeburn 9370: my @css_class = ('LC_odd_row','LC_even_row');
9371: my $balnum = 0;
9372: my $islast;
9373: my (@toshow,$disabledtext);
9374: if (keys(%currbalancer) > 0) {
9375: @toshow = sort(keys(%currbalancer));
9376: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9377: push(@toshow,'');
9378: }
9379: } else {
9380: @toshow = ('');
9381: $disabledtext = &mt('No existing load balancer');
9382: }
9383: foreach my $lonhost (@toshow) {
9384: if ($balnum == scalar(@toshow)-1) {
9385: $islast = 1;
9386: } else {
9387: $islast = 0;
9388: }
9389: my $cssidx = $balnum%2;
9390: my $targets_div_style = 'display: none';
9391: my $disabled_div_style = 'display: block';
9392: my $homedom_div_style = 'display: none';
9393: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9394: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9395: '<p>';
9396: if ($lonhost eq '') {
1.210 raeburn 9397: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9398: if (keys(%currbalancer) > 0) {
9399: $datatable .= &mt('Add balancer:');
9400: } else {
9401: $datatable .= &mt('Enable balancer:');
9402: }
9403: $datatable .= ' '.
9404: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9405: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9406: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9407: '<option value="" selected="selected">'.&mt('None').
9408: '</option>'."\n";
9409: foreach my $server (sort(keys(%servers))) {
9410: next if ($currbalancer{$server});
9411: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9412: }
1.210 raeburn 9413: $datatable .=
1.171 raeburn 9414: '</select>'."\n".
9415: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9416: } else {
9417: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9418: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9419: &mt('Stop balancing').'</label>'.
9420: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9421: $targets_div_style = 'display: block';
9422: $disabled_div_style = 'display: none';
9423: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9424: $homedom_div_style = 'display: block';
9425: }
9426: }
1.306 raeburn 9427: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9428: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9429: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9430: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9431: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9432: my @sparestypes = ('primary','default');
9433: my %typetitles = &sparestype_titles();
1.284 raeburn 9434: my %hostherechecked = (
9435: no => ' checked="checked"',
9436: );
1.342 raeburn 9437: my %balcookiechecked = (
1.425 raeburn 9438: no => ' checked="checked"',
1.342 raeburn 9439: );
1.171 raeburn 9440: foreach my $sparetype (@sparestypes) {
9441: my $targettable;
9442: for (my $i=0; $i<$numspares; $i++) {
9443: my $checked;
9444: if (ref($currtargets{$lonhost}) eq 'HASH') {
9445: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9446: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9447: $checked = ' checked="checked"';
9448: }
9449: }
9450: }
9451: my ($chkboxval,$disabled);
9452: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9453: $chkboxval = $spares[$i];
9454: }
9455: if (exists($currbalancer{$spares[$i]})) {
9456: $disabled = ' disabled="disabled"';
9457: }
1.210 raeburn 9458: $targettable .=
1.253 raeburn 9459: '<td><span class="LC_nobreak"><label>'.
9460: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9461: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.253 raeburn 9462: '</span></label></span></td>';
1.171 raeburn 9463: my $rem = $i%($numinrow);
9464: if ($rem == 0) {
9465: if (($i > 0) && ($i < $numspares-1)) {
9466: $targettable .= '</tr>';
9467: }
9468: if ($i < $numspares-1) {
9469: $targettable .= '<tr>';
1.150 raeburn 9470: }
9471: }
9472: }
1.171 raeburn 9473: if ($targettable ne '') {
9474: my $rem = $numspares%($numinrow);
9475: my $colsleft = $numinrow - $rem;
9476: if ($colsleft > 1 ) {
9477: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9478: ' </td>';
9479: } elsif ($colsleft == 1) {
9480: $targettable .= '<td class="LC_left_item"> </td>';
9481: }
9482: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9483: '<table><tr>'.$targettable.'</tr></table><br />';
9484: }
1.284 raeburn 9485: $hostherechecked{$sparetype} = '';
9486: if (ref($currtargets{$lonhost}) eq 'HASH') {
9487: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9488: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9489: $hostherechecked{$sparetype} = ' checked="checked"';
9490: $hostherechecked{'no'} = '';
9491: }
9492: }
9493: }
9494: }
1.342 raeburn 9495: if ($currcookies{$lonhost}) {
9496: %balcookiechecked = (
9497: yes => ' checked="checked"',
9498: );
9499: }
1.284 raeburn 9500: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9501: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9502: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9503: foreach my $sparetype (@sparestypes) {
9504: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9505: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9506: '</i></label><br />';
1.171 raeburn 9507: }
1.342 raeburn 9508: $datatable .= &mt('Use balancer cookie').'<br />'.
9509: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9510: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9511: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9512: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9513: '</div></td></tr>'.
1.171 raeburn 9514: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9515: $othertitle,$usertypes,$types,\%servers,
9516: \%currbalancer,$lonhost,
9517: $targets_div_style,$homedom_div_style,
9518: $css_class[$cssidx],$balnum,$islast);
9519: $$rowtotal += $rownum;
9520: $balnum ++;
9521: }
9522: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9523: return $datatable;
9524: }
9525:
9526: sub get_loadbalancers_config {
1.342 raeburn 9527: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9528: return unless ((ref($servers) eq 'HASH') &&
9529: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9530: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9531: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9532: if (keys(%{$existing}) > 0) {
9533: my $oldlonhost;
9534: foreach my $key (sort(keys(%{$existing}))) {
9535: if ($key eq 'lonhost') {
9536: $oldlonhost = $existing->{'lonhost'};
9537: $currbalancer->{$oldlonhost} = 1;
9538: } elsif ($key eq 'targets') {
9539: if ($oldlonhost) {
9540: $currtargets->{$oldlonhost} = $existing->{'targets'};
9541: }
9542: } elsif ($key eq 'rules') {
9543: if ($oldlonhost) {
9544: $currrules->{$oldlonhost} = $existing->{'rules'};
9545: }
9546: } elsif (ref($existing->{$key}) eq 'HASH') {
9547: $currbalancer->{$key} = 1;
9548: $currtargets->{$key} = $existing->{$key}{'targets'};
9549: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9550: if ($existing->{$key}{'cookie'}) {
9551: $currcookies->{$key} = 1;
9552: }
1.150 raeburn 9553: }
9554: }
1.171 raeburn 9555: } else {
9556: my ($balancerref,$targetsref) =
9557: &Apache::lonnet::get_lonbalancer_config($servers);
9558: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9559: foreach my $server (sort(keys(%{$balancerref}))) {
9560: $currbalancer->{$server} = 1;
9561: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9562: }
9563: }
9564: }
1.171 raeburn 9565: return;
1.150 raeburn 9566: }
9567:
9568: sub loadbalancing_rules {
9569: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9570: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9571: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9572: my $output;
1.171 raeburn 9573: my $num = 0;
1.210 raeburn 9574: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9575: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9576: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9577: foreach my $type (@{$alltypes}) {
1.171 raeburn 9578: $num ++;
1.150 raeburn 9579: my $current;
9580: if (ref($currrules) eq 'HASH') {
9581: $current = $currrules->{$type};
9582: }
1.253 raeburn 9583: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9584: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9585: $current = '';
9586: }
9587: }
9588: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9589: $servers,$currbalancer,$lonhost,$dom,
9590: $targets_div_style,$homedom_div_style,
9591: $css_class,$balnum,$num,$islast);
1.150 raeburn 9592: }
9593: }
9594: return $output;
9595: }
9596:
9597: sub loadbalancing_titles {
9598: my ($dom,$intdom,$usertypes,$types) = @_;
9599: my %othertypes = (
9600: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9601: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9602: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9603: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9604: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9605: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9606: );
1.209 raeburn 9607: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9608: my @available;
1.150 raeburn 9609: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9610: @available = @{$types};
1.150 raeburn 9611: }
1.302 raeburn 9612: unless (grep(/^default$/,@available)) {
9613: push(@available,'default');
9614: }
9615: unshift(@alltypes,@available);
1.150 raeburn 9616: my %titles;
9617: foreach my $type (@alltypes) {
9618: if ($type =~ /^_LC_/) {
9619: $titles{$type} = $othertypes{$type};
9620: } elsif ($type eq 'default') {
9621: $titles{$type} = &mt('All users from [_1]',$dom);
9622: if (ref($types) eq 'ARRAY') {
9623: if (@{$types} > 0) {
9624: $titles{$type} = &mt('Other users from [_1]',$dom);
9625: }
9626: }
9627: } elsif (ref($usertypes) eq 'HASH') {
9628: $titles{$type} = $usertypes->{$type};
9629: }
9630: }
9631: return (\@alltypes,\%othertypes,\%titles);
9632: }
9633:
9634: sub loadbalance_rule_row {
1.171 raeburn 9635: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9636: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9637: my @rulenames;
1.150 raeburn 9638: my %ruletitles = &offloadtype_text();
1.209 raeburn 9639: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9640: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9641: } else {
1.209 raeburn 9642: @rulenames = ('default','homeserver');
9643: if ($type eq '_LC_external') {
9644: push(@rulenames,'externalbalancer');
9645: } else {
9646: push(@rulenames,'specific');
9647: }
9648: push(@rulenames,'none');
1.150 raeburn 9649: }
9650: my $style = $targets_div_style;
1.253 raeburn 9651: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9652: $style = $homedom_div_style;
9653: }
1.171 raeburn 9654: my $space;
9655: if ($islast && $num == 1) {
1.317 raeburn 9656: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9657: }
1.210 raeburn 9658: my $output =
1.306 raeburn 9659: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9660: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9661: '<td valaign="top">'.$space.
9662: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9663: for (my $i=0; $i<@rulenames; $i++) {
9664: my $rule = $rulenames[$i];
9665: my ($checked,$extra);
9666: if ($rulenames[$i] eq 'default') {
9667: $rule = '';
9668: }
9669: if ($rulenames[$i] eq 'specific') {
9670: if (ref($servers) eq 'HASH') {
9671: my $default;
9672: if (($current ne '') && (exists($servers->{$current}))) {
9673: $checked = ' checked="checked"';
9674: }
9675: unless ($checked) {
9676: $default = ' selected="selected"';
9677: }
1.210 raeburn 9678: $extra =
1.171 raeburn 9679: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9680: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9681: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9682: '<option value=""'.$default.'></option>'."\n";
9683: foreach my $server (sort(keys(%{$servers}))) {
9684: if (ref($currbalancer) eq 'HASH') {
9685: next if (exists($currbalancer->{$server}));
9686: }
1.150 raeburn 9687: my $selected;
1.171 raeburn 9688: if ($server eq $current) {
1.150 raeburn 9689: $selected = ' selected="selected"';
9690: }
1.171 raeburn 9691: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9692: }
9693: $extra .= '</select>';
9694: }
9695: } elsif ($rule eq $current) {
9696: $checked = ' checked="checked"';
9697: }
9698: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9699: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9700: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9701: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9702: ')"'.$checked.' /> ';
9703: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9704: $output .= $ruletitles{'particular'};
9705: } else {
9706: $output .= $ruletitles{$rulenames[$i]};
9707: }
9708: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9709: }
9710: $output .= '</div></td></tr>'."\n";
9711: return $output;
9712: }
9713:
9714: sub offloadtype_text {
9715: my %ruletitles = &Apache::lonlocal::texthash (
9716: 'default' => 'Offloads to default destinations',
9717: 'homeserver' => "Offloads to user's home server",
9718: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9719: 'specific' => 'Offloads to specific server',
1.161 raeburn 9720: 'none' => 'No offload',
1.209 raeburn 9721: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9722: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9723: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9724: );
9725: return %ruletitles;
9726: }
9727:
9728: sub sparestype_titles {
9729: my %typestitles = &Apache::lonlocal::texthash (
9730: 'primary' => 'primary',
9731: 'default' => 'default',
9732: );
9733: return %typestitles;
9734: }
9735:
1.28 raeburn 9736: sub contact_titles {
9737: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9738: 'supportemail' => 'Support E-mail address',
9739: 'adminemail' => 'Default Server Admin E-mail address',
9740: 'errormail' => 'Error reports to be e-mailed to',
9741: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9742: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9743: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9744: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9745: 'requestsmail' => 'E-mail from course requests requiring approval',
9746: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9747: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9748: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9749: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9750: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9751: 'errorweights' => 'Weights used to compute error count',
9752: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9753: );
9754: my %short_titles = &Apache::lonlocal::texthash (
9755: adminemail => 'Admin E-mail address',
9756: supportemail => 'Support E-mail',
9757: );
9758: return (\%titles,\%short_titles);
9759: }
9760:
1.286 raeburn 9761: sub helpform_fields {
9762: my %titles = &Apache::lonlocal::texthash (
9763: 'username' => 'Name',
9764: 'user' => 'Username/domain',
9765: 'phone' => 'Phone',
9766: 'cc' => 'Cc e-mail',
9767: 'course' => 'Course Details',
9768: 'section' => 'Sections',
1.289 raeburn 9769: 'screenshot' => 'File upload',
1.286 raeburn 9770: );
9771: my @fields = ('username','phone','user','course','section','cc','screenshot');
9772: my %possoptions = (
9773: username => ['yes','no','req'],
1.289 raeburn 9774: phone => ['yes','no','req'],
1.286 raeburn 9775: user => ['yes','no'],
1.289 raeburn 9776: cc => ['yes','no'],
1.286 raeburn 9777: course => ['yes','no'],
9778: section => ['yes','no'],
9779: screenshot => ['yes','no'],
9780: );
9781: my %fieldoptions = &Apache::lonlocal::texthash (
9782: 'yes' => 'Optional',
9783: 'req' => 'Required',
9784: 'no' => "Not shown",
9785: );
9786: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9787: }
9788:
1.72 raeburn 9789: sub tool_titles {
9790: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9791: aboutme => 'Personal web page',
1.86 raeburn 9792: blog => 'Blog',
9793: portfolio => 'Portfolio',
1.430 raeburn 9794: portaccess => 'Share portfolio files',
1.413 raeburn 9795: timezone => 'Can set time zone',
1.88 bisitz 9796: official => 'Official courses (with institutional codes)',
9797: unofficial => 'Unofficial courses',
1.98 raeburn 9798: community => 'Communities',
1.216 raeburn 9799: textbook => 'Textbook courses',
1.271 raeburn 9800: placement => 'Placement tests',
1.86 raeburn 9801: );
1.72 raeburn 9802: return %titles;
9803: }
9804:
1.101 raeburn 9805: sub courserequest_titles {
9806: my %titles = &Apache::lonlocal::texthash (
9807: official => 'Official',
9808: unofficial => 'Unofficial',
9809: community => 'Communities',
1.216 raeburn 9810: textbook => 'Textbook',
1.271 raeburn 9811: placement => 'Placement tests',
1.325 raeburn 9812: lti => 'LTI Provider',
1.101 raeburn 9813: norequest => 'Not allowed',
1.325 raeburn 9814: approval => 'Approval by DC',
1.101 raeburn 9815: validate => 'With validation',
9816: autolimit => 'Numerical limit',
1.103 raeburn 9817: unlimited => '(blank for unlimited)',
1.101 raeburn 9818: );
9819: return %titles;
9820: }
9821:
1.163 raeburn 9822: sub authorrequest_titles {
9823: my %titles = &Apache::lonlocal::texthash (
9824: norequest => 'Not allowed',
9825: approval => 'Approval by Dom. Coord.',
9826: automatic => 'Automatic approval',
9827: );
9828: return %titles;
1.210 raeburn 9829: }
1.163 raeburn 9830:
1.101 raeburn 9831: sub courserequest_conditions {
9832: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9833: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9834: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9835: );
9836: return %conditions;
9837: }
9838:
9839:
1.27 raeburn 9840: sub print_usercreation {
1.30 raeburn 9841: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9842: my $numinrow = 4;
1.28 raeburn 9843: my $datatable;
9844: if ($position eq 'top') {
1.30 raeburn 9845: $$rowtotal ++;
1.34 raeburn 9846: my $rowcount = 0;
1.32 raeburn 9847: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9848: if (ref($rules) eq 'HASH') {
9849: if (keys(%{$rules}) > 0) {
1.32 raeburn 9850: $datatable .= &user_formats_row('username',$settings,$rules,
9851: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9852: $$rowtotal ++;
1.32 raeburn 9853: $rowcount ++;
9854: }
9855: }
9856: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9857: if (ref($idrules) eq 'HASH') {
9858: if (keys(%{$idrules}) > 0) {
9859: $datatable .= &user_formats_row('id',$settings,$idrules,
9860: $idruleorder,$numinrow,$rowcount);
9861: $$rowtotal ++;
9862: $rowcount ++;
1.28 raeburn 9863: }
9864: }
1.39 raeburn 9865: if ($rowcount == 0) {
9866: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9867: $$rowtotal ++;
9868: $rowcount ++;
9869: }
1.34 raeburn 9870: } elsif ($position eq 'middle') {
1.224 raeburn 9871: my @creators = ('author','course','requestcrs');
1.37 raeburn 9872: my ($rules,$ruleorder) =
9873: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9874: my %lt = &usercreation_types();
9875: my %checked;
9876: if (ref($settings) eq 'HASH') {
9877: if (ref($settings->{'cancreate'}) eq 'HASH') {
9878: foreach my $item (@creators) {
9879: $checked{$item} = $settings->{'cancreate'}{$item};
9880: }
9881: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9882: foreach my $item (@creators) {
9883: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9884: $checked{$item} = 'none';
9885: }
9886: }
9887: }
9888: }
9889: my $rownum = 0;
9890: foreach my $item (@creators) {
9891: $rownum ++;
1.224 raeburn 9892: if ($checked{$item} eq '') {
9893: $checked{$item} = 'any';
1.34 raeburn 9894: }
9895: my $css_class;
9896: if ($rownum%2) {
9897: $css_class = '';
9898: } else {
9899: $css_class = ' class="LC_odd_row" ';
9900: }
9901: $datatable .= '<tr'.$css_class.'>'.
9902: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9903: '</span></td><td style="text-align: right">';
1.224 raeburn 9904: my @options = ('any');
9905: if (ref($rules) eq 'HASH') {
9906: if (keys(%{$rules}) > 0) {
9907: push(@options,('official','unofficial'));
1.37 raeburn 9908: }
9909: }
1.224 raeburn 9910: push(@options,'none');
1.37 raeburn 9911: foreach my $option (@options) {
1.50 raeburn 9912: my $type = 'radio';
1.34 raeburn 9913: my $check = ' ';
1.224 raeburn 9914: if ($checked{$item} eq $option) {
9915: $check = ' checked="checked" ';
1.34 raeburn 9916: }
9917: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9918: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9919: $item.'" value="'.$option.'"'.$check.'/> '.
9920: $lt{$option}.'</label> </span>';
9921: }
9922: $datatable .= '</td></tr>';
9923: }
1.28 raeburn 9924: } else {
9925: my @contexts = ('author','course','domain');
1.325 raeburn 9926: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9927: my %checked;
9928: if (ref($settings) eq 'HASH') {
9929: if (ref($settings->{'authtypes'}) eq 'HASH') {
9930: foreach my $item (@contexts) {
9931: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9932: foreach my $auth (@authtypes) {
9933: if ($settings->{'authtypes'}{$item}{$auth}) {
9934: $checked{$item}{$auth} = ' checked="checked" ';
9935: }
9936: }
9937: }
9938: }
1.27 raeburn 9939: }
1.35 raeburn 9940: } else {
9941: foreach my $item (@contexts) {
1.36 raeburn 9942: foreach my $auth (@authtypes) {
1.35 raeburn 9943: $checked{$item}{$auth} = ' checked="checked" ';
9944: }
9945: }
1.27 raeburn 9946: }
1.28 raeburn 9947: my %title = &context_names();
9948: my %authname = &authtype_names();
9949: my $rownum = 0;
9950: my $css_class;
9951: foreach my $item (@contexts) {
9952: if ($rownum%2) {
9953: $css_class = '';
9954: } else {
9955: $css_class = ' class="LC_odd_row" ';
9956: }
1.30 raeburn 9957: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9958: '<td>'.$title{$item}.
9959: '</td><td class="LC_left_item">'.
9960: '<span class="LC_nobreak">';
9961: foreach my $auth (@authtypes) {
9962: $datatable .= '<label>'.
9963: '<input type="checkbox" name="'.$item.'_auth" '.
9964: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9965: $authname{$auth}.'</label> ';
9966: }
9967: $datatable .= '</span></td></tr>';
9968: $rownum ++;
1.27 raeburn 9969: }
1.30 raeburn 9970: $$rowtotal += $rownum;
1.27 raeburn 9971: }
9972: return $datatable;
9973: }
9974:
1.224 raeburn 9975: sub print_selfcreation {
9976: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9977: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9978: $emaildomain,$datatable);
1.224 raeburn 9979: if (ref($settings) eq 'HASH') {
9980: if (ref($settings->{'cancreate'}) eq 'HASH') {
9981: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9982: if (ref($createsettings) eq 'HASH') {
9983: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9984: @selfcreate = @{$createsettings->{'selfcreate'}};
9985: } elsif ($createsettings->{'selfcreate'} ne '') {
9986: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9987: @selfcreate = ('email','login','sso');
9988: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9989: @selfcreate = ($createsettings->{'selfcreate'});
9990: }
9991: }
9992: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9993: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9994: }
1.305 raeburn 9995: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9996: $emailoptions = $createsettings->{'emailoptions'};
9997: }
1.303 raeburn 9998: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9999: $emailverified = $createsettings->{'emailverified'};
10000: }
10001: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
10002: $emaildomain = $createsettings->{'emaildomain'};
10003: }
1.224 raeburn 10004: }
10005: }
10006: }
10007: my %radiohash;
10008: my $numinrow = 4;
10009: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 10010: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 10011: if ($position eq 'top') {
10012: my %choices = &Apache::lonlocal::texthash (
10013: cancreate_login => 'Institutional Login',
10014: cancreate_sso => 'Institutional Single Sign On',
10015: );
10016: my @toggles = sort(keys(%choices));
10017: my %defaultchecked = (
10018: 'cancreate_login' => 'off',
10019: 'cancreate_sso' => 'off',
10020: );
1.228 raeburn 10021: my ($onclick,$itemcount);
1.224 raeburn 10022: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10023: \%choices,$itemcount,$onclick);
1.228 raeburn 10024: $$rowtotal += $itemcount;
1.425 raeburn 10025:
1.224 raeburn 10026: if (ref($usertypes) eq 'HASH') {
10027: if (keys(%{$usertypes}) > 0) {
10028: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
10029: $dom,$numinrow,$othertitle,
1.305 raeburn 10030: 'statustocreate',$rowtotal);
1.224 raeburn 10031: $$rowtotal ++;
10032: }
10033: }
1.240 raeburn 10034: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
10035: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10036: $fieldtitles{'inststatus'} = &mt('Institutional status');
10037: my $rem;
10038: my $numperrow = 2;
10039: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
10040: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 10041: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 10042: '<td class="LC_left_item">'."\n".
1.334 raeburn 10043: '<table>'."\n";
1.240 raeburn 10044: for (my $i=0; $i<@fields; $i++) {
10045: $rem = $i%($numperrow);
10046: if ($rem == 0) {
10047: if ($i > 0) {
10048: $datatable .= '</tr>';
10049: }
10050: $datatable .= '<tr>';
10051: }
10052: my $currval;
1.248 raeburn 10053: if (ref($createsettings) eq 'HASH') {
10054: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
10055: $currval = $createsettings->{'shibenv'}{$fields[$i]};
10056: }
1.240 raeburn 10057: }
10058: $datatable .= '<td class="LC_left_item">'.
10059: '<span class="LC_nobreak">'.
10060: '<input type="text" name="shibenv_'.$fields[$i].'" '.
10061: 'value="'.$currval.'" size="10" /> '.
10062: $fieldtitles{$fields[$i]}.'</span></td>';
10063: }
10064: my $colsleft = $numperrow - $rem;
10065: if ($colsleft > 1 ) {
10066: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10067: ' </td>';
10068: } elsif ($colsleft == 1) {
10069: $datatable .= '<td class="LC_left_item"> </td>';
10070: }
10071: $datatable .= '</tr></table></td></tr>';
10072: $$rowtotal ++;
1.224 raeburn 10073: } elsif ($position eq 'middle') {
10074: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 10075: my @posstypes;
1.224 raeburn 10076: if (ref($types) eq 'ARRAY') {
1.302 raeburn 10077: @posstypes = @{$types};
10078: }
10079: unless (grep(/^default$/,@posstypes)) {
10080: push(@posstypes,'default');
10081: }
10082: my %usertypeshash;
10083: if (ref($usertypes) eq 'HASH') {
10084: %usertypeshash = %{$usertypes};
10085: }
10086: $usertypeshash{'default'} = $othertitle;
10087: foreach my $status (@posstypes) {
10088: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
10089: $numinrow,$$rowtotal,\%usertypeshash);
10090: $$rowtotal ++;
1.224 raeburn 10091: }
10092: } else {
1.236 raeburn 10093: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 10094: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 10095: );
10096: my @toggles = sort(keys(%choices));
10097: my %defaultchecked = (
10098: 'cancreate_email' => 'off',
10099: );
1.305 raeburn 10100: my $customclass = 'LC_selfcreate_email';
10101: my $classprefix = 'LC_canmodify_emailusername_';
10102: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10103: my $display = 'none';
1.305 raeburn 10104: my $rowstyle = 'display:none';
1.236 raeburn 10105: if (grep(/^\Qemail\E$/,@selfcreate)) {
10106: $display = 'block';
1.305 raeburn 10107: $rowstyle = 'display:table-row';
1.236 raeburn 10108: }
1.305 raeburn 10109: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10110: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10111: \%choices,$$rowtotal,$onclick);
10112: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10113: $rowstyle);
10114: $$rowtotal ++;
10115: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10116: $rowstyle);
10117: $$rowtotal ++;
10118: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10119: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10120: my ($emailrules,$emailruleorder) =
10121: &Apache::lonnet::inst_userrules($dom,'email');
10122: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10123: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10124: if (ref($types) eq 'ARRAY') {
10125: @posstypes = @{$types};
10126: }
10127: if (@posstypes) {
10128: unless (grep(/^default$/,@posstypes)) {
10129: push(@posstypes,'default');
1.302 raeburn 10130: }
10131: if (ref($usertypes) eq 'HASH') {
10132: %usertypeshash = %{$usertypes};
10133: }
1.305 raeburn 10134: my $currassign;
10135: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10136: $currassign = {
10137: selfassign => $domdefaults{'inststatusguest'},
10138: };
10139: @ordered = @{$domdefaults{'inststatusguest'}};
10140: } else {
10141: $currassign = { selfassign => [] };
10142: }
10143: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10144: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10145: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10146: $numinrow,$othertitle,'selfassign',
10147: $rowtotal,$onclicktypes,$customclass,
10148: $rowstyle);
10149: $$rowtotal ++;
1.302 raeburn 10150: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10151: foreach my $status (@posstypes) {
10152: my $css_class;
10153: if ($$rowtotal%2) {
10154: $css_class = 'LC_odd_row ';
10155: }
10156: $css_class .= $customclass;
10157: my $rowid = $optionsprefix.$status;
10158: my $hidden = 1;
10159: my $currstyle = 'display:none';
10160: if (grep(/^\Q$status\E$/,@ordered)) {
10161: $currstyle = $rowstyle;
1.425 raeburn 10162: $hidden = 0;
1.305 raeburn 10163: }
10164: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10165: $emailrules,$emailruleorder,$settings,$status,$rowid,
10166: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10167: unless ($hidden) {
10168: $$rowtotal ++;
10169: }
1.224 raeburn 10170: }
1.302 raeburn 10171: } else {
1.305 raeburn 10172: my $css_class;
10173: if ($$rowtotal%2) {
10174: $css_class = 'LC_odd_row ';
10175: }
10176: $css_class .= $customclass;
1.302 raeburn 10177: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10178: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10179: $emailrules,$emailruleorder,$settings,'default','',
10180: $othertitle,$css_class,$rowstyle,$intdom);
10181: $$rowtotal ++;
1.224 raeburn 10182: }
10183: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10184: $numinrow = 1;
1.305 raeburn 10185: if (@posstypes) {
10186: foreach my $status (@posstypes) {
10187: my $rowid = $classprefix.$status;
10188: my $datarowstyle = 'display:none';
1.425 raeburn 10189: if (grep(/^\Q$status\E$/,@ordered)) {
10190: $datarowstyle = $rowstyle;
1.305 raeburn 10191: }
10192: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10193: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10194: $infotitles,$rowid,$customclass,$datarowstyle);
10195: unless ($datarowstyle eq 'display:none') {
10196: $$rowtotal ++;
10197: }
1.224 raeburn 10198: }
1.305 raeburn 10199: } else {
10200: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10201: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10202: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10203: }
10204: }
10205: return $datatable;
10206: }
10207:
1.305 raeburn 10208: sub selfcreate_javascript {
10209: return <<"ENDSCRIPT";
10210:
10211: <script type="text/javascript">
10212: // <![CDATA[
10213:
10214: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10215: var x = document.getElementsByClassName(target);
10216: var insttypes = 0;
10217: var insttypeRegExp = new RegExp(prefix);
10218: if ((x.length != undefined) && (x.length > 0)) {
10219: if (form.elements[radio].length != undefined) {
10220: for (var i=0; i<form.elements[radio].length; i++) {
10221: if (form.elements[radio][i].checked) {
10222: if (form.elements[radio][i].value == 1) {
10223: for (var j=0; j<x.length; j++) {
10224: if (x[j].id == 'undefined') {
10225: x[j].style.display = 'table-row';
10226: } else if (insttypeRegExp.test(x[j].id)) {
10227: insttypes ++;
10228: } else {
10229: x[j].style.display = 'table-row';
10230: }
10231: }
10232: } else {
10233: for (var j=0; j<x.length; j++) {
10234: x[j].style.display = 'none';
10235: }
1.236 raeburn 10236: }
1.305 raeburn 10237: break;
10238: }
10239: }
10240: if (insttypes > 0) {
10241: toggleDataRow(form,checkbox,target,altprefix);
10242: toggleDataRow(form,checkbox,target,prefix,1);
10243: }
10244: }
10245: }
10246: return;
10247: }
10248:
10249: function toggleDataRow(form,checkbox,target,prefix,docount) {
10250: if (form.elements[checkbox].length != undefined) {
10251: var count = 0;
10252: if (docount) {
10253: for (var i=0; i<form.elements[checkbox].length; i++) {
10254: if (form.elements[checkbox][i].checked) {
10255: count ++;
1.236 raeburn 10256: }
1.305 raeburn 10257: }
10258: }
10259: for (var i=0; i<form.elements[checkbox].length; i++) {
10260: var type = form.elements[checkbox][i].value;
10261: if (document.getElementById(prefix+type)) {
10262: if (form.elements[checkbox][i].checked) {
10263: document.getElementById(prefix+type).style.display = 'table-row';
10264: if (count % 2 == 1) {
10265: document.getElementById(prefix+type).className = target+' LC_odd_row';
10266: } else {
10267: document.getElementById(prefix+type).className = target;
1.236 raeburn 10268: }
1.305 raeburn 10269: count ++;
1.236 raeburn 10270: } else {
1.305 raeburn 10271: document.getElementById(prefix+type).style.display = 'none';
10272: }
10273: }
10274: }
10275: }
10276: return;
10277: }
10278:
10279: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10280: var caller = radio+'_'+status;
10281: if (form.elements[caller].length != undefined) {
10282: for (var i=0; i<form.elements[caller].length; i++) {
10283: if (form.elements[caller][i].checked) {
10284: if (document.getElementById(altprefix+'_inst_'+status)) {
10285: var curr = form.elements[caller][i].value;
10286: if (prefix) {
10287: document.getElementById(prefix+'_'+status).style.display = 'none';
10288: }
10289: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10290: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10291: if (curr == 'custom') {
1.425 raeburn 10292: if (prefix) {
1.305 raeburn 10293: document.getElementById(prefix+'_'+status).style.display = 'inline';
10294: }
10295: } else if (curr == 'inst') {
10296: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10297: } else if (curr == 'noninst') {
10298: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10299: }
1.305 raeburn 10300: break;
1.236 raeburn 10301: }
10302: }
10303: }
10304: }
10305: }
10306:
1.305 raeburn 10307: // ]]>
10308: </script>
10309:
10310: ENDSCRIPT
10311: }
10312:
10313: sub noninst_users {
10314: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10315: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10316: my $class = 'LC_left_item';
10317: if ($css_class) {
1.425 raeburn 10318: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10319: }
10320: if ($rowid) {
10321: $rowid = ' id="'.$rowid.'"';
10322: }
10323: if ($rowstyle) {
10324: $rowstyle = ' style="'.$rowstyle.'"';
10325: }
10326: my ($output,$description);
10327: if ($type eq 'default') {
10328: $description = &mt('Requests for: [_1]',$typetitle);
10329: } else {
10330: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10331: }
10332: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10333: "<td>$description</td>\n".
1.305 raeburn 10334: '<td class="'.$class.'" colspan="2">'.
10335: '<table><tr>';
1.425 raeburn 10336: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10337: approve => 'Processing',
10338: email => 'E-mail',
10339: username => 'Username',
10340: );
10341: foreach my $item ('approve','email','username') {
10342: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10343: }
1.305 raeburn 10344: $output .= '</tr><tr>';
10345: foreach my $item ('approve','email','username') {
1.306 raeburn 10346: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10347: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10348: if ($item eq 'approve') {
10349: %choices = &Apache::lonlocal::texthash (
10350: automatic => 'Automatically approved',
10351: approval => 'Queued for approval',
10352: );
10353: @options = ('automatic','approval');
10354: $hashref = $processing;
10355: $defoption = 'automatic';
10356: $name = 'cancreate_emailprocess_'.$type;
10357: } elsif ($item eq 'email') {
10358: %choices = &Apache::lonlocal::texthash (
10359: any => 'Any e-mail',
10360: inst => 'Institutional only',
10361: noninst => 'Non-institutional only',
10362: custom => 'Custom restrictions',
10363: );
10364: @options = ('any','inst','noninst');
10365: my $showcustom;
10366: if (ref($emailrules) eq 'HASH') {
10367: if (keys(%{$emailrules}) > 0) {
10368: push(@options,'custom');
10369: $showcustom = 'cancreate_emailrule';
10370: if (ref($settings) eq 'HASH') {
10371: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10372: foreach my $rule (@{$settings->{'email_rule'}}) {
10373: if (exists($emailrules->{$rule})) {
10374: $hascustom ++;
10375: }
10376: }
10377: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10378: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10379: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10380: if (exists($emailrules->{$rule})) {
10381: $hascustom ++;
10382: }
10383: }
10384: }
10385: }
10386: }
10387: }
10388: }
10389: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10390: "'cancreate_emaildomain','$type'".');"';
10391: $hashref = $emailoptions;
10392: $defoption = 'any';
10393: $name = 'cancreate_emailoptions_'.$type;
10394: } elsif ($item eq 'username') {
10395: %choices = &Apache::lonlocal::texthash (
10396: all => 'Same as e-mail',
10397: first => 'Omit @domain',
10398: free => 'Free to choose',
10399: );
10400: @options = ('all','first','free');
10401: $hashref = $emailverified;
10402: $defoption = 'all';
10403: $name = 'cancreate_usernameoptions_'.$type;
10404: }
10405: foreach my $option (@options) {
10406: my $checked;
10407: if (ref($hashref) eq 'HASH') {
10408: if ($type eq '') {
10409: if (!exists($hashref->{'default'})) {
10410: if ($option eq $defoption) {
10411: $checked = ' checked="checked"';
10412: }
10413: } else {
10414: if ($hashref->{'default'} eq $option) {
10415: $checked = ' checked="checked"';
10416: }
1.303 raeburn 10417: }
10418: } else {
1.305 raeburn 10419: if (!exists($hashref->{$type})) {
10420: if ($option eq $defoption) {
10421: $checked = ' checked="checked"';
10422: }
10423: } else {
10424: if ($hashref->{$type} eq $option) {
10425: $checked = ' checked="checked"';
10426: }
1.303 raeburn 10427: }
10428: }
1.305 raeburn 10429: } elsif (($item eq 'email') && ($hascustom)) {
10430: if ($option eq 'custom') {
10431: $checked = ' checked="checked"';
10432: }
10433: } elsif ($option eq $defoption) {
10434: $checked = ' checked="checked"';
10435: }
10436: $output .= '<span class="LC_nobreak"><label>'.
10437: '<input type="radio" name="'.$name.'"'.
10438: $checked.' value="'.$option.'"'.$onclick.' />'.
10439: $choices{$option}.'</label></span><br />';
10440: if ($item eq 'email') {
10441: if ($option eq 'custom') {
10442: my $id = 'cancreate_emailrule_'.$type;
10443: my $display = 'none';
10444: if ($checked) {
10445: $display = 'inline';
1.303 raeburn 10446: }
1.305 raeburn 10447: my $numinrow = 2;
10448: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10449: '<legend>'.&mt('Disallow').'</legend><table>'.
10450: &user_formats_row('email',$settings,$emailrules,
10451: $emailruleorder,$numinrow,'',$type);
10452: '</table></fieldset>';
10453: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10454: my %text = &Apache::lonlocal::texthash (
10455: inst => 'must end:',
10456: noninst => 'cannot end:',
10457: );
10458: my $value;
10459: if (ref($emaildomain) eq 'HASH') {
10460: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10461: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10462: }
10463: }
1.305 raeburn 10464: if ($value eq '') {
10465: $value = '@'.$intdom;
10466: }
10467: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10468: my $display = 'none';
10469: if ($checked) {
10470: $display = 'inline';
10471: }
10472: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10473: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10474: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10475: '</div>';
1.303 raeburn 10476: }
10477: }
10478: }
1.305 raeburn 10479: $output .= '</td>'."\n";
1.303 raeburn 10480: }
1.305 raeburn 10481: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10482: return $output;
10483: }
10484:
1.165 raeburn 10485: sub captcha_choice {
1.305 raeburn 10486: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10487: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10488: $vertext,$currver);
1.165 raeburn 10489: my %lt = &captcha_phrases();
10490: $keyentry = 'hidden';
1.354 raeburn 10491: my $colspan=2;
1.165 raeburn 10492: if ($context eq 'cancreate') {
1.224 raeburn 10493: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10494: } elsif ($context eq 'login') {
10495: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10496: } elsif ($context eq 'passwords') {
10497: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10498: $colspan=1;
1.165 raeburn 10499: }
10500: if (ref($settings) eq 'HASH') {
10501: if ($settings->{'captcha'}) {
10502: $checked{$settings->{'captcha'}} = ' checked="checked"';
10503: } else {
10504: $checked{'original'} = ' checked="checked"';
10505: }
10506: if ($settings->{'captcha'} eq 'recaptcha') {
10507: $pubtext = $lt{'pub'};
10508: $privtext = $lt{'priv'};
10509: $keyentry = 'text';
1.269 raeburn 10510: $vertext = $lt{'ver'};
10511: $currver = $settings->{'recaptchaversion'};
10512: if ($currver ne '2') {
10513: $currver = 1;
10514: }
1.165 raeburn 10515: }
10516: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10517: $currpub = $settings->{'recaptchakeys'}{'public'};
10518: $currpriv = $settings->{'recaptchakeys'}{'private'};
10519: }
10520: } else {
10521: $checked{'original'} = ' checked="checked"';
10522: }
1.305 raeburn 10523: my $css_class;
10524: if ($itemcount%2) {
10525: $css_class = 'LC_odd_row';
10526: }
10527: if ($customcss) {
10528: $css_class .= " $customcss";
10529: }
10530: $css_class =~ s/^\s+//;
10531: if ($css_class) {
10532: $css_class = ' class="'.$css_class.'"';
10533: }
10534: if ($rowstyle) {
10535: $css_class .= ' style="'.$rowstyle.'"';
10536: }
1.169 raeburn 10537: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10538: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10539: '<table><tr><td>'."\n";
10540: foreach my $option ('original','recaptcha','notused') {
10541: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10542: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10543: $lt{$option}.'</label></span>';
10544: unless ($option eq 'notused') {
10545: $output .= (' 'x2)."\n";
10546: }
10547: }
10548: #
10549: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10550: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10551: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10552: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10553: #
1.165 raeburn 10554: $output .= '</td></tr>'."\n".
1.305 raeburn 10555: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10556: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10557: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10558: $currpub.'" size="40" /></span><br />'."\n".
10559: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10560: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10561: $currpriv.'" size="40" /></span><br />'.
10562: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10563: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10564: $currver.'" size="3" /></span><br />'.
10565: '</td></tr></table>'."\n".
1.165 raeburn 10566: '</td></tr>';
10567: return $output;
10568: }
10569:
1.32 raeburn 10570: sub user_formats_row {
1.305 raeburn 10571: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10572: my $output;
10573: my %text = (
10574: 'username' => 'new usernames',
10575: 'id' => 'IDs',
10576: );
1.409 raeburn 10577: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10578: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10579: $output = '<tr '.$css_class.'>'.
10580: '<td><span class="LC_nobreak">'.
10581: &mt("Format rules to check for $text{$type}: ").
10582: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10583: }
1.27 raeburn 10584: my $rem;
10585: if (ref($ruleorder) eq 'ARRAY') {
10586: for (my $i=0; $i<@{$ruleorder}; $i++) {
10587: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10588: my $rem = $i%($numinrow);
10589: if ($rem == 0) {
10590: if ($i > 0) {
10591: $output .= '</tr>';
10592: }
10593: $output .= '<tr>';
10594: }
10595: my $check = ' ';
1.39 raeburn 10596: if (ref($settings) eq 'HASH') {
10597: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10598: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10599: $check = ' checked="checked" ';
10600: }
1.305 raeburn 10601: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10602: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10603: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10604: $check = ' checked="checked" ';
10605: }
10606: }
1.27 raeburn 10607: }
10608: }
1.305 raeburn 10609: my $name = $type.'_rule';
10610: if ($type eq 'email') {
10611: $name .= '_'.$status;
10612: }
1.27 raeburn 10613: $output .= '<td class="LC_left_item">'.
10614: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10615: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10616: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10617: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10618: }
10619: }
10620: $rem = @{$ruleorder}%($numinrow);
10621: }
1.305 raeburn 10622: my $colsleft;
10623: if ($rem) {
10624: $colsleft = $numinrow - $rem;
10625: }
1.27 raeburn 10626: if ($colsleft > 1 ) {
10627: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10628: ' </td>';
10629: } elsif ($colsleft == 1) {
10630: $output .= '<td class="LC_left_item"> </td>';
10631: }
1.409 raeburn 10632: $output .= '</tr>';
10633: unless (($type eq 'email') || ($type eq 'unamemap')) {
10634: $output .= '</table></td></tr>';
1.305 raeburn 10635: }
1.27 raeburn 10636: return $output;
10637: }
10638:
1.34 raeburn 10639: sub usercreation_types {
10640: my %lt = &Apache::lonlocal::texthash (
10641: author => 'When adding a co-author',
10642: course => 'When adding a user to a course',
1.100 raeburn 10643: requestcrs => 'When requesting a course',
1.34 raeburn 10644: any => 'Any',
10645: official => 'Institutional only ',
10646: unofficial => 'Non-institutional only',
10647: none => 'None',
10648: );
10649: return %lt;
1.48 raeburn 10650: }
1.34 raeburn 10651:
1.224 raeburn 10652: sub selfcreation_types {
10653: my %lt = &Apache::lonlocal::texthash (
10654: selfcreate => 'User creates own account',
10655: any => 'Any',
10656: official => 'Institutional only ',
10657: unofficial => 'Non-institutional only',
10658: email => 'E-mail address',
10659: login => 'Institutional Login',
10660: sso => 'SSO',
10661: );
10662: }
10663:
1.28 raeburn 10664: sub authtype_names {
10665: my %lt = &Apache::lonlocal::texthash(
10666: int => 'Internal',
10667: krb4 => 'Kerberos 4',
10668: krb5 => 'Kerberos 5',
10669: loc => 'Local',
1.325 raeburn 10670: lti => 'LTI',
1.28 raeburn 10671: );
10672: return %lt;
10673: }
10674:
10675: sub context_names {
10676: my %context_title = &Apache::lonlocal::texthash(
10677: author => 'Creating users when an Author',
10678: course => 'Creating users when in a course',
10679: domain => 'Creating users when a Domain Coordinator',
10680: );
10681: return %context_title;
10682: }
10683:
1.33 raeburn 10684: sub print_usermodification {
10685: my ($position,$dom,$settings,$rowtotal) = @_;
10686: my $numinrow = 4;
10687: my ($context,$datatable,$rowcount);
10688: if ($position eq 'top') {
10689: $rowcount = 0;
10690: $context = 'author';
10691: foreach my $role ('ca','aa') {
10692: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10693: $numinrow,$rowcount);
10694: $$rowtotal ++;
10695: $rowcount ++;
10696: }
1.443 raeburn 10697: } elsif ($position eq 'middle') {
10698: $rowcount = 0;
10699: $context = 'coauthor';
10700: foreach my $role ('ca','aa') {
10701: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10702: $numinrow,$rowcount);
10703: $$rowtotal ++;
10704: $rowcount ++;
10705: }
1.230 raeburn 10706: } elsif ($position eq 'bottom') {
1.33 raeburn 10707: $context = 'course';
10708: $rowcount = 0;
10709: foreach my $role ('st','ep','ta','in','cr') {
10710: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10711: $numinrow,$rowcount);
10712: $$rowtotal ++;
10713: $rowcount ++;
10714: }
10715: }
10716: return $datatable;
10717: }
10718:
1.43 raeburn 10719: sub print_defaults {
1.236 raeburn 10720: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10721: my $rownum = 0;
1.294 raeburn 10722: my ($datatable,$css_class,$titles);
10723: unless ($position eq 'bottom') {
10724: $titles = &defaults_titles($dom);
10725: }
1.236 raeburn 10726: if ($position eq 'top') {
10727: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10728: 'datelocale_def','portal_def');
10729: my %defaults;
10730: if (ref($settings) eq 'HASH') {
10731: %defaults = %{$settings};
1.43 raeburn 10732: } else {
1.236 raeburn 10733: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10734: foreach my $item (@items) {
10735: $defaults{$item} = $domdefaults{$item};
10736: }
1.43 raeburn 10737: }
1.236 raeburn 10738: foreach my $item (@items) {
10739: if ($rownum%2) {
10740: $css_class = '';
10741: } else {
10742: $css_class = ' class="LC_odd_row" ';
10743: }
10744: $datatable .= '<tr'.$css_class.'>'.
10745: '<td><span class="LC_nobreak">'.$titles->{$item}.
10746: '</span></td><td class="LC_right_item" colspan="3">';
10747: if ($item eq 'auth_def') {
1.325 raeburn 10748: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10749: my %shortauth = (
10750: internal => 'int',
10751: krb4 => 'krb4',
10752: krb5 => 'krb5',
1.325 raeburn 10753: localauth => 'loc',
10754: lti => 'lti',
1.236 raeburn 10755: );
10756: my %authnames = &authtype_names();
10757: foreach my $auth (@authtypes) {
10758: my $checked = ' ';
10759: if ($defaults{$item} eq $auth) {
10760: $checked = ' checked="checked" ';
10761: }
10762: $datatable .= '<label><input type="radio" name="'.$item.
10763: '" value="'.$auth.'"'.$checked.'/>'.
10764: $authnames{$shortauth{$auth}}.'</label> ';
10765: }
10766: } elsif ($item eq 'timezone_def') {
10767: my $includeempty = 1;
10768: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10769: } elsif ($item eq 'datelocale_def') {
10770: my $includeempty = 1;
10771: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10772: } elsif ($item eq 'lang_def') {
1.263 raeburn 10773: my $includeempty = 1;
10774: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10775: } elsif ($item eq 'portal_def') {
10776: $datatable .= '<input type="text" name="'.$item.'" value="'.
10777: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10778: my $portalsty = 'none';
10779: if ($defaults{$item}) {
10780: $portalsty = 'block';
10781: }
10782: foreach my $field ('email','web') {
10783: my $checkedoff = ' checked="checked"';
10784: my $checkedon;
10785: if ($defaults{$item.'_'.$field}) {
10786: $checkedon = $checkedoff;
10787: $checkedoff = '';
1.425 raeburn 10788: }
1.414 raeburn 10789: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10790: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10791: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10792: (' 'x2).
10793: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10794: '</div>';
10795: }
1.236 raeburn 10796: } else {
1.414 raeburn 10797: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10798: }
1.236 raeburn 10799: $datatable .= '</td></tr>';
10800: $rownum ++;
10801: }
1.409 raeburn 10802: } elsif ($position eq 'middle') {
1.294 raeburn 10803: my %defaults;
10804: if (ref($settings) eq 'HASH') {
1.354 raeburn 10805: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10806: my $maxnum = @{$settings->{'inststatusorder'}};
10807: for (my $i=0; $i<$maxnum; $i++) {
10808: $css_class = $rownum%2?' class="LC_odd_row"':'';
10809: my $item = $settings->{'inststatusorder'}->[$i];
10810: my $title = $settings->{'inststatustypes'}->{$item};
10811: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10812: $datatable .= '<tr'.$css_class.'>'.
10813: '<td><span class="LC_nobreak">'.
10814: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10815: for (my $k=0; $k<=$maxnum; $k++) {
10816: my $vpos = $k+1;
10817: my $selstr;
10818: if ($k == $i) {
10819: $selstr = ' selected="selected" ';
10820: }
10821: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10822: }
10823: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10824: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10825: &mt('delete').'</span></td>'.
1.380 raeburn 10826: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10827: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10828: '</span></td></tr>';
10829: }
10830: $css_class = $rownum%2?' class="LC_odd_row"':'';
10831: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10832: $datatable .= '<tr '.$css_class.'>'.
10833: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10834: for (my $k=0; $k<=$maxnum; $k++) {
10835: my $vpos = $k+1;
10836: my $selstr;
10837: if ($k == $maxnum) {
10838: $selstr = ' selected="selected" ';
10839: }
10840: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10841: }
10842: $datatable .= '</select> '.&mt('Internal ID:').
10843: '<input type="text" size="10" name="addinststatus" value="" />'.
10844: ' '.&mt('(new)').
10845: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10846: &mt('Name displayed').':'.
1.354 raeburn 10847: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10848: '</tr>'."\n";
10849: $rownum ++;
1.294 raeburn 10850: }
1.354 raeburn 10851: }
1.409 raeburn 10852: } else {
10853: my ($unamemaprules,$ruleorder) =
10854: &Apache::lonnet::inst_userrules($dom,'unamemap');
10855: $css_class = $rownum%2?' class="LC_odd_row"':'';
10856: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10857: my $numinrow = 2;
10858: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10859: &user_formats_row('unamemap',$settings,$unamemaprules,
10860: $ruleorder,$numinrow).
10861: '</table></td></tr>';
10862: }
10863: if ($datatable eq '') {
10864: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10865: &mt('No rules set for domain in customized localenroll.pm').
10866: '</td></tr>';
10867: }
1.354 raeburn 10868: }
10869: $$rowtotal += $rownum;
1.43 raeburn 10870: return $datatable;
10871: }
10872:
1.168 raeburn 10873: sub get_languages_hash {
10874: my %langchoices;
10875: foreach my $id (&Apache::loncommon::languageids()) {
10876: my $code = &Apache::loncommon::supportedlanguagecode($id);
10877: if ($code ne '') {
10878: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10879: }
10880: }
10881: return %langchoices;
10882: }
10883:
1.43 raeburn 10884: sub defaults_titles {
1.141 raeburn 10885: my ($dom) = @_;
1.43 raeburn 10886: my %titles = &Apache::lonlocal::texthash (
10887: 'auth_def' => 'Default authentication type',
10888: 'auth_arg_def' => 'Default authentication argument',
10889: 'lang_def' => 'Default language',
1.54 raeburn 10890: 'timezone_def' => 'Default timezone',
1.68 raeburn 10891: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10892: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10893: 'email' => 'Email links use portal URL',
10894: 'web' => 'Public web links use portal URL',
1.294 raeburn 10895: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10896: 'intauth_check' => 'Check bcrypt cost if authenticated',
10897: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10898: );
1.141 raeburn 10899: if ($dom) {
10900: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10901: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10902: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10903: $protocol = 'http' if ($protocol ne 'https');
10904: if ($uint_dom) {
10905: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10906: $uint_dom);
10907: }
10908: }
1.43 raeburn 10909: return (\%titles);
10910: }
10911:
1.346 raeburn 10912: sub print_scantron {
10913: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10914: if ($position eq 'top') {
10915: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10916: } else {
10917: return &print_scantronconfig($dom,$settings,\$rowtotal);
10918: }
10919: }
10920:
10921: sub scantron_javascript {
10922: return <<"ENDSCRIPT";
10923:
10924: <script type="text/javascript">
10925: // <![CDATA[
10926:
10927: function toggleScantron(form) {
1.347 raeburn 10928: var csvfieldset = new Array();
1.346 raeburn 10929: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10930: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10931: }
10932: if (document.getElementById('scantroncsv_options')) {
10933: csvfieldset.push(document.getElementById('scantroncsv_options'));
10934: }
10935: if (csvfieldset.length) {
1.346 raeburn 10936: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10937: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10938: if (scantroncsv.checked) {
1.347 raeburn 10939: for (var i=0; i<csvfieldset.length; i++) {
10940: csvfieldset[i].style.display = 'block';
10941: }
1.346 raeburn 10942: } else {
1.347 raeburn 10943: for (var i=0; i<csvfieldset.length; i++) {
10944: csvfieldset[i].style.display = 'none';
10945: }
1.346 raeburn 10946: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10947: if (csvselects.length) {
10948: for (var j=0; j<csvselects.length; j++) {
10949: csvselects[j].selectedIndex = 0;
10950: }
10951: }
10952: }
10953: }
10954: }
10955: return;
10956: }
10957: // ]]>
10958: </script>
10959:
10960: ENDSCRIPT
10961:
10962: }
10963:
1.46 raeburn 10964: sub print_scantronformat {
10965: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10966: my $itemcount = 1;
1.60 raeburn 10967: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10968: %confhash);
1.46 raeburn 10969: my $switchserver = &check_switchserver($dom,$confname);
10970: my %lt = &Apache::lonlocal::texthash (
1.95 www 10971: default => 'Default bubblesheet format file error',
10972: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10973: );
10974: my %scantronfiles = (
10975: default => 'default.tab',
10976: custom => 'custom.tab',
10977: );
10978: foreach my $key (keys(%scantronfiles)) {
10979: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10980: .$scantronfiles{$key};
10981: }
10982: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10983: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10984: if (!$switchserver) {
10985: my $servadm = $r->dir_config('lonAdmEMail');
10986: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10987: if ($configuserok eq 'ok') {
10988: if ($author_ok eq 'ok') {
10989: my %legacyfile = (
1.346 raeburn 10990: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10991: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10992: );
10993: my %md5chk;
10994: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10995: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10996: chomp($md5chk{$type});
1.46 raeburn 10997: }
10998: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10999: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 11000: ($scantronurls{$type},my $error) =
1.46 raeburn 11001: &legacy_scantronformat($r,$dom,$confname,
11002: $type,$legacyfile{$type},
11003: $scantronurls{$type},
11004: $scantronfiles{$type});
1.60 raeburn 11005: if ($error ne '') {
11006: $error{$type} = $error;
11007: }
11008: }
11009: if (keys(%error) == 0) {
11010: $is_custom = 1;
1.346 raeburn 11011: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 11012: $scantronurls{'custom'};
1.346 raeburn 11013: my $putresult =
1.60 raeburn 11014: &Apache::lonnet::put_dom('configuration',
11015: \%confhash,$dom);
11016: if ($putresult ne 'ok') {
1.346 raeburn 11017: $error{'custom'} =
1.60 raeburn 11018: '<span class="LC_error">'.
11019: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11020: }
1.46 raeburn 11021: }
11022: } else {
1.60 raeburn 11023: ($scantronurls{'default'},my $error) =
1.46 raeburn 11024: &legacy_scantronformat($r,$dom,$confname,
11025: 'default',$legacyfile{'default'},
11026: $scantronurls{'default'},
11027: $scantronfiles{'default'});
1.60 raeburn 11028: if ($error eq '') {
11029: $confhash{'scantron'}{'scantronformat'} = '';
11030: my $putresult =
11031: &Apache::lonnet::put_dom('configuration',
11032: \%confhash,$dom);
11033: if ($putresult ne 'ok') {
11034: $error{'default'} =
11035: '<span class="LC_error">'.
11036: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11037: }
11038: } else {
11039: $error{'default'} = $error;
11040: }
1.46 raeburn 11041: }
11042: }
11043: }
11044: } else {
1.95 www 11045: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 11046: }
11047: }
11048: if (ref($settings) eq 'HASH') {
11049: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
11050: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
11051: if ((!@info) || ($info[0] eq 'no_such_dir')) {
11052: $scantronurl = '';
11053: } else {
11054: $scantronurl = $settings->{'scantronformat'};
11055: }
11056: $is_custom = 1;
11057: } else {
11058: $scantronurl = $scantronurls{'default'};
11059: }
11060: } else {
1.60 raeburn 11061: if ($is_custom) {
11062: $scantronurl = $scantronurls{'custom'};
11063: } else {
11064: $scantronurl = $scantronurls{'default'};
11065: }
1.46 raeburn 11066: }
11067: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11068: $datatable .= '<tr'.$css_class.'>';
11069: if (!$is_custom) {
1.65 raeburn 11070: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
11071: '<span class="LC_nobreak">';
1.46 raeburn 11072: if ($scantronurl) {
1.199 raeburn 11073: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
11074: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 11075: } else {
11076: $datatable = &mt('File unavailable for display');
11077: }
1.65 raeburn 11078: $datatable .= '</span></td>';
1.60 raeburn 11079: if (keys(%error) == 0) {
1.306 raeburn 11080: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 11081: if (!$switchserver) {
11082: $datatable .= &mt('Upload:').'<br />';
11083: }
11084: } else {
11085: my $errorstr;
11086: foreach my $key (sort(keys(%error))) {
11087: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11088: }
11089: $datatable .= '<td>'.$errorstr;
11090: }
1.46 raeburn 11091: } else {
11092: if (keys(%error) > 0) {
11093: my $errorstr;
11094: foreach my $key (sort(keys(%error))) {
11095: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11096: }
1.60 raeburn 11097: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 11098: } elsif ($scantronurl) {
1.199 raeburn 11099: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
11100: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 11101: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 11102: $link.
11103: '<label><input type="checkbox" name="scantronformat_del"'.
11104: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 11105: '<td><span class="LC_nobreak"> '.
11106: &mt('Replace:').'</span><br />';
1.46 raeburn 11107: }
11108: }
11109: if (keys(%error) == 0) {
11110: if ($switchserver) {
11111: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
11112: } else {
1.65 raeburn 11113: $datatable .='<span class="LC_nobreak"> '.
11114: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11115: }
11116: }
11117: $datatable .= '</td></tr>';
11118: $$rowtotal ++;
11119: return $datatable;
11120: }
11121:
11122: sub legacy_scantronformat {
11123: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11124: my ($url,$error);
11125: my @statinfo = &Apache::lonnet::stat_file($newurl);
11126: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 11127: my $modified = [];
1.46 raeburn 11128: (my $result,$url) =
1.421 raeburn 11129: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
11130: 'scantron','','',$newfile,$modified);
11131: if ($result eq 'ok') {
11132: &update_modify_urls($r,$modified);
11133: } else {
1.130 raeburn 11134: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11135: }
11136: }
11137: return ($url,$error);
11138: }
1.43 raeburn 11139:
1.346 raeburn 11140: sub print_scantronconfig {
11141: my ($dom,$settings,$rowtotal) = @_;
11142: my $itemcount = 2;
11143: my $is_checked = ' checked="checked"';
1.347 raeburn 11144: my %optionson = (
11145: hdr => ' checked="checked"',
11146: pad => ' checked="checked"',
11147: rem => ' checked="checked"',
11148: );
11149: my %optionsoff = (
11150: hdr => '',
11151: pad => '',
11152: rem => '',
11153: );
1.346 raeburn 11154: my $currcsvsty = 'none';
1.347 raeburn 11155: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11156: my @fields = &scantroncsv_fields();
11157: my %titles = &scantronconfig_titles();
11158: if (ref($settings) eq 'HASH') {
11159: if (ref($settings->{config}) eq 'HASH') {
11160: if ($settings->{config}->{dat}) {
11161: $checked{'dat'} = $is_checked;
11162: }
11163: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11164: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11165: %csvfields = %{$settings->{config}->{csv}->{fields}};
11166: if (keys(%csvfields) > 0) {
11167: $checked{'csv'} = $is_checked;
11168: $currcsvsty = 'block';
11169: }
11170: }
11171: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11172: %csvoptions = %{$settings->{config}->{csv}->{options}};
11173: foreach my $option (keys(%optionson)) {
11174: unless ($csvoptions{$option}) {
11175: $optionsoff{$option} = $optionson{$option};
11176: $optionson{$option} = '';
11177: }
11178: }
1.346 raeburn 11179: }
11180: }
11181: } else {
11182: $checked{'dat'} = $is_checked;
11183: }
11184: } else {
11185: $checked{'dat'} = $is_checked;
11186: }
11187: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11188: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11189: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11190: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11191: foreach my $item ('dat','csv') {
11192: my $id;
11193: if ($item eq 'csv') {
11194: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11195: }
1.346 raeburn 11196: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11197: $titles{$item}.'</label>'.(' 'x3);
11198: if ($item eq 'csv') {
11199: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11200: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11201: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11202: foreach my $col (@fields) {
11203: my $selnone;
11204: if ($csvfields{$col} eq '') {
11205: $selnone = ' selected="selected"';
11206: }
11207: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11208: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11209: '<option value=""'.$selnone.'></option>';
11210: for (my $i=0; $i<20; $i++) {
11211: my $shown = $i+1;
11212: my $sel;
11213: unless ($selnone) {
11214: if (exists($csvfields{$col})) {
11215: if ($csvfields{$col} == $i) {
11216: $sel = ' selected="selected"';
11217: }
11218: }
11219: }
11220: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11221: }
11222: $datatable .= '</select></td></tr>';
11223: }
1.347 raeburn 11224: $datatable .= '</table></fieldset>'.
11225: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11226: '<legend>'.&mt('CSV Options').'</legend>';
11227: foreach my $option ('hdr','pad','rem') {
11228: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11229: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11230: &mt('Yes').'</label>'.(' 'x2)."\n".
11231: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11232: }
11233: $datatable .= '</fieldset>';
1.346 raeburn 11234: $itemcount ++;
11235: }
11236: }
11237: $datatable .= '</td></tr>';
11238: $$rowtotal ++;
11239: return $datatable;
11240: }
11241:
11242: sub scantronconfig_titles {
11243: return &Apache::lonlocal::texthash(
11244: dat => 'Standard format (.dat)',
11245: csv => 'Comma separated values (.csv)',
1.347 raeburn 11246: hdr => 'Remove first line in file (contains column titles)',
11247: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11248: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11249: CODE => 'CODE',
11250: ID => 'Student ID',
11251: PaperID => 'Paper ID',
11252: FirstName => 'First Name',
11253: LastName => 'Last Name',
11254: FirstQuestion => 'First Question Response',
11255: Section => 'Section',
11256: );
11257: }
11258:
11259: sub scantroncsv_fields {
11260: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11261: }
11262:
1.49 raeburn 11263: sub print_coursecategories {
1.57 raeburn 11264: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11265: my $datatable;
11266: if ($position eq 'top') {
1.238 raeburn 11267: my (%checked);
11268: my @catitems = ('unauth','auth');
11269: my @cattypes = ('std','domonly','codesrch','none');
11270: $checked{'unauth'} = 'std';
11271: $checked{'auth'} = 'std';
11272: if (ref($settings) eq 'HASH') {
11273: foreach my $type (@cattypes) {
11274: if ($type eq $settings->{'unauth'}) {
11275: $checked{'unauth'} = $type;
11276: }
11277: if ($type eq $settings->{'auth'}) {
11278: $checked{'auth'} = $type;
11279: }
11280: }
11281: }
11282: my %lt = &Apache::lonlocal::texthash (
11283: unauth => 'Catalog type for unauthenticated users',
11284: auth => 'Catalog type for authenticated users',
11285: none => 'No catalog',
11286: std => 'Standard catalog',
11287: domonly => 'Domain-only catalog',
11288: codesrch => "Code search form",
11289: );
11290: my $itemcount = 0;
11291: foreach my $item (@catitems) {
11292: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11293: $datatable .= '<tr '.$css_class.'>'.
11294: '<td>'.$lt{$item}.'</td>'.
11295: '<td class="LC_right_item"><span class="LC_nobreak">';
11296: foreach my $type (@cattypes) {
11297: my $ischecked;
11298: if ($checked{$item} eq $type) {
11299: $ischecked=' checked="checked"';
11300: }
11301: $datatable .= '<label>'.
11302: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11303: ' />'.$lt{$type}.'</label> ';
11304: }
1.327 raeburn 11305: $datatable .= '</span></td></tr>';
1.238 raeburn 11306: $itemcount ++;
11307: }
11308: $$rowtotal += $itemcount;
11309: } elsif ($position eq 'middle') {
1.57 raeburn 11310: my $toggle_cats_crs = ' ';
11311: my $toggle_cats_dom = ' checked="checked" ';
11312: my $can_cat_crs = ' ';
11313: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11314: my $toggle_catscomm_comm = ' ';
11315: my $toggle_catscomm_dom = ' checked="checked" ';
11316: my $can_catcomm_comm = ' ';
11317: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11318: my $toggle_catsplace_place = ' ';
11319: my $toggle_catsplace_dom = ' checked="checked" ';
11320: my $can_catplace_place = ' ';
11321: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11322:
1.57 raeburn 11323: if (ref($settings) eq 'HASH') {
11324: if ($settings->{'togglecats'} eq 'crs') {
11325: $toggle_cats_crs = $toggle_cats_dom;
11326: $toggle_cats_dom = ' ';
11327: }
11328: if ($settings->{'categorize'} eq 'crs') {
11329: $can_cat_crs = $can_cat_dom;
11330: $can_cat_dom = ' ';
11331: }
1.120 raeburn 11332: if ($settings->{'togglecatscomm'} eq 'comm') {
11333: $toggle_catscomm_comm = $toggle_catscomm_dom;
11334: $toggle_catscomm_dom = ' ';
11335: }
11336: if ($settings->{'categorizecomm'} eq 'comm') {
11337: $can_catcomm_comm = $can_catcomm_dom;
11338: $can_catcomm_dom = ' ';
11339: }
1.272 raeburn 11340: if ($settings->{'togglecatsplace'} eq 'place') {
11341: $toggle_catsplace_place = $toggle_catsplace_dom;
11342: $toggle_catsplace_dom = ' ';
11343: }
11344: if ($settings->{'categorizeplace'} eq 'place') {
11345: $can_catplace_place = $can_catplace_dom;
11346: $can_catplace_dom = ' ';
11347: }
1.57 raeburn 11348: }
11349: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11350: togglecats => 'Show/Hide a course in catalog',
11351: togglecatscomm => 'Show/Hide a community in catalog',
11352: togglecatsplace => 'Show/Hide a placement test in catalog',
11353: categorize => 'Assign a category to a course',
11354: categorizecomm => 'Assign a category to a community',
11355: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11356: );
11357: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11358: dom => 'Set in Domain',
11359: crs => 'Set in Course',
11360: comm => 'Set in Community',
11361: place => 'Set in Placement Test',
1.57 raeburn 11362: );
11363: $datatable = '<tr class="LC_odd_row">'.
11364: '<td>'.$title{'togglecats'}.'</td>'.
11365: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11366: '<input type="radio" name="togglecats"'.
11367: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11368: '<label><input type="radio" name="togglecats"'.
11369: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11370: '</tr><tr>'.
11371: '<td>'.$title{'categorize'}.'</td>'.
11372: '<td class="LC_right_item"><span class="LC_nobreak">'.
11373: '<label><input type="radio" name="categorize"'.
11374: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11375: '<label><input type="radio" name="categorize"'.
11376: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11377: '</tr><tr class="LC_odd_row">'.
11378: '<td>'.$title{'togglecatscomm'}.'</td>'.
11379: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11380: '<input type="radio" name="togglecatscomm"'.
11381: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11382: '<label><input type="radio" name="togglecatscomm"'.
11383: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11384: '</tr><tr>'.
11385: '<td>'.$title{'categorizecomm'}.'</td>'.
11386: '<td class="LC_right_item"><span class="LC_nobreak">'.
11387: '<label><input type="radio" name="categorizecomm"'.
11388: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11389: '<label><input type="radio" name="categorizecomm"'.
11390: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11391: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11392: '<td>'.$title{'togglecatsplace'}.'</td>'.
11393: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11394: '<input type="radio" name="togglecatsplace"'.
11395: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11396: '<label><input type="radio" name="togglecatscomm"'.
11397: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11398: '</tr><tr>'.
11399: '<td>'.$title{'categorizeplace'}.'</td>'.
11400: '<td class="LC_right_item"><span class="LC_nobreak">'.
11401: '<label><input type="radio" name="categorizeplace"'.
11402: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11403: '<label><input type="radio" name="categorizeplace"'.
11404: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11405: '</tr>';
1.272 raeburn 11406: $$rowtotal += 6;
1.57 raeburn 11407: } else {
11408: my $css_class;
11409: my $itemcount = 1;
11410: my $cathash;
11411: if (ref($settings) eq 'HASH') {
11412: $cathash = $settings->{'cats'};
11413: }
11414: if (ref($cathash) eq 'HASH') {
11415: my (@cats,@trails,%allitems,%idx,@jsarray);
11416: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11417: \%allitems,\%idx,\@jsarray);
11418: my $maxdepth = scalar(@cats);
11419: my $colattrib = '';
11420: if ($maxdepth > 2) {
11421: $colattrib = ' colspan="2" ';
11422: }
11423: my @path;
11424: if (@cats > 0) {
11425: if (ref($cats[0]) eq 'ARRAY') {
11426: my $numtop = @{$cats[0]};
11427: my $maxnum = $numtop;
1.120 raeburn 11428: my %default_names = (
11429: instcode => &mt('Official courses'),
11430: communities => &mt('Communities'),
1.272 raeburn 11431: placement => &mt('Placement Tests'),
1.120 raeburn 11432: );
11433:
11434: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11435: ($cathash->{'instcode::0'} eq '') ||
11436: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11437: ($cathash->{'communities::0'} eq '') ||
11438: (!grep(/^placement$/,@{$cats[0]})) ||
11439: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11440: $maxnum ++;
11441: }
11442: my $lastidx;
11443: for (my $i=0; $i<$numtop; $i++) {
11444: my $parent = $cats[0][$i];
11445: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11446: my $item = &escape($parent).'::0';
11447: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11448: $lastidx = $idx{$item};
11449: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11450: .'<select name="'.$item.'"'.$chgstr.'>';
11451: for (my $k=0; $k<=$maxnum; $k++) {
11452: my $vpos = $k+1;
11453: my $selstr;
11454: if ($k == $i) {
11455: $selstr = ' selected="selected" ';
11456: }
11457: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11458: }
1.214 raeburn 11459: $datatable .= '</select></span></td><td>';
1.272 raeburn 11460: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11461: $datatable .= '<span class="LC_nobreak">'
11462: .$default_names{$parent}.'</span>';
11463: if ($parent eq 'instcode') {
11464: $datatable .= '<br /><span class="LC_nobreak">('
11465: .&mt('with institutional codes')
11466: .')</span></td><td'.$colattrib.'>';
11467: } else {
11468: $datatable .= '<table><tr><td>';
11469: }
11470: $datatable .= '<span class="LC_nobreak">'
11471: .'<label><input type="radio" name="'
11472: .$parent.'" value="1" checked="checked" />'
11473: .&mt('Display').'</label>';
11474: if ($parent eq 'instcode') {
11475: $datatable .= ' ';
11476: } else {
11477: $datatable .= '</span></td></tr><tr><td>'
11478: .'<span class="LC_nobreak">';
11479: }
11480: $datatable .= '<label><input type="radio" name="'
11481: .$parent.'" value="0" />'
11482: .&mt('Do not display').'</label></span>';
1.272 raeburn 11483: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11484: $datatable .= '</td></tr></table>';
11485: }
11486: $datatable .= '</td>';
1.57 raeburn 11487: } else {
11488: $datatable .= $parent
1.214 raeburn 11489: .' <span class="LC_nobreak"><label>'
11490: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11491: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11492: }
11493: my $depth = 1;
11494: push(@path,$parent);
11495: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11496: pop(@path);
11497: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11498: $itemcount ++;
11499: }
1.48 raeburn 11500: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11501: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11502: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11503: for (my $k=0; $k<=$maxnum; $k++) {
11504: my $vpos = $k+1;
11505: my $selstr;
1.57 raeburn 11506: if ($k == $numtop) {
1.48 raeburn 11507: $selstr = ' selected="selected" ';
11508: }
11509: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11510: }
1.59 bisitz 11511: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11512: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11513: .'</tr>'."\n";
1.48 raeburn 11514: $itemcount ++;
1.272 raeburn 11515: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11516: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11517: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11518: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11519: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11520: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11521: for (my $k=0; $k<=$maxnum; $k++) {
11522: my $vpos = $k+1;
11523: my $selstr;
11524: if ($k == $maxnum) {
11525: $selstr = ' selected="selected" ';
11526: }
11527: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11528: }
1.120 raeburn 11529: $datatable .= '</select></span></td>'.
11530: '<td><span class="LC_nobreak">'.
11531: $default_names{$default}.'</span>';
11532: if ($default eq 'instcode') {
11533: $datatable .= '<br /><span class="LC_nobreak">('
11534: .&mt('with institutional codes').')</span>';
11535: }
11536: $datatable .= '</td>'
11537: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11538: .&mt('Display').'</label> '
11539: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11540: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11541: }
11542: }
11543: }
1.57 raeburn 11544: } else {
11545: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11546: }
11547: } else {
1.327 raeburn 11548: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11549: .&initialize_categories($itemcount);
1.48 raeburn 11550: }
1.57 raeburn 11551: $$rowtotal += $itemcount;
1.48 raeburn 11552: }
11553: return $datatable;
11554: }
11555:
1.69 raeburn 11556: sub print_serverstatuses {
11557: my ($dom,$settings,$rowtotal) = @_;
11558: my $datatable;
11559: my @pages = &serverstatus_pages();
11560: my (%namedaccess,%machineaccess);
11561: foreach my $type (@pages) {
11562: $namedaccess{$type} = '';
11563: $machineaccess{$type}= '';
11564: }
11565: if (ref($settings) eq 'HASH') {
11566: foreach my $type (@pages) {
11567: if (exists($settings->{$type})) {
11568: if (ref($settings->{$type}) eq 'HASH') {
11569: foreach my $key (keys(%{$settings->{$type}})) {
11570: if ($key eq 'namedusers') {
11571: $namedaccess{$type} = $settings->{$type}->{$key};
11572: } elsif ($key eq 'machines') {
11573: $machineaccess{$type} = $settings->{$type}->{$key};
11574: }
11575: }
11576: }
11577: }
11578: }
11579: }
1.81 raeburn 11580: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11581: my $rownum = 0;
11582: my $css_class;
11583: foreach my $type (@pages) {
11584: $rownum ++;
11585: $css_class = $rownum%2?' class="LC_odd_row"':'';
11586: $datatable .= '<tr'.$css_class.'>'.
11587: '<td><span class="LC_nobreak">'.
11588: $titles->{$type}.'</span></td>'.
11589: '<td class="LC_left_item">'.
11590: '<input type="text" name="'.$type.'_namedusers" '.
11591: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11592: '<td class="LC_right_item">'.
11593: '<span class="LC_nobreak">'.
11594: '<input type="text" name="'.$type.'_machines" '.
11595: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11596: '</span></td></tr>'."\n";
1.69 raeburn 11597: }
11598: $$rowtotal += $rownum;
11599: return $datatable;
11600: }
11601:
11602: sub serverstatus_pages {
11603: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11604: 'checksums','clusterstatus','certstatus','metadata_keywords',
11605: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11606: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11607: }
11608:
1.236 raeburn 11609: sub defaults_javascript {
11610: my ($settings) = @_;
1.354 raeburn 11611: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11612: my $portal_js = <<"ENDPORTAL";
11613:
11614: function portalExtras(caller) {
11615: var x = caller.value;
11616: var y = new Array('email','web');
1.425 raeburn 11617: for (var i=0; i<y.length; i++) {
1.414 raeburn 11618: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11619: var z = document.getElementById('portal_def_'+y[i]+'_div');
11620: if (x.length > 0) {
11621: z.style.display = 'block';
11622: } else {
11623: z.style.display = 'none';
11624: }
11625: }
11626: }
11627: }
11628: ENDPORTAL
1.236 raeburn 11629: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11630: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11631: if ($maxnum eq '') {
11632: $maxnum = 0;
11633: }
11634: $maxnum ++;
1.249 raeburn 11635: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11636: return <<"ENDSCRIPT";
11637: <script type="text/javascript">
11638: // <![CDATA[
11639: function reorderTypes(form,caller) {
11640: var changedVal;
11641: $jstext
11642: var newpos = 'addinststatus_pos';
11643: var current = new Array;
11644: var maxh = $maxnum;
11645: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11646: var oldVal;
11647: if (caller == newpos) {
11648: changedVal = newitemVal;
11649: } else {
11650: var curritem = 'inststatus_pos_'+caller;
11651: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11652: current[newitemVal] = newpos;
11653: }
11654: for (var i=0; i<inststatuses.length; i++) {
11655: if (inststatuses[i] != caller) {
11656: var elementName = 'inststatus_pos_'+inststatuses[i];
11657: if (form.elements[elementName]) {
11658: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11659: current[currVal] = elementName;
11660: }
11661: }
11662: }
11663: for (var j=0; j<maxh; j++) {
11664: if (current[j] == undefined) {
11665: oldVal = j;
11666: }
11667: }
11668: if (oldVal < changedVal) {
11669: for (var k=oldVal+1; k<=changedVal ; k++) {
11670: var elementName = current[k];
11671: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11672: }
11673: } else {
11674: for (var k=changedVal; k<oldVal; k++) {
11675: var elementName = current[k];
11676: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11677: }
11678: }
11679: return;
11680: }
11681:
1.414 raeburn 11682: $portal_js
11683:
11684: // ]]>
11685: </script>
11686:
11687: ENDSCRIPT
11688: } else {
11689: return <<"ENDSCRIPT";
11690: <script type="text/javascript">
11691: // <![CDATA[
11692: $portal_js
1.236 raeburn 11693: // ]]>
11694: </script>
11695:
11696: ENDSCRIPT
11697: }
1.354 raeburn 11698: return;
11699: }
11700:
11701: sub passwords_javascript {
1.405 raeburn 11702: my ($prefix) = @_;
11703: my %intalert;
11704: if ($prefix eq 'passwords') {
11705: %intalert = &Apache::lonlocal::texthash (
11706: authcheck => 'Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.',
11707: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11708: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11709: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11710: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11711: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11712: );
1.421 raeburn 11713: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11714: %intalert = &Apache::lonlocal::texthash (
11715: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11716: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11717: );
11718: }
1.365 raeburn 11719: &js_escape(\%intalert);
11720: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11721: my $intauthjs;
1.405 raeburn 11722: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11723:
11724: function warnIntAuth(field) {
11725: if (field.name == 'intauth_check') {
11726: if (field.value == '2') {
1.365 raeburn 11727: alert('$intalert{authcheck}');
1.354 raeburn 11728: }
11729: }
11730: if (field.name == 'intauth_cost') {
11731: field.value.replace(/\s/g,'');
11732: if (field.value != '') {
11733: var regexdigit=/^\\d+\$/;
11734: if (!regexdigit.test(field.value)) {
1.365 raeburn 11735: alert('$intalert{authcost}');
11736: }
11737: }
11738: }
11739: return;
11740: }
11741:
1.405 raeburn 11742: ENDSCRIPT
11743:
11744: }
11745:
11746: $intauthjs .= <<"ENDSCRIPT";
11747:
11748: function warnInt$prefix(field) {
1.365 raeburn 11749: field.value.replace(/^\s+/,'');
11750: field.value.replace(/\s+\$/,'');
11751: var regexdigit=/^\\d+\$/;
1.408 raeburn 11752: if (field.name == '${prefix}_min') {
1.365 raeburn 11753: if (field.value == '') {
11754: alert('$intalert{passmin}');
11755: field.value = '$defmin';
11756: } else {
11757: if (!regexdigit.test(field.value)) {
11758: alert('$intalert{passmin}');
11759: field.value = '$defmin';
11760: }
1.366 raeburn 11761: var minval = parseInt(field.value,10);
1.365 raeburn 11762: if (minval < $defmin) {
11763: alert('$intalert{passmin}');
11764: field.value = '$defmin';
11765: }
11766: }
11767: } else {
11768: if (field.value == '0') {
11769: field.value = '';
11770: }
11771: if (field.value != '') {
1.408 raeburn 11772: if (field.name == '${prefix}_expire') {
1.365 raeburn 11773: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11774: if (!regexpposnum.test(field.value)) {
11775: alert('$intalert{passexp}');
11776: field.value = '';
11777: } else {
11778: var expval = parseFloat(field.value);
11779: if (expval == 0) {
11780: alert('$intalert{passexp}');
11781: field.value = '';
11782: }
11783: }
11784: } else {
11785: if (!regexdigit.test(field.value)) {
1.408 raeburn 11786: if (field.name == '${prefix}_max') {
1.365 raeburn 11787: alert('$intalert{passmax}');
11788: } else {
1.408 raeburn 11789: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11790: alert('$intalert{passnum}');
11791: }
11792: }
1.370 raeburn 11793: field.value = '';
1.365 raeburn 11794: }
1.354 raeburn 11795: }
11796: }
11797: }
11798: return;
11799: }
11800:
11801: ENDSCRIPT
11802: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11803: }
11804:
1.49 raeburn 11805: sub coursecategories_javascript {
11806: my ($settings) = @_;
1.57 raeburn 11807: my ($output,$jstext,$cathash);
1.49 raeburn 11808: if (ref($settings) eq 'HASH') {
1.57 raeburn 11809: $cathash = $settings->{'cats'};
11810: }
11811: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11812: my (@cats,@jsarray,%idx);
1.57 raeburn 11813: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11814: if (@jsarray > 0) {
11815: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11816: for (my $i=0; $i<@jsarray; $i++) {
11817: if (ref($jsarray[$i]) eq 'ARRAY') {
11818: my $catstr = join('","',@{$jsarray[$i]});
11819: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11820: }
11821: }
11822: }
11823: } else {
11824: $jstext = ' var categories = Array(1);'."\n".
11825: ' categories[0] = Array("instcode_pos");'."\n";
11826: }
1.237 bisitz 11827: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11828: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11829: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11830: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11831: &js_escape(\$instcode_reserved);
11832: &js_escape(\$communities_reserved);
1.272 raeburn 11833: &js_escape(\$placement_reserved);
1.265 damieng 11834: &js_escape(\$choose_again);
1.49 raeburn 11835: $output = <<"ENDSCRIPT";
11836: <script type="text/javascript">
1.109 raeburn 11837: // <![CDATA[
1.49 raeburn 11838: function reorderCats(form,parent,item,idx) {
11839: var changedVal;
11840: $jstext
11841: var newpos = 'addcategory_pos';
11842: if (parent == '') {
11843: var has_instcode = 0;
11844: var maxtop = categories[idx].length;
11845: for (var j=0; j<maxtop; j++) {
11846: if (categories[idx][j] == 'instcode::0') {
11847: has_instcode == 1;
11848: }
11849: }
11850: if (has_instcode == 0) {
11851: categories[idx][maxtop] = 'instcode_pos';
11852: }
11853: } else {
11854: newpos += '_'+parent;
11855: }
11856: var maxh = 1 + categories[idx].length;
11857: var current = new Array;
11858: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11859: if (item == newpos) {
11860: changedVal = newitemVal;
11861: } else {
11862: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11863: current[newitemVal] = newpos;
11864: }
11865: for (var i=0; i<categories[idx].length; i++) {
11866: var elementName = categories[idx][i];
11867: if (elementName != item) {
11868: if (form.elements[elementName]) {
11869: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11870: current[currVal] = elementName;
11871: }
11872: }
11873: }
11874: var oldVal;
11875: for (var j=0; j<maxh; j++) {
11876: if (current[j] == undefined) {
11877: oldVal = j;
11878: }
11879: }
11880: if (oldVal < changedVal) {
11881: for (var k=oldVal+1; k<=changedVal ; k++) {
11882: var elementName = current[k];
11883: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11884: }
11885: } else {
11886: for (var k=changedVal; k<oldVal; k++) {
11887: var elementName = current[k];
11888: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11889: }
11890: }
11891: return;
11892: }
1.120 raeburn 11893:
11894: function categoryCheck(form) {
11895: if (form.elements['addcategory_name'].value == 'instcode') {
11896: alert('$instcode_reserved\\n$choose_again');
11897: return false;
11898: }
11899: if (form.elements['addcategory_name'].value == 'communities') {
11900: alert('$communities_reserved\\n$choose_again');
11901: return false;
11902: }
1.272 raeburn 11903: if (form.elements['addcategory_name'].value == 'placement') {
11904: alert('$placement_reserved\\n$choose_again');
11905: return false;
11906: }
1.120 raeburn 11907: return true;
11908: }
11909:
1.109 raeburn 11910: // ]]>
1.49 raeburn 11911: </script>
11912:
11913: ENDSCRIPT
11914: return $output;
11915: }
11916:
1.48 raeburn 11917: sub initialize_categories {
11918: my ($itemcount) = @_;
1.120 raeburn 11919: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11920: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11921: instcode => 'Official courses (with institutional codes)',
11922: communities => 'Communities',
1.272 raeburn 11923: placement => 'Placement Tests',
1.120 raeburn 11924: );
1.328 raeburn 11925: my %selnum = (
11926: instcode => '0',
11927: communities => '1',
11928: placement => '2',
11929: );
11930: my %selected;
1.272 raeburn 11931: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11932: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11933: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11934: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11935: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11936: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11937: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11938: .'<option value="0"'.$selected{'0'}.'>1</option>'
11939: .'<option value="1"'.$selected{'1'}.'>2</option>'
11940: .'<option value="2"'.$selected{'2'}.'>3</option>'
11941: .'<option value="3">4</option></select> '
1.120 raeburn 11942: .$default_names{$default}
11943: .'</span></td><td><span class="LC_nobreak">'
11944: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11945: .&mt('Display').'</label> <label>'
11946: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11947: .'</label></span></td></tr>';
1.120 raeburn 11948: $itemcount ++;
11949: }
1.48 raeburn 11950: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11951: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11952: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11953: .'<select name="addcategory_pos"'.$chgstr.'>'
11954: .'<option value="0">1</option>'
11955: .'<option value="1">2</option>'
1.328 raeburn 11956: .'<option value="2">3</option>'
11957: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11958: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11959: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11960: .'</td></tr>';
1.48 raeburn 11961: return $datatable;
11962: }
11963:
11964: sub build_category_rows {
1.49 raeburn 11965: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11966: my ($text,$name,$item,$chgstr);
1.48 raeburn 11967: if (ref($cats) eq 'ARRAY') {
11968: my $maxdepth = scalar(@{$cats});
11969: if (ref($cats->[$depth]) eq 'HASH') {
11970: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11971: my $numchildren = @{$cats->[$depth]{$parent}};
11972: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11973: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11974: my ($idxnum,$parent_name,$parent_item);
11975: my $higher = $depth - 1;
11976: if ($higher == 0) {
11977: $parent_name = &escape($parent).'::'.$higher;
11978: } else {
11979: if (ref($path) eq 'ARRAY') {
11980: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11981: }
11982: }
11983: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11984: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11985: if ($j < $numchildren) {
1.48 raeburn 11986: $name = $cats->[$depth]{$parent}[$j];
11987: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11988: $idxnum = $idx->{$item};
11989: } else {
11990: $name = $parent_name;
11991: $item = $parent_item;
1.48 raeburn 11992: }
1.49 raeburn 11993: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11994: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11995: for (my $i=0; $i<=$numchildren; $i++) {
11996: my $vpos = $i+1;
11997: my $selstr;
11998: if ($j == $i) {
11999: $selstr = ' selected="selected" ';
12000: }
12001: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
12002: }
12003: $text .= '</select> ';
12004: if ($j < $numchildren) {
12005: my $deeper = $depth+1;
12006: $text .= $name.' '
12007: .'<label><input type="checkbox" name="deletecategory" value="'
12008: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
12009: if(ref($path) eq 'ARRAY') {
12010: push(@{$path},$name);
1.49 raeburn 12011: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 12012: pop(@{$path});
12013: }
12014: } else {
1.330 raeburn 12015: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 12016: if ($j == $numchildren) {
12017: $text .= $name;
12018: } else {
12019: $text .= $item;
12020: }
12021: $text .= '" value="" />';
12022: }
12023: $text .= '</td></tr>';
12024: }
12025: $text .= '</table></td>';
12026: } else {
12027: my $higher = $depth-1;
12028: if ($higher == 0) {
12029: $name = &escape($parent).'::'.$higher;
12030: } else {
12031: if (ref($path) eq 'ARRAY') {
12032: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12033: }
12034: }
12035: my $colspan;
12036: if ($parent ne 'instcode') {
12037: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 12038: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 12039: }
12040: }
12041: }
12042: }
12043: return $text;
12044: }
12045:
1.33 raeburn 12046: sub modifiable_userdata_row {
1.305 raeburn 12047: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 12048: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 12049: my ($role,$rolename,$statustype);
12050: $role = $item;
1.224 raeburn 12051: if ($context eq 'cancreate') {
1.305 raeburn 12052: if ($item =~ /^(emailusername)_(.+)$/) {
12053: $role = $1;
12054: $statustype = $2;
1.228 raeburn 12055: if (ref($usertypes) eq 'HASH') {
12056: if ($usertypes->{$statustype}) {
12057: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
12058: } else {
12059: $rolename = &mt('Data provided by user');
12060: }
12061: }
1.224 raeburn 12062: }
12063: } elsif ($context eq 'selfcreate') {
1.63 raeburn 12064: if (ref($usertypes) eq 'HASH') {
12065: $rolename = $usertypes->{$role};
12066: } else {
12067: $rolename = $role;
12068: }
1.325 raeburn 12069: } elsif ($context eq 'lti') {
12070: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 12071: } elsif ($context eq 'privacy') {
12072: $rolename = $itemdesc;
1.33 raeburn 12073: } else {
1.63 raeburn 12074: if ($role eq 'cr') {
12075: $rolename = &mt('Custom role');
12076: } else {
12077: $rolename = &Apache::lonnet::plaintext($role);
12078: }
1.33 raeburn 12079: }
1.224 raeburn 12080: my (@fields,%fieldtitles);
12081: if (ref($fieldsref) eq 'ARRAY') {
12082: @fields = @{$fieldsref};
12083: } else {
12084: @fields = ('lastname','firstname','middlename','generation',
12085: 'permanentemail','id');
12086: }
12087: if ((ref($titlesref) eq 'HASH')) {
12088: %fieldtitles = %{$titlesref};
12089: } else {
12090: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12091: }
1.33 raeburn 12092: my $output;
1.305 raeburn 12093: my $css_class;
12094: if ($rowcount%2) {
12095: $css_class = 'LC_odd_row';
12096: }
12097: if ($customcss) {
12098: $css_class .= " $customcss";
12099: }
12100: $css_class =~ s/^\s+//;
12101: if ($css_class) {
12102: $css_class = ' class="'.$css_class.'"';
12103: }
12104: if ($rowstyle) {
12105: $css_class .= ' style="'.$rowstyle.'"';
12106: }
12107: if ($rowid) {
12108: $rowid = ' id="'.$rowid.'"';
12109: }
12110: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 12111: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
12112: '<td class="LC_left_item" colspan="2"><table>';
12113: my $rem;
12114: my %checks;
12115: if (ref($settings) eq 'HASH') {
1.325 raeburn 12116: my $hashref;
12117: if ($context eq 'lti') {
12118: if (ref($settings) eq 'HASH') {
1.447.2.2 raeburn 12119: my %instdata;
12120: if (ref($settings->{'instdata'}) eq 'ARRAY') {
12121: map { $instdata{$_} = 1; } @{$settings->{'instdata'}};
12122: }
12123: $hashref = \%instdata;
1.325 raeburn 12124: }
1.357 raeburn 12125: } elsif ($context eq 'privacy') {
12126: my ($key,$inner) = split(/_/,$role);
12127: if (ref($settings) eq 'HASH') {
12128: if (ref($settings->{$key}) eq 'HASH') {
12129: $hashref = $settings->{$key}->{$inner};
12130: }
12131: }
1.325 raeburn 12132: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12133: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.447.2.2 raeburn 12134: $hashref = $settings->{$context}->{$role};
1.325 raeburn 12135: }
12136: if ($role eq 'emailusername') {
12137: if ($statustype) {
12138: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12139: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12140: }
1.325 raeburn 12141: }
12142: }
12143: }
1.425 raeburn 12144: if (ref($hashref) eq 'HASH') {
1.325 raeburn 12145: foreach my $field (@fields) {
12146: if ($hashref->{$field}) {
12147: if ($role eq 'emailusername') {
12148: $checks{$field} = $hashref->{$field};
12149: } else {
12150: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12151: }
12152: }
12153: }
12154: }
12155: }
1.305 raeburn 12156: my $total = scalar(@fields);
12157: for (my $i=0; $i<$total; $i++) {
12158: $rem = $i%($numinrow);
1.33 raeburn 12159: if ($rem == 0) {
12160: if ($i > 0) {
12161: $output .= '</tr>';
12162: }
12163: $output .= '<tr>';
12164: }
12165: my $check = ' ';
1.228 raeburn 12166: unless ($role eq 'emailusername') {
12167: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12168: $check = $checks{$fields[$i]};
1.357 raeburn 12169: } elsif ($context eq 'privacy') {
12170: if ($role =~ /^priv_(domain|course)$/) {
12171: if (ref($settings) ne 'HASH') {
12172: $check = ' checked="checked" ';
12173: }
12174: } elsif ($role =~ /^priv_(author|community)$/) {
12175: if (ref($settings) ne 'HASH') {
12176: unless ($fields[$i] eq 'id') {
12177: $check = ' checked="checked" ';
12178: }
12179: }
12180: } elsif ($role =~ /^(unpriv|othdom)_/) {
12181: if (ref($settings) ne 'HASH') {
12182: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12183: $check = ' checked="checked" ';
12184: }
12185: }
12186: }
1.325 raeburn 12187: } elsif ($context ne 'lti') {
1.228 raeburn 12188: if ($role eq 'st') {
12189: if (ref($settings) ne 'HASH') {
12190: $check = ' checked="checked" ';
12191: }
1.33 raeburn 12192: }
12193: }
12194: }
12195: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12196: '<span class="LC_nobreak">';
1.325 raeburn 12197: my $prefix = 'canmodify';
1.228 raeburn 12198: if ($role eq 'emailusername') {
12199: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12200: $checks{$fields[$i]} = 'omit';
12201: }
12202: foreach my $option ('required','optional','omit') {
12203: my $checked='';
12204: if ($checks{$fields[$i]} eq $option) {
12205: $checked='checked="checked" ';
12206: }
12207: $output .= '<label>'.
1.325 raeburn 12208: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12209: &mt($option).'</label>'.(' ' x2);
12210: }
12211: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12212: } else {
1.325 raeburn 12213: if ($context eq 'lti') {
12214: $prefix = 'lti';
1.443 raeburn 12215: } elsif ($context eq 'coauthor') {
12216: $prefix = 'cacanmodify';
1.357 raeburn 12217: } elsif ($context eq 'privacy') {
12218: $prefix = 'privacy';
1.325 raeburn 12219: }
1.228 raeburn 12220: $output .= '<label>'.
1.325 raeburn 12221: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12222: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12223: '</label>';
12224: }
12225: $output .= '</span></td>';
1.33 raeburn 12226: }
1.305 raeburn 12227: $rem = $total%$numinrow;
12228: my $colsleft;
12229: if ($rem) {
12230: $colsleft = $numinrow - $rem;
12231: }
12232: if ($colsleft > 1) {
1.33 raeburn 12233: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12234: ' </td>';
12235: } elsif ($colsleft == 1) {
12236: $output .= '<td class="LC_left_item"> </td>';
12237: }
12238: $output .= '</tr></table></td></tr>';
12239: return $output;
12240: }
1.28 raeburn 12241:
1.93 raeburn 12242: sub insttypes_row {
1.305 raeburn 12243: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12244: $customcss,$rowstyle) = @_;
1.93 raeburn 12245: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12246: cansearch => 'Users allowed to search',
1.93 raeburn 12247: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12248: lockablenames => 'User preference to lock name',
12249: selfassign => 'Self-reportable affiliations',
12250: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12251: webdav => 'WebDAV access available',
12252: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12253: );
1.429 raeburn 12254: my ($showdom,$defaultquota);
1.93 raeburn 12255: if ($context eq 'cansearch') {
12256: $showdom = ' ('.$dom.')';
1.429 raeburn 12257: } elsif ($context eq 'authorquota') {
12258: $defaultquota = 500;
1.93 raeburn 12259: }
1.165 raeburn 12260: my $class = 'LC_left_item';
12261: if ($context eq 'statustocreate') {
12262: $class = 'LC_right_item';
12263: }
1.305 raeburn 12264: my $css_class;
12265: if ($$rowtotal%2) {
12266: $css_class = 'LC_odd_row';
12267: }
12268: if ($customcss) {
12269: $css_class .= ' '.$customcss;
12270: }
12271: $css_class =~ s/^\s+//;
12272: if ($css_class) {
12273: $css_class = ' class="'.$css_class.'"';
12274: }
12275: if ($rowstyle) {
12276: $css_class .= ' style="'.$rowstyle.'"';
12277: }
12278: if ($onclick) {
12279: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12280: }
12281: my $output = '<tr'.$css_class.'>'.
12282: '<td>'.$lt{$context}.$showdom.
12283: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12284: my $rem;
12285: if (ref($types) eq 'ARRAY') {
12286: for (my $i=0; $i<@{$types}; $i++) {
12287: if (defined($usertypes->{$types->[$i]})) {
12288: my $rem = $i%($numinrow);
12289: if ($rem == 0) {
12290: if ($i > 0) {
12291: $output .= '</tr>';
12292: }
12293: $output .= '<tr>';
1.23 raeburn 12294: }
1.429 raeburn 12295: if ($context eq 'authorquota') {
12296: my $currquota;
12297: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12298: $currquota = $settings->{$context}->{$types->[$i]};
12299: } else {
12300: $currquota = $defaultquota;
12301: }
12302: $output .= '<td class="LC_left_item">'."\n".
12303: '<label><span class="LC_nobreak">'."\n".
12304: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12305: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12306: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12307: '</label></td>';
12308: } else {
12309: my $check = ' ';
12310: if (ref($settings) eq 'HASH') {
12311: if (ref($settings->{$context}) eq 'ARRAY') {
12312: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12313: $check = ' checked="checked" ';
12314: }
12315: } elsif (ref($settings->{$context}) eq 'HASH') {
12316: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12317: $check = ' checked="checked" ';
12318: } elsif ($context eq 'webdav') {
12319: if ($settings->{$context}->{$types->[$i]}) {
12320: $check = ' checked="checked" ';
12321: }
12322: }
12323: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12324: $check = ' checked="checked" ';
12325: }
1.26 raeburn 12326: }
1.429 raeburn 12327: $output .= '<td class="LC_left_item">'.
12328: '<span class="LC_nobreak"><label>'.
12329: '<input type="checkbox" name="'.$context.'" '.
12330: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12331: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12332: }
12333: }
12334: }
1.26 raeburn 12335: $rem = @{$types}%($numinrow);
1.23 raeburn 12336: }
12337: my $colsleft = $numinrow - $rem;
1.315 raeburn 12338: if ($context eq 'overrides') {
12339: if ($colsleft > 1) {
12340: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12341: } else {
12342: $output .= '<td class="LC_left_item">';
12343: }
1.425 raeburn 12344: $output .= ' ';
1.23 raeburn 12345: } else {
1.334 raeburn 12346: if ($rem == 0) {
1.315 raeburn 12347: $output .= '<tr>';
12348: }
12349: if ($colsleft > 1) {
12350: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12351: } else {
12352: $output .= '<td class="LC_left_item">';
12353: }
1.429 raeburn 12354: if ($context eq 'authorquota') {
12355: my $currquota = 500;
12356: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12357: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12358: $currquota = $settings->{$context}{'default'};
12359: }
12360: }
12361: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12362: '<input type="text" name="'.$context.'_default" '.
12363: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12364: '</label>';
12365: } else {
12366: my $defcheck = ' ';
12367: if (ref($settings) eq 'HASH') {
12368: if (ref($settings->{$context}) eq 'ARRAY') {
12369: if (grep(/^default$/,@{$settings->{$context}})) {
12370: $defcheck = ' checked="checked" ';
12371: }
12372: } elsif (ref($settings->{$context}) eq 'HASH') {
12373: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12374: $defcheck = ' checked="checked" ';
12375: } elsif ($context eq 'webdav') {
12376: if ($settings->{$context}->{'default'}) {
12377: $defcheck = ' checked="checked" ';
12378: }
12379: }
12380: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12381: $defcheck = ' checked="checked" ';
12382: }
1.99 raeburn 12383: }
1.429 raeburn 12384: $output .= '<span class="LC_nobreak"><label>'.
12385: '<input type="checkbox" name="'.$context.'" '.
12386: 'value="default"'.$defcheck.$onclick.'/>'.
12387: $othertitle.'</label></span>';
1.26 raeburn 12388: }
1.23 raeburn 12389: }
1.315 raeburn 12390: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12391: return $output;
1.23 raeburn 12392: }
12393:
12394: sub sorted_searchtitles {
12395: my %searchtitles = &Apache::lonlocal::texthash(
12396: 'uname' => 'username',
12397: 'lastname' => 'last name',
12398: 'lastfirst' => 'last name, first name',
12399: );
12400: my @titleorder = ('uname','lastname','lastfirst');
12401: return (\%searchtitles,\@titleorder);
12402: }
12403:
1.25 raeburn 12404: sub sorted_searchtypes {
12405: my %srchtypes_desc = (
12406: exact => 'is exact match',
12407: contains => 'contains ..',
12408: begins => 'begins with ..',
12409: );
12410: my @srchtypeorder = ('exact','begins','contains');
12411: return (\%srchtypes_desc,\@srchtypeorder);
12412: }
12413:
1.3 raeburn 12414: sub usertype_update_row {
12415: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12416: my $datatable;
12417: my $numinrow = 4;
12418: foreach my $type (@{$types}) {
12419: if (defined($usertypes->{$type})) {
12420: $$rownums ++;
12421: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12422: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12423: '</td><td class="LC_left_item"><table>';
12424: for (my $i=0; $i<@{$fields}; $i++) {
12425: my $rem = $i%($numinrow);
12426: if ($rem == 0) {
12427: if ($i > 0) {
12428: $datatable .= '</tr>';
12429: }
12430: $datatable .= '<tr>';
12431: }
12432: my $check = ' ';
1.39 raeburn 12433: if (ref($settings) eq 'HASH') {
12434: if (ref($settings->{'fields'}) eq 'HASH') {
12435: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12436: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12437: $check = ' checked="checked" ';
12438: }
1.3 raeburn 12439: }
12440: }
12441: }
12442:
12443: if ($i == @{$fields}-1) {
12444: my $colsleft = $numinrow - $rem;
12445: if ($colsleft > 1) {
12446: $datatable .= '<td colspan="'.$colsleft.'">';
12447: } else {
12448: $datatable .= '<td>';
12449: }
12450: } else {
12451: $datatable .= '<td>';
12452: }
1.8 raeburn 12453: $datatable .= '<span class="LC_nobreak"><label>'.
12454: '<input type="checkbox" name="updateable_'.$type.
12455: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12456: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12457: }
12458: $datatable .= '</tr></table></td></tr>';
12459: }
12460: }
12461: return $datatable;
1.1 raeburn 12462: }
12463:
12464: sub modify_login {
1.205 raeburn 12465: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12466: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12467: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12468: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12469: %title = ( coursecatalog => 'Display course catalog',
12470: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12471: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12472: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12473: loginheader => 'Log-in box header',
12474: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12475: @offon = ('off','on');
1.112 raeburn 12476: if (ref($domconfig{login}) eq 'HASH') {
12477: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12478: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12479: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12480: }
12481: }
1.386 raeburn 12482: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12483: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12484: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12485: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12486: $saml{$lonhost} = 1;
12487: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12488: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12489: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12490: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12491: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12492: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12493: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12494: }
12495: }
12496: }
1.112 raeburn 12497: }
1.9 raeburn 12498: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12499: \%domconfig,\%loginhash);
1.188 raeburn 12500: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12501: foreach my $item (@toggles) {
12502: $loginhash{login}{$item} = $env{'form.'.$item};
12503: }
1.41 raeburn 12504: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12505: if (ref($colchanges{'login'}) eq 'HASH') {
12506: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12507: \%loginhash);
12508: }
1.110 raeburn 12509:
1.149 raeburn 12510: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12511: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12512: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12513: if (keys(%servers) > 1) {
12514: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12515: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12516: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12517: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12518: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12519: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12520: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12521: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12522: $changes{'loginvia'}{$lonhost} = 1;
12523: } else {
12524: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12525: $changes{'loginvia'}{$lonhost} = 1;
12526: }
12527: } else {
12528: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12529: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12530: $changes{'loginvia'}{$lonhost} = 1;
12531: }
12532: }
12533: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12534: foreach my $item (@loginvia_attribs) {
12535: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12536: }
12537: } else {
12538: foreach my $item (@loginvia_attribs) {
12539: my $new = $env{'form.'.$lonhost.'_'.$item};
12540: if (($item eq 'serverpath') && ($new eq 'custom')) {
12541: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12542: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12543: $new = '/';
12544: }
12545: }
12546: if (($item eq 'custompath') &&
12547: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12548: $new = '';
12549: }
12550: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12551: $changes{'loginvia'}{$lonhost} = 1;
12552: }
12553: if ($item eq 'exempt') {
1.256 raeburn 12554: $new = &check_exempt_addresses($new);
1.128 raeburn 12555: }
12556: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12557: }
12558: }
1.112 raeburn 12559: } else {
1.128 raeburn 12560: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12561: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12562: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12563: foreach my $item (@loginvia_attribs) {
12564: my $new = $env{'form.'.$lonhost.'_'.$item};
12565: if (($item eq 'serverpath') && ($new eq 'custom')) {
12566: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12567: $new = '/';
12568: }
12569: }
12570: if (($item eq 'custompath') &&
12571: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12572: $new = '';
12573: }
12574: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12575: }
1.110 raeburn 12576: }
12577: }
12578: }
12579: }
1.119 raeburn 12580:
1.168 raeburn 12581: my $servadm = $r->dir_config('lonAdmEMail');
12582: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12583: if (ref($domconfig{'login'}) eq 'HASH') {
12584: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12585: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12586: if ($lang eq 'nolang') {
12587: push(@currlangs,$lang);
12588: } elsif (defined($langchoices{$lang})) {
12589: push(@currlangs,$lang);
12590: } else {
12591: next;
12592: }
12593: }
12594: }
12595: }
12596: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12597: if (@currlangs > 0) {
12598: foreach my $lang (@currlangs) {
12599: if (grep(/^\Q$lang\E$/,@delurls)) {
12600: $changes{'helpurl'}{$lang} = 1;
12601: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12602: $changes{'helpurl'}{$lang} = 1;
12603: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12604: push(@newlangs,$lang);
12605: } else {
12606: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12607: }
12608: }
12609: }
12610: unless (grep(/^nolang$/,@currlangs)) {
12611: if ($env{'form.loginhelpurl_nolang.filename'}) {
12612: $changes{'helpurl'}{'nolang'} = 1;
12613: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12614: push(@newlangs,'nolang');
12615: }
12616: }
12617: if ($env{'form.loginhelpurl_add_lang'}) {
12618: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12619: ($env{'form.loginhelpurl_add_file.filename'})) {
12620: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12621: $addedfile = $env{'form.loginhelpurl_add_lang'};
12622: }
12623: }
12624: if ((@newlangs > 0) || ($addedfile)) {
12625: my $error;
12626: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12627: if ($configuserok eq 'ok') {
12628: if ($switchserver) {
12629: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12630: } elsif ($author_ok eq 'ok') {
12631: my @allnew = @newlangs;
12632: if ($addedfile ne '') {
12633: push(@allnew,$addedfile);
12634: }
1.421 raeburn 12635: my $modified = [];
1.168 raeburn 12636: foreach my $lang (@allnew) {
12637: my $formelem = 'loginhelpurl_'.$lang;
12638: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12639: $formelem = 'loginhelpurl_add_file';
12640: }
1.425 raeburn 12641: (my $result,$newurl{$lang}) =
1.421 raeburn 12642: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12643: "help/$lang",'','',$newfile{$lang},
12644: $modified);
1.168 raeburn 12645: if ($result eq 'ok') {
12646: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12647: $changes{'helpurl'}{$lang} = 1;
12648: } else {
12649: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12650: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12651: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12652: (!grep(/^\Q$lang\E$/,@delurls))) {
12653: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12654: }
12655: }
12656: }
1.421 raeburn 12657: &update_modify_urls($r,$modified);
1.168 raeburn 12658: } else {
12659: $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);
12660: }
12661: } else {
12662: $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);
12663: }
12664: if ($error) {
12665: &Apache::lonnet::logthis($error);
12666: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12667: }
12668: }
1.256 raeburn 12669:
12670: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12671: if (ref($domconfig{'login'}) eq 'HASH') {
12672: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12673: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12674: if ($domservers{$lonhost}) {
12675: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12676: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12677: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12678: }
12679: }
12680: }
12681: }
12682: }
12683: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12684: foreach my $lonhost (sort(keys(%domservers))) {
12685: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12686: $changes{'headtag'}{$lonhost} = 1;
12687: } else {
12688: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12689: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12690: }
12691: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12692: push(@newhosts,$lonhost);
12693: } elsif ($currheadtagurls{$lonhost}) {
12694: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12695: if ($currexempt{$lonhost}) {
1.289 raeburn 12696: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12697: $changes{'headtag'}{$lonhost} = 1;
12698: }
12699: } elsif ($possexempt{$lonhost}) {
12700: $changes{'headtag'}{$lonhost} = 1;
12701: }
12702: if ($possexempt{$lonhost}) {
12703: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12704: }
12705: }
12706: }
12707: }
12708: if (@newhosts) {
12709: my $error;
12710: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12711: if ($configuserok eq 'ok') {
12712: if ($switchserver) {
12713: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12714: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12715: my $modified = [];
1.256 raeburn 12716: foreach my $lonhost (@newhosts) {
12717: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12718: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12719: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12720: "login/headtag/$lonhost",'','',
12721: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12722: $modified);
1.256 raeburn 12723: if ($result eq 'ok') {
12724: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12725: $changes{'headtag'}{$lonhost} = 1;
12726: if ($possexempt{$lonhost}) {
12727: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12728: }
12729: } else {
12730: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12731: $newheadtagurls{$lonhost},$result);
12732: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12733: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12734: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12735: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12736: }
12737: }
12738: }
1.421 raeburn 12739: &update_modify_urls($r,$modified);
1.256 raeburn 12740: } else {
12741: $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);
12742: }
12743: } else {
12744: $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);
12745: }
12746: if ($error) {
12747: &Apache::lonnet::logthis($error);
12748: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12749: }
12750: }
1.386 raeburn 12751: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12752: my @newsamlimgs;
12753: foreach my $lonhost (keys(%domservers)) {
12754: if ($env{'form.saml_'.$lonhost}) {
12755: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12756: push(@newsamlimgs,$lonhost);
12757: }
1.412 raeburn 12758: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12759: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12760: }
12761: if ($saml{$lonhost}) {
1.412 raeburn 12762: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12763: $env{'form.saml_window_'.$lonhost} = '';
12764: }
1.386 raeburn 12765: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12766: #FIXME Need to obsolete published image
12767: delete($currsaml{$lonhost}{'img'});
12768: $changes{'saml'}{$lonhost} = 1;
12769: }
12770: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12771: $changes{'saml'}{$lonhost} = 1;
12772: }
12773: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12774: $changes{'saml'}{$lonhost} = 1;
12775: }
12776: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12777: $changes{'saml'}{$lonhost} = 1;
12778: }
12779: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12780: $changes{'saml'}{$lonhost} = 1;
12781: }
1.412 raeburn 12782: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12783: $changes{'saml'}{$lonhost} = 1;
12784: }
1.386 raeburn 12785: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12786: $changes{'saml'}{$lonhost} = 1;
12787: }
12788: } else {
12789: $changes{'saml'}{$lonhost} = 1;
12790: }
1.412 raeburn 12791: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12792: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12793: }
12794: } else {
1.425 raeburn 12795: if ($saml{$lonhost}) {
1.389 raeburn 12796: $changes{'saml'}{$lonhost} = 1;
12797: delete($currsaml{$lonhost});
12798: }
1.386 raeburn 12799: }
12800: }
12801: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12802: unless (exists($domservers{$posshost})) {
12803: delete($currsaml{$posshost});
1.386 raeburn 12804: }
12805: }
12806: %{$loginhash{'login'}{'saml'}} = %currsaml;
12807: if (@newsamlimgs) {
12808: my $error;
12809: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12810: if ($configuserok eq 'ok') {
12811: if ($switchserver) {
12812: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12813: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12814: my $modified = [];
1.386 raeburn 12815: foreach my $lonhost (@newsamlimgs) {
12816: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12817: my ($result,$imgurl) =
1.421 raeburn 12818: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12819: "login/saml/$lonhost",'','',
12820: $env{'form.saml_img_'.$lonhost.'.filename'},
12821: $modified);
1.386 raeburn 12822: if ($result eq 'ok') {
12823: $currsaml{$lonhost}{'img'} = $imgurl;
12824: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12825: $changes{'saml'}{$lonhost} = 1;
12826: } else {
12827: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12828: $lonhost,$result);
12829: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12830: }
12831: }
1.421 raeburn 12832: &update_modify_urls($r,$modified);
1.386 raeburn 12833: } else {
12834: $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);
12835: }
12836: } else {
12837: $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);
12838: }
12839: if ($error) {
12840: &Apache::lonnet::logthis($error);
12841: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12842: }
12843: }
1.169 raeburn 12844: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12845:
12846: my $defaulthelpfile = '/adm/loginproblems.html';
12847: my $defaulttext = &mt('Default in use');
12848:
1.1 raeburn 12849: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12850: $dom);
12851: if ($putresult eq 'ok') {
1.188 raeburn 12852: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12853: my %defaultchecked = (
12854: 'coursecatalog' => 'on',
1.188 raeburn 12855: 'helpdesk' => 'on',
1.42 raeburn 12856: 'adminmail' => 'off',
1.43 raeburn 12857: 'newuser' => 'off',
1.42 raeburn 12858: );
1.55 raeburn 12859: if (ref($domconfig{'login'}) eq 'HASH') {
12860: foreach my $item (@toggles) {
12861: if ($defaultchecked{$item} eq 'on') {
12862: if (($domconfig{'login'}{$item} eq '0') &&
12863: ($env{'form.'.$item} eq '1')) {
12864: $changes{$item} = 1;
12865: } elsif (($domconfig{'login'}{$item} eq '' ||
12866: $domconfig{'login'}{$item} eq '1') &&
12867: ($env{'form.'.$item} eq '0')) {
12868: $changes{$item} = 1;
12869: }
12870: } elsif ($defaultchecked{$item} eq 'off') {
12871: if (($domconfig{'login'}{$item} eq '1') &&
12872: ($env{'form.'.$item} eq '0')) {
12873: $changes{$item} = 1;
12874: } elsif (($domconfig{'login'}{$item} eq '' ||
12875: $domconfig{'login'}{$item} eq '0') &&
12876: ($env{'form.'.$item} eq '1')) {
12877: $changes{$item} = 1;
12878: }
1.42 raeburn 12879: }
12880: }
1.41 raeburn 12881: }
1.6 raeburn 12882: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12883: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12884: if (exists($changes{'saml'})) {
12885: my $hostid_in_use;
12886: my @hosts = &Apache::lonnet::current_machine_ids();
12887: if (@hosts > 1) {
12888: foreach my $hostid (@hosts) {
12889: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12890: $hostid_in_use = $hostid;
12891: last;
12892: }
12893: }
12894: } else {
12895: $hostid_in_use = $r->dir_config('lonHostID');
12896: }
12897: if (($hostid_in_use) &&
12898: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12899: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12900: }
12901: if (ref($lastactref) eq 'HASH') {
12902: if (ref($changes{'saml'}) eq 'HASH') {
12903: my %updates;
12904: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12905: $lastactref->{'samllanding'} = \%updates;
12906: }
12907: }
12908: }
1.212 raeburn 12909: if (ref($lastactref) eq 'HASH') {
12910: $lastactref->{'domainconfig'} = 1;
12911: }
1.1 raeburn 12912: $resulttext = &mt('Changes made:').'<ul>';
12913: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12914: if ($item eq 'loginvia') {
1.112 raeburn 12915: if (ref($changes{$item}) eq 'HASH') {
12916: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12917: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12918: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12919: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12920: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12921: $protocol = 'http' if ($protocol ne 'https');
12922: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12923:
12924: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12925: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12926: } else {
12927: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12928: }
12929: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12930: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12931: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12932: }
12933: $resulttext .= '</li>';
12934: } else {
12935: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12936: }
1.112 raeburn 12937: } else {
1.128 raeburn 12938: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12939: }
12940: }
1.128 raeburn 12941: $resulttext .= '</ul></li>';
1.112 raeburn 12942: }
1.168 raeburn 12943: } elsif ($item eq 'helpurl') {
12944: if (ref($changes{$item}) eq 'HASH') {
12945: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12946: if (grep(/^\Q$lang\E$/,@delurls)) {
12947: my ($chg,$link);
12948: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12949: if ($lang eq 'nolang') {
12950: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12951: } else {
12952: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12953: }
12954: $resulttext .= '<li>'.$chg.'</li>';
12955: } else {
12956: my $chg;
12957: if ($lang eq 'nolang') {
12958: $chg = &mt('custom log-in help file for no preferred language');
12959: } else {
12960: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12961: }
12962: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12963: $loginhash{'login'}{'helpurl'}{$lang}.
12964: '?inhibitmenu=yes',$chg,600,500).
12965: '</li>';
12966: }
12967: }
12968: }
1.256 raeburn 12969: } elsif ($item eq 'headtag') {
12970: if (ref($changes{$item}) eq 'HASH') {
12971: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12972: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12973: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12974: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12975: $resulttext .= '<li><a href="'.
12976: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12977: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12978: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12979: if ($possexempt{$lonhost}) {
12980: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12981: } else {
12982: $resulttext .= &mt('included for any client IP');
12983: }
12984: $resulttext .= '</li>';
12985: }
12986: }
12987: }
1.386 raeburn 12988: } elsif ($item eq 'saml') {
12989: if (ref($changes{$item}) eq 'HASH') {
12990: my %notlt = (
12991: text => 'Text for log-in by SSO',
12992: img => 'SSO button image',
12993: alt => 'Alt text for button image',
12994: url => 'SSO URL',
12995: title => 'Tooltip for SSO link',
1.412 raeburn 12996: window => 'Pop-up window if iframe',
1.386 raeburn 12997: notsso => 'Text for non-SSO log-in',
12998: );
12999: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
13000: if (ref($currsaml{$lonhost}) eq 'HASH') {
13001: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
13002: '<ul>';
1.412 raeburn 13003: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 13004: if ($currsaml{$lonhost}{$key} eq '') {
13005: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
13006: } else {
13007: my $value = "'$currsaml{$lonhost}{$key}'";
13008: if ($key eq 'img') {
13009: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 13010: } elsif ($key eq 'window') {
13011: $value = 'On';
1.386 raeburn 13012: }
13013: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
13014: $value).'</li>';
13015: }
13016: }
13017: $resulttext .= '</ul></li>';
13018: } else {
13019: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
13020: }
13021: }
13022: }
1.169 raeburn 13023: } elsif ($item eq 'captcha') {
13024: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 13025: my $chgtxt;
1.169 raeburn 13026: if ($loginhash{'login'}{$item} eq 'notused') {
13027: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
13028: } else {
13029: my %captchas = &captcha_phrases();
13030: if ($captchas{$loginhash{'login'}{$item}}) {
13031: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
13032: } else {
13033: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
13034: }
13035: }
13036: $resulttext .= '<li>'.$chgtxt.'</li>';
13037: }
13038: } elsif ($item eq 'recaptchakeys') {
13039: if (ref($loginhash{'login'}) eq 'HASH') {
13040: my ($privkey,$pubkey);
13041: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
13042: $pubkey = $loginhash{'login'}{$item}{'public'};
13043: $privkey = $loginhash{'login'}{$item}{'private'};
13044: }
13045: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
13046: if (!$pubkey) {
13047: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
13048: } else {
13049: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13050: }
13051: if (!$privkey) {
13052: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
13053: } else {
1.251 raeburn 13054: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 13055: }
13056: $chgtxt .= '</ul>';
13057: $resulttext .= '<li>'.$chgtxt.'</li>';
13058: }
1.269 raeburn 13059: } elsif ($item eq 'recaptchaversion') {
13060: if (ref($loginhash{'login'}) eq 'HASH') {
13061: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 13062: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 13063: '</li>';
13064: }
13065: }
1.41 raeburn 13066: } else {
13067: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
13068: }
1.1 raeburn 13069: }
1.6 raeburn 13070: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 13071: } else {
13072: $resulttext = &mt('No changes made to log-in page settings');
13073: }
13074: } else {
1.11 albertel 13075: $resulttext = '<span class="LC_error">'.
13076: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13077: }
1.6 raeburn 13078: if ($errors) {
1.9 raeburn 13079: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 13080: $errors.'</ul>';
13081: }
13082: return $resulttext;
13083: }
13084:
1.256 raeburn 13085: sub check_exempt_addresses {
13086: my ($iplist) = @_;
13087: $iplist =~ s/^\s+//;
13088: $iplist =~ s/\s+$//;
13089: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
13090: my (@okips,$new);
13091: foreach my $ip (@poss_ips) {
13092: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
13093: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
13094: push(@okips,$ip);
13095: }
13096: }
13097: }
13098: if (@okips > 0) {
13099: $new = join(',',@okips);
13100: } else {
13101: $new = '';
13102: }
13103: return $new;
13104: }
13105:
1.6 raeburn 13106: sub color_font_choices {
13107: my %choices =
13108: &Apache::lonlocal::texthash (
13109: bgs => "Background colors",
13110: links => "Link colors",
1.55 raeburn 13111: images => "Images",
1.6 raeburn 13112: font => "Font color",
1.201 raeburn 13113: fontmenu => "Font menu",
1.76 raeburn 13114: pgbg => "Page",
1.6 raeburn 13115: tabbg => "Header",
13116: sidebg => "Border",
13117: link => "Link",
13118: alink => "Active link",
13119: vlink => "Visited link",
13120: );
13121: return %choices;
13122: }
13123:
1.394 raeburn 13124: sub modify_ipaccess {
13125: my ($dom,$lastactref,%domconfig) = @_;
13126: my (@allpos,%changes,%confhash,$errors,$resulttext);
13127: my (@items,%deletions,%itemids,@warnings);
13128: my ($typeorder,$types) = &commblocktype_text();
13129: if ($env{'form.ipaccess_add'}) {
13130: my $name = $env{'form.ipaccess_name_add'};
13131: my ($newid,$error) = &get_ipaccess_id($dom,$name);
13132: if ($newid) {
13133: $itemids{'add'} = $newid;
13134: push(@items,'add');
13135: $changes{$newid} = 1;
13136: } else {
13137: $error = &mt('Failed to acquire unique ID for new IP access control item');
13138: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13139: }
13140: }
13141: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13142: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13143: if (@todelete) {
13144: map { $deletions{$_} = 1; } @todelete;
13145: }
13146: my $maxnum = $env{'form.ipaccess_maxnum'};
13147: for (my $i=0; $i<$maxnum; $i++) {
13148: my $itemid = $env{'form.ipaccess_id_'.$i};
13149: $itemid =~ s/\D+//g;
13150: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13151: if ($deletions{$itemid}) {
13152: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13153: } else {
13154: push(@items,$i);
13155: $itemids{$i} = $itemid;
13156: }
13157: }
13158: }
13159: }
13160: foreach my $idx (@items) {
13161: my $itemid = $itemids{$idx};
13162: next unless ($itemid);
1.446 raeburn 13163: my ($position,%current);
13164: if ($idx eq 'add') {
13165: $position = $env{'form.ipaccess_pos_add'};
13166: } else {
13167: $position = $env{'form.ipaccess_pos_'.$itemid};
1.394 raeburn 13168: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13169: %current = %{$domconfig{'ipaccess'}{$itemid}};
13170: }
13171: }
13172: $position =~ s/\D+//g;
13173: if ($position ne '') {
13174: $allpos[$position] = $itemid;
13175: }
13176: my $name = $env{'form.ipaccess_name_'.$idx};
13177: $name =~ s/^\s+|\s+$//g;
13178: $confhash{$itemid}{'name'} = $name;
13179: my $possrange = $env{'form.ipaccess_range_'.$idx};
13180: $possrange =~ s/^\s+|\s+$//g;
13181: unless ($possrange eq '') {
13182: $possrange =~ s/[\r\n]+/\s/g;
13183: $possrange =~ s/\s*-\s*/-/g;
13184: $possrange =~ s/\s+/,/g;
13185: $possrange =~ s/,+/,/g;
13186: if ($possrange ne '') {
13187: my (@ok,$count);
1.425 raeburn 13188: $count = 0;
1.394 raeburn 13189: foreach my $poss (split(/\,/,$possrange)) {
13190: $count ++;
13191: $poss = &validate_ip_pattern($poss);
13192: if ($poss ne '') {
13193: push(@ok,$poss);
13194: }
13195: }
13196: my $diff = $count - scalar(@ok);
13197: if ($diff) {
13198: $errors .= '<li><span class="LC_error">'.
13199: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13200: $diff,$name).
13201: '</span></li>';
13202: }
13203: if (@ok) {
13204: my @cidr_list;
13205: foreach my $item (@ok) {
13206: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13207: }
13208: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13209: }
13210: }
13211: }
13212: foreach my $field ('name','ip') {
13213: unless (($idx eq 'add') || ($changes{$itemid})) {
13214: if ($current{$field} ne $confhash{$itemid}{$field}) {
13215: $changes{$itemid} = 1;
13216: last;
13217: }
13218: }
13219: }
13220: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13221:
1.394 raeburn 13222: my %commblocks;
1.425 raeburn 13223: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13224: foreach my $type (@{$typeorder}) {
13225: if ($commblocks{$type}) {
13226: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13227: }
13228: unless (($idx eq 'add') || ($changes{$itemid})) {
13229: if (ref($current{'commblocks'}) eq 'HASH') {
13230: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13231: $changes{$itemid} = 1;
13232: }
13233: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13234: $changes{$itemid} = 1;
13235: }
13236: }
13237: }
13238: $confhash{$itemid}{'courses'} = {};
13239: my %crsdeletions;
13240: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13241: if (@delcrs) {
13242: map { $crsdeletions{$_} = 1; } @delcrs;
13243: }
13244: if (ref($current{'courses'}) eq 'HASH') {
13245: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13246: if ($crsdeletions{$cid}) {
13247: $changes{$itemid} = 1;
13248: } else {
13249: $confhash{$itemid}{'courses'}{$cid} = 1;
13250: }
13251: }
13252: }
13253: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13254: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13255: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13256: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13257: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13258: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13259: $errors .= '<li><span class="LC_error">'.
13260: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13261: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13262: '</span></li>';
13263: } else {
13264: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13265: $changes{$itemid} = 1;
13266: }
13267: }
13268: }
13269: if (@allpos > 0) {
13270: my $idx = 0;
13271: foreach my $itemid (@allpos) {
13272: if ($itemid ne '') {
13273: $confhash{$itemid}{'order'} = $idx;
13274: unless ($changes{$itemid}) {
13275: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13276: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13277: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13278: $changes{$itemid} = 1;
13279: }
13280: }
13281: }
13282: }
13283: $idx ++;
13284: }
13285: }
13286: }
13287: if (keys(%changes)) {
13288: my %defaultshash = (
13289: ipaccess => \%confhash,
13290: );
13291: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13292: $dom);
13293: if ($putresult eq 'ok') {
13294: my $cachetime = 1800;
13295: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13296: if (ref($lastactref) eq 'HASH') {
13297: $lastactref->{'ipaccess'} = 1;
13298: }
13299: $resulttext = &mt('Changes made:').'<ul>';
13300: my %bynum;
13301: foreach my $itemid (sort(keys(%changes))) {
13302: if (ref($confhash{$itemid}) eq 'HASH') {
13303: my $position = $confhash{$itemid}{'order'};
13304: if ($position =~ /^\d+$/) {
13305: $bynum{$position} = $itemid;
13306: }
13307: }
13308: }
13309: if (keys(%deletions)) {
13310: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13311: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13312: }
13313: }
13314: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13315: my $itemid = $bynum{$pos};
13316: if (ref($confhash{$itemid}) eq 'HASH') {
13317: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13318: my $position = $pos + 1;
13319: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13320: if ($confhash{$itemid}{'ip'} eq '') {
13321: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13322: } else {
13323: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13324: }
13325: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13326: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13327: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13328: '</li>';
13329: } else {
13330: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13331: }
13332: if (keys(%{$confhash{$itemid}{'courses'}})) {
13333: my @courses;
13334: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13335: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13336: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13337: }
13338: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13339: join('</li><li>',@courses).'</li></ul>';
13340: } else {
13341: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13342: }
1.395 raeburn 13343: $resulttext .= '</ul></li>';
1.394 raeburn 13344: }
13345: }
1.395 raeburn 13346: $resulttext .= '</ul>';
1.394 raeburn 13347: } else {
13348: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13349: }
13350: } else {
13351: $resulttext = &mt('No changes made');
13352: }
13353: if ($errors) {
13354: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13355: $errors.'</ul></p>';
13356: }
13357: return $resulttext;
13358: }
13359:
13360: sub get_ipaccess_id {
13361: my ($domain,$location) = @_;
13362: # get lock on ipaccess db
13363: my $lockhash = {
13364: lock => $env{'user.name'}.
13365: ':'.$env{'user.domain'},
13366: };
13367: my $tries = 0;
13368: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13369: my ($id,$error);
13370:
13371: while (($gotlock ne 'ok') && ($tries<10)) {
13372: $tries ++;
13373: sleep (0.1);
13374: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13375: }
13376: if ($gotlock eq 'ok') {
13377: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13378: if ($currids{'lock'}) {
13379: delete($currids{'lock'});
13380: if (keys(%currids)) {
13381: my @curr = sort { $a <=> $b } keys(%currids);
13382: if ($curr[-1] =~ /^\d+$/) {
13383: $id = 1 + $curr[-1];
13384: }
13385: } else {
13386: $id = 1;
13387: }
13388: if ($id) {
13389: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13390: $error = 'nostore';
13391: }
13392: } else {
13393: $error = 'nonumber';
13394: }
13395: }
13396: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13397: } else {
13398: $error = 'nolock';
13399: }
13400: return ($id,$error);
13401: }
13402:
1.429 raeburn 13403: sub modify_authordefaults {
13404: my ($dom,$lastactref,%domconfig) = @_;
13405: #
13406: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13407: #
13408: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13409: if (ref($domconfig{'quotas'}) eq 'HASH') {
13410: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13411: if ($key =~ /^webdav|authorquota$/) {
13412: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13413: } else {
13414: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13415: }
13416: }
13417: }
13418: my %staticdefaults = (
13419: 'copyright' => 'default',
13420: 'sourceavail' => 'closed',
13421: 'nocodemirror' => 'off',
1.437 raeburn 13422: 'daxecollapse' => 'off',
1.429 raeburn 13423: 'domcoordacc' => 'on',
1.439 raeburn 13424: 'editors' => ['edit','xml'],
1.429 raeburn 13425: 'authorquota' => 500,
13426: 'webdav' => 0,
1.440 raeburn 13427: 'archive' => 'off',
1.429 raeburn 13428: );
13429: my %titles = &authordefaults_titles();
1.440 raeburn 13430: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.429 raeburn 13431: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13432: $confhash{$item} = $env{'form.'.$item};
13433: }
13434: }
13435: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13436: $confhash{'copyright'} = $1;
13437: }
13438: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13439: $confhash{'sourceavail'} = $1;
13440: }
13441: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13442: my @okeditors = ('edit','xml','daxe');
13443: my @editors;
13444: foreach my $item (@posseditors) {
13445: if (grep(/^\Q$item\E$/,@okeditors)) {
13446: push(@editors,$item);
13447: }
13448: }
13449: $confhash{'editors'} = \@editors;
1.436 raeburn 13450:
1.429 raeburn 13451: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13452: my @insttypes;
13453: if (ref($types) eq 'ARRAY') {
13454: @insttypes = @{$types};
13455: }
13456: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13457: my %webdav;
13458: map { $webdav{$_} = 1; } @webdavon;
13459: foreach my $type (@insttypes,'default') {
13460: my $possquota = $env{'form.authorquota_'.$type};
13461: if ($possquota =~ /^\d+$/) {
13462: $save_quotas{'authorquota'}{$type} = $possquota;
13463: }
13464: if ($webdav{$type}) {
13465: $save_quotas{'webdav'}{$type} = 1;
13466: } else {
13467: $save_quotas{'webdav'}{$type} = 0;
13468: }
13469: }
13470: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13471: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13472: }
13473: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
1.440 raeburn 13474: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail','archive') {
1.429 raeburn 13475: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13476: $changes{$item} = 1;
13477: }
13478: }
13479: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
1.436 raeburn 13480: my @diffs =
1.429 raeburn 13481: &Apache::loncommon::compare_arrays($confhash{'editors'},
13482: $domconfig{'authordefaults'}{'editors'});
13483: unless (@diffs == 0) {
13484: $changes{'editors'} = 1;
13485: }
13486: } else {
13487: my @diffs =
13488: &Apache::loncommon::compare_arrays($confhash{'editors'},
13489: $staticdefaults{'editors'});
13490: unless (@diffs == 0) {
13491: $changes{'editors'} = 1;
13492: }
13493: }
13494: } else {
13495: my @offon = ('off','on');
1.440 raeburn 13496: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.436 raeburn 13497: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
1.429 raeburn 13498: $changes{$item} = 1;
13499: }
13500: }
13501: foreach my $item ('copyright','sourceavail') {
13502: if ($confhash{$item} ne $staticdefaults{$item}) {
13503: $changes{$item} = 1;
13504: }
13505: }
1.439 raeburn 13506: my @diffs =
13507: &Apache::loncommon::compare_arrays($confhash{'editors'},
13508: $staticdefaults{'editors'});
13509: unless (@diffs == 0) {
13510: $changes{'editors'} = 1;
13511: }
1.429 raeburn 13512: }
13513: foreach my $key ('authorquota','webdav') {
13514: if (ref($curr_quotas{$key}) eq 'HASH') {
13515: foreach my $type (@insttypes,'default') {
13516: if (exists($save_quotas{$key}{$type})) {
13517: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13518: $changes{$key}{$type} = 1;
13519: }
13520: } elsif (exists($curr_quotas{$key}{$type})) {
13521: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13522: } else {
13523: $save_quotas{$key}{$type} = $staticdefaults{$key};
13524: }
13525: }
13526: } else {
13527: foreach my $type (@insttypes,'default') {
13528: if (exists($save_quotas{$key}{$type})) {
13529: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13530: $changes{$key}{$type} = 1;
13531: }
13532: } else {
13533: $save_quotas{$key}{$type} = $staticdefaults{$key};
13534: }
13535: }
13536: }
13537: }
13538: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13539: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
1.436 raeburn 13540: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
1.429 raeburn 13541: $changes{'webdav_LC_adv'} = 1;
13542: }
13543: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13544: $changes{'webdav_LC_adv'} = 1;
13545: }
13546: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13547: $changes{'webdav_LC_adv'} = 1;
13548: }
13549: my %confighash = (
13550: quotas => \%save_quotas,
13551: authordefaults => \%confhash,
13552: );
13553: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13554: $dom);
13555: my $resulttext;
13556: if ($putresult eq 'ok') {
13557: if (keys(%changes)) {
1.431 raeburn 13558: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13559: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
1.436 raeburn 13560: ($changes{'webdav_LC_adv'})) {
1.429 raeburn 13561: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13562: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13563: }
13564: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13565: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13566: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13567: }
13568: }
13569: $resulttext = &mt('Changes made:').'<ul>';
13570: my $authoroverride;
1.437 raeburn 13571: foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
1.429 raeburn 13572: if (exists($changes{$key})) {
1.431 raeburn 13573: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13574: my $shown;
13575: unless ($authoroverride) {
13576: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13577: $authoroverride = 1;
13578: }
1.437 raeburn 13579: if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
1.429 raeburn 13580: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13581: } elsif ($key eq 'copyright') {
13582: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13583: } elsif ($key eq 'sourceavail') {
13584: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13585: }
1.436 raeburn 13586: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.429 raeburn 13587: }
13588: }
13589: if ($authoroverride) {
13590: $resulttext .= '</ul></li>';
13591: }
13592: my $domcoordoverride;
1.440 raeburn 13593: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv','archive') {
1.429 raeburn 13594: if (exists($changes{$key})) {
13595: my $shown;
13596: unless ($domcoordoverride) {
13597: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13598: $domcoordoverride = 1;
13599: }
13600: if ($key eq 'editors') {
1.431 raeburn 13601: if (ref($confhash{'editors'}) eq 'ARRAY') {
13602: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
13603: if (@{$confhash{'editors'}}) {
13604: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
13605: } else {
13606: $shown = &mt('None');
13607: }
1.429 raeburn 13608: }
13609: } elsif ($key eq 'authorquota') {
13610: foreach my $type (@insttypes) {
13611: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13612: }
13613: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13614: } elsif ($key eq 'webdav') {
13615: foreach my $type (@insttypes) {
13616: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13617: }
13618: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13619: } elsif ($key eq 'webdav_LC_adv') {
13620: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13621: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13622: } else {
13623: $shown = $titles{'none'};
13624: }
1.440 raeburn 13625: } elsif ($key eq 'archive') {
1.441 raeburn 13626: $domdefaults{$key} = $confhash{$key};
1.440 raeburn 13627: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
1.429 raeburn 13628: }
13629: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.436 raeburn 13630: }
1.429 raeburn 13631: }
13632: if ($domcoordoverride) {
13633: $resulttext .= '</ul></li>';
13634: }
1.439 raeburn 13635: $resulttext .= '</ul>';
1.431 raeburn 13636: my $cachetime = 24*60*60;
13637: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13638: if (ref($lastactref) eq 'HASH') {
13639: $lastactref->{'domdefaults'} = 1;
13640: }
1.429 raeburn 13641: } else {
13642: $resulttext = &mt('No changes made to Authoring Space defaults');
13643: }
13644: }
13645: return $resulttext;
13646: }
13647:
1.6 raeburn 13648: sub modify_rolecolors {
1.205 raeburn 13649: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13650: my ($resulttext,%rolehash);
13651: $rolehash{'rolecolors'} = {};
1.55 raeburn 13652: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13653: if ($domconfig{'rolecolors'} eq '') {
13654: $domconfig{'rolecolors'} = {};
13655: }
13656: }
1.9 raeburn 13657: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13658: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13659: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13660: $dom);
13661: if ($putresult eq 'ok') {
13662: if (keys(%changes) > 0) {
1.41 raeburn 13663: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13664: if (ref($lastactref) eq 'HASH') {
13665: $lastactref->{'domainconfig'} = 1;
13666: }
1.6 raeburn 13667: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13668: $rolehash{'rolecolors'});
13669: } else {
13670: $resulttext = &mt('No changes made to default color schemes');
13671: }
13672: } else {
1.11 albertel 13673: $resulttext = '<span class="LC_error">'.
13674: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13675: }
13676: if ($errors) {
13677: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13678: $errors.'</ul>';
13679: }
13680: return $resulttext;
13681: }
13682:
13683: sub modify_colors {
1.9 raeburn 13684: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13685: my (%changes,%choices);
1.51 raeburn 13686: my @bgs;
1.6 raeburn 13687: my @links = ('link','alink','vlink');
1.41 raeburn 13688: my @logintext;
1.6 raeburn 13689: my @images;
13690: my $servadm = $r->dir_config('lonAdmEMail');
13691: my $errors;
1.200 raeburn 13692: my %defaults;
1.6 raeburn 13693: foreach my $role (@{$roles}) {
13694: if ($role eq 'login') {
1.12 raeburn 13695: %choices = &login_choices();
1.41 raeburn 13696: @logintext = ('textcol','bgcol');
1.12 raeburn 13697: } else {
13698: %choices = &color_font_choices();
13699: }
13700: if ($role eq 'login') {
1.41 raeburn 13701: @images = ('img','logo','domlogo','login');
1.51 raeburn 13702: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13703: } else {
1.445 raeburn 13704: @images = ();
1.200 raeburn 13705: @bgs = ('pgbg','tabbg','sidebg');
13706: }
13707: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
1.444 raeburn 13708: $env{'form.'.$role.'_font'} = lc($env{'form.'.$role.'_font'});
13709: if ($env{'form.'.$role.'_font'} =~ /^\w+/) {
13710: $env{'form.'.$role.'_font'} = '#'.$env{'form.'.$role.'_font'};
13711: }
13712: unless ($env{'form.'.$role.'_font'} eq lc($defaults{'font'})) {
1.200 raeburn 13713: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13714: }
13715: if ($role eq 'login') {
13716: foreach my $item (@logintext) {
1.234 raeburn 13717: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13718: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13719: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13720: }
13721: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13722: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13723: }
13724: }
13725: } else {
1.234 raeburn 13726: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13727: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13728: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13729: }
1.445 raeburn 13730: unless ($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13731: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13732: }
1.6 raeburn 13733: }
1.200 raeburn 13734: foreach my $item (@bgs) {
1.234 raeburn 13735: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13736: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13737: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13738: }
13739: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13740: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13741: }
13742: }
13743: foreach my $item (@links) {
1.234 raeburn 13744: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13745: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13746: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13747: }
13748: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13749: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13750: }
1.6 raeburn 13751: }
1.46 raeburn 13752: my ($configuserok,$author_ok,$switchserver) =
13753: &config_check($dom,$confname,$servadm);
1.9 raeburn 13754: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13755: if (ref($domconfig->{$role}) ne 'HASH') {
13756: $domconfig->{$role} = {};
13757: }
1.8 raeburn 13758: foreach my $img (@images) {
1.402 raeburn 13759: if ($role eq 'login') {
13760: if (($img eq 'img') || ($img eq 'logo')) {
13761: if (defined($env{'form.login_showlogo_'.$img})) {
13762: $confhash->{$role}{'showlogo'}{$img} = 1;
13763: } else {
13764: $confhash->{$role}{'showlogo'}{$img} = 0;
13765: }
13766: }
13767: if ($env{'form.login_alt_'.$img} ne '') {
13768: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13769: }
1.402 raeburn 13770: }
1.18 albertel 13771: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13772: && !defined($domconfig->{$role}{$img})
13773: && !$env{'form.'.$role.'_del_'.$img}
13774: && $env{'form.'.$role.'_import_'.$img}) {
13775: # import the old configured image from the .tab setting
13776: # if they haven't provided a new one
13777: $domconfig->{$role}{$img} =
13778: $env{'form.'.$role.'_import_'.$img};
13779: }
1.6 raeburn 13780: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13781: my $error;
1.6 raeburn 13782: if ($configuserok eq 'ok') {
1.9 raeburn 13783: if ($switchserver) {
1.12 raeburn 13784: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13785: } else {
13786: if ($author_ok eq 'ok') {
1.421 raeburn 13787: my $modified = [];
1.9 raeburn 13788: my ($result,$logourl) =
1.421 raeburn 13789: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13790: $dom,$confname,$img,$width,$height,
13791: '',$modified);
1.9 raeburn 13792: if ($result eq 'ok') {
13793: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13794: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13795: &update_modify_urls($r,$modified);
1.9 raeburn 13796: } else {
1.12 raeburn 13797: $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 13798: }
13799: } else {
1.46 raeburn 13800: $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 13801: }
13802: }
13803: } else {
1.46 raeburn 13804: $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 13805: }
13806: if ($error) {
1.8 raeburn 13807: &Apache::lonnet::logthis($error);
1.11 albertel 13808: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13809: }
13810: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13811: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13812: my $error;
13813: if ($configuserok eq 'ok') {
13814: # is confname an author?
13815: if ($switchserver eq '') {
13816: if ($author_ok eq 'ok') {
1.421 raeburn 13817: my $modified = [];
1.9 raeburn 13818: my ($result,$logourl) =
1.421 raeburn 13819: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13820: $dom,$confname,$img,$width,$height,
13821: '',$modified);
1.9 raeburn 13822: if ($result eq 'ok') {
13823: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13824: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13825: &update_modify_urls($r,$modified);
1.9 raeburn 13826: }
13827: }
13828: }
13829: }
1.6 raeburn 13830: }
13831: }
13832: }
13833: if (ref($domconfig) eq 'HASH') {
13834: if (ref($domconfig->{$role}) eq 'HASH') {
13835: foreach my $img (@images) {
13836: if ($domconfig->{$role}{$img} ne '') {
13837: if ($env{'form.'.$role.'_del_'.$img}) {
13838: $confhash->{$role}{$img} = '';
1.12 raeburn 13839: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13840: } else {
1.9 raeburn 13841: if ($confhash->{$role}{$img} eq '') {
13842: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13843: }
1.6 raeburn 13844: }
13845: } else {
13846: if ($env{'form.'.$role.'_del_'.$img}) {
13847: $confhash->{$role}{$img} = '';
1.12 raeburn 13848: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13849: }
13850: }
1.402 raeburn 13851: if ($role eq 'login') {
13852: if (($img eq 'logo') || ($img eq 'img')) {
13853: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13854: if ($confhash->{$role}{'showlogo'}{$img} ne
13855: $domconfig->{$role}{'showlogo'}{$img}) {
13856: $changes{$role}{'showlogo'}{$img} = 1;
13857: }
13858: } else {
13859: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13860: $changes{$role}{'showlogo'}{$img} = 1;
13861: }
1.70 raeburn 13862: }
1.402 raeburn 13863: }
13864: if ($img ne 'login') {
13865: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13866: if ($confhash->{$role}{'alttext'}{$img} ne
13867: $domconfig->{$role}{'alttext'}{$img}) {
13868: $changes{$role}{'alttext'}{$img} = 1;
13869: }
13870: } else {
13871: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13872: $changes{$role}{'alttext'}{$img} = 1;
13873: }
1.70 raeburn 13874: }
13875: }
13876: }
13877: }
1.6 raeburn 13878: if ($domconfig->{$role}{'font'} ne '') {
13879: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13880: $changes{$role}{'font'} = 1;
13881: }
13882: } else {
13883: if ($confhash->{$role}{'font'}) {
13884: $changes{$role}{'font'} = 1;
13885: }
13886: }
1.107 raeburn 13887: if ($role ne 'login') {
13888: if ($domconfig->{$role}{'fontmenu'} ne '') {
13889: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13890: $changes{$role}{'fontmenu'} = 1;
13891: }
13892: } else {
13893: if ($confhash->{$role}{'fontmenu'}) {
13894: $changes{$role}{'fontmenu'} = 1;
13895: }
1.97 tempelho 13896: }
13897: }
1.6 raeburn 13898: foreach my $item (@bgs) {
13899: if ($domconfig->{$role}{$item} ne '') {
13900: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13901: $changes{$role}{'bgs'}{$item} = 1;
13902: }
13903: } else {
13904: if ($confhash->{$role}{$item}) {
13905: $changes{$role}{'bgs'}{$item} = 1;
13906: }
13907: }
13908: }
13909: foreach my $item (@links) {
13910: if ($domconfig->{$role}{$item} ne '') {
13911: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13912: $changes{$role}{'links'}{$item} = 1;
13913: }
13914: } else {
13915: if ($confhash->{$role}{$item}) {
13916: $changes{$role}{'links'}{$item} = 1;
13917: }
13918: }
13919: }
1.41 raeburn 13920: foreach my $item (@logintext) {
13921: if ($domconfig->{$role}{$item} ne '') {
13922: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13923: $changes{$role}{'logintext'}{$item} = 1;
13924: }
13925: } else {
13926: if ($confhash->{$role}{$item}) {
13927: $changes{$role}{'logintext'}{$item} = 1;
13928: }
13929: }
13930: }
1.6 raeburn 13931: } else {
13932: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13933: \@logintext,$confhash,\%changes);
1.6 raeburn 13934: }
13935: } else {
13936: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13937: \@logintext,$confhash,\%changes);
1.6 raeburn 13938: }
13939: }
13940: return ($errors,%changes);
13941: }
13942:
1.46 raeburn 13943: sub config_check {
13944: my ($dom,$confname,$servadm) = @_;
13945: my ($configuserok,$author_ok,$switchserver,%currroles);
13946: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13947: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13948: $confname,$servadm);
13949: if ($configuserok eq 'ok') {
13950: $switchserver = &check_switchserver($dom,$confname);
13951: if ($switchserver eq '') {
13952: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13953: }
13954: }
13955: return ($configuserok,$author_ok,$switchserver);
13956: }
13957:
1.6 raeburn 13958: sub default_change_checker {
1.41 raeburn 13959: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13960: foreach my $item (@{$links}) {
13961: if ($confhash->{$role}{$item}) {
13962: $changes->{$role}{'links'}{$item} = 1;
13963: }
13964: }
13965: foreach my $item (@{$bgs}) {
13966: if ($confhash->{$role}{$item}) {
13967: $changes->{$role}{'bgs'}{$item} = 1;
13968: }
13969: }
1.41 raeburn 13970: foreach my $item (@{$logintext}) {
13971: if ($confhash->{$role}{$item}) {
13972: $changes->{$role}{'logintext'}{$item} = 1;
13973: }
13974: }
1.6 raeburn 13975: foreach my $img (@{$images}) {
13976: if ($env{'form.'.$role.'_del_'.$img}) {
13977: $confhash->{$role}{$img} = '';
1.12 raeburn 13978: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13979: }
1.70 raeburn 13980: if ($role eq 'login') {
13981: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13982: $changes->{$role}{'showlogo'}{$img} = 1;
13983: }
1.402 raeburn 13984: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13985: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13986: $changes->{$role}{'alttext'}{$img} = 1;
13987: }
13988: }
1.70 raeburn 13989: }
1.6 raeburn 13990: }
13991: if ($confhash->{$role}{'font'}) {
13992: $changes->{$role}{'font'} = 1;
13993: }
1.48 raeburn 13994: }
1.6 raeburn 13995:
13996: sub display_colorchgs {
13997: my ($dom,$changes,$roles,$confhash) = @_;
13998: my (%choices,$resulttext);
13999: if (!grep(/^login$/,@{$roles})) {
14000: $resulttext = &mt('Changes made:').'<br />';
14001: }
14002: foreach my $role (@{$roles}) {
14003: if ($role eq 'login') {
14004: %choices = &login_choices();
14005: } else {
14006: %choices = &color_font_choices();
14007: }
14008: if (ref($changes->{$role}) eq 'HASH') {
14009: if ($role ne 'login') {
14010: $resulttext .= '<h4>'.&mt($role).'</h4>';
14011: }
14012: foreach my $key (sort(keys(%{$changes->{$role}}))) {
14013: if ($role ne 'login') {
14014: $resulttext .= '<ul>';
14015: }
14016: if (ref($changes->{$role}{$key}) eq 'HASH') {
14017: if ($role ne 'login') {
14018: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
14019: }
14020: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 14021: if (($role eq 'login') && ($key eq 'showlogo')) {
14022: if ($confhash->{$role}{$key}{$item}) {
14023: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
14024: } else {
14025: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
14026: }
1.402 raeburn 14027: } elsif (($role eq 'login') && ($key eq 'alttext')) {
14028: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 14029: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 14030: $confhash->{$role}{$key}{$item}).'</li>';
14031: } else {
14032: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
14033: }
1.70 raeburn 14034: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 14035: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
14036: } else {
1.12 raeburn 14037: my $newitem = $confhash->{$role}{$item};
14038: if ($key eq 'images') {
1.306 raeburn 14039: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 14040: }
14041: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 14042: }
14043: }
14044: if ($role ne 'login') {
14045: $resulttext .= '</ul></li>';
14046: }
14047: } else {
14048: if ($confhash->{$role}{$key} eq '') {
14049: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
14050: } else {
14051: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
14052: }
14053: }
14054: if ($role ne 'login') {
14055: $resulttext .= '</ul>';
14056: }
14057: }
14058: }
14059: }
1.3 raeburn 14060: return $resulttext;
1.1 raeburn 14061: }
14062:
1.9 raeburn 14063: sub thumb_dimensions {
14064: return ('200','50');
14065: }
14066:
1.16 raeburn 14067: sub check_dimensions {
14068: my ($inputfile) = @_;
14069: my ($fullwidth,$fullheight);
14070: if ($inputfile =~ m|^[/\w.\-]+$|) {
14071: if (open(PIPE,"identify $inputfile 2>&1 |")) {
14072: my $imageinfo = <PIPE>;
14073: if (!close(PIPE)) {
14074: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
14075: }
14076: chomp($imageinfo);
14077: my ($fullsize) =
1.21 raeburn 14078: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 14079: if ($fullsize) {
14080: ($fullwidth,$fullheight) = split(/x/,$fullsize);
14081: }
14082: }
14083: }
14084: return ($fullwidth,$fullheight);
14085: }
14086:
1.9 raeburn 14087: sub check_configuser {
14088: my ($uhome,$dom,$confname,$servadm) = @_;
14089: my ($configuserok,%currroles);
14090: if ($uhome eq 'no_host') {
14091: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 14092: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 14093: $configuserok =
14094: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
14095: $configpass,'','','','','',undef,$servadm);
14096: } else {
14097: $configuserok = 'ok';
14098: %currroles =
14099: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
14100: }
14101: return ($configuserok,%currroles);
14102: }
14103:
14104: sub check_authorstatus {
14105: my ($dom,$confname,%currroles) = @_;
14106: my $author_ok;
1.40 raeburn 14107: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 14108: my $start = time;
14109: my $end = 0;
14110: $author_ok =
14111: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 14112: 'au',$end,$start,'','','domconfig');
1.9 raeburn 14113: } else {
14114: $author_ok = 'ok';
14115: }
14116: return $author_ok;
14117: }
14118:
1.421 raeburn 14119: sub update_modify_urls {
14120: my ($r,$modified) = @_;
14121: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
14122: push(@{$modified_urls},$modified);
14123: unless ($registered_cleanup) {
14124: my $handlers = $r->get_handlers('PerlCleanupHandler');
14125: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
14126: $registered_cleanup=1;
1.9 raeburn 14127: }
14128: }
1.155 raeburn 14129: }
14130:
14131: sub notifysubscribed {
14132: foreach my $targetsource (@{$modified_urls}){
14133: next unless (ref($targetsource) eq 'ARRAY');
14134: my ($target,$source)=@{$targetsource};
14135: if ($source ne '') {
1.316 raeburn 14136: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 14137: print $logfh "\nCleanup phase: Notifications\n";
14138: my @subscribed=&subscribed_hosts($target);
14139: foreach my $subhost (@subscribed) {
14140: print $logfh "\nNotifying host ".$subhost.':';
14141: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
14142: print $logfh $reply;
14143: }
14144: my @subscribedmeta=&subscribed_hosts("$target.meta");
14145: foreach my $subhost (@subscribedmeta) {
14146: print $logfh "\nNotifying host for metadata only ".$subhost.':';
14147: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
14148: $subhost);
14149: print $logfh $reply;
14150: }
14151: print $logfh "\n============ Done ============\n";
1.160 raeburn 14152: close($logfh);
1.155 raeburn 14153: }
14154: }
14155: }
14156: return OK;
14157: }
14158:
14159: sub subscribed_hosts {
14160: my ($target) = @_;
14161: my @subscribed;
1.316 raeburn 14162: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 14163: while (my $subline=<$fh>) {
14164: if ($subline =~ /^($match_lonid):/) {
14165: my $host = $1;
14166: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
14167: unless (grep(/^\Q$host\E$/,@subscribed)) {
14168: push(@subscribed,$host);
14169: }
14170: }
14171: }
14172: }
14173: }
14174: return @subscribed;
1.9 raeburn 14175: }
14176:
14177: sub check_switchserver {
14178: my ($dom,$confname) = @_;
1.424 raeburn 14179: my ($allowed,$switchserver,$home);
14180: if ($confname eq '') {
1.9 raeburn 14181: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14182: } else {
14183: $home = &Apache::lonnet::homeserver($confname,$dom);
14184: if ($home eq 'no_host') {
14185: $home = &Apache::lonnet::domain($dom,'primary');
14186: }
1.9 raeburn 14187: }
14188: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14189: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14190: if (!$allowed) {
1.426 raeburn 14191: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14192: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14193: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14194: }
14195: return $switchserver;
14196: }
14197:
1.1 raeburn 14198: sub modify_quotas {
1.216 raeburn 14199: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14200: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14201: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14202: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14203: $validationfieldsref);
1.86 raeburn 14204: if ($action eq 'quotas') {
1.429 raeburn 14205: $context = 'tools';
1.163 raeburn 14206: } else {
1.86 raeburn 14207: $context = $action;
14208: }
14209: if ($context eq 'requestcourses') {
1.325 raeburn 14210: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14211: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14212: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14213: %titles = &courserequest_titles();
14214: $toolregexp = join('|',@usertools);
14215: %conditions = &courserequest_conditions();
1.216 raeburn 14216: $confname = $dom.'-domainconfig';
14217: my $servadm = $r->dir_config('lonAdmEMail');
14218: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14219: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14220: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14221: } elsif ($context eq 'requestauthor') {
14222: @usertools = ('author');
14223: %titles = &authorrequest_titles();
1.86 raeburn 14224: } else {
1.430 raeburn 14225: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14226: %titles = &tool_titles();
1.86 raeburn 14227: }
1.212 raeburn 14228: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14229: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14230: foreach my $key (keys(%env)) {
1.101 raeburn 14231: if ($context eq 'requestcourses') {
14232: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14233: my $item = $1;
14234: my $type = $2;
14235: if ($type =~ /^limit_(.+)/) {
14236: $limithash{$item}{$1} = $env{$key};
14237: } else {
14238: $confhash{$item}{$type} = $env{$key};
14239: }
14240: }
1.163 raeburn 14241: } elsif ($context eq 'requestauthor') {
14242: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14243: $confhash{$1} = $env{$key};
14244: }
1.101 raeburn 14245: } else {
1.86 raeburn 14246: if ($key =~ /^form\.quota_(.+)$/) {
14247: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14248: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14249: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14250: }
1.72 raeburn 14251: }
14252: }
1.163 raeburn 14253: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14254: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14255: @approvalnotify = sort(@approvalnotify);
14256: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14257: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14258: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14259: foreach my $type (@hasuniquecode) {
14260: if (grep(/^\Q$type\E$/,@crstypes)) {
14261: $confhash{'uniquecode'}{$type} = 1;
14262: }
1.216 raeburn 14263: }
1.242 raeburn 14264: my (%newbook,%allpos);
1.216 raeburn 14265: if ($context eq 'requestcourses') {
1.242 raeburn 14266: foreach my $type ('textbooks','templates') {
14267: @{$allpos{$type}} = ();
14268: my $invalid;
14269: if ($type eq 'textbooks') {
14270: $invalid = &mt('Invalid LON-CAPA course for textbook');
14271: } else {
14272: $invalid = &mt('Invalid LON-CAPA course for template');
14273: }
14274: if ($env{'form.'.$type.'_addbook'}) {
14275: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14276: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14277: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14278: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14279: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14280: } else {
14281: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14282: my $position = $env{'form.'.$type.'_addbook_pos'};
14283: $position =~ s/\D+//g;
14284: if ($position ne '') {
14285: $allpos{$type}[$position] = $newbook{$type};
14286: }
1.216 raeburn 14287: }
1.242 raeburn 14288: } else {
14289: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14290: }
14291: }
1.242 raeburn 14292: }
1.216 raeburn 14293: }
1.102 raeburn 14294: if (ref($domconfig{$action}) eq 'HASH') {
14295: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14296: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14297: $changes{'notify'}{'approval'} = 1;
14298: }
14299: } else {
1.144 raeburn 14300: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14301: $changes{'notify'}{'approval'} = 1;
14302: }
14303: }
1.218 raeburn 14304: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14305: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14306: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14307: unless ($confhash{'uniquecode'}{$crstype}) {
14308: $changes{'uniquecode'} = 1;
14309: }
14310: }
14311: unless ($changes{'uniquecode'}) {
14312: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14313: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14314: $changes{'uniquecode'} = 1;
14315: }
14316: }
14317: }
14318: } else {
14319: $changes{'uniquecode'} = 1;
14320: }
14321: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14322: $changes{'uniquecode'} = 1;
1.216 raeburn 14323: }
14324: if ($context eq 'requestcourses') {
1.242 raeburn 14325: foreach my $type ('textbooks','templates') {
14326: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14327: my %deletions;
14328: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14329: if (@todelete) {
14330: map { $deletions{$_} = 1; } @todelete;
14331: }
14332: my %imgdeletions;
14333: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14334: if (@todeleteimages) {
14335: map { $imgdeletions{$_} = 1; } @todeleteimages;
14336: }
14337: my $maxnum = $env{'form.'.$type.'_maxnum'};
14338: for (my $i=0; $i<=$maxnum; $i++) {
14339: my $itemid = $env{'form.'.$type.'_id_'.$i};
14340: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14341: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14342: if ($deletions{$key}) {
14343: if ($domconfig{$action}{$type}{$key}{'image'}) {
14344: #FIXME need to obsolete item in RES space
14345: }
14346: next;
14347: } else {
14348: my $newpos = $env{'form.'.$itemid};
14349: $newpos =~ s/\D+//g;
1.243 raeburn 14350: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14351: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14352: ($type eq 'templates'));
1.242 raeburn 14353: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14354: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14355: $changes{$type}{$key} = 1;
14356: }
14357: }
14358: $allpos{$type}[$newpos] = $key;
14359: }
14360: if ($imgdeletions{$key}) {
14361: $changes{$type}{$key} = 1;
1.216 raeburn 14362: #FIXME need to obsolete item in RES space
1.242 raeburn 14363: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14364: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14365: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14366: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14367: } else {
14368: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14369: $cdom,$cnum,$type,$configuserok,
14370: $switchserver,$author_ok);
14371: if ($imgurl) {
14372: $confhash{$type}{$key}{'image'} = $imgurl;
14373: $changes{$type}{$key} = 1;
14374: }
14375: if ($error) {
14376: &Apache::lonnet::logthis($error);
14377: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14378: }
14379: }
1.242 raeburn 14380: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14381: $confhash{$type}{$key}{'image'} =
14382: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14383: }
14384: }
14385: }
14386: }
14387: }
14388: }
1.102 raeburn 14389: } else {
1.144 raeburn 14390: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14391: $changes{'notify'}{'approval'} = 1;
14392: }
1.218 raeburn 14393: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14394: $changes{'uniquecode'} = 1;
14395: }
14396: }
14397: if ($context eq 'requestcourses') {
1.242 raeburn 14398: foreach my $type ('textbooks','templates') {
14399: if ($newbook{$type}) {
14400: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14401: foreach my $item ('subject','title','publisher','author') {
14402: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14403: ($type eq 'template'));
1.242 raeburn 14404: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14405: if ($env{'form.'.$type.'_addbook_'.$item}) {
14406: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14407: }
14408: }
14409: if ($type eq 'textbooks') {
14410: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14411: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14412: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14413: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14414: } else {
14415: my ($imageurl,$error) =
14416: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14417: $configuserok,$switchserver,$author_ok);
14418: if ($imageurl) {
14419: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14420: }
14421: if ($error) {
14422: &Apache::lonnet::logthis($error);
14423: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14424: }
1.242 raeburn 14425: }
14426: }
1.216 raeburn 14427: }
14428: }
1.242 raeburn 14429: if (@{$allpos{$type}} > 0) {
14430: my $idx = 0;
14431: foreach my $item (@{$allpos{$type}}) {
14432: if ($item ne '') {
14433: $confhash{$type}{$item}{'order'} = $idx;
14434: if (ref($domconfig{$action}) eq 'HASH') {
14435: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14436: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14437: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14438: $changes{$type}{$item} = 1;
14439: }
1.216 raeburn 14440: }
14441: }
14442: }
1.242 raeburn 14443: $idx ++;
1.216 raeburn 14444: }
14445: }
14446: }
14447: }
1.235 raeburn 14448: if (ref($validationitemsref) eq 'ARRAY') {
14449: foreach my $item (@{$validationitemsref}) {
14450: if ($item eq 'fields') {
14451: my @changed;
14452: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14453: if (@{$confhash{'validation'}{$item}} > 0) {
14454: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14455: }
1.266 raeburn 14456: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14457: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14458: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14459: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14460: $domconfig{'requestcourses'}{'validation'}{$item});
14461: } else {
14462: @changed = @{$confhash{'validation'}{$item}};
14463: }
1.235 raeburn 14464: } else {
14465: @changed = @{$confhash{'validation'}{$item}};
14466: }
14467: } else {
14468: @changed = @{$confhash{'validation'}{$item}};
14469: }
14470: if (@changed) {
14471: if ($confhash{'validation'}{$item}) {
14472: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14473: } else {
14474: $changes{'validation'}{$item} = &mt('None');
14475: }
14476: }
14477: } else {
14478: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14479: if ($item eq 'markup') {
14480: if ($env{'form.requestcourses_validation_'.$item}) {
14481: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14482: }
14483: }
1.266 raeburn 14484: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14485: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14486: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14487: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14488: }
14489: } else {
14490: if ($confhash{'validation'}{$item} ne '') {
14491: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14492: }
1.235 raeburn 14493: }
14494: } else {
14495: if ($confhash{'validation'}{$item} ne '') {
14496: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14497: }
14498: }
14499: }
14500: }
14501: }
14502: if ($env{'form.validationdc'}) {
14503: my $newval = $env{'form.validationdc'};
1.285 raeburn 14504: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14505: if (exists($domcoords{$newval})) {
14506: $confhash{'validation'}{'dc'} = $newval;
14507: }
14508: }
14509: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14510: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14511: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14512: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14513: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14514: if ($confhash{'validation'}{'dc'} eq '') {
14515: $changes{'validation'}{'dc'} = &mt('None');
14516: } else {
14517: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14518: }
1.235 raeburn 14519: }
1.266 raeburn 14520: } elsif ($confhash{'validation'}{'dc'} ne '') {
14521: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14522: }
14523: } elsif ($confhash{'validation'}{'dc'} ne '') {
14524: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14525: }
14526: } elsif ($confhash{'validation'}{'dc'} ne '') {
14527: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14528: }
1.266 raeburn 14529: } else {
14530: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14531: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14532: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14533: $changes{'validation'}{'dc'} = &mt('None');
14534: }
14535: }
1.235 raeburn 14536: }
14537: }
1.102 raeburn 14538: }
14539: } else {
1.86 raeburn 14540: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14541: }
1.72 raeburn 14542: foreach my $item (@usertools) {
14543: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14544: my $unset;
1.101 raeburn 14545: if ($context eq 'requestcourses') {
1.104 raeburn 14546: $unset = '0';
14547: if ($type eq '_LC_adv') {
14548: $unset = '';
14549: }
1.101 raeburn 14550: if ($confhash{$item}{$type} eq 'autolimit') {
14551: $confhash{$item}{$type} .= '=';
14552: unless ($limithash{$item}{$type} =~ /\D/) {
14553: $confhash{$item}{$type} .= $limithash{$item}{$type};
14554: }
14555: }
1.163 raeburn 14556: } elsif ($context eq 'requestauthor') {
14557: $unset = '0';
14558: if ($type eq '_LC_adv') {
14559: $unset = '';
14560: }
1.72 raeburn 14561: } else {
1.101 raeburn 14562: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14563: $confhash{$item}{$type} = 1;
14564: } else {
14565: $confhash{$item}{$type} = 0;
14566: }
1.72 raeburn 14567: }
1.86 raeburn 14568: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14569: if ($action eq 'requestauthor') {
14570: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14571: $changes{$type} = 1;
14572: }
14573: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14574: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14575: $changes{$item}{$type} = 1;
14576: }
14577: } else {
14578: if ($context eq 'requestcourses') {
1.104 raeburn 14579: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14580: $changes{$item}{$type} = 1;
14581: }
14582: } else {
14583: if (!$confhash{$item}{$type}) {
14584: $changes{$item}{$type} = 1;
14585: }
14586: }
14587: }
14588: } else {
14589: if ($context eq 'requestcourses') {
1.104 raeburn 14590: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14591: $changes{$item}{$type} = 1;
14592: }
1.163 raeburn 14593: } elsif ($context eq 'requestauthor') {
14594: if ($confhash{$type} ne $unset) {
14595: $changes{$type} = 1;
14596: }
1.72 raeburn 14597: } else {
14598: if (!$confhash{$item}{$type}) {
14599: $changes{$item}{$type} = 1;
14600: }
14601: }
14602: }
1.1 raeburn 14603: }
14604: }
1.163 raeburn 14605: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14606: if (ref($domconfig{'quotas'}) eq 'HASH') {
14607: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14608: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14609: if (exists($confhash{'defaultquota'}{$key})) {
14610: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14611: $changes{'defaultquota'}{$key} = 1;
14612: }
14613: } else {
14614: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14615: }
14616: }
1.86 raeburn 14617: } else {
14618: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14619: if (exists($confhash{'defaultquota'}{$key})) {
14620: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14621: $changes{'defaultquota'}{$key} = 1;
14622: }
14623: } else {
14624: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14625: }
1.1 raeburn 14626: }
14627: }
1.197 raeburn 14628: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14629: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14630: }
14631: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14632: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14633: }
1.1 raeburn 14634: }
1.86 raeburn 14635: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14636: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14637: if (ref($domconfig{'quotas'}) eq 'HASH') {
14638: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14639: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14640: $changes{'defaultquota'}{$key} = 1;
14641: }
14642: } else {
14643: if (!exists($domconfig{'quotas'}{$key})) {
14644: $changes{'defaultquota'}{$key} = 1;
14645: }
1.72 raeburn 14646: }
14647: } else {
1.86 raeburn 14648: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14649: }
1.1 raeburn 14650: }
14651: }
14652: }
1.72 raeburn 14653:
1.163 raeburn 14654: if ($context eq 'requestauthor') {
14655: $domdefaults{'requestauthor'} = \%confhash;
14656: } else {
14657: foreach my $key (keys(%confhash)) {
1.242 raeburn 14658: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14659: $domdefaults{$key} = $confhash{$key};
14660: }
1.163 raeburn 14661: }
1.72 raeburn 14662: }
1.163 raeburn 14663:
1.1 raeburn 14664: my %quotahash = (
1.86 raeburn 14665: $action => { %confhash }
1.1 raeburn 14666: );
14667: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14668: $dom);
14669: if ($putresult eq 'ok') {
14670: if (keys(%changes) > 0) {
1.72 raeburn 14671: my $cachetime = 24*60*60;
14672: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14673: if (ref($lastactref) eq 'HASH') {
14674: $lastactref->{'domdefaults'} = 1;
14675: }
1.1 raeburn 14676: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14677: unless (($context eq 'requestcourses') ||
1.163 raeburn 14678: ($context eq 'requestauthor')) {
1.86 raeburn 14679: if (ref($changes{'defaultquota'}) eq 'HASH') {
14680: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14681: foreach my $type (@{$types},'default') {
14682: if (defined($changes{'defaultquota'}{$type})) {
14683: my $typetitle = $usertypes->{$type};
14684: if ($type eq 'default') {
14685: $typetitle = $othertitle;
14686: }
1.213 raeburn 14687: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14688: }
14689: }
1.86 raeburn 14690: $resulttext .= '</ul></li>';
1.72 raeburn 14691: }
14692: }
1.80 raeburn 14693: my %newenv;
1.72 raeburn 14694: foreach my $item (@usertools) {
1.163 raeburn 14695: my (%haschgs,%inconf);
14696: if ($context eq 'requestauthor') {
14697: %haschgs = %changes;
1.210 raeburn 14698: %inconf = %confhash;
1.163 raeburn 14699: } else {
14700: if (ref($changes{$item}) eq 'HASH') {
14701: %haschgs = %{$changes{$item}};
14702: }
14703: if (ref($confhash{$item}) eq 'HASH') {
14704: %inconf = %{$confhash{$item}};
14705: }
14706: }
14707: if (keys(%haschgs) > 0) {
1.80 raeburn 14708: my $newacc =
14709: &Apache::lonnet::usertools_access($env{'user.name'},
14710: $env{'user.domain'},
1.86 raeburn 14711: $item,'reload',$context);
1.210 raeburn 14712: if (($context eq 'requestcourses') ||
1.163 raeburn 14713: ($context eq 'requestauthor')) {
1.108 raeburn 14714: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14715: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14716: }
14717: } else {
14718: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14719: $newenv{'environment.availabletools.'.$item} = $newacc;
14720: }
1.80 raeburn 14721: }
1.163 raeburn 14722: unless ($context eq 'requestauthor') {
14723: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14724: }
1.72 raeburn 14725: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14726: if ($haschgs{$type}) {
1.72 raeburn 14727: my $typetitle = $usertypes->{$type};
14728: if ($type eq 'default') {
14729: $typetitle = $othertitle;
14730: } elsif ($type eq '_LC_adv') {
14731: $typetitle = 'LON-CAPA Advanced Users';
14732: }
1.163 raeburn 14733: if ($inconf{$type}) {
1.101 raeburn 14734: if ($context eq 'requestcourses') {
14735: my $cond;
1.163 raeburn 14736: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14737: if ($1 eq '') {
14738: $cond = &mt('(Automatic processing of any request).');
14739: } else {
14740: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14741: }
14742: } else {
1.163 raeburn 14743: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14744: }
14745: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14746: } elsif ($context eq 'requestauthor') {
14747: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14748: $titles{$inconf{$type}},$typetitle);
14749:
1.101 raeburn 14750: } else {
14751: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14752: }
1.72 raeburn 14753: } else {
1.104 raeburn 14754: if ($type eq '_LC_adv') {
1.163 raeburn 14755: if ($inconf{$type} eq '0') {
1.104 raeburn 14756: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14757: } else {
14758: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14759: }
14760: } else {
14761: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14762: }
1.72 raeburn 14763: }
14764: }
1.26 raeburn 14765: }
1.163 raeburn 14766: unless ($context eq 'requestauthor') {
14767: $resulttext .= '</ul></li>';
14768: }
1.26 raeburn 14769: }
1.1 raeburn 14770: }
1.163 raeburn 14771: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14772: if (ref($changes{'notify'}) eq 'HASH') {
14773: if ($changes{'notify'}{'approval'}) {
14774: if (ref($confhash{'notify'}) eq 'HASH') {
14775: if ($confhash{'notify'}{'approval'}) {
14776: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14777: } else {
1.163 raeburn 14778: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14779: }
14780: }
14781: }
14782: }
14783: }
1.216 raeburn 14784: if ($action eq 'requestcourses') {
14785: my @offon = ('off','on');
14786: if ($changes{'uniquecode'}) {
1.218 raeburn 14787: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14788: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14789: $resulttext .= '<li>'.
14790: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14791: '</li>';
14792: } else {
14793: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14794: '</li>';
14795: }
1.216 raeburn 14796: }
1.242 raeburn 14797: foreach my $type ('textbooks','templates') {
14798: if (ref($changes{$type}) eq 'HASH') {
14799: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14800: foreach my $key (sort(keys(%{$changes{$type}}))) {
14801: my %coursehash = &Apache::lonnet::coursedescription($key);
14802: my $coursetitle = $coursehash{'description'};
14803: my $position = $confhash{$type}{$key}{'order'} + 1;
14804: $resulttext .= '<li>';
1.243 raeburn 14805: foreach my $item ('subject','title','publisher','author') {
14806: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14807: ($type eq 'templates'));
1.242 raeburn 14808: my $name = $item.':';
14809: $name =~ s/^(\w)/\U$1/;
14810: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14811: }
14812: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14813: if ($type eq 'textbooks') {
14814: if ($confhash{$type}{$key}{'image'}) {
14815: $resulttext .= ' '.&mt('Image: [_1]',
14816: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14817: ' alt="Textbook cover" />').'<br />';
14818: }
14819: }
14820: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14821: }
1.242 raeburn 14822: $resulttext .= '</ul></li>';
1.216 raeburn 14823: }
14824: }
1.235 raeburn 14825: if (ref($changes{'validation'}) eq 'HASH') {
14826: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14827: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14828: foreach my $item (@{$validationitemsref}) {
14829: if (exists($changes{'validation'}{$item})) {
14830: if ($item eq 'markup') {
14831: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14832: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14833: } else {
14834: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14835: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14836: }
14837: }
14838: }
14839: if (exists($changes{'validation'}{'dc'})) {
14840: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14841: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14842: }
1.442 raeburn 14843: $resulttext .= '</ul></li>';
1.235 raeburn 14844: }
14845: }
1.216 raeburn 14846: }
1.1 raeburn 14847: $resulttext .= '</ul>';
1.80 raeburn 14848: if (keys(%newenv)) {
14849: &Apache::lonnet::appenv(\%newenv);
14850: }
1.1 raeburn 14851: } else {
1.86 raeburn 14852: if ($context eq 'requestcourses') {
14853: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14854: } elsif ($context eq 'requestauthor') {
14855: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14856: } else {
1.90 weissno 14857: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14858: }
1.1 raeburn 14859: }
14860: } else {
1.11 albertel 14861: $resulttext = '<span class="LC_error">'.
14862: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14863: }
1.216 raeburn 14864: if ($errors) {
14865: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14866: '<ul>'.$errors.'</ul></p>';
14867: }
1.3 raeburn 14868: return $resulttext;
1.1 raeburn 14869: }
14870:
1.216 raeburn 14871: sub process_textbook_image {
1.242 raeburn 14872: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14873: my $filename = $env{'form.'.$caller.'.filename'};
14874: my ($error,$url);
14875: my ($width,$height) = (50,50);
14876: if ($configuserok eq 'ok') {
14877: if ($switchserver) {
14878: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14879: $switchserver);
14880: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14881: my $modified = [];
1.216 raeburn 14882: my ($result,$imageurl) =
1.421 raeburn 14883: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14884: "$type/$cdom/$cnum/cover",$width,$height,
14885: '',$modified);
1.216 raeburn 14886: if ($result eq 'ok') {
14887: $url = $imageurl;
1.421 raeburn 14888: &update_modify_urls($r,$modified);
1.216 raeburn 14889: } else {
14890: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14891: }
14892: } else {
14893: $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);
14894: }
14895: } else {
14896: $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);
14897: }
14898: return ($url,$error);
14899: }
14900:
1.267 raeburn 14901: sub modify_ltitools {
14902: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14903: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14904: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14905:
1.267 raeburn 14906: my $confname = $dom.'-domainconfig';
14907: my $servadm = $r->dir_config('lonAdmEMail');
14908: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14909:
14910: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14911: my $toolserror =
14912: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14913: $lastactref,$configuserok,$switchserver,$author_ok);
14914:
14915: my $home = &Apache::lonnet::domain($dom,'primary');
14916: unless (($home eq 'no_host') || ($home eq '')) {
14917: my @ids=&Apache::lonnet::current_machine_ids();
14918: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14919: }
14920:
14921: if (keys(%ltitoolschg)) {
14922: foreach my $id (keys(%ltitoolschg)) {
14923: if (ref($ltitoolschg{$id}) eq 'HASH') {
14924: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14925: if (($inner eq 'secret') || ($inner eq 'key')) {
14926: if ($is_home) {
14927: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14928: }
14929: }
14930: }
1.267 raeburn 14931: }
1.421 raeburn 14932: }
14933: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14934: if (keys(%ltitoolschg)) {
14935: %newltitools = %ltitoolschg;
14936: }
14937: }
14938: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14939: foreach my $id (%{$domconfig{'ltitools'}}) {
14940: next if ($id !~ /^\d+$/);
14941: unless (exists($ltitoolschg{$id})) {
14942: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14943: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14944: if (($inner eq 'secret') || ($inner eq 'key')) {
14945: if ($is_home) {
14946: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14947: }
14948: } else {
14949: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14950: }
14951: }
14952: } else {
14953: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14954: }
1.421 raeburn 14955: }
14956: }
14957: }
14958: if ($toolserror) {
14959: $errors = '<li>'.$toolserror.'</li>';
14960: }
14961: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14962: $resulttext = &mt('No changes made.');
14963: if ($errors) {
14964: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14965: $errors.'</ul>';
14966: }
14967: return $resulttext;
14968: }
14969: my %ltitoolshash = (
14970: $action => { %newltitools }
14971: );
14972: if (keys(%secchanges)) {
14973: $ltitoolshash{'toolsec'} = \%newtoolsec;
14974: }
14975: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14976: if ($putresult eq 'ok') {
14977: my %keystore;
14978: if ($is_home) {
14979: my %toolsenchash = (
14980: $action => { %newtoolsenc }
14981: );
14982: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 14983: my $cachetime = 24*60*60;
14984: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 14985: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
14986: }
14987: $resulttext = &mt('Changes made:').'<ul>';
14988: if (keys(%secchanges) > 0) {
1.423 raeburn 14989: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 14990: }
14991: if (keys(%ltitoolschg) > 0) {
14992: $resulttext .= $ltitoolsoutput;
14993: }
1.423 raeburn 14994: my $cachetime = 24*60*60;
14995: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
14996: if (ref($lastactref) eq 'HASH') {
14997: $lastactref->{'ltitools'} = 1;
14998: }
1.421 raeburn 14999: } else {
15000: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15001: }
15002: if ($errors) {
15003: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
15004: $errors.'</ul></p>';
15005: }
15006: return $resulttext;
15007: }
15008:
15009: sub fetch_secrets {
15010: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
15011: my %keyset;
15012: %{$currsec} = ();
15013: $newsec->{'private'}{'keys'} = [];
15014: $newsec->{'encrypt'} = {};
15015: $newsec->{'rules'} = {};
15016: if ($context eq 'ltisec') {
15017: $newsec->{'linkprot'} = {};
15018: }
15019: if (ref($domconfig->{$context}) eq 'HASH') {
15020: %{$currsec} = %{$domconfig->{$context}};
15021: if ($context eq 'ltisec') {
15022: if (ref($currsec->{'linkprot'}) eq 'HASH') {
15023: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
15024: unless ($id =~ /^\d+$/) {
15025: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 15026: }
1.267 raeburn 15027: }
15028: }
1.421 raeburn 15029: }
15030: if (ref($currsec->{'private'}) eq 'HASH') {
15031: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
15032: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
15033: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 15034: }
1.421 raeburn 15035: }
15036: }
15037: my @items= ('crs','dom');
15038: if ($context eq 'ltisec') {
15039: push(@items,'consumers');
15040: }
15041: foreach my $item (@items) {
15042: my $formelement;
15043: if (($context eq 'toolsec') || ($item eq 'consumers')) {
15044: $formelement = 'form.'.$context.'_'.$item;
15045: } else {
15046: $formelement = 'form.'.$context.'_'.$item.'linkprot';
15047: }
15048: if ($env{$formelement}) {
15049: $newsec->{'encrypt'}{$item} = 1;
15050: if (ref($currsec->{'encrypt'}) eq 'HASH') {
15051: unless ($currsec->{'encrypt'}{$item}) {
15052: $secchanges->{'encrypt'} = 1;
15053: }
15054: } else {
15055: $secchanges->{'encrypt'} = 1;
1.267 raeburn 15056: }
1.421 raeburn 15057: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
15058: if ($currsec->{'encrypt'}{$item}) {
15059: $secchanges->{'encrypt'} = 1;
1.323 raeburn 15060: }
1.421 raeburn 15061: }
15062: }
15063: my $secrets;
15064: if ($context eq 'ltisec') {
15065: $secrets = 'ltisecrets';
15066: } else {
15067: $secrets = 'toolsecrets';
15068: }
15069: unless (exists($currsec->{'rules'})) {
15070: $currsec->{'rules'} = {};
15071: }
15072: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
15073:
15074: my @ids=&Apache::lonnet::current_machine_ids();
15075: my %servers = &Apache::lonnet::get_servers($dom,'library');
15076:
15077: foreach my $hostid (keys(%servers)) {
15078: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
15079: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
15080: if (exists($env{$keyitem})) {
15081: $env{$keyitem} =~ s/(`)/'/g;
15082: if ($keyset{$hostid}) {
15083: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
15084: if ($env{$keyitem} ne '') {
15085: $secchanges->{'private'} = 1;
15086: $newkeyset->{$hostid} = $env{$keyitem};
15087: }
1.296 raeburn 15088: }
1.421 raeburn 15089: } elsif ($env{$keyitem} ne '') {
15090: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
15091: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 15092: }
1.421 raeburn 15093: $secchanges->{'private'} = 1;
15094: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 15095: }
15096: }
1.421 raeburn 15097: }
15098: }
15099: }
15100:
15101: sub store_security {
1.424 raeburn 15102: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 15103: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
15104: (ref($keystore) eq 'HASH'));
15105: if (keys(%{$secchanges})) {
15106: if ($secchanges->{'private'}) {
15107: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
15108: foreach my $hostid (keys(%{$newkeyset})) {
15109: my $storehash = {
15110: key => $newkeyset->{$hostid},
15111: who => $env{'user.name'}.':'.$env{'user.domain'},
15112: };
15113: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
15114: $dom,$hostid);
15115: }
15116: }
15117: }
15118: }
15119:
15120: sub lti_security_results {
1.423 raeburn 15121: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 15122: my $output;
1.423 raeburn 15123: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15124: my $needs_update;
1.421 raeburn 15125: foreach my $item (keys(%{$secchanges})) {
15126: if ($item eq 'encrypt') {
1.423 raeburn 15127: $needs_update = 1;
1.421 raeburn 15128: my %encrypted;
15129: if ($context eq 'lti') {
15130: %encrypted = (
15131: crs => {
15132: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
15133: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
15134: },
15135: dom => {
15136: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
15137: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
15138: },
15139: consumers => {
15140: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
15141: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
15142: },
15143: );
1.267 raeburn 15144: } else {
1.421 raeburn 15145: %encrypted = (
15146: crs => {
15147: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
15148: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
15149: },
15150: dom => {
15151: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
15152: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
15153: },
15154: );
15155: }
15156: my @types= ('crs','dom');
15157: if ($context eq 'lti') {
1.423 raeburn 15158: foreach my $type (@types) {
15159: undef($domdefaults{'linkprotenc_'.$type});
15160: }
1.421 raeburn 15161: push(@types,'consumers');
1.423 raeburn 15162: undef($domdefaults{'ltienc_consumers'});
15163: } elsif ($context eq 'ltitools') {
15164: foreach my $type (@types) {
15165: undef($domdefaults{'toolenc_'.$type});
15166: }
1.267 raeburn 15167: }
1.421 raeburn 15168: foreach my $type (@types) {
15169: my $shown = $encrypted{$type}{'off'};
15170: if (ref($newsec->{$item}) eq 'HASH') {
15171: if ($newsec->{$item}{$type}) {
1.423 raeburn 15172: if ($context eq 'lti') {
15173: if ($type eq 'consumers') {
15174: $domdefaults{'ltienc_consumers'} = 1;
15175: } else {
15176: $domdefaults{'linkprotenc_'.$type} = 1;
15177: }
15178: } elsif ($context eq 'ltitools') {
15179: $domdefaults{'toolenc_'.$type} = 1;
15180: }
1.421 raeburn 15181: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15182: }
1.267 raeburn 15183: }
1.421 raeburn 15184: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15185: }
1.421 raeburn 15186: } elsif ($item eq 'rules') {
15187: my %titles = &Apache::lonlocal::texthash(
15188: min => 'Minimum password length',
15189: max => 'Maximum password length',
15190: chars => 'Required characters',
15191: );
15192: foreach my $rule ('min','max') {
15193: if ($newsec->{rules}{$rule} eq '') {
15194: if ($rule eq 'min') {
15195: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15196: ' '.&mt('Default of [_1] will be used',
15197: $Apache::lonnet::passwdmin).'</li>';
15198: } else {
15199: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15200: }
15201: } else {
15202: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15203: }
15204: }
15205: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15206: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15207: my %rulenames = &Apache::lonlocal::texthash(
15208: uc => 'At least one upper case letter',
15209: lc => 'At least one lower case letter',
15210: num => 'At least one number',
15211: spec => 'At least one non-alphanumeric',
15212: );
15213: my $needed = '<ul><li>'.
15214: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15215: '</li></ul>';
15216: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15217: } else {
15218: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15219: }
1.421 raeburn 15220: } else {
15221: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15222: }
1.421 raeburn 15223: } elsif ($item eq 'private') {
1.423 raeburn 15224: $needs_update = 1;
15225: if ($context eq 'lti') {
15226: undef($domdefaults{'ltiprivhosts'});
15227: } elsif ($context eq 'ltitools') {
15228: undef($domdefaults{'toolprivhosts'});
15229: }
1.421 raeburn 15230: if (keys(%{$newkeyset})) {
1.423 raeburn 15231: my @privhosts;
1.421 raeburn 15232: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15233: if ($keystore->{$hostid} eq 'ok') {
15234: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15235: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15236: push(@privhosts,$hostid);
15237: }
15238: }
15239: }
15240: if (@privhosts) {
15241: if ($context eq 'lti') {
15242: $domdefaults{'ltiprivhosts'} = \@privhosts;
15243: } elsif ($context eq 'ltitools') {
15244: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15245: }
15246: }
15247: }
1.421 raeburn 15248: } elsif ($item eq 'linkprot') {
15249: next;
1.434 raeburn 15250: } elsif ($item eq 'suggested') {
15251: if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
15252: (ref($newsec->{'suggested'}) eq 'HASH')) {
15253: my $suggestions;
15254: foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
15255: if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
15256: my $name = $newsec->{'suggested'}->{$id}->{'name'};
15257: my $info = $newsec->{'suggested'}->{$id}->{'info'};
15258: $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
15259: &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
15260: '</li>';
15261: } else {
15262: $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
15263: $newsec->{'suggested'}->{$id}).'</li>';
15264: }
15265: }
15266: if ($suggestions) {
15267: $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
15268: '<ul>'.$suggestions.'</ul>'.
15269: '</li>';
15270: }
15271: }
1.267 raeburn 15272: }
15273: }
1.423 raeburn 15274: if ($needs_update) {
15275: my $cachetime = 24*60*60;
15276: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15277: }
1.421 raeburn 15278: return $output;
15279: }
15280:
15281: sub modify_proctoring {
15282: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15283: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15284: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15285: my $confname = $dom.'-domainconfig';
15286: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15287: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15288: my %providernames = &proctoring_providernames();
15289: my $maxnum = scalar(keys(%providernames));
15290:
15291: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15292: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15293: if (ref($requref) eq 'HASH') {
15294: %requserfields = %{$requref};
15295: }
15296: if (ref($opturef) eq 'HASH') {
15297: %optuserfields = %{$opturef};
15298: }
15299: if (ref($defref) eq 'HASH') {
15300: %defaults = %{$defref};
15301: }
15302: if (ref($extref) eq 'HASH') {
15303: %extended = %{$extref};
15304: }
15305: if (ref($crsref) eq 'HASH') {
15306: %crsconf = %{$crsref};
15307: }
15308: if (ref($rolesref) eq 'ARRAY') {
15309: @courseroles = @{$rolesref};
15310: }
15311: if (ref($ltiref) eq 'ARRAY') {
15312: @ltiroles = @{$ltiref};
15313: }
15314:
15315: if (ref($domconfig{$action}) eq 'HASH') {
15316: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15317: if (@todeleteimages) {
15318: map { $imgdeletions{$_} = 1; } @todeleteimages;
15319: }
15320: }
15321: my %customadds;
15322: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15323: if (@newcustom) {
15324: map { $customadds{$_} = 1; } @newcustom;
15325: }
15326: foreach my $provider (sort(keys(%providernames))) {
15327: $confhash{$provider} = {};
15328: my $pos = $env{'form.proctoring_pos_'.$provider};
15329: $pos =~ s/\D+//g;
15330: $allpos[$pos] = $provider;
15331: my (%current,%currentenc);
15332: my $showroles = 0;
15333: if (ref($domconfig{$action}) eq 'HASH') {
15334: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15335: %current = %{$domconfig{$action}{$provider}};
15336: foreach my $item ('key','secret') {
15337: $currentenc{$item} = $current{$item};
15338: delete($current{$item});
15339: }
15340: }
15341: }
15342: if ($env{'form.proctoring_available_'.$provider}) {
15343: $confhash{$provider}{'available'} = 1;
15344: unless ($current{'available'}) {
15345: $changes{$provider} = 1;
15346: }
15347: } else {
15348: %{$confhash{$provider}} = %current;
15349: %{$encconfhash{$provider}} = %currentenc;
15350: $confhash{$provider}{'available'} = 0;
15351: if ($current{'available'}) {
15352: $changes{$provider} = 1;
15353: }
15354: }
15355: if ($confhash{$provider}{'available'}) {
15356: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15357: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15358: if ($field eq 'lifetime') {
15359: if ($possval =~ /^\d+$/) {
15360: $confhash{$provider}{$field} = $possval;
15361: }
15362: } elsif ($field eq 'version') {
15363: if ($possval =~ /^\d+\.\d+$/) {
15364: $confhash{$provider}{$field} = $possval;
15365: }
15366: } elsif ($field eq 'sigmethod') {
15367: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15368: $confhash{$provider}{$field} = $possval;
15369: }
15370: } elsif ($field eq 'url') {
15371: $confhash{$provider}{$field} = $possval;
15372: } elsif (($field eq 'key') || ($field eq 'secret')) {
15373: $encconfhash{$provider}{$field} = $possval;
15374: unless ($currentenc{$field} eq $possval) {
15375: $changes{$provider} = 1;
15376: }
15377: }
15378: unless (($field eq 'key') || ($field eq 'secret')) {
15379: unless ($current{$field} eq $confhash{$provider}{$field}) {
15380: $changes{$provider} = 1;
15381: }
15382: }
15383: }
15384: if ($imgdeletions{$provider}) {
15385: $changes{$provider} = 1;
15386: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15387: my ($imageurl,$error) =
15388: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15389: $configuserok,$switchserver,$author_ok);
15390: if ($imageurl) {
15391: $confhash{$provider}{'image'} = $imageurl;
15392: $changes{$provider} = 1;
15393: }
15394: if ($error) {
15395: &Apache::lonnet::logthis($error);
15396: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15397: }
15398: } elsif (exists($current{'image'})) {
15399: $confhash{$provider}{'image'} = $current{'image'};
15400: }
15401: if (ref($requserfields{$provider}) eq 'ARRAY') {
15402: if (@{$requserfields{$provider}} > 0) {
15403: if (grep(/^user$/,@{$requserfields{$provider}})) {
15404: if ($env{'form.proctoring_userincdom_'.$provider}) {
15405: $confhash{$provider}{'incdom'} = 1;
15406: }
15407: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15408: $changes{$provider} = 1;
15409: }
15410: }
15411: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15412: $showroles = 1;
15413: }
15414: }
15415: }
15416: $confhash{$provider}{'fields'} = [];
15417: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15418: if (@{$optuserfields{$provider}} > 0) {
15419: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15420: foreach my $field (@{$optuserfields{$provider}}) {
15421: if (grep(/^\Q$field\E$/,@optfields)) {
15422: push(@{$confhash{$provider}{'fields'}},$field);
15423: }
15424: }
15425: }
15426: if (ref($current{'fields'}) eq 'ARRAY') {
15427: unless ($changes{$provider}) {
15428: my @new = sort(@{$confhash{$provider}{'fields'}});
15429: my @old = sort(@{$current{'fields'}});
15430: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15431: if (@diffs) {
15432: $changes{$provider} = 1;
15433: }
15434: }
15435: } elsif (@{$confhash{$provider}{'fields'}}) {
15436: $changes{$provider} = 1;
15437: }
15438: }
15439: if (ref($defaults{$provider}) eq 'ARRAY') {
15440: if (@{$defaults{$provider}} > 0) {
15441: my %options;
15442: if (ref($extended{$provider}) eq 'HASH') {
15443: %options = %{$extended{$provider}};
15444: }
15445: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15446: foreach my $field (@{$defaults{$provider}}) {
15447: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15448: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15449: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15450: push(@{$confhash{$provider}{'defaults'}},$poss);
15451: }
15452: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15453: foreach my $inner (keys(%{$options{$field}})) {
15454: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15455: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15456: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15457: $confhash{$provider}{'defaults'}{$inner} = $poss;
15458: }
15459: } else {
15460: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15461: }
15462: }
15463: } else {
15464: if (grep(/^\Q$field\E$/,@checked)) {
15465: push(@{$confhash{$provider}{'defaults'}},$field);
15466: }
15467: }
15468: }
15469: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15470: if (ref($current{'defaults'}) eq 'ARRAY') {
15471: unless ($changes{$provider}) {
15472: my @new = sort(@{$confhash{$provider}{'defaults'}});
15473: my @old = sort(@{$current{'defaults'}});
15474: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15475: if (@diffs) {
15476: $changes{$provider} = 1;
15477: }
15478: }
15479: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15480: if (@{$current{'defaults'}}) {
15481: $changes{$provider} = 1;
15482: }
15483: }
15484: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15485: if (ref($current{'defaults'}) eq 'HASH') {
15486: unless ($changes{$provider}) {
15487: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15488: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15489: $changes{$provider} = 1;
15490: last;
15491: }
15492: }
15493: }
15494: unless ($changes{$provider}) {
15495: foreach my $key (keys(%{$current{'defaults'}})) {
15496: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15497: $changes{$provider} = 1;
15498: last;
15499: }
15500: }
15501: }
15502: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15503: $changes{$provider} = 1;
15504: }
15505: }
15506: }
15507: }
15508: if (ref($crsconf{$provider}) eq 'ARRAY') {
15509: if (@{$crsconf{$provider}} > 0) {
15510: $confhash{$provider}{'crsconf'} = [];
15511: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15512: foreach my $crsfield (@{$crsconf{$provider}}) {
15513: if (grep(/^\Q$crsfield\E$/,@checked)) {
15514: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15515: }
15516: }
15517: if (ref($current{'crsconf'}) eq 'ARRAY') {
15518: unless ($changes{$provider}) {
15519: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15520: my @old = sort(@{$current{'crsconf'}});
15521: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15522: if (@diffs) {
15523: $changes{$provider} = 1;
15524: }
15525: }
15526: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15527: $changes{$provider} = 1;
15528: }
15529: }
15530: }
15531: if ($showroles) {
15532: $confhash{$provider}{'roles'} = {};
15533: foreach my $role (@courseroles) {
15534: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15535: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15536: $confhash{$provider}{'roles'}{$role} = $poss;
15537: }
15538: }
15539: unless ($changes{$provider}) {
15540: if (ref($current{'roles'}) eq 'HASH') {
15541: foreach my $role (keys(%{$current{'roles'}})) {
15542: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15543: $changes{$provider} = 1;
15544: last
15545: }
15546: }
15547: unless ($changes{$provider}) {
15548: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15549: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15550: $changes{$provider} = 1;
15551: last;
15552: }
15553: }
15554: }
15555: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15556: $changes{$provider} = 1;
15557: }
15558: }
15559: }
15560: if (ref($current{'custom'}) eq 'HASH') {
15561: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15562: foreach my $key (keys(%{$current{'custom'}})) {
15563: if (grep(/^\Q$key\E$/,@customdels)) {
15564: $changes{$provider} = 1;
15565: } else {
15566: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15567: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15568: $changes{$provider} = 1;
15569: }
15570: }
15571: }
15572: }
15573: if ($customadds{$provider}) {
15574: my $name = $env{'form.proctoring_custom_name_'.$provider};
15575: $name =~ s/(`)/'/g;
15576: $name =~ s/^\s+//;
15577: $name =~ s/\s+$//;
15578: my $value = $env{'form.proctoring_custom_value_'.$provider};
15579: $value =~ s/(`)/'/g;
15580: $value =~ s/^\s+//;
15581: $value =~ s/\s+$//;
15582: if ($name ne '') {
15583: $confhash{$provider}{'custom'}{$name} = $value;
15584: $changes{$provider} = 1;
15585: }
15586: }
15587: }
15588: }
15589: if (@allpos > 0) {
15590: my $idx = 0;
15591: foreach my $provider (@allpos) {
15592: if ($provider ne '') {
15593: $confhash{$provider}{'order'} = $idx;
15594: unless ($changes{$provider}) {
15595: if (ref($domconfig{$action}) eq 'HASH') {
15596: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15597: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15598: $changes{$provider} = 1;
15599: }
15600: }
15601: }
15602: }
15603: $idx ++;
15604: }
15605: }
15606: }
15607: my %proc_hash = (
15608: $action => { %confhash }
15609: );
15610: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15611: $dom);
15612: if ($putresult eq 'ok') {
15613: my %proc_enchash = (
15614: $action => { %encconfhash }
15615: );
1.384 raeburn 15616: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15617: if (keys(%changes) > 0) {
15618: my $cachetime = 24*60*60;
15619: my %procall = %confhash;
15620: foreach my $provider (keys(%procall)) {
15621: if (ref($encconfhash{$provider}) eq 'HASH') {
15622: foreach my $key ('key','secret') {
15623: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15624: }
15625: }
15626: }
15627: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15628: if (ref($lastactref) eq 'HASH') {
15629: $lastactref->{'proctoring'} = 1;
15630: }
15631: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15632: my %bynum;
15633: foreach my $provider (sort(keys(%changes))) {
15634: my $position = $confhash{$provider}{'order'};
15635: $bynum{$position} = $provider;
15636: }
15637: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15638: my $provider = $bynum{$pos};
15639: my %lt = &proctoring_titles($provider);
15640: my %fieldtitles = &proctoring_fieldtitles($provider);
15641: if (!$confhash{$provider}{'available'}) {
15642: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15643: } else {
15644: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15645: if ($confhash{$provider}{'image'}) {
15646: $resulttext .= ' '.
15647: '<img src="'.$confhash{$provider}{'image'}.'"'.
15648: ' alt="'.&mt('Proctoring icon').'" />';
15649: }
15650: $resulttext .= '<ul>';
15651: my $position = $pos + 1;
15652: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15653: foreach my $key ('version','sigmethod','url','lifetime') {
15654: if ($confhash{$provider}{$key} ne '') {
15655: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15656: }
15657: }
15658: if ($encconfhash{$provider}{'key'} ne '') {
15659: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15660: }
15661: if ($encconfhash{$provider}{'secret'} ne '') {
15662: $resulttext .= '<li>'.$lt{'secret'}.': ';
15663: my $num = length($encconfhash{$provider}{'secret'});
15664: $resulttext .= ('*'x$num).'</li>';
15665: }
15666: my (@fields,$showroles);
15667: if (ref($requserfields{$provider}) eq 'ARRAY') {
15668: push(@fields,@{$requserfields{$provider}});
15669: }
15670: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15671: push(@fields,@{$confhash{$provider}{'fields'}});
15672: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15673: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15674: }
15675: if (@fields) {
15676: if (grep(/^roles$/,@fields)) {
15677: $showroles = 1;
15678: }
15679: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15680: join('", "', map { $lt{$_}; } @fields).'"</li>';
15681: }
15682: if (ref($requserfields{$provider}) eq 'ARRAY') {
15683: if (grep(/^user$/,@{$requserfields{$provider}})) {
15684: if ($confhash{$provider}{'incdom'}) {
15685: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15686: } else {
15687: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15688: }
15689: }
15690: }
15691: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15692: if (@{$confhash{$provider}{'defaults'}} > 0) {
15693: $resulttext .= '<li>'.$lt{'defa'};
15694: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15695: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15696: }
15697: $resulttext =~ s/,$//;
15698: $resulttext .= '</li>';
15699: }
15700: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15701: if (keys(%{$confhash{$provider}{'defaults'}})) {
15702: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15703: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15704: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15705: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15706: }
15707: }
15708: $resulttext .= '</ul></li>';
15709: }
15710: }
15711: if (ref($crsconf{$provider}) eq 'ARRAY') {
15712: if (@{$crsconf{$provider}} > 0) {
15713: $resulttext .= '<li>'.&mt('Configurable in course:');
15714: my $numconfig = 0;
15715: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15716: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15717: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15718: $numconfig ++;
15719: if ($provider eq 'examity') {
15720: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15721: } else {
15722: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15723: }
15724: }
15725: $resulttext =~ s/,$//;
15726: }
15727: }
15728: if (!$numconfig) {
15729: $resulttext .= ' '.&mt('None');
15730: }
15731: $resulttext .= '</li>';
15732: }
15733: }
15734: if ($showroles) {
15735: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15736: my $rolemaps;
15737: foreach my $role (@courseroles) {
15738: if ($confhash{$provider}{'roles'}{$role}) {
15739: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15740: $confhash{$provider}{'roles'}{$role}.',';
15741: }
15742: }
15743: if ($rolemaps) {
15744: $rolemaps =~ s/,$//;
15745: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15746: }
15747: }
15748: }
15749: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15750: my $customlist;
15751: if (keys(%{$confhash{$provider}{'custom'}})) {
15752: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15753: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15754: }
15755: $customlist =~ s/,$//;
15756: }
15757: if ($customlist) {
15758: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15759: }
15760: }
15761: $resulttext .= '</ul></li>';
15762: }
15763: }
15764: $resulttext .= '</ul>';
15765: } else {
15766: $resulttext = &mt('No changes made.');
15767: }
15768: } else {
15769: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15770: }
15771: if ($errors) {
15772: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15773: $errors.'</ul>';
15774: }
15775: return $resulttext;
15776: }
15777:
15778: sub process_proctoring_image {
15779: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15780: my $filename = $env{'form.'.$caller.'.filename'};
15781: my ($error,$url);
15782: my ($width,$height) = (21,21);
15783: if ($configuserok eq 'ok') {
15784: if ($switchserver) {
15785: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15786: $switchserver);
15787: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15788: my $modified = [];
1.372 raeburn 15789: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15790: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15791: "proctoring/$provider/icon",$width,$height,
15792: '',$modified);
1.372 raeburn 15793: if ($result eq 'ok') {
15794: if ($madethumb) {
15795: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15796: my $imagethumb = "$path/tn-".$imagefile;
15797: $url = $imagethumb;
15798: } else {
15799: $url = $imageurl;
15800: }
1.421 raeburn 15801: &update_modify_urls($r,$modified);
1.372 raeburn 15802: } else {
15803: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15804: }
15805: } else {
15806: $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);
15807: }
15808: } else {
15809: $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);
15810: }
15811: return ($url,$error);
15812: }
15813:
1.320 raeburn 15814: sub modify_lti {
15815: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15816: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15817: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15818: my (%posslti,%posslticrs,%posscrstype);
15819: my @courseroles = ('cc','in','ta','ep','st');
15820: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15821: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15822: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15823: my %coursetypetitles = &Apache::lonlocal::texthash (
15824: official => 'Official',
15825: unofficial => 'Unofficial',
15826: community => 'Community',
15827: textbook => 'Textbook',
15828: placement => 'Placement Test',
1.392 raeburn 15829: lti => 'LTI Provider',
1.320 raeburn 15830: );
1.325 raeburn 15831: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15832: my %lt = <i_names();
15833: map { $posslti{$_} = 1; } @ltiroles;
15834: map { $posslticrs{$_} = 1; } @lticourseroles;
15835: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15836:
1.326 raeburn 15837: my %menutitles = <imenu_titles();
1.421 raeburn 15838: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15839:
1.421 raeburn 15840: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15841:
1.406 raeburn 15842: my (%linkprotchg,$linkprotoutput,$is_home);
15843: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15844: \%linkprotchg,'domain');
15845: my $home = &Apache::lonnet::domain($dom,'primary');
15846: unless (($home eq 'no_host') || ($home eq '')) {
15847: my @ids=&Apache::lonnet::current_machine_ids();
15848: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15849: }
15850:
15851: if (keys(%linkprotchg)) {
15852: $secchanges{'linkprot'} = 1;
15853: my %oldlinkprot;
15854: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15855: %oldlinkprot = %{$currltisec{'linkprot'}};
15856: }
15857: foreach my $id (keys(%linkprotchg)) {
15858: if (ref($linkprotchg{$id}) eq 'HASH') {
15859: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15860: if (($inner eq 'secret') || ($inner eq 'key')) {
15861: if ($is_home) {
15862: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15863: }
15864: }
15865: }
15866: } else {
15867: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15868: }
15869: }
15870: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15871: if (keys(%linkprotchg)) {
15872: %{$newltisec{'linkprot'}} = %linkprotchg;
15873: }
15874: }
15875: if (ref($currltisec{'linkprot'}) eq 'HASH') {
1.434 raeburn 15876: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
1.406 raeburn 15877: next if ($id !~ /^\d+$/);
15878: unless (exists($linkprotchg{$id})) {
15879: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15880: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15881: if (($inner eq 'secret') || ($inner eq 'key')) {
15882: if ($is_home) {
15883: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15884: }
15885: } else {
15886: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15887: }
15888: }
15889: } else {
15890: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15891: }
15892: }
15893: }
15894: }
15895: if ($proterror) {
15896: $errors .= '<li>'.$proterror.'</li>';
15897: }
1.434 raeburn 15898:
15899: my (%delsuggested,%suggids,@suggested);;
15900: if (ref($currltisec{'suggested'}) eq 'HASH') {
15901: my $maxnum = $env{'form.linkprot_suggested_maxnum'};
15902: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
15903: for (my $i=0; $i<$maxnum; $i++) {
15904: my $itemid = $env{'form.linkprot_suggested_id_'.$i};
15905: $itemid =~ s/\D+//g;
15906: if ($itemid) {
15907: if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
15908: push(@suggested,$i);
15909: $suggids{$i} = $itemid;
15910: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
15911: if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
15912: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15913: }
15914: } else {
15915: if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
15916: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15917: } else {
15918: $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
15919: $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
15920: $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
15921: $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
15922: if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
15923: ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
15924: $secchanges{'suggested'}{$itemid} = 1;
15925: }
15926: }
15927: }
15928: }
15929: }
15930: }
15931: }
15932: foreach my $key (keys(%delsuggested)) {
15933: $newltisec{'suggested'}{$key} = $delsuggested{$key};
15934: $secchanges{'suggested'}{$key} = 1;
15935: }
15936: if (($env{'form.linkprot_suggested_add'}) &&
15937: ($env{'form.linkprot_suggested_name_add'} ne '')) {
15938: $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
15939: $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
15940: my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
15941: if ($newsuggid) {
15942: $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
15943: $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
15944: $secchanges{'suggested'}{$newsuggid} = 1;
15945: } else {
15946: my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
15947: if ($errormsg) {
15948: $error .= ' ('.$errormsg.')';
15949: }
15950: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15951: }
15952: }
1.320 raeburn 15953: my (@items,%deletions,%itemids);
15954: if ($env{'form.lti_add'}) {
15955: my $consumer = $env{'form.lti_consumer_add'};
15956: $consumer =~ s/(`)/'/g;
1.434 raeburn 15957: ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
1.320 raeburn 15958: if ($newid) {
15959: $itemids{'add'} = $newid;
15960: push(@items,'add');
15961: $changes{$newid} = 1;
15962: } else {
15963: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
1.434 raeburn 15964: if ($errormsg) {
15965: $error .= ' ('.$errormsg.')';
15966: }
1.320 raeburn 15967: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15968: }
15969: }
15970: if (ref($domconfig{$action}) eq 'HASH') {
15971: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15972: if (@todelete) {
15973: map { $deletions{$_} = 1; } @todelete;
15974: }
15975: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15976: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15977: my $itemid = $env{'form.lti_id_'.$i};
15978: $itemid =~ s/\D+//g;
15979: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15980: if ($deletions{$itemid}) {
15981: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15982: } else {
1.390 raeburn 15983: push(@items,$i);
15984: $itemids{$i} = $itemid;
1.320 raeburn 15985: }
15986: }
15987: }
15988: }
1.424 raeburn 15989: my (%keystore,$secstored);
15990: if ($is_home) {
15991: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
15992: }
15993:
15994: my ($cipher,$privnum);
15995: if ((@items > 0) && ($is_home)) {
15996: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
15997: $newltisec{'encrypt'},$keystore{$home});
15998: }
1.320 raeburn 15999: foreach my $idx (@items) {
16000: my $itemid = $itemids{$idx};
16001: next unless ($itemid);
1.424 raeburn 16002: my %currlti;
16003: unless ($idx eq 'add') {
16004: if (ref($domconfig{$action}) eq 'HASH') {
16005: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16006: %currlti = %{$domconfig{$action}{$itemid}};
16007: }
16008: }
16009: }
1.390 raeburn 16010: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 16011: $position =~ s/\D+//g;
16012: if ($position ne '') {
16013: $allpos[$position] = $itemid;
16014: }
1.424 raeburn 16015: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 16016: my $formitem = 'form.lti_'.$item.'_'.$idx;
16017: $env{$formitem} =~ s/(`)/'/g;
16018: if ($item eq 'lifetime') {
16019: $env{$formitem} =~ s/[^\d.]//g;
16020: }
16021: if ($env{$formitem} ne '') {
1.424 raeburn 16022: $confhash{$itemid}{$item} = $env{$formitem};
16023: unless (($idx eq 'add') || ($changes{$itemid})) {
16024: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
16025: $changes{$itemid} = 1;
1.320 raeburn 16026: }
16027: }
16028: }
16029: }
16030: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
16031: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
16032: }
1.345 raeburn 16033: if ($confhash{$itemid}{'requser'}) {
16034: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 16035: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 16036: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
16037: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
16038: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
16039: my $mapuser = $env{'form.lti_customuser_'.$idx};
16040: $mapuser =~ s/(`)/'/g;
1.405 raeburn 16041: $mapuser =~ s/^\s+|\s+$//g;
16042: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 16043: }
16044: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
16045: my @makeuser;
16046: foreach my $ltirole (sort(@possmakeuser)) {
16047: if ($posslti{$ltirole}) {
16048: push(@makeuser,$ltirole);
16049: }
16050: }
16051: $confhash{$itemid}{'makeuser'} = \@makeuser;
16052: if (@makeuser) {
16053: my $lcauth = $env{'form.lti_lcauth_'.$idx};
16054: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
16055: $confhash{$itemid}{'lcauth'} = $lcauth;
16056: if ($lcauth ne 'internal') {
16057: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
16058: $lcauthparm =~ s/^(\s+|\s+)$//g;
16059: $lcauthparm =~ s/`//g;
16060: if ($lcauthparm ne '') {
16061: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
16062: }
16063: }
16064: } else {
16065: $confhash{$itemid}{'lcauth'} = 'lti';
16066: }
1.320 raeburn 16067: }
1.345 raeburn 16068: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
16069: if (@possinstdata) {
1.447.2.2 raeburn 16070: foreach my $field (sort(@possinstdata)) {
1.345 raeburn 16071: if (exists($fieldtitles{$field})) {
1.447.2.2 raeburn 16072: push(@{$confhash{$itemid}{'instdata'}},$field);
1.325 raeburn 16073: }
16074: }
16075: }
1.363 raeburn 16076: if ($env{'form.lti_callback_'.$idx}) {
16077: if ($env{'form.lti_callbackparam_'.$idx}) {
16078: my $callback = $env{'form.lti_callbackparam_'.$idx};
16079: $callback =~ s/^\s+|\s+$//g;
16080: $confhash{$itemid}{'callback'} = $callback;
16081: }
16082: }
1.391 raeburn 16083: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 16084: if ($env{'form.lti_'.$field.'_'.$idx}) {
16085: $confhash{$itemid}{$field} = 1;
16086: }
1.320 raeburn 16087: }
1.345 raeburn 16088: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
16089: $confhash{$itemid}{lcmenu} = [];
16090: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
16091: foreach my $field (@possmenu) {
16092: if (exists($menutitles{$field})) {
16093: if ($field eq 'grades') {
16094: next unless ($env{'form.lti_inlinemenu_'.$idx});
16095: }
16096: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 16097: }
16098: }
16099: }
1.391 raeburn 16100: if ($confhash{$itemid}{'crsinc'}) {
16101: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
16102: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
16103: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
16104: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
16105: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
16106: $mapcrs =~ s/(`)/'/g;
16107: $mapcrs =~ s/^\s+|\s+$//g;
16108: $confhash{$itemid}{'mapcrs'} = $mapcrs;
16109: }
16110: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
16111: my @crstypes;
16112: foreach my $type (sort(@posstypes)) {
16113: if ($posscrstype{$type}) {
16114: push(@crstypes,$type);
16115: }
16116: }
16117: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 16118: if ($env{'form.lti_storecrs_'.$idx}) {
16119: $confhash{$itemid}{'storecrs'} = 1;
16120: }
1.391 raeburn 16121: if ($env{'form.lti_makecrs_'.$idx}) {
16122: $confhash{$itemid}{'makecrs'} = 1;
16123: }
16124: foreach my $ltirole (@lticourseroles) {
16125: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
16126: if (grep(/^\Q$possrole\E$/,@courseroles)) {
16127: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
16128: }
16129: }
16130: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
16131: my @selfenroll;
16132: foreach my $type (sort(@possenroll)) {
16133: if ($posslticrs{$type}) {
16134: push(@selfenroll,$type);
16135: }
16136: }
16137: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
16138: if ($env{'form.lti_crssec_'.$idx}) {
16139: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
16140: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
16141: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
16142: my $section = $env{'form.lti_customsection_'.$idx};
16143: $section =~ s/(`)/'/g;
16144: $section =~ s/^\s+|\s+$//g;
16145: if ($section ne '') {
16146: $confhash{$itemid}{'section'} = $section;
16147: }
16148: }
16149: }
16150: foreach my $field ('passback','roster') {
16151: if ($env{'form.lti_'.$field.'_'.$idx}) {
16152: $confhash{$itemid}{$field} = 1;
16153: }
16154: }
16155: if ($env{'form.lti_passback_'.$idx}) {
16156: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
16157: $confhash{$itemid}{'passbackformat'} = '1.0';
16158: } else {
16159: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 16160: }
16161: }
1.391 raeburn 16162: }
16163: unless (($idx eq 'add') || ($changes{$itemid})) {
16164: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 16165: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 16166: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 16167: $changes{$itemid} = 1;
16168: }
1.345 raeburn 16169: }
16170: unless ($changes{$itemid}) {
1.424 raeburn 16171: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
16172: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 16173: $changes{$itemid} = 1;
16174: }
16175: }
1.345 raeburn 16176: }
1.391 raeburn 16177: foreach my $field ('mapcrstype','selfenroll') {
16178: unless ($changes{$itemid}) {
1.424 raeburn 16179: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16180: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16181: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16182: $confhash{$itemid}{$field});
16183: if (@diffs) {
16184: $changes{$itemid} = 1;
16185: }
1.424 raeburn 16186: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16187: $changes{$itemid} = 1;
16188: }
16189: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16190: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 16191: $changes{$itemid} = 1;
16192: }
16193: }
1.391 raeburn 16194: }
16195: }
16196: unless ($changes{$itemid}) {
1.424 raeburn 16197: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 16198: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 16199: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
16200: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 16201: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 16202: $changes{$itemid} = 1;
16203: last;
16204: }
16205: }
1.391 raeburn 16206: unless ($changes{$itemid}) {
16207: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
16208: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 16209: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 16210: $changes{$itemid} = 1;
16211: last;
16212: }
16213: }
16214: }
1.424 raeburn 16215: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 16216: $changes{$itemid} = 1;
1.345 raeburn 16217: }
1.391 raeburn 16218: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16219: unless ($changes{$itemid}) {
16220: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16221: $changes{$itemid} = 1;
16222: }
16223: }
16224: }
16225: }
16226: }
16227: unless ($changes{$itemid}) {
16228: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 16229: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16230: $changes{$itemid} = 1;
1.320 raeburn 16231: }
1.391 raeburn 16232: }
16233: unless ($changes{$itemid}) {
1.447.2.2 raeburn 16234: foreach my $field ('makeuser','lcmenu','instdata') {
1.424 raeburn 16235: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16236: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16237: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16238: $confhash{$itemid}{$field});
16239: if (@diffs) {
16240: $changes{$itemid} = 1;
16241: }
1.424 raeburn 16242: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16243: $changes{$itemid} = 1;
16244: }
16245: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16246: if (@{$confhash{$itemid}{$field}} > 0) {
16247: $changes{$itemid} = 1;
16248: }
1.345 raeburn 16249: }
1.320 raeburn 16250: }
16251: }
16252: }
16253: }
16254: }
1.424 raeburn 16255: if ($is_home) {
16256: my $keyitem = 'form.lti_key_'.$idx;
16257: $env{$keyitem} =~ s/(`)/'/g;
16258: if ($env{$keyitem} ne '') {
16259: $ltienc{$itemid}{'key'} = $env{$keyitem};
16260: unless ($changes{$itemid}) {
16261: if ($currlti{'key'} ne $env{$keyitem}) {
16262: $changes{$itemid} = 1;
16263: }
16264: }
16265: }
16266: my $secretitem = 'form.lti_secret_'.$idx;
16267: $env{$secretitem} =~ s/(`)/'/g;
16268: if ($currlti{'usable'}) {
16269: if ($env{'form.lti_changesecret_'.$idx}) {
16270: if ($env{$secretitem} ne '') {
16271: if ($privnum && $cipher) {
16272: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16273: $confhash{$itemid}{'cipher'} = $privnum;
16274: } else {
16275: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16276: }
16277: $changes{$itemid} = 1;
16278: }
16279: } else {
16280: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16281: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16282: }
16283: if (ref($ltienc{$itemid}) eq 'HASH') {
16284: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16285: $confhash{$itemid}{'usable'} = 1;
16286: }
16287: }
16288: } elsif ($env{$secretitem} ne '') {
16289: if ($privnum && $cipher) {
16290: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16291: $confhash{$itemid}{'cipher'} = $privnum;
16292: } else {
16293: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16294: }
16295: if (ref($ltienc{$itemid}) eq 'HASH') {
16296: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16297: $confhash{$itemid}{'usable'} = 1;
16298: }
16299: }
16300: $changes{$itemid} = 1;
16301: }
16302: }
16303: unless ($changes{$itemid}) {
16304: foreach my $key (keys(%currlti)) {
16305: if (ref($currlti{$key}) eq 'HASH') {
16306: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16307: foreach my $innerkey (keys(%{$currlti{$key}})) {
16308: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16309: $changes{$itemid} = 1;
16310: last;
16311: }
16312: }
16313: } elsif (keys(%{$currlti{$key}}) > 0) {
16314: $changes{$itemid} = 1;
16315: }
16316: }
16317: last if ($changes{$itemid});
16318: }
16319: }
1.320 raeburn 16320: }
16321: if (@allpos > 0) {
16322: my $idx = 0;
16323: foreach my $itemid (@allpos) {
16324: if ($itemid ne '') {
16325: $confhash{$itemid}{'order'} = $idx;
16326: if (ref($domconfig{$action}) eq 'HASH') {
16327: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16328: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16329: $changes{$itemid} = 1;
16330: }
16331: }
16332: }
16333: $idx ++;
16334: }
16335: }
16336: }
1.424 raeburn 16337:
16338: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16339: return &mt('No changes made.');
16340: }
16341:
1.320 raeburn 16342: my %ltihash = (
1.405 raeburn 16343: $action => { %confhash }
16344: );
1.424 raeburn 16345: my %ltienchash;
16346:
16347: if ($is_home) {
16348: %ltienchash = (
16349: $action => { %ltienc }
16350: );
16351: }
1.405 raeburn 16352: if (keys(%secchanges)) {
16353: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16354: if ($secchanges{'linkprot'}) {
16355: if ($is_home) {
16356: $ltienchash{'linkprot'} = \%newltienc;
16357: }
16358: }
1.405 raeburn 16359: }
16360: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16361: if ($putresult eq 'ok') {
1.424 raeburn 16362: if (keys(%ltienchash)) {
16363: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16364: }
16365: $resulttext = &mt('Changes made:').'<ul>';
16366: if (keys(%secchanges) > 0) {
1.423 raeburn 16367: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16368: if (exists($secchanges{'linkprot'})) {
16369: $resulttext .= $linkprotoutput;
1.405 raeburn 16370: }
16371: }
1.320 raeburn 16372: if (keys(%changes) > 0) {
16373: my $cachetime = 24*60*60;
1.424 raeburn 16374: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16375: if (ref($lastactref) eq 'HASH') {
16376: $lastactref->{'lti'} = 1;
16377: }
16378: my %bynum;
16379: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16380: if (ref($confhash{$itemid}) eq 'HASH') {
16381: my $position = $confhash{$itemid}{'order'};
16382: $bynum{$position} = $itemid;
16383: }
1.320 raeburn 16384: }
16385: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16386: my $itemid = $bynum{$pos};
1.424 raeburn 16387: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16388: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16389: my $position = $pos + 1;
16390: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16391: foreach my $item ('version','lifetime') {
16392: if ($confhash{$itemid}{$item} ne '') {
16393: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16394: }
16395: }
1.424 raeburn 16396: if ($ltienc{$itemid}{'key'} ne '') {
16397: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16398: }
1.424 raeburn 16399: if ($ltienc{$itemid}{'secret'} ne '') {
16400: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16401: }
1.345 raeburn 16402: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16403: if ($confhash{$itemid}{'callback'}) {
16404: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16405: } else {
1.392 raeburn 16406: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16407: }
1.345 raeburn 16408: if ($confhash{$itemid}{'mapuser'}) {
16409: my $shownmapuser;
16410: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16411: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16412: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16413: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16414: } else {
16415: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16416: }
1.345 raeburn 16417: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16418: }
1.345 raeburn 16419: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16420: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16421: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16422: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16423: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16424: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16425: } else {
16426: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16427: $confhash{$itemid}{'lcauth'});
16428: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16429: $resulttext .= '; '.&mt('a randomly generated password will be created');
16430: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16431: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16432: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16433: }
16434: } else {
16435: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16436: }
16437: }
16438: $resulttext .= '</li>';
16439: } else {
16440: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16441: }
1.320 raeburn 16442: }
1.345 raeburn 16443: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16444: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16445: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16446: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16447: } else {
1.447.2.2 raeburn 16448: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user').'</li>';
1.325 raeburn 16449: }
1.447.2.2 raeburn 16450: } else {
16451: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user').'</li>';
1.320 raeburn 16452: }
1.391 raeburn 16453: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16454: $resulttext .= '<li>'.$lt{$item}.': ';
16455: if ($confhash{$itemid}{$item}) {
16456: $resulttext .= &mt('Yes');
16457: } else {
16458: $resulttext .= &mt('No');
1.337 raeburn 16459: }
1.345 raeburn 16460: $resulttext .= '</li>';
1.320 raeburn 16461: }
1.345 raeburn 16462: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16463: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16464: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16465: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16466: } else {
16467: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16468: }
16469: }
16470: if ($confhash{$itemid}{'crsinc'}) {
16471: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16472: my $rolemaps;
16473: foreach my $role (@ltiroles) {
16474: if ($confhash{$itemid}{'maproles'}{$role}) {
16475: $rolemaps .= (' 'x2).$role.'='.
16476: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16477: 'Course').',';
16478: }
16479: }
16480: if ($rolemaps) {
16481: $rolemaps =~ s/,$//;
16482: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16483: }
16484: }
16485: if ($confhash{$itemid}{'mapcrs'}) {
16486: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16487: }
16488: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16489: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16490: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16491: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16492: '</li>';
16493: } else {
16494: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16495: }
16496: }
1.392 raeburn 16497: if ($confhash{$itemid}{'storecrs'}) {
16498: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16499: }
1.391 raeburn 16500: if ($confhash{$itemid}{'makecrs'}) {
16501: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16502: } else {
16503: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16504: }
16505: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16506: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16507: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16508: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16509: '</li>';
16510: } else {
16511: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16512: }
16513: }
16514: if ($confhash{$itemid}{'section'}) {
16515: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16516: $resulttext .= '<li>'.&mt('User section from standard field:').
16517: ' (course_section_sourcedid)'.'</li>';
16518: } else {
16519: $resulttext .= '<li>'.&mt('User section from:').' '.
16520: $confhash{$itemid}{'section'}.'</li>';
16521: }
1.345 raeburn 16522: } else {
1.391 raeburn 16523: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16524: }
16525: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16526: $resulttext .= '<li>'.$lt{$item}.': ';
16527: if ($confhash{$itemid}{$item}) {
16528: $resulttext .= &mt('Yes');
16529: if ($item eq 'passback') {
16530: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16531: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16532: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16533: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16534: }
16535: }
16536: } else {
16537: $resulttext .= &mt('No');
16538: }
16539: $resulttext .= '</li>';
16540: }
16541: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16542: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16543: $resulttext .= '<li>'.&mt('Menu items:').' '.
16544: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16545: } else {
16546: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16547: }
1.345 raeburn 16548: }
1.326 raeburn 16549: }
16550: }
1.320 raeburn 16551: $resulttext .= '</ul></li>';
16552: }
16553: }
1.424 raeburn 16554: if (keys(%deletions)) {
16555: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16556: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16557: }
16558: }
1.320 raeburn 16559: }
1.405 raeburn 16560: $resulttext .= '</ul>';
1.424 raeburn 16561: if (ref($lastactref) eq 'HASH') {
1.434 raeburn 16562: if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
16563: &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 16564: $lastactref->{'domdefaults'} = 1;
16565: }
16566: }
1.320 raeburn 16567: } else {
16568: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16569: }
16570: if ($errors) {
16571: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16572: $errors.'</ul>';
16573: }
16574: return $resulttext;
16575: }
16576:
1.424 raeburn 16577: sub get_priv_creds {
16578: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16579: my ($needenc,$cipher,$privnum);
16580: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16581: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16582: $needenc = $encrypt->{'consumers'}
16583: } else {
16584: $needenc = $domdefs{'ltienc_consumers'};
16585: }
16586: if ($needenc) {
16587: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16588: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16589: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16590: my $privkey = $privhash{'key'};
16591: $privnum = $privhash{'version'};
16592: if (($privnum) && ($privkey ne '')) {
16593: $cipher = Crypt::CBC->new({'key' => $privkey,
16594: 'cipher' => 'DES'});
16595: }
16596: }
16597: }
16598: return ($cipher,$privnum);
16599: }
16600:
1.320 raeburn 16601: sub get_lti_id {
1.434 raeburn 16602: my ($domain,$consumer,$dbname) = @_;
16603: unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
16604: return ('','invalid db');
16605: }
16606: # get lock on db
1.320 raeburn 16607: my $lockhash = {
16608: lock => $env{'user.name'}.
16609: ':'.$env{'user.domain'},
16610: };
16611: my $tries = 0;
1.434 raeburn 16612: my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16613: my ($id,$error);
16614:
16615: while (($gotlock ne 'ok') && ($tries<10)) {
16616: $tries ++;
16617: sleep (0.1);
1.434 raeburn 16618: $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16619: }
16620: if ($gotlock eq 'ok') {
1.434 raeburn 16621: my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1.320 raeburn 16622: if ($currids{'lock'}) {
16623: delete($currids{'lock'});
16624: if (keys(%currids)) {
16625: my @curr = sort { $a <=> $b } keys(%currids);
16626: if ($curr[-1] =~ /^\d+$/) {
16627: $id = 1 + $curr[-1];
16628: }
16629: } else {
16630: $id = 1;
16631: }
16632: if ($id) {
1.434 raeburn 16633: unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1.320 raeburn 16634: $error = 'nostore';
16635: }
16636: } else {
16637: $error = 'nonumber';
16638: }
16639: }
1.434 raeburn 16640: my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1.320 raeburn 16641: } else {
16642: $error = 'nolock';
16643: }
16644: return ($id,$error);
16645: }
16646:
1.3 raeburn 16647: sub modify_autoenroll {
1.205 raeburn 16648: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16649: my ($resulttext,%changes);
16650: my %currautoenroll;
16651: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16652: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16653: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16654: }
16655: }
16656: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16657: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16658: sender => 'Sender for notification messages',
1.274 raeburn 16659: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16660: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16661: my @offon = ('off','on');
1.17 raeburn 16662: my $sender_uname = $env{'form.sender_uname'};
16663: my $sender_domain = $env{'form.sender_domain'};
16664: if ($sender_domain eq '') {
16665: $sender_uname = '';
16666: } elsif ($sender_uname eq '') {
16667: $sender_domain = '';
16668: }
1.129 raeburn 16669: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16670: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16671: $autofailsafe =~ s{^\s+|\s+$}{}g;
16672: if ($autofailsafe =~ /\D/) {
16673: undef($autofailsafe);
16674: }
1.274 raeburn 16675: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16676: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16677: $failsafe = 'off';
1.400 raeburn 16678: undef($autofailsafe);
1.274 raeburn 16679: }
1.1 raeburn 16680: my %autoenrollhash = (
1.129 raeburn 16681: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16682: 'sender_uname' => $sender_uname,
16683: 'sender_domain' => $sender_domain,
16684: 'co-owners' => $coowners,
1.399 raeburn 16685: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16686: 'failsafe' => $failsafe,
1.1 raeburn 16687: }
16688: );
1.4 raeburn 16689: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16690: $dom);
1.1 raeburn 16691: if ($putresult eq 'ok') {
16692: if (exists($currautoenroll{'run'})) {
16693: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16694: $changes{'run'} = 1;
16695: }
16696: } elsif ($autorun) {
16697: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16698: $changes{'run'} = 1;
1.1 raeburn 16699: }
16700: }
1.17 raeburn 16701: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16702: $changes{'sender'} = 1;
16703: }
1.17 raeburn 16704: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16705: $changes{'sender'} = 1;
16706: }
1.129 raeburn 16707: if ($currautoenroll{'co-owners'} ne '') {
16708: if ($currautoenroll{'co-owners'} ne $coowners) {
16709: $changes{'coowners'} = 1;
16710: }
16711: } elsif ($coowners) {
16712: $changes{'coowners'} = 1;
1.274 raeburn 16713: }
1.399 raeburn 16714: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16715: $changes{'autofailsafe'} = 1;
16716: }
1.399 raeburn 16717: if ($currautoenroll{'failsafe'} ne $failsafe) {
16718: $changes{'failsafe'} = 1;
16719: }
1.1 raeburn 16720: if (keys(%changes) > 0) {
16721: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16722: if ($changes{'run'}) {
1.1 raeburn 16723: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16724: }
16725: if ($changes{'sender'}) {
1.17 raeburn 16726: if ($sender_uname eq '' || $sender_domain eq '') {
16727: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16728: } else {
16729: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16730: }
1.1 raeburn 16731: }
1.129 raeburn 16732: if ($changes{'coowners'}) {
16733: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16734: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16735: if (ref($lastactref) eq 'HASH') {
16736: $lastactref->{'domainconfig'} = 1;
16737: }
1.129 raeburn 16738: }
1.274 raeburn 16739: if ($changes{'autofailsafe'}) {
1.399 raeburn 16740: if ($autofailsafe ne '') {
16741: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16742: } else {
1.399 raeburn 16743: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16744: }
1.399 raeburn 16745: }
16746: if ($changes{'failsafe'}) {
16747: if ($failsafe eq 'off') {
16748: unless ($changes{'autofailsafe'}) {
16749: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16750: }
16751: } elsif ($failsafe eq 'zero') {
16752: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16753: } else {
16754: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16755: }
16756: }
16757: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16758: &Apache::lonnet::get_domain_defaults($dom,1);
16759: if (ref($lastactref) eq 'HASH') {
16760: $lastactref->{'domdefaults'} = 1;
16761: }
16762: }
1.1 raeburn 16763: $resulttext .= '</ul>';
16764: } else {
16765: $resulttext = &mt('No changes made to auto-enrollment settings');
16766: }
16767: } else {
1.11 albertel 16768: $resulttext = '<span class="LC_error">'.
16769: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16770: }
1.3 raeburn 16771: return $resulttext;
1.1 raeburn 16772: }
16773:
16774: sub modify_autoupdate {
1.3 raeburn 16775: my ($dom,%domconfig) = @_;
1.1 raeburn 16776: my ($resulttext,%currautoupdate,%fields,%changes);
16777: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16778: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16779: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16780: }
16781: }
16782: my @offon = ('off','on');
16783: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16784: run => 'Auto-update:',
16785: classlists => 'Updates to user information in classlists?',
16786: unexpired => 'Skip updates for users without active or future roles?',
16787: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16788: );
1.44 raeburn 16789: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16790: my %fieldtitles = &Apache::lonlocal::texthash (
16791: id => 'Student/Employee ID',
1.20 raeburn 16792: permanentemail => 'E-mail address',
1.1 raeburn 16793: lastname => 'Last Name',
16794: firstname => 'First Name',
16795: middlename => 'Middle Name',
1.132 raeburn 16796: generation => 'Generation',
1.1 raeburn 16797: );
1.142 raeburn 16798: $othertitle = &mt('All users');
1.1 raeburn 16799: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16800: $othertitle = &mt('Other users');
1.1 raeburn 16801: }
16802: foreach my $key (keys(%env)) {
16803: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16804: my ($usertype,$item) = ($1,$2);
16805: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16806: if ($usertype eq 'default') {
16807: push(@{$fields{$1}},$2);
16808: } elsif (ref($types) eq 'ARRAY') {
16809: if (grep(/^\Q$usertype\E$/,@{$types})) {
16810: push(@{$fields{$1}},$2);
16811: }
16812: }
16813: }
1.1 raeburn 16814: }
16815: }
1.131 raeburn 16816: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16817: @lockablenames = sort(@lockablenames);
16818: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16819: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16820: if (@changed) {
16821: $changes{'lockablenames'} = 1;
16822: }
16823: } else {
16824: if (@lockablenames) {
16825: $changes{'lockablenames'} = 1;
16826: }
16827: }
1.1 raeburn 16828: my %updatehash = (
16829: autoupdate => { run => $env{'form.autoupdate_run'},
16830: classlists => $env{'form.classlists'},
1.385 raeburn 16831: unexpired => $env{'form.unexpired'},
1.1 raeburn 16832: fields => {%fields},
1.131 raeburn 16833: lockablenames => \@lockablenames,
1.1 raeburn 16834: }
16835: );
1.385 raeburn 16836: my $lastactivedays;
16837: if ($env{'form.lastactive'}) {
16838: $lastactivedays = $env{'form.lastactivedays'};
16839: $lastactivedays =~ s/^\s+|\s+$//g;
16840: unless ($lastactivedays =~ /^\d+$/) {
16841: undef($lastactivedays);
16842: $env{'form.lastactive'} = 0;
16843: }
16844: }
16845: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16846: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16847: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16848: if (exists($updatehash{autoupdate}{$key})) {
16849: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16850: $changes{$key} = 1;
16851: }
16852: }
16853: } elsif ($key eq 'fields') {
16854: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16855: foreach my $item (@{$types},'default') {
1.1 raeburn 16856: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16857: my $change = 0;
16858: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16859: if (!exists($fields{$item})) {
16860: $change = 1;
1.132 raeburn 16861: last;
1.1 raeburn 16862: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16863: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16864: $change = 1;
1.132 raeburn 16865: last;
1.1 raeburn 16866: }
16867: }
16868: }
16869: if ($change) {
16870: push(@{$changes{$key}},$item);
16871: }
1.26 raeburn 16872: }
1.1 raeburn 16873: }
16874: }
1.131 raeburn 16875: } elsif ($key eq 'lockablenames') {
16876: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16877: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16878: if (@changed) {
16879: $changes{'lockablenames'} = 1;
16880: }
16881: } else {
16882: if (@lockablenames) {
16883: $changes{'lockablenames'} = 1;
16884: }
16885: }
16886: }
16887: }
16888: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16889: if (@lockablenames) {
16890: $changes{'lockablenames'} = 1;
1.1 raeburn 16891: }
16892: }
1.385 raeburn 16893: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16894: if ($updatehash{'autoupdate'}{'unexpired'}) {
16895: $changes{'unexpired'} = 1;
16896: }
16897: }
16898: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16899: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16900: $changes{'lastactive'} = 1;
16901: }
16902: }
1.26 raeburn 16903: foreach my $item (@{$types},'default') {
16904: if (defined($fields{$item})) {
16905: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16906: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16907: my $change = 0;
16908: if (ref($fields{$item}) eq 'ARRAY') {
16909: foreach my $type (@{$fields{$item}}) {
16910: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16911: $change = 1;
16912: last;
16913: }
16914: }
16915: }
16916: if ($change) {
16917: push(@{$changes{'fields'}},$item);
16918: }
16919: } else {
1.26 raeburn 16920: push(@{$changes{'fields'}},$item);
16921: }
16922: } else {
16923: push(@{$changes{'fields'}},$item);
1.1 raeburn 16924: }
16925: }
16926: }
16927: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16928: $dom);
16929: if ($putresult eq 'ok') {
16930: if (keys(%changes) > 0) {
16931: $resulttext = &mt('Changes made:').'<ul>';
16932: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16933: if ($key eq 'lockablenames') {
16934: $resulttext .= '<li>';
16935: if (@lockablenames) {
16936: $usertypes->{'default'} = $othertitle;
16937: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16938: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16939: } else {
16940: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16941: }
16942: $resulttext .= '</li>';
16943: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16944: foreach my $item (@{$changes{$key}}) {
16945: my @newvalues;
16946: foreach my $type (@{$fields{$item}}) {
16947: push(@newvalues,$fieldtitles{$type});
16948: }
1.3 raeburn 16949: my $newvaluestr;
16950: if (@newvalues > 0) {
16951: $newvaluestr = join(', ',@newvalues);
16952: } else {
16953: $newvaluestr = &mt('none');
1.6 raeburn 16954: }
1.1 raeburn 16955: if ($item eq 'default') {
1.26 raeburn 16956: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16957: } else {
1.26 raeburn 16958: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16959: }
16960: }
16961: } else {
16962: my $newvalue;
16963: if ($key eq 'run') {
16964: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16965: } elsif ($key eq 'lastactive') {
16966: $newvalue = $offon[$env{'form.lastactive'}];
16967: unless ($lastactivedays eq '') {
16968: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16969: }
1.1 raeburn 16970: } else {
16971: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16972: }
1.1 raeburn 16973: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16974: }
16975: }
16976: $resulttext .= '</ul>';
16977: } else {
1.3 raeburn 16978: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16979: }
16980: } else {
1.11 albertel 16981: $resulttext = '<span class="LC_error">'.
16982: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16983: }
1.3 raeburn 16984: return $resulttext;
1.1 raeburn 16985: }
16986:
1.125 raeburn 16987: sub modify_autocreate {
16988: my ($dom,%domconfig) = @_;
16989: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
16990: if (ref($domconfig{'autocreate'}) eq 'HASH') {
16991: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
16992: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
16993: }
16994: }
16995: my %title= ( xml => 'Auto-creation of courses in XML course description files',
16996: req => 'Auto-creation of validated requests for official courses',
16997: xmldc => 'Identity of course creator of courses from XML files',
16998: );
16999: my @types = ('xml','req');
17000: foreach my $item (@types) {
17001: $newvals{$item} = $env{'form.autocreate_'.$item};
17002: $newvals{$item} =~ s/\D//g;
17003: $newvals{$item} = 0 if ($newvals{$item} eq '');
17004: }
17005: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 17006: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 17007: unless (exists($domcoords{$newvals{'xmldc'}})) {
17008: $newvals{'xmldc'} = '';
17009: }
17010: %autocreatehash = (
17011: autocreate => { xml => $newvals{'xml'},
17012: req => $newvals{'req'},
17013: }
17014: );
17015: if ($newvals{'xmldc'} ne '') {
17016: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
17017: }
17018: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
17019: $dom);
17020: if ($putresult eq 'ok') {
17021: my @items = @types;
17022: if ($newvals{'xml'}) {
17023: push(@items,'xmldc');
17024: }
17025: foreach my $item (@items) {
17026: if (exists($currautocreate{$item})) {
17027: if ($currautocreate{$item} ne $newvals{$item}) {
17028: $changes{$item} = 1;
17029: }
17030: } elsif ($newvals{$item}) {
17031: $changes{$item} = 1;
17032: }
17033: }
17034: if (keys(%changes) > 0) {
17035: my @offon = ('off','on');
17036: $resulttext = &mt('Changes made:').'<ul>';
17037: foreach my $item (@types) {
17038: if ($changes{$item}) {
17039: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 17040: $resulttext .= '<li>'.
17041: &mt("$title{$item} set to [_1]$newtxt [_2]",
17042: '<b>','</b>').
17043: '</li>';
1.125 raeburn 17044: }
17045: }
17046: if ($changes{'xmldc'}) {
17047: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
17048: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 17049: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 17050: }
17051: $resulttext .= '</ul>';
17052: } else {
17053: $resulttext = &mt('No changes made to auto-creation settings');
17054: }
17055: } else {
17056: $resulttext = '<span class="LC_error">'.
17057: &mt('An error occurred: [_1]',$putresult).'</span>';
17058: }
17059: return $resulttext;
17060: }
17061:
1.23 raeburn 17062: sub modify_directorysrch {
1.295 raeburn 17063: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 17064: my ($resulttext,%changes);
17065: my %currdirsrch;
17066: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
17067: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
17068: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
17069: }
17070: }
1.277 raeburn 17071: my %title = ( available => 'Institutional directory search available',
17072: localonly => 'Other domains can search institution',
17073: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 17074: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 17075: searchby => 'Search types',
17076: searchtypes => 'Search latitude');
17077: my @offon = ('off','on');
1.24 raeburn 17078: my @otherdoms = ('Yes','No');
1.23 raeburn 17079:
1.25 raeburn 17080: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 17081: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
17082: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
17083:
1.44 raeburn 17084: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 17085: if (keys(%{$usertypes}) == 0) {
17086: @cansearch = ('default');
17087: } else {
17088: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
17089: foreach my $type (@{$currdirsrch{'cansearch'}}) {
17090: if (!grep(/^\Q$type\E$/,@cansearch)) {
17091: push(@{$changes{'cansearch'}},$type);
17092: }
1.23 raeburn 17093: }
1.26 raeburn 17094: foreach my $type (@cansearch) {
17095: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
17096: push(@{$changes{'cansearch'}},$type);
17097: }
1.23 raeburn 17098: }
1.26 raeburn 17099: } else {
17100: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 17101: }
17102: }
17103:
17104: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
17105: foreach my $by (@{$currdirsrch{'searchby'}}) {
17106: if (!grep(/^\Q$by\E$/,@searchby)) {
17107: push(@{$changes{'searchby'}},$by);
17108: }
17109: }
17110: foreach my $by (@searchby) {
17111: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
17112: push(@{$changes{'searchby'}},$by);
17113: }
17114: }
17115: } else {
17116: push(@{$changes{'searchby'}},@searchby);
17117: }
1.25 raeburn 17118:
17119: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
17120: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
17121: if (!grep(/^\Q$type\E$/,@searchtypes)) {
17122: push(@{$changes{'searchtypes'}},$type);
17123: }
17124: }
17125: foreach my $type (@searchtypes) {
17126: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
17127: push(@{$changes{'searchtypes'}},$type);
17128: }
17129: }
17130: } else {
17131: if (exists($currdirsrch{'searchtypes'})) {
17132: foreach my $type (@searchtypes) {
17133: if ($type ne $currdirsrch{'searchtypes'}) {
17134: push(@{$changes{'searchtypes'}},$type);
17135: }
17136: }
17137: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
17138: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
17139: }
17140: } else {
17141: push(@{$changes{'searchtypes'}},@searchtypes);
17142: }
17143: }
17144:
1.23 raeburn 17145: my %dirsrch_hash = (
17146: directorysrch => { available => $env{'form.dirsrch_available'},
17147: cansearch => \@cansearch,
1.277 raeburn 17148: localonly => $env{'form.dirsrch_instlocalonly'},
17149: lclocalonly => $env{'form.dirsrch_domlocalonly'},
17150: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 17151: searchby => \@searchby,
1.25 raeburn 17152: searchtypes => \@searchtypes,
1.23 raeburn 17153: }
17154: );
17155: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
17156: $dom);
17157: if ($putresult eq 'ok') {
17158: if (exists($currdirsrch{'available'})) {
17159: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
17160: $changes{'available'} = 1;
17161: }
17162: } else {
17163: if ($env{'form.dirsrch_available'} eq '1') {
17164: $changes{'available'} = 1;
17165: }
17166: }
1.277 raeburn 17167: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 17168: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
17169: $changes{'lcavailable'} = 1;
17170: }
1.277 raeburn 17171: } else {
17172: if ($env{'form.dirsrch_lcavailable'} eq '1') {
17173: $changes{'lcavailable'} = 1;
17174: }
17175: }
1.24 raeburn 17176: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 17177: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
17178: $changes{'localonly'} = 1;
17179: }
1.24 raeburn 17180: } else {
1.277 raeburn 17181: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 17182: $changes{'localonly'} = 1;
17183: }
17184: }
1.277 raeburn 17185: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 17186: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
17187: $changes{'lclocalonly'} = 1;
17188: }
1.277 raeburn 17189: } else {
17190: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
17191: $changes{'lclocalonly'} = 1;
17192: }
17193: }
1.23 raeburn 17194: if (keys(%changes) > 0) {
17195: $resulttext = &mt('Changes made:').'<ul>';
17196: if ($changes{'available'}) {
17197: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
17198: }
1.277 raeburn 17199: if ($changes{'lcavailable'}) {
17200: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
17201: }
1.24 raeburn 17202: if ($changes{'localonly'}) {
1.277 raeburn 17203: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 17204: }
1.277 raeburn 17205: if ($changes{'lclocalonly'}) {
17206: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 17207: }
1.23 raeburn 17208: if (ref($changes{'cansearch'}) eq 'ARRAY') {
17209: my $chgtext;
1.26 raeburn 17210: if (ref($usertypes) eq 'HASH') {
17211: if (keys(%{$usertypes}) > 0) {
17212: foreach my $type (@{$types}) {
17213: if (grep(/^\Q$type\E$/,@cansearch)) {
17214: $chgtext .= $usertypes->{$type}.'; ';
17215: }
17216: }
17217: if (grep(/^default$/,@cansearch)) {
17218: $chgtext .= $othertitle;
17219: } else {
17220: $chgtext =~ s/\; $//;
17221: }
1.210 raeburn 17222: $resulttext .=
1.178 raeburn 17223: '<li>'.
17224: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17225: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17226: '</li>';
1.23 raeburn 17227: }
17228: }
17229: }
17230: if (ref($changes{'searchby'}) eq 'ARRAY') {
17231: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17232: my $chgtext;
17233: foreach my $type (@{$titleorder}) {
17234: if (grep(/^\Q$type\E$/,@searchby)) {
17235: if (defined($searchtitles->{$type})) {
17236: $chgtext .= $searchtitles->{$type}.'; ';
17237: }
17238: }
17239: }
17240: $chgtext =~ s/\; $//;
17241: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17242: }
1.25 raeburn 17243: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17244: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17245: my $chgtext;
17246: foreach my $type (@{$srchtypeorder}) {
17247: if (grep(/^\Q$type\E$/,@searchtypes)) {
17248: if (defined($srchtypes_desc->{$type})) {
17249: $chgtext .= $srchtypes_desc->{$type}.'; ';
17250: }
17251: }
17252: }
17253: $chgtext =~ s/\; $//;
1.178 raeburn 17254: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17255: }
17256: $resulttext .= '</ul>';
1.295 raeburn 17257: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17258: if (ref($lastactref) eq 'HASH') {
17259: $lastactref->{'directorysrch'} = 1;
17260: }
1.23 raeburn 17261: } else {
1.277 raeburn 17262: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17263: }
17264: } else {
17265: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17266: &mt('An error occurred: [_1]',$putresult).'</span>';
17267: }
17268: return $resulttext;
17269: }
17270:
1.28 raeburn 17271: sub modify_contacts {
1.205 raeburn 17272: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17273: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17274: if (ref($domconfig{'contacts'}) eq 'HASH') {
17275: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17276: $currsetting{$key} = $domconfig{'contacts'}{$key};
17277: }
17278: }
1.286 raeburn 17279: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17280: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17281: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17282: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17283: my @toggles = ('reporterrors','reportupdates','reportstatus');
17284: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17285: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17286: foreach my $type (@mailings) {
17287: @{$newsetting{$type}} =
17288: &Apache::loncommon::get_env_multiple('form.'.$type);
17289: foreach my $item (@contacts) {
17290: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17291: $contacts_hash{contacts}{$type}{$item} = 1;
17292: } else {
17293: $contacts_hash{contacts}{$type}{$item} = 0;
17294: }
1.289 raeburn 17295: }
1.28 raeburn 17296: $others{$type} = $env{'form.'.$type.'_others'};
17297: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17298: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17299: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17300: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17301: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17302: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17303: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17304: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17305: }
1.134 raeburn 17306: }
1.28 raeburn 17307: }
17308: foreach my $item (@contacts) {
17309: $to{$item} = $env{'form.'.$item};
17310: $contacts_hash{'contacts'}{$item} = $to{$item};
17311: }
1.203 raeburn 17312: foreach my $item (@toggles) {
17313: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17314: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17315: }
17316: }
1.340 raeburn 17317: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17318: foreach my $item (@lonstatus) {
17319: if ($item eq 'excluded') {
17320: my (%serverhomes,@excluded);
17321: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17322: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17323: if (@possexcluded) {
17324: foreach my $id (sort(@possexcluded)) {
17325: if ($serverhomes{$id}) {
17326: push(@excluded,$id);
17327: }
17328: }
17329: }
17330: if (@excluded) {
17331: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17332: }
17333: } elsif ($item eq 'weights') {
1.377 raeburn 17334: foreach my $type ('E','W','N','U') {
1.340 raeburn 17335: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17336: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17337: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17338: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17339: $env{'form.error'.$item.'_'.$type};
17340: }
17341: }
17342: }
17343: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17344: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17345: if ($env{'form.error'.$item} =~ /^\d+$/) {
17346: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17347: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17348: }
17349: }
17350: }
17351: }
1.286 raeburn 17352: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17353: foreach my $field (@{$fields}) {
17354: if (ref($possoptions->{$field}) eq 'ARRAY') {
17355: my $value = $env{'form.helpform_'.$field};
17356: $value =~ s/^\s+|\s+$//g;
17357: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17358: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17359: if ($field eq 'screenshot') {
17360: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17361: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17362: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17363: }
17364: }
17365: }
17366: }
17367: }
17368: }
1.315 raeburn 17369: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17370: my (@statuses,%usertypeshash,@overrides);
17371: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17372: @statuses = @{$types};
17373: if (ref($usertypes) eq 'HASH') {
17374: %usertypeshash = %{$usertypes};
17375: }
17376: }
17377: if (@statuses) {
17378: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17379: foreach my $type (@possoverrides) {
17380: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17381: push(@overrides,$type);
17382: }
17383: }
17384: if (@overrides) {
17385: foreach my $type (@overrides) {
17386: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17387: foreach my $item (@contacts) {
17388: if (grep(/^\Q$item\E$/,@standard)) {
17389: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17390: $newsetting{'override_'.$type}{$item} = 1;
17391: } else {
17392: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17393: $newsetting{'override_'.$type}{$item} = 0;
17394: }
17395: }
17396: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17397: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17398: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17399: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17400: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17401: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17402: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17403: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17404: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17405: }
1.425 raeburn 17406: }
1.315 raeburn 17407: }
17408: }
1.28 raeburn 17409: if (keys(%currsetting) > 0) {
17410: foreach my $item (@contacts) {
17411: if ($to{$item} ne $currsetting{$item}) {
17412: $changes{$item} = 1;
17413: }
17414: }
17415: foreach my $type (@mailings) {
17416: foreach my $item (@contacts) {
17417: if (ref($currsetting{$type}) eq 'HASH') {
17418: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17419: push(@{$changes{$type}},$item);
17420: }
17421: } else {
17422: push(@{$changes{$type}},@{$newsetting{$type}});
17423: }
17424: }
17425: if ($others{$type} ne $currsetting{$type}{'others'}) {
17426: push(@{$changes{$type}},'others');
17427: }
1.289 raeburn 17428: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17429: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17430: push(@{$changes{$type}},'bcc');
17431: }
1.286 raeburn 17432: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17433: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17434: push(@{$changes{$type}},'include');
17435: }
17436: }
17437: }
17438: if (ref($fields) eq 'ARRAY') {
17439: if (ref($currsetting{'helpform'}) eq 'HASH') {
17440: foreach my $field (@{$fields}) {
17441: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17442: push(@{$changes{'helpform'}},$field);
17443: }
17444: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17445: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17446: push(@{$changes{'helpform'}},'maxsize');
17447: }
17448: }
17449: }
17450: } else {
17451: foreach my $field (@{$fields}) {
17452: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17453: push(@{$changes{'helpform'}},$field);
17454: }
17455: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17456: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17457: push(@{$changes{'helpform'}},'maxsize');
17458: }
17459: }
17460: }
1.134 raeburn 17461: }
1.28 raeburn 17462: }
1.315 raeburn 17463: if (@statuses) {
1.425 raeburn 17464: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17465: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17466: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17467: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17468: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17469: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17470: push(@{$changes{'overrides'}},$key);
17471: last;
17472: }
17473: }
17474: } else {
17475: push(@{$changes{'overrides'}},$key);
17476: }
17477: }
17478: }
17479: foreach my $key (@overrides) {
17480: unless (exists($currsetting{'overrides'}{$key})) {
17481: push(@{$changes{'overrides'}},$key);
17482: }
17483: }
17484: } else {
17485: foreach my $key (@overrides) {
1.425 raeburn 17486: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17487: }
17488: }
17489: }
1.340 raeburn 17490: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17491: foreach my $key ('excluded','weights','threshold','sysmail') {
17492: if ($key eq 'excluded') {
17493: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17494: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17495: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17496: (@{$currsetting{'lonstatus'}{$key}})) {
17497: my @diffs =
17498: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17499: $currsetting{'lonstatus'}{$key});
17500: if (@diffs) {
17501: push(@{$changes{'lonstatus'}},$key);
17502: }
17503: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17504: push(@{$changes{'lonstatus'}},$key);
17505: }
17506: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17507: (@{$currsetting{'lonstatus'}{$key}})) {
17508: push(@{$changes{'lonstatus'}},$key);
17509: }
17510: } elsif ($key eq 'weights') {
17511: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17512: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17513: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17514: foreach my $type ('E','W','N','U') {
1.340 raeburn 17515: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17516: $currsetting{'lonstatus'}{$key}{$type}) {
17517: push(@{$changes{'lonstatus'}},$key);
17518: last;
17519: }
17520: }
17521: } else {
1.341 raeburn 17522: foreach my $type ('E','W','N','U') {
1.340 raeburn 17523: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17524: push(@{$changes{'lonstatus'}},$key);
17525: last;
17526: }
17527: }
17528: }
17529: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17530: foreach my $type ('E','W','N','U') {
1.340 raeburn 17531: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17532: push(@{$changes{'lonstatus'}},$key);
17533: last;
17534: }
17535: }
17536: }
17537: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17538: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17539: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17540: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17541: push(@{$changes{'lonstatus'}},$key);
17542: }
17543: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17544: push(@{$changes{'lonstatus'}},$key);
17545: }
17546: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17547: push(@{$changes{'lonstatus'}},$key);
17548: }
17549: }
17550: }
17551: } else {
17552: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17553: foreach my $key ('excluded','weights','threshold','sysmail') {
17554: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17555: push(@{$changes{'lonstatus'}},$key);
17556: }
17557: }
17558: }
17559: }
1.28 raeburn 17560: } else {
17561: my %default;
17562: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17563: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17564: $default{'errormail'} = 'adminemail';
17565: $default{'packagesmail'} = 'adminemail';
17566: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17567: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17568: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17569: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17570: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17571: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17572: foreach my $item (@contacts) {
17573: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17574: $changes{$item} = 1;
1.203 raeburn 17575: }
1.28 raeburn 17576: }
17577: foreach my $type (@mailings) {
17578: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17579: push(@{$changes{$type}},@{$newsetting{$type}});
17580: }
17581: if ($others{$type} ne '') {
17582: push(@{$changes{$type}},'others');
1.134 raeburn 17583: }
1.286 raeburn 17584: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17585: if ($bcc{$type} ne '') {
17586: push(@{$changes{$type}},'bcc');
17587: }
1.286 raeburn 17588: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17589: push(@{$changes{$type}},'include');
17590: }
1.134 raeburn 17591: }
1.28 raeburn 17592: }
1.286 raeburn 17593: if (ref($fields) eq 'ARRAY') {
17594: foreach my $field (@{$fields}) {
17595: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17596: push(@{$changes{'helpform'}},$field);
17597: }
17598: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17599: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17600: push(@{$changes{'helpform'}},'maxsize');
17601: }
17602: }
17603: }
1.289 raeburn 17604: }
1.340 raeburn 17605: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17606: foreach my $key ('excluded','weights','threshold','sysmail') {
17607: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17608: push(@{$changes{'lonstatus'}},$key);
17609: }
17610: }
17611: }
1.28 raeburn 17612: }
1.203 raeburn 17613: foreach my $item (@toggles) {
17614: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17615: $changes{$item} = 1;
17616: } elsif ((!$env{'form.'.$item}) &&
17617: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17618: $changes{$item} = 1;
17619: }
17620: }
1.28 raeburn 17621: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17622: $dom);
17623: if ($putresult eq 'ok') {
17624: if (keys(%changes) > 0) {
1.205 raeburn 17625: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17626: if (ref($lastactref) eq 'HASH') {
17627: $lastactref->{'domainconfig'} = 1;
17628: }
1.28 raeburn 17629: my ($titles,$short_titles) = &contact_titles();
17630: $resulttext = &mt('Changes made:').'<ul>';
17631: foreach my $item (@contacts) {
17632: if ($changes{$item}) {
17633: $resulttext .= '<li>'.$titles->{$item}.
17634: &mt(' set to: ').
17635: '<span class="LC_cusr_emph">'.
17636: $to{$item}.'</span></li>';
17637: }
17638: }
17639: foreach my $type (@mailings) {
17640: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17641: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17642: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17643: } else {
17644: $resulttext .= '<li>'.$titles->{$type}.': ';
17645: }
1.28 raeburn 17646: my @text;
17647: foreach my $item (@{$newsetting{$type}}) {
17648: push(@text,$short_titles->{$item});
17649: }
17650: if ($others{$type} ne '') {
17651: push(@text,$others{$type});
17652: }
1.286 raeburn 17653: if (@text) {
17654: $resulttext .= '<span class="LC_cusr_emph">'.
17655: join(', ',@text).'</span>';
17656: }
17657: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17658: if ($bcc{$type} ne '') {
1.286 raeburn 17659: my $bcctext;
17660: if (@text) {
1.289 raeburn 17661: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17662: } else {
17663: $bcctext = '(Bcc)';
17664: }
17665: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17666: } elsif (!@text) {
17667: $resulttext .= &mt('No one');
1.425 raeburn 17668: }
1.289 raeburn 17669: if ($includestr{$type} ne '') {
1.286 raeburn 17670: if ($includeloc{$type} eq 'b') {
17671: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17672: } elsif ($includeloc{$type} eq 's') {
17673: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17674: }
1.134 raeburn 17675: }
1.286 raeburn 17676: } elsif (!@text) {
17677: $resulttext .= &mt('No recipients');
1.134 raeburn 17678: }
17679: $resulttext .= '</li>';
1.28 raeburn 17680: }
17681: }
1.315 raeburn 17682: if (ref($changes{'overrides'}) eq 'ARRAY') {
17683: my @deletions;
17684: foreach my $type (@{$changes{'overrides'}}) {
17685: if ($usertypeshash{$type}) {
17686: if (grep(/^\Q$type\E/,@overrides)) {
17687: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17688: $usertypeshash{$type}).'<ul><li>';
17689: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17690: my @text;
17691: foreach my $item (@contacts) {
1.425 raeburn 17692: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17693: push(@text,$short_titles->{$item});
17694: }
17695: }
17696: if ($newsetting{'override_'.$type}{'others'} ne '') {
17697: push(@text,$newsetting{'override_'.$type}{'others'});
17698: }
1.425 raeburn 17699:
1.315 raeburn 17700: if (@text) {
17701: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17702: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17703: }
17704: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17705: my $bcctext;
17706: if (@text) {
17707: $bcctext = ' '.&mt('with Bcc to');
17708: } else {
17709: $bcctext = '(Bcc)';
17710: }
17711: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17712: } elsif (!@text) {
17713: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17714: }
17715: $resulttext .= '</li>';
17716: if ($newsetting{'override_'.$type}{'include'} ne '') {
17717: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17718: if ($loc eq 'b') {
17719: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17720: } elsif ($loc eq 's') {
17721: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17722: }
17723: }
17724: }
17725: $resulttext .= '</li></ul></li>';
17726: } else {
17727: push(@deletions,$usertypeshash{$type});
17728: }
17729: }
17730: }
17731: if (@deletions) {
17732: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17733: join(', ',@deletions)).'</li>';
17734: }
17735: }
1.203 raeburn 17736: my @offon = ('off','on');
1.340 raeburn 17737: my $corelink = &core_link_msu();
1.203 raeburn 17738: if ($changes{'reporterrors'}) {
17739: $resulttext .= '<li>'.
17740: &mt('E-mail error reports to [_1] set to "'.
17741: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17742: $corelink).
1.203 raeburn 17743: '</li>';
17744: }
17745: if ($changes{'reportupdates'}) {
17746: $resulttext .= '<li>'.
17747: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17748: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17749: $corelink).
1.203 raeburn 17750: '</li>';
17751: }
1.340 raeburn 17752: if ($changes{'reportstatus'}) {
17753: $resulttext .= '<li>'.
17754: &mt('E-mail status if errors above threshold to [_1] set to "'.
17755: $offon[$env{'form.reportstatus'}].'".',
17756: $corelink).
17757: '</li>';
17758: }
17759: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17760: $resulttext .= '<li>'.
17761: &mt('Nightly status check e-mail settings').':<ul>';
17762: my (%defval,%use_def,%shown);
17763: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17764: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17765: $defval{'weights'} =
1.341 raeburn 17766: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17767: $defval{'excluded'} = &mt('None');
17768: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17769: foreach my $item ('threshold','sysmail','weights','excluded') {
17770: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17771: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17772: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17773: } elsif ($item eq 'weights') {
17774: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17775: foreach my $type ('E','W','N','U') {
1.340 raeburn 17776: $shown{$item} .= $lonstatus_names->{$type}.'=';
17777: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17778: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17779: } else {
17780: $shown{$item} .= $lonstatus_defs->{$type};
17781: }
17782: $shown{$item} .= ', ';
17783: }
17784: $shown{$item} =~ s/, $//;
17785: } else {
17786: $shown{$item} = $defval{$item};
17787: }
17788: } elsif ($item eq 'excluded') {
17789: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17790: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17791: } else {
17792: $shown{$item} = $defval{$item};
17793: }
17794: }
17795: } else {
17796: $shown{$item} = $defval{$item};
17797: }
17798: }
17799: } else {
17800: foreach my $item ('threshold','weights','excluded','sysmail') {
17801: $shown{$item} = $defval{$item};
17802: }
17803: }
17804: foreach my $item ('threshold','weights','excluded','sysmail') {
17805: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17806: $shown{$item}).'</li>';
17807: }
17808: $resulttext .= '</ul></li>';
17809: }
1.286 raeburn 17810: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17811: my (@optional,@required,@unused,$maxsizechg);
17812: foreach my $field (@{$changes{'helpform'}}) {
17813: if ($field eq 'maxsize') {
17814: $maxsizechg = 1;
17815: next;
17816: }
17817: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17818: push(@optional,$field);
1.286 raeburn 17819: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17820: push(@unused,$field);
17821: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17822: push(@required,$field);
1.286 raeburn 17823: }
17824: }
17825: if (@optional) {
17826: $resulttext .= '<li>'.
17827: &mt('Help form fields changed to "Optional": [_1].',
17828: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17829: '</li>';
17830: }
17831: if (@required) {
17832: $resulttext .= '<li>'.
17833: &mt('Help form fields changed to "Required": [_1].',
17834: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17835: '</li>';
17836: }
17837: if (@unused) {
17838: $resulttext .= '<li>'.
17839: &mt('Help form fields changed to "Not shown": [_1].',
17840: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17841: '</li>';
17842: }
17843: if ($maxsizechg) {
17844: $resulttext .= '<li>'.
17845: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17846: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17847: '</li>';
17848: }
17849: }
1.28 raeburn 17850: $resulttext .= '</ul>';
17851: } else {
1.288 raeburn 17852: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17853: }
17854: } else {
17855: $resulttext = '<span class="LC_error">'.
17856: &mt('An error occurred: [_1].',$putresult).'</span>';
17857: }
17858: return $resulttext;
17859: }
17860:
1.357 raeburn 17861: sub modify_privacy {
1.427 raeburn 17862: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17863: my ($resulttext,%current,%changes);
17864: if (ref($domconfig{'privacy'}) eq 'HASH') {
17865: %current = %{$domconfig{'privacy'}};
17866: }
17867: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17868: my @items = ('domain','author','course','community');
17869: my %names = &Apache::lonlocal::texthash (
17870: domain => 'Assigned domain role(s)',
17871: author => 'Assigned co-author role(s)',
17872: course => 'Assigned course role(s)',
1.416 raeburn 17873: community => 'Assigned community role(s)',
1.357 raeburn 17874: );
17875: my %roles = &Apache::lonlocal::texthash (
17876: domain => 'Domain role',
17877: author => 'Co-author role',
17878: course => 'Course role',
17879: community => 'Community role',
17880: );
17881: my %titles = &Apache::lonlocal::texthash (
17882: approval => 'Approval for role in different domain',
17883: othdom => 'User information available in other domain',
17884: priv => 'Information viewable by privileged user in same domain',
17885: unpriv => 'Information viewable by unprivileged user in same domain',
17886: instdom => 'Other domain shares institution/provider',
17887: extdom => 'Other domain has different institution/provider',
17888: none => 'Not allowed',
17889: user => 'User authorizes',
17890: domain => 'Domain Coordinator authorizes',
17891: auto => 'Unrestricted',
1.418 raeburn 17892: notify => 'Notify when role needs authorization',
1.357 raeburn 17893: );
17894: my %fieldnames = &Apache::lonlocal::texthash (
17895: id => 'Student/Employee ID',
17896: permanentemail => 'E-mail address',
17897: lastname => 'Last Name',
17898: firstname => 'First Name',
17899: middlename => 'Middle Name',
17900: generation => 'Generation',
17901: );
17902: my ($othertitle,$usertypes,$types) =
17903: &Apache::loncommon::sorted_inst_types($dom);
17904: my (%by_ip,%by_location,@intdoms,@instdoms);
17905: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17906:
17907: my %privacyhash = (
17908: 'approval' => {
17909: instdom => {},
17910: extdom => {},
17911: },
17912: 'othdom' => {},
17913: 'priv' => {},
17914: 'unpriv' => {},
17915: );
17916: foreach my $item (@items) {
17917: if (@instdoms > 1) {
1.416 raeburn 17918: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17919: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17920: }
17921: if (ref($current{'approval'}) eq 'HASH') {
17922: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17923: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17924: $changes{'approval'} = 1;
17925: }
17926: }
17927: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17928: $changes{'approval'} = 1;
17929: }
17930: }
17931: if (keys(%by_location) > 0) {
17932: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17933: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17934: }
17935: if (ref($current{'approval'}) eq 'HASH') {
17936: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17937: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17938: $changes{'approval'} = 1;
17939: }
17940: }
17941: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17942: $changes{'approval'} = 1;
17943: }
17944: }
17945: foreach my $status ('priv','unpriv') {
17946: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17947: my @newvalues;
17948: foreach my $field (@possibles) {
17949: if (grep(/^\Q$field\E$/,@fields)) {
17950: $privacyhash{$status}{$item}{$field} = 1;
17951: push(@newvalues,$field);
17952: }
17953: }
17954: @newvalues = sort(@newvalues);
17955: if (ref($current{$status}) eq 'HASH') {
17956: if (ref($current{$status}{$item}) eq 'HASH') {
17957: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17958: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17959: if (@diffs > 0) {
17960: $changes{$status} = 1;
17961: }
1.447.2.3! raeburn 17962: } elsif (@newvalues > 0) {
! 17963: $changes{$status} = 1;
1.357 raeburn 17964: }
17965: } else {
17966: my @stdfields;
17967: foreach my $field (@fields) {
17968: if ($field eq 'id') {
17969: next if ($status eq 'unpriv');
17970: next if (($status eq 'priv') && ($item eq 'community'));
17971: }
17972: push(@stdfields,$field);
17973: }
17974: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17975: if (@diffs > 0) {
17976: $changes{$status} = 1;
17977: }
17978: }
17979: }
17980: }
17981: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17982: my @statuses;
17983: if (ref($types) eq 'ARRAY') {
17984: @statuses = @{$types};
17985: }
17986: foreach my $type (@statuses,'default') {
17987: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17988: my @newvalues;
17989: foreach my $field (sort(@possfields)) {
17990: if (grep(/^\Q$field\E$/,@fields)) {
17991: $privacyhash{'othdom'}{$type}{$field} = 1;
17992: push(@newvalues,$field);
17993: }
17994: }
17995: @newvalues = sort(@newvalues);
17996: if (ref($current{'othdom'}) eq 'HASH') {
17997: if (ref($current{'othdom'}{$type}) eq 'HASH') {
17998: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
17999: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
18000: if (@diffs > 0) {
18001: $changes{'othdom'} = 1;
18002: }
1.447.2.3! raeburn 18003: } elsif (@newvalues > 0) {
! 18004: $changes{'othdom'} = 1;
1.357 raeburn 18005: }
18006: } else {
18007: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
18008: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
18009: if (@diffs > 0) {
18010: $changes{'othdom'} = 1;
18011: }
18012: }
18013: }
1.417 raeburn 18014: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
18015: my %notify;
18016: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
18017: if (exists($domcoords{$possdc})) {
18018: $notify{$possdc} = 1;
18019: }
18020: }
18021: my $notify = join(',',sort(keys(%notify)));
18022: if ($current{'notify'} ne $notify) {
18023: $changes{'notify'} = 1;
18024: }
18025: $privacyhash{'notify'} = $notify;
1.357 raeburn 18026: }
18027: my %confighash = (
18028: privacy => \%privacyhash,
18029: );
18030: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18031: if ($putresult eq 'ok') {
18032: if (keys(%changes) > 0) {
18033: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 18034: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 18035: if ($changes{$key}) {
18036: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18037: if ($key eq 'approval') {
18038: if (keys(%{$privacyhash{$key}{instdom}})) {
18039: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
18040: foreach my $item (@items) {
18041: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
18042: }
18043: $resulttext .= '</ul></li>';
18044: }
18045: if (keys(%{$privacyhash{$key}{extdom}})) {
18046: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
18047: foreach my $item (@items) {
18048: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
18049: }
18050: $resulttext .= '</ul></li>';
18051: }
1.417 raeburn 18052: } elsif ($key eq 'notify') {
18053: if ($privacyhash{$key}) {
18054: foreach my $dc (split(/,/,$privacyhash{$key})) {
18055: my ($dcname,$dcdom) = split(/:/,$dc);
18056: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
18057: }
18058: } else {
18059: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
18060: }
1.357 raeburn 18061: } elsif ($key eq 'othdom') {
18062: my @statuses;
18063: if (ref($types) eq 'ARRAY') {
18064: @statuses = @{$types};
18065: }
18066: if (ref($privacyhash{$key}) eq 'HASH') {
18067: foreach my $status (@statuses,'default') {
18068: if ($status eq 'default') {
18069: $resulttext .= '<li>'.$othertitle.': ';
18070: } elsif (ref($usertypes) eq 'HASH') {
18071: $resulttext .= '<li>'.$usertypes->{$status}.': ';
18072: } else {
18073: next;
18074: }
18075: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
18076: if (keys(%{$privacyhash{$key}{$status}})) {
18077: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
18078: } else {
18079: $resulttext .= &mt('none');
18080: }
18081: }
18082: $resulttext .= '</li>';
18083: }
18084: }
18085: } else {
18086: foreach my $item (@items) {
18087: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
18088: $resulttext .= '<li>'.$names{$item}.': ';
18089: if (keys(%{$privacyhash{$key}{$item}})) {
18090: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
18091: } else {
18092: $resulttext .= &mt('none');
18093: }
18094: $resulttext .= '</li>';
18095: }
18096: }
18097: }
18098: $resulttext .= '</ul></li>';
18099: }
18100: }
1.421 raeburn 18101: $resulttext .= '</ul>';
1.427 raeburn 18102: if ($changes{'approval'}) {
18103: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18104: delete($domdefaults{'userapprovals'});
18105: if (ref($privacyhash{'approval'}) eq 'HASH') {
18106: foreach my $domtype ('instdom','extdom') {
18107: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
18108: foreach my $roletype ('domain','author','course','community') {
18109: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
18110: $domdefaults{'userapprovals'} = 1;
18111: last;
18112: }
18113: }
18114: }
18115: last if ($domdefaults{'userapprovals'});
18116: }
18117: }
18118: my $cachetime = 24*60*60;
18119: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18120: if (ref($lastactref) eq 'HASH') {
18121: $lastactref->{'domdefaults'} = 1;
18122: }
18123: }
1.357 raeburn 18124: } else {
18125: $resulttext = &mt('No changes made to user information settings');
18126: }
18127: } else {
18128: $resulttext = '<span class="LC_error">'.
18129: &mt('An error occurred: [_1]',$putresult).'</span>';
18130: }
18131: return $resulttext;
18132: }
18133:
1.354 raeburn 18134: sub modify_passwords {
18135: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18136: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18137: $updatedefaults,$updateconf);
1.354 raeburn 18138: my $customfn = 'resetpw.html';
18139: if (ref($domconfig{'passwords'}) eq 'HASH') {
18140: %current = %{$domconfig{'passwords'}};
18141: }
18142: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18143: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18144: if (ref($types) eq 'ARRAY') {
18145: @oktypes = @{$types};
18146: }
18147: push(@oktypes,'default');
18148:
18149: my %titles = &Apache::lonlocal::texthash (
18150: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18151: intauth_check => 'Check bcrypt cost if authenticated',
18152: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18153: permanent => 'Permanent e-mail address',
18154: critical => 'Critical notification address',
18155: notify => 'Notification address',
18156: min => 'Minimum password length',
18157: max => 'Maximum password length',
18158: chars => 'Required characters',
18159: expire => 'Password expiration (days)',
1.356 raeburn 18160: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18161: reset => 'Resetting Forgotten Password',
18162: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18163: rules => 'Rules for LON-CAPA Passwords',
18164: crsownerchg => 'Course Owner Changing Student Passwords',
18165: username => 'Username',
18166: email => 'E-mail address',
18167: );
18168:
18169: #
18170: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18171: #
18172: my (%curr_defaults,%save_defaults);
18173: if (ref($domconfig{'defaults'}) eq 'HASH') {
18174: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18175: if ($key =~ /^intauth_(cost|check|switch)$/) {
18176: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18177: } else {
18178: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18179: }
18180: }
18181: }
18182: my %staticdefaults = (
18183: 'resetlink' => 2,
18184: 'resetcase' => \@oktypes,
18185: 'resetprelink' => 'both',
18186: 'resetemail' => ['critical','notify','permanent'],
18187: 'intauth_cost' => 10,
18188: 'intauth_check' => 0,
18189: 'intauth_switch' => 0,
18190: );
1.365 raeburn 18191: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18192: foreach my $type (@oktypes) {
18193: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18194: }
18195: my $linklife = $env{'form.passwords_link'};
18196: $linklife =~ s/^\s+|\s+$//g;
18197: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18198: $newvalues{'resetlink'} = $linklife;
18199: if ($current{'resetlink'}) {
18200: if ($current{'resetlink'} ne $linklife) {
18201: $changes{'reset'} = 1;
18202: }
1.368 raeburn 18203: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18204: if ($staticdefaults{'resetlink'} ne $linklife) {
18205: $changes{'reset'} = 1;
18206: }
18207: }
18208: } elsif ($current{'resetlink'}) {
18209: $changes{'reset'} = 1;
18210: }
18211: my @casesens;
18212: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18213: foreach my $case (sort(@posscase)) {
18214: if (grep(/^\Q$case\E$/,@oktypes)) {
18215: push(@casesens,$case);
18216: }
18217: }
18218: $newvalues{'resetcase'} = \@casesens;
18219: if (ref($current{'resetcase'}) eq 'ARRAY') {
18220: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18221: if (@diffs > 0) {
18222: $changes{'reset'} = 1;
18223: }
1.368 raeburn 18224: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18225: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18226: if (@diffs > 0) {
18227: $changes{'reset'} = 1;
18228: }
18229: }
18230: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18231: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18232: if (exists($current{'resetprelink'})) {
18233: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18234: $changes{'reset'} = 1;
18235: }
1.368 raeburn 18236: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18237: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18238: $changes{'reset'} = 1;
18239: }
18240: }
18241: } elsif ($current{'resetprelink'}) {
18242: $changes{'reset'} = 1;
18243: }
18244: foreach my $type (@oktypes) {
18245: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18246: my @postlink;
18247: foreach my $item (sort(@possplink)) {
18248: if ($item =~ /^(email|username)$/) {
18249: push(@postlink,$item);
18250: }
18251: }
18252: $newvalues{'resetpostlink'}{$type} = \@postlink;
18253: unless ($changes{'reset'}) {
18254: if (ref($current{'resetpostlink'}) eq 'HASH') {
18255: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18256: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18257: if (@diffs > 0) {
18258: $changes{'reset'} = 1;
18259: }
18260: } else {
18261: $changes{'reset'} = 1;
18262: }
1.368 raeburn 18263: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18264: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18265: if (@diffs > 0) {
18266: $changes{'reset'} = 1;
18267: }
18268: }
18269: }
18270: }
18271: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18272: my @resetemail;
18273: foreach my $item (sort(@possemailsrc)) {
18274: if ($item =~ /^(permanent|critical|notify)$/) {
18275: push(@resetemail,$item);
18276: }
18277: }
18278: $newvalues{'resetemail'} = \@resetemail;
18279: unless ($changes{'reset'}) {
18280: if (ref($current{'resetemail'}) eq 'ARRAY') {
18281: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18282: if (@diffs > 0) {
18283: $changes{'reset'} = 1;
18284: }
1.368 raeburn 18285: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18286: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18287: if (@diffs > 0) {
18288: $changes{'reset'} = 1;
18289: }
18290: }
18291: }
18292: if ($env{'form.passwords_stdtext'} == 0) {
18293: $newvalues{'resetremove'} = 1;
18294: unless ($current{'resetremove'}) {
18295: $changes{'reset'} = 1;
18296: }
18297: } elsif ($current{'resetremove'}) {
18298: $changes{'reset'} = 1;
18299: }
18300: if ($env{'form.passwords_customfile.filename'} ne '') {
18301: my $servadm = $r->dir_config('lonAdmEMail');
18302: my ($configuserok,$author_ok,$switchserver) =
18303: &config_check($dom,$confname,$servadm);
18304: my $error;
18305: if ($configuserok eq 'ok') {
18306: if ($switchserver) {
18307: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18308: } else {
18309: if ($author_ok eq 'ok') {
1.421 raeburn 18310: my $modified = [];
1.354 raeburn 18311: my ($result,$customurl) =
1.421 raeburn 18312: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18313: $confname,'customtext/resetpw','','',$customfn,
18314: $modified);
1.354 raeburn 18315: if ($result eq 'ok') {
18316: $newvalues{'resetcustom'} = $customurl;
18317: $changes{'reset'} = 1;
1.421 raeburn 18318: &update_modify_urls($r,$modified);
1.354 raeburn 18319: } else {
18320: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18321: }
18322: } else {
18323: $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);
18324: }
18325: }
18326: } else {
18327: $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);
18328: }
18329: if ($error) {
18330: &Apache::lonnet::logthis($error);
18331: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18332: }
18333: } elsif ($current{'resetcustom'}) {
18334: if ($env{'form.passwords_custom_del'}) {
18335: $changes{'reset'} = 1;
18336: } else {
18337: $newvalues{'resetcustom'} = $current{'resetcustom'};
18338: }
18339: }
18340: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18341: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18342: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18343: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18344: $changes{'intauth'} = 1;
18345: }
18346: } else {
18347: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18348: }
18349: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18350: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18351: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18352: $changes{'intauth'} = 1;
18353: }
18354: } else {
18355: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18356: }
18357: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18358: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18359: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18360: $changes{'intauth'} = 1;
18361: }
18362: } else {
18363: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18364: }
18365: foreach my $item ('cost','check','switch') {
18366: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18367: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18368: $updatedefaults = 1;
18369: }
18370: }
1.405 raeburn 18371: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18372: my %crsownerchg = (
18373: by => [],
18374: for => [],
18375: );
18376: foreach my $item ('by','for') {
18377: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18378: foreach my $type (sort(@posstypes)) {
18379: if (grep(/^\Q$type\E$/,@oktypes)) {
18380: push(@{$crsownerchg{$item}},$type);
18381: }
18382: }
18383: }
18384: $newvalues{'crsownerchg'} = \%crsownerchg;
18385: if (ref($current{'crsownerchg'}) eq 'HASH') {
18386: foreach my $item ('by','for') {
18387: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18388: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18389: if (@diffs > 0) {
18390: $changes{'crsownerchg'} = 1;
18391: last;
18392: }
18393: }
18394: }
1.368 raeburn 18395: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18396: foreach my $item ('by','for') {
18397: if (@{$crsownerchg{$item}} > 0) {
18398: $changes{'crsownerchg'} = 1;
18399: last;
18400: }
1.354 raeburn 18401: }
18402: }
18403:
18404: my %confighash = (
18405: defaults => \%save_defaults,
18406: passwords => \%newvalues,
18407: );
18408: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18409:
18410: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18411: if ($putresult eq 'ok') {
18412: if (keys(%changes) > 0) {
18413: $resulttext = &mt('Changes made: ').'<ul>';
18414: foreach my $key ('reset','intauth','rules','crsownerchg') {
18415: if ($changes{$key}) {
1.355 raeburn 18416: unless ($key eq 'intauth') {
18417: $updateconf = 1;
18418: }
1.354 raeburn 18419: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18420: if ($key eq 'reset') {
18421: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18422: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18423: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18424: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18425: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18426: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18427: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18428: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18429: }
1.354 raeburn 18430: } else {
18431: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18432: }
18433: if ($confighash{'passwords'}{'resetlink'}) {
18434: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18435: } else {
18436: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18437: &mt('Will default to 2 hours').'</li>';
18438: }
18439: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18440: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18441: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18442: } else {
18443: my $casesens;
18444: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18445: if ($type eq 'default') {
18446: $casesens .= $othertitle.', ';
18447: } elsif ($usertypes->{$type} ne '') {
18448: $casesens .= $usertypes->{$type}.', ';
18449: }
18450: }
18451: $casesens =~ s/\Q, \E$//;
18452: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18453: }
18454: } else {
18455: $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>';
18456: }
18457: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18458: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18459: } else {
18460: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18461: }
18462: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18463: my $output;
18464: if (ref($types) eq 'ARRAY') {
18465: foreach my $type (@{$types}) {
18466: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18467: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18468: $output .= $usertypes->{$type}.' -- '.&mt('none');
18469: } else {
18470: $output .= $usertypes->{$type}.' -- '.
18471: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18472: }
18473: }
18474: }
18475: }
18476: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18477: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18478: $output .= $othertitle.' -- '.&mt('none');
18479: } else {
18480: $output .= $othertitle.' -- '.
18481: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18482: }
18483: }
18484: if ($output) {
18485: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18486: } else {
18487: $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>';
18488: }
18489: } else {
18490: $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>';
18491: }
18492: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18493: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18494: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18495: } else {
18496: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18497: }
18498: } else {
1.379 raeburn 18499: $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 18500: }
18501: if ($confighash{'passwords'}{'resetremove'}) {
18502: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18503: } else {
18504: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18505: }
18506: if ($confighash{'passwords'}{'resetcustom'}) {
18507: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18508: &mt('custom text'),600,500,undef,undef,
18509: undef,undef,'background-color:#ffffff');
18510: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18511: } else {
18512: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18513: }
18514: } elsif ($key eq 'intauth') {
18515: foreach my $item ('cost','switch','check') {
18516: my $value = $save_defaults{$key.'_'.$item};
18517: if ($item eq 'switch') {
18518: my %optiondesc = &Apache::lonlocal::texthash (
18519: 0 => 'No',
18520: 1 => 'Yes',
18521: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18522: );
18523: if ($value =~ /^(0|1|2)$/) {
18524: $value = $optiondesc{$value};
18525: } else {
18526: $value = &mt('none -- defaults to No');
18527: }
18528: } elsif ($item eq 'check') {
18529: my %optiondesc = &Apache::lonlocal::texthash (
18530: 0 => 'No',
18531: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18532: 2 => 'Yes, disallow login if stored cost is less than domain default',
18533: );
18534: if ($value =~ /^(0|1|2)$/) {
18535: $value = $optiondesc{$value};
18536: } else {
18537: $value = &mt('none -- defaults to No');
18538: }
18539: }
18540: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18541: }
18542: } elsif ($key eq 'rules') {
1.356 raeburn 18543: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18544: if ($confighash{'passwords'}{$rule} eq '') {
18545: if ($rule eq 'min') {
1.356 raeburn 18546: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18547: ' '.&mt('Default of [_1] will be used',
18548: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18549: } else {
18550: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18551: }
18552: } else {
18553: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18554: }
18555: }
1.370 raeburn 18556: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18557: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18558: my %rulenames = &Apache::lonlocal::texthash(
18559: uc => 'At least one upper case letter',
18560: lc => 'At least one lower case letter',
18561: num => 'At least one number',
18562: spec => 'At least one non-alphanumeric',
18563: );
18564: my $needed = '<ul><li>'.
18565: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18566: '</li></ul>';
1.370 raeburn 18567: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18568: } else {
18569: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18570: }
18571: } else {
18572: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18573: }
1.354 raeburn 18574: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18575: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18576: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18577: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18578: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18579: } else {
18580: my %crsownerstr;
18581: foreach my $item ('by','for') {
18582: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18583: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18584: if ($type eq 'default') {
18585: $crsownerstr{$item} .= $othertitle.', ';
18586: } elsif ($usertypes->{$type} ne '') {
18587: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18588: }
18589: }
18590: $crsownerstr{$item} =~ s/\Q, \E$//;
18591: }
18592: }
18593: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18594: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18595: }
1.354 raeburn 18596: } else {
1.359 raeburn 18597: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18598: }
18599: }
18600: $resulttext .= '</ul></li>';
18601: }
18602: }
18603: $resulttext .= '</ul>';
18604: } else {
18605: $resulttext = &mt('No changes made to password settings');
18606: }
1.355 raeburn 18607: my $cachetime = 24*60*60;
1.354 raeburn 18608: if ($updatedefaults) {
18609: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18610: if (ref($lastactref) eq 'HASH') {
18611: $lastactref->{'domdefaults'} = 1;
18612: }
18613: }
1.355 raeburn 18614: if ($updateconf) {
18615: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18616: if (ref($lastactref) eq 'HASH') {
18617: $lastactref->{'passwdconf'} = 1;
18618: }
18619: }
1.354 raeburn 18620: } else {
18621: $resulttext = '<span class="LC_error">'.
18622: &mt('An error occurred: [_1]',$putresult).'</span>';
18623: }
18624: if ($errors) {
18625: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18626: $errors.'</ul></p>';
18627: }
18628: return $resulttext;
18629: }
18630:
1.405 raeburn 18631: sub password_rule_changes {
18632: my ($prefix,$newvalues,$current,$changes) = @_;
18633: return unless ((ref($newvalues) eq 'HASH') &&
18634: (ref($current) eq 'HASH') &&
18635: (ref($changes) eq 'HASH'));
18636: my (@rules,%staticdefaults);
18637: if ($prefix eq 'passwords') {
18638: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18639: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18640: @rules = ('min','max');
18641: }
18642: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18643: foreach my $rule (@rules) {
18644: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18645: my $ruleok;
18646: if ($rule eq 'expire') {
18647: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18648: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18649: $ruleok = 1;
18650: }
18651: } elsif ($rule eq 'min') {
18652: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18653: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18654: $ruleok = 1;
18655: }
18656: }
18657: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18658: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18659: $ruleok = 1;
18660: }
18661: if ($ruleok) {
18662: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18663: if (exists($current->{$rule})) {
18664: if ($newvalues->{$rule} ne $current->{$rule}) {
18665: $changes->{'rules'} = 1;
18666: }
18667: } elsif ($rule eq 'min') {
18668: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18669: $changes->{'rules'} = 1;
18670: }
18671: } else {
18672: $changes->{'rules'} = 1;
18673: }
18674: } elsif (exists($current->{$rule})) {
18675: $changes->{'rules'} = 1;
18676: }
18677: }
18678: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18679: my @chars;
18680: foreach my $item (sort(@posschars)) {
18681: if ($item =~ /^(uc|lc|num|spec)$/) {
18682: push(@chars,$item);
18683: }
18684: }
18685: $newvalues->{'chars'} = \@chars;
18686: unless ($changes->{'rules'}) {
18687: if (ref($current->{'chars'}) eq 'ARRAY') {
18688: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18689: if (@diffs > 0) {
18690: $changes->{'rules'} = 1;
18691: }
18692: } else {
18693: if (@chars > 0) {
18694: $changes->{'rules'} = 1;
18695: }
18696: }
18697: }
18698: return;
18699: }
18700:
1.28 raeburn 18701: sub modify_usercreation {
1.27 raeburn 18702: my ($dom,%domconfig) = @_;
1.224 raeburn 18703: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18704: my $warningmsg;
1.27 raeburn 18705: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18706: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18707: if ($key eq 'cancreate') {
18708: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18709: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18710: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18711: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18712: } else {
1.224 raeburn 18713: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18714: }
18715: }
18716: }
18717: } elsif ($key eq 'email_rule') {
18718: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18719: } else {
18720: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18721: }
1.27 raeburn 18722: }
18723: }
18724: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18725: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18726: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18727: foreach my $item(@contexts) {
1.224 raeburn 18728: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18729: }
1.34 raeburn 18730: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18731: foreach my $item (@contexts) {
1.224 raeburn 18732: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18733: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18734: }
1.27 raeburn 18735: }
1.34 raeburn 18736: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18737: foreach my $item (@contexts) {
1.43 raeburn 18738: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18739: if ($cancreate{$item} ne 'any') {
18740: push(@{$changes{'cancreate'}},$item);
18741: }
18742: } else {
18743: if ($cancreate{$item} ne 'none') {
18744: push(@{$changes{'cancreate'}},$item);
18745: }
1.27 raeburn 18746: }
18747: }
18748: } else {
1.43 raeburn 18749: foreach my $item (@contexts) {
1.34 raeburn 18750: push(@{$changes{'cancreate'}},$item);
18751: }
1.27 raeburn 18752: }
1.34 raeburn 18753:
1.27 raeburn 18754: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18755: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18756: if (!grep(/^\Q$type\E$/,@username_rule)) {
18757: push(@{$changes{'username_rule'}},$type);
18758: }
18759: }
18760: foreach my $type (@username_rule) {
18761: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18762: push(@{$changes{'username_rule'}},$type);
18763: }
18764: }
18765: } else {
18766: push(@{$changes{'username_rule'}},@username_rule);
18767: }
18768:
1.32 raeburn 18769: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18770: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18771: if (!grep(/^\Q$type\E$/,@id_rule)) {
18772: push(@{$changes{'id_rule'}},$type);
18773: }
18774: }
18775: foreach my $type (@id_rule) {
18776: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18777: push(@{$changes{'id_rule'}},$type);
18778: }
18779: }
18780: } else {
18781: push(@{$changes{'id_rule'}},@id_rule);
18782: }
18783:
1.43 raeburn 18784: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18785: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18786: my %authhash;
1.43 raeburn 18787: foreach my $item (@authen_contexts) {
1.28 raeburn 18788: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18789: foreach my $auth (@authtypes) {
18790: if (grep(/^\Q$auth\E$/,@authallowed)) {
18791: $authhash{$item}{$auth} = 1;
18792: } else {
18793: $authhash{$item}{$auth} = 0;
18794: }
18795: }
18796: }
18797: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18798: foreach my $item (@authen_contexts) {
1.28 raeburn 18799: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18800: foreach my $auth (@authtypes) {
18801: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18802: push(@{$changes{'authtypes'}},$item);
18803: last;
18804: }
18805: }
18806: }
18807: }
18808: } else {
1.43 raeburn 18809: foreach my $item (@authen_contexts) {
1.28 raeburn 18810: push(@{$changes{'authtypes'}},$item);
18811: }
18812: }
18813:
1.224 raeburn 18814: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18815: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18816: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18817: $save_usercreate{'id_rule'} = \@id_rule;
18818: $save_usercreate{'username_rule'} = \@username_rule,
18819: $save_usercreate{'authtypes'} = \%authhash;
18820:
1.27 raeburn 18821: my %usercreation_hash = (
1.224 raeburn 18822: usercreation => \%save_usercreate,
18823: );
1.27 raeburn 18824:
18825: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18826: $dom);
1.50 raeburn 18827:
1.224 raeburn 18828: if ($putresult eq 'ok') {
18829: if (keys(%changes) > 0) {
18830: $resulttext = &mt('Changes made:').'<ul>';
18831: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18832: my %lt = &usercreation_types();
18833: foreach my $type (@{$changes{'cancreate'}}) {
18834: my $chgtext = $lt{$type}.', ';
18835: if ($cancreate{$type} eq 'none') {
18836: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18837: } elsif ($cancreate{$type} eq 'any') {
18838: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18839: } elsif ($cancreate{$type} eq 'official') {
18840: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18841: } elsif ($cancreate{$type} eq 'unofficial') {
18842: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18843: }
18844: $resulttext .= '<li>'.$chgtext.'</li>';
18845: }
18846: }
18847: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18848: my ($rules,$ruleorder) =
18849: &Apache::lonnet::inst_userrules($dom,'username');
18850: my $chgtext = '<ul>';
18851: foreach my $type (@username_rule) {
18852: if (ref($rules->{$type}) eq 'HASH') {
18853: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18854: }
18855: }
18856: $chgtext .= '</ul>';
18857: if (@username_rule > 0) {
18858: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18859: } else {
18860: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18861: }
18862: }
18863: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18864: my ($idrules,$idruleorder) =
18865: &Apache::lonnet::inst_userrules($dom,'id');
18866: my $chgtext = '<ul>';
18867: foreach my $type (@id_rule) {
18868: if (ref($idrules->{$type}) eq 'HASH') {
18869: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18870: }
18871: }
18872: $chgtext .= '</ul>';
18873: if (@id_rule > 0) {
18874: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18875: } else {
18876: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18877: }
18878: }
18879: my %authname = &authtype_names();
18880: my %context_title = &context_names();
18881: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18882: my $chgtext = '<ul>';
18883: foreach my $type (@{$changes{'authtypes'}}) {
18884: my @allowed;
18885: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18886: foreach my $auth (@authtypes) {
18887: if ($authhash{$type}{$auth}) {
18888: push(@allowed,$authname{$auth});
18889: }
18890: }
18891: if (@allowed > 0) {
18892: $chgtext .= join(', ',@allowed).'</li>';
18893: } else {
18894: $chgtext .= &mt('none').'</li>';
18895: }
18896: }
18897: $chgtext .= '</ul>';
18898: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18899: $resulttext .= '</li>';
18900: }
18901: $resulttext .= '</ul>';
18902: } else {
18903: $resulttext = &mt('No changes made to user creation settings');
18904: }
18905: } else {
18906: $resulttext = '<span class="LC_error">'.
18907: &mt('An error occurred: [_1]',$putresult).'</span>';
18908: }
18909: if ($warningmsg ne '') {
18910: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18911: }
18912: return $resulttext;
18913: }
18914:
18915: sub modify_selfcreation {
1.305 raeburn 18916: my ($dom,$lastactref,%domconfig) = @_;
18917: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18918: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18919: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18920: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18921: if (ref($typesref) eq 'ARRAY') {
18922: @types = @{$typesref};
18923: }
18924: if (ref($usertypesref) eq 'HASH') {
18925: %usertypes = %{$usertypesref};
1.228 raeburn 18926: }
1.303 raeburn 18927: $usertypes{'default'} = $othertitle;
1.224 raeburn 18928: #
18929: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18930: #
18931: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18932: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18933: if ($key eq 'cancreate') {
18934: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18935: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18936: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18937: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18938: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18939: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18940: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18941: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18942: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18943: } else {
18944: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18945: }
18946: }
18947: }
18948: } elsif ($key eq 'email_rule') {
18949: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18950: } else {
18951: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18952: }
18953: }
18954: }
18955: #
18956: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18957: #
18958: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18959: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18960: if ($key eq 'selfcreate') {
18961: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18962: } else {
18963: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18964: }
18965: }
18966: }
1.305 raeburn 18967: #
18968: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18969: #
18970: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18971: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18972: if ($key eq 'inststatusguest') {
18973: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18974: } else {
18975: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18976: }
18977: }
18978: }
1.224 raeburn 18979:
18980: my @contexts = ('selfcreate');
18981: @{$cancreate{'selfcreate'}} = ();
18982: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18983: if (@types) {
18984: @{$cancreate{'statustocreate'}} = ();
18985: }
1.236 raeburn 18986: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18987: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18988: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18989: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18990: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18991: my %selfcreatetypes = (
18992: sso => 'users authenticated by institutional single sign on',
18993: login => 'users authenticated by institutional log-in',
1.303 raeburn 18994: email => 'users verified by e-mail',
1.50 raeburn 18995: );
1.224 raeburn 18996: #
18997: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18998: # is permitted.
18999: #
1.305 raeburn 19000: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 19001:
1.305 raeburn 19002: my (@statuses,%email_rule);
1.228 raeburn 19003: foreach my $item ('login','sso','email') {
1.224 raeburn 19004: if ($item eq 'email') {
1.236 raeburn 19005: if ($env{'form.cancreate_email'}) {
1.305 raeburn 19006: if (@types) {
19007: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
19008: foreach my $status (@poss_statuses) {
19009: if (grep(/^\Q$status\E$/,(@types,'default'))) {
19010: push(@statuses,$status);
19011: }
19012: }
19013: $save_inststatus{'inststatusguest'} = \@statuses;
19014: } else {
19015: push(@statuses,'default');
19016: }
19017: if (@statuses) {
19018: my %curr_rule;
19019: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
19020: foreach my $type (@statuses) {
19021: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 19022: }
1.305 raeburn 19023: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
19024: foreach my $type (@statuses) {
19025: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
19026: }
19027: }
19028: push(@{$cancreate{'selfcreate'}},'email');
19029: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
19030: my %curremaildom;
19031: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
19032: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
19033: }
19034: foreach my $type (@statuses) {
19035: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
19036: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
19037: }
19038: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
19039: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
19040: }
19041: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
19042: #
19043: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
19044: #
19045: my $chosen = $1;
19046: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
19047: my $emaildom;
19048: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 19049: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 19050: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
19051: if (ref($curremaildom{$type}) eq 'HASH') {
19052: if (exists($curremaildom{$type}{$chosen})) {
19053: if ($curremaildom{$type}{$chosen} ne $emaildom) {
19054: push(@{$changes{'cancreate'}},'emaildomain');
19055: }
19056: } elsif ($emaildom ne '') {
19057: push(@{$changes{'cancreate'}},'emaildomain');
19058: }
19059: } elsif ($emaildom ne '') {
19060: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 19061: }
1.305 raeburn 19062: }
19063: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19064: } elsif ($chosen eq 'custom') {
19065: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
19066: $email_rule{$type} = [];
19067: if (ref($emailrules) eq 'HASH') {
19068: foreach my $rule (@possemail_rules) {
19069: if (exists($emailrules->{$rule})) {
19070: push(@{$email_rule{$type}},$rule);
19071: }
19072: }
19073: }
19074: if (@{$email_rule{$type}}) {
19075: $cancreate{'emailoptions'}{$type} = 'custom';
19076: if (ref($curr_rule{$type}) eq 'ARRAY') {
19077: if (@{$curr_rule{$type}} > 0) {
19078: foreach my $rule (@{$curr_rule{$type}}) {
19079: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
19080: push(@{$changes{'email_rule'}},$type);
19081: }
19082: }
19083: }
19084: foreach my $type (@{$email_rule{$type}}) {
19085: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
19086: push(@{$changes{'email_rule'}},$type);
19087: }
19088: }
19089: } else {
19090: push(@{$changes{'email_rule'}},$type);
19091: }
19092: }
19093: } else {
19094: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19095: }
19096: }
19097: }
19098: if (@types) {
19099: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19100: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
19101: if (@changed) {
19102: push(@{$changes{'inststatus'}},'inststatusguest');
19103: }
19104: } else {
19105: push(@{$changes{'inststatus'}},'inststatusguest');
19106: }
19107: }
19108: } else {
19109: delete($env{'form.cancreate_email'});
19110: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19111: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19112: push(@{$changes{'inststatus'}},'inststatusguest');
19113: }
19114: }
19115: }
19116: } else {
19117: $save_inststatus{'inststatusguest'} = [];
19118: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19119: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19120: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 19121: }
19122: }
1.224 raeburn 19123: }
19124: } else {
19125: if ($env{'form.cancreate_'.$item}) {
19126: push(@{$cancreate{'selfcreate'}},$item);
19127: }
19128: }
19129: }
1.305 raeburn 19130: my (%userinfo,%savecaptcha);
1.224 raeburn 19131: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
19132: #
1.228 raeburn 19133: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
19134: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19135: #
1.236 raeburn 19136:
1.244 raeburn 19137: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19138: push(@contexts,'emailusername');
1.305 raeburn 19139: if (@statuses) {
19140: foreach my $type (@statuses) {
1.228 raeburn 19141: if (ref($infofields) eq 'ARRAY') {
19142: foreach my $field (@{$infofields}) {
19143: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19144: $cancreate{'emailusername'}{$type}{$field} = $1;
19145: }
19146: }
1.224 raeburn 19147: }
19148: }
19149: }
19150: #
19151: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19152: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19153: #
19154:
19155: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19156: @approvalnotify = sort(@approvalnotify);
19157: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19158: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19159: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19160: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19161: push(@{$changes{'cancreate'}},'notify');
19162: }
19163: } else {
19164: if ($cancreate{'notify'}{'approval'}) {
19165: push(@{$changes{'cancreate'}},'notify');
19166: }
19167: }
19168: } elsif ($cancreate{'notify'}{'approval'}) {
19169: push(@{$changes{'cancreate'}},'notify');
19170: }
19171:
19172: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19173: }
19174: #
1.236 raeburn 19175: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19176: # institutional log-in.
19177: #
19178: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19179: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19180: ($domdefaults{'auth_def'} eq 'localauth'))) {
19181: $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.').' '.
19182: &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.');
19183: }
19184: }
19185: my @fields = ('lastname','firstname','middlename','generation',
19186: 'permanentemail','id');
1.240 raeburn 19187: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19188: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19189: #
19190: # Where usernames may created for institutional log-in and/or institutional single sign on:
19191: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19192: # may self-create accounts
19193: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19194: # which the user may supply, if institutional data is unavailable.
19195: #
19196: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19197: if (@types) {
1.305 raeburn 19198: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19199: push(@contexts,'statustocreate');
1.303 raeburn 19200: foreach my $type (@types) {
1.224 raeburn 19201: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19202: foreach my $field (@fields) {
19203: if (grep(/^\Q$field\E$/,@modifiable)) {
19204: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19205: } else {
19206: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19207: }
19208: }
19209: }
19210: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19211: foreach my $type (@types) {
1.224 raeburn 19212: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19213: foreach my $field (@fields) {
19214: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19215: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19216: push(@{$changes{'selfcreate'}},$type);
19217: last;
19218: }
19219: }
19220: }
19221: }
19222: } else {
1.303 raeburn 19223: foreach my $type (@types) {
1.224 raeburn 19224: push(@{$changes{'selfcreate'}},$type);
19225: }
19226: }
19227: }
1.240 raeburn 19228: foreach my $field (@shibfields) {
19229: if ($env{'form.shibenv_'.$field} ne '') {
19230: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19231: }
19232: }
19233: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19234: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19235: foreach my $field (@shibfields) {
19236: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19237: push(@{$changes{'cancreate'}},'shibenv');
19238: }
19239: }
19240: } else {
19241: foreach my $field (@shibfields) {
19242: if ($env{'form.shibenv_'.$field}) {
19243: push(@{$changes{'cancreate'}},'shibenv');
19244: last;
19245: }
19246: }
19247: }
19248: }
1.224 raeburn 19249: }
19250: foreach my $item (@contexts) {
19251: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19252: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19253: if (ref($cancreate{$item}) eq 'ARRAY') {
19254: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19255: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19256: push(@{$changes{'cancreate'}},$item);
19257: }
19258: }
19259: }
19260: }
19261: if (ref($cancreate{$item}) eq 'ARRAY') {
19262: foreach my $type (@{$cancreate{$item}}) {
19263: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19264: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19265: push(@{$changes{'cancreate'}},$item);
19266: }
19267: }
19268: }
19269: }
19270: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19271: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19272: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19273: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19274: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19275: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19276: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19277: push(@{$changes{'cancreate'}},$item);
19278: }
19279: }
19280: }
1.305 raeburn 19281: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19282: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19283: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19284: push(@{$changes{'cancreate'}},$item);
19285: }
1.224 raeburn 19286: }
19287: }
19288: }
1.305 raeburn 19289: foreach my $type (keys(%{$cancreate{$item}})) {
19290: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19291: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19292: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19293: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19294: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19295: push(@{$changes{'cancreate'}},$item);
19296: }
19297: }
19298: } else {
19299: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19300: push(@{$changes{'cancreate'}},$item);
19301: }
19302: }
19303: }
1.305 raeburn 19304: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19305: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19306: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19307: push(@{$changes{'cancreate'}},$item);
19308: }
1.224 raeburn 19309: }
19310: }
19311: }
19312: }
19313: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19314: if (ref($cancreate{$item}) eq 'ARRAY') {
19315: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19316: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19317: push(@{$changes{'cancreate'}},$item);
19318: }
19319: }
1.305 raeburn 19320: }
19321: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19322: if (ref($cancreate{$item}) eq 'HASH') {
19323: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19324: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19325: }
19326: }
19327: } elsif ($item eq 'emailusername') {
1.228 raeburn 19328: if (ref($cancreate{$item}) eq 'HASH') {
19329: foreach my $type (keys(%{$cancreate{$item}})) {
19330: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19331: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19332: if ($cancreate{$item}{$type}{$field}) {
19333: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19334: push(@{$changes{'cancreate'}},$item);
19335: }
19336: last;
19337: }
19338: }
19339: }
19340: }
1.224 raeburn 19341: }
19342: }
19343: }
19344: #
19345: # Populate %save_usercreate hash with updates to self-creation configuration.
19346: #
19347: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19348: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19349: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19350: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19351: if (ref($cancreate{'notify'}) eq 'HASH') {
19352: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19353: }
1.236 raeburn 19354: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19355: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19356: }
1.303 raeburn 19357: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19358: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19359: }
1.305 raeburn 19360: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19361: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19362: }
1.303 raeburn 19363: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19364: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19365: }
1.224 raeburn 19366: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19367: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19368: }
1.240 raeburn 19369: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19370: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19371: }
1.224 raeburn 19372: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19373: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19374:
19375: my %userconfig_hash = (
19376: usercreation => \%save_usercreate,
19377: usermodification => \%save_usermodify,
1.305 raeburn 19378: inststatus => \%save_inststatus,
1.224 raeburn 19379: );
1.305 raeburn 19380:
1.224 raeburn 19381: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19382: $dom);
19383: #
1.305 raeburn 19384: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19385: #
1.27 raeburn 19386: if ($putresult eq 'ok') {
19387: if (keys(%changes) > 0) {
19388: $resulttext = &mt('Changes made:').'<ul>';
19389: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19390: my %lt = &selfcreation_types();
1.34 raeburn 19391: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19392: my $chgtext = '';
1.45 raeburn 19393: if ($type eq 'selfcreate') {
1.50 raeburn 19394: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19395: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19396: } else {
1.224 raeburn 19397: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19398: '<ul>';
1.50 raeburn 19399: foreach my $case (@{$cancreate{$type}}) {
19400: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19401: }
19402: $chgtext .= '</ul>';
1.100 raeburn 19403: if (ref($cancreate{$type}) eq 'ARRAY') {
19404: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19405: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19406: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19407: $chgtext .= '<span class="LC_warning">'.
19408: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19409: '</span><br />';
19410: }
19411: }
19412: }
19413: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19414: if (!@statuses) {
19415: $chgtext .= '<span class="LC_warning">'.
19416: &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.").
19417: '</span><br />';
1.303 raeburn 19418:
1.100 raeburn 19419: }
19420: }
19421: }
1.43 raeburn 19422: }
1.240 raeburn 19423: } elsif ($type eq 'shibenv') {
19424: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19425: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19426: } else {
19427: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19428: '<ul>';
19429: foreach my $field (@shibfields) {
19430: next if ($cancreate{$type}{$field} eq '');
19431: if ($field eq 'inststatus') {
19432: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19433: } else {
19434: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19435: }
19436: }
19437: $chgtext .= '</ul>';
1.303 raeburn 19438: }
1.93 raeburn 19439: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19440: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19441: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19442: if (@{$cancreate{'selfcreate'}} > 0) {
19443: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19444: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19445: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19446: $chgtext .= '<br />'.
19447: '<span class="LC_warning">'.
19448: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19449: '</span>';
19450: }
1.303 raeburn 19451: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19452: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19453: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19454: } else {
19455: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19456: }
19457: $chgtext .= '<ul>';
19458: foreach my $case (@{$cancreate{$type}}) {
19459: if ($case eq 'default') {
19460: $chgtext .= '<li>'.$othertitle.'</li>';
19461: } else {
1.303 raeburn 19462: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19463: }
19464: }
1.100 raeburn 19465: $chgtext .= '</ul>';
19466: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19467: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19468: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19469: '</span>';
1.100 raeburn 19470: }
19471: }
19472: } else {
19473: if (@{$cancreate{$type}} == 0) {
19474: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19475: } else {
19476: $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 19477: }
19478: }
1.303 raeburn 19479: $chgtext .= '<br />';
1.93 raeburn 19480: }
1.236 raeburn 19481: } elsif ($type eq 'selfcreateprocessing') {
19482: my %choices = &Apache::lonlocal::texthash (
19483: automatic => 'Automatic approval',
19484: approval => 'Queued for approval',
19485: );
1.305 raeburn 19486: if (@types) {
19487: if (@statuses) {
1.425 raeburn 19488: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19489: '<ul>';
1.305 raeburn 19490: foreach my $status (@statuses) {
19491: if ($status eq 'default') {
19492: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19493: } else {
1.305 raeburn 19494: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19495: }
19496: }
19497: $chgtext .= '</ul>';
19498: }
19499: } else {
19500: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19501: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19502: }
19503: } elsif ($type eq 'emailverified') {
19504: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19505: all => 'Same as e-mail',
19506: first => 'Omit @domain',
19507: free => 'Free to choose',
1.303 raeburn 19508: );
1.305 raeburn 19509: if (@types) {
19510: if (@statuses) {
1.303 raeburn 19511: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19512: '<ul>';
1.305 raeburn 19513: foreach my $status (@statuses) {
1.362 raeburn 19514: if ($status eq 'default') {
1.305 raeburn 19515: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19516: } else {
1.305 raeburn 19517: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19518: }
19519: }
19520: $chgtext .= '</ul>';
19521: }
19522: } else {
1.305 raeburn 19523: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19524: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19525: }
1.305 raeburn 19526: } elsif ($type eq 'emailoptions') {
19527: my %options = &Apache::lonlocal::texthash (
19528: any => 'Any e-mail',
19529: inst => 'Institutional only',
19530: noninst => 'Non-institutional only',
19531: custom => 'Custom restrictions',
19532: );
19533: if (@types) {
19534: if (@statuses) {
19535: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19536: '<ul>';
19537: foreach my $status (@statuses) {
19538: if ($type eq 'default') {
19539: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19540: } else {
19541: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19542: }
19543: }
1.305 raeburn 19544: $chgtext .= '</ul>';
19545: }
19546: } else {
19547: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19548: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19549: } else {
19550: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19551: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19552: }
1.305 raeburn 19553: }
19554: } elsif ($type eq 'emaildomain') {
19555: my $output;
19556: if (@statuses) {
19557: foreach my $type (@statuses) {
19558: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19559: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19560: if ($type eq 'default') {
19561: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19562: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19563: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19564: } else {
19565: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19566: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19567: }
1.303 raeburn 19568: } else {
1.305 raeburn 19569: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19570: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19571: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19572: } else {
19573: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19574: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19575: }
1.303 raeburn 19576: }
1.305 raeburn 19577: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19578: if ($type eq 'default') {
19579: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19580: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19581: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19582: } else {
19583: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19584: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19585: }
1.303 raeburn 19586: } else {
1.305 raeburn 19587: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19588: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19589: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19590: } else {
19591: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19592: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19593: }
1.303 raeburn 19594: }
19595: }
19596: }
19597: }
1.305 raeburn 19598: }
19599: if ($output ne '') {
19600: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19601: '<ul>'.$output.'</ul>';
1.236 raeburn 19602: }
1.165 raeburn 19603: } elsif ($type eq 'captcha') {
1.224 raeburn 19604: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19605: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19606: } else {
19607: my %captchas = &captcha_phrases();
1.224 raeburn 19608: if ($captchas{$savecaptcha{$type}}) {
19609: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19610: } else {
1.210 raeburn 19611: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19612: }
19613: }
19614: } elsif ($type eq 'recaptchakeys') {
19615: my ($privkey,$pubkey);
1.224 raeburn 19616: if (ref($savecaptcha{$type}) eq 'HASH') {
19617: $pubkey = $savecaptcha{$type}{'public'};
19618: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19619: }
19620: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19621: if (!$pubkey) {
19622: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19623: } else {
19624: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19625: }
19626: if (!$privkey) {
19627: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19628: } else {
19629: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19630: }
19631: $chgtext .= '</ul>';
1.269 raeburn 19632: } elsif ($type eq 'recaptchaversion') {
19633: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19634: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19635: }
1.224 raeburn 19636: } elsif ($type eq 'emailusername') {
19637: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19638: if (@statuses) {
19639: foreach my $type (@statuses) {
1.228 raeburn 19640: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19641: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19642: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19643: '<ul>';
19644: foreach my $field (@{$infofields}) {
19645: if ($cancreate{'emailusername'}{$type}{$field}) {
19646: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19647: }
19648: }
1.245 raeburn 19649: $chgtext .= '</ul>';
19650: } else {
1.303 raeburn 19651: $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 19652: }
19653: } else {
1.303 raeburn 19654: $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 19655: }
19656: }
19657: }
19658: }
19659: } elsif ($type eq 'notify') {
1.303 raeburn 19660: my $numapprove = 0;
1.224 raeburn 19661: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19662: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19663: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19664: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19665: $numapprove ++;
1.224 raeburn 19666: }
19667: }
1.43 raeburn 19668: }
1.303 raeburn 19669: unless ($numapprove) {
19670: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19671: }
1.34 raeburn 19672: }
1.224 raeburn 19673: if ($chgtext) {
19674: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19675: }
19676: }
19677: }
1.305 raeburn 19678: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19679: my ($emailrules,$emailruleorder) =
19680: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19681: foreach my $type (@{$changes{'email_rule'}}) {
19682: if (ref($email_rule{$type}) eq 'ARRAY') {
19683: my $chgtext = '<ul>';
19684: foreach my $rule (@{$email_rule{$type}}) {
19685: if (ref($emailrules->{$rule}) eq 'HASH') {
19686: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19687: }
19688: }
19689: $chgtext .= '</ul>';
1.310 raeburn 19690: my $typename;
1.305 raeburn 19691: if (@types) {
19692: if ($type eq 'default') {
19693: $typename = $othertitle;
19694: } else {
19695: $typename = $usertypes{$type};
1.425 raeburn 19696: }
1.305 raeburn 19697: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19698: }
19699: if (@{$email_rule{$type}} > 0) {
19700: $resulttext .= '<li>'.
19701: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19702: $usertypes{$type}).
19703: $chgtext.
19704: '</li>';
19705: } else {
19706: $resulttext .= '<li>'.
1.310 raeburn 19707: &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 19708: '</li>'.
1.310 raeburn 19709: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19710: }
1.43 raeburn 19711: }
19712: }
1.305 raeburn 19713: }
19714: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19715: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19716: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19717: my $chgtext = '<ul>';
19718: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19719: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19720: }
19721: $chgtext .= '</ul>';
19722: $resulttext .= '<li>'.
19723: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19724: $chgtext.
19725: '</li>';
19726: } else {
19727: $resulttext .= '<li>'.
19728: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19729: '</li>';
19730: }
1.43 raeburn 19731: }
19732: }
1.224 raeburn 19733: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19734: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19735: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19736: foreach my $type (@{$changes{'selfcreate'}}) {
19737: my $typename = $type;
1.303 raeburn 19738: if (keys(%usertypes) > 0) {
19739: if ($usertypes{$type} ne '') {
19740: $typename = $usertypes{$type};
1.224 raeburn 19741: }
19742: }
19743: my @modifiable;
19744: $resulttext .= '<li>'.
19745: &mt('Self-creation of account by users with status: [_1]',
19746: '<span class="LC_cusr_emph">'.$typename.'</span>').
19747: ' - '.&mt('modifiable fields (if institutional data blank): ');
19748: foreach my $field (@fields) {
19749: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19750: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19751: }
19752: }
1.224 raeburn 19753: if (@modifiable > 0) {
19754: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19755: } else {
1.224 raeburn 19756: $resulttext .= &mt('none');
1.43 raeburn 19757: }
1.224 raeburn 19758: $resulttext .= '</li>';
1.28 raeburn 19759: }
1.224 raeburn 19760: $resulttext .= '</ul></li>';
1.28 raeburn 19761: }
1.27 raeburn 19762: $resulttext .= '</ul>';
1.305 raeburn 19763: my $cachetime = 24*60*60;
19764: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19765: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19766: if (ref($lastactref) eq 'HASH') {
19767: $lastactref->{'domdefaults'} = 1;
19768: }
1.27 raeburn 19769: } else {
1.224 raeburn 19770: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19771: }
19772: } else {
19773: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19774: &mt('An error occurred: [_1]',$putresult).'</span>';
19775: }
1.43 raeburn 19776: if ($warningmsg ne '') {
19777: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19778: }
1.23 raeburn 19779: return $resulttext;
19780: }
19781:
1.165 raeburn 19782: sub process_captcha {
1.369 raeburn 19783: my ($container,$changes,$newsettings,$currsettings) = @_;
19784: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19785: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19786: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19787: $newsettings->{'captcha'} = 'original';
19788: }
1.369 raeburn 19789: my %current;
19790: if (ref($currsettings) eq 'HASH') {
19791: %current = %{$currsettings};
19792: }
19793: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19794: if ($container eq 'cancreate') {
1.169 raeburn 19795: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19796: push(@{$changes->{'cancreate'}},'captcha');
19797: } elsif (!defined($changes->{'cancreate'})) {
19798: $changes->{'cancreate'} = ['captcha'];
19799: }
1.368 raeburn 19800: } elsif ($container eq 'passwords') {
19801: $changes->{'reset'} = 1;
1.169 raeburn 19802: } else {
19803: $changes->{'captcha'} = 1;
1.165 raeburn 19804: }
19805: }
1.269 raeburn 19806: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19807: if ($newsettings->{'captcha'} eq 'recaptcha') {
19808: $newpub = $env{'form.'.$container.'_recaptchapub'};
19809: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19810: $newpub =~ s/[^\w\-]//g;
19811: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19812: $newsettings->{'recaptchakeys'} = {
19813: public => $newpub,
19814: private => $newpriv,
19815: };
1.269 raeburn 19816: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19817: $newversion =~ s/\D//g;
19818: if ($newversion ne '2') {
19819: $newversion = 1;
19820: }
19821: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19822: }
1.369 raeburn 19823: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19824: $currpub = $current{'recaptchakeys'}{'public'};
19825: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19826: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19827: $newsettings->{'recaptchakeys'} = {
19828: public => '',
19829: private => '',
19830: }
19831: }
1.165 raeburn 19832: }
1.369 raeburn 19833: if ($current{'captcha'} eq 'recaptcha') {
19834: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19835: if ($currversion ne '2') {
19836: $currversion = 1;
19837: }
19838: }
19839: if ($currversion ne $newversion) {
19840: if ($container eq 'cancreate') {
19841: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19842: push(@{$changes->{'cancreate'}},'recaptchaversion');
19843: } elsif (!defined($changes->{'cancreate'})) {
19844: $changes->{'cancreate'} = ['recaptchaversion'];
19845: }
1.368 raeburn 19846: } elsif ($container eq 'passwords') {
19847: $changes->{'reset'} = 1;
1.269 raeburn 19848: } else {
19849: $changes->{'recaptchaversion'} = 1;
19850: }
19851: }
1.165 raeburn 19852: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19853: if ($container eq 'cancreate') {
19854: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19855: push(@{$changes->{'cancreate'}},'recaptchakeys');
19856: } elsif (!defined($changes->{'cancreate'})) {
19857: $changes->{'cancreate'} = ['recaptchakeys'];
19858: }
1.368 raeburn 19859: } elsif ($container eq 'passwords') {
19860: $changes->{'reset'} = 1;
1.169 raeburn 19861: } else {
1.210 raeburn 19862: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19863: }
19864: }
19865: return;
19866: }
19867:
1.33 raeburn 19868: sub modify_usermodification {
19869: my ($dom,%domconfig) = @_;
1.224 raeburn 19870: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19871: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19872: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19873: if ($key eq 'selfcreate') {
19874: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19875: } else {
19876: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19877: }
1.33 raeburn 19878: }
19879: }
1.443 raeburn 19880: my @contexts = ('author','coauthor','course');
1.33 raeburn 19881: my %context_title = (
19882: author => 'In author context',
1.443 raeburn 19883: coauthor => 'As co-author manager',
1.33 raeburn 19884: course => 'In course context',
19885: );
19886: my @fields = ('lastname','firstname','middlename','generation',
19887: 'permanentemail','id');
19888: my %roles = (
19889: author => ['ca','aa'],
1.443 raeburn 19890: coauthor => ['ca','aa'],
1.33 raeburn 19891: course => ['st','ep','ta','in','cr'],
19892: );
19893: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19894: foreach my $context (@contexts) {
1.443 raeburn 19895: my $prefix = 'canmodify';
19896: if ($context eq 'coauthor') {
19897: $prefix = 'cacanmodify';
19898: }
1.33 raeburn 19899: foreach my $role (@{$roles{$context}}) {
1.443 raeburn 19900: my @modifiable = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$role);
1.33 raeburn 19901: foreach my $item (@fields) {
19902: if (grep(/^\Q$item\E$/,@modifiable)) {
19903: $modifyhash{$context}{$role}{$item} = 1;
19904: } else {
19905: $modifyhash{$context}{$role}{$item} = 0;
19906: }
19907: }
19908: }
19909: if (ref($curr_usermodification{$context}) eq 'HASH') {
19910: foreach my $role (@{$roles{$context}}) {
19911: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19912: foreach my $field (@fields) {
19913: if ($modifyhash{$context}{$role}{$field} ne
19914: $curr_usermodification{$context}{$role}{$field}) {
19915: push(@{$changes{$context}},$role);
19916: last;
19917: }
19918: }
19919: }
19920: }
19921: } else {
19922: foreach my $context (@contexts) {
19923: foreach my $role (@{$roles{$context}}) {
19924: push(@{$changes{$context}},$role);
19925: }
19926: }
19927: }
19928: }
19929: my %usermodification_hash = (
19930: usermodification => \%modifyhash,
19931: );
19932: my $putresult = &Apache::lonnet::put_dom('configuration',
19933: \%usermodification_hash,$dom);
19934: if ($putresult eq 'ok') {
19935: if (keys(%changes) > 0) {
19936: $resulttext = &mt('Changes made: ').'<ul>';
19937: foreach my $context (@contexts) {
19938: if (ref($changes{$context}) eq 'ARRAY') {
19939: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19940: if (ref($changes{$context}) eq 'ARRAY') {
19941: foreach my $role (@{$changes{$context}}) {
19942: my $rolename;
1.224 raeburn 19943: if ($role eq 'cr') {
19944: $rolename = &mt('Custom');
1.33 raeburn 19945: } else {
1.224 raeburn 19946: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19947: }
19948: my @modifiable;
1.224 raeburn 19949: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19950: foreach my $field (@fields) {
19951: if ($modifyhash{$context}{$role}{$field}) {
19952: push(@modifiable,$fieldtitles{$field});
19953: }
19954: }
19955: if (@modifiable > 0) {
19956: $resulttext .= join(', ',@modifiable);
19957: } else {
19958: $resulttext .= &mt('none');
19959: }
19960: $resulttext .= '</li>';
19961: }
19962: $resulttext .= '</ul></li>';
19963: }
19964: }
19965: }
19966: $resulttext .= '</ul>';
19967: } else {
19968: $resulttext = &mt('No changes made to user modification settings');
19969: }
19970: } else {
19971: $resulttext = '<span class="LC_error">'.
19972: &mt('An error occurred: [_1]',$putresult).'</span>';
19973: }
19974: return $resulttext;
19975: }
19976:
1.43 raeburn 19977: sub modify_defaults {
1.212 raeburn 19978: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19979: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19980: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19981: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19982: 'portal_def');
1.325 raeburn 19983: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19984: foreach my $item (@items) {
19985: $newvalues{$item} = $env{'form.'.$item};
19986: if ($item eq 'auth_def') {
19987: if ($newvalues{$item} ne '') {
19988: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19989: push(@errors,$item);
19990: }
19991: }
19992: } elsif ($item eq 'lang_def') {
19993: if ($newvalues{$item} ne '') {
19994: if ($newvalues{$item} =~ /^(\w+)/) {
19995: my $langcode = $1;
1.103 raeburn 19996: if ($langcode ne 'x_chef') {
19997: if (code2language($langcode) eq '') {
19998: push(@errors,$item);
19999: }
1.43 raeburn 20000: }
20001: } else {
20002: push(@errors,$item);
20003: }
20004: }
1.54 raeburn 20005: } elsif ($item eq 'timezone_def') {
20006: if ($newvalues{$item} ne '') {
1.62 raeburn 20007: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 20008: push(@errors,$item);
20009: }
20010: }
1.68 raeburn 20011: } elsif ($item eq 'datelocale_def') {
20012: if ($newvalues{$item} ne '') {
20013: my @datelocale_ids = DateTime::Locale->ids();
20014: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
20015: push(@errors,$item);
20016: }
20017: }
1.141 raeburn 20018: } elsif ($item eq 'portal_def') {
20019: if ($newvalues{$item} ne '') {
1.414 raeburn 20020: 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])\/?$/) {
20021: foreach my $field ('email','web') {
20022: if ($env{'form.'.$item.'_'.$field}) {
20023: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
20024: }
20025: }
20026: } else {
1.141 raeburn 20027: push(@errors,$item);
20028: }
20029: }
1.43 raeburn 20030: }
20031: if (grep(/^\Q$item\E$/,@errors)) {
20032: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 20033: if ($item eq 'portal_def') {
20034: if ($domdefaults{$item}) {
20035: foreach my $field ('email','web') {
20036: if (exists($domdefaults{$item.'_'.$field})) {
20037: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
20038: }
20039: }
20040: }
20041: }
1.43 raeburn 20042: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
20043: $changes{$item} = 1;
20044: }
1.414 raeburn 20045: if ($item eq 'portal_def') {
20046: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 20047: if ($newvalues{$item} eq '') {
1.414 raeburn 20048: foreach my $field ('email','web') {
20049: if (exists($domdefaults{$item.'_'.$field})) {
20050: delete($domdefaults{$item.'_'.$field});
20051: }
20052: }
20053: } else {
20054: unless ($changes{$item}) {
20055: foreach my $field ('email','web') {
20056: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
20057: $changes{$item} = 1;
20058: last;
20059: }
20060: }
20061: }
20062: foreach my $field ('email','web') {
20063: if ($newvalues{$item.'_'.$field}) {
20064: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
20065: } elsif (exists($domdefaults{$item.'_'.$field})) {
20066: delete($domdefaults{$item.'_'.$field});
20067: }
20068: }
20069: }
20070: }
20071: }
1.72 raeburn 20072: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 20073: }
1.354 raeburn 20074: my %staticdefaults = (
20075: 'intauth_cost' => 10,
20076: 'intauth_check' => 0,
20077: 'intauth_switch' => 0,
20078: );
20079: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
20080: if (exists($domdefaults{$item})) {
20081: $newvalues{$item} = $domdefaults{$item};
20082: } else {
20083: $newvalues{$item} = $staticdefaults{$item};
20084: }
20085: }
1.409 raeburn 20086: my ($unamemaprules,$ruleorder);
20087: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
20088: if (@possunamemaprules) {
20089: ($unamemaprules,$ruleorder) =
20090: &Apache::lonnet::inst_userrules($dom,'unamemap');
20091: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
20092: if (@{$ruleorder} > 0) {
20093: my %possrules;
20094: map { $possrules{$_} = 1; } @possunamemaprules;
20095: foreach my $rule (@{$ruleorder}) {
20096: if ($possrules{$rule}) {
20097: push(@{$newvalues{'unamemap_rule'}},$rule);
20098: }
20099: }
20100: }
20101: }
20102: }
20103: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
20104: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20105: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
20106: $newvalues{'unamemap_rule'});
20107: if (@rulediffs) {
20108: $changes{'unamemap_rule'} = 1;
20109: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20110: }
20111: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
20112: $changes{'unamemap_rule'} = 1;
20113: delete($domdefaults{'unamemap_rule'});
20114: }
20115: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20116: if (@{$newvalues{'unamemap_rule'}} > 0) {
20117: $changes{'unamemap_rule'} = 1;
20118: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20119: }
20120: }
1.43 raeburn 20121: my %defaults_hash = (
1.72 raeburn 20122: defaults => \%newvalues,
20123: );
1.43 raeburn 20124: my $title = &defaults_titles();
1.236 raeburn 20125:
20126: my $currinststatus;
20127: if (ref($domconfig{'inststatus'}) eq 'HASH') {
20128: $currinststatus = $domconfig{'inststatus'};
20129: } else {
20130: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
20131: $currinststatus = {
20132: inststatustypes => $usertypes,
20133: inststatusorder => $types,
20134: inststatusguest => [],
20135: };
20136: }
20137: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20138: my @allpos;
20139: my %alltypes;
1.305 raeburn 20140: my @inststatusguest;
20141: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20142: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20143: unless (grep(/^\Q$type\E$/,@todelete)) {
20144: push(@inststatusguest,$type);
20145: }
20146: }
20147: }
20148: my ($currtitles,$currorder);
1.236 raeburn 20149: if (ref($currinststatus) eq 'HASH') {
20150: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20151: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20152: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20153: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20154: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20155: }
20156: }
20157: unless (grep(/^\Q$type\E$/,@todelete)) {
20158: my $position = $env{'form.inststatus_pos_'.$type};
20159: $position =~ s/\D+//g;
20160: $allpos[$position] = $type;
20161: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20162: $alltypes{$type} =~ s/`//g;
20163: }
20164: }
20165: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20166: $currtitles =~ s/,$//;
20167: }
20168: }
20169: if ($env{'form.addinststatus'}) {
20170: my $newtype = $env{'form.addinststatus'};
20171: $newtype =~ s/\W//g;
20172: unless (exists($alltypes{$newtype})) {
20173: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20174: $alltypes{$newtype} =~ s/`//g;
20175: my $position = $env{'form.addinststatus_pos'};
20176: $position =~ s/\D+//g;
20177: if ($position ne '') {
20178: $allpos[$position] = $newtype;
20179: }
20180: }
20181: }
1.305 raeburn 20182: my @orderedstatus;
1.236 raeburn 20183: foreach my $type (@allpos) {
20184: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20185: push(@orderedstatus,$type);
20186: }
20187: }
20188: foreach my $type (keys(%alltypes)) {
20189: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20190: delete($alltypes{$type});
20191: }
20192: }
20193: $defaults_hash{'inststatus'} = {
20194: inststatustypes => \%alltypes,
20195: inststatusorder => \@orderedstatus,
1.305 raeburn 20196: inststatusguest => \@inststatusguest,
1.236 raeburn 20197: };
20198: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20199: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20200: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20201: }
20202: }
20203: if ($currorder ne join(',',@orderedstatus)) {
20204: $changes{'inststatus'}{'inststatusorder'} = 1;
20205: }
20206: my $newtitles;
20207: foreach my $item (@orderedstatus) {
20208: $newtitles .= $alltypes{$item}.',';
20209: }
20210: $newtitles =~ s/,$//;
20211: if ($currtitles ne $newtitles) {
20212: $changes{'inststatus'}{'inststatustypes'} = 1;
20213: }
1.43 raeburn 20214: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20215: $dom);
20216: if ($putresult eq 'ok') {
20217: if (keys(%changes) > 0) {
20218: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20219: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20220: 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";
20221: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20222: if ($item eq 'inststatus') {
20223: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20224: if (@orderedstatus) {
1.236 raeburn 20225: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20226: foreach my $type (@orderedstatus) {
20227: $resulttext .= $alltypes{$type}.', ';
20228: }
20229: $resulttext =~ s/, $//;
20230: $resulttext .= '</li>';
1.305 raeburn 20231: } else {
1.425 raeburn 20232: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20233: }
20234: }
1.409 raeburn 20235: } elsif ($item eq 'unamemap_rule') {
20236: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20237: my @rulenames;
20238: if (ref($unamemaprules) eq 'HASH') {
20239: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20240: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20241: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20242: }
20243: }
20244: }
20245: if (@rulenames) {
20246: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20247: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20248: '</li>';
20249: } else {
20250: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20251: }
20252: } else {
20253: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20254: }
1.236 raeburn 20255: } else {
20256: my $value = $env{'form.'.$item};
20257: if ($value eq '') {
20258: $value = &mt('none');
20259: } elsif ($item eq 'auth_def') {
20260: my %authnames = &authtype_names();
20261: my %shortauth = (
20262: internal => 'int',
20263: krb4 => 'krb4',
20264: krb5 => 'krb5',
20265: localauth => 'loc',
1.325 raeburn 20266: lti => 'lti',
1.236 raeburn 20267: );
20268: $value = $authnames{$shortauth{$value}};
20269: }
20270: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20271: $mailmsgtext .= "$title->{$item} set to $value\n";
20272: if ($item eq 'portal_def') {
20273: if ($env{'form.'.$item} ne '') {
20274: foreach my $field ('email','web') {
20275: $value = $env{'form.'.$item.'_'.$field};
20276: if ($value) {
20277: $value = &mt('Yes');
20278: } else {
20279: $value = &mt('No');
20280: }
20281: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20282: }
20283: }
20284: }
1.43 raeburn 20285: }
20286: }
20287: $resulttext .= '</ul>';
20288: $mailmsgtext .= "\n";
20289: my $cachetime = 24*60*60;
1.72 raeburn 20290: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20291: if (ref($lastactref) eq 'HASH') {
20292: $lastactref->{'domdefaults'} = 1;
20293: }
1.68 raeburn 20294: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20295: my $notify = 1;
20296: if (ref($domconfig{'contacts'}) eq 'HASH') {
20297: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20298: $notify = 0;
20299: }
20300: }
20301: if ($notify) {
20302: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20303: "LON-CAPA Domain Settings Change - $dom",
20304: $mailmsgtext);
20305: }
1.54 raeburn 20306: }
1.43 raeburn 20307: } else {
1.54 raeburn 20308: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20309: }
20310: } else {
20311: $resulttext = '<span class="LC_error">'.
20312: &mt('An error occurred: [_1]',$putresult).'</span>';
20313: }
20314: if (@errors > 0) {
20315: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20316: foreach my $item (@errors) {
20317: $resulttext .= ' "'.$title->{$item}.'",';
20318: }
20319: $resulttext =~ s/,$//;
20320: }
20321: return $resulttext;
20322: }
20323:
1.46 raeburn 20324: sub modify_scantron {
1.205 raeburn 20325: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20326: my ($resulttext,%confhash,%changes,$errors);
20327: my $custom = 'custom.tab';
20328: my $default = 'default.tab';
20329: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20330: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20331: &config_check($dom,$confname,$servadm);
20332: if ($env{'form.scantronformat.filename'} ne '') {
20333: my $error;
20334: if ($configuserok eq 'ok') {
20335: if ($switchserver) {
1.130 raeburn 20336: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20337: } else {
20338: if ($author_ok eq 'ok') {
1.421 raeburn 20339: my $modified = [];
1.46 raeburn 20340: my ($result,$scantronurl) =
1.421 raeburn 20341: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20342: $confname,'scantron','','',$custom,
20343: $modified);
1.46 raeburn 20344: if ($result eq 'ok') {
20345: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20346: $changes{'scantronformat'} = 1;
1.421 raeburn 20347: &update_modify_urls($r,$modified);
1.46 raeburn 20348: } else {
20349: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20350: }
20351: } else {
20352: $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);
20353: }
20354: }
20355: } else {
20356: $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);
20357: }
20358: if ($error) {
20359: &Apache::lonnet::logthis($error);
20360: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20361: }
20362: }
1.48 raeburn 20363: if (ref($domconfig{'scantron'}) eq 'HASH') {
20364: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20365: if ($env{'form.scantronformat_del'}) {
20366: $confhash{'scantron'}{'scantronformat'} = '';
20367: $changes{'scantronformat'} = 1;
1.347 raeburn 20368: } else {
20369: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20370: }
20371: }
20372: }
1.347 raeburn 20373: my @options = ('hdr','pad','rem');
1.346 raeburn 20374: my @fields = &scantroncsv_fields();
20375: my %titles = &scantronconfig_titles();
1.347 raeburn 20376: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20377: my ($newdat,$currdat,%newcol,%currcol);
20378: if (grep(/^dat$/,@formats)) {
20379: $confhash{'scantron'}{config}{dat} = 1;
20380: $newdat = 1;
20381: } else {
20382: $newdat = 0;
20383: }
20384: if (grep(/^csv$/,@formats)) {
20385: my %bynum;
20386: foreach my $field (@fields) {
20387: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20388: my $posscol = $1;
20389: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20390: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20391: $bynum{$posscol} = $field;
20392: $newcol{$field} = $posscol;
20393: }
20394: }
20395: }
1.347 raeburn 20396: if (keys(%newcol)) {
20397: foreach my $option (@options) {
20398: if ($env{'form.scantroncsv_'.$option}) {
20399: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20400: }
20401: }
20402: }
1.346 raeburn 20403: }
20404: $currdat = 1;
20405: if (ref($domconfig{'scantron'}) eq 'HASH') {
20406: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20407: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20408: $currdat = 0;
20409: }
20410: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20411: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20412: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20413: }
1.346 raeburn 20414: }
20415: }
20416: }
20417: if ($currdat != $newdat) {
20418: $changes{'config'} = 1;
20419: } else {
20420: foreach my $field (@fields) {
20421: if ($currcol{$field} ne '') {
20422: if ($currcol{$field} ne $newcol{$field}) {
20423: $changes{'config'} = 1;
20424: last;
1.347 raeburn 20425: }
1.346 raeburn 20426: } elsif ($newcol{$field} ne '') {
20427: $changes{'config'} = 1;
20428: last;
20429: }
20430: }
20431: }
1.46 raeburn 20432: if (keys(%confhash) > 0) {
20433: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20434: $dom);
20435: if ($putresult eq 'ok') {
20436: if (keys(%changes) > 0) {
1.48 raeburn 20437: if (ref($confhash{'scantron'}) eq 'HASH') {
20438: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20439: if ($changes{'scantronformat'}) {
20440: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20441: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20442: } else {
20443: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20444: }
20445: }
1.347 raeburn 20446: if ($changes{'config'}) {
1.346 raeburn 20447: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20448: if ($confhash{'scantron'}{'config'}{'dat'}) {
20449: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20450: }
20451: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20452: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20453: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20454: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20455: foreach my $field (@fields) {
20456: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20457: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20458: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20459: }
20460: }
20461: $resulttext .= '</ul></li>';
20462: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20463: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20464: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20465: foreach my $option (@options) {
20466: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20467: $resulttext .= '<li>'.$titles{$option}.'</li>';
20468: }
20469: }
20470: $resulttext .= '</ul></li>';
20471: }
1.346 raeburn 20472: }
20473: }
20474: }
20475: }
20476: } else {
20477: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20478: }
1.46 raeburn 20479: }
1.48 raeburn 20480: $resulttext .= '</ul>';
20481: } else {
1.130 raeburn 20482: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20483: }
20484: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20485: if (ref($lastactref) eq 'HASH') {
20486: $lastactref->{'domainconfig'} = 1;
20487: }
1.46 raeburn 20488: } else {
1.346 raeburn 20489: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20490: }
20491: } else {
20492: $resulttext = '<span class="LC_error">'.
20493: &mt('An error occurred: [_1]',$putresult).'</span>';
20494: }
20495: } else {
1.130 raeburn 20496: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20497: }
20498: if ($errors) {
1.353 raeburn 20499: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20500: $errors.'</ul></p>';
1.46 raeburn 20501: }
20502: return $resulttext;
20503: }
20504:
1.48 raeburn 20505: sub modify_coursecategories {
1.239 raeburn 20506: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20507: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20508: $cathash);
1.48 raeburn 20509: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20510: my @catitems = ('unauth','auth');
20511: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20512: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20513: $cathash = $domconfig{'coursecategories'}{'cats'};
20514: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20515: $changes{'togglecats'} = 1;
20516: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20517: }
20518: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20519: $changes{'categorize'} = 1;
20520: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20521: }
1.120 raeburn 20522: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20523: $changes{'togglecatscomm'} = 1;
20524: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20525: }
20526: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20527: $changes{'categorizecomm'} = 1;
20528: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20529:
20530: }
20531: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20532: $changes{'togglecatsplace'} = 1;
20533: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20534: }
20535: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20536: $changes{'categorizeplace'} = 1;
20537: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20538: }
1.238 raeburn 20539: foreach my $item (@catitems) {
20540: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20541: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20542: $changes{$item} = 1;
20543: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20544: }
20545: }
20546: }
1.57 raeburn 20547: } else {
20548: $changes{'togglecats'} = 1;
20549: $changes{'categorize'} = 1;
1.124 raeburn 20550: $changes{'togglecatscomm'} = 1;
20551: $changes{'categorizecomm'} = 1;
1.272 raeburn 20552: $changes{'togglecatsplace'} = 1;
20553: $changes{'categorizeplace'} = 1;
1.87 raeburn 20554: $domconfig{'coursecategories'} = {
20555: togglecats => $env{'form.togglecats'},
20556: categorize => $env{'form.categorize'},
1.124 raeburn 20557: togglecatscomm => $env{'form.togglecatscomm'},
20558: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20559: togglecatsplace => $env{'form.togglecatsplace'},
20560: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20561: };
1.238 raeburn 20562: foreach my $item (@catitems) {
20563: if ($env{'form.coursecat_'.$item} ne 'std') {
20564: $changes{$item} = 1;
20565: }
20566: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20567: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20568: }
20569: }
1.57 raeburn 20570: }
20571: if (ref($cathash) eq 'HASH') {
20572: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20573: push (@deletecategory,'instcode::0');
20574: }
1.120 raeburn 20575: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20576: push(@deletecategory,'communities::0');
20577: }
1.272 raeburn 20578: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20579: push(@deletecategory,'placement::0');
20580: }
1.48 raeburn 20581: }
1.57 raeburn 20582: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20583: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20584: if (@deletecategory > 0) {
20585: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20586: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20587: foreach my $item (@deletecategory) {
1.57 raeburn 20588: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20589: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20590: $deletions{$item} = 1;
1.57 raeburn 20591: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20592: }
20593: }
20594: }
1.57 raeburn 20595: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20596: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20597: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20598: $reorderings{$item} = 1;
1.57 raeburn 20599: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20600: }
20601: if ($env{'form.addcategory_name_'.$item} ne '') {
20602: my $newcat = $env{'form.addcategory_name_'.$item};
20603: my $newdepth = $depth+1;
20604: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20605: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20606: $adds{$newitem} = 1;
20607: }
20608: if ($env{'form.subcat_'.$item} ne '') {
20609: my $newcat = $env{'form.subcat_'.$item};
20610: my $newdepth = $depth+1;
20611: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20612: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20613: $adds{$newitem} = 1;
20614: }
20615: }
20616: }
20617: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20618: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20619: my $newitem = 'instcode::0';
1.57 raeburn 20620: if ($cathash->{$newitem} eq '') {
20621: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20622: $adds{$newitem} = 1;
20623: }
20624: } else {
20625: my $newitem = 'instcode::0';
1.57 raeburn 20626: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20627: $adds{$newitem} = 1;
20628: }
20629: }
1.120 raeburn 20630: if ($env{'form.communities'} eq '1') {
20631: if (ref($cathash) eq 'HASH') {
20632: my $newitem = 'communities::0';
20633: if ($cathash->{$newitem} eq '') {
20634: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20635: $adds{$newitem} = 1;
20636: }
20637: } else {
20638: my $newitem = 'communities::0';
20639: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20640: $adds{$newitem} = 1;
20641: }
20642: }
1.272 raeburn 20643: if ($env{'form.placement'} eq '1') {
20644: if (ref($cathash) eq 'HASH') {
20645: my $newitem = 'placement::0';
20646: if ($cathash->{$newitem} eq '') {
20647: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20648: $adds{$newitem} = 1;
20649: }
20650: } else {
20651: my $newitem = 'placement::0';
20652: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20653: $adds{$newitem} = 1;
20654: }
20655: }
1.48 raeburn 20656: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20657: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20658: ($env{'form.addcategory_name'} ne 'communities') &&
20659: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20660: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20661: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20662: $adds{$newitem} = 1;
20663: }
1.48 raeburn 20664: }
1.57 raeburn 20665: my $putresult;
1.48 raeburn 20666: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20667: if (keys(%deletions) > 0) {
20668: foreach my $key (keys(%deletions)) {
20669: if ($predelallitems{$key} ne '') {
20670: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20671: }
20672: }
20673: }
20674: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20675: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20676: if (ref($chkcats[0]) eq 'ARRAY') {
20677: my $depth = 0;
20678: my $chg = 0;
20679: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20680: my $name = $chkcats[0][$i];
20681: my $item;
20682: if ($name eq '') {
20683: $chg ++;
20684: } else {
20685: $item = &escape($name).'::0';
20686: if ($chg) {
1.57 raeburn 20687: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20688: }
20689: $depth ++;
1.57 raeburn 20690: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20691: $depth --;
20692: }
20693: }
20694: }
1.57 raeburn 20695: }
20696: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20697: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20698: if ($putresult eq 'ok') {
1.57 raeburn 20699: my %title = (
1.120 raeburn 20700: togglecats => 'Show/Hide a course in catalog',
20701: categorize => 'Assign a category to a course',
20702: togglecatscomm => 'Show/Hide a community in catalog',
20703: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20704: );
20705: my %level = (
1.120 raeburn 20706: dom => 'set in Domain ("Modify Course/Community")',
20707: crs => 'set in Course ("Course Configuration")',
20708: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20709: none => 'No catalog',
20710: std => 'Standard catalog',
20711: domonly => 'Domain-only catalog',
20712: codesrch => 'Code search form',
1.57 raeburn 20713: );
1.48 raeburn 20714: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20715: if ($changes{'togglecats'}) {
20716: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20717: }
20718: if ($changes{'categorize'}) {
20719: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20720: }
1.120 raeburn 20721: if ($changes{'togglecatscomm'}) {
20722: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20723: }
20724: if ($changes{'categorizecomm'}) {
20725: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20726: }
1.238 raeburn 20727: if ($changes{'unauth'}) {
20728: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20729: }
20730: if ($changes{'auth'}) {
20731: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20732: }
1.57 raeburn 20733: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20734: my $cathash;
20735: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20736: $cathash = $domconfig{'coursecategories'}{'cats'};
20737: } else {
20738: $cathash = {};
20739: }
20740: my (@cats,@trails,%allitems);
20741: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20742: if (keys(%deletions) > 0) {
20743: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20744: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20745: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20746: }
20747: $resulttext .= '</ul></li>';
20748: }
20749: if (keys(%reorderings) > 0) {
20750: my %sort_by_trail;
20751: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20752: foreach my $key (keys(%reorderings)) {
20753: if ($allitems{$key} ne '') {
20754: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20755: }
1.48 raeburn 20756: }
1.57 raeburn 20757: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20758: $resulttext .= '<li>'.$trails[$trail].'</li>';
20759: }
20760: $resulttext .= '</ul></li>';
1.48 raeburn 20761: }
1.57 raeburn 20762: if (keys(%adds) > 0) {
20763: my %sort_by_trail;
20764: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20765: foreach my $key (keys(%adds)) {
20766: if ($allitems{$key} ne '') {
20767: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20768: }
20769: }
20770: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20771: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20772: }
1.57 raeburn 20773: $resulttext .= '</ul></li>';
1.48 raeburn 20774: }
1.364 raeburn 20775: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20776: if (ref($lastactref) eq 'HASH') {
20777: $lastactref->{'cats'} = 1;
20778: }
1.48 raeburn 20779: }
20780: $resulttext .= '</ul>';
1.239 raeburn 20781: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20782: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20783: if ($changes{'auth'}) {
20784: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20785: }
20786: if ($changes{'unauth'}) {
20787: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20788: }
20789: my $cachetime = 24*60*60;
20790: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20791: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20792: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20793: }
20794: }
1.48 raeburn 20795: } else {
20796: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20797: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20798: }
20799: } else {
1.120 raeburn 20800: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20801: }
20802: return $resulttext;
20803: }
20804:
1.69 raeburn 20805: sub modify_serverstatuses {
20806: my ($dom,%domconfig) = @_;
20807: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20808: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20809: %currserverstatus = %{$domconfig{'serverstatuses'}};
20810: }
20811: my @pages = &serverstatus_pages();
20812: foreach my $type (@pages) {
20813: $newserverstatus{$type}{'namedusers'} = '';
20814: $newserverstatus{$type}{'machines'} = '';
20815: if (defined($env{'form.'.$type.'_namedusers'})) {
20816: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20817: my @okusers;
20818: foreach my $user (@users) {
20819: my ($uname,$udom) = split(/:/,$user);
20820: if (($udom =~ /^$match_domain$/) &&
20821: (&Apache::lonnet::domain($udom)) &&
20822: ($uname =~ /^$match_username$/)) {
20823: if (!grep(/^\Q$user\E/,@okusers)) {
20824: push(@okusers,$user);
20825: }
20826: }
20827: }
20828: if (@okusers > 0) {
20829: @okusers = sort(@okusers);
20830: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20831: }
20832: }
20833: if (defined($env{'form.'.$type.'_machines'})) {
20834: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20835: my @okmachines;
20836: foreach my $ip (@machines) {
20837: my @parts = split(/\./,$ip);
20838: next if (@parts < 4);
20839: my $badip = 0;
20840: for (my $i=0; $i<4; $i++) {
20841: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20842: $badip = 1;
20843: last;
20844: }
20845: }
20846: if (!$badip) {
20847: push(@okmachines,$ip);
20848: }
20849: }
20850: @okmachines = sort(@okmachines);
20851: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20852: }
20853: }
20854: my %serverstatushash = (
20855: serverstatuses => \%newserverstatus,
20856: );
20857: foreach my $type (@pages) {
1.83 raeburn 20858: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20859: my (@current,@new);
1.83 raeburn 20860: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20861: if ($currserverstatus{$type}{$setting} ne '') {
20862: @current = split(/,/,$currserverstatus{$type}{$setting});
20863: }
20864: }
20865: if ($newserverstatus{$type}{$setting} ne '') {
20866: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20867: }
20868: if (@current > 0) {
20869: if (@new > 0) {
20870: foreach my $item (@current) {
20871: if (!grep(/^\Q$item\E$/,@new)) {
20872: $changes{$type}{$setting} = 1;
1.82 raeburn 20873: last;
20874: }
20875: }
1.84 raeburn 20876: foreach my $item (@new) {
20877: if (!grep(/^\Q$item\E$/,@current)) {
20878: $changes{$type}{$setting} = 1;
20879: last;
1.82 raeburn 20880: }
20881: }
20882: } else {
1.83 raeburn 20883: $changes{$type}{$setting} = 1;
1.69 raeburn 20884: }
1.83 raeburn 20885: } elsif (@new > 0) {
20886: $changes{$type}{$setting} = 1;
1.69 raeburn 20887: }
20888: }
20889: }
20890: if (keys(%changes) > 0) {
1.81 raeburn 20891: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20892: my $putresult = &Apache::lonnet::put_dom('configuration',
20893: \%serverstatushash,$dom);
20894: if ($putresult eq 'ok') {
20895: $resulttext .= &mt('Changes made:').'<ul>';
20896: foreach my $type (@pages) {
1.84 raeburn 20897: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20898: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20899: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20900: if ($newserverstatus{$type}{'namedusers'} eq '') {
20901: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20902: } else {
20903: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20904: }
1.84 raeburn 20905: }
20906: if ($changes{$type}{'machines'}) {
1.69 raeburn 20907: if ($newserverstatus{$type}{'machines'} eq '') {
20908: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20909: } else {
20910: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20911: }
20912:
20913: }
20914: $resulttext .= '</ul></li>';
20915: }
20916: }
20917: $resulttext .= '</ul>';
20918: } else {
20919: $resulttext = '<span class="LC_error">'.
20920: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20921:
20922: }
20923: } else {
20924: $resulttext = &mt('No changes made to access to server status pages');
20925: }
20926: return $resulttext;
20927: }
20928:
1.118 jms 20929: sub modify_helpsettings {
1.285 raeburn 20930: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20931: my ($resulttext,$errors,%changes,%helphash);
20932: my %defaultchecked = ('submitbugs' => 'on');
20933: my @offon = ('off','on');
1.118 jms 20934: my @toggles = ('submitbugs');
1.285 raeburn 20935: my %current = ('submitbugs' => '',
20936: 'adhoc' => {},
20937: );
1.118 jms 20938: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20939: %current = %{$domconfig{'helpsettings'}};
20940: }
1.285 raeburn 20941: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20942: foreach my $item (@toggles) {
20943: if ($defaultchecked{$item} eq 'on') {
20944: if ($current{$item} eq '') {
20945: if ($env{'form.'.$item} eq '0') {
20946: $changes{$item} = 1;
20947: }
20948: } elsif ($current{$item} ne $env{'form.'.$item}) {
20949: $changes{$item} = 1;
20950: }
20951: } elsif ($defaultchecked{$item} eq 'off') {
20952: if ($current{$item} eq '') {
20953: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20954: $changes{$item} = 1;
20955: }
1.282 raeburn 20956: } elsif ($current{$item} ne $env{'form.'.$item}) {
20957: $changes{$item} = 1;
20958: }
20959: }
20960: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20961: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20962: }
20963: }
1.285 raeburn 20964: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20965: my $confname = $dom.'-domainconfig';
20966: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20967: my (@allpos,%newsettings,%changedprivs,$newrole);
20968: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20969: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20970: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20971: my %lt = &Apache::lonlocal::texthash(
20972: s => 'system',
20973: d => 'domain',
20974: order => 'Display order',
20975: access => 'Role usage',
1.291 raeburn 20976: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20977: dh => 'All with domain helpdesk role',
20978: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20979: none => 'None',
20980: status => 'Determined based on institutional status',
20981: inc => 'Include all, but exclude specific personnel',
20982: exc => 'Exclude all, but include specific personnel',
20983: );
20984: for (my $num=0; $num<=$maxnum; $num++) {
20985: my ($prefix,$identifier,$rolename,%curr);
20986: if ($num == $maxnum) {
20987: next unless ($env{'form.newcusthelp'} == $maxnum);
20988: $identifier = 'custhelp'.$num;
20989: $prefix = 'helproles_'.$num;
20990: $rolename = $env{'form.custhelpname'.$num};
20991: $rolename=~s/[^A-Za-z0-9]//gs;
20992: next if ($rolename eq '');
20993: next if (exists($existing{'rolesdef_'.$rolename}));
20994: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20995: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20996: $newprivs{'c'},$confname,$dom);
20997: if ($result ne 'ok') {
20998: $errors .= '<li><span class="LC_error">'.
20999: &mt('An error occurred storing the new custom role: [_1]',
21000: $result).'</span></li>';
21001: next;
21002: } else {
21003: $changedprivs{$rolename} = \%newprivs;
21004: $newrole = $rolename;
21005: }
21006: } else {
21007: $prefix = 'helproles_'.$num;
21008: $rolename = $env{'form.'.$prefix};
21009: next if ($rolename eq '');
21010: next unless (exists($existing{'rolesdef_'.$rolename}));
21011: $identifier = 'custhelp'.$num;
21012: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21013: my %currprivs;
1.289 raeburn 21014: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 21015: split(/\_/,$existing{'rolesdef_'.$rolename});
21016: foreach my $level ('c','d','s') {
21017: if ($newprivs{$level} ne $currprivs{$level}) {
21018: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21019: $newprivs{'c'},$confname,$dom);
21020: if ($result ne 'ok') {
21021: $errors .= '<li><span class="LC_error">'.
21022: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
21023: $rolename,$result).'</span></li>';
21024: } else {
21025: $changedprivs{$rolename} = \%newprivs;
21026: }
21027: last;
21028: }
21029: }
21030: if (ref($current{'adhoc'}) eq 'HASH') {
21031: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21032: %curr = %{$current{'adhoc'}{$rolename}};
21033: }
21034: }
21035: }
21036: my $newpos = $env{'form.'.$prefix.'_pos'};
21037: $newpos =~ s/\D+//g;
21038: $allpos[$newpos] = $rolename;
21039: my $newdesc = $env{'form.'.$prefix.'_desc'};
21040: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
21041: if ($curr{'desc'}) {
21042: if ($curr{'desc'} ne $newdesc) {
21043: $changes{'customrole'}{$rolename}{'desc'} = 1;
21044: $newsettings{$rolename}{'desc'} = $newdesc;
21045: }
21046: } elsif ($newdesc ne '') {
21047: $changes{'customrole'}{$rolename}{'desc'} = 1;
21048: $newsettings{$rolename}{'desc'} = $newdesc;
21049: }
21050: my $access = $env{'form.'.$prefix.'_access'};
21051: if (grep(/^\Q$access\E$/,@accesstypes)) {
21052: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
21053: if ($access eq 'status') {
21054: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
21055: if (scalar(@statuses) == 0) {
1.289 raeburn 21056: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 21057: } else {
21058: my (@shownstatus,$numtypes);
21059: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21060: if (ref($types) eq 'ARRAY') {
21061: $numtypes = scalar(@{$types});
21062: foreach my $type (sort(@statuses)) {
21063: if ($type eq 'default') {
21064: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21065: } elsif (grep(/^\Q$type\E$/,@{$types})) {
21066: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21067: push(@shownstatus,$usertypes->{$type});
21068: }
21069: }
21070: }
21071: if (grep(/^default$/,@statuses)) {
21072: push(@shownstatus,$othertitle);
21073: }
21074: if (scalar(@shownstatus) == 1+$numtypes) {
21075: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
21076: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
21077: } else {
21078: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
21079: if (ref($curr{'status'}) eq 'ARRAY') {
21080: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21081: if (@diffs) {
21082: $changes{'customrole'}{$rolename}{$access} = 1;
21083: }
21084: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21085: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 21086: }
1.166 raeburn 21087: }
21088: }
1.285 raeburn 21089: } elsif (($access eq 'inc') || ($access eq 'exc')) {
21090: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
21091: my @newspecstaff;
21092: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21093: foreach my $person (sort(@personnel)) {
21094: if ($domhelpdesk{$person}) {
21095: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
21096: }
21097: }
21098: if (ref($curr{$access}) eq 'ARRAY') {
21099: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21100: if (@diffs) {
21101: $changes{'customrole'}{$rolename}{$access} = 1;
21102: }
21103: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21104: $changes{'customrole'}{$rolename}{$access} = 1;
21105: }
21106: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21107: my ($uname,$udom) = split(/:/,$person);
21108: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
21109: }
21110: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 21111: }
1.285 raeburn 21112: } else {
21113: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
21114: }
21115: unless ($curr{'access'} eq $access) {
21116: $changes{'customrole'}{$rolename}{'access'} = 1;
21117: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 21118: }
21119: }
1.285 raeburn 21120: if (@allpos > 0) {
21121: my $idx = 0;
21122: foreach my $rolename (@allpos) {
21123: if ($rolename ne '') {
21124: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
21125: if (ref($current{'adhoc'}) eq 'HASH') {
21126: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21127: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
21128: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 21129: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 21130: }
21131: }
1.282 raeburn 21132: }
1.285 raeburn 21133: $idx ++;
1.166 raeburn 21134: }
21135: }
1.118 jms 21136: }
1.123 jms 21137: my $putresult;
21138: if (keys(%changes) > 0) {
1.166 raeburn 21139: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21140: if ($putresult eq 'ok') {
1.285 raeburn 21141: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21142: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21143: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21144: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21145: }
21146: }
21147: my $cachetime = 24*60*60;
21148: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21149: if (ref($lastactref) eq 'HASH') {
21150: $lastactref->{'domdefaults'} = 1;
21151: }
21152: } else {
21153: $errors .= '<li><span class="LC_error">'.
21154: &mt('An error occurred storing the settings: [_1]',
21155: $putresult).'</span></li>';
21156: }
21157: }
21158: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21159: $resulttext = &mt('Changes made:').'<ul>';
21160: my (%shownprivs,@levelorder);
21161: @levelorder = ('c','d','s');
21162: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21163: foreach my $item (sort(keys(%changes))) {
21164: if ($item eq 'submitbugs') {
21165: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21166: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21167: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21168: } elsif ($item eq 'customrole') {
21169: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21170: my @keyorder = ('order','desc','access','status','exc','inc');
21171: my %keytext = &Apache::lonlocal::texthash(
21172: order => 'Order',
21173: desc => 'Role description',
21174: access => 'Role usage',
1.300 droeschl 21175: status => 'Allowed institutional types',
1.285 raeburn 21176: exc => 'Allowed personnel',
21177: inc => 'Disallowed personnel',
21178: );
1.282 raeburn 21179: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21180: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21181: if ($role eq $newrole) {
21182: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21183: $role).'<ul>';
21184: } else {
21185: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21186: $role).'<ul>';
21187: }
21188: foreach my $key (@keyorder) {
21189: if ($changes{'customrole'}{$role}{$key}) {
21190: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21191: $keytext{$key},$newsettings{$role}{$key}).
21192: '</li>';
21193: }
21194: }
21195: if (ref($changedprivs{$role}) eq 'HASH') {
21196: $shownprivs{$role} = 1;
21197: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21198: foreach my $level (@levelorder) {
21199: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21200: next if ($item eq '');
21201: my ($priv) = split(/\&/,$item,2);
21202: if (&Apache::lonnet::plaintext($priv)) {
21203: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21204: unless ($level eq 'c') {
21205: $resulttext .= ' ('.$lt{$level}.')';
21206: }
21207: $resulttext .= '</li>';
21208: }
21209: }
21210: }
21211: $resulttext .= '</ul>';
21212: }
21213: $resulttext .= '</ul></li>';
21214: }
21215: }
21216: }
21217: }
21218: }
21219: }
21220: if (keys(%changedprivs)) {
21221: foreach my $role (sort(keys(%changedprivs))) {
21222: unless ($shownprivs{$role}) {
21223: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21224: $role).'<ul>'.
21225: '<li>'.&mt('Privileges set to :').'<ul>';
21226: foreach my $level (@levelorder) {
21227: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21228: next if ($item eq '');
21229: my ($priv) = split(/\&/,$item,2);
21230: if (&Apache::lonnet::plaintext($priv)) {
21231: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21232: unless ($level eq 'c') {
21233: $resulttext .= ' ('.$lt{$level}.')';
21234: }
21235: $resulttext .= '</li>';
21236: }
1.282 raeburn 21237: }
21238: }
1.285 raeburn 21239: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21240: }
21241: }
21242: }
1.285 raeburn 21243: $resulttext .= '</ul>';
21244: } else {
21245: $resulttext = &mt('No changes made to help settings');
1.118 jms 21246: }
21247: if ($errors) {
1.168 raeburn 21248: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21249: $errors.'</ul>';
1.118 jms 21250: }
21251: return $resulttext;
21252: }
21253:
1.121 raeburn 21254: sub modify_coursedefaults {
1.212 raeburn 21255: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21256: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21257: my %defaultchecked = (
21258: 'canuse_pdfforms' => 'off',
21259: 'uselcmath' => 'on',
1.398 raeburn 21260: 'usejsme' => 'on',
21261: 'inline_chem' => 'on',
1.404 raeburn 21262: 'ltiauth' => 'off',
1.257 raeburn 21263: );
1.404 raeburn 21264: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21265: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21266: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21267: 'coursequota_official','coursequota_unofficial','coursequota_community',
21268: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21269: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21270: 'mysqltables_placement');
1.271 raeburn 21271: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21272: my %staticdefaults = (
21273: anonsurvey_threshold => 10,
21274: uploadquota => 500,
1.428 raeburn 21275: coursequota => 20,
1.257 raeburn 21276: postsubmit => 60,
1.276 raeburn 21277: mysqltables => 172800,
1.422 raeburn 21278: domexttool => 1,
1.432 raeburn 21279: crsauthor => 1,
1.438 raeburn 21280: crseditors => ['edit','xml'],
1.198 raeburn 21281: );
1.314 raeburn 21282: my %texoptions = (
21283: MathJax => 'MathJax',
21284: mimetex => &mt('Convert to Images'),
21285: tth => &mt('TeX to HTML'),
21286: );
1.438 raeburn 21287:
21288: my @editors = ('edit','xml','daxe');
21289: my %editornames = &crseditor_titles();
21290:
1.121 raeburn 21291: $defaultshash{'coursedefaults'} = {};
21292:
21293: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21294: if ($domconfig{'coursedefaults'} eq '') {
21295: $domconfig{'coursedefaults'} = {};
21296: }
21297: }
21298:
21299: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21300: foreach my $item (@toggles) {
21301: if ($defaultchecked{$item} eq 'on') {
21302: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21303: ($env{'form.'.$item} eq '0')) {
21304: $changes{$item} = 1;
1.192 raeburn 21305: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21306: $changes{$item} = 1;
21307: }
21308: } elsif ($defaultchecked{$item} eq 'off') {
21309: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21310: ($env{'form.'.$item} eq '1')) {
21311: $changes{$item} = 1;
21312: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21313: $changes{$item} = 1;
21314: }
21315: }
21316: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21317: }
1.198 raeburn 21318: foreach my $item (@numbers) {
21319: my ($currdef,$newdef);
1.208 raeburn 21320: $newdef = $env{'form.'.$item};
1.198 raeburn 21321: if ($item eq 'anonsurvey_threshold') {
21322: $currdef = $domconfig{'coursedefaults'}{$item};
21323: $newdef =~ s/\D//g;
21324: if ($newdef eq '' || $newdef < 1) {
21325: $newdef = 1;
21326: }
21327: $defaultshash{'coursedefaults'}{$item} = $newdef;
21328: } else {
1.428 raeburn 21329: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21330: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21331: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21332: }
21333: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21334: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21335: }
21336: if ($currdef ne $newdef) {
21337: if ($item eq 'anonsurvey_threshold') {
21338: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21339: $changes{$item} = 1;
21340: }
1.428 raeburn 21341: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21342: my $setting = $1;
1.276 raeburn 21343: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21344: $changes{$setting} = 1;
1.198 raeburn 21345: }
21346: }
1.139 raeburn 21347: }
21348: }
1.314 raeburn 21349: my $texengine;
21350: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21351: $texengine = $env{'form.texengine'};
1.349 raeburn 21352: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21353: if ($currdef eq '') {
21354: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21355: $changes{'texengine'} = 1;
21356: }
1.349 raeburn 21357: } elsif ($currdef ne $texengine) {
1.314 raeburn 21358: $changes{'texengine'} = 1;
21359: }
21360: }
21361: if ($texengine ne '') {
21362: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21363: }
1.264 raeburn 21364: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21365: my @currclonecode;
21366: if (ref($currclone) eq 'HASH') {
21367: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21368: @currclonecode = @{$currclone->{'instcode'}};
21369: }
21370: }
21371: my $newclone;
1.289 raeburn 21372: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21373: $newclone = $env{'form.canclone'};
21374: }
21375: if ($newclone eq 'instcode') {
21376: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21377: my (%codedefaults,@code_order,@clonecode);
21378: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21379: \@code_order);
21380: foreach my $item (@code_order) {
21381: if (grep(/^\Q$item\E$/,@newcodes)) {
21382: push(@clonecode,$item);
21383: }
21384: }
21385: if (@clonecode) {
21386: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21387: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21388: if (@diffs) {
21389: $changes{'canclone'} = 1;
21390: }
21391: } else {
21392: $newclone eq '';
21393: }
21394: } elsif ($newclone ne '') {
1.289 raeburn 21395: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21396: }
1.264 raeburn 21397: if ($newclone ne $currclone) {
21398: $changes{'canclone'} = 1;
21399: }
1.257 raeburn 21400: my %credits;
21401: foreach my $type (@types) {
21402: unless ($type eq 'community') {
21403: $credits{$type} = $env{'form.'.$type.'_credits'};
21404: $credits{$type} =~ s/[^\d.]+//g;
21405: }
21406: }
21407: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21408: ($env{'form.coursecredits'} eq '1')) {
21409: $changes{'coursecredits'} = 1;
21410: foreach my $type (keys(%credits)) {
21411: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21412: }
21413: } else {
1.289 raeburn 21414: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21415: foreach my $type (@types) {
21416: unless ($type eq 'community') {
1.289 raeburn 21417: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21418: $changes{'coursecredits'} = 1;
21419: }
21420: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21421: }
21422: }
21423: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21424: foreach my $type (@types) {
21425: unless ($type eq 'community') {
21426: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21427: $changes{'coursecredits'} = 1;
21428: last;
21429: }
21430: }
21431: }
21432: }
21433: }
21434: if ($env{'form.postsubmit'} eq '1') {
21435: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21436: my %currtimeout;
21437: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21438: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21439: $changes{'postsubmit'} = 1;
21440: }
21441: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21442: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21443: }
21444: } else {
21445: $changes{'postsubmit'} = 1;
21446: }
21447: foreach my $type (@types) {
21448: my $timeout = $env{'form.'.$type.'_timeout'};
21449: $timeout =~ s/\D//g;
21450: if ($timeout == $staticdefaults{'postsubmit'}) {
21451: $timeout = '';
21452: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21453: $timeout = '0';
21454: }
21455: unless ($timeout eq '') {
21456: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21457: }
21458: if (exists($currtimeout{$type})) {
21459: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21460: $changes{'postsubmit'} = 1;
1.257 raeburn 21461: }
21462: } elsif ($timeout ne '') {
21463: $changes{'postsubmit'} = 1;
21464: }
21465: }
21466: } else {
21467: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21468: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21469: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21470: $changes{'postsubmit'} = 1;
21471: }
21472: } else {
21473: $changes{'postsubmit'} = 1;
21474: }
1.192 raeburn 21475: }
1.438 raeburn 21476: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor,
21477: %posscrseditors);
1.422 raeburn 21478: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21479: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 raeburn 21480: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.438 raeburn 21481: map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
1.422 raeburn 21482: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21483: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21484: } else {
21485: foreach my $type (@types) {
21486: if ($staticdefaults{'domexttool'}) {
21487: $olddomexttool{$type} = 1;
21488: } else {
21489: $olddomexttool{$type} = 0;
21490: }
21491: }
21492: }
21493: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21494: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21495: } else {
21496: foreach my $type (@types) {
21497: if ($staticdefaults{'exttool'}) {
21498: $oldexttool{$type} = 1;
21499: } else {
21500: $oldexttool{$type} = 0;
21501: }
21502: }
21503: }
1.432 raeburn 21504: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21505: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
21506: } else {
21507: foreach my $type (@types) {
21508: if ($staticdefaults{'crsauthor'}) {
21509: $oldcrsauthor{$type} = 1;
21510: } else {
21511: $oldcrsauthor{$type} = 0;
21512: }
21513: }
21514: }
1.438 raeburn 21515: my @newcrseditors = ();
21516: foreach my $editor (@editors) {
21517: if ($posscrseditors{$editor}) {
21518: push(@newcrseditors,$editor);
21519: }
21520: }
21521: if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21522: my @diffs =
21523: &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
21524: \@newcrseditors);
21525: if (@diffs) {
21526: $changes{'crseditors'} = 1;
21527: }
21528: } else {
21529: my @diffs =
21530: &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
21531: \@newcrseditors);
21532: unless (@diffs == 0) {
21533: $changes{'crseditors'} = 1;
21534: }
21535: }
1.422 raeburn 21536: foreach my $type (@types) {
21537: unless ($newdomexttool{$type}) {
21538: $newdomexttool{$type} = 0;
21539: }
21540: unless ($newexttool{$type}) {
21541: $newexttool{$type} = 0;
21542: }
1.432 raeburn 21543: unless ($newcrsauthor{$type}) {
21544: $newcrsauthor{$type} = 0;
21545: }
1.422 raeburn 21546: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21547: $changes{'domexttool'} = 1;
21548: }
21549: if ($newexttool{$type} != $oldexttool{$type}) {
21550: $changes{'exttool'} = 1;
21551: }
1.432 raeburn 21552: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
21553: $changes{'crsauthor'} = 1;
21554: }
1.422 raeburn 21555: }
21556: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21557: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 raeburn 21558: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.438 raeburn 21559: $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 21560: }
21561: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21562: $dom);
21563: if ($putresult eq 'ok') {
21564: if (keys(%changes) > 0) {
1.213 raeburn 21565: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21566: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21567: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21568: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21569: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 raeburn 21570: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21571: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21572: 'ltiauth') {
1.257 raeburn 21573: if ($changes{$item}) {
21574: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21575: }
1.289 raeburn 21576: }
1.192 raeburn 21577: if ($changes{'coursecredits'}) {
21578: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21579: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21580: $domdefaults{$type.'credits'} =
21581: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21582: }
21583: }
21584: }
21585: if ($changes{'postsubmit'}) {
21586: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21587: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21588: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21589: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21590: $domdefaults{$type.'postsubtimeout'} =
21591: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21592: }
21593: }
1.192 raeburn 21594: }
21595: }
1.198 raeburn 21596: if ($changes{'uploadquota'}) {
21597: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21598: foreach my $type (@types) {
21599: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21600: }
21601: }
21602: }
1.428 raeburn 21603: if ($changes{'coursequota'}) {
21604: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21605: foreach my $type (@types) {
21606: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21607: }
21608: }
21609: }
1.264 raeburn 21610: if ($changes{'canclone'}) {
21611: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21612: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21613: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21614: if (@clonecodes) {
21615: $domdefaults{'canclone'} = join('+',@clonecodes);
21616: }
21617: }
21618: } else {
21619: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21620: }
21621: }
1.422 raeburn 21622: if ($changes{'domexttool'}) {
21623: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21624: foreach my $type (@types) {
21625: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21626: }
21627: }
21628: }
21629: if ($changes{'exttool'}) {
21630: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21631: foreach my $type (@types) {
21632: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21633: }
21634: }
21635: }
1.432 raeburn 21636: if ($changes{'crsauthor'}) {
21637: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21638: foreach my $type (@types) {
21639: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
21640: }
21641: }
21642: }
1.438 raeburn 21643: if ($changes{'crseditors'}) {
21644: if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21645: $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
21646: }
21647: }
1.121 raeburn 21648: my $cachetime = 24*60*60;
21649: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21650: if (ref($lastactref) eq 'HASH') {
21651: $lastactref->{'domdefaults'} = 1;
21652: }
1.121 raeburn 21653: }
21654: $resulttext = &mt('Changes made:').'<ul>';
21655: foreach my $item (sort(keys(%changes))) {
21656: if ($item eq 'canuse_pdfforms') {
21657: if ($env{'form.'.$item} eq '1') {
21658: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21659: } else {
21660: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21661: }
1.257 raeburn 21662: } elsif ($item eq 'uselcmath') {
21663: if ($env{'form.'.$item} eq '1') {
21664: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21665: } else {
21666: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21667: }
21668: } elsif ($item eq 'usejsme') {
21669: if ($env{'form.'.$item} eq '1') {
21670: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21671: } else {
1.289 raeburn 21672: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21673: }
1.398 raeburn 21674: } elsif ($item eq 'inline_chem') {
21675: if ($env{'form.'.$item} eq '1') {
21676: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21677: } else {
21678: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21679: }
1.314 raeburn 21680: } elsif ($item eq 'texengine') {
21681: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21682: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21683: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21684: }
1.139 raeburn 21685: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21686: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21687: } elsif ($item eq 'uploadquota') {
21688: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21689: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21690: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21691: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21692: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21693: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21694: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21695: '</ul>'.
21696: '</li>';
21697: } else {
21698: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21699: }
1.428 raeburn 21700: } elsif ($item eq 'coursequota') {
21701: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21702: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21703: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21704: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21705: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21706: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21707: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21708: '</ul>'.
21709: '</li>';
21710: } else {
21711: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21712: }
1.276 raeburn 21713: } elsif ($item eq 'mysqltables') {
21714: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21715: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21716: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21717: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21718: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21719: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21720: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21721: '</ul>'.
21722: '</li>';
21723: } else {
21724: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21725: }
1.257 raeburn 21726: } elsif ($item eq 'postsubmit') {
21727: if ($domdefaults{'postsubmit'} eq 'off') {
21728: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21729: } else {
21730: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21731: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21732: $resulttext .= &mt('durations:').'<ul>';
21733: foreach my $type (@types) {
21734: $resulttext .= '<li>';
21735: my $timeout;
21736: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21737: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21738: }
21739: my $display;
21740: if ($timeout eq '0') {
21741: $display = &mt('unlimited');
21742: } elsif ($timeout eq '') {
21743: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21744: } else {
21745: $display = &mt('[quant,_1,second]',$timeout);
21746: }
21747: if ($type eq 'community') {
21748: $resulttext .= &mt('Communities');
21749: } elsif ($type eq 'official') {
21750: $resulttext .= &mt('Official courses');
21751: } elsif ($type eq 'unofficial') {
21752: $resulttext .= &mt('Unofficial courses');
21753: } elsif ($type eq 'textbook') {
21754: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21755: } elsif ($type eq 'placement') {
21756: $resulttext .= &mt('Placement tests');
1.257 raeburn 21757: }
21758: $resulttext .= ' -- '.$display.'</li>';
21759: }
21760: $resulttext .= '</ul>';
21761: }
1.289 raeburn 21762: $resulttext .= '</li>';
1.257 raeburn 21763: }
1.192 raeburn 21764: } elsif ($item eq 'coursecredits') {
21765: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21766: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21767: ($domdefaults{'unofficialcredits'} eq '') &&
21768: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21769: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21770: } else {
21771: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21772: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21773: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21774: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21775: '</ul>'.
21776: '</li>';
21777: }
21778: } else {
21779: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21780: }
1.264 raeburn 21781: } elsif ($item eq 'canclone') {
21782: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21783: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21784: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21785: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21786: }
21787: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21788: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21789: } else {
1.289 raeburn 21790: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21791: }
1.404 raeburn 21792: } elsif ($item eq 'ltiauth') {
21793: if ($env{'form.'.$item} eq '1') {
21794: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21795: } else {
21796: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21797: }
1.432 raeburn 21798: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21799: my @noyes = (&mt('no'),&mt('yes'));
1.432 raeburn 21800: my %status = (
21801: domexttool => {
21802: ishash => &mt('External Tools defined in the domain may be used as follows:'),
21803: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
21804: },
21805: exttool => {
21806: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
21807: default => &mt('External Tools can not be defined in any course types, by default'),
21808: },
21809: crsauthor => {
21810: ishash => &mt('Standard Problems can be created within course containers as follows:'),
21811: default => &mt('Standard Problems can be created within any course type, by default'),
21812: },
21813: );
21814:
21815: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
21816: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
21817: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
21818: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
21819: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
21820: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
21821: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21822: '</ul>'.
21823: '</li>';
21824: } else {
1.432 raeburn 21825: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21826: }
1.438 raeburn 21827: } elsif ($item eq 'crseditors') {
21828: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
21829: my $shown;
21830: if (@{$defaultshash{'coursedefaults'}{$item}}) {
21831: $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
21832: } else {
21833: $shown = &mt('None');
21834: }
21835: $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
21836: }
1.140 raeburn 21837: }
1.121 raeburn 21838: }
21839: $resulttext .= '</ul>';
21840: } else {
21841: $resulttext = &mt('No changes made to course defaults');
21842: }
21843: } else {
21844: $resulttext = '<span class="LC_error">'.
21845: &mt('An error occurred: [_1]',$putresult).'</span>';
21846: }
21847: return $resulttext;
21848: }
21849:
1.231 raeburn 21850: sub modify_selfenrollment {
21851: my ($dom,$lastactref,%domconfig) = @_;
21852: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21853: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21854: my %titles = &tool_titles();
1.232 raeburn 21855: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21856: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21857: $ordered{'default'} = ['types','registered','approval','limit'];
21858:
21859: my (%roles,%shown,%toplevel);
21860: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21861:
21862: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21863: if ($domconfig{'selfenrollment'} eq '') {
21864: $domconfig{'selfenrollment'} = {};
21865: }
21866: }
21867: %toplevel = (
21868: admin => 'Configuration Rights',
21869: default => 'Default settings',
21870: validation => 'Validation of self-enrollment requests',
21871: );
1.233 raeburn 21872: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21873:
21874: if (ref($ordered{'admin'}) eq 'ARRAY') {
21875: foreach my $item (@{$ordered{'admin'}}) {
21876: foreach my $type (@types) {
21877: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21878: $selfenrollhash{'admin'}{$type}{$item} = 1;
21879: } else {
21880: $selfenrollhash{'admin'}{$type}{$item} = 0;
21881: }
21882: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21883: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21884: if ($selfenrollhash{'admin'}{$type}{$item} ne
21885: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21886: push(@{$changes{'admin'}{$type}},$item);
21887: }
21888: } else {
21889: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21890: push(@{$changes{'admin'}{$type}},$item);
21891: }
21892: }
21893: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21894: push(@{$changes{'admin'}{$type}},$item);
21895: }
21896: }
21897: }
21898: }
21899:
21900: foreach my $item (@{$ordered{'default'}}) {
21901: foreach my $type (@types) {
21902: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21903: if ($item eq 'types') {
21904: unless (($value eq 'all') || ($value eq 'dom')) {
21905: $value = '';
21906: }
21907: } elsif ($item eq 'registered') {
21908: unless ($value eq '1') {
21909: $value = 0;
21910: }
21911: } elsif ($item eq 'approval') {
21912: unless ($value =~ /^[012]$/) {
21913: $value = 0;
21914: }
21915: } else {
21916: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21917: $value = 'none';
21918: }
21919: }
21920: $selfenrollhash{'default'}{$type}{$item} = $value;
21921: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21922: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21923: if ($selfenrollhash{'default'}{$type}{$item} ne
21924: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21925: push(@{$changes{'default'}{$type}},$item);
21926: }
21927: } else {
21928: push(@{$changes{'default'}{$type}},$item);
21929: }
21930: } else {
21931: push(@{$changes{'default'}{$type}},$item);
21932: }
21933: if ($item eq 'limit') {
21934: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21935: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21936: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21937: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21938: }
21939: } else {
21940: $selfenrollhash{'default'}{$type}{'cap'} = '';
21941: }
21942: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21943: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21944: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21945: push(@{$changes{'default'}{$type}},'cap');
21946: }
21947: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21948: push(@{$changes{'default'}{$type}},'cap');
21949: }
21950: }
21951: }
21952: }
21953:
21954: foreach my $item (@{$itemsref}) {
21955: if ($item eq 'fields') {
21956: my @changed;
21957: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21958: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21959: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21960: }
21961: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21962: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21963: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21964: $domconfig{'selfenrollment'}{'validation'}{$item});
21965: } else {
21966: @changed = @{$selfenrollhash{'validation'}{$item}};
21967: }
21968: } else {
21969: @changed = @{$selfenrollhash{'validation'}{$item}};
21970: }
21971: if (@changed) {
21972: if ($selfenrollhash{'validation'}{$item}) {
21973: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21974: } else {
21975: $changes{'validation'}{$item} = &mt('None');
21976: }
21977: }
21978: } else {
21979: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21980: if ($item eq 'markup') {
21981: if ($env{'form.selfenroll_validation_'.$item}) {
21982: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21983: }
21984: }
21985: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21986: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21987: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21988: }
21989: }
21990: }
21991: }
21992:
21993: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21994: $dom);
21995: if ($putresult eq 'ok') {
21996: if (keys(%changes) > 0) {
21997: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21998: $resulttext = &mt('Changes made:').'<ul>';
21999: foreach my $key ('admin','default','validation') {
22000: if (ref($changes{$key}) eq 'HASH') {
22001: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
22002: if ($key eq 'validation') {
22003: foreach my $item (@{$itemsref}) {
22004: if (exists($changes{$key}{$item})) {
22005: if ($item eq 'markup') {
22006: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22007: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
22008: } else {
22009: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22010: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
22011: }
22012: }
22013: }
22014: } else {
22015: foreach my $type (@types) {
22016: if ($type eq 'community') {
22017: $roles{'1'} = &mt('Community personnel');
22018: } else {
22019: $roles{'1'} = &mt('Course personnel');
22020: }
22021: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 22022: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22023: if ($key eq 'admin') {
22024: my @mgrdc = ();
22025: if (ref($ordered{$key}) eq 'ARRAY') {
22026: foreach my $item (@{$ordered{'admin'}}) {
22027: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22028: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
22029: push(@mgrdc,$item);
22030: }
22031: }
22032: }
22033: if (@mgrdc) {
22034: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
22035: } else {
22036: delete($domdefaults{$type.'selfenrolladmdc'});
22037: }
22038: }
22039: } else {
22040: if (ref($ordered{$key}) eq 'ARRAY') {
22041: foreach my $item (@{$ordered{$key}}) {
22042: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22043: $domdefaults{$type.'selfenroll'.$item} =
22044: $selfenrollhash{$key}{$type}{$item};
22045: }
22046: }
22047: }
22048: }
22049: }
1.231 raeburn 22050: $resulttext .= '<li>'.$titles{$type}.'<ul>';
22051: foreach my $item (@{$ordered{$key}}) {
22052: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22053: $resulttext .= '<li>';
22054: if ($key eq 'admin') {
22055: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
22056: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
22057: } else {
22058: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
22059: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
22060: }
22061: $resulttext .= '</li>';
22062: }
22063: }
22064: $resulttext .= '</ul></li>';
22065: }
22066: }
22067: $resulttext .= '</ul></li>';
22068: }
22069: }
1.305 raeburn 22070: }
22071: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
22072: my $cachetime = 24*60*60;
22073: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22074: if (ref($lastactref) eq 'HASH') {
22075: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 22076: }
1.231 raeburn 22077: }
22078: $resulttext .= '</ul>';
22079: } else {
22080: $resulttext = &mt('No changes made to self-enrollment settings');
22081: }
22082: } else {
22083: $resulttext = '<span class="LC_error">'.
22084: &mt('An error occurred: [_1]',$putresult).'</span>';
22085: }
22086: return $resulttext;
22087: }
22088:
1.373 raeburn 22089: sub modify_wafproxy {
22090: my ($dom,$action,$lastactref,%domconfig) = @_;
22091: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 22092: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
22093: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 22094: foreach my $server (sort(keys(%servers))) {
22095: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
22096: if ($serverhome eq $server) {
22097: my $serverdom = &Apache::lonnet::host_domain($server);
22098: if ($serverdom eq $dom) {
22099: $canset{$server} = 1;
22100: }
22101: }
22102: }
1.381 raeburn 22103: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
22104: %{$values{$dom}} = ();
22105: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
22106: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
22107: }
1.388 raeburn 22108: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
22109: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
22110: }
1.382 raeburn 22111: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 22112: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
22113: }
22114: }
1.373 raeburn 22115: my $output;
22116: if (keys(%canset)) {
22117: %{$wafproxy{'alias'}} = ();
1.388 raeburn 22118: %{$wafproxy{'saml'}} = ();
1.373 raeburn 22119: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 22120: if ($env{'form.wafproxy_'.$dom}) {
22121: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
22122: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
22123: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
22124: $changes{'alias'} = 1;
22125: }
1.388 raeburn 22126: if ($env{'form.wafproxy_alias_saml_'.$key}) {
22127: $wafproxy{'saml'}{$key} = 1;
22128: }
22129: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
22130: $changes{'saml'} = 1;
22131: }
1.381 raeburn 22132: } else {
22133: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 22134: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 22135: if ($curralias{$key}) {
22136: $changes{'alias'} = 1;
22137: }
1.388 raeburn 22138: if ($currsaml{$key}) {
22139: $changes{'saml'} = 1;
22140: }
1.373 raeburn 22141: }
22142: if ($wafproxy{'alias'}{$key} eq '') {
22143: if ($curralias{$key}) {
22144: $expirecache{$key} = 1;
22145: }
22146: delete($wafproxy{'alias'}{$key});
22147: }
1.388 raeburn 22148: if ($wafproxy{'saml'}{$key} eq '') {
22149: if ($currsaml{$key}) {
22150: $expiresaml{$key} = 1;
22151: }
22152: delete($wafproxy{'saml'}{$key});
22153: }
1.373 raeburn 22154: }
22155: unless (keys(%{$wafproxy{'alias'}})) {
22156: delete($wafproxy{'alias'});
22157: }
1.388 raeburn 22158: unless (keys(%{$wafproxy{'saml'}})) {
22159: delete($wafproxy{'saml'});
22160: }
22161: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 22162: my %warn = (
22163: trusted => 'trusted IP range(s)',
1.381 raeburn 22164: vpnint => 'internal IP range(s) for VPN sessions(s)',
22165: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 22166: );
1.382 raeburn 22167: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22168: my $possible = $env{'form.wafproxy_'.$item};
22169: $possible =~ s/^\s+|\s+$//g;
22170: if ($possible ne '') {
1.381 raeburn 22171: if ($item eq 'remoteip') {
22172: if ($possible =~ /^[mhn]$/) {
22173: $wafproxy{$item} = $possible;
22174: }
22175: } elsif ($item eq 'ipheader') {
22176: if ($wafproxy{'remoteip'} eq 'h') {
22177: $wafproxy{$item} = $possible;
22178: }
1.382 raeburn 22179: } elsif ($item eq 'sslopt') {
22180: if ($possible =~ /^0|1$/) {
22181: $wafproxy{$item} = $possible;
22182: }
1.373 raeburn 22183: } else {
22184: my (@ok,$count);
1.381 raeburn 22185: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
22186: unless ($env{'form.wafproxy_vpnaccess'}) {
22187: $possible = '';
22188: }
22189: } elsif ($item eq 'trusted') {
22190: unless ($wafproxy{'remoteip'} eq 'h') {
22191: $possible = '';
22192: }
22193: }
22194: unless ($possible eq '') {
22195: $possible =~ s/[\r\n]+/\s/g;
22196: $possible =~ s/\s*-\s*/-/g;
22197: $possible =~ s/\s+/,/g;
1.393 raeburn 22198: $possible =~ s/,+/,/g;
1.381 raeburn 22199: }
1.373 raeburn 22200: $count = 0;
1.381 raeburn 22201: if ($possible ne '') {
1.373 raeburn 22202: foreach my $poss (split(/\,/,$possible)) {
22203: $count ++;
1.393 raeburn 22204: $poss = &validate_ip_pattern($poss);
22205: if ($poss ne '') {
1.373 raeburn 22206: push(@ok,$poss);
22207: }
22208: }
22209: my $diff = $count - scalar(@ok);
22210: if ($diff) {
22211: push(@warnings,'<li>'.
22212: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
22213: $diff,$warn{$item}).
22214: '</li>');
22215: }
1.393 raeburn 22216: if (@ok) {
22217: my @cidr_list;
22218: foreach my $item (@ok) {
22219: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
22220: }
22221: $wafproxy{$item} = join(',',@cidr_list);
22222: }
1.373 raeburn 22223: }
22224: }
1.381 raeburn 22225: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 22226: $changes{$item} = 1;
22227: }
1.381 raeburn 22228: } elsif ($currvalue{$item}) {
22229: $changes{$item} = 1;
1.425 raeburn 22230: }
1.381 raeburn 22231: }
22232: } else {
22233: if (keys(%curralias)) {
22234: $changes{'alias'} = 1;
1.388 raeburn 22235: }
22236: if (keys(%currsaml)) {
22237: $changes{'saml'} = 1;
1.425 raeburn 22238: }
1.381 raeburn 22239: if (keys(%currvalue)) {
22240: foreach my $key (keys(%currvalue)) {
22241: $changes{$key} = 1;
1.373 raeburn 22242: }
22243: }
22244: }
22245: if (keys(%changes)) {
22246: my %defaultshash = (
22247: wafproxy => \%wafproxy,
1.425 raeburn 22248: );
1.373 raeburn 22249: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22250: $dom);
22251: if ($putresult eq 'ok') {
22252: my $cachetime = 24*60*60;
22253: my (%domdefaults,$updatedomdefs);
1.382 raeburn 22254: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22255: if ($changes{$item}) {
22256: unless ($updatedomdefs) {
22257: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
22258: $updatedomdefs = 1;
22259: }
22260: if ($wafproxy{$item}) {
22261: $domdefaults{'waf_'.$item} = $wafproxy{$item};
22262: } elsif (exists($domdefaults{'waf_'.$item})) {
22263: delete($domdefaults{'waf_'.$item});
1.425 raeburn 22264: }
1.373 raeburn 22265: }
22266: }
22267: if ($updatedomdefs) {
22268: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22269: if (ref($lastactref) eq 'HASH') {
22270: $lastactref->{'domdefaults'} = 1;
22271: }
22272: }
22273: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22274: my %updates = %expirecache;
22275: foreach my $key (keys(%expirecache)) {
22276: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22277: }
22278: if (ref($wafproxy{'alias'}) eq 'HASH') {
22279: my $cachetime = 24*60*60;
22280: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22281: $updates{$key} = 1;
22282: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22283: $cachetime);
22284: }
22285: }
22286: if (ref($lastactref) eq 'HASH') {
22287: $lastactref->{'proxyalias'} = \%updates;
22288: }
22289: }
1.388 raeburn 22290: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22291: my %samlupdates = %expiresaml;
22292: foreach my $key (keys(%expiresaml)) {
22293: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22294: }
22295: if (ref($wafproxy{'saml'}) eq 'HASH') {
22296: my $cachetime = 24*60*60;
22297: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22298: $samlupdates{$key} = 1;
22299: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22300: $cachetime);
22301: }
22302: }
22303: if (ref($lastactref) eq 'HASH') {
22304: $lastactref->{'proxysaml'} = \%samlupdates;
22305: }
22306: }
1.373 raeburn 22307: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22308: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22309: if ($changes{$item}) {
22310: if ($item eq 'alias') {
22311: my $numaliased = 0;
22312: if (ref($wafproxy{'alias'}) eq 'HASH') {
22313: my $shown;
22314: if (keys(%{$wafproxy{'alias'}})) {
22315: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22316: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22317: &Apache::lonnet::hostname($server),
22318: $wafproxy{'alias'}{$server}).'</li>';
22319: $numaliased ++;
22320: }
22321: if ($numaliased) {
22322: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22323: '<ul>'.$shown.'</ul>').'</li>';
22324: }
22325: }
22326: }
22327: unless ($numaliased) {
22328: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22329: }
1.388 raeburn 22330: } elsif ($item eq 'saml') {
1.425 raeburn 22331: my $shown;
1.388 raeburn 22332: if (ref($wafproxy{'saml'}) eq 'HASH') {
22333: if (keys(%{$wafproxy{'saml'}})) {
22334: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22335: }
22336: }
22337: if ($shown) {
1.396 raeburn 22338: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22339: $shown).'</li>';
22340: } else {
1.396 raeburn 22341: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22342: }
1.373 raeburn 22343: } else {
1.381 raeburn 22344: if ($item eq 'remoteip') {
22345: my %ip_methods = &remoteip_methods();
22346: if ($wafproxy{$item} =~ /^[mh]$/) {
22347: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22348: $ip_methods{$wafproxy{$item}}).'</li>';
22349: } else {
22350: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22351: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22352: '</li>';
22353: } else {
22354: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22355: }
22356: }
22357: } elsif ($item eq 'ipheader') {
1.373 raeburn 22358: if ($wafproxy{$item}) {
1.381 raeburn 22359: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22360: $wafproxy{$item}).'</li>';
22361: } else {
1.381 raeburn 22362: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22363: }
22364: } elsif ($item eq 'trusted') {
22365: if ($wafproxy{$item}) {
1.381 raeburn 22366: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22367: $wafproxy{$item}).'</li>';
22368: } else {
22369: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22370: }
1.381 raeburn 22371: } elsif ($item eq 'vpnint') {
22372: if ($wafproxy{$item}) {
22373: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22374: $wafproxy{$item}).'</li>';
22375: } else {
22376: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22377: }
22378: } elsif ($item eq 'vpnext') {
1.373 raeburn 22379: if ($wafproxy{$item}) {
1.381 raeburn 22380: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22381: $wafproxy{$item}).'</li>';
22382: } else {
1.381 raeburn 22383: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22384: }
1.382 raeburn 22385: } elsif ($item eq 'sslopt') {
22386: if ($wafproxy{$item}) {
22387: $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>';
22388: } else {
22389: $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>';
22390: }
1.373 raeburn 22391: }
22392: }
22393: }
22394: }
1.420 raeburn 22395: $output .= '</ul>';
1.373 raeburn 22396: } else {
22397: $output = '<span class="LC_error">'.
22398: &mt('An error occurred: [_1]',$putresult).'</span>';
22399: }
22400: } elsif (keys(%canset)) {
22401: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22402: }
22403: if (@warnings) {
22404: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22405: join("\n",@warnings).'</ul>';
22406: }
22407: return $output;
22408: }
22409:
22410: sub validate_ip_pattern {
22411: my ($pattern) = @_;
22412: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22413: my ($start,$end) = ($1,$2);
22414: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22415: if (($start !~ m{/}) && ($end !~ m{/})) {
22416: return $start.'-'.$end;
22417: }
22418: }
22419: } elsif ($pattern ne '') {
22420: $pattern = &Net::CIDR::cidrvalidate($pattern);
22421: if ($pattern ne '') {
22422: return $pattern;
1.373 raeburn 22423: }
22424: }
1.393 raeburn 22425: return;
1.373 raeburn 22426: }
22427:
1.137 raeburn 22428: sub modify_usersessions {
1.212 raeburn 22429: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22430: my @hostingtypes = ('version','excludedomain','includedomain');
22431: my @offloadtypes = ('primary','default');
22432: my %types = (
22433: remote => \@hostingtypes,
22434: hosted => \@hostingtypes,
22435: spares => \@offloadtypes,
22436: );
22437: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22438: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22439: my (%by_ip,%by_location,@intdoms,@instdoms);
22440: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22441: my @locations = sort(keys(%by_location));
1.137 raeburn 22442: my (%defaultshash,%changes);
22443: foreach my $prefix (@prefixes) {
22444: $defaultshash{'usersessions'}{$prefix} = {};
22445: }
1.212 raeburn 22446: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22447: my $resulttext;
1.138 raeburn 22448: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22449: foreach my $prefix (@prefixes) {
1.145 raeburn 22450: next if ($prefix eq 'spares');
22451: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22452: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22453: if ($type eq 'version') {
22454: my $value = $env{'form.'.$prefix.'_'.$type};
22455: my $okvalue;
22456: if ($value ne '') {
22457: if (grep(/^\Q$value\E$/,@lcversions)) {
22458: $okvalue = $value;
22459: }
22460: }
22461: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22462: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22463: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22464: if ($inuse == 0) {
22465: $changes{$prefix}{$type} = 1;
22466: } else {
22467: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22468: $changes{$prefix}{$type} = 1;
22469: }
22470: if ($okvalue ne '') {
22471: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22472: }
22473: }
22474: } else {
22475: if (($inuse == 1) && ($okvalue ne '')) {
22476: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22477: $changes{$prefix}{$type} = 1;
22478: }
22479: }
22480: } else {
22481: if (($inuse == 1) && ($okvalue ne '')) {
22482: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22483: $changes{$prefix}{$type} = 1;
22484: }
22485: }
22486: } else {
22487: if (($inuse == 1) && ($okvalue ne '')) {
22488: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22489: $changes{$prefix}{$type} = 1;
22490: }
22491: }
22492: } else {
22493: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22494: my @okvals;
22495: foreach my $val (@vals) {
1.138 raeburn 22496: if ($val =~ /:/) {
22497: my @items = split(/:/,$val);
22498: foreach my $item (@items) {
22499: if (ref($by_location{$item}) eq 'ARRAY') {
22500: push(@okvals,$item);
22501: }
22502: }
22503: } else {
22504: if (ref($by_location{$val}) eq 'ARRAY') {
22505: push(@okvals,$val);
22506: }
1.137 raeburn 22507: }
22508: }
22509: @okvals = sort(@okvals);
22510: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22511: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22512: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22513: if ($inuse == 0) {
22514: $changes{$prefix}{$type} = 1;
22515: } else {
22516: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22517: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22518: if (@changed > 0) {
22519: $changes{$prefix}{$type} = 1;
22520: }
22521: }
22522: } else {
22523: if ($inuse == 1) {
22524: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22525: $changes{$prefix}{$type} = 1;
22526: }
22527: }
22528: } else {
22529: if ($inuse == 1) {
22530: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22531: $changes{$prefix}{$type} = 1;
22532: }
22533: }
22534: } else {
22535: if ($inuse == 1) {
22536: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22537: $changes{$prefix}{$type} = 1;
22538: }
22539: }
22540: }
22541: }
22542: }
1.145 raeburn 22543:
22544: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22545: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22546: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22547: my $savespares;
22548:
22549: foreach my $lonhost (sort(keys(%servers))) {
22550: my $serverhomeID =
22551: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22552: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22553: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22554: my %spareschg;
22555: foreach my $type (@{$types{'spares'}}) {
22556: my @okspares;
22557: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22558: foreach my $server (@checked) {
1.152 raeburn 22559: if (&Apache::lonnet::hostname($server) ne '') {
22560: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22561: unless (grep(/^\Q$server\E$/,@okspares)) {
22562: push(@okspares,$server);
22563: }
1.145 raeburn 22564: }
22565: }
22566: }
22567: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22568: my $newspare;
1.152 raeburn 22569: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22570: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22571: $newspare = $new;
22572: }
22573: }
1.152 raeburn 22574: my @spares;
22575: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22576: @spares = sort(@okspares,$newspare);
22577: } else {
22578: @spares = sort(@okspares);
22579: }
22580: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22581: if (ref($spareid{$lonhost}) eq 'HASH') {
22582: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22583: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22584: if (@diffs > 0) {
22585: $spareschg{$type} = 1;
22586: }
22587: }
22588: }
22589: }
22590: if (keys(%spareschg) > 0) {
22591: $changes{'spares'}{$lonhost} = \%spareschg;
22592: }
22593: }
1.261 raeburn 22594: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22595: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22596: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22597: my @okoffload;
22598: if (@offloadnow) {
22599: foreach my $server (@offloadnow) {
22600: if (&Apache::lonnet::hostname($server) ne '') {
22601: unless (grep(/^\Q$server\E$/,@okoffload)) {
22602: push(@okoffload,$server);
22603: }
22604: }
22605: }
22606: if (@okoffload) {
22607: foreach my $lonhost (@okoffload) {
22608: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22609: }
22610: }
22611: }
1.371 raeburn 22612: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22613: my @okoffloadoth;
22614: if (@offloadoth) {
22615: foreach my $server (@offloadoth) {
22616: if (&Apache::lonnet::hostname($server) ne '') {
22617: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22618: push(@okoffloadoth,$server);
22619: }
22620: }
22621: }
22622: if (@okoffloadoth) {
22623: foreach my $lonhost (@okoffloadoth) {
22624: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22625: }
22626: }
22627: }
1.145 raeburn 22628: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22629: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22630: if (ref($changes{'spares'}) eq 'HASH') {
22631: if (keys(%{$changes{'spares'}}) > 0) {
22632: $savespares = 1;
22633: }
22634: }
22635: } else {
22636: $savespares = 1;
22637: }
1.371 raeburn 22638: foreach my $offload ('offloadnow','offloadoth') {
22639: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22640: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22641: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22642: $changes{$offload} = 1;
22643: last;
22644: }
1.261 raeburn 22645: }
1.371 raeburn 22646: unless ($changes{$offload}) {
22647: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22648: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22649: $changes{$offload} = 1;
22650: last;
22651: }
1.261 raeburn 22652: }
22653: }
1.371 raeburn 22654: } else {
22655: if (($offload eq 'offloadnow') && (@okoffload)) {
22656: $changes{'offloadnow'} = 1;
22657: }
22658: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22659: $changes{'offloadoth'} = 1;
22660: }
1.425 raeburn 22661: }
1.371 raeburn 22662: }
22663: } else {
22664: if (@okoffload) {
1.261 raeburn 22665: $changes{'offloadnow'} = 1;
22666: }
1.371 raeburn 22667: if (@okoffloadoth) {
22668: $changes{'offloadoth'} = 1;
22669: }
1.145 raeburn 22670: }
1.147 raeburn 22671: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22672: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22673: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22674: $dom);
22675: if ($putresult eq 'ok') {
22676: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22677: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22678: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22679: }
22680: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22681: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22682: }
1.261 raeburn 22683: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22684: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22685: }
1.371 raeburn 22686: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22687: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22688: }
1.137 raeburn 22689: }
22690: my $cachetime = 24*60*60;
22691: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22692: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22693: if (ref($lastactref) eq 'HASH') {
22694: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22695: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22696: }
1.147 raeburn 22697: if (keys(%changes) > 0) {
22698: my %lt = &usersession_titles();
22699: $resulttext = &mt('Changes made:').'<ul>';
22700: foreach my $prefix (@prefixes) {
22701: if (ref($changes{$prefix}) eq 'HASH') {
22702: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22703: if ($prefix eq 'spares') {
22704: if (ref($changes{$prefix}) eq 'HASH') {
22705: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22706: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22707: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22708: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22709: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22710: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22711: foreach my $type (@{$types{$prefix}}) {
22712: if ($changes{$prefix}{$lonhost}{$type}) {
22713: my $offloadto = &mt('None');
22714: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22715: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22716: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22717: }
1.145 raeburn 22718: }
1.147 raeburn 22719: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22720: }
1.137 raeburn 22721: }
22722: }
1.147 raeburn 22723: $resulttext .= '</li>';
1.137 raeburn 22724: }
22725: }
1.147 raeburn 22726: } else {
22727: foreach my $type (@{$types{$prefix}}) {
22728: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22729: my ($newvalue,$notinuse);
1.147 raeburn 22730: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22731: if (ref($defaultshash{'usersessions'}{$prefix})) {
22732: if ($type eq 'version') {
22733: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22734: } else {
22735: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22736: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22737: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22738: }
22739: } else {
22740: $notinuse = 1;
1.147 raeburn 22741: }
1.145 raeburn 22742: }
22743: }
22744: }
1.147 raeburn 22745: if ($newvalue eq '') {
22746: if ($type eq 'version') {
22747: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22748: } elsif ($notinuse) {
22749: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22750: } else {
22751: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22752: }
1.145 raeburn 22753: } else {
1.147 raeburn 22754: if ($type eq 'version') {
1.344 raeburn 22755: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22756: }
22757: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22758: }
1.137 raeburn 22759: }
22760: }
22761: }
1.147 raeburn 22762: $resulttext .= '</ul>';
1.137 raeburn 22763: }
22764: }
1.261 raeburn 22765: if ($changes{'offloadnow'}) {
22766: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22767: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22768: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22769: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22770: $resulttext .= '<li>'.$lonhost.'</li>';
22771: }
22772: $resulttext .= '</ul>';
22773: } else {
1.371 raeburn 22774: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22775: }
22776: } else {
22777: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22778: }
22779: }
22780: if ($changes{'offloadoth'}) {
22781: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22782: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22783: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22784: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22785: $resulttext .= '<li>'.$lonhost.'</li>';
22786: }
22787: $resulttext .= '</ul>';
22788: } else {
22789: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22790: }
22791: } else {
1.371 raeburn 22792: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22793: }
22794: }
1.147 raeburn 22795: $resulttext .= '</ul>';
22796: } else {
22797: $resulttext = $nochgmsg;
1.137 raeburn 22798: }
22799: } else {
22800: $resulttext = '<span class="LC_error">'.
22801: &mt('An error occurred: [_1]',$putresult).'</span>';
22802: }
22803: } else {
1.147 raeburn 22804: $resulttext = $nochgmsg;
1.137 raeburn 22805: }
22806: return $resulttext;
22807: }
22808:
1.275 raeburn 22809: sub modify_ssl {
22810: my ($dom,$lastactref,%domconfig) = @_;
22811: my (%by_ip,%by_location,@intdoms,@instdoms);
22812: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22813: my @locations = sort(keys(%by_location));
22814: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22815: my (%defaultshash,%changes);
22816: my $action = 'ssl';
1.293 raeburn 22817: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22818: foreach my $prefix (@prefixes) {
22819: $defaultshash{$action}{$prefix} = {};
22820: }
22821: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22822: my $resulttext;
22823: my %iphost = &Apache::lonnet::get_iphost();
22824: my @reptypes = ('certreq','nocertreq');
22825: my @connecttypes = ('dom','intdom','other');
22826: my %types = (
1.293 raeburn 22827: connto => \@connecttypes,
22828: connfrom => \@connecttypes,
22829: replication => \@reptypes,
1.275 raeburn 22830: );
22831: foreach my $prefix (sort(keys(%types))) {
22832: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22833: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22834: my $value = 'yes';
22835: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22836: $value = $env{'form.'.$prefix.'_'.$type};
22837: }
1.335 raeburn 22838: if (ref($domconfig{$action}) eq 'HASH') {
22839: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22840: if ($domconfig{$action}{$prefix}{$type} ne '') {
22841: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22842: $changes{$prefix}{$type} = 1;
22843: }
22844: $defaultshash{$action}{$prefix}{$type} = $value;
22845: } else {
22846: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22847: $changes{$prefix}{$type} = 1;
22848: }
22849: } else {
22850: $defaultshash{$action}{$prefix}{$type} = $value;
22851: $changes{$prefix}{$type} = 1;
22852: }
22853: } else {
22854: $defaultshash{$action}{$prefix}{$type} = $value;
22855: $changes{$prefix}{$type} = 1;
22856: }
22857: if (($type eq 'dom') && (keys(%servers) == 1)) {
22858: delete($changes{$prefix}{$type});
22859: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22860: delete($changes{$prefix}{$type});
22861: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22862: delete($changes{$prefix}{$type});
22863: }
22864: } elsif ($prefix eq 'replication') {
22865: if (@locations > 0) {
22866: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22867: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22868: my @okvals;
22869: foreach my $val (@vals) {
22870: if ($val =~ /:/) {
22871: my @items = split(/:/,$val);
22872: foreach my $item (@items) {
22873: if (ref($by_location{$item}) eq 'ARRAY') {
22874: push(@okvals,$item);
22875: }
22876: }
22877: } else {
22878: if (ref($by_location{$val}) eq 'ARRAY') {
22879: push(@okvals,$val);
22880: }
22881: }
22882: }
22883: @okvals = sort(@okvals);
22884: if (ref($domconfig{$action}) eq 'HASH') {
22885: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22886: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22887: if ($inuse == 0) {
22888: $changes{$prefix}{$type} = 1;
22889: } else {
22890: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22891: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22892: if (@changed > 0) {
22893: $changes{$prefix}{$type} = 1;
22894: }
22895: }
22896: } else {
22897: if ($inuse == 1) {
22898: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22899: $changes{$prefix}{$type} = 1;
22900: }
22901: }
22902: } else {
22903: if ($inuse == 1) {
22904: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22905: $changes{$prefix}{$type} = 1;
22906: }
22907: }
22908: } else {
22909: if ($inuse == 1) {
22910: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22911: $changes{$prefix}{$type} = 1;
22912: }
22913: }
22914: }
22915: }
22916: }
22917: }
1.336 raeburn 22918: if (keys(%changes)) {
22919: foreach my $prefix (keys(%changes)) {
22920: if (ref($changes{$prefix}) eq 'HASH') {
22921: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22922: delete($changes{$prefix});
22923: }
22924: } else {
22925: delete($changes{$prefix});
22926: }
22927: }
22928: }
1.275 raeburn 22929: my $nochgmsg = &mt('No changes made to LON-CAPA SSL 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{$action}) eq 'HASH') {
22935: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22936: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22937: }
1.293 raeburn 22938: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22939: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22940: }
22941: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22942: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22943: }
22944: }
22945: my $cachetime = 24*60*60;
22946: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22947: if (ref($lastactref) eq 'HASH') {
22948: $lastactref->{'domdefaults'} = 1;
22949: }
22950: if (keys(%changes) > 0) {
22951: my %titles = &ssl_titles();
22952: $resulttext = &mt('Changes made:').'<ul>';
22953: foreach my $prefix (@prefixes) {
22954: if (ref($changes{$prefix}) eq 'HASH') {
22955: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22956: foreach my $type (@{$types{$prefix}}) {
22957: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22958: my ($newvalue,$notinuse);
1.275 raeburn 22959: if (ref($defaultshash{$action}) eq 'HASH') {
22960: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22961: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22962: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22963: } else {
22964: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22965: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22966: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22967: }
22968: } else {
22969: $notinuse = 1;
1.275 raeburn 22970: }
22971: }
22972: }
1.344 raeburn 22973: if ($notinuse) {
22974: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22975: } elsif ($newvalue eq '') {
1.275 raeburn 22976: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22977: } else {
22978: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22979: }
22980: }
22981: }
22982: }
22983: $resulttext .= '</ul>';
22984: }
22985: }
22986: } else {
22987: $resulttext = $nochgmsg;
22988: }
22989: } else {
22990: $resulttext = '<span class="LC_error">'.
22991: &mt('An error occurred: [_1]',$putresult).'</span>';
22992: }
22993: } else {
22994: $resulttext = $nochgmsg;
22995: }
22996: return $resulttext;
22997: }
22998:
1.279 raeburn 22999: sub modify_trust {
23000: my ($dom,$lastactref,%domconfig) = @_;
23001: my (%by_ip,%by_location,@intdoms,@instdoms);
23002: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
23003: my @locations = sort(keys(%by_location));
23004: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
23005: my @types = ('exc','inc');
23006: my (%defaultshash,%changes);
23007: foreach my $prefix (@prefixes) {
23008: $defaultshash{'trust'}{$prefix} = {};
23009: }
23010: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
23011: my $resulttext;
23012: foreach my $prefix (@prefixes) {
23013: foreach my $type (@types) {
23014: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
23015: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
23016: my @okvals;
23017: foreach my $val (@vals) {
23018: if ($val =~ /:/) {
23019: my @items = split(/:/,$val);
23020: foreach my $item (@items) {
23021: if (ref($by_location{$item}) eq 'ARRAY') {
23022: push(@okvals,$item);
23023: }
23024: }
23025: } else {
23026: if (ref($by_location{$val}) eq 'ARRAY') {
23027: push(@okvals,$val);
23028: }
23029: }
23030: }
23031: @okvals = sort(@okvals);
23032: if (ref($domconfig{'trust'}) eq 'HASH') {
23033: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
23034: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23035: if ($inuse == 0) {
23036: $changes{$prefix}{$type} = 1;
23037: } else {
23038: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23039: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
23040: if (@changed > 0) {
23041: $changes{$prefix}{$type} = 1;
23042: }
23043: }
23044: } else {
23045: if ($inuse == 1) {
23046: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23047: $changes{$prefix}{$type} = 1;
23048: }
23049: }
23050: } else {
23051: if ($inuse == 1) {
23052: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23053: $changes{$prefix}{$type} = 1;
23054: }
23055: }
23056: } else {
23057: if ($inuse == 1) {
23058: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23059: $changes{$prefix}{$type} = 1;
23060: }
23061: }
23062: }
23063: }
23064: my $nochgmsg = &mt('No changes made to trust settings.');
23065: if (keys(%changes) > 0) {
23066: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
23067: $dom);
23068: if ($putresult eq 'ok') {
23069: if (ref($defaultshash{'trust'}) eq 'HASH') {
23070: foreach my $prefix (@prefixes) {
23071: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
23072: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
23073: }
23074: }
23075: }
23076: my $cachetime = 24*60*60;
23077: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 23078: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 23079: if (ref($lastactref) eq 'HASH') {
23080: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 23081: $lastactref->{'trust'} = 1;
1.279 raeburn 23082: }
23083: if (keys(%changes) > 0) {
23084: my %lt = &trust_titles();
23085: $resulttext = &mt('Changes made:').'<ul>';
23086: foreach my $prefix (@prefixes) {
23087: if (ref($changes{$prefix}) eq 'HASH') {
23088: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
23089: foreach my $type (@types) {
23090: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 23091: my ($newvalue,$notinuse);
1.279 raeburn 23092: if (ref($defaultshash{'trust'}) eq 'HASH') {
23093: if (ref($defaultshash{'trust'}{$prefix})) {
23094: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23095: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
23096: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
23097: }
1.344 raeburn 23098: } else {
23099: $notinuse = 1;
1.279 raeburn 23100: }
23101: }
23102: }
1.344 raeburn 23103: if ($notinuse) {
23104: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
23105: } elsif ($newvalue eq '') {
1.279 raeburn 23106: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
23107: } else {
23108: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
23109: }
23110: }
23111: }
23112: $resulttext .= '</ul>';
23113: }
23114: }
23115: $resulttext .= '</ul>';
23116: } else {
23117: $resulttext = $nochgmsg;
23118: }
23119: } else {
23120: $resulttext = '<span class="LC_error">'.
23121: &mt('An error occurred: [_1]',$putresult).'</span>';
23122: }
23123: } else {
23124: $resulttext = $nochgmsg;
23125: }
23126: return $resulttext;
23127: }
23128:
1.150 raeburn 23129: sub modify_loadbalancing {
23130: my ($dom,%domconfig) = @_;
23131: my $primary_id = &Apache::lonnet::domain($dom,'primary');
23132: my $intdom = &Apache::lonnet::internet_dom($primary_id);
23133: my ($othertitle,$usertypes,$types) =
23134: &Apache::loncommon::sorted_inst_types($dom);
23135: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 23136: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 23137: my @sparestypes = ('primary','default');
23138: my %typetitles = &sparestype_titles();
23139: my $resulttext;
1.342 raeburn 23140: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23141: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23142: %existing = %{$domconfig{'loadbalancing'}};
23143: }
23144: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 23145: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 23146: my ($saveloadbalancing,%defaultshash,%changes);
23147: my ($alltypes,$othertypes,$titles) =
23148: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
23149: my %ruletitles = &offloadtype_text();
23150: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
23151: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
23152: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
23153: if ($balancer eq '') {
23154: next;
23155: }
1.210 raeburn 23156: if (!exists($servers{$balancer})) {
1.171 raeburn 23157: if (exists($currbalancer{$balancer})) {
23158: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 23159: }
1.171 raeburn 23160: next;
23161: }
23162: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
23163: push(@{$changes{'delete'}},$balancer);
23164: next;
23165: }
23166: if (!exists($currbalancer{$balancer})) {
23167: push(@{$changes{'add'}},$balancer);
23168: }
23169: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
23170: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
23171: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
23172: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23173: $saveloadbalancing = 1;
23174: }
23175: foreach my $sparetype (@sparestypes) {
23176: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
23177: my @offloadto;
23178: foreach my $target (@targets) {
23179: if (($servers{$target}) && ($target ne $balancer)) {
23180: if ($sparetype eq 'default') {
23181: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
23182: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 23183: }
23184: }
1.171 raeburn 23185: unless(grep(/^\Q$target\E$/,@offloadto)) {
23186: push(@offloadto,$target);
23187: }
1.150 raeburn 23188: }
23189: }
1.284 raeburn 23190: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
23191: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
23192: push(@offloadto,$balancer);
23193: }
23194: }
23195: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 23196: }
1.342 raeburn 23197: if ($env{'form.loadbalancing_cookie_'.$i}) {
23198: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 23199: if (exists($currbalancer{$balancer})) {
1.342 raeburn 23200: unless ($currcookies{$balancer}) {
23201: $changes{'curr'}{$balancer}{'cookie'} = 1;
23202: }
23203: }
23204: } elsif (exists($currbalancer{$balancer})) {
23205: if ($currcookies{$balancer}) {
23206: $changes{'curr'}{$balancer}{'cookie'} = 1;
23207: }
23208: }
1.171 raeburn 23209: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 23210: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23211: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
23212: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 23213: if (@targetdiffs > 0) {
1.171 raeburn 23214: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23215: }
1.171 raeburn 23216: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23217: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23218: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23219: }
23220: }
23221: }
23222: } else {
1.171 raeburn 23223: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 23224: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23225: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23226: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23227: $changes{'curr'}{$balancer}{'targets'} = 1;
23228: }
1.150 raeburn 23229: }
23230: }
1.210 raeburn 23231: }
1.150 raeburn 23232: }
23233: my $ishomedom;
1.171 raeburn 23234: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
23235: $ishomedom = 1;
1.150 raeburn 23236: }
23237: if (ref($alltypes) eq 'ARRAY') {
23238: foreach my $type (@{$alltypes}) {
23239: my $rule;
1.210 raeburn 23240: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 23241: (!$ishomedom)) {
1.171 raeburn 23242: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
23243: }
23244: if ($rule eq 'specific') {
1.255 raeburn 23245: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 23246: if (exists($servers{$specifiedhost})) {
1.255 raeburn 23247: $rule = $specifiedhost;
23248: }
1.150 raeburn 23249: }
1.171 raeburn 23250: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
23251: if (ref($currrules{$balancer}) eq 'HASH') {
23252: if ($rule ne $currrules{$balancer}{$type}) {
23253: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23254: }
23255: } elsif ($rule ne '') {
1.171 raeburn 23256: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23257: }
23258: }
23259: }
1.171 raeburn 23260: }
23261: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
23262: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
23263: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23264: $defaultshash{'loadbalancing'} = {};
23265: }
23266: my $putresult = &Apache::lonnet::put_dom('configuration',
23267: \%defaultshash,$dom);
23268: if ($putresult eq 'ok') {
23269: if (keys(%changes) > 0) {
1.252 raeburn 23270: my %toupdate;
1.171 raeburn 23271: if (ref($changes{'delete'}) eq 'ARRAY') {
23272: foreach my $balancer (sort(@{$changes{'delete'}})) {
23273: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23274: $toupdate{$balancer} = 1;
1.150 raeburn 23275: }
1.171 raeburn 23276: }
23277: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23278: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23279: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23280: $toupdate{$balancer} = 1;
1.171 raeburn 23281: }
23282: }
23283: if (ref($changes{'curr'}) eq 'HASH') {
23284: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23285: $toupdate{$balancer} = 1;
1.171 raeburn 23286: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23287: if ($changes{'curr'}{$balancer}{'targets'}) {
23288: my %offloadstr;
23289: foreach my $sparetype (@sparestypes) {
23290: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23291: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23292: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23293: }
23294: }
1.150 raeburn 23295: }
1.171 raeburn 23296: if (keys(%offloadstr) == 0) {
23297: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23298: } else {
1.171 raeburn 23299: my $showoffload;
23300: foreach my $sparetype (@sparestypes) {
23301: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23302: if (defined($offloadstr{$sparetype})) {
23303: $showoffload .= $offloadstr{$sparetype};
23304: } else {
23305: $showoffload .= &mt('None');
23306: }
23307: $showoffload .= (' 'x3);
23308: }
23309: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23310: }
23311: }
23312: }
1.171 raeburn 23313: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23314: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23315: foreach my $type (@{$alltypes}) {
23316: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23317: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23318: my $balancetext;
23319: if ($rule eq '') {
23320: $balancetext = $ruletitles{'default'};
1.209 raeburn 23321: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23322: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23323: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23324: foreach my $sparetype (@sparestypes) {
23325: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23326: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23327: }
23328: }
1.253 raeburn 23329: foreach my $item (@{$alltypes}) {
23330: next if ($item =~ /^_LC_ipchange/);
23331: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23332: if ($hasrule eq 'homeserver') {
23333: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23334: } else {
23335: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23336: if ($servers{$hasrule}) {
23337: $toupdate{$hasrule} = 1;
23338: }
23339: }
23340: }
23341: }
1.254 raeburn 23342: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23343: $balancetext = $ruletitles{$rule};
23344: } else {
23345: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23346: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23347: if ($receiver) {
23348: $toupdate{$receiver};
23349: }
23350: }
23351: } else {
23352: $balancetext = $ruletitles{$rule};
1.252 raeburn 23353: }
1.171 raeburn 23354: } else {
23355: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23356: }
1.210 raeburn 23357: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23358: }
23359: }
23360: }
23361: }
1.342 raeburn 23362: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23363: if ($currcookies{$balancer}) {
23364: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23365: $balancer).'</li>';
23366: } else {
23367: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23368: $balancer).'</li>';
23369: }
1.342 raeburn 23370: }
1.375 raeburn 23371: }
23372: }
23373: if (keys(%toupdate)) {
23374: my %thismachine;
23375: my $updatedhere;
23376: my $cachetime = 60*60*24;
23377: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23378: foreach my $lonhost (keys(%toupdate)) {
23379: if ($thismachine{$lonhost}) {
23380: unless ($updatedhere) {
23381: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23382: $defaultshash{'loadbalancing'},
23383: $cachetime);
23384: $updatedhere = 1;
1.252 raeburn 23385: }
1.375 raeburn 23386: } else {
23387: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23388: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23389: }
1.150 raeburn 23390: }
1.171 raeburn 23391: }
23392: if ($resulttext ne '') {
23393: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23394: } else {
23395: $resulttext = $nochgmsg;
23396: }
23397: } else {
1.171 raeburn 23398: $resulttext = $nochgmsg;
1.150 raeburn 23399: }
23400: } else {
1.171 raeburn 23401: $resulttext = '<span class="LC_error">'.
23402: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23403: }
23404: } else {
1.171 raeburn 23405: $resulttext = $nochgmsg;
1.150 raeburn 23406: }
23407: return $resulttext;
23408: }
23409:
1.48 raeburn 23410: sub recurse_check {
23411: my ($chkcats,$categories,$depth,$name) = @_;
23412: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23413: my $chg = 0;
23414: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23415: my $category = $chkcats->[$depth]{$name}[$j];
23416: my $item;
23417: if ($category eq '') {
23418: $chg ++;
23419: } else {
23420: my $deeper = $depth + 1;
23421: $item = &escape($category).':'.&escape($name).':'.$depth;
23422: if ($chg) {
23423: $categories->{$item} -= $chg;
23424: }
23425: &recurse_check($chkcats,$categories,$deeper,$category);
23426: $deeper --;
23427: }
23428: }
23429: }
23430: return;
23431: }
23432:
23433: sub recurse_cat_deletes {
23434: my ($item,$coursecategories,$deletions) = @_;
23435: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23436: my $subdepth = $depth + 1;
23437: if (ref($coursecategories) eq 'HASH') {
23438: foreach my $subitem (keys(%{$coursecategories})) {
23439: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23440: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23441: delete($coursecategories->{$subitem});
23442: $deletions->{$subitem} = 1;
23443: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23444: }
1.48 raeburn 23445: }
23446: }
23447: return;
23448: }
23449:
1.125 raeburn 23450: sub active_dc_picker {
1.191 raeburn 23451: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23452: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23453: my @domcoord = keys(%domcoords);
23454: if (keys(%currhash)) {
23455: foreach my $dc (keys(%currhash)) {
23456: unless (exists($domcoords{$dc})) {
23457: push(@domcoord,$dc);
23458: }
23459: }
23460: }
23461: @domcoord = sort(@domcoord);
1.210 raeburn 23462: my $numdcs = scalar(@domcoord);
1.191 raeburn 23463: my $rows = 0;
23464: my $table;
1.125 raeburn 23465: if ($numdcs > 1) {
1.191 raeburn 23466: $table = '<table>';
23467: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23468: my $rem = $i%($numinrow);
23469: if ($rem == 0) {
23470: if ($i > 0) {
1.191 raeburn 23471: $table .= '</tr>';
1.125 raeburn 23472: }
1.191 raeburn 23473: $table .= '<tr>';
23474: $rows ++;
1.125 raeburn 23475: }
1.191 raeburn 23476: my $check = '';
23477: if ($inputtype eq 'radio') {
23478: if (keys(%currhash) == 0) {
23479: if (!$i) {
23480: $check = ' checked="checked"';
23481: }
23482: } elsif (exists($currhash{$domcoord[$i]})) {
23483: $check = ' checked="checked"';
23484: }
23485: } else {
23486: if (exists($currhash{$domcoord[$i]})) {
23487: $check = ' checked="checked"';
1.125 raeburn 23488: }
23489: }
1.191 raeburn 23490: if ($i == @domcoord - 1) {
1.125 raeburn 23491: my $colsleft = $numinrow - $rem;
23492: if ($colsleft > 1) {
1.191 raeburn 23493: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23494: } else {
1.191 raeburn 23495: $table .= '<td class="LC_left_item">';
1.125 raeburn 23496: }
23497: } else {
1.191 raeburn 23498: $table .= '<td class="LC_left_item">';
23499: }
23500: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23501: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23502: $table .= '<span class="LC_nobreak"><label>'.
23503: '<input type="'.$inputtype.'" name="'.$name.'"'.
23504: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23505: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23506: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23507: }
1.219 raeburn 23508: $table .= '</label></span></td>';
1.191 raeburn 23509: }
23510: $table .= '</tr></table>';
23511: } elsif ($numdcs == 1) {
1.219 raeburn 23512: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23513: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23514: if ($inputtype eq 'radio') {
1.247 raeburn 23515: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23516: if ($user ne $dcname.':'.$dcdom) {
23517: $table .= ' ('.$dcname.':'.$dcdom.')';
23518: }
1.191 raeburn 23519: } else {
23520: my $check;
23521: if (exists($currhash{$domcoord[0]})) {
23522: $check = ' checked="checked"';
1.125 raeburn 23523: }
1.247 raeburn 23524: $table = '<span class="LC_nobreak"><label>'.
23525: '<input type="checkbox" name="'.$name.'" '.
23526: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23527: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23528: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23529: }
1.220 raeburn 23530: $table .= '</label></span>';
1.191 raeburn 23531: $rows ++;
1.125 raeburn 23532: }
23533: }
1.191 raeburn 23534: return ($numdcs,$table,$rows);
1.125 raeburn 23535: }
23536:
1.137 raeburn 23537: sub usersession_titles {
23538: return &Apache::lonlocal::texthash(
23539: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23540: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23541: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23542: version => 'LON-CAPA version requirement',
1.138 raeburn 23543: excludedomain => 'Allow all, but exclude specific domains',
23544: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23545: primary => 'Primary (checked first)',
1.154 raeburn 23546: default => 'Default',
1.137 raeburn 23547: );
23548: }
23549:
1.152 raeburn 23550: sub id_for_thisdom {
23551: my (%servers) = @_;
23552: my %altids;
23553: foreach my $server (keys(%servers)) {
23554: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23555: if ($serverhome ne $server) {
23556: $altids{$serverhome} = $server;
23557: }
23558: }
23559: return %altids;
23560: }
23561:
1.150 raeburn 23562: sub count_servers {
23563: my ($currbalancer,%servers) = @_;
23564: my (@spares,$numspares);
23565: foreach my $lonhost (sort(keys(%servers))) {
23566: next if ($currbalancer eq $lonhost);
23567: push(@spares,$lonhost);
23568: }
23569: if ($currbalancer) {
23570: $numspares = scalar(@spares);
23571: } else {
23572: $numspares = scalar(@spares) - 1;
23573: }
23574: return ($numspares,@spares);
23575: }
23576:
23577: sub lonbalance_targets_js {
1.171 raeburn 23578: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23579: my $select = &mt('Select');
23580: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23581: if (ref($servers) eq 'HASH') {
23582: $alltargets = join("','",sort(keys(%{$servers})));
23583: my @homedoms;
23584: foreach my $server (sort(keys(%{$servers}))) {
23585: if (&Apache::lonnet::host_domain($server) eq $dom) {
23586: push(@homedoms,'1');
23587: } else {
23588: push(@homedoms,'0');
23589: }
23590: }
23591: $allishome = join("','",@homedoms);
23592: }
23593: if (ref($types) eq 'ARRAY') {
23594: if (@{$types} > 0) {
23595: @alltypes = @{$types};
23596: }
23597: }
23598: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23599: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23600: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23601: if (ref($settings) eq 'HASH') {
23602: %existing = %{$settings};
23603: }
23604: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23605: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23606: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23607: return <<"END";
23608:
23609: <script type="text/javascript">
23610: // <![CDATA[
23611:
1.171 raeburn 23612: currBalancers = new Array('$balancers');
23613:
23614: function toggleTargets(balnum) {
23615: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23616: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23617: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23618: var prevbalancer = prevhostitem.value;
23619: var baltotal = document.getElementById('loadbalancing_total').value;
23620: prevhostitem.value = balancer;
23621: if (prevbalancer != '') {
23622: var prevIdx = currBalancers.indexOf(prevbalancer);
23623: if (prevIdx != -1) {
23624: currBalancers.splice(prevIdx,1);
23625: }
23626: }
1.150 raeburn 23627: if (balancer == '') {
1.171 raeburn 23628: hideSpares(balnum);
1.150 raeburn 23629: } else {
1.171 raeburn 23630: var currIdx = currBalancers.indexOf(balancer);
23631: if (currIdx == -1) {
23632: currBalancers.push(balancer);
23633: }
1.150 raeburn 23634: var homedoms = new Array('$allishome');
1.171 raeburn 23635: var ishomedom = homedoms[lonhostitem.selectedIndex];
23636: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23637: }
1.171 raeburn 23638: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23639: return;
23640: }
23641:
1.171 raeburn 23642: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23643: var alltargets = new Array('$alltargets');
23644: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23645: var offloadtypes = new Array('primary','default');
23646:
1.171 raeburn 23647: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23648: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23649:
1.151 raeburn 23650: for (var i=0; i<offloadtypes.length; i++) {
23651: var count = 0;
23652: for (var j=0; j<alltargets.length; j++) {
23653: if (alltargets[j] != balancer) {
1.171 raeburn 23654: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23655: item.value = alltargets[j];
23656: item.style.textAlign='left';
23657: item.style.textFace='normal';
23658: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23659: if (currBalancers.indexOf(alltargets[j]) == -1) {
23660: item.disabled = '';
23661: } else {
23662: item.disabled = 'disabled';
23663: item.checked = false;
23664: }
1.151 raeburn 23665: count ++;
23666: }
1.150 raeburn 23667: }
23668: }
1.151 raeburn 23669: for (var k=0; k<insttypes.length; k++) {
23670: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23671: if (ishomedom == 1) {
1.171 raeburn 23672: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23673: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23674: } else {
1.171 raeburn 23675: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23676: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23677: }
23678: } else {
1.171 raeburn 23679: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23680: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23681: }
1.151 raeburn 23682: if ((insttypes[k] != '_LC_external') &&
23683: ((insttypes[k] != '_LC_internetdom') ||
23684: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23685: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23686: item.options.length = 0;
23687: item.options[0] = new Option("","",true,true);
1.210 raeburn 23688: var idx = 0;
1.151 raeburn 23689: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23690: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23691: idx ++;
23692: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23693: }
23694: }
23695: }
23696: }
23697: return;
23698: }
23699:
1.171 raeburn 23700: function hideSpares(balnum) {
1.150 raeburn 23701: var alltargets = new Array('$alltargets');
23702: var insttypes = new Array('$allinsttypes');
23703: var offloadtypes = new Array('primary','default');
23704:
1.171 raeburn 23705: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23706: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23707:
23708: var total = alltargets.length - 1;
23709: for (var i=0; i<offloadtypes; i++) {
23710: for (var j=0; j<total; j++) {
1.171 raeburn 23711: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23712: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23713: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23714: }
1.150 raeburn 23715: }
23716: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23717: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23718: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23719: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23720: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23721: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23722: }
23723: }
23724: return;
23725: }
23726:
1.171 raeburn 23727: function checkOffloads(item,balnum,type) {
1.150 raeburn 23728: var alltargets = new Array('$alltargets');
23729: var offloadtypes = new Array('primary','default');
23730: if (item.checked) {
23731: var total = alltargets.length - 1;
23732: var other;
23733: if (type == offloadtypes[0]) {
1.151 raeburn 23734: other = offloadtypes[1];
1.150 raeburn 23735: } else {
1.151 raeburn 23736: other = offloadtypes[0];
1.150 raeburn 23737: }
23738: for (var i=0; i<total; i++) {
1.171 raeburn 23739: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23740: if (server == item.value) {
1.171 raeburn 23741: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23742: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23743: }
23744: }
23745: }
23746: }
23747: return;
23748: }
23749:
1.171 raeburn 23750: function singleServerToggle(balnum,type) {
23751: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23752: if (offloadtoSelIdx == 0) {
1.171 raeburn 23753: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23754: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23755:
23756: } else {
1.171 raeburn 23757: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23758: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23759: }
23760: return;
23761: }
23762:
1.171 raeburn 23763: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23764: if (type == '_LC_external') {
1.171 raeburn 23765: return;
1.150 raeburn 23766: }
1.171 raeburn 23767: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23768: for (var i=0; i<typesRules.length; i++) {
23769: if (formname.elements[typesRules[i]].checked) {
23770: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23771: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23772: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23773: } else {
1.171 raeburn 23774: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23775: }
23776: }
23777: }
23778: return;
23779: }
23780:
23781: function balancerDeleteChange(balnum) {
23782: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23783: var baltotal = document.getElementById('loadbalancing_total').value;
23784: var addtarget;
23785: var removetarget;
23786: var action = 'delete';
23787: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23788: var lonhost = hostitem.value;
23789: var currIdx = currBalancers.indexOf(lonhost);
23790: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23791: if (currIdx != -1) {
23792: currBalancers.splice(currIdx,1);
23793: }
23794: addtarget = lonhost;
23795: } else {
23796: if (currIdx == -1) {
23797: currBalancers.push(lonhost);
23798: }
23799: removetarget = lonhost;
23800: action = 'undelete';
23801: }
23802: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23803: }
23804: return;
23805: }
23806:
23807: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23808: if (baltotal > 1) {
23809: var offloadtypes = new Array('primary','default');
23810: var alltargets = new Array('$alltargets');
23811: var insttypes = new Array('$allinsttypes');
23812: for (var i=0; i<baltotal; i++) {
23813: if (i != balnum) {
23814: for (var j=0; j<offloadtypes.length; j++) {
23815: var total = alltargets.length - 1;
23816: for (var k=0; k<total; k++) {
23817: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23818: var server = serveritem.value;
23819: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23820: if (server == addtarget) {
23821: serveritem.disabled = '';
23822: }
23823: }
23824: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23825: if (server == removetarget) {
23826: serveritem.disabled = 'disabled';
23827: serveritem.checked = false;
23828: }
23829: }
23830: }
23831: }
23832: for (var j=0; j<insttypes.length; j++) {
23833: if (insttypes[j] != '_LC_external') {
23834: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23835: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23836: var currSel = singleserver.selectedIndex;
23837: var currVal = singleserver.options[currSel].value;
23838: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23839: var numoptions = singleserver.options.length;
23840: var needsnew = 1;
23841: for (var k=0; k<numoptions; k++) {
23842: if (singleserver.options[k] == addtarget) {
23843: needsnew = 0;
23844: break;
23845: }
23846: }
23847: if (needsnew == 1) {
23848: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23849: }
23850: }
23851: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23852: singleserver.options.length = 0;
23853: if ((currVal) && (currVal != removetarget)) {
23854: singleserver.options[0] = new Option("","",false,false);
23855: } else {
23856: singleserver.options[0] = new Option("","",true,true);
23857: }
23858: var idx = 0;
23859: for (var m=0; m<alltargets.length; m++) {
23860: if (currBalancers.indexOf(alltargets[m]) == -1) {
23861: idx ++;
23862: if (currVal == alltargets[m]) {
23863: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23864: } else {
23865: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23866: }
23867: }
23868: }
23869: }
23870: }
23871: }
23872: }
1.150 raeburn 23873: }
23874: }
23875: }
23876: return;
23877: }
23878:
1.152 raeburn 23879: // ]]>
23880: </script>
23881:
23882: END
23883: }
23884:
23885: sub new_spares_js {
23886: my @sparestypes = ('primary','default');
23887: my $types = join("','",@sparestypes);
23888: my $select = &mt('Select');
23889: return <<"END";
23890:
23891: <script type="text/javascript">
23892: // <![CDATA[
23893:
23894: function updateNewSpares(formname,lonhost) {
23895: var types = new Array('$types');
23896: var include = new Array();
23897: var exclude = new Array();
23898: for (var i=0; i<types.length; i++) {
23899: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23900: for (var j=0; j<spareboxes.length; j++) {
23901: if (formname.elements[spareboxes[j]].checked) {
23902: exclude.push(formname.elements[spareboxes[j]].value);
23903: } else {
23904: include.push(formname.elements[spareboxes[j]].value);
23905: }
23906: }
23907: }
23908: for (var i=0; i<types.length; i++) {
23909: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23910: var selIdx = newSpare.selectedIndex;
23911: var currnew = newSpare.options[selIdx].value;
23912: var okSpares = new Array();
23913: for (var j=0; j<newSpare.options.length; j++) {
23914: var possible = newSpare.options[j].value;
23915: if (possible != '') {
23916: if (exclude.indexOf(possible) == -1) {
23917: okSpares.push(possible);
23918: } else {
23919: if (currnew == possible) {
23920: selIdx = 0;
23921: }
23922: }
23923: }
23924: }
23925: for (var k=0; k<include.length; k++) {
23926: if (okSpares.indexOf(include[k]) == -1) {
23927: okSpares.push(include[k]);
23928: }
23929: }
23930: okSpares.sort();
23931: newSpare.options.length = 0;
23932: if (selIdx == 0) {
23933: newSpare.options[0] = new Option("$select","",true,true);
23934: } else {
23935: newSpare.options[0] = new Option("$select","",false,false);
23936: }
23937: for (var m=0; m<okSpares.length; m++) {
23938: var idx = m+1;
23939: var selThis = 0;
23940: if (selIdx != 0) {
23941: if (okSpares[m] == currnew) {
23942: selThis = 1;
23943: }
23944: }
23945: if (selThis == 1) {
23946: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23947: } else {
23948: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23949: }
23950: }
23951: }
23952: return;
23953: }
23954:
23955: function checkNewSpares(lonhost,type) {
23956: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23957: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23958: if (chosen != '') {
1.152 raeburn 23959: var othertype;
23960: var othernewSpare;
23961: if (type == 'primary') {
23962: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23963: }
23964: if (type == 'default') {
23965: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23966: }
23967: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23968: othernewSpare.selectedIndex = 0;
23969: }
23970: }
23971: return;
23972: }
23973:
23974: // ]]>
23975: </script>
23976:
23977: END
23978:
23979: }
23980:
23981: sub common_domprefs_js {
23982: return <<"END";
23983:
23984: <script type="text/javascript">
23985: // <![CDATA[
23986:
1.150 raeburn 23987: function getIndicesByName(formname,item) {
1.152 raeburn 23988: var group = new Array();
1.150 raeburn 23989: for (var i=0;i<formname.elements.length;i++) {
23990: if (formname.elements[i].name == item) {
1.152 raeburn 23991: group.push(formname.elements[i].id);
1.150 raeburn 23992: }
23993: }
1.152 raeburn 23994: return group;
1.150 raeburn 23995: }
23996:
23997: // ]]>
23998: </script>
23999:
24000: END
1.152 raeburn 24001:
1.150 raeburn 24002: }
24003:
1.165 raeburn 24004: sub recaptcha_js {
24005: my %lt = &captcha_phrases();
24006: return <<"END";
24007:
24008: <script type="text/javascript">
24009: // <![CDATA[
24010:
24011: function updateCaptcha(caller,context) {
24012: var privitem;
24013: var pubitem;
24014: var privtext;
24015: var pubtext;
1.269 raeburn 24016: var versionitem;
24017: var versiontext;
1.165 raeburn 24018: if (document.getElementById(context+'_recaptchapub')) {
24019: pubitem = document.getElementById(context+'_recaptchapub');
24020: } else {
24021: return;
24022: }
24023: if (document.getElementById(context+'_recaptchapriv')) {
24024: privitem = document.getElementById(context+'_recaptchapriv');
24025: } else {
24026: return;
24027: }
24028: if (document.getElementById(context+'_recaptchapubtxt')) {
24029: pubtext = document.getElementById(context+'_recaptchapubtxt');
24030: } else {
24031: return;
24032: }
24033: if (document.getElementById(context+'_recaptchaprivtxt')) {
24034: privtext = document.getElementById(context+'_recaptchaprivtxt');
24035: } else {
24036: return;
24037: }
1.269 raeburn 24038: if (document.getElementById(context+'_recaptchaversion')) {
24039: versionitem = document.getElementById(context+'_recaptchaversion');
24040: } else {
24041: return;
24042: }
24043: if (document.getElementById(context+'_recaptchavertxt')) {
24044: versiontext = document.getElementById(context+'_recaptchavertxt');
24045: } else {
24046: return;
24047: }
1.165 raeburn 24048: if (caller.checked) {
24049: if (caller.value == 'recaptcha') {
24050: pubitem.type = 'text';
24051: privitem.type = 'text';
24052: pubitem.size = '40';
24053: privitem.size = '40';
24054: pubtext.innerHTML = "$lt{'pub'}";
24055: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 24056: versionitem.type = 'text';
24057: versionitem.size = '3';
1.289 raeburn 24058: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 24059: } else {
24060: pubitem.type = 'hidden';
24061: privitem.type = 'hidden';
1.269 raeburn 24062: versionitem.type = 'hidden';
1.165 raeburn 24063: pubtext.innerHTML = '';
24064: privtext.innerHTML = '';
1.269 raeburn 24065: versiontext.innerHTML = '';
1.165 raeburn 24066: }
24067: }
24068: return;
24069: }
24070:
24071: // ]]>
24072: </script>
24073:
24074: END
24075:
24076: }
24077:
1.236 raeburn 24078: sub toggle_display_js {
1.192 raeburn 24079: return <<"END";
24080:
24081: <script type="text/javascript">
24082: // <![CDATA[
24083:
1.236 raeburn 24084: function toggleDisplay(domForm,caller) {
24085: if (document.getElementById(caller)) {
24086: var divitem = document.getElementById(caller);
24087: var optionsElement = domForm.coursecredits;
1.264 raeburn 24088: var checkval = 1;
24089: var dispval = 'block';
1.303 raeburn 24090: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 24091: if (caller == 'emailoptions') {
1.372 raeburn 24092: optionsElement = domForm.cancreate_email;
1.236 raeburn 24093: }
1.257 raeburn 24094: if (caller == 'studentsubmission') {
24095: optionsElement = domForm.postsubmit;
24096: }
1.264 raeburn 24097: if (caller == 'cloneinstcode') {
24098: optionsElement = domForm.canclone;
24099: checkval = 'instcode';
24100: }
1.303 raeburn 24101: if (selfcreateRegExp.test(caller)) {
24102: optionsElement = domForm.elements[caller];
24103: checkval = 'other';
24104: dispval = 'inline'
24105: }
1.236 raeburn 24106: if (optionsElement.length) {
1.192 raeburn 24107: var currval;
1.236 raeburn 24108: for (var i=0; i<optionsElement.length; i++) {
24109: if (optionsElement[i].checked) {
24110: currval = optionsElement[i].value;
1.192 raeburn 24111: }
24112: }
1.264 raeburn 24113: if (currval == checkval) {
24114: divitem.style.display = dispval;
1.192 raeburn 24115: } else {
1.236 raeburn 24116: divitem.style.display = 'none';
1.192 raeburn 24117: }
24118: }
24119: }
24120: return;
24121: }
24122:
24123: // ]]>
24124: </script>
24125:
24126: END
24127:
24128: }
24129:
1.165 raeburn 24130: sub captcha_phrases {
24131: return &Apache::lonlocal::texthash (
24132: priv => 'Private key',
24133: pub => 'Public key',
24134: original => 'original (CAPTCHA)',
24135: recaptcha => 'successor (ReCAPTCHA)',
24136: notused => 'unused',
1.289 raeburn 24137: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 24138: );
24139: }
24140:
1.205 raeburn 24141: sub devalidate_remote_domconfs {
1.212 raeburn 24142: my ($dom,$cachekeys) = @_;
24143: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 24144: my %servers = &Apache::lonnet::internet_dom_servers($dom);
24145: my %thismachine;
24146: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 24147: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 24148: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 24149: 'ipaccess','trust');
1.386 raeburn 24150: my %cache_by_lonhost;
24151: if (exists($cachekeys->{'samllanding'})) {
24152: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
24153: my %landing = %{$cachekeys->{'samllanding'}};
24154: my %domservers = &Apache::lonnet::get_servers($dom);
24155: if (keys(%domservers)) {
24156: foreach my $server (keys(%domservers)) {
24157: my @cached;
24158: next if ($thismachine{$server});
24159: if ($landing{$server}) {
24160: push(@cached,&escape('samllanding').':'.&escape($server));
24161: }
24162: if (@cached) {
24163: $cache_by_lonhost{$server} = \@cached;
24164: }
24165: }
24166: }
24167: }
24168: }
1.260 raeburn 24169: if (keys(%servers)) {
1.205 raeburn 24170: foreach my $server (keys(%servers)) {
24171: next if ($thismachine{$server});
1.212 raeburn 24172: my @cached;
24173: foreach my $name (@posscached) {
24174: if ($cachekeys->{$name}) {
1.388 raeburn 24175: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 24176: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 24177: foreach my $key (keys(%{$cachekeys->{$name}})) {
24178: push(@cached,&escape($name).':'.&escape($key));
24179: }
24180: }
24181: } else {
24182: push(@cached,&escape($name).':'.&escape($dom));
24183: }
1.212 raeburn 24184: }
24185: }
1.386 raeburn 24186: if ((exists($cache_by_lonhost{$server})) &&
24187: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
24188: push(@cached,@{$cache_by_lonhost{$server}});
24189: }
1.212 raeburn 24190: if (@cached) {
24191: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
24192: }
1.205 raeburn 24193: }
24194: }
24195: return;
24196: }
24197:
1.3 raeburn 24198: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>