Annotation of loncom/interface/domainprefs.pm, revision 1.447.2.2
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.447.2.2! raeburn 4: # $Id: domainprefs.pm,v 1.447.2.1 2025/01/11 16:10:31 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: }
17962: }
17963: } else {
17964: my @stdfields;
17965: foreach my $field (@fields) {
17966: if ($field eq 'id') {
17967: next if ($status eq 'unpriv');
17968: next if (($status eq 'priv') && ($item eq 'community'));
17969: }
17970: push(@stdfields,$field);
17971: }
17972: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17973: if (@diffs > 0) {
17974: $changes{$status} = 1;
17975: }
17976: }
17977: }
17978: }
17979: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17980: my @statuses;
17981: if (ref($types) eq 'ARRAY') {
17982: @statuses = @{$types};
17983: }
17984: foreach my $type (@statuses,'default') {
17985: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17986: my @newvalues;
17987: foreach my $field (sort(@possfields)) {
17988: if (grep(/^\Q$field\E$/,@fields)) {
17989: $privacyhash{'othdom'}{$type}{$field} = 1;
17990: push(@newvalues,$field);
17991: }
17992: }
17993: @newvalues = sort(@newvalues);
17994: if (ref($current{'othdom'}) eq 'HASH') {
17995: if (ref($current{'othdom'}{$type}) eq 'HASH') {
17996: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
17997: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17998: if (@diffs > 0) {
17999: $changes{'othdom'} = 1;
18000: }
18001: }
18002: } else {
18003: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
18004: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
18005: if (@diffs > 0) {
18006: $changes{'othdom'} = 1;
18007: }
18008: }
18009: }
1.417 raeburn 18010: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
18011: my %notify;
18012: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
18013: if (exists($domcoords{$possdc})) {
18014: $notify{$possdc} = 1;
18015: }
18016: }
18017: my $notify = join(',',sort(keys(%notify)));
18018: if ($current{'notify'} ne $notify) {
18019: $changes{'notify'} = 1;
18020: }
18021: $privacyhash{'notify'} = $notify;
1.357 raeburn 18022: }
18023: my %confighash = (
18024: privacy => \%privacyhash,
18025: );
18026: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18027: if ($putresult eq 'ok') {
18028: if (keys(%changes) > 0) {
18029: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 18030: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 18031: if ($changes{$key}) {
18032: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18033: if ($key eq 'approval') {
18034: if (keys(%{$privacyhash{$key}{instdom}})) {
18035: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
18036: foreach my $item (@items) {
18037: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
18038: }
18039: $resulttext .= '</ul></li>';
18040: }
18041: if (keys(%{$privacyhash{$key}{extdom}})) {
18042: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
18043: foreach my $item (@items) {
18044: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
18045: }
18046: $resulttext .= '</ul></li>';
18047: }
1.417 raeburn 18048: } elsif ($key eq 'notify') {
18049: if ($privacyhash{$key}) {
18050: foreach my $dc (split(/,/,$privacyhash{$key})) {
18051: my ($dcname,$dcdom) = split(/:/,$dc);
18052: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
18053: }
18054: } else {
18055: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
18056: }
1.357 raeburn 18057: } elsif ($key eq 'othdom') {
18058: my @statuses;
18059: if (ref($types) eq 'ARRAY') {
18060: @statuses = @{$types};
18061: }
18062: if (ref($privacyhash{$key}) eq 'HASH') {
18063: foreach my $status (@statuses,'default') {
18064: if ($status eq 'default') {
18065: $resulttext .= '<li>'.$othertitle.': ';
18066: } elsif (ref($usertypes) eq 'HASH') {
18067: $resulttext .= '<li>'.$usertypes->{$status}.': ';
18068: } else {
18069: next;
18070: }
18071: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
18072: if (keys(%{$privacyhash{$key}{$status}})) {
18073: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
18074: } else {
18075: $resulttext .= &mt('none');
18076: }
18077: }
18078: $resulttext .= '</li>';
18079: }
18080: }
18081: } else {
18082: foreach my $item (@items) {
18083: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
18084: $resulttext .= '<li>'.$names{$item}.': ';
18085: if (keys(%{$privacyhash{$key}{$item}})) {
18086: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
18087: } else {
18088: $resulttext .= &mt('none');
18089: }
18090: $resulttext .= '</li>';
18091: }
18092: }
18093: }
18094: $resulttext .= '</ul></li>';
18095: }
18096: }
1.421 raeburn 18097: $resulttext .= '</ul>';
1.427 raeburn 18098: if ($changes{'approval'}) {
18099: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18100: delete($domdefaults{'userapprovals'});
18101: if (ref($privacyhash{'approval'}) eq 'HASH') {
18102: foreach my $domtype ('instdom','extdom') {
18103: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
18104: foreach my $roletype ('domain','author','course','community') {
18105: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
18106: $domdefaults{'userapprovals'} = 1;
18107: last;
18108: }
18109: }
18110: }
18111: last if ($domdefaults{'userapprovals'});
18112: }
18113: }
18114: my $cachetime = 24*60*60;
18115: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18116: if (ref($lastactref) eq 'HASH') {
18117: $lastactref->{'domdefaults'} = 1;
18118: }
18119: }
1.357 raeburn 18120: } else {
18121: $resulttext = &mt('No changes made to user information settings');
18122: }
18123: } else {
18124: $resulttext = '<span class="LC_error">'.
18125: &mt('An error occurred: [_1]',$putresult).'</span>';
18126: }
18127: return $resulttext;
18128: }
18129:
1.354 raeburn 18130: sub modify_passwords {
18131: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18132: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18133: $updatedefaults,$updateconf);
1.354 raeburn 18134: my $customfn = 'resetpw.html';
18135: if (ref($domconfig{'passwords'}) eq 'HASH') {
18136: %current = %{$domconfig{'passwords'}};
18137: }
18138: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18139: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18140: if (ref($types) eq 'ARRAY') {
18141: @oktypes = @{$types};
18142: }
18143: push(@oktypes,'default');
18144:
18145: my %titles = &Apache::lonlocal::texthash (
18146: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18147: intauth_check => 'Check bcrypt cost if authenticated',
18148: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18149: permanent => 'Permanent e-mail address',
18150: critical => 'Critical notification address',
18151: notify => 'Notification address',
18152: min => 'Minimum password length',
18153: max => 'Maximum password length',
18154: chars => 'Required characters',
18155: expire => 'Password expiration (days)',
1.356 raeburn 18156: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18157: reset => 'Resetting Forgotten Password',
18158: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18159: rules => 'Rules for LON-CAPA Passwords',
18160: crsownerchg => 'Course Owner Changing Student Passwords',
18161: username => 'Username',
18162: email => 'E-mail address',
18163: );
18164:
18165: #
18166: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18167: #
18168: my (%curr_defaults,%save_defaults);
18169: if (ref($domconfig{'defaults'}) eq 'HASH') {
18170: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18171: if ($key =~ /^intauth_(cost|check|switch)$/) {
18172: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18173: } else {
18174: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18175: }
18176: }
18177: }
18178: my %staticdefaults = (
18179: 'resetlink' => 2,
18180: 'resetcase' => \@oktypes,
18181: 'resetprelink' => 'both',
18182: 'resetemail' => ['critical','notify','permanent'],
18183: 'intauth_cost' => 10,
18184: 'intauth_check' => 0,
18185: 'intauth_switch' => 0,
18186: );
1.365 raeburn 18187: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18188: foreach my $type (@oktypes) {
18189: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18190: }
18191: my $linklife = $env{'form.passwords_link'};
18192: $linklife =~ s/^\s+|\s+$//g;
18193: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18194: $newvalues{'resetlink'} = $linklife;
18195: if ($current{'resetlink'}) {
18196: if ($current{'resetlink'} ne $linklife) {
18197: $changes{'reset'} = 1;
18198: }
1.368 raeburn 18199: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18200: if ($staticdefaults{'resetlink'} ne $linklife) {
18201: $changes{'reset'} = 1;
18202: }
18203: }
18204: } elsif ($current{'resetlink'}) {
18205: $changes{'reset'} = 1;
18206: }
18207: my @casesens;
18208: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18209: foreach my $case (sort(@posscase)) {
18210: if (grep(/^\Q$case\E$/,@oktypes)) {
18211: push(@casesens,$case);
18212: }
18213: }
18214: $newvalues{'resetcase'} = \@casesens;
18215: if (ref($current{'resetcase'}) eq 'ARRAY') {
18216: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18217: if (@diffs > 0) {
18218: $changes{'reset'} = 1;
18219: }
1.368 raeburn 18220: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18221: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18222: if (@diffs > 0) {
18223: $changes{'reset'} = 1;
18224: }
18225: }
18226: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18227: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18228: if (exists($current{'resetprelink'})) {
18229: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18230: $changes{'reset'} = 1;
18231: }
1.368 raeburn 18232: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18233: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18234: $changes{'reset'} = 1;
18235: }
18236: }
18237: } elsif ($current{'resetprelink'}) {
18238: $changes{'reset'} = 1;
18239: }
18240: foreach my $type (@oktypes) {
18241: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18242: my @postlink;
18243: foreach my $item (sort(@possplink)) {
18244: if ($item =~ /^(email|username)$/) {
18245: push(@postlink,$item);
18246: }
18247: }
18248: $newvalues{'resetpostlink'}{$type} = \@postlink;
18249: unless ($changes{'reset'}) {
18250: if (ref($current{'resetpostlink'}) eq 'HASH') {
18251: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18252: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18253: if (@diffs > 0) {
18254: $changes{'reset'} = 1;
18255: }
18256: } else {
18257: $changes{'reset'} = 1;
18258: }
1.368 raeburn 18259: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18260: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18261: if (@diffs > 0) {
18262: $changes{'reset'} = 1;
18263: }
18264: }
18265: }
18266: }
18267: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18268: my @resetemail;
18269: foreach my $item (sort(@possemailsrc)) {
18270: if ($item =~ /^(permanent|critical|notify)$/) {
18271: push(@resetemail,$item);
18272: }
18273: }
18274: $newvalues{'resetemail'} = \@resetemail;
18275: unless ($changes{'reset'}) {
18276: if (ref($current{'resetemail'}) eq 'ARRAY') {
18277: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18278: if (@diffs > 0) {
18279: $changes{'reset'} = 1;
18280: }
1.368 raeburn 18281: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18282: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18283: if (@diffs > 0) {
18284: $changes{'reset'} = 1;
18285: }
18286: }
18287: }
18288: if ($env{'form.passwords_stdtext'} == 0) {
18289: $newvalues{'resetremove'} = 1;
18290: unless ($current{'resetremove'}) {
18291: $changes{'reset'} = 1;
18292: }
18293: } elsif ($current{'resetremove'}) {
18294: $changes{'reset'} = 1;
18295: }
18296: if ($env{'form.passwords_customfile.filename'} ne '') {
18297: my $servadm = $r->dir_config('lonAdmEMail');
18298: my ($configuserok,$author_ok,$switchserver) =
18299: &config_check($dom,$confname,$servadm);
18300: my $error;
18301: if ($configuserok eq 'ok') {
18302: if ($switchserver) {
18303: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18304: } else {
18305: if ($author_ok eq 'ok') {
1.421 raeburn 18306: my $modified = [];
1.354 raeburn 18307: my ($result,$customurl) =
1.421 raeburn 18308: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18309: $confname,'customtext/resetpw','','',$customfn,
18310: $modified);
1.354 raeburn 18311: if ($result eq 'ok') {
18312: $newvalues{'resetcustom'} = $customurl;
18313: $changes{'reset'} = 1;
1.421 raeburn 18314: &update_modify_urls($r,$modified);
1.354 raeburn 18315: } else {
18316: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18317: }
18318: } else {
18319: $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);
18320: }
18321: }
18322: } else {
18323: $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);
18324: }
18325: if ($error) {
18326: &Apache::lonnet::logthis($error);
18327: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18328: }
18329: } elsif ($current{'resetcustom'}) {
18330: if ($env{'form.passwords_custom_del'}) {
18331: $changes{'reset'} = 1;
18332: } else {
18333: $newvalues{'resetcustom'} = $current{'resetcustom'};
18334: }
18335: }
18336: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18337: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18338: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18339: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18340: $changes{'intauth'} = 1;
18341: }
18342: } else {
18343: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18344: }
18345: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18346: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18347: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18348: $changes{'intauth'} = 1;
18349: }
18350: } else {
18351: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18352: }
18353: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18354: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18355: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18356: $changes{'intauth'} = 1;
18357: }
18358: } else {
18359: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18360: }
18361: foreach my $item ('cost','check','switch') {
18362: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18363: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18364: $updatedefaults = 1;
18365: }
18366: }
1.405 raeburn 18367: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18368: my %crsownerchg = (
18369: by => [],
18370: for => [],
18371: );
18372: foreach my $item ('by','for') {
18373: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18374: foreach my $type (sort(@posstypes)) {
18375: if (grep(/^\Q$type\E$/,@oktypes)) {
18376: push(@{$crsownerchg{$item}},$type);
18377: }
18378: }
18379: }
18380: $newvalues{'crsownerchg'} = \%crsownerchg;
18381: if (ref($current{'crsownerchg'}) eq 'HASH') {
18382: foreach my $item ('by','for') {
18383: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18384: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18385: if (@diffs > 0) {
18386: $changes{'crsownerchg'} = 1;
18387: last;
18388: }
18389: }
18390: }
1.368 raeburn 18391: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18392: foreach my $item ('by','for') {
18393: if (@{$crsownerchg{$item}} > 0) {
18394: $changes{'crsownerchg'} = 1;
18395: last;
18396: }
1.354 raeburn 18397: }
18398: }
18399:
18400: my %confighash = (
18401: defaults => \%save_defaults,
18402: passwords => \%newvalues,
18403: );
18404: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18405:
18406: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18407: if ($putresult eq 'ok') {
18408: if (keys(%changes) > 0) {
18409: $resulttext = &mt('Changes made: ').'<ul>';
18410: foreach my $key ('reset','intauth','rules','crsownerchg') {
18411: if ($changes{$key}) {
1.355 raeburn 18412: unless ($key eq 'intauth') {
18413: $updateconf = 1;
18414: }
1.354 raeburn 18415: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18416: if ($key eq 'reset') {
18417: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18418: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18419: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18420: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18421: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18422: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18423: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18424: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18425: }
1.354 raeburn 18426: } else {
18427: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18428: }
18429: if ($confighash{'passwords'}{'resetlink'}) {
18430: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18431: } else {
18432: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18433: &mt('Will default to 2 hours').'</li>';
18434: }
18435: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18436: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18437: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18438: } else {
18439: my $casesens;
18440: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18441: if ($type eq 'default') {
18442: $casesens .= $othertitle.', ';
18443: } elsif ($usertypes->{$type} ne '') {
18444: $casesens .= $usertypes->{$type}.', ';
18445: }
18446: }
18447: $casesens =~ s/\Q, \E$//;
18448: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18449: }
18450: } else {
18451: $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>';
18452: }
18453: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18454: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18455: } else {
18456: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18457: }
18458: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18459: my $output;
18460: if (ref($types) eq 'ARRAY') {
18461: foreach my $type (@{$types}) {
18462: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18463: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18464: $output .= $usertypes->{$type}.' -- '.&mt('none');
18465: } else {
18466: $output .= $usertypes->{$type}.' -- '.
18467: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18468: }
18469: }
18470: }
18471: }
18472: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18473: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18474: $output .= $othertitle.' -- '.&mt('none');
18475: } else {
18476: $output .= $othertitle.' -- '.
18477: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18478: }
18479: }
18480: if ($output) {
18481: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18482: } else {
18483: $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>';
18484: }
18485: } else {
18486: $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>';
18487: }
18488: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18489: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18490: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18491: } else {
18492: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18493: }
18494: } else {
1.379 raeburn 18495: $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 18496: }
18497: if ($confighash{'passwords'}{'resetremove'}) {
18498: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18499: } else {
18500: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18501: }
18502: if ($confighash{'passwords'}{'resetcustom'}) {
18503: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18504: &mt('custom text'),600,500,undef,undef,
18505: undef,undef,'background-color:#ffffff');
18506: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18507: } else {
18508: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18509: }
18510: } elsif ($key eq 'intauth') {
18511: foreach my $item ('cost','switch','check') {
18512: my $value = $save_defaults{$key.'_'.$item};
18513: if ($item eq 'switch') {
18514: my %optiondesc = &Apache::lonlocal::texthash (
18515: 0 => 'No',
18516: 1 => 'Yes',
18517: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18518: );
18519: if ($value =~ /^(0|1|2)$/) {
18520: $value = $optiondesc{$value};
18521: } else {
18522: $value = &mt('none -- defaults to No');
18523: }
18524: } elsif ($item eq 'check') {
18525: my %optiondesc = &Apache::lonlocal::texthash (
18526: 0 => 'No',
18527: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18528: 2 => 'Yes, disallow login if stored cost is less than domain default',
18529: );
18530: if ($value =~ /^(0|1|2)$/) {
18531: $value = $optiondesc{$value};
18532: } else {
18533: $value = &mt('none -- defaults to No');
18534: }
18535: }
18536: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18537: }
18538: } elsif ($key eq 'rules') {
1.356 raeburn 18539: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18540: if ($confighash{'passwords'}{$rule} eq '') {
18541: if ($rule eq 'min') {
1.356 raeburn 18542: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18543: ' '.&mt('Default of [_1] will be used',
18544: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18545: } else {
18546: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18547: }
18548: } else {
18549: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18550: }
18551: }
1.370 raeburn 18552: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18553: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18554: my %rulenames = &Apache::lonlocal::texthash(
18555: uc => 'At least one upper case letter',
18556: lc => 'At least one lower case letter',
18557: num => 'At least one number',
18558: spec => 'At least one non-alphanumeric',
18559: );
18560: my $needed = '<ul><li>'.
18561: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18562: '</li></ul>';
1.370 raeburn 18563: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18564: } else {
18565: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18566: }
18567: } else {
18568: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18569: }
1.354 raeburn 18570: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18571: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18572: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18573: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18574: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18575: } else {
18576: my %crsownerstr;
18577: foreach my $item ('by','for') {
18578: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18579: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18580: if ($type eq 'default') {
18581: $crsownerstr{$item} .= $othertitle.', ';
18582: } elsif ($usertypes->{$type} ne '') {
18583: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18584: }
18585: }
18586: $crsownerstr{$item} =~ s/\Q, \E$//;
18587: }
18588: }
18589: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18590: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18591: }
1.354 raeburn 18592: } else {
1.359 raeburn 18593: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18594: }
18595: }
18596: $resulttext .= '</ul></li>';
18597: }
18598: }
18599: $resulttext .= '</ul>';
18600: } else {
18601: $resulttext = &mt('No changes made to password settings');
18602: }
1.355 raeburn 18603: my $cachetime = 24*60*60;
1.354 raeburn 18604: if ($updatedefaults) {
18605: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18606: if (ref($lastactref) eq 'HASH') {
18607: $lastactref->{'domdefaults'} = 1;
18608: }
18609: }
1.355 raeburn 18610: if ($updateconf) {
18611: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18612: if (ref($lastactref) eq 'HASH') {
18613: $lastactref->{'passwdconf'} = 1;
18614: }
18615: }
1.354 raeburn 18616: } else {
18617: $resulttext = '<span class="LC_error">'.
18618: &mt('An error occurred: [_1]',$putresult).'</span>';
18619: }
18620: if ($errors) {
18621: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18622: $errors.'</ul></p>';
18623: }
18624: return $resulttext;
18625: }
18626:
1.405 raeburn 18627: sub password_rule_changes {
18628: my ($prefix,$newvalues,$current,$changes) = @_;
18629: return unless ((ref($newvalues) eq 'HASH') &&
18630: (ref($current) eq 'HASH') &&
18631: (ref($changes) eq 'HASH'));
18632: my (@rules,%staticdefaults);
18633: if ($prefix eq 'passwords') {
18634: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18635: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18636: @rules = ('min','max');
18637: }
18638: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18639: foreach my $rule (@rules) {
18640: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18641: my $ruleok;
18642: if ($rule eq 'expire') {
18643: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18644: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18645: $ruleok = 1;
18646: }
18647: } elsif ($rule eq 'min') {
18648: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18649: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18650: $ruleok = 1;
18651: }
18652: }
18653: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18654: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18655: $ruleok = 1;
18656: }
18657: if ($ruleok) {
18658: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18659: if (exists($current->{$rule})) {
18660: if ($newvalues->{$rule} ne $current->{$rule}) {
18661: $changes->{'rules'} = 1;
18662: }
18663: } elsif ($rule eq 'min') {
18664: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18665: $changes->{'rules'} = 1;
18666: }
18667: } else {
18668: $changes->{'rules'} = 1;
18669: }
18670: } elsif (exists($current->{$rule})) {
18671: $changes->{'rules'} = 1;
18672: }
18673: }
18674: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18675: my @chars;
18676: foreach my $item (sort(@posschars)) {
18677: if ($item =~ /^(uc|lc|num|spec)$/) {
18678: push(@chars,$item);
18679: }
18680: }
18681: $newvalues->{'chars'} = \@chars;
18682: unless ($changes->{'rules'}) {
18683: if (ref($current->{'chars'}) eq 'ARRAY') {
18684: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18685: if (@diffs > 0) {
18686: $changes->{'rules'} = 1;
18687: }
18688: } else {
18689: if (@chars > 0) {
18690: $changes->{'rules'} = 1;
18691: }
18692: }
18693: }
18694: return;
18695: }
18696:
1.28 raeburn 18697: sub modify_usercreation {
1.27 raeburn 18698: my ($dom,%domconfig) = @_;
1.224 raeburn 18699: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18700: my $warningmsg;
1.27 raeburn 18701: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18702: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18703: if ($key eq 'cancreate') {
18704: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18705: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18706: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18707: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18708: } else {
1.224 raeburn 18709: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18710: }
18711: }
18712: }
18713: } elsif ($key eq 'email_rule') {
18714: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18715: } else {
18716: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18717: }
1.27 raeburn 18718: }
18719: }
18720: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18721: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18722: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18723: foreach my $item(@contexts) {
1.224 raeburn 18724: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18725: }
1.34 raeburn 18726: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18727: foreach my $item (@contexts) {
1.224 raeburn 18728: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18729: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18730: }
1.27 raeburn 18731: }
1.34 raeburn 18732: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18733: foreach my $item (@contexts) {
1.43 raeburn 18734: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18735: if ($cancreate{$item} ne 'any') {
18736: push(@{$changes{'cancreate'}},$item);
18737: }
18738: } else {
18739: if ($cancreate{$item} ne 'none') {
18740: push(@{$changes{'cancreate'}},$item);
18741: }
1.27 raeburn 18742: }
18743: }
18744: } else {
1.43 raeburn 18745: foreach my $item (@contexts) {
1.34 raeburn 18746: push(@{$changes{'cancreate'}},$item);
18747: }
1.27 raeburn 18748: }
1.34 raeburn 18749:
1.27 raeburn 18750: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18751: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18752: if (!grep(/^\Q$type\E$/,@username_rule)) {
18753: push(@{$changes{'username_rule'}},$type);
18754: }
18755: }
18756: foreach my $type (@username_rule) {
18757: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18758: push(@{$changes{'username_rule'}},$type);
18759: }
18760: }
18761: } else {
18762: push(@{$changes{'username_rule'}},@username_rule);
18763: }
18764:
1.32 raeburn 18765: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18766: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18767: if (!grep(/^\Q$type\E$/,@id_rule)) {
18768: push(@{$changes{'id_rule'}},$type);
18769: }
18770: }
18771: foreach my $type (@id_rule) {
18772: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18773: push(@{$changes{'id_rule'}},$type);
18774: }
18775: }
18776: } else {
18777: push(@{$changes{'id_rule'}},@id_rule);
18778: }
18779:
1.43 raeburn 18780: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18781: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18782: my %authhash;
1.43 raeburn 18783: foreach my $item (@authen_contexts) {
1.28 raeburn 18784: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18785: foreach my $auth (@authtypes) {
18786: if (grep(/^\Q$auth\E$/,@authallowed)) {
18787: $authhash{$item}{$auth} = 1;
18788: } else {
18789: $authhash{$item}{$auth} = 0;
18790: }
18791: }
18792: }
18793: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18794: foreach my $item (@authen_contexts) {
1.28 raeburn 18795: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18796: foreach my $auth (@authtypes) {
18797: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18798: push(@{$changes{'authtypes'}},$item);
18799: last;
18800: }
18801: }
18802: }
18803: }
18804: } else {
1.43 raeburn 18805: foreach my $item (@authen_contexts) {
1.28 raeburn 18806: push(@{$changes{'authtypes'}},$item);
18807: }
18808: }
18809:
1.224 raeburn 18810: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18811: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18812: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18813: $save_usercreate{'id_rule'} = \@id_rule;
18814: $save_usercreate{'username_rule'} = \@username_rule,
18815: $save_usercreate{'authtypes'} = \%authhash;
18816:
1.27 raeburn 18817: my %usercreation_hash = (
1.224 raeburn 18818: usercreation => \%save_usercreate,
18819: );
1.27 raeburn 18820:
18821: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18822: $dom);
1.50 raeburn 18823:
1.224 raeburn 18824: if ($putresult eq 'ok') {
18825: if (keys(%changes) > 0) {
18826: $resulttext = &mt('Changes made:').'<ul>';
18827: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18828: my %lt = &usercreation_types();
18829: foreach my $type (@{$changes{'cancreate'}}) {
18830: my $chgtext = $lt{$type}.', ';
18831: if ($cancreate{$type} eq 'none') {
18832: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18833: } elsif ($cancreate{$type} eq 'any') {
18834: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18835: } elsif ($cancreate{$type} eq 'official') {
18836: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18837: } elsif ($cancreate{$type} eq 'unofficial') {
18838: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18839: }
18840: $resulttext .= '<li>'.$chgtext.'</li>';
18841: }
18842: }
18843: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18844: my ($rules,$ruleorder) =
18845: &Apache::lonnet::inst_userrules($dom,'username');
18846: my $chgtext = '<ul>';
18847: foreach my $type (@username_rule) {
18848: if (ref($rules->{$type}) eq 'HASH') {
18849: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18850: }
18851: }
18852: $chgtext .= '</ul>';
18853: if (@username_rule > 0) {
18854: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18855: } else {
18856: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18857: }
18858: }
18859: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18860: my ($idrules,$idruleorder) =
18861: &Apache::lonnet::inst_userrules($dom,'id');
18862: my $chgtext = '<ul>';
18863: foreach my $type (@id_rule) {
18864: if (ref($idrules->{$type}) eq 'HASH') {
18865: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18866: }
18867: }
18868: $chgtext .= '</ul>';
18869: if (@id_rule > 0) {
18870: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18871: } else {
18872: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18873: }
18874: }
18875: my %authname = &authtype_names();
18876: my %context_title = &context_names();
18877: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18878: my $chgtext = '<ul>';
18879: foreach my $type (@{$changes{'authtypes'}}) {
18880: my @allowed;
18881: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18882: foreach my $auth (@authtypes) {
18883: if ($authhash{$type}{$auth}) {
18884: push(@allowed,$authname{$auth});
18885: }
18886: }
18887: if (@allowed > 0) {
18888: $chgtext .= join(', ',@allowed).'</li>';
18889: } else {
18890: $chgtext .= &mt('none').'</li>';
18891: }
18892: }
18893: $chgtext .= '</ul>';
18894: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18895: $resulttext .= '</li>';
18896: }
18897: $resulttext .= '</ul>';
18898: } else {
18899: $resulttext = &mt('No changes made to user creation settings');
18900: }
18901: } else {
18902: $resulttext = '<span class="LC_error">'.
18903: &mt('An error occurred: [_1]',$putresult).'</span>';
18904: }
18905: if ($warningmsg ne '') {
18906: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18907: }
18908: return $resulttext;
18909: }
18910:
18911: sub modify_selfcreation {
1.305 raeburn 18912: my ($dom,$lastactref,%domconfig) = @_;
18913: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18914: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18915: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18916: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18917: if (ref($typesref) eq 'ARRAY') {
18918: @types = @{$typesref};
18919: }
18920: if (ref($usertypesref) eq 'HASH') {
18921: %usertypes = %{$usertypesref};
1.228 raeburn 18922: }
1.303 raeburn 18923: $usertypes{'default'} = $othertitle;
1.224 raeburn 18924: #
18925: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18926: #
18927: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18928: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18929: if ($key eq 'cancreate') {
18930: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18931: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18932: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18933: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18934: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18935: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18936: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18937: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18938: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18939: } else {
18940: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18941: }
18942: }
18943: }
18944: } elsif ($key eq 'email_rule') {
18945: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18946: } else {
18947: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18948: }
18949: }
18950: }
18951: #
18952: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18953: #
18954: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18955: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18956: if ($key eq 'selfcreate') {
18957: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18958: } else {
18959: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18960: }
18961: }
18962: }
1.305 raeburn 18963: #
18964: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18965: #
18966: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18967: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18968: if ($key eq 'inststatusguest') {
18969: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18970: } else {
18971: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18972: }
18973: }
18974: }
1.224 raeburn 18975:
18976: my @contexts = ('selfcreate');
18977: @{$cancreate{'selfcreate'}} = ();
18978: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18979: if (@types) {
18980: @{$cancreate{'statustocreate'}} = ();
18981: }
1.236 raeburn 18982: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18983: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18984: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18985: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18986: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18987: my %selfcreatetypes = (
18988: sso => 'users authenticated by institutional single sign on',
18989: login => 'users authenticated by institutional log-in',
1.303 raeburn 18990: email => 'users verified by e-mail',
1.50 raeburn 18991: );
1.224 raeburn 18992: #
18993: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18994: # is permitted.
18995: #
1.305 raeburn 18996: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 18997:
1.305 raeburn 18998: my (@statuses,%email_rule);
1.228 raeburn 18999: foreach my $item ('login','sso','email') {
1.224 raeburn 19000: if ($item eq 'email') {
1.236 raeburn 19001: if ($env{'form.cancreate_email'}) {
1.305 raeburn 19002: if (@types) {
19003: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
19004: foreach my $status (@poss_statuses) {
19005: if (grep(/^\Q$status\E$/,(@types,'default'))) {
19006: push(@statuses,$status);
19007: }
19008: }
19009: $save_inststatus{'inststatusguest'} = \@statuses;
19010: } else {
19011: push(@statuses,'default');
19012: }
19013: if (@statuses) {
19014: my %curr_rule;
19015: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
19016: foreach my $type (@statuses) {
19017: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 19018: }
1.305 raeburn 19019: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
19020: foreach my $type (@statuses) {
19021: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
19022: }
19023: }
19024: push(@{$cancreate{'selfcreate'}},'email');
19025: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
19026: my %curremaildom;
19027: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
19028: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
19029: }
19030: foreach my $type (@statuses) {
19031: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
19032: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
19033: }
19034: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
19035: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
19036: }
19037: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
19038: #
19039: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
19040: #
19041: my $chosen = $1;
19042: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
19043: my $emaildom;
19044: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 19045: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 19046: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
19047: if (ref($curremaildom{$type}) eq 'HASH') {
19048: if (exists($curremaildom{$type}{$chosen})) {
19049: if ($curremaildom{$type}{$chosen} ne $emaildom) {
19050: push(@{$changes{'cancreate'}},'emaildomain');
19051: }
19052: } elsif ($emaildom ne '') {
19053: push(@{$changes{'cancreate'}},'emaildomain');
19054: }
19055: } elsif ($emaildom ne '') {
19056: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 19057: }
1.305 raeburn 19058: }
19059: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19060: } elsif ($chosen eq 'custom') {
19061: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
19062: $email_rule{$type} = [];
19063: if (ref($emailrules) eq 'HASH') {
19064: foreach my $rule (@possemail_rules) {
19065: if (exists($emailrules->{$rule})) {
19066: push(@{$email_rule{$type}},$rule);
19067: }
19068: }
19069: }
19070: if (@{$email_rule{$type}}) {
19071: $cancreate{'emailoptions'}{$type} = 'custom';
19072: if (ref($curr_rule{$type}) eq 'ARRAY') {
19073: if (@{$curr_rule{$type}} > 0) {
19074: foreach my $rule (@{$curr_rule{$type}}) {
19075: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
19076: push(@{$changes{'email_rule'}},$type);
19077: }
19078: }
19079: }
19080: foreach my $type (@{$email_rule{$type}}) {
19081: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
19082: push(@{$changes{'email_rule'}},$type);
19083: }
19084: }
19085: } else {
19086: push(@{$changes{'email_rule'}},$type);
19087: }
19088: }
19089: } else {
19090: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19091: }
19092: }
19093: }
19094: if (@types) {
19095: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19096: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
19097: if (@changed) {
19098: push(@{$changes{'inststatus'}},'inststatusguest');
19099: }
19100: } else {
19101: push(@{$changes{'inststatus'}},'inststatusguest');
19102: }
19103: }
19104: } else {
19105: delete($env{'form.cancreate_email'});
19106: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19107: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19108: push(@{$changes{'inststatus'}},'inststatusguest');
19109: }
19110: }
19111: }
19112: } else {
19113: $save_inststatus{'inststatusguest'} = [];
19114: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19115: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19116: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 19117: }
19118: }
1.224 raeburn 19119: }
19120: } else {
19121: if ($env{'form.cancreate_'.$item}) {
19122: push(@{$cancreate{'selfcreate'}},$item);
19123: }
19124: }
19125: }
1.305 raeburn 19126: my (%userinfo,%savecaptcha);
1.224 raeburn 19127: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
19128: #
1.228 raeburn 19129: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
19130: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19131: #
1.236 raeburn 19132:
1.244 raeburn 19133: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19134: push(@contexts,'emailusername');
1.305 raeburn 19135: if (@statuses) {
19136: foreach my $type (@statuses) {
1.228 raeburn 19137: if (ref($infofields) eq 'ARRAY') {
19138: foreach my $field (@{$infofields}) {
19139: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19140: $cancreate{'emailusername'}{$type}{$field} = $1;
19141: }
19142: }
1.224 raeburn 19143: }
19144: }
19145: }
19146: #
19147: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19148: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19149: #
19150:
19151: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19152: @approvalnotify = sort(@approvalnotify);
19153: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19154: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19155: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19156: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19157: push(@{$changes{'cancreate'}},'notify');
19158: }
19159: } else {
19160: if ($cancreate{'notify'}{'approval'}) {
19161: push(@{$changes{'cancreate'}},'notify');
19162: }
19163: }
19164: } elsif ($cancreate{'notify'}{'approval'}) {
19165: push(@{$changes{'cancreate'}},'notify');
19166: }
19167:
19168: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19169: }
19170: #
1.236 raeburn 19171: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19172: # institutional log-in.
19173: #
19174: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19175: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19176: ($domdefaults{'auth_def'} eq 'localauth'))) {
19177: $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.').' '.
19178: &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.');
19179: }
19180: }
19181: my @fields = ('lastname','firstname','middlename','generation',
19182: 'permanentemail','id');
1.240 raeburn 19183: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19184: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19185: #
19186: # Where usernames may created for institutional log-in and/or institutional single sign on:
19187: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19188: # may self-create accounts
19189: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19190: # which the user may supply, if institutional data is unavailable.
19191: #
19192: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19193: if (@types) {
1.305 raeburn 19194: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19195: push(@contexts,'statustocreate');
1.303 raeburn 19196: foreach my $type (@types) {
1.224 raeburn 19197: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19198: foreach my $field (@fields) {
19199: if (grep(/^\Q$field\E$/,@modifiable)) {
19200: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19201: } else {
19202: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19203: }
19204: }
19205: }
19206: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19207: foreach my $type (@types) {
1.224 raeburn 19208: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19209: foreach my $field (@fields) {
19210: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19211: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19212: push(@{$changes{'selfcreate'}},$type);
19213: last;
19214: }
19215: }
19216: }
19217: }
19218: } else {
1.303 raeburn 19219: foreach my $type (@types) {
1.224 raeburn 19220: push(@{$changes{'selfcreate'}},$type);
19221: }
19222: }
19223: }
1.240 raeburn 19224: foreach my $field (@shibfields) {
19225: if ($env{'form.shibenv_'.$field} ne '') {
19226: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19227: }
19228: }
19229: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19230: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19231: foreach my $field (@shibfields) {
19232: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19233: push(@{$changes{'cancreate'}},'shibenv');
19234: }
19235: }
19236: } else {
19237: foreach my $field (@shibfields) {
19238: if ($env{'form.shibenv_'.$field}) {
19239: push(@{$changes{'cancreate'}},'shibenv');
19240: last;
19241: }
19242: }
19243: }
19244: }
1.224 raeburn 19245: }
19246: foreach my $item (@contexts) {
19247: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19248: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19249: if (ref($cancreate{$item}) eq 'ARRAY') {
19250: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19251: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19252: push(@{$changes{'cancreate'}},$item);
19253: }
19254: }
19255: }
19256: }
19257: if (ref($cancreate{$item}) eq 'ARRAY') {
19258: foreach my $type (@{$cancreate{$item}}) {
19259: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19260: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19261: push(@{$changes{'cancreate'}},$item);
19262: }
19263: }
19264: }
19265: }
19266: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19267: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19268: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19269: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19270: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19271: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19272: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19273: push(@{$changes{'cancreate'}},$item);
19274: }
19275: }
19276: }
1.305 raeburn 19277: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19278: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19279: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19280: push(@{$changes{'cancreate'}},$item);
19281: }
1.224 raeburn 19282: }
19283: }
19284: }
1.305 raeburn 19285: foreach my $type (keys(%{$cancreate{$item}})) {
19286: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19287: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19288: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19289: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19290: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19291: push(@{$changes{'cancreate'}},$item);
19292: }
19293: }
19294: } else {
19295: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19296: push(@{$changes{'cancreate'}},$item);
19297: }
19298: }
19299: }
1.305 raeburn 19300: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19301: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19302: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19303: push(@{$changes{'cancreate'}},$item);
19304: }
1.224 raeburn 19305: }
19306: }
19307: }
19308: }
19309: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19310: if (ref($cancreate{$item}) eq 'ARRAY') {
19311: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19312: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19313: push(@{$changes{'cancreate'}},$item);
19314: }
19315: }
1.305 raeburn 19316: }
19317: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19318: if (ref($cancreate{$item}) eq 'HASH') {
19319: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19320: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19321: }
19322: }
19323: } elsif ($item eq 'emailusername') {
1.228 raeburn 19324: if (ref($cancreate{$item}) eq 'HASH') {
19325: foreach my $type (keys(%{$cancreate{$item}})) {
19326: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19327: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19328: if ($cancreate{$item}{$type}{$field}) {
19329: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19330: push(@{$changes{'cancreate'}},$item);
19331: }
19332: last;
19333: }
19334: }
19335: }
19336: }
1.224 raeburn 19337: }
19338: }
19339: }
19340: #
19341: # Populate %save_usercreate hash with updates to self-creation configuration.
19342: #
19343: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19344: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19345: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19346: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19347: if (ref($cancreate{'notify'}) eq 'HASH') {
19348: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19349: }
1.236 raeburn 19350: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19351: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19352: }
1.303 raeburn 19353: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19354: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19355: }
1.305 raeburn 19356: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19357: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19358: }
1.303 raeburn 19359: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19360: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19361: }
1.224 raeburn 19362: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19363: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19364: }
1.240 raeburn 19365: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19366: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19367: }
1.224 raeburn 19368: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19369: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19370:
19371: my %userconfig_hash = (
19372: usercreation => \%save_usercreate,
19373: usermodification => \%save_usermodify,
1.305 raeburn 19374: inststatus => \%save_inststatus,
1.224 raeburn 19375: );
1.305 raeburn 19376:
1.224 raeburn 19377: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19378: $dom);
19379: #
1.305 raeburn 19380: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19381: #
1.27 raeburn 19382: if ($putresult eq 'ok') {
19383: if (keys(%changes) > 0) {
19384: $resulttext = &mt('Changes made:').'<ul>';
19385: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19386: my %lt = &selfcreation_types();
1.34 raeburn 19387: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19388: my $chgtext = '';
1.45 raeburn 19389: if ($type eq 'selfcreate') {
1.50 raeburn 19390: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19391: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19392: } else {
1.224 raeburn 19393: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19394: '<ul>';
1.50 raeburn 19395: foreach my $case (@{$cancreate{$type}}) {
19396: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19397: }
19398: $chgtext .= '</ul>';
1.100 raeburn 19399: if (ref($cancreate{$type}) eq 'ARRAY') {
19400: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19401: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19402: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19403: $chgtext .= '<span class="LC_warning">'.
19404: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19405: '</span><br />';
19406: }
19407: }
19408: }
19409: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19410: if (!@statuses) {
19411: $chgtext .= '<span class="LC_warning">'.
19412: &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.").
19413: '</span><br />';
1.303 raeburn 19414:
1.100 raeburn 19415: }
19416: }
19417: }
1.43 raeburn 19418: }
1.240 raeburn 19419: } elsif ($type eq 'shibenv') {
19420: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19421: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19422: } else {
19423: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19424: '<ul>';
19425: foreach my $field (@shibfields) {
19426: next if ($cancreate{$type}{$field} eq '');
19427: if ($field eq 'inststatus') {
19428: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19429: } else {
19430: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19431: }
19432: }
19433: $chgtext .= '</ul>';
1.303 raeburn 19434: }
1.93 raeburn 19435: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19436: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19437: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19438: if (@{$cancreate{'selfcreate'}} > 0) {
19439: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19440: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19441: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19442: $chgtext .= '<br />'.
19443: '<span class="LC_warning">'.
19444: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19445: '</span>';
19446: }
1.303 raeburn 19447: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19448: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19449: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19450: } else {
19451: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19452: }
19453: $chgtext .= '<ul>';
19454: foreach my $case (@{$cancreate{$type}}) {
19455: if ($case eq 'default') {
19456: $chgtext .= '<li>'.$othertitle.'</li>';
19457: } else {
1.303 raeburn 19458: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19459: }
19460: }
1.100 raeburn 19461: $chgtext .= '</ul>';
19462: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19463: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19464: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19465: '</span>';
1.100 raeburn 19466: }
19467: }
19468: } else {
19469: if (@{$cancreate{$type}} == 0) {
19470: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19471: } else {
19472: $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 19473: }
19474: }
1.303 raeburn 19475: $chgtext .= '<br />';
1.93 raeburn 19476: }
1.236 raeburn 19477: } elsif ($type eq 'selfcreateprocessing') {
19478: my %choices = &Apache::lonlocal::texthash (
19479: automatic => 'Automatic approval',
19480: approval => 'Queued for approval',
19481: );
1.305 raeburn 19482: if (@types) {
19483: if (@statuses) {
1.425 raeburn 19484: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19485: '<ul>';
1.305 raeburn 19486: foreach my $status (@statuses) {
19487: if ($status eq 'default') {
19488: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19489: } else {
1.305 raeburn 19490: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19491: }
19492: }
19493: $chgtext .= '</ul>';
19494: }
19495: } else {
19496: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19497: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19498: }
19499: } elsif ($type eq 'emailverified') {
19500: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19501: all => 'Same as e-mail',
19502: first => 'Omit @domain',
19503: free => 'Free to choose',
1.303 raeburn 19504: );
1.305 raeburn 19505: if (@types) {
19506: if (@statuses) {
1.303 raeburn 19507: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19508: '<ul>';
1.305 raeburn 19509: foreach my $status (@statuses) {
1.362 raeburn 19510: if ($status eq 'default') {
1.305 raeburn 19511: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19512: } else {
1.305 raeburn 19513: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19514: }
19515: }
19516: $chgtext .= '</ul>';
19517: }
19518: } else {
1.305 raeburn 19519: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19520: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19521: }
1.305 raeburn 19522: } elsif ($type eq 'emailoptions') {
19523: my %options = &Apache::lonlocal::texthash (
19524: any => 'Any e-mail',
19525: inst => 'Institutional only',
19526: noninst => 'Non-institutional only',
19527: custom => 'Custom restrictions',
19528: );
19529: if (@types) {
19530: if (@statuses) {
19531: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19532: '<ul>';
19533: foreach my $status (@statuses) {
19534: if ($type eq 'default') {
19535: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19536: } else {
19537: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19538: }
19539: }
1.305 raeburn 19540: $chgtext .= '</ul>';
19541: }
19542: } else {
19543: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19544: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19545: } else {
19546: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19547: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19548: }
1.305 raeburn 19549: }
19550: } elsif ($type eq 'emaildomain') {
19551: my $output;
19552: if (@statuses) {
19553: foreach my $type (@statuses) {
19554: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19555: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19556: if ($type eq 'default') {
19557: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19558: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19559: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19560: } else {
19561: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19562: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19563: }
1.303 raeburn 19564: } else {
1.305 raeburn 19565: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19566: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19567: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19568: } else {
19569: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19570: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19571: }
1.303 raeburn 19572: }
1.305 raeburn 19573: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19574: if ($type eq 'default') {
19575: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19576: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19577: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19578: } else {
19579: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19580: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19581: }
1.303 raeburn 19582: } else {
1.305 raeburn 19583: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19584: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19585: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19586: } else {
19587: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19588: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19589: }
1.303 raeburn 19590: }
19591: }
19592: }
19593: }
1.305 raeburn 19594: }
19595: if ($output ne '') {
19596: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19597: '<ul>'.$output.'</ul>';
1.236 raeburn 19598: }
1.165 raeburn 19599: } elsif ($type eq 'captcha') {
1.224 raeburn 19600: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19601: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19602: } else {
19603: my %captchas = &captcha_phrases();
1.224 raeburn 19604: if ($captchas{$savecaptcha{$type}}) {
19605: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19606: } else {
1.210 raeburn 19607: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19608: }
19609: }
19610: } elsif ($type eq 'recaptchakeys') {
19611: my ($privkey,$pubkey);
1.224 raeburn 19612: if (ref($savecaptcha{$type}) eq 'HASH') {
19613: $pubkey = $savecaptcha{$type}{'public'};
19614: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19615: }
19616: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19617: if (!$pubkey) {
19618: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19619: } else {
19620: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19621: }
19622: if (!$privkey) {
19623: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19624: } else {
19625: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19626: }
19627: $chgtext .= '</ul>';
1.269 raeburn 19628: } elsif ($type eq 'recaptchaversion') {
19629: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19630: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19631: }
1.224 raeburn 19632: } elsif ($type eq 'emailusername') {
19633: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19634: if (@statuses) {
19635: foreach my $type (@statuses) {
1.228 raeburn 19636: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19637: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19638: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19639: '<ul>';
19640: foreach my $field (@{$infofields}) {
19641: if ($cancreate{'emailusername'}{$type}{$field}) {
19642: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19643: }
19644: }
1.245 raeburn 19645: $chgtext .= '</ul>';
19646: } else {
1.303 raeburn 19647: $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 19648: }
19649: } else {
1.303 raeburn 19650: $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 19651: }
19652: }
19653: }
19654: }
19655: } elsif ($type eq 'notify') {
1.303 raeburn 19656: my $numapprove = 0;
1.224 raeburn 19657: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19658: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19659: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19660: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19661: $numapprove ++;
1.224 raeburn 19662: }
19663: }
1.43 raeburn 19664: }
1.303 raeburn 19665: unless ($numapprove) {
19666: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19667: }
1.34 raeburn 19668: }
1.224 raeburn 19669: if ($chgtext) {
19670: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19671: }
19672: }
19673: }
1.305 raeburn 19674: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19675: my ($emailrules,$emailruleorder) =
19676: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19677: foreach my $type (@{$changes{'email_rule'}}) {
19678: if (ref($email_rule{$type}) eq 'ARRAY') {
19679: my $chgtext = '<ul>';
19680: foreach my $rule (@{$email_rule{$type}}) {
19681: if (ref($emailrules->{$rule}) eq 'HASH') {
19682: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19683: }
19684: }
19685: $chgtext .= '</ul>';
1.310 raeburn 19686: my $typename;
1.305 raeburn 19687: if (@types) {
19688: if ($type eq 'default') {
19689: $typename = $othertitle;
19690: } else {
19691: $typename = $usertypes{$type};
1.425 raeburn 19692: }
1.305 raeburn 19693: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19694: }
19695: if (@{$email_rule{$type}} > 0) {
19696: $resulttext .= '<li>'.
19697: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19698: $usertypes{$type}).
19699: $chgtext.
19700: '</li>';
19701: } else {
19702: $resulttext .= '<li>'.
1.310 raeburn 19703: &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 19704: '</li>'.
1.310 raeburn 19705: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19706: }
1.43 raeburn 19707: }
19708: }
1.305 raeburn 19709: }
19710: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19711: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19712: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19713: my $chgtext = '<ul>';
19714: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19715: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19716: }
19717: $chgtext .= '</ul>';
19718: $resulttext .= '<li>'.
19719: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19720: $chgtext.
19721: '</li>';
19722: } else {
19723: $resulttext .= '<li>'.
19724: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19725: '</li>';
19726: }
1.43 raeburn 19727: }
19728: }
1.224 raeburn 19729: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19730: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19731: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19732: foreach my $type (@{$changes{'selfcreate'}}) {
19733: my $typename = $type;
1.303 raeburn 19734: if (keys(%usertypes) > 0) {
19735: if ($usertypes{$type} ne '') {
19736: $typename = $usertypes{$type};
1.224 raeburn 19737: }
19738: }
19739: my @modifiable;
19740: $resulttext .= '<li>'.
19741: &mt('Self-creation of account by users with status: [_1]',
19742: '<span class="LC_cusr_emph">'.$typename.'</span>').
19743: ' - '.&mt('modifiable fields (if institutional data blank): ');
19744: foreach my $field (@fields) {
19745: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19746: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19747: }
19748: }
1.224 raeburn 19749: if (@modifiable > 0) {
19750: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19751: } else {
1.224 raeburn 19752: $resulttext .= &mt('none');
1.43 raeburn 19753: }
1.224 raeburn 19754: $resulttext .= '</li>';
1.28 raeburn 19755: }
1.224 raeburn 19756: $resulttext .= '</ul></li>';
1.28 raeburn 19757: }
1.27 raeburn 19758: $resulttext .= '</ul>';
1.305 raeburn 19759: my $cachetime = 24*60*60;
19760: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19761: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19762: if (ref($lastactref) eq 'HASH') {
19763: $lastactref->{'domdefaults'} = 1;
19764: }
1.27 raeburn 19765: } else {
1.224 raeburn 19766: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19767: }
19768: } else {
19769: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19770: &mt('An error occurred: [_1]',$putresult).'</span>';
19771: }
1.43 raeburn 19772: if ($warningmsg ne '') {
19773: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19774: }
1.23 raeburn 19775: return $resulttext;
19776: }
19777:
1.165 raeburn 19778: sub process_captcha {
1.369 raeburn 19779: my ($container,$changes,$newsettings,$currsettings) = @_;
19780: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19781: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19782: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19783: $newsettings->{'captcha'} = 'original';
19784: }
1.369 raeburn 19785: my %current;
19786: if (ref($currsettings) eq 'HASH') {
19787: %current = %{$currsettings};
19788: }
19789: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19790: if ($container eq 'cancreate') {
1.169 raeburn 19791: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19792: push(@{$changes->{'cancreate'}},'captcha');
19793: } elsif (!defined($changes->{'cancreate'})) {
19794: $changes->{'cancreate'} = ['captcha'];
19795: }
1.368 raeburn 19796: } elsif ($container eq 'passwords') {
19797: $changes->{'reset'} = 1;
1.169 raeburn 19798: } else {
19799: $changes->{'captcha'} = 1;
1.165 raeburn 19800: }
19801: }
1.269 raeburn 19802: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19803: if ($newsettings->{'captcha'} eq 'recaptcha') {
19804: $newpub = $env{'form.'.$container.'_recaptchapub'};
19805: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19806: $newpub =~ s/[^\w\-]//g;
19807: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19808: $newsettings->{'recaptchakeys'} = {
19809: public => $newpub,
19810: private => $newpriv,
19811: };
1.269 raeburn 19812: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19813: $newversion =~ s/\D//g;
19814: if ($newversion ne '2') {
19815: $newversion = 1;
19816: }
19817: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19818: }
1.369 raeburn 19819: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19820: $currpub = $current{'recaptchakeys'}{'public'};
19821: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19822: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19823: $newsettings->{'recaptchakeys'} = {
19824: public => '',
19825: private => '',
19826: }
19827: }
1.165 raeburn 19828: }
1.369 raeburn 19829: if ($current{'captcha'} eq 'recaptcha') {
19830: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19831: if ($currversion ne '2') {
19832: $currversion = 1;
19833: }
19834: }
19835: if ($currversion ne $newversion) {
19836: if ($container eq 'cancreate') {
19837: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19838: push(@{$changes->{'cancreate'}},'recaptchaversion');
19839: } elsif (!defined($changes->{'cancreate'})) {
19840: $changes->{'cancreate'} = ['recaptchaversion'];
19841: }
1.368 raeburn 19842: } elsif ($container eq 'passwords') {
19843: $changes->{'reset'} = 1;
1.269 raeburn 19844: } else {
19845: $changes->{'recaptchaversion'} = 1;
19846: }
19847: }
1.165 raeburn 19848: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19849: if ($container eq 'cancreate') {
19850: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19851: push(@{$changes->{'cancreate'}},'recaptchakeys');
19852: } elsif (!defined($changes->{'cancreate'})) {
19853: $changes->{'cancreate'} = ['recaptchakeys'];
19854: }
1.368 raeburn 19855: } elsif ($container eq 'passwords') {
19856: $changes->{'reset'} = 1;
1.169 raeburn 19857: } else {
1.210 raeburn 19858: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19859: }
19860: }
19861: return;
19862: }
19863:
1.33 raeburn 19864: sub modify_usermodification {
19865: my ($dom,%domconfig) = @_;
1.224 raeburn 19866: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19867: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19868: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19869: if ($key eq 'selfcreate') {
19870: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19871: } else {
19872: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19873: }
1.33 raeburn 19874: }
19875: }
1.443 raeburn 19876: my @contexts = ('author','coauthor','course');
1.33 raeburn 19877: my %context_title = (
19878: author => 'In author context',
1.443 raeburn 19879: coauthor => 'As co-author manager',
1.33 raeburn 19880: course => 'In course context',
19881: );
19882: my @fields = ('lastname','firstname','middlename','generation',
19883: 'permanentemail','id');
19884: my %roles = (
19885: author => ['ca','aa'],
1.443 raeburn 19886: coauthor => ['ca','aa'],
1.33 raeburn 19887: course => ['st','ep','ta','in','cr'],
19888: );
19889: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19890: foreach my $context (@contexts) {
1.443 raeburn 19891: my $prefix = 'canmodify';
19892: if ($context eq 'coauthor') {
19893: $prefix = 'cacanmodify';
19894: }
1.33 raeburn 19895: foreach my $role (@{$roles{$context}}) {
1.443 raeburn 19896: my @modifiable = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$role);
1.33 raeburn 19897: foreach my $item (@fields) {
19898: if (grep(/^\Q$item\E$/,@modifiable)) {
19899: $modifyhash{$context}{$role}{$item} = 1;
19900: } else {
19901: $modifyhash{$context}{$role}{$item} = 0;
19902: }
19903: }
19904: }
19905: if (ref($curr_usermodification{$context}) eq 'HASH') {
19906: foreach my $role (@{$roles{$context}}) {
19907: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19908: foreach my $field (@fields) {
19909: if ($modifyhash{$context}{$role}{$field} ne
19910: $curr_usermodification{$context}{$role}{$field}) {
19911: push(@{$changes{$context}},$role);
19912: last;
19913: }
19914: }
19915: }
19916: }
19917: } else {
19918: foreach my $context (@contexts) {
19919: foreach my $role (@{$roles{$context}}) {
19920: push(@{$changes{$context}},$role);
19921: }
19922: }
19923: }
19924: }
19925: my %usermodification_hash = (
19926: usermodification => \%modifyhash,
19927: );
19928: my $putresult = &Apache::lonnet::put_dom('configuration',
19929: \%usermodification_hash,$dom);
19930: if ($putresult eq 'ok') {
19931: if (keys(%changes) > 0) {
19932: $resulttext = &mt('Changes made: ').'<ul>';
19933: foreach my $context (@contexts) {
19934: if (ref($changes{$context}) eq 'ARRAY') {
19935: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19936: if (ref($changes{$context}) eq 'ARRAY') {
19937: foreach my $role (@{$changes{$context}}) {
19938: my $rolename;
1.224 raeburn 19939: if ($role eq 'cr') {
19940: $rolename = &mt('Custom');
1.33 raeburn 19941: } else {
1.224 raeburn 19942: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19943: }
19944: my @modifiable;
1.224 raeburn 19945: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19946: foreach my $field (@fields) {
19947: if ($modifyhash{$context}{$role}{$field}) {
19948: push(@modifiable,$fieldtitles{$field});
19949: }
19950: }
19951: if (@modifiable > 0) {
19952: $resulttext .= join(', ',@modifiable);
19953: } else {
19954: $resulttext .= &mt('none');
19955: }
19956: $resulttext .= '</li>';
19957: }
19958: $resulttext .= '</ul></li>';
19959: }
19960: }
19961: }
19962: $resulttext .= '</ul>';
19963: } else {
19964: $resulttext = &mt('No changes made to user modification settings');
19965: }
19966: } else {
19967: $resulttext = '<span class="LC_error">'.
19968: &mt('An error occurred: [_1]',$putresult).'</span>';
19969: }
19970: return $resulttext;
19971: }
19972:
1.43 raeburn 19973: sub modify_defaults {
1.212 raeburn 19974: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19975: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19976: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19977: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19978: 'portal_def');
1.325 raeburn 19979: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19980: foreach my $item (@items) {
19981: $newvalues{$item} = $env{'form.'.$item};
19982: if ($item eq 'auth_def') {
19983: if ($newvalues{$item} ne '') {
19984: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19985: push(@errors,$item);
19986: }
19987: }
19988: } elsif ($item eq 'lang_def') {
19989: if ($newvalues{$item} ne '') {
19990: if ($newvalues{$item} =~ /^(\w+)/) {
19991: my $langcode = $1;
1.103 raeburn 19992: if ($langcode ne 'x_chef') {
19993: if (code2language($langcode) eq '') {
19994: push(@errors,$item);
19995: }
1.43 raeburn 19996: }
19997: } else {
19998: push(@errors,$item);
19999: }
20000: }
1.54 raeburn 20001: } elsif ($item eq 'timezone_def') {
20002: if ($newvalues{$item} ne '') {
1.62 raeburn 20003: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 20004: push(@errors,$item);
20005: }
20006: }
1.68 raeburn 20007: } elsif ($item eq 'datelocale_def') {
20008: if ($newvalues{$item} ne '') {
20009: my @datelocale_ids = DateTime::Locale->ids();
20010: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
20011: push(@errors,$item);
20012: }
20013: }
1.141 raeburn 20014: } elsif ($item eq 'portal_def') {
20015: if ($newvalues{$item} ne '') {
1.414 raeburn 20016: 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])\/?$/) {
20017: foreach my $field ('email','web') {
20018: if ($env{'form.'.$item.'_'.$field}) {
20019: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
20020: }
20021: }
20022: } else {
1.141 raeburn 20023: push(@errors,$item);
20024: }
20025: }
1.43 raeburn 20026: }
20027: if (grep(/^\Q$item\E$/,@errors)) {
20028: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 20029: if ($item eq 'portal_def') {
20030: if ($domdefaults{$item}) {
20031: foreach my $field ('email','web') {
20032: if (exists($domdefaults{$item.'_'.$field})) {
20033: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
20034: }
20035: }
20036: }
20037: }
1.43 raeburn 20038: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
20039: $changes{$item} = 1;
20040: }
1.414 raeburn 20041: if ($item eq 'portal_def') {
20042: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 20043: if ($newvalues{$item} eq '') {
1.414 raeburn 20044: foreach my $field ('email','web') {
20045: if (exists($domdefaults{$item.'_'.$field})) {
20046: delete($domdefaults{$item.'_'.$field});
20047: }
20048: }
20049: } else {
20050: unless ($changes{$item}) {
20051: foreach my $field ('email','web') {
20052: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
20053: $changes{$item} = 1;
20054: last;
20055: }
20056: }
20057: }
20058: foreach my $field ('email','web') {
20059: if ($newvalues{$item.'_'.$field}) {
20060: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
20061: } elsif (exists($domdefaults{$item.'_'.$field})) {
20062: delete($domdefaults{$item.'_'.$field});
20063: }
20064: }
20065: }
20066: }
20067: }
1.72 raeburn 20068: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 20069: }
1.354 raeburn 20070: my %staticdefaults = (
20071: 'intauth_cost' => 10,
20072: 'intauth_check' => 0,
20073: 'intauth_switch' => 0,
20074: );
20075: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
20076: if (exists($domdefaults{$item})) {
20077: $newvalues{$item} = $domdefaults{$item};
20078: } else {
20079: $newvalues{$item} = $staticdefaults{$item};
20080: }
20081: }
1.409 raeburn 20082: my ($unamemaprules,$ruleorder);
20083: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
20084: if (@possunamemaprules) {
20085: ($unamemaprules,$ruleorder) =
20086: &Apache::lonnet::inst_userrules($dom,'unamemap');
20087: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
20088: if (@{$ruleorder} > 0) {
20089: my %possrules;
20090: map { $possrules{$_} = 1; } @possunamemaprules;
20091: foreach my $rule (@{$ruleorder}) {
20092: if ($possrules{$rule}) {
20093: push(@{$newvalues{'unamemap_rule'}},$rule);
20094: }
20095: }
20096: }
20097: }
20098: }
20099: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
20100: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20101: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
20102: $newvalues{'unamemap_rule'});
20103: if (@rulediffs) {
20104: $changes{'unamemap_rule'} = 1;
20105: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20106: }
20107: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
20108: $changes{'unamemap_rule'} = 1;
20109: delete($domdefaults{'unamemap_rule'});
20110: }
20111: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20112: if (@{$newvalues{'unamemap_rule'}} > 0) {
20113: $changes{'unamemap_rule'} = 1;
20114: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20115: }
20116: }
1.43 raeburn 20117: my %defaults_hash = (
1.72 raeburn 20118: defaults => \%newvalues,
20119: );
1.43 raeburn 20120: my $title = &defaults_titles();
1.236 raeburn 20121:
20122: my $currinststatus;
20123: if (ref($domconfig{'inststatus'}) eq 'HASH') {
20124: $currinststatus = $domconfig{'inststatus'};
20125: } else {
20126: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
20127: $currinststatus = {
20128: inststatustypes => $usertypes,
20129: inststatusorder => $types,
20130: inststatusguest => [],
20131: };
20132: }
20133: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20134: my @allpos;
20135: my %alltypes;
1.305 raeburn 20136: my @inststatusguest;
20137: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20138: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20139: unless (grep(/^\Q$type\E$/,@todelete)) {
20140: push(@inststatusguest,$type);
20141: }
20142: }
20143: }
20144: my ($currtitles,$currorder);
1.236 raeburn 20145: if (ref($currinststatus) eq 'HASH') {
20146: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20147: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20148: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20149: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20150: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20151: }
20152: }
20153: unless (grep(/^\Q$type\E$/,@todelete)) {
20154: my $position = $env{'form.inststatus_pos_'.$type};
20155: $position =~ s/\D+//g;
20156: $allpos[$position] = $type;
20157: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20158: $alltypes{$type} =~ s/`//g;
20159: }
20160: }
20161: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20162: $currtitles =~ s/,$//;
20163: }
20164: }
20165: if ($env{'form.addinststatus'}) {
20166: my $newtype = $env{'form.addinststatus'};
20167: $newtype =~ s/\W//g;
20168: unless (exists($alltypes{$newtype})) {
20169: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20170: $alltypes{$newtype} =~ s/`//g;
20171: my $position = $env{'form.addinststatus_pos'};
20172: $position =~ s/\D+//g;
20173: if ($position ne '') {
20174: $allpos[$position] = $newtype;
20175: }
20176: }
20177: }
1.305 raeburn 20178: my @orderedstatus;
1.236 raeburn 20179: foreach my $type (@allpos) {
20180: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20181: push(@orderedstatus,$type);
20182: }
20183: }
20184: foreach my $type (keys(%alltypes)) {
20185: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20186: delete($alltypes{$type});
20187: }
20188: }
20189: $defaults_hash{'inststatus'} = {
20190: inststatustypes => \%alltypes,
20191: inststatusorder => \@orderedstatus,
1.305 raeburn 20192: inststatusguest => \@inststatusguest,
1.236 raeburn 20193: };
20194: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20195: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20196: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20197: }
20198: }
20199: if ($currorder ne join(',',@orderedstatus)) {
20200: $changes{'inststatus'}{'inststatusorder'} = 1;
20201: }
20202: my $newtitles;
20203: foreach my $item (@orderedstatus) {
20204: $newtitles .= $alltypes{$item}.',';
20205: }
20206: $newtitles =~ s/,$//;
20207: if ($currtitles ne $newtitles) {
20208: $changes{'inststatus'}{'inststatustypes'} = 1;
20209: }
1.43 raeburn 20210: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20211: $dom);
20212: if ($putresult eq 'ok') {
20213: if (keys(%changes) > 0) {
20214: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20215: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20216: 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";
20217: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20218: if ($item eq 'inststatus') {
20219: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20220: if (@orderedstatus) {
1.236 raeburn 20221: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20222: foreach my $type (@orderedstatus) {
20223: $resulttext .= $alltypes{$type}.', ';
20224: }
20225: $resulttext =~ s/, $//;
20226: $resulttext .= '</li>';
1.305 raeburn 20227: } else {
1.425 raeburn 20228: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20229: }
20230: }
1.409 raeburn 20231: } elsif ($item eq 'unamemap_rule') {
20232: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20233: my @rulenames;
20234: if (ref($unamemaprules) eq 'HASH') {
20235: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20236: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20237: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20238: }
20239: }
20240: }
20241: if (@rulenames) {
20242: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20243: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20244: '</li>';
20245: } else {
20246: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20247: }
20248: } else {
20249: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20250: }
1.236 raeburn 20251: } else {
20252: my $value = $env{'form.'.$item};
20253: if ($value eq '') {
20254: $value = &mt('none');
20255: } elsif ($item eq 'auth_def') {
20256: my %authnames = &authtype_names();
20257: my %shortauth = (
20258: internal => 'int',
20259: krb4 => 'krb4',
20260: krb5 => 'krb5',
20261: localauth => 'loc',
1.325 raeburn 20262: lti => 'lti',
1.236 raeburn 20263: );
20264: $value = $authnames{$shortauth{$value}};
20265: }
20266: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20267: $mailmsgtext .= "$title->{$item} set to $value\n";
20268: if ($item eq 'portal_def') {
20269: if ($env{'form.'.$item} ne '') {
20270: foreach my $field ('email','web') {
20271: $value = $env{'form.'.$item.'_'.$field};
20272: if ($value) {
20273: $value = &mt('Yes');
20274: } else {
20275: $value = &mt('No');
20276: }
20277: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20278: }
20279: }
20280: }
1.43 raeburn 20281: }
20282: }
20283: $resulttext .= '</ul>';
20284: $mailmsgtext .= "\n";
20285: my $cachetime = 24*60*60;
1.72 raeburn 20286: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20287: if (ref($lastactref) eq 'HASH') {
20288: $lastactref->{'domdefaults'} = 1;
20289: }
1.68 raeburn 20290: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20291: my $notify = 1;
20292: if (ref($domconfig{'contacts'}) eq 'HASH') {
20293: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20294: $notify = 0;
20295: }
20296: }
20297: if ($notify) {
20298: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20299: "LON-CAPA Domain Settings Change - $dom",
20300: $mailmsgtext);
20301: }
1.54 raeburn 20302: }
1.43 raeburn 20303: } else {
1.54 raeburn 20304: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20305: }
20306: } else {
20307: $resulttext = '<span class="LC_error">'.
20308: &mt('An error occurred: [_1]',$putresult).'</span>';
20309: }
20310: if (@errors > 0) {
20311: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20312: foreach my $item (@errors) {
20313: $resulttext .= ' "'.$title->{$item}.'",';
20314: }
20315: $resulttext =~ s/,$//;
20316: }
20317: return $resulttext;
20318: }
20319:
1.46 raeburn 20320: sub modify_scantron {
1.205 raeburn 20321: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20322: my ($resulttext,%confhash,%changes,$errors);
20323: my $custom = 'custom.tab';
20324: my $default = 'default.tab';
20325: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20326: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20327: &config_check($dom,$confname,$servadm);
20328: if ($env{'form.scantronformat.filename'} ne '') {
20329: my $error;
20330: if ($configuserok eq 'ok') {
20331: if ($switchserver) {
1.130 raeburn 20332: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20333: } else {
20334: if ($author_ok eq 'ok') {
1.421 raeburn 20335: my $modified = [];
1.46 raeburn 20336: my ($result,$scantronurl) =
1.421 raeburn 20337: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20338: $confname,'scantron','','',$custom,
20339: $modified);
1.46 raeburn 20340: if ($result eq 'ok') {
20341: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20342: $changes{'scantronformat'} = 1;
1.421 raeburn 20343: &update_modify_urls($r,$modified);
1.46 raeburn 20344: } else {
20345: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20346: }
20347: } else {
20348: $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);
20349: }
20350: }
20351: } else {
20352: $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);
20353: }
20354: if ($error) {
20355: &Apache::lonnet::logthis($error);
20356: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20357: }
20358: }
1.48 raeburn 20359: if (ref($domconfig{'scantron'}) eq 'HASH') {
20360: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20361: if ($env{'form.scantronformat_del'}) {
20362: $confhash{'scantron'}{'scantronformat'} = '';
20363: $changes{'scantronformat'} = 1;
1.347 raeburn 20364: } else {
20365: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20366: }
20367: }
20368: }
1.347 raeburn 20369: my @options = ('hdr','pad','rem');
1.346 raeburn 20370: my @fields = &scantroncsv_fields();
20371: my %titles = &scantronconfig_titles();
1.347 raeburn 20372: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20373: my ($newdat,$currdat,%newcol,%currcol);
20374: if (grep(/^dat$/,@formats)) {
20375: $confhash{'scantron'}{config}{dat} = 1;
20376: $newdat = 1;
20377: } else {
20378: $newdat = 0;
20379: }
20380: if (grep(/^csv$/,@formats)) {
20381: my %bynum;
20382: foreach my $field (@fields) {
20383: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20384: my $posscol = $1;
20385: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20386: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20387: $bynum{$posscol} = $field;
20388: $newcol{$field} = $posscol;
20389: }
20390: }
20391: }
1.347 raeburn 20392: if (keys(%newcol)) {
20393: foreach my $option (@options) {
20394: if ($env{'form.scantroncsv_'.$option}) {
20395: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20396: }
20397: }
20398: }
1.346 raeburn 20399: }
20400: $currdat = 1;
20401: if (ref($domconfig{'scantron'}) eq 'HASH') {
20402: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20403: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20404: $currdat = 0;
20405: }
20406: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20407: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20408: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20409: }
1.346 raeburn 20410: }
20411: }
20412: }
20413: if ($currdat != $newdat) {
20414: $changes{'config'} = 1;
20415: } else {
20416: foreach my $field (@fields) {
20417: if ($currcol{$field} ne '') {
20418: if ($currcol{$field} ne $newcol{$field}) {
20419: $changes{'config'} = 1;
20420: last;
1.347 raeburn 20421: }
1.346 raeburn 20422: } elsif ($newcol{$field} ne '') {
20423: $changes{'config'} = 1;
20424: last;
20425: }
20426: }
20427: }
1.46 raeburn 20428: if (keys(%confhash) > 0) {
20429: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20430: $dom);
20431: if ($putresult eq 'ok') {
20432: if (keys(%changes) > 0) {
1.48 raeburn 20433: if (ref($confhash{'scantron'}) eq 'HASH') {
20434: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20435: if ($changes{'scantronformat'}) {
20436: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20437: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20438: } else {
20439: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20440: }
20441: }
1.347 raeburn 20442: if ($changes{'config'}) {
1.346 raeburn 20443: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20444: if ($confhash{'scantron'}{'config'}{'dat'}) {
20445: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20446: }
20447: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20448: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20449: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20450: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20451: foreach my $field (@fields) {
20452: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20453: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20454: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20455: }
20456: }
20457: $resulttext .= '</ul></li>';
20458: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20459: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20460: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20461: foreach my $option (@options) {
20462: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20463: $resulttext .= '<li>'.$titles{$option}.'</li>';
20464: }
20465: }
20466: $resulttext .= '</ul></li>';
20467: }
1.346 raeburn 20468: }
20469: }
20470: }
20471: }
20472: } else {
20473: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20474: }
1.46 raeburn 20475: }
1.48 raeburn 20476: $resulttext .= '</ul>';
20477: } else {
1.130 raeburn 20478: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20479: }
20480: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20481: if (ref($lastactref) eq 'HASH') {
20482: $lastactref->{'domainconfig'} = 1;
20483: }
1.46 raeburn 20484: } else {
1.346 raeburn 20485: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20486: }
20487: } else {
20488: $resulttext = '<span class="LC_error">'.
20489: &mt('An error occurred: [_1]',$putresult).'</span>';
20490: }
20491: } else {
1.130 raeburn 20492: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20493: }
20494: if ($errors) {
1.353 raeburn 20495: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20496: $errors.'</ul></p>';
1.46 raeburn 20497: }
20498: return $resulttext;
20499: }
20500:
1.48 raeburn 20501: sub modify_coursecategories {
1.239 raeburn 20502: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20503: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20504: $cathash);
1.48 raeburn 20505: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20506: my @catitems = ('unauth','auth');
20507: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20508: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20509: $cathash = $domconfig{'coursecategories'}{'cats'};
20510: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20511: $changes{'togglecats'} = 1;
20512: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20513: }
20514: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20515: $changes{'categorize'} = 1;
20516: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20517: }
1.120 raeburn 20518: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20519: $changes{'togglecatscomm'} = 1;
20520: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20521: }
20522: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20523: $changes{'categorizecomm'} = 1;
20524: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20525:
20526: }
20527: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20528: $changes{'togglecatsplace'} = 1;
20529: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20530: }
20531: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20532: $changes{'categorizeplace'} = 1;
20533: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20534: }
1.238 raeburn 20535: foreach my $item (@catitems) {
20536: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20537: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20538: $changes{$item} = 1;
20539: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20540: }
20541: }
20542: }
1.57 raeburn 20543: } else {
20544: $changes{'togglecats'} = 1;
20545: $changes{'categorize'} = 1;
1.124 raeburn 20546: $changes{'togglecatscomm'} = 1;
20547: $changes{'categorizecomm'} = 1;
1.272 raeburn 20548: $changes{'togglecatsplace'} = 1;
20549: $changes{'categorizeplace'} = 1;
1.87 raeburn 20550: $domconfig{'coursecategories'} = {
20551: togglecats => $env{'form.togglecats'},
20552: categorize => $env{'form.categorize'},
1.124 raeburn 20553: togglecatscomm => $env{'form.togglecatscomm'},
20554: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20555: togglecatsplace => $env{'form.togglecatsplace'},
20556: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20557: };
1.238 raeburn 20558: foreach my $item (@catitems) {
20559: if ($env{'form.coursecat_'.$item} ne 'std') {
20560: $changes{$item} = 1;
20561: }
20562: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20563: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20564: }
20565: }
1.57 raeburn 20566: }
20567: if (ref($cathash) eq 'HASH') {
20568: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20569: push (@deletecategory,'instcode::0');
20570: }
1.120 raeburn 20571: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20572: push(@deletecategory,'communities::0');
20573: }
1.272 raeburn 20574: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20575: push(@deletecategory,'placement::0');
20576: }
1.48 raeburn 20577: }
1.57 raeburn 20578: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20579: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20580: if (@deletecategory > 0) {
20581: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20582: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20583: foreach my $item (@deletecategory) {
1.57 raeburn 20584: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20585: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20586: $deletions{$item} = 1;
1.57 raeburn 20587: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20588: }
20589: }
20590: }
1.57 raeburn 20591: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20592: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20593: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20594: $reorderings{$item} = 1;
1.57 raeburn 20595: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20596: }
20597: if ($env{'form.addcategory_name_'.$item} ne '') {
20598: my $newcat = $env{'form.addcategory_name_'.$item};
20599: my $newdepth = $depth+1;
20600: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20601: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20602: $adds{$newitem} = 1;
20603: }
20604: if ($env{'form.subcat_'.$item} ne '') {
20605: my $newcat = $env{'form.subcat_'.$item};
20606: my $newdepth = $depth+1;
20607: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20608: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20609: $adds{$newitem} = 1;
20610: }
20611: }
20612: }
20613: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20614: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20615: my $newitem = 'instcode::0';
1.57 raeburn 20616: if ($cathash->{$newitem} eq '') {
20617: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20618: $adds{$newitem} = 1;
20619: }
20620: } else {
20621: my $newitem = 'instcode::0';
1.57 raeburn 20622: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20623: $adds{$newitem} = 1;
20624: }
20625: }
1.120 raeburn 20626: if ($env{'form.communities'} eq '1') {
20627: if (ref($cathash) eq 'HASH') {
20628: my $newitem = 'communities::0';
20629: if ($cathash->{$newitem} eq '') {
20630: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20631: $adds{$newitem} = 1;
20632: }
20633: } else {
20634: my $newitem = 'communities::0';
20635: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20636: $adds{$newitem} = 1;
20637: }
20638: }
1.272 raeburn 20639: if ($env{'form.placement'} eq '1') {
20640: if (ref($cathash) eq 'HASH') {
20641: my $newitem = 'placement::0';
20642: if ($cathash->{$newitem} eq '') {
20643: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20644: $adds{$newitem} = 1;
20645: }
20646: } else {
20647: my $newitem = 'placement::0';
20648: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20649: $adds{$newitem} = 1;
20650: }
20651: }
1.48 raeburn 20652: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20653: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20654: ($env{'form.addcategory_name'} ne 'communities') &&
20655: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20656: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20657: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20658: $adds{$newitem} = 1;
20659: }
1.48 raeburn 20660: }
1.57 raeburn 20661: my $putresult;
1.48 raeburn 20662: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20663: if (keys(%deletions) > 0) {
20664: foreach my $key (keys(%deletions)) {
20665: if ($predelallitems{$key} ne '') {
20666: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20667: }
20668: }
20669: }
20670: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20671: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20672: if (ref($chkcats[0]) eq 'ARRAY') {
20673: my $depth = 0;
20674: my $chg = 0;
20675: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20676: my $name = $chkcats[0][$i];
20677: my $item;
20678: if ($name eq '') {
20679: $chg ++;
20680: } else {
20681: $item = &escape($name).'::0';
20682: if ($chg) {
1.57 raeburn 20683: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20684: }
20685: $depth ++;
1.57 raeburn 20686: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20687: $depth --;
20688: }
20689: }
20690: }
1.57 raeburn 20691: }
20692: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20693: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20694: if ($putresult eq 'ok') {
1.57 raeburn 20695: my %title = (
1.120 raeburn 20696: togglecats => 'Show/Hide a course in catalog',
20697: categorize => 'Assign a category to a course',
20698: togglecatscomm => 'Show/Hide a community in catalog',
20699: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20700: );
20701: my %level = (
1.120 raeburn 20702: dom => 'set in Domain ("Modify Course/Community")',
20703: crs => 'set in Course ("Course Configuration")',
20704: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20705: none => 'No catalog',
20706: std => 'Standard catalog',
20707: domonly => 'Domain-only catalog',
20708: codesrch => 'Code search form',
1.57 raeburn 20709: );
1.48 raeburn 20710: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20711: if ($changes{'togglecats'}) {
20712: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20713: }
20714: if ($changes{'categorize'}) {
20715: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20716: }
1.120 raeburn 20717: if ($changes{'togglecatscomm'}) {
20718: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20719: }
20720: if ($changes{'categorizecomm'}) {
20721: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20722: }
1.238 raeburn 20723: if ($changes{'unauth'}) {
20724: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20725: }
20726: if ($changes{'auth'}) {
20727: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20728: }
1.57 raeburn 20729: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20730: my $cathash;
20731: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20732: $cathash = $domconfig{'coursecategories'}{'cats'};
20733: } else {
20734: $cathash = {};
20735: }
20736: my (@cats,@trails,%allitems);
20737: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20738: if (keys(%deletions) > 0) {
20739: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20740: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20741: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20742: }
20743: $resulttext .= '</ul></li>';
20744: }
20745: if (keys(%reorderings) > 0) {
20746: my %sort_by_trail;
20747: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20748: foreach my $key (keys(%reorderings)) {
20749: if ($allitems{$key} ne '') {
20750: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20751: }
1.48 raeburn 20752: }
1.57 raeburn 20753: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20754: $resulttext .= '<li>'.$trails[$trail].'</li>';
20755: }
20756: $resulttext .= '</ul></li>';
1.48 raeburn 20757: }
1.57 raeburn 20758: if (keys(%adds) > 0) {
20759: my %sort_by_trail;
20760: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20761: foreach my $key (keys(%adds)) {
20762: if ($allitems{$key} ne '') {
20763: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20764: }
20765: }
20766: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20767: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20768: }
1.57 raeburn 20769: $resulttext .= '</ul></li>';
1.48 raeburn 20770: }
1.364 raeburn 20771: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20772: if (ref($lastactref) eq 'HASH') {
20773: $lastactref->{'cats'} = 1;
20774: }
1.48 raeburn 20775: }
20776: $resulttext .= '</ul>';
1.239 raeburn 20777: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20778: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20779: if ($changes{'auth'}) {
20780: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20781: }
20782: if ($changes{'unauth'}) {
20783: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20784: }
20785: my $cachetime = 24*60*60;
20786: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20787: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20788: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20789: }
20790: }
1.48 raeburn 20791: } else {
20792: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20793: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20794: }
20795: } else {
1.120 raeburn 20796: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20797: }
20798: return $resulttext;
20799: }
20800:
1.69 raeburn 20801: sub modify_serverstatuses {
20802: my ($dom,%domconfig) = @_;
20803: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20804: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20805: %currserverstatus = %{$domconfig{'serverstatuses'}};
20806: }
20807: my @pages = &serverstatus_pages();
20808: foreach my $type (@pages) {
20809: $newserverstatus{$type}{'namedusers'} = '';
20810: $newserverstatus{$type}{'machines'} = '';
20811: if (defined($env{'form.'.$type.'_namedusers'})) {
20812: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20813: my @okusers;
20814: foreach my $user (@users) {
20815: my ($uname,$udom) = split(/:/,$user);
20816: if (($udom =~ /^$match_domain$/) &&
20817: (&Apache::lonnet::domain($udom)) &&
20818: ($uname =~ /^$match_username$/)) {
20819: if (!grep(/^\Q$user\E/,@okusers)) {
20820: push(@okusers,$user);
20821: }
20822: }
20823: }
20824: if (@okusers > 0) {
20825: @okusers = sort(@okusers);
20826: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20827: }
20828: }
20829: if (defined($env{'form.'.$type.'_machines'})) {
20830: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20831: my @okmachines;
20832: foreach my $ip (@machines) {
20833: my @parts = split(/\./,$ip);
20834: next if (@parts < 4);
20835: my $badip = 0;
20836: for (my $i=0; $i<4; $i++) {
20837: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20838: $badip = 1;
20839: last;
20840: }
20841: }
20842: if (!$badip) {
20843: push(@okmachines,$ip);
20844: }
20845: }
20846: @okmachines = sort(@okmachines);
20847: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20848: }
20849: }
20850: my %serverstatushash = (
20851: serverstatuses => \%newserverstatus,
20852: );
20853: foreach my $type (@pages) {
1.83 raeburn 20854: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20855: my (@current,@new);
1.83 raeburn 20856: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20857: if ($currserverstatus{$type}{$setting} ne '') {
20858: @current = split(/,/,$currserverstatus{$type}{$setting});
20859: }
20860: }
20861: if ($newserverstatus{$type}{$setting} ne '') {
20862: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20863: }
20864: if (@current > 0) {
20865: if (@new > 0) {
20866: foreach my $item (@current) {
20867: if (!grep(/^\Q$item\E$/,@new)) {
20868: $changes{$type}{$setting} = 1;
1.82 raeburn 20869: last;
20870: }
20871: }
1.84 raeburn 20872: foreach my $item (@new) {
20873: if (!grep(/^\Q$item\E$/,@current)) {
20874: $changes{$type}{$setting} = 1;
20875: last;
1.82 raeburn 20876: }
20877: }
20878: } else {
1.83 raeburn 20879: $changes{$type}{$setting} = 1;
1.69 raeburn 20880: }
1.83 raeburn 20881: } elsif (@new > 0) {
20882: $changes{$type}{$setting} = 1;
1.69 raeburn 20883: }
20884: }
20885: }
20886: if (keys(%changes) > 0) {
1.81 raeburn 20887: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20888: my $putresult = &Apache::lonnet::put_dom('configuration',
20889: \%serverstatushash,$dom);
20890: if ($putresult eq 'ok') {
20891: $resulttext .= &mt('Changes made:').'<ul>';
20892: foreach my $type (@pages) {
1.84 raeburn 20893: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20894: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20895: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20896: if ($newserverstatus{$type}{'namedusers'} eq '') {
20897: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20898: } else {
20899: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20900: }
1.84 raeburn 20901: }
20902: if ($changes{$type}{'machines'}) {
1.69 raeburn 20903: if ($newserverstatus{$type}{'machines'} eq '') {
20904: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20905: } else {
20906: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20907: }
20908:
20909: }
20910: $resulttext .= '</ul></li>';
20911: }
20912: }
20913: $resulttext .= '</ul>';
20914: } else {
20915: $resulttext = '<span class="LC_error">'.
20916: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20917:
20918: }
20919: } else {
20920: $resulttext = &mt('No changes made to access to server status pages');
20921: }
20922: return $resulttext;
20923: }
20924:
1.118 jms 20925: sub modify_helpsettings {
1.285 raeburn 20926: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20927: my ($resulttext,$errors,%changes,%helphash);
20928: my %defaultchecked = ('submitbugs' => 'on');
20929: my @offon = ('off','on');
1.118 jms 20930: my @toggles = ('submitbugs');
1.285 raeburn 20931: my %current = ('submitbugs' => '',
20932: 'adhoc' => {},
20933: );
1.118 jms 20934: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20935: %current = %{$domconfig{'helpsettings'}};
20936: }
1.285 raeburn 20937: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20938: foreach my $item (@toggles) {
20939: if ($defaultchecked{$item} eq 'on') {
20940: if ($current{$item} eq '') {
20941: if ($env{'form.'.$item} eq '0') {
20942: $changes{$item} = 1;
20943: }
20944: } elsif ($current{$item} ne $env{'form.'.$item}) {
20945: $changes{$item} = 1;
20946: }
20947: } elsif ($defaultchecked{$item} eq 'off') {
20948: if ($current{$item} eq '') {
20949: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20950: $changes{$item} = 1;
20951: }
1.282 raeburn 20952: } elsif ($current{$item} ne $env{'form.'.$item}) {
20953: $changes{$item} = 1;
20954: }
20955: }
20956: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20957: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20958: }
20959: }
1.285 raeburn 20960: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20961: my $confname = $dom.'-domainconfig';
20962: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20963: my (@allpos,%newsettings,%changedprivs,$newrole);
20964: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20965: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20966: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20967: my %lt = &Apache::lonlocal::texthash(
20968: s => 'system',
20969: d => 'domain',
20970: order => 'Display order',
20971: access => 'Role usage',
1.291 raeburn 20972: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20973: dh => 'All with domain helpdesk role',
20974: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20975: none => 'None',
20976: status => 'Determined based on institutional status',
20977: inc => 'Include all, but exclude specific personnel',
20978: exc => 'Exclude all, but include specific personnel',
20979: );
20980: for (my $num=0; $num<=$maxnum; $num++) {
20981: my ($prefix,$identifier,$rolename,%curr);
20982: if ($num == $maxnum) {
20983: next unless ($env{'form.newcusthelp'} == $maxnum);
20984: $identifier = 'custhelp'.$num;
20985: $prefix = 'helproles_'.$num;
20986: $rolename = $env{'form.custhelpname'.$num};
20987: $rolename=~s/[^A-Za-z0-9]//gs;
20988: next if ($rolename eq '');
20989: next if (exists($existing{'rolesdef_'.$rolename}));
20990: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20991: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20992: $newprivs{'c'},$confname,$dom);
20993: if ($result ne 'ok') {
20994: $errors .= '<li><span class="LC_error">'.
20995: &mt('An error occurred storing the new custom role: [_1]',
20996: $result).'</span></li>';
20997: next;
20998: } else {
20999: $changedprivs{$rolename} = \%newprivs;
21000: $newrole = $rolename;
21001: }
21002: } else {
21003: $prefix = 'helproles_'.$num;
21004: $rolename = $env{'form.'.$prefix};
21005: next if ($rolename eq '');
21006: next unless (exists($existing{'rolesdef_'.$rolename}));
21007: $identifier = 'custhelp'.$num;
21008: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21009: my %currprivs;
1.289 raeburn 21010: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 21011: split(/\_/,$existing{'rolesdef_'.$rolename});
21012: foreach my $level ('c','d','s') {
21013: if ($newprivs{$level} ne $currprivs{$level}) {
21014: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21015: $newprivs{'c'},$confname,$dom);
21016: if ($result ne 'ok') {
21017: $errors .= '<li><span class="LC_error">'.
21018: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
21019: $rolename,$result).'</span></li>';
21020: } else {
21021: $changedprivs{$rolename} = \%newprivs;
21022: }
21023: last;
21024: }
21025: }
21026: if (ref($current{'adhoc'}) eq 'HASH') {
21027: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21028: %curr = %{$current{'adhoc'}{$rolename}};
21029: }
21030: }
21031: }
21032: my $newpos = $env{'form.'.$prefix.'_pos'};
21033: $newpos =~ s/\D+//g;
21034: $allpos[$newpos] = $rolename;
21035: my $newdesc = $env{'form.'.$prefix.'_desc'};
21036: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
21037: if ($curr{'desc'}) {
21038: if ($curr{'desc'} ne $newdesc) {
21039: $changes{'customrole'}{$rolename}{'desc'} = 1;
21040: $newsettings{$rolename}{'desc'} = $newdesc;
21041: }
21042: } elsif ($newdesc ne '') {
21043: $changes{'customrole'}{$rolename}{'desc'} = 1;
21044: $newsettings{$rolename}{'desc'} = $newdesc;
21045: }
21046: my $access = $env{'form.'.$prefix.'_access'};
21047: if (grep(/^\Q$access\E$/,@accesstypes)) {
21048: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
21049: if ($access eq 'status') {
21050: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
21051: if (scalar(@statuses) == 0) {
1.289 raeburn 21052: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 21053: } else {
21054: my (@shownstatus,$numtypes);
21055: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21056: if (ref($types) eq 'ARRAY') {
21057: $numtypes = scalar(@{$types});
21058: foreach my $type (sort(@statuses)) {
21059: if ($type eq 'default') {
21060: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21061: } elsif (grep(/^\Q$type\E$/,@{$types})) {
21062: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21063: push(@shownstatus,$usertypes->{$type});
21064: }
21065: }
21066: }
21067: if (grep(/^default$/,@statuses)) {
21068: push(@shownstatus,$othertitle);
21069: }
21070: if (scalar(@shownstatus) == 1+$numtypes) {
21071: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
21072: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
21073: } else {
21074: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
21075: if (ref($curr{'status'}) eq 'ARRAY') {
21076: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21077: if (@diffs) {
21078: $changes{'customrole'}{$rolename}{$access} = 1;
21079: }
21080: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21081: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 21082: }
1.166 raeburn 21083: }
21084: }
1.285 raeburn 21085: } elsif (($access eq 'inc') || ($access eq 'exc')) {
21086: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
21087: my @newspecstaff;
21088: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21089: foreach my $person (sort(@personnel)) {
21090: if ($domhelpdesk{$person}) {
21091: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
21092: }
21093: }
21094: if (ref($curr{$access}) eq 'ARRAY') {
21095: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21096: if (@diffs) {
21097: $changes{'customrole'}{$rolename}{$access} = 1;
21098: }
21099: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21100: $changes{'customrole'}{$rolename}{$access} = 1;
21101: }
21102: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21103: my ($uname,$udom) = split(/:/,$person);
21104: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
21105: }
21106: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 21107: }
1.285 raeburn 21108: } else {
21109: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
21110: }
21111: unless ($curr{'access'} eq $access) {
21112: $changes{'customrole'}{$rolename}{'access'} = 1;
21113: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 21114: }
21115: }
1.285 raeburn 21116: if (@allpos > 0) {
21117: my $idx = 0;
21118: foreach my $rolename (@allpos) {
21119: if ($rolename ne '') {
21120: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
21121: if (ref($current{'adhoc'}) eq 'HASH') {
21122: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21123: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
21124: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 21125: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 21126: }
21127: }
1.282 raeburn 21128: }
1.285 raeburn 21129: $idx ++;
1.166 raeburn 21130: }
21131: }
1.118 jms 21132: }
1.123 jms 21133: my $putresult;
21134: if (keys(%changes) > 0) {
1.166 raeburn 21135: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21136: if ($putresult eq 'ok') {
1.285 raeburn 21137: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21138: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21139: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21140: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21141: }
21142: }
21143: my $cachetime = 24*60*60;
21144: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21145: if (ref($lastactref) eq 'HASH') {
21146: $lastactref->{'domdefaults'} = 1;
21147: }
21148: } else {
21149: $errors .= '<li><span class="LC_error">'.
21150: &mt('An error occurred storing the settings: [_1]',
21151: $putresult).'</span></li>';
21152: }
21153: }
21154: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21155: $resulttext = &mt('Changes made:').'<ul>';
21156: my (%shownprivs,@levelorder);
21157: @levelorder = ('c','d','s');
21158: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21159: foreach my $item (sort(keys(%changes))) {
21160: if ($item eq 'submitbugs') {
21161: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21162: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21163: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21164: } elsif ($item eq 'customrole') {
21165: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21166: my @keyorder = ('order','desc','access','status','exc','inc');
21167: my %keytext = &Apache::lonlocal::texthash(
21168: order => 'Order',
21169: desc => 'Role description',
21170: access => 'Role usage',
1.300 droeschl 21171: status => 'Allowed institutional types',
1.285 raeburn 21172: exc => 'Allowed personnel',
21173: inc => 'Disallowed personnel',
21174: );
1.282 raeburn 21175: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21176: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21177: if ($role eq $newrole) {
21178: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21179: $role).'<ul>';
21180: } else {
21181: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21182: $role).'<ul>';
21183: }
21184: foreach my $key (@keyorder) {
21185: if ($changes{'customrole'}{$role}{$key}) {
21186: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21187: $keytext{$key},$newsettings{$role}{$key}).
21188: '</li>';
21189: }
21190: }
21191: if (ref($changedprivs{$role}) eq 'HASH') {
21192: $shownprivs{$role} = 1;
21193: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21194: foreach my $level (@levelorder) {
21195: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21196: next if ($item eq '');
21197: my ($priv) = split(/\&/,$item,2);
21198: if (&Apache::lonnet::plaintext($priv)) {
21199: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21200: unless ($level eq 'c') {
21201: $resulttext .= ' ('.$lt{$level}.')';
21202: }
21203: $resulttext .= '</li>';
21204: }
21205: }
21206: }
21207: $resulttext .= '</ul>';
21208: }
21209: $resulttext .= '</ul></li>';
21210: }
21211: }
21212: }
21213: }
21214: }
21215: }
21216: if (keys(%changedprivs)) {
21217: foreach my $role (sort(keys(%changedprivs))) {
21218: unless ($shownprivs{$role}) {
21219: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21220: $role).'<ul>'.
21221: '<li>'.&mt('Privileges set to :').'<ul>';
21222: foreach my $level (@levelorder) {
21223: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21224: next if ($item eq '');
21225: my ($priv) = split(/\&/,$item,2);
21226: if (&Apache::lonnet::plaintext($priv)) {
21227: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21228: unless ($level eq 'c') {
21229: $resulttext .= ' ('.$lt{$level}.')';
21230: }
21231: $resulttext .= '</li>';
21232: }
1.282 raeburn 21233: }
21234: }
1.285 raeburn 21235: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21236: }
21237: }
21238: }
1.285 raeburn 21239: $resulttext .= '</ul>';
21240: } else {
21241: $resulttext = &mt('No changes made to help settings');
1.118 jms 21242: }
21243: if ($errors) {
1.168 raeburn 21244: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21245: $errors.'</ul>';
1.118 jms 21246: }
21247: return $resulttext;
21248: }
21249:
1.121 raeburn 21250: sub modify_coursedefaults {
1.212 raeburn 21251: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21252: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21253: my %defaultchecked = (
21254: 'canuse_pdfforms' => 'off',
21255: 'uselcmath' => 'on',
1.398 raeburn 21256: 'usejsme' => 'on',
21257: 'inline_chem' => 'on',
1.404 raeburn 21258: 'ltiauth' => 'off',
1.257 raeburn 21259: );
1.404 raeburn 21260: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21261: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21262: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21263: 'coursequota_official','coursequota_unofficial','coursequota_community',
21264: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21265: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21266: 'mysqltables_placement');
1.271 raeburn 21267: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21268: my %staticdefaults = (
21269: anonsurvey_threshold => 10,
21270: uploadquota => 500,
1.428 raeburn 21271: coursequota => 20,
1.257 raeburn 21272: postsubmit => 60,
1.276 raeburn 21273: mysqltables => 172800,
1.422 raeburn 21274: domexttool => 1,
1.432 raeburn 21275: crsauthor => 1,
1.438 raeburn 21276: crseditors => ['edit','xml'],
1.198 raeburn 21277: );
1.314 raeburn 21278: my %texoptions = (
21279: MathJax => 'MathJax',
21280: mimetex => &mt('Convert to Images'),
21281: tth => &mt('TeX to HTML'),
21282: );
1.438 raeburn 21283:
21284: my @editors = ('edit','xml','daxe');
21285: my %editornames = &crseditor_titles();
21286:
1.121 raeburn 21287: $defaultshash{'coursedefaults'} = {};
21288:
21289: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21290: if ($domconfig{'coursedefaults'} eq '') {
21291: $domconfig{'coursedefaults'} = {};
21292: }
21293: }
21294:
21295: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21296: foreach my $item (@toggles) {
21297: if ($defaultchecked{$item} eq 'on') {
21298: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21299: ($env{'form.'.$item} eq '0')) {
21300: $changes{$item} = 1;
1.192 raeburn 21301: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21302: $changes{$item} = 1;
21303: }
21304: } elsif ($defaultchecked{$item} eq 'off') {
21305: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21306: ($env{'form.'.$item} eq '1')) {
21307: $changes{$item} = 1;
21308: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21309: $changes{$item} = 1;
21310: }
21311: }
21312: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21313: }
1.198 raeburn 21314: foreach my $item (@numbers) {
21315: my ($currdef,$newdef);
1.208 raeburn 21316: $newdef = $env{'form.'.$item};
1.198 raeburn 21317: if ($item eq 'anonsurvey_threshold') {
21318: $currdef = $domconfig{'coursedefaults'}{$item};
21319: $newdef =~ s/\D//g;
21320: if ($newdef eq '' || $newdef < 1) {
21321: $newdef = 1;
21322: }
21323: $defaultshash{'coursedefaults'}{$item} = $newdef;
21324: } else {
1.428 raeburn 21325: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21326: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21327: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21328: }
21329: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21330: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21331: }
21332: if ($currdef ne $newdef) {
21333: if ($item eq 'anonsurvey_threshold') {
21334: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21335: $changes{$item} = 1;
21336: }
1.428 raeburn 21337: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21338: my $setting = $1;
1.276 raeburn 21339: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21340: $changes{$setting} = 1;
1.198 raeburn 21341: }
21342: }
1.139 raeburn 21343: }
21344: }
1.314 raeburn 21345: my $texengine;
21346: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21347: $texengine = $env{'form.texengine'};
1.349 raeburn 21348: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21349: if ($currdef eq '') {
21350: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21351: $changes{'texengine'} = 1;
21352: }
1.349 raeburn 21353: } elsif ($currdef ne $texengine) {
1.314 raeburn 21354: $changes{'texengine'} = 1;
21355: }
21356: }
21357: if ($texengine ne '') {
21358: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21359: }
1.264 raeburn 21360: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21361: my @currclonecode;
21362: if (ref($currclone) eq 'HASH') {
21363: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21364: @currclonecode = @{$currclone->{'instcode'}};
21365: }
21366: }
21367: my $newclone;
1.289 raeburn 21368: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21369: $newclone = $env{'form.canclone'};
21370: }
21371: if ($newclone eq 'instcode') {
21372: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21373: my (%codedefaults,@code_order,@clonecode);
21374: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21375: \@code_order);
21376: foreach my $item (@code_order) {
21377: if (grep(/^\Q$item\E$/,@newcodes)) {
21378: push(@clonecode,$item);
21379: }
21380: }
21381: if (@clonecode) {
21382: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21383: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21384: if (@diffs) {
21385: $changes{'canclone'} = 1;
21386: }
21387: } else {
21388: $newclone eq '';
21389: }
21390: } elsif ($newclone ne '') {
1.289 raeburn 21391: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21392: }
1.264 raeburn 21393: if ($newclone ne $currclone) {
21394: $changes{'canclone'} = 1;
21395: }
1.257 raeburn 21396: my %credits;
21397: foreach my $type (@types) {
21398: unless ($type eq 'community') {
21399: $credits{$type} = $env{'form.'.$type.'_credits'};
21400: $credits{$type} =~ s/[^\d.]+//g;
21401: }
21402: }
21403: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21404: ($env{'form.coursecredits'} eq '1')) {
21405: $changes{'coursecredits'} = 1;
21406: foreach my $type (keys(%credits)) {
21407: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21408: }
21409: } else {
1.289 raeburn 21410: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21411: foreach my $type (@types) {
21412: unless ($type eq 'community') {
1.289 raeburn 21413: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21414: $changes{'coursecredits'} = 1;
21415: }
21416: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21417: }
21418: }
21419: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21420: foreach my $type (@types) {
21421: unless ($type eq 'community') {
21422: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21423: $changes{'coursecredits'} = 1;
21424: last;
21425: }
21426: }
21427: }
21428: }
21429: }
21430: if ($env{'form.postsubmit'} eq '1') {
21431: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21432: my %currtimeout;
21433: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21434: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21435: $changes{'postsubmit'} = 1;
21436: }
21437: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21438: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21439: }
21440: } else {
21441: $changes{'postsubmit'} = 1;
21442: }
21443: foreach my $type (@types) {
21444: my $timeout = $env{'form.'.$type.'_timeout'};
21445: $timeout =~ s/\D//g;
21446: if ($timeout == $staticdefaults{'postsubmit'}) {
21447: $timeout = '';
21448: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21449: $timeout = '0';
21450: }
21451: unless ($timeout eq '') {
21452: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21453: }
21454: if (exists($currtimeout{$type})) {
21455: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21456: $changes{'postsubmit'} = 1;
1.257 raeburn 21457: }
21458: } elsif ($timeout ne '') {
21459: $changes{'postsubmit'} = 1;
21460: }
21461: }
21462: } else {
21463: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21464: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21465: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21466: $changes{'postsubmit'} = 1;
21467: }
21468: } else {
21469: $changes{'postsubmit'} = 1;
21470: }
1.192 raeburn 21471: }
1.438 raeburn 21472: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor,
21473: %posscrseditors);
1.422 raeburn 21474: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21475: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 raeburn 21476: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.438 raeburn 21477: map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
1.422 raeburn 21478: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21479: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21480: } else {
21481: foreach my $type (@types) {
21482: if ($staticdefaults{'domexttool'}) {
21483: $olddomexttool{$type} = 1;
21484: } else {
21485: $olddomexttool{$type} = 0;
21486: }
21487: }
21488: }
21489: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21490: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21491: } else {
21492: foreach my $type (@types) {
21493: if ($staticdefaults{'exttool'}) {
21494: $oldexttool{$type} = 1;
21495: } else {
21496: $oldexttool{$type} = 0;
21497: }
21498: }
21499: }
1.432 raeburn 21500: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21501: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
21502: } else {
21503: foreach my $type (@types) {
21504: if ($staticdefaults{'crsauthor'}) {
21505: $oldcrsauthor{$type} = 1;
21506: } else {
21507: $oldcrsauthor{$type} = 0;
21508: }
21509: }
21510: }
1.438 raeburn 21511: my @newcrseditors = ();
21512: foreach my $editor (@editors) {
21513: if ($posscrseditors{$editor}) {
21514: push(@newcrseditors,$editor);
21515: }
21516: }
21517: if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21518: my @diffs =
21519: &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
21520: \@newcrseditors);
21521: if (@diffs) {
21522: $changes{'crseditors'} = 1;
21523: }
21524: } else {
21525: my @diffs =
21526: &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
21527: \@newcrseditors);
21528: unless (@diffs == 0) {
21529: $changes{'crseditors'} = 1;
21530: }
21531: }
1.422 raeburn 21532: foreach my $type (@types) {
21533: unless ($newdomexttool{$type}) {
21534: $newdomexttool{$type} = 0;
21535: }
21536: unless ($newexttool{$type}) {
21537: $newexttool{$type} = 0;
21538: }
1.432 raeburn 21539: unless ($newcrsauthor{$type}) {
21540: $newcrsauthor{$type} = 0;
21541: }
1.422 raeburn 21542: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21543: $changes{'domexttool'} = 1;
21544: }
21545: if ($newexttool{$type} != $oldexttool{$type}) {
21546: $changes{'exttool'} = 1;
21547: }
1.432 raeburn 21548: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
21549: $changes{'crsauthor'} = 1;
21550: }
1.422 raeburn 21551: }
21552: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21553: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 raeburn 21554: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.438 raeburn 21555: $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 21556: }
21557: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21558: $dom);
21559: if ($putresult eq 'ok') {
21560: if (keys(%changes) > 0) {
1.213 raeburn 21561: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21562: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21563: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21564: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21565: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 raeburn 21566: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21567: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21568: 'ltiauth') {
1.257 raeburn 21569: if ($changes{$item}) {
21570: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21571: }
1.289 raeburn 21572: }
1.192 raeburn 21573: if ($changes{'coursecredits'}) {
21574: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21575: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21576: $domdefaults{$type.'credits'} =
21577: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21578: }
21579: }
21580: }
21581: if ($changes{'postsubmit'}) {
21582: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21583: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21584: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21585: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21586: $domdefaults{$type.'postsubtimeout'} =
21587: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21588: }
21589: }
1.192 raeburn 21590: }
21591: }
1.198 raeburn 21592: if ($changes{'uploadquota'}) {
21593: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21594: foreach my $type (@types) {
21595: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21596: }
21597: }
21598: }
1.428 raeburn 21599: if ($changes{'coursequota'}) {
21600: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21601: foreach my $type (@types) {
21602: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21603: }
21604: }
21605: }
1.264 raeburn 21606: if ($changes{'canclone'}) {
21607: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21608: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21609: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21610: if (@clonecodes) {
21611: $domdefaults{'canclone'} = join('+',@clonecodes);
21612: }
21613: }
21614: } else {
21615: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21616: }
21617: }
1.422 raeburn 21618: if ($changes{'domexttool'}) {
21619: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21620: foreach my $type (@types) {
21621: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21622: }
21623: }
21624: }
21625: if ($changes{'exttool'}) {
21626: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21627: foreach my $type (@types) {
21628: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21629: }
21630: }
21631: }
1.432 raeburn 21632: if ($changes{'crsauthor'}) {
21633: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21634: foreach my $type (@types) {
21635: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
21636: }
21637: }
21638: }
1.438 raeburn 21639: if ($changes{'crseditors'}) {
21640: if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21641: $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
21642: }
21643: }
1.121 raeburn 21644: my $cachetime = 24*60*60;
21645: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21646: if (ref($lastactref) eq 'HASH') {
21647: $lastactref->{'domdefaults'} = 1;
21648: }
1.121 raeburn 21649: }
21650: $resulttext = &mt('Changes made:').'<ul>';
21651: foreach my $item (sort(keys(%changes))) {
21652: if ($item eq 'canuse_pdfforms') {
21653: if ($env{'form.'.$item} eq '1') {
21654: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21655: } else {
21656: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21657: }
1.257 raeburn 21658: } elsif ($item eq 'uselcmath') {
21659: if ($env{'form.'.$item} eq '1') {
21660: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21661: } else {
21662: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21663: }
21664: } elsif ($item eq 'usejsme') {
21665: if ($env{'form.'.$item} eq '1') {
21666: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21667: } else {
1.289 raeburn 21668: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21669: }
1.398 raeburn 21670: } elsif ($item eq 'inline_chem') {
21671: if ($env{'form.'.$item} eq '1') {
21672: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21673: } else {
21674: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21675: }
1.314 raeburn 21676: } elsif ($item eq 'texengine') {
21677: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21678: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21679: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21680: }
1.139 raeburn 21681: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21682: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21683: } elsif ($item eq 'uploadquota') {
21684: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21685: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21686: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21687: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21688: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21689: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21690: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21691: '</ul>'.
21692: '</li>';
21693: } else {
21694: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21695: }
1.428 raeburn 21696: } elsif ($item eq 'coursequota') {
21697: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21698: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21699: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21700: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21701: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21702: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21703: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21704: '</ul>'.
21705: '</li>';
21706: } else {
21707: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21708: }
1.276 raeburn 21709: } elsif ($item eq 'mysqltables') {
21710: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21711: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21712: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21713: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21714: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21715: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21716: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21717: '</ul>'.
21718: '</li>';
21719: } else {
21720: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21721: }
1.257 raeburn 21722: } elsif ($item eq 'postsubmit') {
21723: if ($domdefaults{'postsubmit'} eq 'off') {
21724: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21725: } else {
21726: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21727: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21728: $resulttext .= &mt('durations:').'<ul>';
21729: foreach my $type (@types) {
21730: $resulttext .= '<li>';
21731: my $timeout;
21732: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21733: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21734: }
21735: my $display;
21736: if ($timeout eq '0') {
21737: $display = &mt('unlimited');
21738: } elsif ($timeout eq '') {
21739: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21740: } else {
21741: $display = &mt('[quant,_1,second]',$timeout);
21742: }
21743: if ($type eq 'community') {
21744: $resulttext .= &mt('Communities');
21745: } elsif ($type eq 'official') {
21746: $resulttext .= &mt('Official courses');
21747: } elsif ($type eq 'unofficial') {
21748: $resulttext .= &mt('Unofficial courses');
21749: } elsif ($type eq 'textbook') {
21750: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21751: } elsif ($type eq 'placement') {
21752: $resulttext .= &mt('Placement tests');
1.257 raeburn 21753: }
21754: $resulttext .= ' -- '.$display.'</li>';
21755: }
21756: $resulttext .= '</ul>';
21757: }
1.289 raeburn 21758: $resulttext .= '</li>';
1.257 raeburn 21759: }
1.192 raeburn 21760: } elsif ($item eq 'coursecredits') {
21761: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21762: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21763: ($domdefaults{'unofficialcredits'} eq '') &&
21764: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21765: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21766: } else {
21767: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21768: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21769: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21770: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21771: '</ul>'.
21772: '</li>';
21773: }
21774: } else {
21775: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21776: }
1.264 raeburn 21777: } elsif ($item eq 'canclone') {
21778: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21779: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21780: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21781: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21782: }
21783: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21784: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21785: } else {
1.289 raeburn 21786: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21787: }
1.404 raeburn 21788: } elsif ($item eq 'ltiauth') {
21789: if ($env{'form.'.$item} eq '1') {
21790: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21791: } else {
21792: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21793: }
1.432 raeburn 21794: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21795: my @noyes = (&mt('no'),&mt('yes'));
1.432 raeburn 21796: my %status = (
21797: domexttool => {
21798: ishash => &mt('External Tools defined in the domain may be used as follows:'),
21799: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
21800: },
21801: exttool => {
21802: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
21803: default => &mt('External Tools can not be defined in any course types, by default'),
21804: },
21805: crsauthor => {
21806: ishash => &mt('Standard Problems can be created within course containers as follows:'),
21807: default => &mt('Standard Problems can be created within any course type, by default'),
21808: },
21809: );
21810:
21811: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
21812: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
21813: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
21814: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
21815: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
21816: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
21817: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21818: '</ul>'.
21819: '</li>';
21820: } else {
1.432 raeburn 21821: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21822: }
1.438 raeburn 21823: } elsif ($item eq 'crseditors') {
21824: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
21825: my $shown;
21826: if (@{$defaultshash{'coursedefaults'}{$item}}) {
21827: $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
21828: } else {
21829: $shown = &mt('None');
21830: }
21831: $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
21832: }
1.140 raeburn 21833: }
1.121 raeburn 21834: }
21835: $resulttext .= '</ul>';
21836: } else {
21837: $resulttext = &mt('No changes made to course defaults');
21838: }
21839: } else {
21840: $resulttext = '<span class="LC_error">'.
21841: &mt('An error occurred: [_1]',$putresult).'</span>';
21842: }
21843: return $resulttext;
21844: }
21845:
1.231 raeburn 21846: sub modify_selfenrollment {
21847: my ($dom,$lastactref,%domconfig) = @_;
21848: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21849: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21850: my %titles = &tool_titles();
1.232 raeburn 21851: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21852: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21853: $ordered{'default'} = ['types','registered','approval','limit'];
21854:
21855: my (%roles,%shown,%toplevel);
21856: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21857:
21858: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21859: if ($domconfig{'selfenrollment'} eq '') {
21860: $domconfig{'selfenrollment'} = {};
21861: }
21862: }
21863: %toplevel = (
21864: admin => 'Configuration Rights',
21865: default => 'Default settings',
21866: validation => 'Validation of self-enrollment requests',
21867: );
1.233 raeburn 21868: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21869:
21870: if (ref($ordered{'admin'}) eq 'ARRAY') {
21871: foreach my $item (@{$ordered{'admin'}}) {
21872: foreach my $type (@types) {
21873: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21874: $selfenrollhash{'admin'}{$type}{$item} = 1;
21875: } else {
21876: $selfenrollhash{'admin'}{$type}{$item} = 0;
21877: }
21878: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21879: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21880: if ($selfenrollhash{'admin'}{$type}{$item} ne
21881: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21882: push(@{$changes{'admin'}{$type}},$item);
21883: }
21884: } else {
21885: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21886: push(@{$changes{'admin'}{$type}},$item);
21887: }
21888: }
21889: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21890: push(@{$changes{'admin'}{$type}},$item);
21891: }
21892: }
21893: }
21894: }
21895:
21896: foreach my $item (@{$ordered{'default'}}) {
21897: foreach my $type (@types) {
21898: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21899: if ($item eq 'types') {
21900: unless (($value eq 'all') || ($value eq 'dom')) {
21901: $value = '';
21902: }
21903: } elsif ($item eq 'registered') {
21904: unless ($value eq '1') {
21905: $value = 0;
21906: }
21907: } elsif ($item eq 'approval') {
21908: unless ($value =~ /^[012]$/) {
21909: $value = 0;
21910: }
21911: } else {
21912: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21913: $value = 'none';
21914: }
21915: }
21916: $selfenrollhash{'default'}{$type}{$item} = $value;
21917: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21918: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21919: if ($selfenrollhash{'default'}{$type}{$item} ne
21920: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21921: push(@{$changes{'default'}{$type}},$item);
21922: }
21923: } else {
21924: push(@{$changes{'default'}{$type}},$item);
21925: }
21926: } else {
21927: push(@{$changes{'default'}{$type}},$item);
21928: }
21929: if ($item eq 'limit') {
21930: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21931: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21932: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21933: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21934: }
21935: } else {
21936: $selfenrollhash{'default'}{$type}{'cap'} = '';
21937: }
21938: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21939: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21940: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21941: push(@{$changes{'default'}{$type}},'cap');
21942: }
21943: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21944: push(@{$changes{'default'}{$type}},'cap');
21945: }
21946: }
21947: }
21948: }
21949:
21950: foreach my $item (@{$itemsref}) {
21951: if ($item eq 'fields') {
21952: my @changed;
21953: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21954: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21955: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21956: }
21957: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21958: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21959: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21960: $domconfig{'selfenrollment'}{'validation'}{$item});
21961: } else {
21962: @changed = @{$selfenrollhash{'validation'}{$item}};
21963: }
21964: } else {
21965: @changed = @{$selfenrollhash{'validation'}{$item}};
21966: }
21967: if (@changed) {
21968: if ($selfenrollhash{'validation'}{$item}) {
21969: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21970: } else {
21971: $changes{'validation'}{$item} = &mt('None');
21972: }
21973: }
21974: } else {
21975: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21976: if ($item eq 'markup') {
21977: if ($env{'form.selfenroll_validation_'.$item}) {
21978: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21979: }
21980: }
21981: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21982: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21983: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21984: }
21985: }
21986: }
21987: }
21988:
21989: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21990: $dom);
21991: if ($putresult eq 'ok') {
21992: if (keys(%changes) > 0) {
21993: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21994: $resulttext = &mt('Changes made:').'<ul>';
21995: foreach my $key ('admin','default','validation') {
21996: if (ref($changes{$key}) eq 'HASH') {
21997: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
21998: if ($key eq 'validation') {
21999: foreach my $item (@{$itemsref}) {
22000: if (exists($changes{$key}{$item})) {
22001: if ($item eq 'markup') {
22002: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22003: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
22004: } else {
22005: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22006: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
22007: }
22008: }
22009: }
22010: } else {
22011: foreach my $type (@types) {
22012: if ($type eq 'community') {
22013: $roles{'1'} = &mt('Community personnel');
22014: } else {
22015: $roles{'1'} = &mt('Course personnel');
22016: }
22017: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 22018: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22019: if ($key eq 'admin') {
22020: my @mgrdc = ();
22021: if (ref($ordered{$key}) eq 'ARRAY') {
22022: foreach my $item (@{$ordered{'admin'}}) {
22023: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22024: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
22025: push(@mgrdc,$item);
22026: }
22027: }
22028: }
22029: if (@mgrdc) {
22030: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
22031: } else {
22032: delete($domdefaults{$type.'selfenrolladmdc'});
22033: }
22034: }
22035: } else {
22036: if (ref($ordered{$key}) eq 'ARRAY') {
22037: foreach my $item (@{$ordered{$key}}) {
22038: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22039: $domdefaults{$type.'selfenroll'.$item} =
22040: $selfenrollhash{$key}{$type}{$item};
22041: }
22042: }
22043: }
22044: }
22045: }
1.231 raeburn 22046: $resulttext .= '<li>'.$titles{$type}.'<ul>';
22047: foreach my $item (@{$ordered{$key}}) {
22048: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22049: $resulttext .= '<li>';
22050: if ($key eq 'admin') {
22051: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
22052: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
22053: } else {
22054: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
22055: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
22056: }
22057: $resulttext .= '</li>';
22058: }
22059: }
22060: $resulttext .= '</ul></li>';
22061: }
22062: }
22063: $resulttext .= '</ul></li>';
22064: }
22065: }
1.305 raeburn 22066: }
22067: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
22068: my $cachetime = 24*60*60;
22069: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22070: if (ref($lastactref) eq 'HASH') {
22071: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 22072: }
1.231 raeburn 22073: }
22074: $resulttext .= '</ul>';
22075: } else {
22076: $resulttext = &mt('No changes made to self-enrollment settings');
22077: }
22078: } else {
22079: $resulttext = '<span class="LC_error">'.
22080: &mt('An error occurred: [_1]',$putresult).'</span>';
22081: }
22082: return $resulttext;
22083: }
22084:
1.373 raeburn 22085: sub modify_wafproxy {
22086: my ($dom,$action,$lastactref,%domconfig) = @_;
22087: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 22088: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
22089: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 22090: foreach my $server (sort(keys(%servers))) {
22091: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
22092: if ($serverhome eq $server) {
22093: my $serverdom = &Apache::lonnet::host_domain($server);
22094: if ($serverdom eq $dom) {
22095: $canset{$server} = 1;
22096: }
22097: }
22098: }
1.381 raeburn 22099: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
22100: %{$values{$dom}} = ();
22101: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
22102: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
22103: }
1.388 raeburn 22104: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
22105: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
22106: }
1.382 raeburn 22107: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 22108: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
22109: }
22110: }
1.373 raeburn 22111: my $output;
22112: if (keys(%canset)) {
22113: %{$wafproxy{'alias'}} = ();
1.388 raeburn 22114: %{$wafproxy{'saml'}} = ();
1.373 raeburn 22115: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 22116: if ($env{'form.wafproxy_'.$dom}) {
22117: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
22118: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
22119: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
22120: $changes{'alias'} = 1;
22121: }
1.388 raeburn 22122: if ($env{'form.wafproxy_alias_saml_'.$key}) {
22123: $wafproxy{'saml'}{$key} = 1;
22124: }
22125: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
22126: $changes{'saml'} = 1;
22127: }
1.381 raeburn 22128: } else {
22129: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 22130: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 22131: if ($curralias{$key}) {
22132: $changes{'alias'} = 1;
22133: }
1.388 raeburn 22134: if ($currsaml{$key}) {
22135: $changes{'saml'} = 1;
22136: }
1.373 raeburn 22137: }
22138: if ($wafproxy{'alias'}{$key} eq '') {
22139: if ($curralias{$key}) {
22140: $expirecache{$key} = 1;
22141: }
22142: delete($wafproxy{'alias'}{$key});
22143: }
1.388 raeburn 22144: if ($wafproxy{'saml'}{$key} eq '') {
22145: if ($currsaml{$key}) {
22146: $expiresaml{$key} = 1;
22147: }
22148: delete($wafproxy{'saml'}{$key});
22149: }
1.373 raeburn 22150: }
22151: unless (keys(%{$wafproxy{'alias'}})) {
22152: delete($wafproxy{'alias'});
22153: }
1.388 raeburn 22154: unless (keys(%{$wafproxy{'saml'}})) {
22155: delete($wafproxy{'saml'});
22156: }
22157: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 22158: my %warn = (
22159: trusted => 'trusted IP range(s)',
1.381 raeburn 22160: vpnint => 'internal IP range(s) for VPN sessions(s)',
22161: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 22162: );
1.382 raeburn 22163: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22164: my $possible = $env{'form.wafproxy_'.$item};
22165: $possible =~ s/^\s+|\s+$//g;
22166: if ($possible ne '') {
1.381 raeburn 22167: if ($item eq 'remoteip') {
22168: if ($possible =~ /^[mhn]$/) {
22169: $wafproxy{$item} = $possible;
22170: }
22171: } elsif ($item eq 'ipheader') {
22172: if ($wafproxy{'remoteip'} eq 'h') {
22173: $wafproxy{$item} = $possible;
22174: }
1.382 raeburn 22175: } elsif ($item eq 'sslopt') {
22176: if ($possible =~ /^0|1$/) {
22177: $wafproxy{$item} = $possible;
22178: }
1.373 raeburn 22179: } else {
22180: my (@ok,$count);
1.381 raeburn 22181: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
22182: unless ($env{'form.wafproxy_vpnaccess'}) {
22183: $possible = '';
22184: }
22185: } elsif ($item eq 'trusted') {
22186: unless ($wafproxy{'remoteip'} eq 'h') {
22187: $possible = '';
22188: }
22189: }
22190: unless ($possible eq '') {
22191: $possible =~ s/[\r\n]+/\s/g;
22192: $possible =~ s/\s*-\s*/-/g;
22193: $possible =~ s/\s+/,/g;
1.393 raeburn 22194: $possible =~ s/,+/,/g;
1.381 raeburn 22195: }
1.373 raeburn 22196: $count = 0;
1.381 raeburn 22197: if ($possible ne '') {
1.373 raeburn 22198: foreach my $poss (split(/\,/,$possible)) {
22199: $count ++;
1.393 raeburn 22200: $poss = &validate_ip_pattern($poss);
22201: if ($poss ne '') {
1.373 raeburn 22202: push(@ok,$poss);
22203: }
22204: }
22205: my $diff = $count - scalar(@ok);
22206: if ($diff) {
22207: push(@warnings,'<li>'.
22208: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
22209: $diff,$warn{$item}).
22210: '</li>');
22211: }
1.393 raeburn 22212: if (@ok) {
22213: my @cidr_list;
22214: foreach my $item (@ok) {
22215: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
22216: }
22217: $wafproxy{$item} = join(',',@cidr_list);
22218: }
1.373 raeburn 22219: }
22220: }
1.381 raeburn 22221: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 22222: $changes{$item} = 1;
22223: }
1.381 raeburn 22224: } elsif ($currvalue{$item}) {
22225: $changes{$item} = 1;
1.425 raeburn 22226: }
1.381 raeburn 22227: }
22228: } else {
22229: if (keys(%curralias)) {
22230: $changes{'alias'} = 1;
1.388 raeburn 22231: }
22232: if (keys(%currsaml)) {
22233: $changes{'saml'} = 1;
1.425 raeburn 22234: }
1.381 raeburn 22235: if (keys(%currvalue)) {
22236: foreach my $key (keys(%currvalue)) {
22237: $changes{$key} = 1;
1.373 raeburn 22238: }
22239: }
22240: }
22241: if (keys(%changes)) {
22242: my %defaultshash = (
22243: wafproxy => \%wafproxy,
1.425 raeburn 22244: );
1.373 raeburn 22245: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22246: $dom);
22247: if ($putresult eq 'ok') {
22248: my $cachetime = 24*60*60;
22249: my (%domdefaults,$updatedomdefs);
1.382 raeburn 22250: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22251: if ($changes{$item}) {
22252: unless ($updatedomdefs) {
22253: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
22254: $updatedomdefs = 1;
22255: }
22256: if ($wafproxy{$item}) {
22257: $domdefaults{'waf_'.$item} = $wafproxy{$item};
22258: } elsif (exists($domdefaults{'waf_'.$item})) {
22259: delete($domdefaults{'waf_'.$item});
1.425 raeburn 22260: }
1.373 raeburn 22261: }
22262: }
22263: if ($updatedomdefs) {
22264: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22265: if (ref($lastactref) eq 'HASH') {
22266: $lastactref->{'domdefaults'} = 1;
22267: }
22268: }
22269: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22270: my %updates = %expirecache;
22271: foreach my $key (keys(%expirecache)) {
22272: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22273: }
22274: if (ref($wafproxy{'alias'}) eq 'HASH') {
22275: my $cachetime = 24*60*60;
22276: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22277: $updates{$key} = 1;
22278: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22279: $cachetime);
22280: }
22281: }
22282: if (ref($lastactref) eq 'HASH') {
22283: $lastactref->{'proxyalias'} = \%updates;
22284: }
22285: }
1.388 raeburn 22286: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22287: my %samlupdates = %expiresaml;
22288: foreach my $key (keys(%expiresaml)) {
22289: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22290: }
22291: if (ref($wafproxy{'saml'}) eq 'HASH') {
22292: my $cachetime = 24*60*60;
22293: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22294: $samlupdates{$key} = 1;
22295: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22296: $cachetime);
22297: }
22298: }
22299: if (ref($lastactref) eq 'HASH') {
22300: $lastactref->{'proxysaml'} = \%samlupdates;
22301: }
22302: }
1.373 raeburn 22303: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22304: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22305: if ($changes{$item}) {
22306: if ($item eq 'alias') {
22307: my $numaliased = 0;
22308: if (ref($wafproxy{'alias'}) eq 'HASH') {
22309: my $shown;
22310: if (keys(%{$wafproxy{'alias'}})) {
22311: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22312: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22313: &Apache::lonnet::hostname($server),
22314: $wafproxy{'alias'}{$server}).'</li>';
22315: $numaliased ++;
22316: }
22317: if ($numaliased) {
22318: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22319: '<ul>'.$shown.'</ul>').'</li>';
22320: }
22321: }
22322: }
22323: unless ($numaliased) {
22324: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22325: }
1.388 raeburn 22326: } elsif ($item eq 'saml') {
1.425 raeburn 22327: my $shown;
1.388 raeburn 22328: if (ref($wafproxy{'saml'}) eq 'HASH') {
22329: if (keys(%{$wafproxy{'saml'}})) {
22330: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22331: }
22332: }
22333: if ($shown) {
1.396 raeburn 22334: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22335: $shown).'</li>';
22336: } else {
1.396 raeburn 22337: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22338: }
1.373 raeburn 22339: } else {
1.381 raeburn 22340: if ($item eq 'remoteip') {
22341: my %ip_methods = &remoteip_methods();
22342: if ($wafproxy{$item} =~ /^[mh]$/) {
22343: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22344: $ip_methods{$wafproxy{$item}}).'</li>';
22345: } else {
22346: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22347: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22348: '</li>';
22349: } else {
22350: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22351: }
22352: }
22353: } elsif ($item eq 'ipheader') {
1.373 raeburn 22354: if ($wafproxy{$item}) {
1.381 raeburn 22355: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22356: $wafproxy{$item}).'</li>';
22357: } else {
1.381 raeburn 22358: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22359: }
22360: } elsif ($item eq 'trusted') {
22361: if ($wafproxy{$item}) {
1.381 raeburn 22362: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22363: $wafproxy{$item}).'</li>';
22364: } else {
22365: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22366: }
1.381 raeburn 22367: } elsif ($item eq 'vpnint') {
22368: if ($wafproxy{$item}) {
22369: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22370: $wafproxy{$item}).'</li>';
22371: } else {
22372: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22373: }
22374: } elsif ($item eq 'vpnext') {
1.373 raeburn 22375: if ($wafproxy{$item}) {
1.381 raeburn 22376: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22377: $wafproxy{$item}).'</li>';
22378: } else {
1.381 raeburn 22379: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22380: }
1.382 raeburn 22381: } elsif ($item eq 'sslopt') {
22382: if ($wafproxy{$item}) {
22383: $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>';
22384: } else {
22385: $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>';
22386: }
1.373 raeburn 22387: }
22388: }
22389: }
22390: }
1.420 raeburn 22391: $output .= '</ul>';
1.373 raeburn 22392: } else {
22393: $output = '<span class="LC_error">'.
22394: &mt('An error occurred: [_1]',$putresult).'</span>';
22395: }
22396: } elsif (keys(%canset)) {
22397: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22398: }
22399: if (@warnings) {
22400: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22401: join("\n",@warnings).'</ul>';
22402: }
22403: return $output;
22404: }
22405:
22406: sub validate_ip_pattern {
22407: my ($pattern) = @_;
22408: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22409: my ($start,$end) = ($1,$2);
22410: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22411: if (($start !~ m{/}) && ($end !~ m{/})) {
22412: return $start.'-'.$end;
22413: }
22414: }
22415: } elsif ($pattern ne '') {
22416: $pattern = &Net::CIDR::cidrvalidate($pattern);
22417: if ($pattern ne '') {
22418: return $pattern;
1.373 raeburn 22419: }
22420: }
1.393 raeburn 22421: return;
1.373 raeburn 22422: }
22423:
1.137 raeburn 22424: sub modify_usersessions {
1.212 raeburn 22425: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22426: my @hostingtypes = ('version','excludedomain','includedomain');
22427: my @offloadtypes = ('primary','default');
22428: my %types = (
22429: remote => \@hostingtypes,
22430: hosted => \@hostingtypes,
22431: spares => \@offloadtypes,
22432: );
22433: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22434: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22435: my (%by_ip,%by_location,@intdoms,@instdoms);
22436: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22437: my @locations = sort(keys(%by_location));
1.137 raeburn 22438: my (%defaultshash,%changes);
22439: foreach my $prefix (@prefixes) {
22440: $defaultshash{'usersessions'}{$prefix} = {};
22441: }
1.212 raeburn 22442: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22443: my $resulttext;
1.138 raeburn 22444: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22445: foreach my $prefix (@prefixes) {
1.145 raeburn 22446: next if ($prefix eq 'spares');
22447: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22448: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22449: if ($type eq 'version') {
22450: my $value = $env{'form.'.$prefix.'_'.$type};
22451: my $okvalue;
22452: if ($value ne '') {
22453: if (grep(/^\Q$value\E$/,@lcversions)) {
22454: $okvalue = $value;
22455: }
22456: }
22457: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22458: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22459: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22460: if ($inuse == 0) {
22461: $changes{$prefix}{$type} = 1;
22462: } else {
22463: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22464: $changes{$prefix}{$type} = 1;
22465: }
22466: if ($okvalue ne '') {
22467: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22468: }
22469: }
22470: } else {
22471: if (($inuse == 1) && ($okvalue ne '')) {
22472: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22473: $changes{$prefix}{$type} = 1;
22474: }
22475: }
22476: } else {
22477: if (($inuse == 1) && ($okvalue ne '')) {
22478: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22479: $changes{$prefix}{$type} = 1;
22480: }
22481: }
22482: } else {
22483: if (($inuse == 1) && ($okvalue ne '')) {
22484: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22485: $changes{$prefix}{$type} = 1;
22486: }
22487: }
22488: } else {
22489: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22490: my @okvals;
22491: foreach my $val (@vals) {
1.138 raeburn 22492: if ($val =~ /:/) {
22493: my @items = split(/:/,$val);
22494: foreach my $item (@items) {
22495: if (ref($by_location{$item}) eq 'ARRAY') {
22496: push(@okvals,$item);
22497: }
22498: }
22499: } else {
22500: if (ref($by_location{$val}) eq 'ARRAY') {
22501: push(@okvals,$val);
22502: }
1.137 raeburn 22503: }
22504: }
22505: @okvals = sort(@okvals);
22506: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22507: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22508: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22509: if ($inuse == 0) {
22510: $changes{$prefix}{$type} = 1;
22511: } else {
22512: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22513: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22514: if (@changed > 0) {
22515: $changes{$prefix}{$type} = 1;
22516: }
22517: }
22518: } else {
22519: if ($inuse == 1) {
22520: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22521: $changes{$prefix}{$type} = 1;
22522: }
22523: }
22524: } else {
22525: if ($inuse == 1) {
22526: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22527: $changes{$prefix}{$type} = 1;
22528: }
22529: }
22530: } else {
22531: if ($inuse == 1) {
22532: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22533: $changes{$prefix}{$type} = 1;
22534: }
22535: }
22536: }
22537: }
22538: }
1.145 raeburn 22539:
22540: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22541: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22542: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22543: my $savespares;
22544:
22545: foreach my $lonhost (sort(keys(%servers))) {
22546: my $serverhomeID =
22547: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22548: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22549: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22550: my %spareschg;
22551: foreach my $type (@{$types{'spares'}}) {
22552: my @okspares;
22553: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22554: foreach my $server (@checked) {
1.152 raeburn 22555: if (&Apache::lonnet::hostname($server) ne '') {
22556: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22557: unless (grep(/^\Q$server\E$/,@okspares)) {
22558: push(@okspares,$server);
22559: }
1.145 raeburn 22560: }
22561: }
22562: }
22563: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22564: my $newspare;
1.152 raeburn 22565: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22566: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22567: $newspare = $new;
22568: }
22569: }
1.152 raeburn 22570: my @spares;
22571: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22572: @spares = sort(@okspares,$newspare);
22573: } else {
22574: @spares = sort(@okspares);
22575: }
22576: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22577: if (ref($spareid{$lonhost}) eq 'HASH') {
22578: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22579: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22580: if (@diffs > 0) {
22581: $spareschg{$type} = 1;
22582: }
22583: }
22584: }
22585: }
22586: if (keys(%spareschg) > 0) {
22587: $changes{'spares'}{$lonhost} = \%spareschg;
22588: }
22589: }
1.261 raeburn 22590: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22591: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22592: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22593: my @okoffload;
22594: if (@offloadnow) {
22595: foreach my $server (@offloadnow) {
22596: if (&Apache::lonnet::hostname($server) ne '') {
22597: unless (grep(/^\Q$server\E$/,@okoffload)) {
22598: push(@okoffload,$server);
22599: }
22600: }
22601: }
22602: if (@okoffload) {
22603: foreach my $lonhost (@okoffload) {
22604: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22605: }
22606: }
22607: }
1.371 raeburn 22608: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22609: my @okoffloadoth;
22610: if (@offloadoth) {
22611: foreach my $server (@offloadoth) {
22612: if (&Apache::lonnet::hostname($server) ne '') {
22613: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22614: push(@okoffloadoth,$server);
22615: }
22616: }
22617: }
22618: if (@okoffloadoth) {
22619: foreach my $lonhost (@okoffloadoth) {
22620: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22621: }
22622: }
22623: }
1.145 raeburn 22624: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22625: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22626: if (ref($changes{'spares'}) eq 'HASH') {
22627: if (keys(%{$changes{'spares'}}) > 0) {
22628: $savespares = 1;
22629: }
22630: }
22631: } else {
22632: $savespares = 1;
22633: }
1.371 raeburn 22634: foreach my $offload ('offloadnow','offloadoth') {
22635: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22636: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22637: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22638: $changes{$offload} = 1;
22639: last;
22640: }
1.261 raeburn 22641: }
1.371 raeburn 22642: unless ($changes{$offload}) {
22643: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22644: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22645: $changes{$offload} = 1;
22646: last;
22647: }
1.261 raeburn 22648: }
22649: }
1.371 raeburn 22650: } else {
22651: if (($offload eq 'offloadnow') && (@okoffload)) {
22652: $changes{'offloadnow'} = 1;
22653: }
22654: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22655: $changes{'offloadoth'} = 1;
22656: }
1.425 raeburn 22657: }
1.371 raeburn 22658: }
22659: } else {
22660: if (@okoffload) {
1.261 raeburn 22661: $changes{'offloadnow'} = 1;
22662: }
1.371 raeburn 22663: if (@okoffloadoth) {
22664: $changes{'offloadoth'} = 1;
22665: }
1.145 raeburn 22666: }
1.147 raeburn 22667: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22668: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22669: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22670: $dom);
22671: if ($putresult eq 'ok') {
22672: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22673: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22674: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22675: }
22676: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22677: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22678: }
1.261 raeburn 22679: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22680: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22681: }
1.371 raeburn 22682: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22683: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22684: }
1.137 raeburn 22685: }
22686: my $cachetime = 24*60*60;
22687: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22688: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22689: if (ref($lastactref) eq 'HASH') {
22690: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22691: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22692: }
1.147 raeburn 22693: if (keys(%changes) > 0) {
22694: my %lt = &usersession_titles();
22695: $resulttext = &mt('Changes made:').'<ul>';
22696: foreach my $prefix (@prefixes) {
22697: if (ref($changes{$prefix}) eq 'HASH') {
22698: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22699: if ($prefix eq 'spares') {
22700: if (ref($changes{$prefix}) eq 'HASH') {
22701: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22702: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22703: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22704: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22705: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22706: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22707: foreach my $type (@{$types{$prefix}}) {
22708: if ($changes{$prefix}{$lonhost}{$type}) {
22709: my $offloadto = &mt('None');
22710: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22711: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22712: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22713: }
1.145 raeburn 22714: }
1.147 raeburn 22715: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22716: }
1.137 raeburn 22717: }
22718: }
1.147 raeburn 22719: $resulttext .= '</li>';
1.137 raeburn 22720: }
22721: }
1.147 raeburn 22722: } else {
22723: foreach my $type (@{$types{$prefix}}) {
22724: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22725: my ($newvalue,$notinuse);
1.147 raeburn 22726: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22727: if (ref($defaultshash{'usersessions'}{$prefix})) {
22728: if ($type eq 'version') {
22729: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22730: } else {
22731: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22732: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22733: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22734: }
22735: } else {
22736: $notinuse = 1;
1.147 raeburn 22737: }
1.145 raeburn 22738: }
22739: }
22740: }
1.147 raeburn 22741: if ($newvalue eq '') {
22742: if ($type eq 'version') {
22743: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22744: } elsif ($notinuse) {
22745: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22746: } else {
22747: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22748: }
1.145 raeburn 22749: } else {
1.147 raeburn 22750: if ($type eq 'version') {
1.344 raeburn 22751: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22752: }
22753: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22754: }
1.137 raeburn 22755: }
22756: }
22757: }
1.147 raeburn 22758: $resulttext .= '</ul>';
1.137 raeburn 22759: }
22760: }
1.261 raeburn 22761: if ($changes{'offloadnow'}) {
22762: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22763: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22764: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22765: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22766: $resulttext .= '<li>'.$lonhost.'</li>';
22767: }
22768: $resulttext .= '</ul>';
22769: } else {
1.371 raeburn 22770: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22771: }
22772: } else {
22773: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22774: }
22775: }
22776: if ($changes{'offloadoth'}) {
22777: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22778: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22779: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22780: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22781: $resulttext .= '<li>'.$lonhost.'</li>';
22782: }
22783: $resulttext .= '</ul>';
22784: } else {
22785: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22786: }
22787: } else {
1.371 raeburn 22788: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22789: }
22790: }
1.147 raeburn 22791: $resulttext .= '</ul>';
22792: } else {
22793: $resulttext = $nochgmsg;
1.137 raeburn 22794: }
22795: } else {
22796: $resulttext = '<span class="LC_error">'.
22797: &mt('An error occurred: [_1]',$putresult).'</span>';
22798: }
22799: } else {
1.147 raeburn 22800: $resulttext = $nochgmsg;
1.137 raeburn 22801: }
22802: return $resulttext;
22803: }
22804:
1.275 raeburn 22805: sub modify_ssl {
22806: my ($dom,$lastactref,%domconfig) = @_;
22807: my (%by_ip,%by_location,@intdoms,@instdoms);
22808: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22809: my @locations = sort(keys(%by_location));
22810: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22811: my (%defaultshash,%changes);
22812: my $action = 'ssl';
1.293 raeburn 22813: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22814: foreach my $prefix (@prefixes) {
22815: $defaultshash{$action}{$prefix} = {};
22816: }
22817: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22818: my $resulttext;
22819: my %iphost = &Apache::lonnet::get_iphost();
22820: my @reptypes = ('certreq','nocertreq');
22821: my @connecttypes = ('dom','intdom','other');
22822: my %types = (
1.293 raeburn 22823: connto => \@connecttypes,
22824: connfrom => \@connecttypes,
22825: replication => \@reptypes,
1.275 raeburn 22826: );
22827: foreach my $prefix (sort(keys(%types))) {
22828: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22829: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22830: my $value = 'yes';
22831: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22832: $value = $env{'form.'.$prefix.'_'.$type};
22833: }
1.335 raeburn 22834: if (ref($domconfig{$action}) eq 'HASH') {
22835: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22836: if ($domconfig{$action}{$prefix}{$type} ne '') {
22837: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22838: $changes{$prefix}{$type} = 1;
22839: }
22840: $defaultshash{$action}{$prefix}{$type} = $value;
22841: } else {
22842: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22843: $changes{$prefix}{$type} = 1;
22844: }
22845: } else {
22846: $defaultshash{$action}{$prefix}{$type} = $value;
22847: $changes{$prefix}{$type} = 1;
22848: }
22849: } else {
22850: $defaultshash{$action}{$prefix}{$type} = $value;
22851: $changes{$prefix}{$type} = 1;
22852: }
22853: if (($type eq 'dom') && (keys(%servers) == 1)) {
22854: delete($changes{$prefix}{$type});
22855: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22856: delete($changes{$prefix}{$type});
22857: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22858: delete($changes{$prefix}{$type});
22859: }
22860: } elsif ($prefix eq 'replication') {
22861: if (@locations > 0) {
22862: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22863: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22864: my @okvals;
22865: foreach my $val (@vals) {
22866: if ($val =~ /:/) {
22867: my @items = split(/:/,$val);
22868: foreach my $item (@items) {
22869: if (ref($by_location{$item}) eq 'ARRAY') {
22870: push(@okvals,$item);
22871: }
22872: }
22873: } else {
22874: if (ref($by_location{$val}) eq 'ARRAY') {
22875: push(@okvals,$val);
22876: }
22877: }
22878: }
22879: @okvals = sort(@okvals);
22880: if (ref($domconfig{$action}) eq 'HASH') {
22881: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22882: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22883: if ($inuse == 0) {
22884: $changes{$prefix}{$type} = 1;
22885: } else {
22886: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22887: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22888: if (@changed > 0) {
22889: $changes{$prefix}{$type} = 1;
22890: }
22891: }
22892: } else {
22893: if ($inuse == 1) {
22894: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22895: $changes{$prefix}{$type} = 1;
22896: }
22897: }
22898: } else {
22899: if ($inuse == 1) {
22900: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22901: $changes{$prefix}{$type} = 1;
22902: }
22903: }
22904: } else {
22905: if ($inuse == 1) {
22906: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22907: $changes{$prefix}{$type} = 1;
22908: }
22909: }
22910: }
22911: }
22912: }
22913: }
1.336 raeburn 22914: if (keys(%changes)) {
22915: foreach my $prefix (keys(%changes)) {
22916: if (ref($changes{$prefix}) eq 'HASH') {
22917: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22918: delete($changes{$prefix});
22919: }
22920: } else {
22921: delete($changes{$prefix});
22922: }
22923: }
22924: }
1.275 raeburn 22925: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22926: if (keys(%changes) > 0) {
22927: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22928: $dom);
22929: if ($putresult eq 'ok') {
22930: if (ref($defaultshash{$action}) eq 'HASH') {
22931: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22932: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22933: }
1.293 raeburn 22934: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22935: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22936: }
22937: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22938: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22939: }
22940: }
22941: my $cachetime = 24*60*60;
22942: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22943: if (ref($lastactref) eq 'HASH') {
22944: $lastactref->{'domdefaults'} = 1;
22945: }
22946: if (keys(%changes) > 0) {
22947: my %titles = &ssl_titles();
22948: $resulttext = &mt('Changes made:').'<ul>';
22949: foreach my $prefix (@prefixes) {
22950: if (ref($changes{$prefix}) eq 'HASH') {
22951: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22952: foreach my $type (@{$types{$prefix}}) {
22953: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22954: my ($newvalue,$notinuse);
1.275 raeburn 22955: if (ref($defaultshash{$action}) eq 'HASH') {
22956: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22957: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22958: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22959: } else {
22960: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22961: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22962: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22963: }
22964: } else {
22965: $notinuse = 1;
1.275 raeburn 22966: }
22967: }
22968: }
1.344 raeburn 22969: if ($notinuse) {
22970: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22971: } elsif ($newvalue eq '') {
1.275 raeburn 22972: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22973: } else {
22974: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22975: }
22976: }
22977: }
22978: }
22979: $resulttext .= '</ul>';
22980: }
22981: }
22982: } else {
22983: $resulttext = $nochgmsg;
22984: }
22985: } else {
22986: $resulttext = '<span class="LC_error">'.
22987: &mt('An error occurred: [_1]',$putresult).'</span>';
22988: }
22989: } else {
22990: $resulttext = $nochgmsg;
22991: }
22992: return $resulttext;
22993: }
22994:
1.279 raeburn 22995: sub modify_trust {
22996: my ($dom,$lastactref,%domconfig) = @_;
22997: my (%by_ip,%by_location,@intdoms,@instdoms);
22998: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22999: my @locations = sort(keys(%by_location));
23000: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
23001: my @types = ('exc','inc');
23002: my (%defaultshash,%changes);
23003: foreach my $prefix (@prefixes) {
23004: $defaultshash{'trust'}{$prefix} = {};
23005: }
23006: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
23007: my $resulttext;
23008: foreach my $prefix (@prefixes) {
23009: foreach my $type (@types) {
23010: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
23011: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
23012: my @okvals;
23013: foreach my $val (@vals) {
23014: if ($val =~ /:/) {
23015: my @items = split(/:/,$val);
23016: foreach my $item (@items) {
23017: if (ref($by_location{$item}) eq 'ARRAY') {
23018: push(@okvals,$item);
23019: }
23020: }
23021: } else {
23022: if (ref($by_location{$val}) eq 'ARRAY') {
23023: push(@okvals,$val);
23024: }
23025: }
23026: }
23027: @okvals = sort(@okvals);
23028: if (ref($domconfig{'trust'}) eq 'HASH') {
23029: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
23030: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23031: if ($inuse == 0) {
23032: $changes{$prefix}{$type} = 1;
23033: } else {
23034: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23035: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
23036: if (@changed > 0) {
23037: $changes{$prefix}{$type} = 1;
23038: }
23039: }
23040: } else {
23041: if ($inuse == 1) {
23042: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23043: $changes{$prefix}{$type} = 1;
23044: }
23045: }
23046: } else {
23047: if ($inuse == 1) {
23048: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23049: $changes{$prefix}{$type} = 1;
23050: }
23051: }
23052: } else {
23053: if ($inuse == 1) {
23054: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23055: $changes{$prefix}{$type} = 1;
23056: }
23057: }
23058: }
23059: }
23060: my $nochgmsg = &mt('No changes made to trust settings.');
23061: if (keys(%changes) > 0) {
23062: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
23063: $dom);
23064: if ($putresult eq 'ok') {
23065: if (ref($defaultshash{'trust'}) eq 'HASH') {
23066: foreach my $prefix (@prefixes) {
23067: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
23068: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
23069: }
23070: }
23071: }
23072: my $cachetime = 24*60*60;
23073: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 23074: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 23075: if (ref($lastactref) eq 'HASH') {
23076: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 23077: $lastactref->{'trust'} = 1;
1.279 raeburn 23078: }
23079: if (keys(%changes) > 0) {
23080: my %lt = &trust_titles();
23081: $resulttext = &mt('Changes made:').'<ul>';
23082: foreach my $prefix (@prefixes) {
23083: if (ref($changes{$prefix}) eq 'HASH') {
23084: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
23085: foreach my $type (@types) {
23086: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 23087: my ($newvalue,$notinuse);
1.279 raeburn 23088: if (ref($defaultshash{'trust'}) eq 'HASH') {
23089: if (ref($defaultshash{'trust'}{$prefix})) {
23090: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23091: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
23092: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
23093: }
1.344 raeburn 23094: } else {
23095: $notinuse = 1;
1.279 raeburn 23096: }
23097: }
23098: }
1.344 raeburn 23099: if ($notinuse) {
23100: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
23101: } elsif ($newvalue eq '') {
1.279 raeburn 23102: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
23103: } else {
23104: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
23105: }
23106: }
23107: }
23108: $resulttext .= '</ul>';
23109: }
23110: }
23111: $resulttext .= '</ul>';
23112: } else {
23113: $resulttext = $nochgmsg;
23114: }
23115: } else {
23116: $resulttext = '<span class="LC_error">'.
23117: &mt('An error occurred: [_1]',$putresult).'</span>';
23118: }
23119: } else {
23120: $resulttext = $nochgmsg;
23121: }
23122: return $resulttext;
23123: }
23124:
1.150 raeburn 23125: sub modify_loadbalancing {
23126: my ($dom,%domconfig) = @_;
23127: my $primary_id = &Apache::lonnet::domain($dom,'primary');
23128: my $intdom = &Apache::lonnet::internet_dom($primary_id);
23129: my ($othertitle,$usertypes,$types) =
23130: &Apache::loncommon::sorted_inst_types($dom);
23131: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 23132: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 23133: my @sparestypes = ('primary','default');
23134: my %typetitles = &sparestype_titles();
23135: my $resulttext;
1.342 raeburn 23136: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23137: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23138: %existing = %{$domconfig{'loadbalancing'}};
23139: }
23140: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 23141: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 23142: my ($saveloadbalancing,%defaultshash,%changes);
23143: my ($alltypes,$othertypes,$titles) =
23144: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
23145: my %ruletitles = &offloadtype_text();
23146: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
23147: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
23148: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
23149: if ($balancer eq '') {
23150: next;
23151: }
1.210 raeburn 23152: if (!exists($servers{$balancer})) {
1.171 raeburn 23153: if (exists($currbalancer{$balancer})) {
23154: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 23155: }
1.171 raeburn 23156: next;
23157: }
23158: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
23159: push(@{$changes{'delete'}},$balancer);
23160: next;
23161: }
23162: if (!exists($currbalancer{$balancer})) {
23163: push(@{$changes{'add'}},$balancer);
23164: }
23165: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
23166: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
23167: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
23168: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23169: $saveloadbalancing = 1;
23170: }
23171: foreach my $sparetype (@sparestypes) {
23172: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
23173: my @offloadto;
23174: foreach my $target (@targets) {
23175: if (($servers{$target}) && ($target ne $balancer)) {
23176: if ($sparetype eq 'default') {
23177: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
23178: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 23179: }
23180: }
1.171 raeburn 23181: unless(grep(/^\Q$target\E$/,@offloadto)) {
23182: push(@offloadto,$target);
23183: }
1.150 raeburn 23184: }
23185: }
1.284 raeburn 23186: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
23187: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
23188: push(@offloadto,$balancer);
23189: }
23190: }
23191: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 23192: }
1.342 raeburn 23193: if ($env{'form.loadbalancing_cookie_'.$i}) {
23194: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 23195: if (exists($currbalancer{$balancer})) {
1.342 raeburn 23196: unless ($currcookies{$balancer}) {
23197: $changes{'curr'}{$balancer}{'cookie'} = 1;
23198: }
23199: }
23200: } elsif (exists($currbalancer{$balancer})) {
23201: if ($currcookies{$balancer}) {
23202: $changes{'curr'}{$balancer}{'cookie'} = 1;
23203: }
23204: }
1.171 raeburn 23205: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 23206: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23207: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
23208: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 23209: if (@targetdiffs > 0) {
1.171 raeburn 23210: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23211: }
1.171 raeburn 23212: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23213: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23214: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23215: }
23216: }
23217: }
23218: } else {
1.171 raeburn 23219: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 23220: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23221: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23222: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23223: $changes{'curr'}{$balancer}{'targets'} = 1;
23224: }
1.150 raeburn 23225: }
23226: }
1.210 raeburn 23227: }
1.150 raeburn 23228: }
23229: my $ishomedom;
1.171 raeburn 23230: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
23231: $ishomedom = 1;
1.150 raeburn 23232: }
23233: if (ref($alltypes) eq 'ARRAY') {
23234: foreach my $type (@{$alltypes}) {
23235: my $rule;
1.210 raeburn 23236: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 23237: (!$ishomedom)) {
1.171 raeburn 23238: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
23239: }
23240: if ($rule eq 'specific') {
1.255 raeburn 23241: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 23242: if (exists($servers{$specifiedhost})) {
1.255 raeburn 23243: $rule = $specifiedhost;
23244: }
1.150 raeburn 23245: }
1.171 raeburn 23246: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
23247: if (ref($currrules{$balancer}) eq 'HASH') {
23248: if ($rule ne $currrules{$balancer}{$type}) {
23249: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23250: }
23251: } elsif ($rule ne '') {
1.171 raeburn 23252: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23253: }
23254: }
23255: }
1.171 raeburn 23256: }
23257: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
23258: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
23259: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23260: $defaultshash{'loadbalancing'} = {};
23261: }
23262: my $putresult = &Apache::lonnet::put_dom('configuration',
23263: \%defaultshash,$dom);
23264: if ($putresult eq 'ok') {
23265: if (keys(%changes) > 0) {
1.252 raeburn 23266: my %toupdate;
1.171 raeburn 23267: if (ref($changes{'delete'}) eq 'ARRAY') {
23268: foreach my $balancer (sort(@{$changes{'delete'}})) {
23269: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23270: $toupdate{$balancer} = 1;
1.150 raeburn 23271: }
1.171 raeburn 23272: }
23273: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23274: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23275: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23276: $toupdate{$balancer} = 1;
1.171 raeburn 23277: }
23278: }
23279: if (ref($changes{'curr'}) eq 'HASH') {
23280: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23281: $toupdate{$balancer} = 1;
1.171 raeburn 23282: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23283: if ($changes{'curr'}{$balancer}{'targets'}) {
23284: my %offloadstr;
23285: foreach my $sparetype (@sparestypes) {
23286: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23287: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23288: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23289: }
23290: }
1.150 raeburn 23291: }
1.171 raeburn 23292: if (keys(%offloadstr) == 0) {
23293: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23294: } else {
1.171 raeburn 23295: my $showoffload;
23296: foreach my $sparetype (@sparestypes) {
23297: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23298: if (defined($offloadstr{$sparetype})) {
23299: $showoffload .= $offloadstr{$sparetype};
23300: } else {
23301: $showoffload .= &mt('None');
23302: }
23303: $showoffload .= (' 'x3);
23304: }
23305: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23306: }
23307: }
23308: }
1.171 raeburn 23309: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23310: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23311: foreach my $type (@{$alltypes}) {
23312: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23313: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23314: my $balancetext;
23315: if ($rule eq '') {
23316: $balancetext = $ruletitles{'default'};
1.209 raeburn 23317: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23318: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23319: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23320: foreach my $sparetype (@sparestypes) {
23321: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23322: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23323: }
23324: }
1.253 raeburn 23325: foreach my $item (@{$alltypes}) {
23326: next if ($item =~ /^_LC_ipchange/);
23327: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23328: if ($hasrule eq 'homeserver') {
23329: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23330: } else {
23331: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23332: if ($servers{$hasrule}) {
23333: $toupdate{$hasrule} = 1;
23334: }
23335: }
23336: }
23337: }
1.254 raeburn 23338: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23339: $balancetext = $ruletitles{$rule};
23340: } else {
23341: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23342: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23343: if ($receiver) {
23344: $toupdate{$receiver};
23345: }
23346: }
23347: } else {
23348: $balancetext = $ruletitles{$rule};
1.252 raeburn 23349: }
1.171 raeburn 23350: } else {
23351: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23352: }
1.210 raeburn 23353: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23354: }
23355: }
23356: }
23357: }
1.342 raeburn 23358: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23359: if ($currcookies{$balancer}) {
23360: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23361: $balancer).'</li>';
23362: } else {
23363: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23364: $balancer).'</li>';
23365: }
1.342 raeburn 23366: }
1.375 raeburn 23367: }
23368: }
23369: if (keys(%toupdate)) {
23370: my %thismachine;
23371: my $updatedhere;
23372: my $cachetime = 60*60*24;
23373: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23374: foreach my $lonhost (keys(%toupdate)) {
23375: if ($thismachine{$lonhost}) {
23376: unless ($updatedhere) {
23377: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23378: $defaultshash{'loadbalancing'},
23379: $cachetime);
23380: $updatedhere = 1;
1.252 raeburn 23381: }
1.375 raeburn 23382: } else {
23383: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23384: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23385: }
1.150 raeburn 23386: }
1.171 raeburn 23387: }
23388: if ($resulttext ne '') {
23389: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23390: } else {
23391: $resulttext = $nochgmsg;
23392: }
23393: } else {
1.171 raeburn 23394: $resulttext = $nochgmsg;
1.150 raeburn 23395: }
23396: } else {
1.171 raeburn 23397: $resulttext = '<span class="LC_error">'.
23398: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23399: }
23400: } else {
1.171 raeburn 23401: $resulttext = $nochgmsg;
1.150 raeburn 23402: }
23403: return $resulttext;
23404: }
23405:
1.48 raeburn 23406: sub recurse_check {
23407: my ($chkcats,$categories,$depth,$name) = @_;
23408: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23409: my $chg = 0;
23410: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23411: my $category = $chkcats->[$depth]{$name}[$j];
23412: my $item;
23413: if ($category eq '') {
23414: $chg ++;
23415: } else {
23416: my $deeper = $depth + 1;
23417: $item = &escape($category).':'.&escape($name).':'.$depth;
23418: if ($chg) {
23419: $categories->{$item} -= $chg;
23420: }
23421: &recurse_check($chkcats,$categories,$deeper,$category);
23422: $deeper --;
23423: }
23424: }
23425: }
23426: return;
23427: }
23428:
23429: sub recurse_cat_deletes {
23430: my ($item,$coursecategories,$deletions) = @_;
23431: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23432: my $subdepth = $depth + 1;
23433: if (ref($coursecategories) eq 'HASH') {
23434: foreach my $subitem (keys(%{$coursecategories})) {
23435: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23436: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23437: delete($coursecategories->{$subitem});
23438: $deletions->{$subitem} = 1;
23439: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23440: }
1.48 raeburn 23441: }
23442: }
23443: return;
23444: }
23445:
1.125 raeburn 23446: sub active_dc_picker {
1.191 raeburn 23447: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23448: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23449: my @domcoord = keys(%domcoords);
23450: if (keys(%currhash)) {
23451: foreach my $dc (keys(%currhash)) {
23452: unless (exists($domcoords{$dc})) {
23453: push(@domcoord,$dc);
23454: }
23455: }
23456: }
23457: @domcoord = sort(@domcoord);
1.210 raeburn 23458: my $numdcs = scalar(@domcoord);
1.191 raeburn 23459: my $rows = 0;
23460: my $table;
1.125 raeburn 23461: if ($numdcs > 1) {
1.191 raeburn 23462: $table = '<table>';
23463: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23464: my $rem = $i%($numinrow);
23465: if ($rem == 0) {
23466: if ($i > 0) {
1.191 raeburn 23467: $table .= '</tr>';
1.125 raeburn 23468: }
1.191 raeburn 23469: $table .= '<tr>';
23470: $rows ++;
1.125 raeburn 23471: }
1.191 raeburn 23472: my $check = '';
23473: if ($inputtype eq 'radio') {
23474: if (keys(%currhash) == 0) {
23475: if (!$i) {
23476: $check = ' checked="checked"';
23477: }
23478: } elsif (exists($currhash{$domcoord[$i]})) {
23479: $check = ' checked="checked"';
23480: }
23481: } else {
23482: if (exists($currhash{$domcoord[$i]})) {
23483: $check = ' checked="checked"';
1.125 raeburn 23484: }
23485: }
1.191 raeburn 23486: if ($i == @domcoord - 1) {
1.125 raeburn 23487: my $colsleft = $numinrow - $rem;
23488: if ($colsleft > 1) {
1.191 raeburn 23489: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23490: } else {
1.191 raeburn 23491: $table .= '<td class="LC_left_item">';
1.125 raeburn 23492: }
23493: } else {
1.191 raeburn 23494: $table .= '<td class="LC_left_item">';
23495: }
23496: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23497: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23498: $table .= '<span class="LC_nobreak"><label>'.
23499: '<input type="'.$inputtype.'" name="'.$name.'"'.
23500: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23501: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23502: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23503: }
1.219 raeburn 23504: $table .= '</label></span></td>';
1.191 raeburn 23505: }
23506: $table .= '</tr></table>';
23507: } elsif ($numdcs == 1) {
1.219 raeburn 23508: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23509: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23510: if ($inputtype eq 'radio') {
1.247 raeburn 23511: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23512: if ($user ne $dcname.':'.$dcdom) {
23513: $table .= ' ('.$dcname.':'.$dcdom.')';
23514: }
1.191 raeburn 23515: } else {
23516: my $check;
23517: if (exists($currhash{$domcoord[0]})) {
23518: $check = ' checked="checked"';
1.125 raeburn 23519: }
1.247 raeburn 23520: $table = '<span class="LC_nobreak"><label>'.
23521: '<input type="checkbox" name="'.$name.'" '.
23522: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23523: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23524: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23525: }
1.220 raeburn 23526: $table .= '</label></span>';
1.191 raeburn 23527: $rows ++;
1.125 raeburn 23528: }
23529: }
1.191 raeburn 23530: return ($numdcs,$table,$rows);
1.125 raeburn 23531: }
23532:
1.137 raeburn 23533: sub usersession_titles {
23534: return &Apache::lonlocal::texthash(
23535: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23536: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23537: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23538: version => 'LON-CAPA version requirement',
1.138 raeburn 23539: excludedomain => 'Allow all, but exclude specific domains',
23540: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23541: primary => 'Primary (checked first)',
1.154 raeburn 23542: default => 'Default',
1.137 raeburn 23543: );
23544: }
23545:
1.152 raeburn 23546: sub id_for_thisdom {
23547: my (%servers) = @_;
23548: my %altids;
23549: foreach my $server (keys(%servers)) {
23550: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23551: if ($serverhome ne $server) {
23552: $altids{$serverhome} = $server;
23553: }
23554: }
23555: return %altids;
23556: }
23557:
1.150 raeburn 23558: sub count_servers {
23559: my ($currbalancer,%servers) = @_;
23560: my (@spares,$numspares);
23561: foreach my $lonhost (sort(keys(%servers))) {
23562: next if ($currbalancer eq $lonhost);
23563: push(@spares,$lonhost);
23564: }
23565: if ($currbalancer) {
23566: $numspares = scalar(@spares);
23567: } else {
23568: $numspares = scalar(@spares) - 1;
23569: }
23570: return ($numspares,@spares);
23571: }
23572:
23573: sub lonbalance_targets_js {
1.171 raeburn 23574: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23575: my $select = &mt('Select');
23576: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23577: if (ref($servers) eq 'HASH') {
23578: $alltargets = join("','",sort(keys(%{$servers})));
23579: my @homedoms;
23580: foreach my $server (sort(keys(%{$servers}))) {
23581: if (&Apache::lonnet::host_domain($server) eq $dom) {
23582: push(@homedoms,'1');
23583: } else {
23584: push(@homedoms,'0');
23585: }
23586: }
23587: $allishome = join("','",@homedoms);
23588: }
23589: if (ref($types) eq 'ARRAY') {
23590: if (@{$types} > 0) {
23591: @alltypes = @{$types};
23592: }
23593: }
23594: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23595: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23596: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23597: if (ref($settings) eq 'HASH') {
23598: %existing = %{$settings};
23599: }
23600: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23601: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23602: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23603: return <<"END";
23604:
23605: <script type="text/javascript">
23606: // <![CDATA[
23607:
1.171 raeburn 23608: currBalancers = new Array('$balancers');
23609:
23610: function toggleTargets(balnum) {
23611: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23612: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23613: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23614: var prevbalancer = prevhostitem.value;
23615: var baltotal = document.getElementById('loadbalancing_total').value;
23616: prevhostitem.value = balancer;
23617: if (prevbalancer != '') {
23618: var prevIdx = currBalancers.indexOf(prevbalancer);
23619: if (prevIdx != -1) {
23620: currBalancers.splice(prevIdx,1);
23621: }
23622: }
1.150 raeburn 23623: if (balancer == '') {
1.171 raeburn 23624: hideSpares(balnum);
1.150 raeburn 23625: } else {
1.171 raeburn 23626: var currIdx = currBalancers.indexOf(balancer);
23627: if (currIdx == -1) {
23628: currBalancers.push(balancer);
23629: }
1.150 raeburn 23630: var homedoms = new Array('$allishome');
1.171 raeburn 23631: var ishomedom = homedoms[lonhostitem.selectedIndex];
23632: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23633: }
1.171 raeburn 23634: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23635: return;
23636: }
23637:
1.171 raeburn 23638: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23639: var alltargets = new Array('$alltargets');
23640: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23641: var offloadtypes = new Array('primary','default');
23642:
1.171 raeburn 23643: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23644: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23645:
1.151 raeburn 23646: for (var i=0; i<offloadtypes.length; i++) {
23647: var count = 0;
23648: for (var j=0; j<alltargets.length; j++) {
23649: if (alltargets[j] != balancer) {
1.171 raeburn 23650: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23651: item.value = alltargets[j];
23652: item.style.textAlign='left';
23653: item.style.textFace='normal';
23654: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23655: if (currBalancers.indexOf(alltargets[j]) == -1) {
23656: item.disabled = '';
23657: } else {
23658: item.disabled = 'disabled';
23659: item.checked = false;
23660: }
1.151 raeburn 23661: count ++;
23662: }
1.150 raeburn 23663: }
23664: }
1.151 raeburn 23665: for (var k=0; k<insttypes.length; k++) {
23666: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23667: if (ishomedom == 1) {
1.171 raeburn 23668: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23669: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23670: } else {
1.171 raeburn 23671: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23672: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23673: }
23674: } else {
1.171 raeburn 23675: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23676: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23677: }
1.151 raeburn 23678: if ((insttypes[k] != '_LC_external') &&
23679: ((insttypes[k] != '_LC_internetdom') ||
23680: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23681: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23682: item.options.length = 0;
23683: item.options[0] = new Option("","",true,true);
1.210 raeburn 23684: var idx = 0;
1.151 raeburn 23685: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23686: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23687: idx ++;
23688: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23689: }
23690: }
23691: }
23692: }
23693: return;
23694: }
23695:
1.171 raeburn 23696: function hideSpares(balnum) {
1.150 raeburn 23697: var alltargets = new Array('$alltargets');
23698: var insttypes = new Array('$allinsttypes');
23699: var offloadtypes = new Array('primary','default');
23700:
1.171 raeburn 23701: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23702: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23703:
23704: var total = alltargets.length - 1;
23705: for (var i=0; i<offloadtypes; i++) {
23706: for (var j=0; j<total; j++) {
1.171 raeburn 23707: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23708: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23709: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23710: }
1.150 raeburn 23711: }
23712: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23713: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23714: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23715: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23716: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23717: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23718: }
23719: }
23720: return;
23721: }
23722:
1.171 raeburn 23723: function checkOffloads(item,balnum,type) {
1.150 raeburn 23724: var alltargets = new Array('$alltargets');
23725: var offloadtypes = new Array('primary','default');
23726: if (item.checked) {
23727: var total = alltargets.length - 1;
23728: var other;
23729: if (type == offloadtypes[0]) {
1.151 raeburn 23730: other = offloadtypes[1];
1.150 raeburn 23731: } else {
1.151 raeburn 23732: other = offloadtypes[0];
1.150 raeburn 23733: }
23734: for (var i=0; i<total; i++) {
1.171 raeburn 23735: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23736: if (server == item.value) {
1.171 raeburn 23737: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23738: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23739: }
23740: }
23741: }
23742: }
23743: return;
23744: }
23745:
1.171 raeburn 23746: function singleServerToggle(balnum,type) {
23747: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23748: if (offloadtoSelIdx == 0) {
1.171 raeburn 23749: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23750: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23751:
23752: } else {
1.171 raeburn 23753: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23754: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23755: }
23756: return;
23757: }
23758:
1.171 raeburn 23759: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23760: if (type == '_LC_external') {
1.171 raeburn 23761: return;
1.150 raeburn 23762: }
1.171 raeburn 23763: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23764: for (var i=0; i<typesRules.length; i++) {
23765: if (formname.elements[typesRules[i]].checked) {
23766: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23767: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23768: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23769: } else {
1.171 raeburn 23770: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23771: }
23772: }
23773: }
23774: return;
23775: }
23776:
23777: function balancerDeleteChange(balnum) {
23778: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23779: var baltotal = document.getElementById('loadbalancing_total').value;
23780: var addtarget;
23781: var removetarget;
23782: var action = 'delete';
23783: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23784: var lonhost = hostitem.value;
23785: var currIdx = currBalancers.indexOf(lonhost);
23786: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23787: if (currIdx != -1) {
23788: currBalancers.splice(currIdx,1);
23789: }
23790: addtarget = lonhost;
23791: } else {
23792: if (currIdx == -1) {
23793: currBalancers.push(lonhost);
23794: }
23795: removetarget = lonhost;
23796: action = 'undelete';
23797: }
23798: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23799: }
23800: return;
23801: }
23802:
23803: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23804: if (baltotal > 1) {
23805: var offloadtypes = new Array('primary','default');
23806: var alltargets = new Array('$alltargets');
23807: var insttypes = new Array('$allinsttypes');
23808: for (var i=0; i<baltotal; i++) {
23809: if (i != balnum) {
23810: for (var j=0; j<offloadtypes.length; j++) {
23811: var total = alltargets.length - 1;
23812: for (var k=0; k<total; k++) {
23813: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23814: var server = serveritem.value;
23815: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23816: if (server == addtarget) {
23817: serveritem.disabled = '';
23818: }
23819: }
23820: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23821: if (server == removetarget) {
23822: serveritem.disabled = 'disabled';
23823: serveritem.checked = false;
23824: }
23825: }
23826: }
23827: }
23828: for (var j=0; j<insttypes.length; j++) {
23829: if (insttypes[j] != '_LC_external') {
23830: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23831: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23832: var currSel = singleserver.selectedIndex;
23833: var currVal = singleserver.options[currSel].value;
23834: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23835: var numoptions = singleserver.options.length;
23836: var needsnew = 1;
23837: for (var k=0; k<numoptions; k++) {
23838: if (singleserver.options[k] == addtarget) {
23839: needsnew = 0;
23840: break;
23841: }
23842: }
23843: if (needsnew == 1) {
23844: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23845: }
23846: }
23847: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23848: singleserver.options.length = 0;
23849: if ((currVal) && (currVal != removetarget)) {
23850: singleserver.options[0] = new Option("","",false,false);
23851: } else {
23852: singleserver.options[0] = new Option("","",true,true);
23853: }
23854: var idx = 0;
23855: for (var m=0; m<alltargets.length; m++) {
23856: if (currBalancers.indexOf(alltargets[m]) == -1) {
23857: idx ++;
23858: if (currVal == alltargets[m]) {
23859: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23860: } else {
23861: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23862: }
23863: }
23864: }
23865: }
23866: }
23867: }
23868: }
1.150 raeburn 23869: }
23870: }
23871: }
23872: return;
23873: }
23874:
1.152 raeburn 23875: // ]]>
23876: </script>
23877:
23878: END
23879: }
23880:
23881: sub new_spares_js {
23882: my @sparestypes = ('primary','default');
23883: my $types = join("','",@sparestypes);
23884: my $select = &mt('Select');
23885: return <<"END";
23886:
23887: <script type="text/javascript">
23888: // <![CDATA[
23889:
23890: function updateNewSpares(formname,lonhost) {
23891: var types = new Array('$types');
23892: var include = new Array();
23893: var exclude = new Array();
23894: for (var i=0; i<types.length; i++) {
23895: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23896: for (var j=0; j<spareboxes.length; j++) {
23897: if (formname.elements[spareboxes[j]].checked) {
23898: exclude.push(formname.elements[spareboxes[j]].value);
23899: } else {
23900: include.push(formname.elements[spareboxes[j]].value);
23901: }
23902: }
23903: }
23904: for (var i=0; i<types.length; i++) {
23905: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23906: var selIdx = newSpare.selectedIndex;
23907: var currnew = newSpare.options[selIdx].value;
23908: var okSpares = new Array();
23909: for (var j=0; j<newSpare.options.length; j++) {
23910: var possible = newSpare.options[j].value;
23911: if (possible != '') {
23912: if (exclude.indexOf(possible) == -1) {
23913: okSpares.push(possible);
23914: } else {
23915: if (currnew == possible) {
23916: selIdx = 0;
23917: }
23918: }
23919: }
23920: }
23921: for (var k=0; k<include.length; k++) {
23922: if (okSpares.indexOf(include[k]) == -1) {
23923: okSpares.push(include[k]);
23924: }
23925: }
23926: okSpares.sort();
23927: newSpare.options.length = 0;
23928: if (selIdx == 0) {
23929: newSpare.options[0] = new Option("$select","",true,true);
23930: } else {
23931: newSpare.options[0] = new Option("$select","",false,false);
23932: }
23933: for (var m=0; m<okSpares.length; m++) {
23934: var idx = m+1;
23935: var selThis = 0;
23936: if (selIdx != 0) {
23937: if (okSpares[m] == currnew) {
23938: selThis = 1;
23939: }
23940: }
23941: if (selThis == 1) {
23942: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23943: } else {
23944: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23945: }
23946: }
23947: }
23948: return;
23949: }
23950:
23951: function checkNewSpares(lonhost,type) {
23952: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23953: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23954: if (chosen != '') {
1.152 raeburn 23955: var othertype;
23956: var othernewSpare;
23957: if (type == 'primary') {
23958: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23959: }
23960: if (type == 'default') {
23961: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23962: }
23963: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23964: othernewSpare.selectedIndex = 0;
23965: }
23966: }
23967: return;
23968: }
23969:
23970: // ]]>
23971: </script>
23972:
23973: END
23974:
23975: }
23976:
23977: sub common_domprefs_js {
23978: return <<"END";
23979:
23980: <script type="text/javascript">
23981: // <![CDATA[
23982:
1.150 raeburn 23983: function getIndicesByName(formname,item) {
1.152 raeburn 23984: var group = new Array();
1.150 raeburn 23985: for (var i=0;i<formname.elements.length;i++) {
23986: if (formname.elements[i].name == item) {
1.152 raeburn 23987: group.push(formname.elements[i].id);
1.150 raeburn 23988: }
23989: }
1.152 raeburn 23990: return group;
1.150 raeburn 23991: }
23992:
23993: // ]]>
23994: </script>
23995:
23996: END
1.152 raeburn 23997:
1.150 raeburn 23998: }
23999:
1.165 raeburn 24000: sub recaptcha_js {
24001: my %lt = &captcha_phrases();
24002: return <<"END";
24003:
24004: <script type="text/javascript">
24005: // <![CDATA[
24006:
24007: function updateCaptcha(caller,context) {
24008: var privitem;
24009: var pubitem;
24010: var privtext;
24011: var pubtext;
1.269 raeburn 24012: var versionitem;
24013: var versiontext;
1.165 raeburn 24014: if (document.getElementById(context+'_recaptchapub')) {
24015: pubitem = document.getElementById(context+'_recaptchapub');
24016: } else {
24017: return;
24018: }
24019: if (document.getElementById(context+'_recaptchapriv')) {
24020: privitem = document.getElementById(context+'_recaptchapriv');
24021: } else {
24022: return;
24023: }
24024: if (document.getElementById(context+'_recaptchapubtxt')) {
24025: pubtext = document.getElementById(context+'_recaptchapubtxt');
24026: } else {
24027: return;
24028: }
24029: if (document.getElementById(context+'_recaptchaprivtxt')) {
24030: privtext = document.getElementById(context+'_recaptchaprivtxt');
24031: } else {
24032: return;
24033: }
1.269 raeburn 24034: if (document.getElementById(context+'_recaptchaversion')) {
24035: versionitem = document.getElementById(context+'_recaptchaversion');
24036: } else {
24037: return;
24038: }
24039: if (document.getElementById(context+'_recaptchavertxt')) {
24040: versiontext = document.getElementById(context+'_recaptchavertxt');
24041: } else {
24042: return;
24043: }
1.165 raeburn 24044: if (caller.checked) {
24045: if (caller.value == 'recaptcha') {
24046: pubitem.type = 'text';
24047: privitem.type = 'text';
24048: pubitem.size = '40';
24049: privitem.size = '40';
24050: pubtext.innerHTML = "$lt{'pub'}";
24051: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 24052: versionitem.type = 'text';
24053: versionitem.size = '3';
1.289 raeburn 24054: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 24055: } else {
24056: pubitem.type = 'hidden';
24057: privitem.type = 'hidden';
1.269 raeburn 24058: versionitem.type = 'hidden';
1.165 raeburn 24059: pubtext.innerHTML = '';
24060: privtext.innerHTML = '';
1.269 raeburn 24061: versiontext.innerHTML = '';
1.165 raeburn 24062: }
24063: }
24064: return;
24065: }
24066:
24067: // ]]>
24068: </script>
24069:
24070: END
24071:
24072: }
24073:
1.236 raeburn 24074: sub toggle_display_js {
1.192 raeburn 24075: return <<"END";
24076:
24077: <script type="text/javascript">
24078: // <![CDATA[
24079:
1.236 raeburn 24080: function toggleDisplay(domForm,caller) {
24081: if (document.getElementById(caller)) {
24082: var divitem = document.getElementById(caller);
24083: var optionsElement = domForm.coursecredits;
1.264 raeburn 24084: var checkval = 1;
24085: var dispval = 'block';
1.303 raeburn 24086: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 24087: if (caller == 'emailoptions') {
1.372 raeburn 24088: optionsElement = domForm.cancreate_email;
1.236 raeburn 24089: }
1.257 raeburn 24090: if (caller == 'studentsubmission') {
24091: optionsElement = domForm.postsubmit;
24092: }
1.264 raeburn 24093: if (caller == 'cloneinstcode') {
24094: optionsElement = domForm.canclone;
24095: checkval = 'instcode';
24096: }
1.303 raeburn 24097: if (selfcreateRegExp.test(caller)) {
24098: optionsElement = domForm.elements[caller];
24099: checkval = 'other';
24100: dispval = 'inline'
24101: }
1.236 raeburn 24102: if (optionsElement.length) {
1.192 raeburn 24103: var currval;
1.236 raeburn 24104: for (var i=0; i<optionsElement.length; i++) {
24105: if (optionsElement[i].checked) {
24106: currval = optionsElement[i].value;
1.192 raeburn 24107: }
24108: }
1.264 raeburn 24109: if (currval == checkval) {
24110: divitem.style.display = dispval;
1.192 raeburn 24111: } else {
1.236 raeburn 24112: divitem.style.display = 'none';
1.192 raeburn 24113: }
24114: }
24115: }
24116: return;
24117: }
24118:
24119: // ]]>
24120: </script>
24121:
24122: END
24123:
24124: }
24125:
1.165 raeburn 24126: sub captcha_phrases {
24127: return &Apache::lonlocal::texthash (
24128: priv => 'Private key',
24129: pub => 'Public key',
24130: original => 'original (CAPTCHA)',
24131: recaptcha => 'successor (ReCAPTCHA)',
24132: notused => 'unused',
1.289 raeburn 24133: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 24134: );
24135: }
24136:
1.205 raeburn 24137: sub devalidate_remote_domconfs {
1.212 raeburn 24138: my ($dom,$cachekeys) = @_;
24139: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 24140: my %servers = &Apache::lonnet::internet_dom_servers($dom);
24141: my %thismachine;
24142: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 24143: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 24144: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 24145: 'ipaccess','trust');
1.386 raeburn 24146: my %cache_by_lonhost;
24147: if (exists($cachekeys->{'samllanding'})) {
24148: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
24149: my %landing = %{$cachekeys->{'samllanding'}};
24150: my %domservers = &Apache::lonnet::get_servers($dom);
24151: if (keys(%domservers)) {
24152: foreach my $server (keys(%domservers)) {
24153: my @cached;
24154: next if ($thismachine{$server});
24155: if ($landing{$server}) {
24156: push(@cached,&escape('samllanding').':'.&escape($server));
24157: }
24158: if (@cached) {
24159: $cache_by_lonhost{$server} = \@cached;
24160: }
24161: }
24162: }
24163: }
24164: }
1.260 raeburn 24165: if (keys(%servers)) {
1.205 raeburn 24166: foreach my $server (keys(%servers)) {
24167: next if ($thismachine{$server});
1.212 raeburn 24168: my @cached;
24169: foreach my $name (@posscached) {
24170: if ($cachekeys->{$name}) {
1.388 raeburn 24171: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 24172: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 24173: foreach my $key (keys(%{$cachekeys->{$name}})) {
24174: push(@cached,&escape($name).':'.&escape($key));
24175: }
24176: }
24177: } else {
24178: push(@cached,&escape($name).':'.&escape($dom));
24179: }
1.212 raeburn 24180: }
24181: }
1.386 raeburn 24182: if ((exists($cache_by_lonhost{$server})) &&
24183: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
24184: push(@cached,@{$cache_by_lonhost{$server}});
24185: }
1.212 raeburn 24186: if (@cached) {
24187: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
24188: }
1.205 raeburn 24189: }
24190: }
24191: return;
24192: }
24193:
1.3 raeburn 24194: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>