Annotation of loncom/interface/domainprefs.pm, revision 1.429
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.429 ! raeburn 4: # $Id: domainprefs.pm,v 1.428 2023/07/29 20:33:25 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.429 ! raeburn 225: 'privacy','passwords','proctoring','wafproxy',
! 226: 'ipaccess','authordefaults'],$dom);
1.320 raeburn 227: my %encconfig =
1.405 raeburn 228: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring','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.372 raeburn 291: if (ref($domconfig{'proctoring'}) eq 'HASH') {
292: if (ref($encconfig{'proctoring'}) eq 'HASH') {
293: foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
294: if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
295: (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
296: foreach my $item ('key','secret') {
297: $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
298: }
299: }
300: }
301: }
302: }
1.394 raeburn 303: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
304: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373 raeburn 305: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 306: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 307: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.429 ! raeburn 308: 'authordefaults','ltitools','proctoring','selfenrollment',
! 309: 'usersessions','ssl','trust','lti');
1.171 raeburn 310: my %existing;
311: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
312: %existing = %{$domconfig{'loadbalancing'}};
313: }
314: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 315: push(@prefs_order,'loadbalancing');
316: }
1.30 raeburn 317: my %prefs = (
318: 'rolecolors' =>
319: { text => 'Default color schemes',
1.67 raeburn 320: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 321: header => [{col1 => 'Student Settings',
322: col2 => '',},
323: {col1 => 'Coordinator Settings',
324: col2 => '',},
325: {col1 => 'Author Settings',
326: col2 => '',},
327: {col1 => 'Administrator Settings',
328: col2 => '',}],
1.230 raeburn 329: print => \&print_rolecolors,
330: modify => \&modify_rolecolors,
1.30 raeburn 331: },
1.110 raeburn 332: 'login' =>
1.30 raeburn 333: { text => 'Log-in page options',
1.67 raeburn 334: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 335: header => [{col1 => 'Log-in Page Items',
336: col2 => '',},
337: {col1 => 'Log-in Help',
1.256 raeburn 338: col2 => 'Value'},
339: {col1 => 'Custom HTML in document head',
1.386 raeburn 340: col2 => 'Value'},
341: {col1 => 'SSO',
342: col2 => 'Dual login: SSO and non-SSO options'},
343: ],
1.230 raeburn 344: print => \&print_login,
345: modify => \&modify_login,
1.30 raeburn 346: },
1.43 raeburn 347: 'defaults' =>
1.236 raeburn 348: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 349: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 350: header => [{col1 => 'Setting',
1.236 raeburn 351: col2 => 'Value'},
352: {col1 => 'Institutional user types',
1.409 raeburn 353: col2 => 'Name displayed'},
354: {col1 => 'Mapping for missing usernames via standard log-in',
355: col2 => 'Rules in use'}],
1.230 raeburn 356: print => \&print_defaults,
357: modify => \&modify_defaults,
1.43 raeburn 358: },
1.381 raeburn 359: 'wafproxy' =>
360: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 361: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 362: header => [{col1 => 'Domain(s)',
363: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 364: },
1.381 raeburn 365: {col1 => 'Domain(s)',
366: col2 => 'WAF Configuration',}],
1.373 raeburn 367: print => \&print_wafproxy,
1.381 raeburn 368: modify => \&modify_wafproxy,
1.373 raeburn 369: },
1.354 raeburn 370: 'passwords' =>
371: { text => 'Passwords (Internal authentication)',
372: help => 'Domain_Configuration_Passwords',
373: header => [{col1 => 'Resetting Forgotten Password',
374: col2 => 'Settings'},
375: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
376: col2 => 'Settings'},
377: {col1 => 'Rules for LON-CAPA Passwords',
378: col2 => 'Settings'},
379: {col1 => 'Course Owner Changing Student Passwords',
380: col2 => 'Settings'}],
381: print => \&print_passwords,
382: modify => \&modify_passwords,
383: },
1.30 raeburn 384: 'quotas' =>
1.429 ! raeburn 385: { text => 'Blogs, personal pages/timezones, portfolio/quotas',
1.67 raeburn 386: help => 'Domain_Configuration_Quotas',
1.77 raeburn 387: header => [{col1 => 'User affiliation',
1.72 raeburn 388: col2 => 'Available tools',
1.429 ! raeburn 389: col3 => 'Portfilo quota (MB)',}],
1.230 raeburn 390: print => \&print_quotas,
391: modify => \&modify_quotas,
1.30 raeburn 392: },
393: 'autoenroll' =>
394: { text => 'Auto-enrollment settings',
1.67 raeburn 395: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 396: header => [{col1 => 'Configuration setting',
397: col2 => 'Value(s)'}],
1.230 raeburn 398: print => \&print_autoenroll,
399: modify => \&modify_autoenroll,
1.30 raeburn 400: },
401: 'autoupdate' =>
402: { text => 'Auto-update settings',
1.67 raeburn 403: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 404: header => [{col1 => 'Setting',
405: col2 => 'Value',},
1.131 raeburn 406: {col1 => 'Setting',
407: col2 => 'Affiliation'},
1.43 raeburn 408: {col1 => 'User population',
1.227 bisitz 409: col2 => 'Updatable user data'}],
1.230 raeburn 410: print => \&print_autoupdate,
411: modify => \&modify_autoupdate,
1.30 raeburn 412: },
1.125 raeburn 413: 'autocreate' =>
414: { text => 'Auto-course creation settings',
415: help => 'Domain_Configuration_Auto_Creation',
416: header => [{col1 => 'Configuration Setting',
417: col2 => 'Value',}],
1.230 raeburn 418: print => \&print_autocreate,
419: modify => \&modify_autocreate,
1.125 raeburn 420: },
1.30 raeburn 421: 'directorysrch' =>
1.277 raeburn 422: { text => 'Directory searches',
1.67 raeburn 423: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 424: header => [{col1 => 'Institutional Directory Setting',
425: col2 => 'Value',},
426: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 427: col2 => 'Value',}],
1.230 raeburn 428: print => \&print_directorysrch,
429: modify => \&modify_directorysrch,
1.30 raeburn 430: },
431: 'contacts' =>
1.286 raeburn 432: { text => 'E-mail addresses and helpform',
1.67 raeburn 433: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 434: header => [{col1 => 'Default e-mail addresses',
435: col2 => 'Value',},
436: {col1 => 'Recipient(s) for notifications',
437: col2 => 'Value',},
1.340 raeburn 438: {col1 => 'Nightly status check e-mail',
439: col2 => 'Settings',},
1.286 raeburn 440: {col1 => 'Ask helpdesk form settings',
441: col2 => 'Value',},],
1.230 raeburn 442: print => \&print_contacts,
443: modify => \&modify_contacts,
1.30 raeburn 444: },
445: 'usercreation' =>
446: { text => 'User creation',
1.67 raeburn 447: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 448: header => [{col1 => 'Format rule type',
449: col2 => 'Format rules in force'},
1.34 raeburn 450: {col1 => 'User account creation',
451: col2 => 'Usernames which may be created',},
1.30 raeburn 452: {col1 => 'Context',
1.43 raeburn 453: col2 => 'Assignable authentication types'}],
1.230 raeburn 454: print => \&print_usercreation,
455: modify => \&modify_usercreation,
1.30 raeburn 456: },
1.224 raeburn 457: 'selfcreation' =>
458: { text => 'Users self-creating accounts',
459: help => 'Domain_Configuration_Self_Creation',
460: header => [{col1 => 'Self-creation with institutional username',
461: col2 => 'Enabled?'},
462: {col1 => 'Institutional user type (login/SSO self-creation)',
463: col2 => 'Information user can enter'},
1.303 raeburn 464: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 465: col2 => 'Settings'}],
1.230 raeburn 466: print => \&print_selfcreation,
467: modify => \&modify_selfcreation,
1.224 raeburn 468: },
1.69 raeburn 469: 'usermodification' =>
1.33 raeburn 470: { text => 'User modification',
1.67 raeburn 471: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 472: header => [{col1 => 'Target user has role',
1.227 bisitz 473: col2 => 'User information updatable in author context'},
1.33 raeburn 474: {col1 => 'Target user has role',
1.227 bisitz 475: col2 => 'User information updatable in course context'}],
1.230 raeburn 476: print => \&print_usermodification,
477: modify => \&modify_usermodification,
1.33 raeburn 478: },
1.69 raeburn 479: 'scantron' =>
1.346 raeburn 480: { text => 'Bubblesheet format',
1.67 raeburn 481: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 482: header => [ {col1 => 'Bubblesheet format file',
483: col2 => ''},
484: {col1 => 'Bubblesheet data upload formats',
485: col2 => 'Settings'}],
1.230 raeburn 486: print => \&print_scantron,
487: modify => \&modify_scantron,
1.46 raeburn 488: },
1.86 raeburn 489: 'requestcourses' =>
490: {text => 'Request creation of courses',
491: help => 'Domain_Configuration_Request_Courses',
492: header => [{col1 => 'User affiliation',
1.102 raeburn 493: col2 => 'Availability/Processing of requests',},
494: {col1 => 'Setting',
1.216 raeburn 495: col2 => 'Value'},
496: {col1 => 'Available textbooks',
1.235 raeburn 497: col2 => ''},
1.242 raeburn 498: {col1 => 'Available templates',
499: col2 => ''},
1.235 raeburn 500: {col1 => 'Validation (not official courses)',
501: col2 => 'Value'},],
1.230 raeburn 502: print => \&print_quotas,
503: modify => \&modify_quotas,
1.86 raeburn 504: },
1.163 raeburn 505: 'requestauthor' =>
1.223 bisitz 506: {text => 'Request Authoring Space',
1.163 raeburn 507: help => 'Domain_Configuration_Request_Author',
508: header => [{col1 => 'User affiliation',
509: col2 => 'Availability/Processing of requests',},
510: {col1 => 'Setting',
511: col2 => 'Value'}],
1.230 raeburn 512: print => \&print_quotas,
513: modify => \&modify_quotas,
1.163 raeburn 514: },
1.69 raeburn 515: 'coursecategories' =>
1.120 raeburn 516: { text => 'Cataloging of courses/communities',
1.67 raeburn 517: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 518: header => [{col1 => 'Catalog type/availability',
519: col2 => '',},
520: {col1 => 'Category settings for standard catalog',
1.57 raeburn 521: col2 => '',},
522: {col1 => 'Categories',
523: col2 => '',
524: }],
1.230 raeburn 525: print => \&print_coursecategories,
526: modify => \&modify_coursecategories,
1.69 raeburn 527: },
528: 'serverstatuses' =>
1.77 raeburn 529: {text => 'Access to server status pages',
1.69 raeburn 530: help => 'Domain_Configuration_Server_Status',
531: header => [{col1 => 'Status Page',
532: col2 => 'Other named users',
533: col3 => 'Specific IPs',
534: }],
1.230 raeburn 535: print => \&print_serverstatuses,
536: modify => \&modify_serverstatuses,
1.69 raeburn 537: },
1.118 jms 538: 'helpsettings' =>
1.282 raeburn 539: {text => 'Support settings',
1.118 jms 540: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 541: header => [{col1 => 'Help Page Settings (logged-in users)',
542: col2 => 'Value'},
543: {col1 => 'Helpdesk Roles',
544: col2 => 'Settings'},],
1.230 raeburn 545: print => \&print_helpsettings,
546: modify => \&modify_helpsettings,
1.118 jms 547: },
1.121 raeburn 548: 'coursedefaults' =>
549: {text => 'Course/Community defaults',
550: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 551: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
552: col2 => 'Value',},
553: {col1 => 'Defaults which can be overridden for each course by a DC',
554: col2 => 'Value',},],
1.230 raeburn 555: print => \&print_coursedefaults,
556: modify => \&modify_coursedefaults,
1.121 raeburn 557: },
1.231 raeburn 558: 'selfenrollment' =>
559: {text => 'Self-enrollment in Course/Community',
560: help => 'Domain_Configuration_Selfenrollment',
561: header => [{col1 => 'Configuration Rights',
562: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
563: {col1 => 'Defaults',
564: col2 => 'Value'},
565: {col1 => 'Self-enrollment validation (optional)',
566: col2 => 'Value'},],
567: print => \&print_selfenrollment,
568: modify => \&modify_selfenrollment,
569: },
1.120 raeburn 570: 'privacy' =>
1.427 raeburn 571: {text => 'Role assignments and user privacy',
1.120 raeburn 572: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 573: header => [{col1 => 'Role assigned in different domain',
574: col2 => 'Approval options'},
575: {col1 => 'Role assigned in different domain to user of type',
576: col2 => 'User information available in that domain'},
577: {col1 => "Role assigned in user's domain",
578: col2 => 'Information viewable by privileged user'},
579: {col1 => "Role assigned in user's domain",
580: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 581: print => \&print_privacy,
582: modify => \&modify_privacy,
1.120 raeburn 583: },
1.141 raeburn 584: 'usersessions' =>
1.145 raeburn 585: {text => 'User session hosting/offloading',
1.137 raeburn 586: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 587: header => [{col1 => 'Domain server',
588: col2 => 'Servers to offload sessions to when busy'},
589: {col1 => 'Hosting of users from other domains',
1.137 raeburn 590: col2 => 'Rules'},
591: {col1 => "Hosting domain's own users elsewhere",
592: col2 => 'Rules'}],
1.230 raeburn 593: print => \&print_usersessions,
594: modify => \&modify_usersessions,
1.137 raeburn 595: },
1.279 raeburn 596: 'loadbalancing' =>
1.185 raeburn 597: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 598: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 599: header => [{col1 => 'Balancers',
1.150 raeburn 600: col2 => 'Default destinations',
1.183 bisitz 601: col3 => 'User affiliation',
1.150 raeburn 602: col4 => 'Overrides'},
603: ],
1.230 raeburn 604: print => \&print_loadbalancing,
605: modify => \&modify_loadbalancing,
1.150 raeburn 606: },
1.425 raeburn 607: 'ltitools' =>
1.267 raeburn 608: {text => 'External Tools (LTI)',
1.296 raeburn 609: help => 'Domain_Configuration_LTI_Tools',
1.421 raeburn 610: header => [{col1 => 'Encryption of shared secrets',
611: col2 => 'Settings'},
612: {col1 => 'Rules for shared secrets',
613: col2 => 'Settings'},
614: {col1 => 'Providers',
615: col2 => 'Settings',}],
1.267 raeburn 616: print => \&print_ltitools,
617: modify => \&modify_ltitools,
618: },
1.372 raeburn 619: 'proctoring' =>
620: {text => 'Remote Proctoring Integration',
621: help => 'Domain_Configuration_Proctoring',
622: header => [{col1 => 'Name',
623: col2 => 'Configuration'}],
624: print => \&print_proctoring,
625: modify => \&modify_proctoring,
626: },
1.279 raeburn 627: 'ssl' =>
1.275 raeburn 628: {text => 'LON-CAPA Network (SSL)',
629: help => 'Domain_Configuration_Network_SSL',
630: header => [{col1 => 'Server',
631: col2 => 'Certificate Status'},
632: {col1 => 'Connections to other servers',
633: col2 => 'Rules'},
1.293 raeburn 634: {col1 => 'Connections from other servers',
635: col2 => 'Rules'},
1.275 raeburn 636: {col1 => "Replicating domain's published content",
637: col2 => 'Rules'}],
638: print => \&print_ssl,
639: modify => \&modify_ssl,
640: },
1.279 raeburn 641: 'trust' =>
642: {text => 'Trust Settings',
643: help => 'Domain_Configuration_Trust',
644: header => [{col1 => "Access to this domain's content by others",
645: col2 => 'Rules'},
646: {col1 => "Access to other domain's content by this domain",
647: col2 => 'Rules'},
648: {col1 => "Enrollment in this domain's courses by others",
649: col2 => 'Rules',},
650: {col1 => "Co-author roles in this domain for others",
651: col2 => 'Rules',},
652: {col1 => "Co-author roles for this domain's users elsewhere",
653: col2 => 'Rules',},
654: {col1 => "Domain roles in this domain assignable to others",
655: col2 => 'Rules'},
656: {col1 => "Course catalog for this domain displayed elsewhere",
657: col2 => 'Rules'},
658: {col1 => "Requests for creation of courses in this domain by others",
659: col2 => 'Rules'},
660: {col1 => "Users in other domains can send messages to this domain",
661: col2 => 'Rules'},],
662: print => \&print_trust,
663: modify => \&modify_trust,
664: },
1.425 raeburn 665: 'lti' =>
1.405 raeburn 666: {text => 'LTI Link Protection and LTI Consumers',
1.320 raeburn 667: help => 'Domain_Configuration_LTI_Provider',
1.405 raeburn 668: header => [{col1 => 'Encryption of shared secrets',
669: col2 => 'Settings'},
1.425 raeburn 670: {col1 => 'Rules for shared secrets',
1.405 raeburn 671: col2 => 'Settings'},
1.406 raeburn 672: {col1 => 'Link Protectors',
1.405 raeburn 673: col2 => 'Settings'},
674: {col1 => 'Consumers',
675: col2 => 'Settings'},],
1.320 raeburn 676: print => \&print_lti,
677: modify => \&modify_lti,
678: },
1.425 raeburn 679: 'ipaccess' =>
1.394 raeburn 680: {text => 'IP-based access control',
681: help => 'Domain_Configuration_IP_Access',
682: header => [{col1 => 'Setting',
683: col2 => 'Value'},],
684: print => \&print_ipaccess,
685: modify => \&modify_ipaccess,
686: },
1.429 ! raeburn 687: 'authordefaults' =>
! 688: {text => 'Authoring Space defaults',
! 689: help => 'Domain_Configuration_Author_Defaults',
! 690: header => [{col1 => 'Defaults which can be overridden by Author',
! 691: col2 => 'Settings',},
! 692: {col1 => 'Defaults which can be overridden by a Dom. Coord.',
! 693: col2 => 'Settings',},],
! 694: print => \&print_authordefaults,
! 695: modify => \&modify_authordefaults,
! 696: },
1.3 raeburn 697: );
1.110 raeburn 698: if (keys(%servers) > 1) {
699: $prefs{'login'} = { text => 'Log-in page options',
700: help => 'Domain_Configuration_Login_Page',
701: header => [{col1 => 'Log-in Service',
702: col2 => 'Server Setting',},
703: {col1 => 'Log-in Page Items',
1.405 raeburn 704: col2 => 'Settings'},
1.168 raeburn 705: {col1 => 'Log-in Help',
1.256 raeburn 706: col2 => 'Value'},
707: {col1 => 'Custom HTML in document head',
1.386 raeburn 708: col2 => 'Value'},
709: {col1 => 'SSO',
710: col2 => 'Dual login: SSO and non-SSO options'},
711: ],
1.230 raeburn 712: print => \&print_login,
713: modify => \&modify_login,
1.110 raeburn 714: };
715: }
1.174 foxr 716:
1.6 raeburn 717: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 718: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 719: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 720: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 721: text=>"Settings to display/modify"});
1.9 raeburn 722: my $confname = $dom.'-domainconfig';
1.174 foxr 723:
1.3 raeburn 724: if ($phase eq 'process') {
1.212 raeburn 725: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
726: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 727: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 728: $r->rflush();
1.212 raeburn 729: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 730: }
1.30 raeburn 731: } elsif ($phase eq 'display') {
1.192 raeburn 732: my $js = &recaptcha_js().
1.236 raeburn 733: &toggle_display_js();
1.171 raeburn 734: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 735: my ($othertitle,$usertypes,$types) =
736: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 737: $js .= &lonbalance_targets_js($dom,$types,\%servers,
738: $domconfig{'loadbalancing'}).
1.170 raeburn 739: &new_spares_js().
740: &common_domprefs_js().
741: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 742: }
1.216 raeburn 743: if (grep(/^requestcourses$/,@actions)) {
744: my $javascript_validations;
745: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
746: $js .= <<END;
747: <script type="text/javascript">
748: $javascript_validations
749: </script>
750: $coursebrowserjs
751: END
1.394 raeburn 752: } elsif (grep(/^ipaccess$/,@actions)) {
753: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 754: }
1.305 raeburn 755: if (grep(/^selfcreation$/,@actions)) {
756: $js .= &selfcreate_javascript();
757: }
1.286 raeburn 758: if (grep(/^contacts$/,@actions)) {
759: $js .= &contacts_javascript();
760: }
1.346 raeburn 761: if (grep(/^scantron$/,@actions)) {
762: $js .= &scantron_javascript();
763: }
1.150 raeburn 764: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 765: } else {
1.180 raeburn 766: # check if domconfig user exists for the domain.
767: my $servadm = $r->dir_config('lonAdmEMail');
768: my ($configuserok,$author_ok,$switchserver) =
769: &config_check($dom,$confname,$servadm);
770: unless ($configuserok eq 'ok') {
1.181 raeburn 771: &Apache::lonconfigsettings::print_header($r,$phase,$context);
772: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 773: $confname).
1.181 raeburn 774: '<br />'
775: );
1.180 raeburn 776: if ($switchserver) {
1.181 raeburn 777: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
778: '<br />'.
779: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
780: '<br />'.
781: &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).
782: '<br />'.
783: &mt('To do that now, use the following link: [_1]',$switchserver)
784: );
785: } else {
786: $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.').
787: '<br />'.
788: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
789: );
1.180 raeburn 790: }
791: $r->print(&Apache::loncommon::end_page());
792: return OK;
793: }
1.21 raeburn 794: if (keys(%domconfig) == 0) {
795: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 796: my @ids=&Apache::lonnet::current_machine_ids();
797: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 798: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 799: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 800: my $custom_img_count = 0;
801: foreach my $img (@loginimages) {
802: if ($designhash{$dom.'.login.'.$img} ne '') {
803: $custom_img_count ++;
804: }
805: }
806: foreach my $role (@roles) {
807: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
808: $custom_img_count ++;
809: }
810: }
811: if ($custom_img_count > 0) {
1.94 raeburn 812: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 813: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 814: $r->print(
815: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
816: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
817: &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 />'.
818: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
819: if ($switch_server) {
1.30 raeburn 820: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 821: }
1.91 raeburn 822: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 823: return OK;
824: }
825: }
826: }
1.91 raeburn 827: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 828: }
829: return OK;
830: }
831:
832: sub process_changes {
1.205 raeburn 833: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 834: my %domconfig;
835: if (ref($values) eq 'HASH') {
836: %domconfig = %{$values};
837: }
1.3 raeburn 838: my $output;
839: if ($action eq 'login') {
1.205 raeburn 840: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 841: } elsif ($action eq 'rolecolors') {
1.9 raeburn 842: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 843: $lastactref,%domconfig);
1.3 raeburn 844: } elsif ($action eq 'quotas') {
1.216 raeburn 845: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 846: } elsif ($action eq 'autoenroll') {
1.205 raeburn 847: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 848: } elsif ($action eq 'autoupdate') {
849: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 850: } elsif ($action eq 'autocreate') {
851: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 852: } elsif ($action eq 'directorysrch') {
1.295 raeburn 853: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 854: } elsif ($action eq 'usercreation') {
1.28 raeburn 855: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 856: } elsif ($action eq 'selfcreation') {
1.305 raeburn 857: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 858: } elsif ($action eq 'usermodification') {
859: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 860: } elsif ($action eq 'contacts') {
1.205 raeburn 861: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 862: } elsif ($action eq 'defaults') {
1.212 raeburn 863: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 864: } elsif ($action eq 'scantron') {
1.205 raeburn 865: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 866: } elsif ($action eq 'coursecategories') {
1.239 raeburn 867: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 868: } elsif ($action eq 'serverstatuses') {
869: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 870: } elsif ($action eq 'requestcourses') {
1.216 raeburn 871: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 872: } elsif ($action eq 'requestauthor') {
1.216 raeburn 873: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 874: } elsif ($action eq 'helpsettings') {
1.285 raeburn 875: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 876: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 877: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 878: } elsif ($action eq 'selfenrollment') {
879: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 880: } elsif ($action eq 'usersessions') {
1.212 raeburn 881: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 882: } elsif ($action eq 'loadbalancing') {
883: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 884: } elsif ($action eq 'ltitools') {
885: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 886: } elsif ($action eq 'proctoring') {
887: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 888: } elsif ($action eq 'ssl') {
889: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 890: } elsif ($action eq 'trust') {
891: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 892: } elsif ($action eq 'lti') {
893: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 894: } elsif ($action eq 'privacy') {
1.427 raeburn 895: $output = &modify_privacy($dom,$lastactref,%domconfig);
1.354 raeburn 896: } elsif ($action eq 'passwords') {
897: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 898: } elsif ($action eq 'wafproxy') {
899: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 900: } elsif ($action eq 'ipaccess') {
901: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.429 ! raeburn 902: } elsif ($action eq 'authordefaults') {
! 903: $output = &modify_authordefaults($dom,$lastactref,%domconfig);
1.3 raeburn 904: }
905: return $output;
906: }
907:
908: sub print_config_box {
1.9 raeburn 909: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 910: my $rowtotal = 0;
1.49 raeburn 911: my $output;
912: if ($action eq 'coursecategories') {
913: $output = &coursecategories_javascript($settings);
1.236 raeburn 914: } elsif ($action eq 'defaults') {
915: $output = &defaults_javascript($settings);
1.354 raeburn 916: } elsif ($action eq 'passwords') {
1.405 raeburn 917: $output = &passwords_javascript($action);
1.282 raeburn 918: } elsif ($action eq 'helpsettings') {
919: my (%privs,%levelscurrent);
920: my %full=();
921: my %levels=(
922: course => {},
923: domain => {},
924: system => {},
925: );
926: my $context = 'domain';
927: my $crstype = 'Course';
928: my $formname = 'display';
929: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
930: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
931: $output =
1.425 raeburn 932: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
1.282 raeburn 933: \@templateroles);
1.334 raeburn 934: } elsif ($action eq 'ltitools') {
1.421 raeburn 935: $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
1.334 raeburn 936: } elsif ($action eq 'lti') {
1.421 raeburn 937: $output .= &passwords_javascript('ltisecrets')."\n".
1.405 raeburn 938: <i_javascript($dom,$settings);
1.372 raeburn 939: } elsif ($action eq 'proctoring') {
940: $output .= &proctoring_javascript($settings);
1.381 raeburn 941: } elsif ($action eq 'wafproxy') {
942: $output .= &wafproxy_javascript($dom);
1.385 raeburn 943: } elsif ($action eq 'autoupdate') {
944: $output .= &autoupdate_javascript();
1.399 raeburn 945: } elsif ($action eq 'autoenroll') {
946: $output .= &autoenroll_javascript();
1.386 raeburn 947: } elsif ($action eq 'login') {
948: $output .= &saml_javascript();
1.394 raeburn 949: } elsif ($action eq 'ipaccess') {
950: $output .= &ipaccess_javascript($settings);
1.429 ! raeburn 951: } elsif ($action eq 'authordefaults') {
! 952: $output .= &authordefaults_javascript();
1.91 raeburn 953: }
1.236 raeburn 954: $output .=
1.30 raeburn 955: '<table class="LC_nested_outer">
1.3 raeburn 956: <tr>
1.306 raeburn 957: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 958: &mt($item->{text}).' '.
959: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
960: '</tr>';
1.30 raeburn 961: $rowtotal ++;
1.110 raeburn 962: my $numheaders = 1;
963: if (ref($item->{'header'}) eq 'ARRAY') {
964: $numheaders = scalar(@{$item->{'header'}});
965: }
966: if ($numheaders > 1) {
1.64 raeburn 967: my $colspan = '';
1.145 raeburn 968: my $rightcolspan = '';
1.369 raeburn 969: my $leftnobr = '';
1.238 raeburn 970: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 971: ($action eq 'directorysrch') ||
1.386 raeburn 972: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 973: $colspan = ' colspan="2"';
974: }
1.145 raeburn 975: if ($action eq 'usersessions') {
976: $rightcolspan = ' colspan="3"';
977: }
1.369 raeburn 978: if ($action eq 'passwords') {
979: $leftnobr = ' LC_nobreak';
980: }
1.30 raeburn 981: $output .= '
1.3 raeburn 982: <tr>
983: <td>
984: <table class="LC_nested">
985: <tr class="LC_info_row">
1.369 raeburn 986: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 987: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 988: </tr>';
1.69 raeburn 989: $rowtotal ++;
1.230 raeburn 990: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 991: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 992: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 993: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.421 raeburn 994: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') ||
1.429 ! raeburn 995: ($action eq 'lti') || ($action eq 'ltitools') || ($action eq 'authordefaults')) {
1.230 raeburn 996: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 997: } elsif ($action eq 'passwords') {
998: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 999: } elsif ($action eq 'coursecategories') {
1.230 raeburn 1000: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 1001: } elsif ($action eq 'scantron') {
1002: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 1003: } elsif ($action eq 'login') {
1.386 raeburn 1004: if ($numheaders == 5) {
1.168 raeburn 1005: $colspan = ' colspan="2"';
1006: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
1007: } else {
1008: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
1009: }
1.230 raeburn 1010: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 1011: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 1012: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1013: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 1014: }
1.30 raeburn 1015: $output .= '
1.6 raeburn 1016: </table>
1017: </td>
1018: </tr>
1019: <tr>
1020: <td>
1021: <table class="LC_nested">
1022: <tr class="LC_info_row">
1.230 raeburn 1023: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 1024: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 1025: </tr>';
1026: $rowtotal ++;
1.230 raeburn 1027: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
1028: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 1029: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 1030: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.421 raeburn 1031: ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti') ||
1032: ($action eq 'ltitools')) {
1.238 raeburn 1033: if ($action eq 'coursecategories') {
1034: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
1035: $colspan = ' colspan="2"';
1.279 raeburn 1036: } elsif ($action eq 'trust') {
1037: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 1038: } elsif ($action eq 'passwords') {
1039: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 1040: } else {
1041: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1042: }
1.279 raeburn 1043: if ($action eq 'trust') {
1044: $output .= '
1045: </table>
1046: </td>
1047: </tr>';
1048: my @trusthdrs = qw(2 3 4 5 6 7);
1049: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1050: for (my $i=0; $i<@trusthdrs; $i++) {
1051: $output .= '
1052: <tr>
1053: <td>
1054: <table class="LC_nested">
1055: <tr class="LC_info_row">
1056: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1057: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1058: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1059: </table>
1060: </td>
1061: </tr>';
1062: }
1063: $output .= '
1064: <tr>
1065: <td>
1066: <table class="LC_nested">
1067: <tr class="LC_info_row">
1068: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1069: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1070: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1071: } else {
1072: $output .= '
1.63 raeburn 1073: </table>
1074: </td>
1075: </tr>
1076: <tr>
1077: <td>
1078: <table class="LC_nested">
1079: <tr class="LC_info_row">
1080: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 1081: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 1082: </tr>'."\n";
1.279 raeburn 1083: if ($action eq 'coursecategories') {
1084: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405 raeburn 1085: } elsif (($action eq 'contacts') || ($action eq 'privacy') ||
1086: ($action eq 'passwords') || ($action eq 'lti')) {
1.354 raeburn 1087: if ($action eq 'passwords') {
1088: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1089: } else {
1090: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1091: }
1092: $output .= '
1.340 raeburn 1093: </tr>
1094: </table>
1095: </td>
1096: </tr>
1097: <tr>
1098: <td>
1099: <table class="LC_nested">
1100: <tr class="LC_info_row">
1.369 raeburn 1101: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 1102: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1103: if ($action eq 'passwords') {
1104: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1105: } else {
1106: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1107: }
1108: $output .= '
1.340 raeburn 1109: </table>
1110: </td>
1111: </tr>
1112: <tr>';
1.279 raeburn 1113: } else {
1114: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1115: }
1.238 raeburn 1116: }
1.63 raeburn 1117: $rowtotal ++;
1.236 raeburn 1118: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.409 raeburn 1119: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1.429 ! raeburn 1120: ($action eq 'wafproxy') || ($action eq 'authordefaults')) {
1.230 raeburn 1121: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1122: } elsif ($action eq 'scantron') {
1123: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1124: } elsif ($action eq 'ssl') {
1125: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1126: </table>
1127: </td>
1128: </tr>
1129: <tr>
1130: <td>
1131: <table class="LC_nested">
1132: <tr class="LC_info_row">
1133: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1134: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1135: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1136: </table>
1137: </td>
1138: </tr>
1139: <tr>
1140: <td>
1141: <table class="LC_nested">
1142: <tr class="LC_info_row">
1143: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1144: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1145: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1146: } elsif ($action eq 'login') {
1.386 raeburn 1147: if ($numheaders == 5) {
1.168 raeburn 1148: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1149: </table>
1150: </td>
1151: </tr>
1152: <tr>
1153: <td>
1154: <table class="LC_nested">
1155: <tr class="LC_info_row">
1156: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1157: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1158: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1159: $rowtotal ++;
1160: } else {
1161: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1162: }
1.256 raeburn 1163: $output .= '
1164: </table>
1165: </td>
1166: </tr>
1167: <tr>
1168: <td>
1169: <table class="LC_nested">
1170: <tr class="LC_info_row">';
1.386 raeburn 1171: if ($numheaders == 5) {
1.256 raeburn 1172: $output .= '
1173: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1174: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1175: </tr>';
1176: } else {
1177: $output .= '
1178: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1179: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1180: </tr>';
1181: }
1182: $rowtotal ++;
1.386 raeburn 1183: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1184: </table>
1185: </td>
1186: </tr>
1187: <tr>
1188: <td>
1189: <table class="LC_nested">
1190: <tr class="LC_info_row">';
1191: if ($numheaders == 5) {
1192: $output .= '
1193: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1194: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1195: </tr>';
1196: } else {
1197: $output .= '
1198: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1199: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1200: </tr>';
1201: }
1202: $rowtotal ++;
1203: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1204: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1205: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1206: $rowtotal ++;
1207: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1208: </table>
1209: </td>
1210: </tr>
1211: <tr>
1212: <td>
1213: <table class="LC_nested">
1214: <tr class="LC_info_row">
1215: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1216: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1217: &textbookcourses_javascript($settings).
1218: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1219: </table>
1220: </td>
1221: </tr>
1222: <tr>
1223: <td>
1224: <table class="LC_nested">
1225: <tr class="LC_info_row">
1226: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1227: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1228: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1229: </table>
1230: </td>
1231: </tr>
1232: <tr>
1233: <td>
1234: <table class="LC_nested">
1235: <tr class="LC_info_row">
1.306 raeburn 1236: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1237: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1238: </tr>'.
1239: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1240: } elsif ($action eq 'requestauthor') {
1241: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1242: $rowtotal ++;
1.122 jms 1243: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1244: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1245: </table>
1246: </td>
1247: </tr>
1248: <tr>
1249: <td>
1250: <table class="LC_nested">
1251: <tr class="LC_info_row">
1.306 raeburn 1252: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1253: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1254: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1255: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1256: </tr>'.
1.30 raeburn 1257: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1258: </table>
1259: </td>
1260: </tr>
1261: <tr>
1262: <td>
1263: <table class="LC_nested">
1264: <tr class="LC_info_row">
1.59 bisitz 1265: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1266: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1267: </tr>'.
1.30 raeburn 1268: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1269: $rowtotal += 2;
1.6 raeburn 1270: }
1.3 raeburn 1271: } else {
1.30 raeburn 1272: $output .= '
1.3 raeburn 1273: <tr>
1274: <td>
1275: <table class="LC_nested">
1.30 raeburn 1276: <tr class="LC_info_row">';
1.277 raeburn 1277: if ($action eq 'login') {
1.30 raeburn 1278: $output .= '
1.59 bisitz 1279: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1280: } elsif ($action eq 'serverstatuses') {
1281: $output .= '
1.306 raeburn 1282: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1283: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1284:
1.6 raeburn 1285: } else {
1.30 raeburn 1286: $output .= '
1.306 raeburn 1287: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1288: }
1.72 raeburn 1289: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1290: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1291: &mt($item->{'header'}->[0]->{'col2'});
1292: if ($action eq 'serverstatuses') {
1293: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1294: }
1.69 raeburn 1295: } else {
1.306 raeburn 1296: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1297: &mt($item->{'header'}->[0]->{'col2'});
1298: }
1299: $output .= '</td>';
1300: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1301: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1302: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1303: &mt($item->{'header'}->[0]->{'col3'});
1304: } else {
1.306 raeburn 1305: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1306: &mt($item->{'header'}->[0]->{'col3'});
1307: }
1.69 raeburn 1308: if ($action eq 'serverstatuses') {
1309: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1310: }
1311: $output .= '</td>';
1.6 raeburn 1312: }
1.150 raeburn 1313: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1314: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1315: &mt($item->{'header'}->[0]->{'col4'});
1316: }
1.69 raeburn 1317: $output .= '</tr>';
1.48 raeburn 1318: $rowtotal ++;
1.168 raeburn 1319: if ($action eq 'quotas') {
1.86 raeburn 1320: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1321: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1322: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.421 raeburn 1323: ($action eq 'proctoring') || ($action eq 'ipaccess')) {
1.230 raeburn 1324: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1325: }
1.3 raeburn 1326: }
1.30 raeburn 1327: $output .= '
1.3 raeburn 1328: </table>
1329: </td>
1330: </tr>
1.30 raeburn 1331: </table><br />';
1332: return ($output,$rowtotal);
1.1 raeburn 1333: }
1334:
1.3 raeburn 1335: sub print_login {
1.168 raeburn 1336: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1337: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1338: my %choices = &login_choices();
1.386 raeburn 1339: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1340: %lt = &login_file_options();
1341: $switchserver = &check_switchserver($dom,$confname);
1342: }
1.168 raeburn 1343: if ($caller eq 'service') {
1.149 raeburn 1344: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1345: my $choice = $choices{'disallowlogin'};
1346: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1347: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1348: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1349: '<th>'.$choices{'server'}.'</th>'.
1350: '<th>'.$choices{'serverpath'}.'</th>'.
1351: '<th>'.$choices{'custompath'}.'</th>'.
1352: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1353: my %disallowed;
1354: if (ref($settings) eq 'HASH') {
1355: if (ref($settings->{'loginvia'}) eq 'HASH') {
1356: %disallowed = %{$settings->{'loginvia'}};
1357: }
1358: }
1359: foreach my $lonhost (sort(keys(%servers))) {
1360: my $direct = 'selected="selected"';
1.128 raeburn 1361: if (ref($disallowed{$lonhost}) eq 'HASH') {
1362: if ($disallowed{$lonhost}{'server'} ne '') {
1363: $direct = '';
1364: }
1.110 raeburn 1365: }
1.115 raeburn 1366: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1367: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1368: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1369: '</option>';
1.184 raeburn 1370: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1371: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1372: my $selected = '';
1.128 raeburn 1373: if (ref($disallowed{$lonhost}) eq 'HASH') {
1374: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1375: $selected = 'selected="selected"';
1376: }
1.110 raeburn 1377: }
1378: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1379: $servers{$hostid}.'</option>';
1380: }
1.128 raeburn 1381: $datatable .= '</select></td>'.
1382: '<td><select name="'.$lonhost.'_serverpath">';
1383: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1384: my $pathname = $path;
1385: if ($path eq 'custom') {
1386: $pathname = &mt('Custom Path').' ->';
1387: }
1388: my $selected = '';
1389: if (ref($disallowed{$lonhost}) eq 'HASH') {
1390: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1391: $selected = 'selected="selected"';
1392: }
1393: } elsif ($path eq '') {
1394: $selected = 'selected="selected"';
1395: }
1396: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1397: }
1398: $datatable .= '</select></td>';
1399: my ($custom,$exempt);
1400: if (ref($disallowed{$lonhost}) eq 'HASH') {
1401: $custom = $disallowed{$lonhost}{'custompath'};
1402: $exempt = $disallowed{$lonhost}{'exempt'};
1403: }
1404: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1405: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1406: '</tr>';
1.110 raeburn 1407: }
1408: $datatable .= '</table></td></tr>';
1409: return $datatable;
1.168 raeburn 1410: } elsif ($caller eq 'page') {
1411: my %defaultchecked = (
1412: 'coursecatalog' => 'on',
1.188 raeburn 1413: 'helpdesk' => 'on',
1.168 raeburn 1414: 'adminmail' => 'off',
1415: 'newuser' => 'off',
1416: );
1.188 raeburn 1417: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1418: my (%checkedon,%checkedoff);
1.42 raeburn 1419: foreach my $item (@toggles) {
1.168 raeburn 1420: if ($defaultchecked{$item} eq 'on') {
1421: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1422: $checkedoff{$item} = ' ';
1.168 raeburn 1423: } elsif ($defaultchecked{$item} eq 'off') {
1424: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1425: $checkedon{$item} = ' ';
1426: }
1.1 raeburn 1427: }
1.168 raeburn 1428: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1429: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1430: my @logintext = ('textcol','bgcol');
1431: my @bgs = ('pgbg','mainbg','sidebg');
1432: my @links = ('link','alink','vlink');
1433: my %designhash = &Apache::loncommon::get_domainconf($dom);
1434: my %defaultdesign = %Apache::loncommon::defaultdesign;
1435: my (%is_custom,%designs);
1436: my %defaults = (
1437: font => $defaultdesign{'login.font'},
1438: );
1.6 raeburn 1439: foreach my $item (@images) {
1.168 raeburn 1440: $defaults{$item} = $defaultdesign{'login.'.$item};
1441: $defaults{'showlogo'}{$item} = 1;
1442: }
1443: foreach my $item (@bgs) {
1444: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1445: }
1.41 raeburn 1446: foreach my $item (@logintext) {
1.168 raeburn 1447: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1448: }
1.168 raeburn 1449: foreach my $item (@links) {
1450: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1451: }
1.168 raeburn 1452: if (ref($settings) eq 'HASH') {
1453: foreach my $item (@toggles) {
1454: if ($settings->{$item} eq '1') {
1455: $checkedon{$item} = ' checked="checked" ';
1456: $checkedoff{$item} = ' ';
1457: } elsif ($settings->{$item} eq '0') {
1458: $checkedoff{$item} = ' checked="checked" ';
1459: $checkedon{$item} = ' ';
1460: }
1461: }
1462: foreach my $item (@images) {
1463: if (defined($settings->{$item})) {
1464: $designs{$item} = $settings->{$item};
1465: $is_custom{$item} = 1;
1466: }
1467: if (defined($settings->{'showlogo'}{$item})) {
1468: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1469: }
1470: }
1.402 raeburn 1471: foreach my $item (@alttext) {
1472: if (ref($settings->{'alttext'}) eq 'HASH') {
1473: if ($settings->{'alttext'}->{$item} ne '') {
1474: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1475: }
1476: }
1477: }
1.168 raeburn 1478: foreach my $item (@logintext) {
1479: if ($settings->{$item} ne '') {
1480: $designs{'logintext'}{$item} = $settings->{$item};
1481: $is_custom{$item} = 1;
1482: }
1483: }
1484: if ($settings->{'font'} ne '') {
1485: $designs{'font'} = $settings->{'font'};
1486: $is_custom{'font'} = 1;
1487: }
1488: foreach my $item (@bgs) {
1489: if ($settings->{$item} ne '') {
1490: $designs{'bgs'}{$item} = $settings->{$item};
1491: $is_custom{$item} = 1;
1492: }
1493: }
1494: foreach my $item (@links) {
1495: if ($settings->{$item} ne '') {
1496: $designs{'links'}{$item} = $settings->{$item};
1497: $is_custom{$item} = 1;
1498: }
1499: }
1500: } else {
1501: if ($designhash{$dom.'.login.font'} ne '') {
1502: $designs{'font'} = $designhash{$dom.'.login.font'};
1503: $is_custom{'font'} = 1;
1504: }
1505: foreach my $item (@images) {
1506: if ($designhash{$dom.'.login.'.$item} ne '') {
1507: $designs{$item} = $designhash{$dom.'.login.'.$item};
1508: $is_custom{$item} = 1;
1509: }
1510: }
1511: foreach my $item (@bgs) {
1512: if ($designhash{$dom.'.login.'.$item} ne '') {
1513: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1514: $is_custom{$item} = 1;
1515: }
1.6 raeburn 1516: }
1.168 raeburn 1517: foreach my $item (@links) {
1518: if ($designhash{$dom.'.login.'.$item} ne '') {
1519: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1520: $is_custom{$item} = 1;
1521: }
1.6 raeburn 1522: }
1523: }
1.168 raeburn 1524: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1525: logo => 'Institution Logo',
1526: domlogo => 'Domain Logo',
1527: login => 'Login box');
1528: my $itemcount = 1;
1529: foreach my $item (@toggles) {
1530: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1531: $datatable .=
1532: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1533: '</td><td>'.
1534: '<span class="LC_nobreak"><label><input type="radio" name="'.
1535: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1536: '</label> <label><input type="radio" name="'.$item.'"'.
1537: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1538: '</tr>';
1539: $itemcount ++;
1.6 raeburn 1540: }
1.168 raeburn 1541: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1542: $datatable .= '</tr></table></td></tr>';
1543: } elsif ($caller eq 'help') {
1.386 raeburn 1544: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1545: my $itemcount = 1;
1546: $defaulturl = '/adm/loginproblems.html';
1547: $defaulttype = 'default';
1548: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1549: my @currlangs;
1550: if (ref($settings) eq 'HASH') {
1551: if (ref($settings->{'helpurl'}) eq 'HASH') {
1552: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1553: next if ($settings->{'helpurl'}{$key} eq '');
1554: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1555: $type{$key} = 'custom';
1556: unless ($key eq 'nolang') {
1557: push(@currlangs,$key);
1558: }
1559: }
1560: } elsif ($settings->{'helpurl'} ne '') {
1561: $type{'nolang'} = 'custom';
1562: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1563: }
1564: }
1.168 raeburn 1565: foreach my $lang ('nolang',sort(@currlangs)) {
1566: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1567: $datatable .= '<tr'.$css_class.'>';
1568: if ($url{$lang} eq '') {
1569: $url{$lang} = $defaulturl;
1570: }
1571: if ($type{$lang} eq '') {
1572: $type{$lang} = $defaulttype;
1573: }
1574: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1575: if ($lang eq 'nolang') {
1576: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1577: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1578: } else {
1579: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1580: $langchoices{$lang},
1581: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1582: }
1583: $datatable .= '</span></td>'."\n".
1584: '<td class="LC_left_item">';
1585: if ($type{$lang} eq 'custom') {
1586: $datatable .= '<span class="LC_nobreak"><label>'.
1587: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1588: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1589: } else {
1590: $datatable .= $lt{'upl'};
1591: }
1592: $datatable .='<br />';
1593: if ($switchserver) {
1594: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1595: } else {
1596: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1597: }
1.168 raeburn 1598: $datatable .= '</td></tr>';
1599: $itemcount ++;
1.6 raeburn 1600: }
1.168 raeburn 1601: my @addlangs;
1602: foreach my $lang (sort(keys(%langchoices))) {
1603: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1604: push(@addlangs,$lang);
1605: }
1606: if (@addlangs > 0) {
1607: my %toadd;
1608: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1609: $toadd{''} = &mt('Select');
1610: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1611: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1612: &mt('Add log-in help page for a specific language:').' '.
1613: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1614: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1615: if ($switchserver) {
1616: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1617: } else {
1618: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1619: }
1.168 raeburn 1620: $datatable .= '</td></tr>';
1.169 raeburn 1621: $itemcount ++;
1.6 raeburn 1622: }
1.169 raeburn 1623: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1624: } elsif ($caller eq 'headtag') {
1625: my %domservers = &Apache::lonnet::get_servers($dom);
1626: my $choice = $choices{'headtag'};
1627: $css_class = ' class="LC_odd_row"';
1628: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1629: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1630: '<th>'.$choices{'current'}.'</th>'.
1631: '<th>'.$choices{'action'}.'</th>'.
1632: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1633: my (%currurls,%currexempt);
1634: if (ref($settings) eq 'HASH') {
1635: if (ref($settings->{'headtag'}) eq 'HASH') {
1636: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1637: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1638: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1639: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1640: }
1641: }
1642: }
1643: }
1644: foreach my $lonhost (sort(keys(%domservers))) {
1645: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1646: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1647: if ($currurls{$lonhost}) {
1648: $datatable .= '<td class="LC_right_item"><a href="'.
1649: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1650: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1651: '">'.$lt{'curr'}.'</a></td>'.
1652: '<td><span class="LC_nobreak"><label>'.
1653: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1654: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1655: } else {
1656: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1657: }
1658: $datatable .='<br />';
1659: if ($switchserver) {
1660: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1661: } else {
1662: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1663: }
1.330 raeburn 1664: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1665: }
1666: $datatable .= '</table></td></tr>';
1.386 raeburn 1667: } elsif ($caller eq 'saml') {
1668: my %domservers = &Apache::lonnet::get_servers($dom);
1669: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1670: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1671: '<th>'.$choices{'samllanding'}.'</th>'.
1672: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1673: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1674: foreach my $lonhost (keys(%domservers)) {
1675: $samlurl{$lonhost} = '/adm/sso';
1676: $styleon{$lonhost} = 'display:none';
1677: $styleoff{$lonhost} = '';
1678: }
1.411 raeburn 1679: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1680: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1681: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1682: $saml{$lonhost} = 1;
1683: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1684: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1685: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1686: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1687: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1688: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1689: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1690: $styleon{$lonhost} = '';
1691: $styleoff{$lonhost} = 'display:none';
1692: } else {
1693: $styleon{$lonhost} = 'display:none';
1694: $styleoff{$lonhost} = '';
1695: }
1696: }
1697: }
1698: my $itemcount = 1;
1699: foreach my $lonhost (sort(keys(%domservers))) {
1700: my $samlon = ' ';
1701: my $samloff = ' checked="checked" ';
1702: if ($saml{$lonhost}) {
1703: $samlon = $samloff;
1704: $samloff = ' ';
1705: }
1.412 raeburn 1706: my $samlwinon = '';
1707: my $samlwinoff = ' checked="checked"';
1708: if ($samlwindow{$lonhost}) {
1709: $samlwinon = $samlwinoff;
1710: $samlwinoff = '';
1711: }
1.386 raeburn 1712: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1713: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1714: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1715: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1716: &mt('No').'</label>'.(' 'x2).
1717: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1718: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1719: &mt('Yes').'</label></span></td>'.
1720: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1721: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1722: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1723: '<th>'.&mt('Alt Text').'</th></tr>'.
1724: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1725: $samltext{$lonhost}.'" /></td><td>';
1726: if ($samlimg{$lonhost}) {
1727: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1728: '<span class="LC_nobreak"><label>'.
1729: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1730: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1731: } else {
1732: $datatable .= $lt{'upl'};
1733: }
1734: $datatable .='<br />';
1735: if ($switchserver) {
1736: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1737: } else {
1738: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1739: }
1740: $datatable .= '</td>'.
1.412 raeburn 1741: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1742: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1743: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1744: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1745: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1746: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1747: '<tr'.$css_class.'>'.
1748: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1749: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1750: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1751: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1752: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1753: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1754: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1755: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1756: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1757: '</table></td>'.
1758: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1759: $itemcount ++;
1760: }
1761: $datatable .= '</table></td></tr>';
1.1 raeburn 1762: }
1.6 raeburn 1763: return $datatable;
1764: }
1765:
1766: sub login_choices {
1767: my %choices =
1768: &Apache::lonlocal::texthash (
1.116 bisitz 1769: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1770: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1771: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1772: disallowlogin => "Login page requests redirected",
1773: hostid => "Server",
1.128 raeburn 1774: server => "Redirect to:",
1775: serverpath => "Path",
1776: custompath => "Custom",
1777: exempt => "Exempt IP(s)",
1.110 raeburn 1778: directlogin => "No redirect",
1779: newuser => "Link to create a user account",
1780: img => "Header",
1781: logo => "Main Logo",
1782: domlogo => "Domain Logo",
1783: login => "Log-in Header",
1784: textcol => "Text color",
1785: bgcol => "Box color",
1786: bgs => "Background colors",
1787: links => "Link colors",
1788: font => "Font color",
1789: pgbg => "Header",
1790: mainbg => "Page",
1791: sidebg => "Login box",
1792: link => "Link",
1793: alink => "Active link",
1794: vlink => "Visited link",
1.256 raeburn 1795: headtag => "Custom markup",
1796: action => "Action",
1797: current => "Current",
1.386 raeburn 1798: samllanding => "Dual login?",
1799: samloptions => "Options",
1.402 raeburn 1800: alttext => "Alt text",
1.6 raeburn 1801: );
1802: return %choices;
1803: }
1804:
1.386 raeburn 1805: sub login_file_options {
1806: return &Apache::lonlocal::texthash(
1807: del => 'Delete?',
1808: rep => 'Replace:',
1809: upl => 'Upload:',
1810: curr => 'View contents',
1811: default => 'Default',
1812: custom => 'Custom',
1813: none => 'None',
1814: );
1815: }
1816:
1.394 raeburn 1817: sub print_ipaccess {
1818: my ($dom,$settings,$rowtotal) = @_;
1819: my $css_class;
1820: my $itemcount = 0;
1821: my $datatable;
1822: my %ordered;
1823: if (ref($settings) eq 'HASH') {
1824: foreach my $item (keys(%{$settings})) {
1825: if (ref($settings->{$item}) eq 'HASH') {
1826: my $num = $settings->{$item}{'order'};
1827: if ($num eq '') {
1828: $num = scalar(keys(%{$settings}));
1829: }
1830: $ordered{$num} = $item;
1831: }
1832: }
1833: }
1834: my $maxnum = scalar(keys(%ordered));
1835: if (keys(%ordered)) {
1836: my @items = sort { $a <=> $b } keys(%ordered);
1837: for (my $i=0; $i<@items; $i++) {
1838: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1839: my $item = $ordered{$items[$i]};
1840: my ($name,$ipranges,%commblocks,%courses);
1841: if (ref($settings->{$item}) eq 'HASH') {
1842: $name = $settings->{$item}->{'name'};
1843: $ipranges = $settings->{$item}->{'ip'};
1844: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1845: %commblocks = %{$settings->{$item}->{'commblocks'}};
1846: }
1847: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1848: %courses = %{$settings->{$item}->{'courses'}};
1849: }
1850: }
1851: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1852: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1853: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1854: for (my $k=0; $k<=$maxnum; $k++) {
1855: my $vpos = $k+1;
1856: my $selstr;
1857: if ($k == $i) {
1858: $selstr = ' selected="selected" ';
1859: }
1860: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1861: }
1862: $datatable .= '</select>'.(' 'x2).
1863: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1864: &mt('Delete?').'</label></span></td>'.
1865: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1866: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1867: '</td></tr>';
1868: $itemcount ++;
1869: }
1870: }
1871: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1872: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1873: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1874: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1875: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1876: for (my $k=0; $k<$maxnum+1; $k++) {
1877: my $vpos = $k+1;
1878: my $selstr;
1879: if ($k == $maxnum) {
1880: $selstr = ' selected="selected" ';
1881: }
1882: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1883: }
1884: $datatable .= '</select> '."\n".
1885: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1886: '<td colspan="2">'.
1887: &ipaccess_options('add',$itemcount,$dom).
1888: '</td>'."\n".
1889: '</tr>'."\n";
1890: $$rowtotal ++;
1891: return $datatable;
1892: }
1893:
1894: sub ipaccess_options {
1895: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1896: my (%currblocks,%currcourses,$output);
1897: if (ref($blocksref) eq 'HASH') {
1898: %currblocks = %{$blocksref};
1899: }
1900: if (ref($coursesref) eq 'HASH') {
1901: %currcourses = %{$coursesref};
1902: }
1903: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1904: '<span class="LC_nobreak">'.&mt('Name').': '.
1905: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1906: '</span></fieldset>'.
1907: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1908: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1909: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1910: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1911: $ipranges.'</textarea></fieldset>'.
1912: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1913: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1914: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1915: '<table>';
1916: foreach my $cid (sort(keys(%currcourses))) {
1917: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1918: $output .= '<tr><td><span class="LC_nobreak">'.
1919: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1920: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1921: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1922: }
1923: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1924: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1925: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1926: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1927: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1928: '</span></td></tr></table>'."\n".
1929: '</fieldset>';
1930: return $output;
1931: }
1932:
1933: sub blocker_checkboxes {
1934: my ($num,$blocks) = @_;
1935: my ($typeorder,$types) = &commblocktype_text();
1936: my $numinrow = 6;
1937: my $output = '<table>';
1938: for (my $i=0; $i<@{$typeorder}; $i++) {
1939: my $block = $typeorder->[$i];
1940: my $blockstatus;
1941: if (ref($blocks) eq 'HASH') {
1942: if ($blocks->{$block} eq 'on') {
1943: $blockstatus = 'checked="checked"';
1944: }
1945: }
1946: my $rem = $i%($numinrow);
1947: if ($rem == 0) {
1948: if ($i > 0) {
1949: $output .= '</tr>';
1950: }
1951: $output .= '<tr>';
1952: }
1953: if ($i == scalar(@{$typeorder})-1) {
1954: my $colsleft = $numinrow-$rem;
1955: if ($colsleft > 1) {
1956: $output .= '<td colspan="'.$colsleft.'">';
1957: } else {
1958: $output .= '<td>';
1959: }
1960: } else {
1961: $output .= '<td>';
1962: }
1963: my $item = 'ipaccess_block_'.$num;
1964: if ($blockstatus) {
1965: $blockstatus = ' '.$blockstatus;
1966: }
1967: $output .= '<span class="LC_nobreak"><label>'."\n".
1968: '<input type="checkbox" name="'.$item.'"'.
1969: $blockstatus.' value="'.$block.'"'.' />'.
1970: $types->{$block}.'</label></span>'."\n".
1971: '<br /></td>';
1972: }
1973: $output .= '</tr></table>';
1974: return $output;
1975: }
1976:
1977: sub commblocktype_text {
1978: my %types = &Apache::lonlocal::texthash(
1979: 'com' => 'Messaging',
1980: 'chat' => 'Chat Room',
1981: 'boards' => 'Discussion',
1982: 'port' => 'Portfolio',
1983: 'groups' => 'Groups',
1984: 'blogs' => 'Blogs',
1985: 'about' => 'User Information',
1986: 'printout' => 'Printouts',
1987: 'passwd' => 'Change Password',
1988: 'grades' => 'Gradebook',
1.397 raeburn 1989: 'search' => 'Course search',
1990: 'wishlist' => 'Stored links',
1991: 'annotate' => 'Annotations',
1.394 raeburn 1992: );
1.397 raeburn 1993: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394 raeburn 1994: return ($typeorder,\%types);
1995: }
1996:
1.6 raeburn 1997: sub print_rolecolors {
1.30 raeburn 1998: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1999: my %choices = &color_font_choices();
2000: my @bgs = ('pgbg','tabbg','sidebg');
2001: my @links = ('link','alink','vlink');
2002: my @images = ('img');
2003: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 2004: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 2005: my %defaultdesign = %Apache::loncommon::defaultdesign;
2006: my (%is_custom,%designs);
1.200 raeburn 2007: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 2008: if (ref($settings) eq 'HASH') {
2009: if (ref($settings->{$role}) eq 'HASH') {
2010: if ($settings->{$role}->{'img'} ne '') {
2011: $designs{'img'} = $settings->{$role}->{'img'};
2012: $is_custom{'img'} = 1;
2013: }
2014: if ($settings->{$role}->{'font'} ne '') {
2015: $designs{'font'} = $settings->{$role}->{'font'};
2016: $is_custom{'font'} = 1;
2017: }
1.97 tempelho 2018: if ($settings->{$role}->{'fontmenu'} ne '') {
2019: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
2020: $is_custom{'fontmenu'} = 1;
2021: }
1.6 raeburn 2022: foreach my $item (@bgs) {
2023: if ($settings->{$role}->{$item} ne '') {
2024: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
2025: $is_custom{$item} = 1;
2026: }
2027: }
2028: foreach my $item (@links) {
2029: if ($settings->{$role}->{$item} ne '') {
2030: $designs{'links'}{$item} = $settings->{$role}->{$item};
2031: $is_custom{$item} = 1;
2032: }
2033: }
2034: }
2035: } else {
2036: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
2037: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
2038: $is_custom{'img'} = 1;
2039: }
1.97 tempelho 2040: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2041: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2042: $is_custom{'fontmenu'} = 1;
2043: }
1.6 raeburn 2044: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2045: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2046: $is_custom{'font'} = 1;
2047: }
2048: foreach my $item (@bgs) {
2049: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2050: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2051: $is_custom{$item} = 1;
2052:
2053: }
2054: }
2055: foreach my $item (@links) {
2056: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2057: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2058: $is_custom{$item} = 1;
2059: }
2060: }
2061: }
2062: my $itemcount = 1;
1.30 raeburn 2063: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2064: $datatable .= '</tr></table></td></tr>';
2065: return $datatable;
2066: }
2067:
1.200 raeburn 2068: sub role_defaults {
2069: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2070: my %defaults;
2071: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2072: return %defaults;
2073: }
2074: my %defaultdesign = %Apache::loncommon::defaultdesign;
2075: if ($role eq 'login') {
2076: %defaults = (
2077: font => $defaultdesign{$role.'.font'},
2078: );
2079: if (ref($logintext) eq 'ARRAY') {
2080: foreach my $item (@{$logintext}) {
2081: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2082: }
2083: }
2084: foreach my $item (@{$images}) {
2085: $defaults{'showlogo'}{$item} = 1;
2086: }
2087: } else {
2088: %defaults = (
2089: img => $defaultdesign{$role.'.img'},
2090: font => $defaultdesign{$role.'.font'},
2091: fontmenu => $defaultdesign{$role.'.fontmenu'},
2092: );
2093: }
2094: foreach my $item (@{$bgs}) {
2095: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2096: }
2097: foreach my $item (@{$links}) {
2098: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2099: }
2100: foreach my $item (@{$images}) {
2101: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2102: }
2103: return %defaults;
2104: }
2105:
1.6 raeburn 2106: sub display_color_options {
1.9 raeburn 2107: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2108: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2109: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2110: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2111: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2112: '<td>'.$choices->{'font'}.'</td>';
2113: if (!$is_custom->{'font'}) {
1.329 raeburn 2114: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2115: } else {
2116: $datatable .= '<td> </td>';
2117: }
1.174 foxr 2118: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2119:
1.8 raeburn 2120: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2121: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2122: ' value="'.$current_color.'" /> '.
1.329 raeburn 2123: ' </span></td></tr>';
1.107 raeburn 2124: unless ($role eq 'login') {
2125: $datatable .= '<tr'.$css_class.'>'.
2126: '<td>'.$choices->{'fontmenu'}.'</td>';
2127: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2128: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2129: } else {
2130: $datatable .= '<td> </td>';
2131: }
1.202 raeburn 2132: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2133: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2134: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2135: '<input class="colorchooser" type="text" size="10" name="'
2136: .$role.'_fontmenu"'.
2137: ' value="'.$current_color.'" /> '.
1.329 raeburn 2138: ' </span></td></tr>';
1.97 tempelho 2139: }
1.9 raeburn 2140: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2141: foreach my $img (@{$images}) {
1.18 albertel 2142: $itemcount ++;
1.6 raeburn 2143: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2144: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2145: '<td>'.$choices->{$img};
1.402 raeburn 2146: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2147: if ($role eq 'login') {
2148: if ($img eq 'login') {
2149: $login_hdr_pick =
1.135 bisitz 2150: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2151: $logincolors =
2152: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2153: $designs,$defaults);
1.402 raeburn 2154: } else {
2155: if ($img ne 'domlogo') {
2156: $datatable.= &logo_display_options($img,$defaults,$designs);
2157: }
2158: if (ref($designs->{'alttext'}) eq 'HASH') {
2159: $alttext = $designs->{'alttext'}{$img};
2160: }
1.70 raeburn 2161: }
2162: }
2163: $datatable .= '</td>';
1.6 raeburn 2164: if ($designs->{$img} ne '') {
2165: $imgfile = $designs->{$img};
1.18 albertel 2166: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2167: } else {
2168: $imgfile = $defaults->{$img};
2169: }
2170: if ($imgfile) {
1.9 raeburn 2171: my ($showfile,$fullsize);
2172: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2173: my $urldir = $1;
2174: my $filename = $2;
2175: my @info = &Apache::lonnet::stat_file($designs->{$img});
2176: if (@info) {
2177: my $thumbfile = 'tn-'.$filename;
2178: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2179: if (@thumb) {
2180: $showfile = $urldir.'/'.$thumbfile;
2181: } else {
2182: $showfile = $imgfile;
2183: }
2184: } else {
2185: $showfile = '';
2186: }
2187: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2188: $showfile = $imgfile;
1.6 raeburn 2189: my $imgdir = $1;
2190: my $filename = $2;
1.159 raeburn 2191: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2192: $showfile = "/$imgdir/tn-".$filename;
2193: } else {
1.159 raeburn 2194: my $input = $londocroot.$imgfile;
2195: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2196: if (!-e $output) {
1.9 raeburn 2197: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2198: my ($fullwidth,$fullheight) = &check_dimensions($input);
2199: if ($fullwidth ne '' && $fullheight ne '') {
2200: if ($fullwidth > $width && $fullheight > $height) {
2201: my $size = $width.'x'.$height;
1.316 raeburn 2202: my @args = ('convert','-sample',$size,$input,$output);
2203: system({$args[0]} @args);
1.159 raeburn 2204: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2205: }
2206: }
1.6 raeburn 2207: }
2208: }
1.16 raeburn 2209: }
1.6 raeburn 2210: if ($showfile) {
1.40 raeburn 2211: if ($showfile =~ m{^/(adm|res)/}) {
2212: if ($showfile =~ m{^/res/}) {
2213: my $local_showfile =
2214: &Apache::lonnet::filelocation('',$showfile);
2215: &Apache::lonnet::repcopy($local_showfile);
2216: }
2217: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2218: }
2219: if ($imgfile) {
2220: if ($imgfile =~ m{^/(adm|res)/}) {
2221: if ($imgfile =~ m{^/res/}) {
2222: my $local_imgfile =
2223: &Apache::lonnet::filelocation('',$imgfile);
2224: &Apache::lonnet::repcopy($local_imgfile);
2225: }
2226: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2227: } else {
2228: $fullsize = $imgfile;
2229: }
2230: }
1.41 raeburn 2231: $datatable .= '<td>';
2232: if ($img eq 'login') {
1.135 bisitz 2233: $datatable .= $login_hdr_pick;
2234: }
1.41 raeburn 2235: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2236: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2237: } else {
1.201 raeburn 2238: $datatable .= '<td> </td><td class="LC_left_item">'.
2239: &mt('Upload:').'<br />';
1.6 raeburn 2240: }
2241: } else {
1.201 raeburn 2242: $datatable .= '<td> </td><td class="LC_left_item">'.
2243: &mt('Upload:').'<br />';
1.6 raeburn 2244: }
1.9 raeburn 2245: if ($switchserver) {
2246: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2247: } else {
1.135 bisitz 2248: if ($img ne 'login') { # suppress file selection for Log-in header
2249: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2250: }
1.9 raeburn 2251: }
1.402 raeburn 2252: if (($role eq 'login') && ($img ne 'login')) {
2253: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2254: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2255: '</label></span>';
2256: }
1.9 raeburn 2257: $datatable .= '</td></tr>';
1.6 raeburn 2258: }
2259: $itemcount ++;
2260: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2261: $datatable .= '<tr'.$css_class.'>'.
2262: '<td>'.$choices->{'bgs'}.'</td>';
2263: my $bgs_def;
2264: foreach my $item (@{$bgs}) {
2265: if (!$is_custom->{$item}) {
1.329 raeburn 2266: $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 2267: }
2268: }
2269: if ($bgs_def) {
1.8 raeburn 2270: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2271: } else {
2272: $datatable .= '<td> </td>';
2273: }
2274: $datatable .= '<td class="LC_right_item">'.
2275: '<table border="0"><tr>';
1.174 foxr 2276:
1.6 raeburn 2277: foreach my $item (@{$bgs}) {
1.306 raeburn 2278: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2279: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2280: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2281: $datatable .= ' ';
1.6 raeburn 2282: }
1.174 foxr 2283: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2284: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2285: }
2286: $datatable .= '</tr></table></td></tr>';
2287: $itemcount ++;
2288: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2289: $datatable .= '<tr'.$css_class.'>'.
2290: '<td>'.$choices->{'links'}.'</td>';
2291: my $links_def;
2292: foreach my $item (@{$links}) {
2293: if (!$is_custom->{$item}) {
1.329 raeburn 2294: $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 2295: }
2296: }
2297: if ($links_def) {
1.8 raeburn 2298: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2299: } else {
2300: $datatable .= '<td> </td>';
2301: }
2302: $datatable .= '<td class="LC_right_item">'.
2303: '<table border="0"><tr>';
2304: foreach my $item (@{$links}) {
1.234 raeburn 2305: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2306: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2307: if ($designs->{'links'}{$item}) {
1.174 foxr 2308: $datatable.=' ';
1.6 raeburn 2309: }
1.174 foxr 2310: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2311: '" /></td>';
2312: }
1.30 raeburn 2313: $$rowtotal += $itemcount;
1.3 raeburn 2314: return $datatable;
2315: }
2316:
1.70 raeburn 2317: sub logo_display_options {
2318: my ($img,$defaults,$designs) = @_;
2319: my $checkedon;
2320: if (ref($defaults) eq 'HASH') {
2321: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2322: if ($defaults->{'showlogo'}{$img}) {
2323: $checkedon = 'checked="checked" ';
2324: }
2325: }
2326: }
2327: if (ref($designs) eq 'HASH') {
2328: if (ref($designs->{'showlogo'}) eq 'HASH') {
2329: if (defined($designs->{'showlogo'}{$img})) {
2330: if ($designs->{'showlogo'}{$img} == 0) {
2331: $checkedon = '';
2332: } elsif ($designs->{'showlogo'}{$img} == 1) {
2333: $checkedon = 'checked="checked" ';
2334: }
2335: }
2336: }
2337: }
2338: return '<br /><label> <input type="checkbox" name="'.
2339: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2340: &mt('show').'</label>'."\n";
2341: }
2342:
1.41 raeburn 2343: sub login_header_options {
1.135 bisitz 2344: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2345: my $output = '';
1.41 raeburn 2346: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2347: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2348: if (!$is_custom->{'textcol'}) {
2349: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2350: ' ';
2351: }
2352: if (!$is_custom->{'bgcol'}) {
2353: $output .= $choices->{'bgcol'}.': '.
2354: '<span id="css_'.$role.'_font" style="background-color: '.
2355: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2356: }
2357: $output .= '<br />';
2358: }
2359: $output .='<br />';
2360: return $output;
2361: }
2362:
2363: sub login_text_colors {
1.201 raeburn 2364: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2365: my $color_menu = '<table border="0"><tr>';
2366: foreach my $item (@{$logintext}) {
1.306 raeburn 2367: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2368: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2369: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2370: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2371: }
2372: $color_menu .= '</tr></table><br />';
2373: return $color_menu;
2374: }
2375:
2376: sub image_changes {
2377: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2378: my $output;
1.135 bisitz 2379: if ($img eq 'login') {
1.331 raeburn 2380: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2381: } elsif (!$is_custom) {
1.70 raeburn 2382: if ($img ne 'domlogo') {
1.331 raeburn 2383: $output = &mt('Default image:').'<br />';
1.41 raeburn 2384: } else {
1.331 raeburn 2385: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2386: }
2387: }
1.331 raeburn 2388: if ($img ne 'login') {
1.135 bisitz 2389: if ($img_import) {
2390: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2391: }
2392: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2393: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2394: if ($is_custom) {
2395: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2396: '<input type="checkbox" name="'.
2397: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2398: '</label> '.&mt('Replace:').'</span><br />';
2399: } else {
1.306 raeburn 2400: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2401: }
1.41 raeburn 2402: }
2403: return $output;
2404: }
2405:
1.3 raeburn 2406: sub print_quotas {
1.86 raeburn 2407: my ($dom,$settings,$rowtotal,$action) = @_;
2408: my $context;
2409: if ($action eq 'quotas') {
2410: $context = 'tools';
2411: } else {
2412: $context = $action;
2413: }
1.429 ! raeburn 2414: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2415: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2416: my $typecount = 0;
1.101 raeburn 2417: my ($css_class,%titles);
1.86 raeburn 2418: if ($context eq 'requestcourses') {
1.325 raeburn 2419: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2420: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2421: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2422: %titles = &courserequest_titles();
1.163 raeburn 2423: } elsif ($context eq 'requestauthor') {
2424: @usertools = ('author');
2425: @options = ('norequest','approval','automatic');
1.210 raeburn 2426: %titles = &authorrequest_titles();
1.86 raeburn 2427: } else {
1.429 ! raeburn 2428: @usertools = ('aboutme','blog','portfolio','timezone');
1.101 raeburn 2429: %titles = &tool_titles();
1.86 raeburn 2430: }
1.26 raeburn 2431: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2432: foreach my $type (@{$types}) {
1.429 ! raeburn 2433: my $currdefquota;
1.163 raeburn 2434: unless (($context eq 'requestcourses') ||
2435: ($context eq 'requestauthor')) {
1.86 raeburn 2436: if (ref($settings) eq 'HASH') {
2437: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2438: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2439: } else {
2440: $currdefquota = $settings->{$type};
2441: }
1.78 raeburn 2442: }
1.72 raeburn 2443: }
1.3 raeburn 2444: if (defined($usertypes->{$type})) {
2445: $typecount ++;
2446: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2447: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2448: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2449: '<td class="LC_left_item">';
1.101 raeburn 2450: if ($context eq 'requestcourses') {
2451: $datatable .= '<table><tr>';
2452: }
2453: my %cell;
1.72 raeburn 2454: foreach my $item (@usertools) {
1.101 raeburn 2455: if ($context eq 'requestcourses') {
2456: my ($curroption,$currlimit);
2457: if (ref($settings) eq 'HASH') {
2458: if (ref($settings->{$item}) eq 'HASH') {
2459: $curroption = $settings->{$item}->{$type};
2460: if ($curroption =~ /^autolimit=(\d*)$/) {
2461: $currlimit = $1;
2462: }
2463: }
2464: }
2465: if (!$curroption) {
2466: $curroption = 'norequest';
2467: }
2468: $datatable .= '<th>'.$titles{$item}.'</th>';
2469: foreach my $option (@options) {
2470: my $val = $option;
2471: if ($option eq 'norequest') {
2472: $val = 0;
2473: }
2474: if ($option eq 'validate') {
2475: my $canvalidate = 0;
2476: if (ref($validations{$item}) eq 'HASH') {
2477: if ($validations{$item}{$type}) {
2478: $canvalidate = 1;
2479: }
2480: }
2481: next if (!$canvalidate);
2482: }
2483: my $checked = '';
2484: if ($option eq $curroption) {
2485: $checked = ' checked="checked"';
2486: } elsif ($option eq 'autolimit') {
2487: if ($curroption =~ /^autolimit/) {
2488: $checked = ' checked="checked"';
2489: }
2490: }
2491: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2492: '<input type="radio" name="crsreq_'.$item.
2493: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2494: $titles{$option}.'</label>';
1.101 raeburn 2495: if ($option eq 'autolimit') {
1.127 raeburn 2496: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2497: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2498: 'value="'.$currlimit.'" />';
1.101 raeburn 2499: }
1.127 raeburn 2500: $cell{$item} .= '</span> ';
1.103 raeburn 2501: if ($option eq 'autolimit') {
1.127 raeburn 2502: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2503: }
1.101 raeburn 2504: }
1.163 raeburn 2505: } elsif ($context eq 'requestauthor') {
2506: my $curroption;
2507: if (ref($settings) eq 'HASH') {
2508: $curroption = $settings->{$type};
2509: }
2510: if (!$curroption) {
2511: $curroption = 'norequest';
2512: }
2513: foreach my $option (@options) {
2514: my $val = $option;
2515: if ($option eq 'norequest') {
2516: $val = 0;
2517: }
2518: my $checked = '';
2519: if ($option eq $curroption) {
2520: $checked = ' checked="checked"';
2521: }
2522: $datatable .= '<span class="LC_nobreak"><label>'.
2523: '<input type="radio" name="authorreq_'.$type.
2524: '" value="'.$val.'"'.$checked.' />'.
2525: $titles{$option}.'</label></span> ';
2526: }
1.101 raeburn 2527: } else {
2528: my $checked = 'checked="checked" ';
1.413 raeburn 2529: if ($item eq 'timezone') {
2530: $checked = '';
2531: }
1.101 raeburn 2532: if (ref($settings) eq 'HASH') {
2533: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2534: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2535: $checked = '';
2536: } elsif ($settings->{$item}->{$type} == 1) {
2537: $checked = 'checked="checked" ';
2538: }
1.78 raeburn 2539: }
1.72 raeburn 2540: }
1.101 raeburn 2541: $datatable .= '<span class="LC_nobreak"><label>'.
2542: '<input type="checkbox" name="'.$context.'_'.$item.
2543: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2544: '</label></span> ';
1.72 raeburn 2545: }
1.101 raeburn 2546: }
2547: if ($context eq 'requestcourses') {
2548: $datatable .= '</tr><tr>';
2549: foreach my $item (@usertools) {
1.106 raeburn 2550: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2551: }
2552: $datatable .= '</tr></table>';
1.72 raeburn 2553: }
1.86 raeburn 2554: $datatable .= '</td>';
1.163 raeburn 2555: unless (($context eq 'requestcourses') ||
2556: ($context eq 'requestauthor')) {
1.86 raeburn 2557: $datatable .=
1.197 raeburn 2558: '<td class="LC_right_item">'.
1.429 ! raeburn 2559: '<span class="LC_nobreak">'.
1.3 raeburn 2560: '<input type="text" name="quota_'.$type.
1.72 raeburn 2561: '" value="'.$currdefquota.
1.197 raeburn 2562: '" size="5" /></span></td>';
1.86 raeburn 2563: }
2564: $datatable .= '</tr>';
1.3 raeburn 2565: }
2566: }
2567: }
1.163 raeburn 2568: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2569: $defaultquota = '20';
2570: if (ref($settings) eq 'HASH') {
2571: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2572: $defaultquota = $settings->{'defaultquota'}->{'default'};
2573: } elsif (defined($settings->{'default'})) {
2574: $defaultquota = $settings->{'default'};
2575: }
1.3 raeburn 2576: }
2577: }
2578: $typecount ++;
2579: $css_class = $typecount%2?' class="LC_odd_row"':'';
2580: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2581: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2582: '<td class="LC_left_item">';
1.101 raeburn 2583: if ($context eq 'requestcourses') {
2584: $datatable .= '<table><tr>';
2585: }
2586: my %defcell;
1.72 raeburn 2587: foreach my $item (@usertools) {
1.101 raeburn 2588: if ($context eq 'requestcourses') {
2589: my ($curroption,$currlimit);
2590: if (ref($settings) eq 'HASH') {
2591: if (ref($settings->{$item}) eq 'HASH') {
2592: $curroption = $settings->{$item}->{'default'};
2593: if ($curroption =~ /^autolimit=(\d*)$/) {
2594: $currlimit = $1;
2595: }
2596: }
2597: }
2598: if (!$curroption) {
2599: $curroption = 'norequest';
2600: }
2601: $datatable .= '<th>'.$titles{$item}.'</th>';
2602: foreach my $option (@options) {
2603: my $val = $option;
2604: if ($option eq 'norequest') {
2605: $val = 0;
2606: }
2607: if ($option eq 'validate') {
2608: my $canvalidate = 0;
2609: if (ref($validations{$item}) eq 'HASH') {
2610: if ($validations{$item}{'default'}) {
2611: $canvalidate = 1;
2612: }
2613: }
2614: next if (!$canvalidate);
2615: }
2616: my $checked = '';
2617: if ($option eq $curroption) {
2618: $checked = ' checked="checked"';
2619: } elsif ($option eq 'autolimit') {
2620: if ($curroption =~ /^autolimit/) {
2621: $checked = ' checked="checked"';
2622: }
2623: }
2624: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2625: '<input type="radio" name="crsreq_'.$item.
2626: '_default" value="'.$val.'"'.$checked.' />'.
2627: $titles{$option}.'</label>';
2628: if ($option eq 'autolimit') {
1.127 raeburn 2629: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2630: $item.'_limit_default" size="1" '.
2631: 'value="'.$currlimit.'" />';
2632: }
1.127 raeburn 2633: $defcell{$item} .= '</span> ';
1.104 raeburn 2634: if ($option eq 'autolimit') {
1.127 raeburn 2635: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2636: }
1.101 raeburn 2637: }
1.163 raeburn 2638: } elsif ($context eq 'requestauthor') {
2639: my $curroption;
2640: if (ref($settings) eq 'HASH') {
1.172 raeburn 2641: $curroption = $settings->{'default'};
1.163 raeburn 2642: }
2643: if (!$curroption) {
2644: $curroption = 'norequest';
2645: }
2646: foreach my $option (@options) {
2647: my $val = $option;
2648: if ($option eq 'norequest') {
2649: $val = 0;
2650: }
2651: my $checked = '';
2652: if ($option eq $curroption) {
2653: $checked = ' checked="checked"';
2654: }
2655: $datatable .= '<span class="LC_nobreak"><label>'.
2656: '<input type="radio" name="authorreq_default"'.
2657: ' value="'.$val.'"'.$checked.' />'.
2658: $titles{$option}.'</label></span> ';
2659: }
1.101 raeburn 2660: } else {
2661: my $checked = 'checked="checked" ';
2662: if (ref($settings) eq 'HASH') {
2663: if (ref($settings->{$item}) eq 'HASH') {
2664: if ($settings->{$item}->{'default'} == 0) {
2665: $checked = '';
2666: } elsif ($settings->{$item}->{'default'} == 1) {
2667: $checked = 'checked="checked" ';
2668: }
1.78 raeburn 2669: }
1.72 raeburn 2670: }
1.101 raeburn 2671: $datatable .= '<span class="LC_nobreak"><label>'.
2672: '<input type="checkbox" name="'.$context.'_'.$item.
2673: '" value="default" '.$checked.'/>'.$titles{$item}.
2674: '</label></span> ';
2675: }
2676: }
2677: if ($context eq 'requestcourses') {
2678: $datatable .= '</tr><tr>';
2679: foreach my $item (@usertools) {
1.106 raeburn 2680: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2681: }
1.101 raeburn 2682: $datatable .= '</tr></table>';
1.72 raeburn 2683: }
1.86 raeburn 2684: $datatable .= '</td>';
1.163 raeburn 2685: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2686: $datatable .= '<td class="LC_right_item">'.
1.429 ! raeburn 2687: '<span class="LC_nobreak">'.
1.86 raeburn 2688: '<input type="text" name="defaultquota" value="'.
1.429 ! raeburn 2689: $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2690: }
2691: $datatable .= '</tr>';
1.72 raeburn 2692: $typecount ++;
2693: $css_class = $typecount%2?' class="LC_odd_row"':'';
2694: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2695: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2696: if ($context eq 'requestcourses') {
1.109 raeburn 2697: $datatable .= &mt('(overrides affiliation, if set)').
2698: '</td>'.
2699: '<td class="LC_left_item">'.
2700: '<table><tr>';
1.101 raeburn 2701: } else {
1.109 raeburn 2702: $datatable .= &mt('(overrides affiliation, if checked)').
2703: '</td>'.
2704: '<td class="LC_left_item" colspan="2">'.
2705: '<br />';
1.101 raeburn 2706: }
2707: my %advcell;
1.72 raeburn 2708: foreach my $item (@usertools) {
1.101 raeburn 2709: if ($context eq 'requestcourses') {
2710: my ($curroption,$currlimit);
2711: if (ref($settings) eq 'HASH') {
2712: if (ref($settings->{$item}) eq 'HASH') {
2713: $curroption = $settings->{$item}->{'_LC_adv'};
2714: if ($curroption =~ /^autolimit=(\d*)$/) {
2715: $currlimit = $1;
2716: }
2717: }
2718: }
2719: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2720: my $checked = '';
2721: if ($curroption eq '') {
2722: $checked = ' checked="checked"';
2723: }
2724: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2725: '<input type="radio" name="crsreq_'.$item.
2726: '__LC_adv" value=""'.$checked.' />'.
2727: &mt('No override set').'</label></span> ';
1.101 raeburn 2728: foreach my $option (@options) {
2729: my $val = $option;
2730: if ($option eq 'norequest') {
2731: $val = 0;
2732: }
2733: if ($option eq 'validate') {
2734: my $canvalidate = 0;
2735: if (ref($validations{$item}) eq 'HASH') {
2736: if ($validations{$item}{'_LC_adv'}) {
2737: $canvalidate = 1;
2738: }
2739: }
2740: next if (!$canvalidate);
2741: }
2742: my $checked = '';
1.104 raeburn 2743: if ($val eq $curroption) {
1.101 raeburn 2744: $checked = ' checked="checked"';
2745: } elsif ($option eq 'autolimit') {
2746: if ($curroption =~ /^autolimit/) {
2747: $checked = ' checked="checked"';
2748: }
2749: }
2750: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2751: '<input type="radio" name="crsreq_'.$item.
2752: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2753: $titles{$option}.'</label>';
2754: if ($option eq 'autolimit') {
1.127 raeburn 2755: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2756: $item.'_limit__LC_adv" size="1" '.
2757: 'value="'.$currlimit.'" />';
2758: }
1.127 raeburn 2759: $advcell{$item} .= '</span> ';
1.104 raeburn 2760: if ($option eq 'autolimit') {
1.127 raeburn 2761: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2762: }
1.101 raeburn 2763: }
1.163 raeburn 2764: } elsif ($context eq 'requestauthor') {
2765: my $curroption;
2766: if (ref($settings) eq 'HASH') {
2767: $curroption = $settings->{'_LC_adv'};
2768: }
2769: my $checked = '';
2770: if ($curroption eq '') {
2771: $checked = ' checked="checked"';
2772: }
2773: $datatable .= '<span class="LC_nobreak"><label>'.
2774: '<input type="radio" name="authorreq__LC_adv"'.
2775: ' value=""'.$checked.' />'.
2776: &mt('No override set').'</label></span> ';
2777: foreach my $option (@options) {
2778: my $val = $option;
2779: if ($option eq 'norequest') {
2780: $val = 0;
2781: }
2782: my $checked = '';
2783: if ($val eq $curroption) {
2784: $checked = ' checked="checked"';
2785: }
2786: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2787: '<input type="radio" name="authorreq__LC_adv"'.
2788: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2789: $titles{$option}.'</label></span> ';
2790: }
1.101 raeburn 2791: } else {
2792: my $checked = 'checked="checked" ';
2793: if (ref($settings) eq 'HASH') {
2794: if (ref($settings->{$item}) eq 'HASH') {
2795: if ($settings->{$item}->{'_LC_adv'} == 0) {
2796: $checked = '';
2797: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2798: $checked = 'checked="checked" ';
2799: }
1.79 raeburn 2800: }
1.72 raeburn 2801: }
1.101 raeburn 2802: $datatable .= '<span class="LC_nobreak"><label>'.
2803: '<input type="checkbox" name="'.$context.'_'.$item.
2804: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2805: '</label></span> ';
2806: }
2807: }
2808: if ($context eq 'requestcourses') {
2809: $datatable .= '</tr><tr>';
2810: foreach my $item (@usertools) {
1.106 raeburn 2811: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2812: }
1.101 raeburn 2813: $datatable .= '</tr></table>';
1.72 raeburn 2814: }
1.98 raeburn 2815: $datatable .= '</td></tr>';
1.30 raeburn 2816: $$rowtotal += $typecount;
1.3 raeburn 2817: return $datatable;
2818: }
2819:
1.163 raeburn 2820: sub print_requestmail {
1.305 raeburn 2821: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2822: my ($now,$datatable,%currapp);
1.102 raeburn 2823: $now = time;
2824: if (ref($settings) eq 'HASH') {
2825: if (ref($settings->{'notify'}) eq 'HASH') {
2826: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2827: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2828: }
2829: }
2830: }
1.191 raeburn 2831: my $numinrow = 2;
1.224 raeburn 2832: my $css_class;
1.305 raeburn 2833: if ($$rowtotal%2) {
2834: $css_class = 'LC_odd_row';
2835: }
2836: if ($customcss) {
2837: $css_class .= " $customcss";
2838: }
2839: $css_class =~ s/^\s+//;
2840: if ($css_class) {
2841: $css_class = ' class="'.$css_class.'"';
2842: }
2843: if ($rowstyle) {
2844: $css_class .= ' style="'.$rowstyle.'"';
2845: }
1.163 raeburn 2846: my $text;
2847: if ($action eq 'requestcourses') {
2848: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2849: } elsif ($action eq 'requestauthor') {
2850: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2851: } else {
1.224 raeburn 2852: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2853: }
1.224 raeburn 2854: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2855: ' <td>'.$text.'</td>'.
1.102 raeburn 2856: ' <td class="LC_left_item">';
1.191 raeburn 2857: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2858: $action.'notifyapproval',%currapp);
1.191 raeburn 2859: if ($numdc > 0) {
2860: $datatable .= $table;
1.102 raeburn 2861: } else {
2862: $datatable .= &mt('There are no active Domain Coordinators');
2863: }
2864: $datatable .='</td></tr>';
2865: return $datatable;
2866: }
2867:
1.216 raeburn 2868: sub print_studentcode {
2869: my ($settings,$rowtotal) = @_;
2870: my $rownum = 0;
1.218 raeburn 2871: my ($output,%current);
1.325 raeburn 2872: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2873: if (ref($settings) eq 'HASH') {
2874: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2875: foreach my $type (@crstypes) {
2876: $current{$type} = $settings->{'uniquecode'}{$type};
2877: }
1.218 raeburn 2878: }
2879: }
2880: $output .= '<tr>'.
2881: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2882: '<td class="LC_left_item">';
2883: foreach my $type (@crstypes) {
2884: my $check = ' ';
2885: if ($current{$type}) {
2886: $check = ' checked="checked" ';
2887: }
2888: $output .= '<span class="LC_nobreak"><label>'.
2889: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2890: &mt($type).'</label></span>'.(' 'x2).' ';
2891: }
2892: $output .= '</td></tr>';
2893: $$rowtotal ++;
2894: return $output;
1.216 raeburn 2895: }
2896:
2897: sub print_textbookcourses {
1.242 raeburn 2898: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2899: my $rownum = 0;
2900: my $css_class;
2901: my $itemcount = 1;
2902: my $maxnum = 0;
2903: my $bookshash;
2904: if (ref($settings) eq 'HASH') {
1.242 raeburn 2905: $bookshash = $settings->{$type};
1.216 raeburn 2906: }
2907: my %ordered;
2908: if (ref($bookshash) eq 'HASH') {
2909: foreach my $item (keys(%{$bookshash})) {
2910: if (ref($bookshash->{$item}) eq 'HASH') {
2911: my $num = $bookshash->{$item}{'order'};
2912: $ordered{$num} = $item;
2913: }
2914: }
2915: }
2916: my $confname = $dom.'-domainconfig';
2917: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2918: my $maxnum = scalar(keys(%ordered));
2919: my $datatable;
1.216 raeburn 2920: if (keys(%ordered)) {
2921: my @items = sort { $a <=> $b } keys(%ordered);
2922: for (my $i=0; $i<@items; $i++) {
2923: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2924: my $key = $ordered{$items[$i]};
2925: my %coursehash=&Apache::lonnet::coursedescription($key);
2926: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2927: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2928: if (ref($bookshash->{$key}) eq 'HASH') {
2929: $subject = $bookshash->{$key}->{'subject'};
2930: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2931: if ($type eq 'textbooks') {
1.243 raeburn 2932: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2933: $author = $bookshash->{$key}->{'author'};
2934: $image = $bookshash->{$key}->{'image'};
2935: if ($image ne '') {
2936: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2937: my $imagethumb = "$path/tn-".$imagefile;
2938: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2939: }
1.216 raeburn 2940: }
2941: }
1.242 raeburn 2942: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2943: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2944: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2945: for (my $k=0; $k<=$maxnum; $k++) {
2946: my $vpos = $k+1;
2947: my $selstr;
2948: if ($k == $i) {
2949: $selstr = ' selected="selected" ';
2950: }
2951: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2952: }
2953: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2954: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2955: &mt('Delete?').'</label></span></td>'.
2956: '<td colspan="2">'.
1.242 raeburn 2957: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2958: (' 'x2).
1.242 raeburn 2959: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2960: if ($type eq 'textbooks') {
2961: $datatable .= (' 'x2).
1.243 raeburn 2962: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2963: (' 'x2).
1.242 raeburn 2964: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2965: (' 'x2).
2966: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2967: if ($image) {
1.267 raeburn 2968: $datatable .= $imgsrc.
1.242 raeburn 2969: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2970: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2971: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2972: }
2973: if ($switchserver) {
2974: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2975: } else {
2976: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2977: }
1.216 raeburn 2978: }
1.242 raeburn 2979: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2980: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2981: $coursetitle.'</span></td></tr>'."\n";
2982: $itemcount ++;
2983: }
2984: }
2985: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2986: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2987: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2988: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2989: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2990: for (my $k=0; $k<$maxnum+1; $k++) {
2991: my $vpos = $k+1;
2992: my $selstr;
2993: if ($k == $maxnum) {
2994: $selstr = ' selected="selected" ';
2995: }
2996: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2997: }
2998: $datatable .= '</select> '."\n".
1.334 raeburn 2999: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 3000: '<td colspan="2">'.
1.242 raeburn 3001: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 3002: (' 'x2).
1.242 raeburn 3003: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
3004: (' 'x2);
3005: if ($type eq 'textbooks') {
1.243 raeburn 3006: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
3007: (' 'x2).
3008: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 3009: (' 'x2).
3010: '<span class="LC_nobreak">'.&mt('Image:').' ';
3011: if ($switchserver) {
3012: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3013: } else {
3014: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
3015: }
1.334 raeburn 3016: $datatable .= '</span>'."\n";
1.216 raeburn 3017: }
1.334 raeburn 3018: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 3019: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
3020: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 3021: &Apache::loncommon::selectcourse_link
1.334 raeburn 3022: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 3023: '</span></td>'."\n".
3024: '</tr>'."\n";
3025: $itemcount ++;
3026: return $datatable;
3027: }
3028:
1.217 raeburn 3029: sub textbookcourses_javascript {
1.242 raeburn 3030: my ($settings) = @_;
3031: return unless(ref($settings) eq 'HASH');
3032: my (%ordered,%total,%jstext);
3033: foreach my $type ('textbooks','templates') {
3034: $total{$type} = 0;
3035: if (ref($settings->{$type}) eq 'HASH') {
3036: foreach my $item (keys(%{$settings->{$type}})) {
3037: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3038: my $num = $settings->{$type}->{$item}{'order'};
3039: $ordered{$type}{$num} = $item;
3040: }
3041: }
3042: $total{$type} = scalar(keys(%{$settings->{$type}}));
3043: }
3044: my @jsarray = ();
3045: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3046: push(@jsarray,$ordered{$type}{$item});
3047: }
3048: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3049: }
3050: return <<"ENDSCRIPT";
3051: <script type="text/javascript">
3052: // <![CDATA[
1.242 raeburn 3053: function reorderBooks(form,item,caller) {
1.217 raeburn 3054: var changedVal;
1.242 raeburn 3055: $jstext{'textbooks'};
3056: $jstext{'templates'};
3057: var newpos;
3058: var maxh;
3059: if (caller == 'textbooks') {
3060: newpos = 'textbooks_addbook_pos';
3061: maxh = 1 + $total{'textbooks'};
3062: } else {
3063: newpos = 'templates_addbook_pos';
3064: maxh = 1 + $total{'templates'};
3065: }
1.217 raeburn 3066: var current = new Array;
3067: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3068: if (item == newpos) {
3069: changedVal = newitemVal;
3070: } else {
3071: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3072: current[newitemVal] = newpos;
3073: }
1.242 raeburn 3074: if (caller == 'textbooks') {
3075: for (var i=0; i<textbooks.length; i++) {
3076: var elementName = 'textbooks_'+textbooks[i];
3077: if (elementName != item) {
3078: if (form.elements[elementName]) {
3079: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3080: current[currVal] = elementName;
3081: }
3082: }
3083: }
3084: }
3085: if (caller == 'templates') {
3086: for (var i=0; i<templates.length; i++) {
3087: var elementName = 'templates_'+templates[i];
3088: if (elementName != item) {
3089: if (form.elements[elementName]) {
3090: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3091: current[currVal] = elementName;
3092: }
1.217 raeburn 3093: }
3094: }
3095: }
3096: var oldVal;
3097: for (var j=0; j<maxh; j++) {
3098: if (current[j] == undefined) {
3099: oldVal = j;
3100: }
3101: }
3102: if (oldVal < changedVal) {
3103: for (var k=oldVal+1; k<=changedVal ; k++) {
3104: var elementName = current[k];
3105: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3106: }
3107: } else {
3108: for (var k=changedVal; k<oldVal; k++) {
3109: var elementName = current[k];
3110: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3111: }
3112: }
3113: return;
3114: }
3115:
3116: // ]]>
3117: </script>
3118:
3119: ENDSCRIPT
3120: }
3121:
1.267 raeburn 3122: sub ltitools_javascript {
3123: my ($settings) = @_;
1.319 raeburn 3124: my $togglejs = <itools_toggle_js();
3125: unless (ref($settings) eq 'HASH') {
3126: return $togglejs;
3127: }
1.267 raeburn 3128: my (%ordered,$total,%jstext);
3129: $total = 0;
3130: foreach my $item (keys(%{$settings})) {
3131: if (ref($settings->{$item}) eq 'HASH') {
3132: my $num = $settings->{$item}{'order'};
3133: $ordered{$num} = $item;
3134: }
3135: }
3136: $total = scalar(keys(%{$settings}));
3137: my @jsarray = ();
3138: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3139: push(@jsarray,$ordered{$item});
3140: }
3141: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3142: return <<"ENDSCRIPT";
3143: <script type="text/javascript">
3144: // <![CDATA[
1.319 raeburn 3145: function reorderLTITools(form,item) {
1.267 raeburn 3146: var changedVal;
3147: $jstext
3148: var newpos = 'ltitools_add_pos';
3149: var maxh = 1 + $total;
3150: var current = new Array;
3151: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3152: if (item == newpos) {
3153: changedVal = newitemVal;
3154: } else {
3155: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3156: current[newitemVal] = newpos;
3157: }
3158: for (var i=0; i<ltitools.length; i++) {
3159: var elementName = 'ltitools_'+ltitools[i];
3160: if (elementName != item) {
3161: if (form.elements[elementName]) {
3162: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3163: current[currVal] = elementName;
3164: }
3165: }
3166: }
3167: var oldVal;
3168: for (var j=0; j<maxh; j++) {
3169: if (current[j] == undefined) {
3170: oldVal = j;
3171: }
3172: }
3173: if (oldVal < changedVal) {
3174: for (var k=oldVal+1; k<=changedVal ; k++) {
3175: var elementName = current[k];
3176: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3177: }
3178: } else {
3179: for (var k=changedVal; k<oldVal; k++) {
3180: var elementName = current[k];
3181: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3182: }
3183: }
3184: return;
3185: }
3186:
3187: // ]]>
3188: </script>
3189:
1.319 raeburn 3190: $togglejs
3191:
3192: ENDSCRIPT
3193: }
3194:
3195: sub ltitools_toggle_js {
3196: return <<"ENDSCRIPT";
3197: <script type="text/javascript">
3198: // <![CDATA[
3199:
3200: function toggleLTITools(form,setting,item) {
3201: var radioname = '';
3202: var divid = '';
3203: if ((setting == 'passback') || (setting == 'roster')) {
3204: radioname = 'ltitools_'+setting+'_'+item;
3205: divid = 'ltitools_'+setting+'time_'+item;
3206: var num = form.elements[radioname].length;
3207: if (num) {
3208: var setvis = '';
3209: for (var i=0; i<num; i++) {
3210: if (form.elements[radioname][i].checked) {
3211: if (form.elements[radioname][i].value == '1') {
3212: if (document.getElementById(divid)) {
3213: document.getElementById(divid).style.display = 'inline-block';
3214: }
3215: setvis = 1;
3216: }
3217: break;
3218: }
3219: }
3220: }
3221: if (!setvis) {
3222: if (document.getElementById(divid)) {
3223: document.getElementById(divid).style.display = 'none';
3224: }
3225: }
3226: }
1.324 raeburn 3227: if (setting == 'user') {
3228: divid = 'ltitools_'+setting+'_div_'+item;
3229: var checkid = 'ltitools_'+setting+'_field_'+item;
3230: if (document.getElementById(divid)) {
3231: if (document.getElementById(checkid)) {
3232: if (document.getElementById(checkid).checked) {
3233: document.getElementById(divid).style.display = 'inline-block';
3234: } else {
3235: document.getElementById(divid).style.display = 'none';
3236: }
3237: }
3238: }
3239: }
1.319 raeburn 3240: return;
3241: }
3242: // ]]>
3243: </script>
3244:
1.267 raeburn 3245: ENDSCRIPT
3246: }
3247:
1.381 raeburn 3248: sub wafproxy_javascript {
3249: my ($dom) = @_;
3250: return <<"ENDSCRIPT";
3251: <script type="text/javascript">
3252: // <![CDATA[
3253: function updateWAF() {
3254: if (document.getElementById('wafproxy_remoteip')) {
3255: var wafremote = 0;
3256: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3257: wafremote = 1;
3258: }
3259: var fields = new Array('header','trust');
3260: for (var i=0; i<fields.length; i++) {
3261: if (document.getElementById('wafproxy_'+fields[i])) {
3262: if (wafremote == 1) {
3263: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3264: }
3265: else {
3266: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3267: }
3268: }
3269: }
3270: if (document.getElementById('wafproxyranges_$dom')) {
3271: if (wafremote == 1) {
3272: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3273: } else {
3274: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3275: if (document.display.wafproxy_vpnaccess[i].checked) {
3276: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3277: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3278: }
3279: }
3280: }
3281: }
3282: }
3283: }
3284: return;
3285: }
3286:
3287: function checkWAF() {
3288: if (document.getElementById('wafproxy_remoteip')) {
3289: var wafvpn = 0;
3290: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3291: if (document.display.wafproxy_vpnaccess[i].checked) {
3292: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3293: wafvpn = 1;
3294: }
3295: break;
3296: }
3297: }
3298: var vpn = new Array('vpnint','vpnext');
3299: for (var i=0; i<vpn.length; i++) {
3300: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3301: if (wafvpn == 1) {
3302: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3303: }
3304: else {
3305: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3306: }
3307: }
3308: }
3309: if (document.getElementById('wafproxyranges_$dom')) {
3310: if (wafvpn == 1) {
3311: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3312: }
3313: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3314: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3315: }
3316: }
3317: }
3318: return;
3319: }
3320:
3321: function toggleWAF() {
3322: if (document.getElementById('wafproxy_table')) {
3323: var wafproxy = 0;
3324: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3325: if (document.display.wafproxy_${dom}[i].checked) {
3326: if (document.display.wafproxy_${dom}[i].value == 1) {
3327: wafproxy = 1;
3328: break;
3329: }
3330: }
3331: }
3332: if (wafproxy == 1) {
3333: document.getElementById('wafproxy_table').style.display='inline';
3334: }
3335: else {
3336: document.getElementById('wafproxy_table').style.display='none';
3337: }
3338: if (document.getElementById('wafproxyrow_${dom}')) {
3339: if (wafproxy == 1) {
3340: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3341: }
3342: else {
3343: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3344: }
3345: }
3346: if (document.getElementById('nowafproxyrow_$dom')) {
3347: if (wafproxy == 1) {
3348: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3349: }
3350: else {
3351: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3352: }
3353: }
3354: }
3355: return;
3356: }
3357: // ]]>
3358: </script>
3359:
3360: ENDSCRIPT
3361: }
3362:
1.372 raeburn 3363: sub proctoring_javascript {
3364: my ($settings) = @_;
3365: my (%ordered,$total,%jstext);
3366: $total = 0;
3367: if (ref($settings) eq 'HASH') {
3368: foreach my $item (keys(%{$settings})) {
3369: if (ref($settings->{$item}) eq 'HASH') {
3370: my $num = $settings->{$item}{'order'};
3371: $ordered{$num} = $item;
3372: }
3373: }
3374: $total = scalar(keys(%{$settings}));
3375: } else {
3376: %ordered = (
3377: 0 => 'proctorio',
3378: 1 => 'examity',
3379: );
3380: $total = 2;
3381: }
3382: my @jsarray = ();
3383: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3384: push(@jsarray,$ordered{$item});
3385: }
3386: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3387: return <<"ENDSCRIPT";
3388: <script type="text/javascript">
3389: // <![CDATA[
3390: function reorderProctoring(form,item) {
3391: var changedVal;
3392: $jstext
3393: var maxh = $total;
3394: var current = new Array;
3395: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3396: for (var i=0; i<proctors.length; i++) {
3397: var elementName = 'proctoring_pos_'+proctors[i];
3398: if (elementName != item) {
3399: if (form.elements[elementName]) {
3400: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3401: current[currVal] = elementName;
3402: }
3403: }
3404: }
3405: var oldVal;
3406: for (var j=0; j<maxh; j++) {
3407: if (current[j] == undefined) {
3408: oldVal = j;
3409: }
3410: }
3411: if (oldVal < changedVal) {
3412: for (var k=oldVal+1; k<=changedVal ; k++) {
3413: var elementName = current[k];
3414: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3415: }
3416: } else {
3417: for (var k=changedVal; k<oldVal; k++) {
3418: var elementName = current[k];
3419: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3420: }
3421: }
3422: return;
3423: }
3424:
3425: function toggleProctoring(form,item) {
3426: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3427: if (fieldsets.length) {
3428: var radioname = 'proctoring_available_'+item;
3429: var num = form.elements[radioname].length;
3430: if (num) {
3431: var setvis = '';
3432: for (var i=0; i<num; i++) {
3433: if (form.elements[radioname][i].checked) {
3434: if (form.elements[radioname][i].value == '1') {
3435: setvis = 1;
3436: break;
3437: }
3438: }
3439: }
3440: for (var j=0; j<fieldsets.length; j++) {
3441: if (setvis) {
3442: fieldsets[j].style.display = 'block';
3443: } else {
3444: fieldsets[j].style.display = 'none';
3445: }
3446: }
3447: }
3448: }
3449: return;
3450: }
3451:
3452: // ]]>
3453: </script>
3454:
3455: ENDSCRIPT
3456: }
3457:
3458:
1.320 raeburn 3459: sub lti_javascript {
1.405 raeburn 3460: my ($dom,$settings) = @_;
3461: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3462: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3463: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3464: return $togglejs.'
3465: <script type="text/javascript">
3466: // <![CDATA[
3467:
3468: '.$linkprot_js.'
3469:
3470: // ]]>
3471: </script>
3472: ';
1.320 raeburn 3473: }
3474: my (%ordered,$total,%jstext);
1.390 raeburn 3475: $total = scalar(keys(%{$settings}));
1.320 raeburn 3476: foreach my $item (keys(%{$settings})) {
3477: if (ref($settings->{$item}) eq 'HASH') {
3478: my $num = $settings->{$item}{'order'};
1.390 raeburn 3479: if ($num eq '') {
3480: $num = $total - 1;
3481: }
1.320 raeburn 3482: $ordered{$num} = $item;
3483: }
3484: }
3485: my @jsarray = ();
3486: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3487: push(@jsarray,$ordered{$item});
3488: }
3489: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3490: return <<"ENDSCRIPT";
3491: <script type="text/javascript">
3492: // <![CDATA[
3493: function reorderLTI(form,item) {
3494: var changedVal;
3495: $jstext
3496: var newpos = 'lti_pos_add';
3497: var maxh = 1 + $total;
3498: var current = new Array;
3499: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3500: if (item == newpos) {
3501: changedVal = newitemVal;
3502: } else {
3503: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3504: current[newitemVal] = newpos;
3505: }
3506: for (var i=0; i<lti.length; i++) {
3507: var elementName = 'lti_pos_'+lti[i];
3508: if (elementName != item) {
3509: if (form.elements[elementName]) {
3510: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3511: current[currVal] = elementName;
3512: }
3513: }
3514: }
3515: var oldVal;
3516: for (var j=0; j<maxh; j++) {
3517: if (current[j] == undefined) {
3518: oldVal = j;
3519: }
3520: }
3521: if (oldVal < changedVal) {
3522: for (var k=oldVal+1; k<=changedVal ; k++) {
3523: var elementName = current[k];
3524: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3525: }
3526: } else {
3527: for (var k=changedVal; k<oldVal; k++) {
3528: var elementName = current[k];
3529: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3530: }
3531: }
3532: return;
3533: }
1.406 raeburn 3534:
3535: $linkprot_js
3536:
1.320 raeburn 3537: // ]]>
3538: </script>
3539:
3540: $togglejs
3541:
3542: ENDSCRIPT
3543: }
3544:
3545: sub lti_toggle_js {
1.405 raeburn 3546: my ($dom) = @_;
1.325 raeburn 3547: my %lcauthparmtext = &Apache::lonlocal::texthash (
3548: localauth => 'Local auth argument',
3549: krb => 'Kerberos domain',
3550: );
1.391 raeburn 3551: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3552: &js_escape(\$crsincalert);
1.405 raeburn 3553: my %servers = &Apache::lonnet::get_servers($dom,'library');
3554: my $primary = &Apache::lonnet::domain($dom,'primary');
3555: my $course_servers = "'".join("','",keys(%servers))."'";
1.320 raeburn 3556: return <<"ENDSCRIPT";
3557: <script type="text/javascript">
3558: // <![CDATA[
3559:
3560: function toggleLTI(form,setting,item) {
1.391 raeburn 3561: if ((setting == 'requser') || (setting == 'crsinc')) {
3562: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3563: var setvis = '';
3564: var radioname = 'lti_requser_'+item;
3565: var num = form.elements[radioname].length;
3566: if (num) {
3567: for (var i=0; i<num; i++) {
3568: if (form.elements[radioname][i].checked) {
3569: if (form.elements[radioname][i].value == '1') {
3570: setvis = 1;
3571: break;
3572: }
3573: }
3574: }
3575: }
3576: if (usrfieldsets.length) {
3577: for (var j=0; j<usrfieldsets.length; j++) {
3578: if (setvis) {
3579: usrfieldsets[j].style.display = 'block';
3580: } else {
3581: usrfieldsets[j].style.display = 'none';
3582: }
3583: }
3584: }
3585: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3586: if (crsfieldsets.length) {
3587: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3588: var num = form.elements[radioname].length;
3589: if (num) {
1.391 raeburn 3590: var crsvis = '';
1.345 raeburn 3591: for (var i=0; i<num; i++) {
3592: if (form.elements[radioname][i].checked) {
3593: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3594: if (setvis == '') {
3595: if (setting == 'crsinc'){
3596: alert("$crsincalert");
3597: form.elements[radioname][0].checked = true;
3598: }
3599: } else {
3600: crsvis = 1;
3601: }
3602: break;
1.345 raeburn 3603: }
3604: }
3605: }
1.391 raeburn 3606: setvis = crsvis;
3607: }
3608: for (var j=0; j<crsfieldsets.length; j++) {
3609: if (setvis) {
3610: crsfieldsets[j].style.display = 'block';
3611: } else {
3612: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3613: }
3614: }
3615: }
1.363 raeburn 3616: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3617: var radioname = '';
3618: var divid = '';
3619: if (setting == 'user') {
3620: radioname = 'lti_mapuser_'+item;
3621: divid = 'lti_userfield_'+item;
1.343 raeburn 3622: } else if (setting == 'crs') {
1.320 raeburn 3623: radioname = 'lti_mapcrs_'+item;
3624: divid = 'lti_crsfield_'+item;
1.363 raeburn 3625: } else if (setting == 'callback') {
3626: radioname = 'lti_callback_'+item;
3627: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3628: } else {
1.351 raeburn 3629: radioname = 'lti_passback_'+item;
1.337 raeburn 3630: divid = 'lti_passback_'+item;
1.320 raeburn 3631: }
3632: var num = form.elements[radioname].length;
3633: if (num) {
3634: var setvis = '';
3635: for (var i=0; i<num; i++) {
3636: if (form.elements[radioname][i].checked) {
1.363 raeburn 3637: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3638: if (form.elements[radioname][i].value == '1') {
3639: if (document.getElementById(divid)) {
3640: document.getElementById(divid).style.display = 'inline-block';
3641: }
3642: setvis = 1;
3643: break;
3644: }
3645: } else {
3646: if (form.elements[radioname][i].value == 'other') {
3647: if (document.getElementById(divid)) {
3648: document.getElementById(divid).style.display = 'inline-block';
3649: }
3650: setvis = 1;
3651: break;
1.320 raeburn 3652: }
3653: }
1.425 raeburn 3654: }
1.320 raeburn 3655: }
3656: if (!setvis) {
3657: if (document.getElementById(divid)) {
3658: document.getElementById(divid).style.display = 'none';
3659: }
3660: }
3661: }
3662: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3663: var numsec = form.elements['lti_crssec_'+item].length;
3664: if (numsec) {
3665: var setvis = '';
3666: for (var i=0; i<numsec; i++) {
3667: if (form.elements['lti_crssec_'+item][i].checked) {
3668: if (form.elements['lti_crssec_'+item][i].value == '1') {
3669: if (document.getElementById('lti_crssecfield_'+item)) {
3670: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3671: setvis = 1;
3672: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3673: if (numsrcsec) {
3674: var setsrcvis = '';
3675: for (var j=0; j<numsrcsec; j++) {
3676: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3677: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3678: if (document.getElementById('lti_secsrcfield_'+item)) {
3679: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3680: setsrcvis = 1;
3681: }
3682: }
3683: }
3684: }
3685: if (!setsrcvis) {
3686: if (document.getElementById('lti_secsrcfield_'+item)) {
3687: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3688: }
3689: }
3690: }
3691: }
3692: }
3693: }
3694: }
3695: if (!setvis) {
3696: if (document.getElementById('lti_crssecfield_'+item)) {
3697: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3698: }
3699: if (document.getElementById('lti_secsrcfield_'+item)) {
3700: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3701: }
3702: }
3703: }
1.325 raeburn 3704: } else if (setting == 'lcauth') {
3705: var numauth = form.elements['lti_lcauth_'+item].length;
3706: if (numauth) {
3707: for (var i=0; i<numauth; i++) {
3708: if (form.elements['lti_lcauth_'+item][i].checked) {
3709: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3710: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3711: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3712: } else {
3713: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3714: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3715: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3716: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3717: } else {
3718: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3719: }
3720: }
3721: }
3722: }
3723: }
3724: }
3725: }
1.326 raeburn 3726: } else if (setting == 'lcmenu') {
3727: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3728: var divid = 'lti_menufield_'+item;
3729: var setvis = '';
3730: for (var i=0; i<menus.length; i++) {
1.425 raeburn 3731: var radioname = menus[i];
1.326 raeburn 3732: var num = form.elements[radioname].length;
3733: if (num) {
3734: for (var j=0; j<num; j++) {
3735: if (form.elements[radioname][j].checked) {
3736: if (form.elements[radioname][j].value == '1') {
3737: if (document.getElementById(divid)) {
3738: document.getElementById(divid).style.display = 'inline-block';
3739: }
3740: setvis = 1;
3741: break;
3742: }
3743: }
3744: }
3745: }
3746: if (setvis == 1) {
3747: break;
3748: }
3749: }
3750: if (!setvis) {
3751: if (document.getElementById(divid)) {
3752: document.getElementById(divid).style.display = 'none';
3753: }
3754: }
1.320 raeburn 3755: }
3756: return;
3757: }
1.405 raeburn 3758:
1.320 raeburn 3759: // ]]>
3760: </script>
3761:
3762: ENDSCRIPT
3763: }
3764:
1.385 raeburn 3765: sub autoupdate_javascript {
3766: return <<"ENDSCRIPT";
3767: <script type="text/javascript">
3768: // <![CDATA[
3769: function toggleLastActiveDays(form) {
3770: var radioname = 'lastactive';
3771: var divid = 'lastactive_div';
3772: var num = form.elements[radioname].length;
3773: if (num) {
3774: var setvis = '';
3775: for (var i=0; i<num; i++) {
3776: if (form.elements[radioname][i].checked) {
3777: if (form.elements[radioname][i].value == '1') {
3778: if (document.getElementById(divid)) {
3779: document.getElementById(divid).style.display = 'inline-block';
3780: }
3781: setvis = 1;
3782: }
3783: break;
3784: }
3785: }
3786: if (!setvis) {
3787: if (document.getElementById(divid)) {
3788: document.getElementById(divid).style.display = 'none';
3789: }
3790: }
3791: }
3792: return;
3793: }
3794: // ]]>
3795: </script>
3796:
3797: ENDSCRIPT
3798: }
3799:
1.399 raeburn 3800: sub autoenroll_javascript {
3801: return <<"ENDSCRIPT";
3802: <script type="text/javascript">
3803: // <![CDATA[
3804: function toggleFailsafe(form) {
3805: var radioname = 'autoenroll_failsafe';
3806: var divid = 'autoenroll_failsafe_div';
3807: var num = form.elements[radioname].length;
3808: if (num) {
3809: var setvis = '';
3810: for (var i=0; i<num; i++) {
3811: if (form.elements[radioname][i].checked) {
3812: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3813: if (document.getElementById(divid)) {
3814: document.getElementById(divid).style.display = 'inline-block';
3815: }
3816: setvis = 1;
3817: }
3818: break;
3819: }
3820: }
3821: if (!setvis) {
3822: if (document.getElementById(divid)) {
3823: document.getElementById(divid).style.display = 'none';
3824: }
3825: }
3826: }
3827: return;
3828: }
3829: // ]]>
3830: </script>
3831:
3832: ENDSCRIPT
3833: }
3834:
1.386 raeburn 3835: sub saml_javascript {
3836: return <<"ENDSCRIPT";
3837: <script type="text/javascript">
3838: // <![CDATA[
1.425 raeburn 3839: function toggleSamlOptions(form,hostid) {
1.386 raeburn 3840: var radioname = 'saml_'+hostid;
3841: var tablecellon = 'samloptionson_'+hostid;
3842: var tablecelloff = 'samloptionsoff_'+hostid;
3843: var num = form.elements[radioname].length;
3844: if (num) {
1.425 raeburn 3845: var setvis = '';
1.386 raeburn 3846: for (var i=0; i<num; i++) {
3847: if (form.elements[radioname][i].checked) {
1.425 raeburn 3848: if (form.elements[radioname][i].value == '1') {
1.386 raeburn 3849: if (document.getElementById(tablecellon)) {
3850: document.getElementById(tablecellon).style.display='';
3851: }
3852: if (document.getElementById(tablecelloff)) {
3853: document.getElementById(tablecelloff).style.display='none';
3854: }
3855: setvis = 1;
3856: }
3857: break;
3858: }
3859: }
3860: if (!setvis) {
3861: if (document.getElementById(tablecellon)) {
3862: document.getElementById(tablecellon).style.display='none';
3863: }
3864: if (document.getElementById(tablecelloff)) {
3865: document.getElementById(tablecelloff).style.display='';
3866: }
3867: }
3868: }
3869: return;
3870: }
3871: // ]]>
3872: </script>
3873:
3874: ENDSCRIPT
3875: }
3876:
1.394 raeburn 3877: sub ipaccess_javascript {
3878: my ($settings) = @_;
3879: my (%ordered,$total,%jstext);
3880: $total = 0;
3881: if (ref($settings) eq 'HASH') {
3882: foreach my $item (keys(%{$settings})) {
3883: if (ref($settings->{$item}) eq 'HASH') {
3884: my $num = $settings->{$item}{'order'};
3885: $ordered{$num} = $item;
3886: }
3887: }
3888: $total = scalar(keys(%{$settings}));
3889: }
3890: my @jsarray = ();
3891: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3892: push(@jsarray,$ordered{$item});
3893: }
3894: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3895: return <<"ENDSCRIPT";
3896: <script type="text/javascript">
3897: // <![CDATA[
3898: function reorderIPaccess(form,item) {
3899: var changedVal;
3900: $jstext
3901: var newpos = 'ipaccess_pos_add';
3902: var maxh = 1 + $total;
3903: var current = new Array;
3904: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3905: if (item == newpos) {
3906: changedVal = newitemVal;
3907: } else {
3908: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3909: current[newitemVal] = newpos;
3910: }
3911: for (var i=0; i<ipaccess.length; i++) {
3912: var elementName = 'ipaccess_pos_'+ipaccess[i];
3913: if (elementName != item) {
3914: if (form.elements[elementName]) {
3915: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3916: current[currVal] = elementName;
3917: }
3918: }
3919: }
3920: var oldVal;
3921: for (var j=0; j<maxh; j++) {
3922: if (current[j] == undefined) {
3923: oldVal = j;
3924: }
3925: }
3926: if (oldVal < changedVal) {
3927: for (var k=oldVal+1; k<=changedVal ; k++) {
3928: var elementName = current[k];
3929: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3930: }
3931: } else {
3932: for (var k=changedVal; k<oldVal; k++) {
3933: var elementName = current[k];
3934: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3935: }
3936: }
3937: return;
3938: }
3939: // ]]>
3940: </script>
3941:
3942: ENDSCRIPT
3943: }
3944:
1.429 ! raeburn 3945: sub authordefaults_javascript {
! 3946: my %alert = &Apache::lonlocal::texthash (
! 3947: reqd => 'Warning: at least one editor needs to be available.',
! 3948: rest => 'Unchecking this editor disallowed while others unchecked.',
! 3949: );
! 3950: &js_escape(\%alert);
! 3951: return <<"ENDSCRIPT";
! 3952: <script type="text/javascript">
! 3953: // <![CDATA[
! 3954:
! 3955: function checkEditors(form,checkbox,current) {
! 3956: if (form.elements[checkbox].length != undefined) {
! 3957: var count = 0;
! 3958: for (var i=0; i<form.elements[checkbox].length; i++) {
! 3959: if (form.elements[checkbox][i].checked) {
! 3960: count ++;
! 3961: }
! 3962: }
! 3963: if (count == 0) {
! 3964: if (current.type =='radio') {
! 3965: current.checked = true;
! 3966: alert('$alert{reqd}\\n$alert{rest}');
! 3967: }
! 3968: }
! 3969: }
! 3970: return;
! 3971: }
! 3972: // ]]>
! 3973: </script>
! 3974:
! 3975: ENDSCRIPT
! 3976: }
! 3977:
1.3 raeburn 3978: sub print_autoenroll {
1.30 raeburn 3979: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3980: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 3981: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3982: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3983: $failsafesty = 'none';
3984: %failsafechecked = (
3985: off => ' checked="checked"',
3986: );
1.3 raeburn 3987: if (ref($settings) eq 'HASH') {
3988: if (exists($settings->{'run'})) {
3989: if ($settings->{'run'} eq '0') {
3990: $runoff = ' checked="checked" ';
3991: $runon = ' ';
3992: } else {
3993: $runon = ' checked="checked" ';
3994: $runoff = ' ';
3995: }
3996: } else {
3997: if ($autorun) {
3998: $runon = ' checked="checked" ';
3999: $runoff = ' ';
4000: } else {
4001: $runoff = ' checked="checked" ';
4002: $runon = ' ';
4003: }
4004: }
1.129 raeburn 4005: if (exists($settings->{'co-owners'})) {
4006: if ($settings->{'co-owners'} eq '0') {
4007: $coownersoff = ' checked="checked" ';
4008: $coownerson = ' ';
4009: } else {
4010: $coownerson = ' checked="checked" ';
4011: $coownersoff = ' ';
4012: }
4013: } else {
4014: $coownersoff = ' checked="checked" ';
4015: $coownerson = ' ';
4016: }
1.3 raeburn 4017: if (exists($settings->{'sender_domain'})) {
4018: $defdom = $settings->{'sender_domain'};
4019: }
1.399 raeburn 4020: if (exists($settings->{'failsafe'})) {
4021: $failsafe = $settings->{'failsafe'};
4022: if ($failsafe eq 'zero') {
1.400 raeburn 4023: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 4024: $failsafechecked{'off'} = '';
4025: $failsafesty = 'inline-block';
4026: } elsif ($failsafe eq 'any') {
4027: $failsafechecked{'any'} = ' checked="checked"';
4028: $failsafechecked{'off'} = '';
4029: }
4030: $autofailsafe = $settings->{'autofailsafe'};
4031: } elsif (exists($settings->{'autofailsafe'})) {
4032: $autofailsafe = $settings->{'autofailsafe'};
4033: if ($autofailsafe ne '') {
4034: $failsafechecked{'zero'} = ' checked="checked"';
4035: $failsafe = 'zero';
1.400 raeburn 4036: $failsafechecked{'off'} = '';
1.399 raeburn 4037: }
1.274 raeburn 4038: }
1.14 raeburn 4039: } else {
4040: if ($autorun) {
4041: $runon = ' checked="checked" ';
4042: $runoff = ' ';
4043: } else {
4044: $runoff = ' checked="checked" ';
4045: $runon = ' ';
4046: }
1.3 raeburn 4047: }
4048: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4049: my $notif_sender;
4050: if (ref($settings) eq 'HASH') {
4051: $notif_sender = $settings->{'sender_uname'};
4052: }
1.3 raeburn 4053: my $datatable='<tr class="LC_odd_row">'.
4054: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4055: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4056: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4057: $runon.' value="1" />'.&mt('Yes').'</label> '.
4058: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4059: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4060: '</tr><tr>'.
4061: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4062: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4063: &mt('username').': '.
4064: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4065: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4066: ': '.$domform.'</span></td></tr>'.
4067: '<tr class="LC_odd_row">'.
4068: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4069: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4070: '<input type="radio" name="autoassign_coowners"'.
4071: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4072: '<label><input type="radio" name="autoassign_coowners"'.
4073: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4074: '</tr><tr>'.
4075: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4076: '<td class="LC_left_item"><span class="LC_nobreak">'.
4077: '<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> '.
4078: '<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 />'.
4079: '<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 4080: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4081: '<span class="LC_nobreak">'.
4082: &mt('Threshold for number of students in section to drop: [_1]',
4083: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4084: '</span></div></td></tr>';
1.274 raeburn 4085: $$rowtotal += 4;
1.3 raeburn 4086: return $datatable;
4087: }
4088:
4089: sub print_autoupdate {
1.30 raeburn 4090: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4091: my ($enable,$datatable);
1.3 raeburn 4092: if ($position eq 'top') {
1.385 raeburn 4093: my %choices = &Apache::lonlocal::texthash (
4094: run => 'Auto-update active?',
4095: classlists => 'Update information in classlists?',
4096: unexpired => 'Skip updates for users without active or future roles?',
4097: lastactive => 'Skip updates for inactive users?',
4098: );
4099: my $itemcount = 0;
1.3 raeburn 4100: my $updateon = ' ';
4101: my $updateoff = ' checked="checked" ';
4102: if (ref($settings) eq 'HASH') {
4103: if ($settings->{'run'} eq '1') {
4104: $updateon = $updateoff;
4105: $updateoff = ' ';
4106: }
4107: }
1.385 raeburn 4108: $enable = '<tr class="LC_odd_row">'.
4109: '<td>'.$choices{'run'}.'</td>'.
4110: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4111: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4112: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4113: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4114: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4115: '</tr>';
1.385 raeburn 4116: my @toggles = ('classlists','unexpired');
4117: my %defaultchecked = ('classlists' => 'off',
4118: 'unexpired' => 'off'
4119: );
4120: $$rowtotal ++;
4121: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4122: \%choices,$itemcount,'','','left','no');
4123: $datatable = $enable.$datatable;
4124: $$rowtotal += $itemcount;
4125: my $lastactiveon = ' ';
4126: my $lastactiveoff = ' checked="checked" ';
4127: my $lastactivestyle = 'none';
4128: my $lastactivedays;
4129: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4130: if (ref($settings) eq 'HASH') {
4131: if ($settings->{'lastactive'} =~ /^\d+$/) {
4132: $lastactiveon = $lastactiveoff;
4133: $lastactiveoff = ' ';
4134: $lastactivestyle = 'inline-block';
4135: $lastactivedays = $settings->{'lastactive'};
4136: }
4137: }
4138: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4139: $datatable .= '<tr'.$css_class.'>'.
4140: '<td>'.$choices{'lastactive'}.'</td>'.
4141: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4142: '<input type="radio" name="lastactive"'.
4143: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4144: ' <label>'.
4145: '<input type="radio" name="lastactive"'.
4146: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4147: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4148: ': '.&mt('inactive = no activity in last [_1] days',
4149: '<input type="text" size="5" name="lastactivedays" value="'.
4150: $lastactivedays.'" />').
4151: '</span></td>'.
4152: '</tr>';
4153: $$rowtotal ++;
1.131 raeburn 4154: } elsif ($position eq 'middle') {
4155: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4156: my $numinrow = 3;
4157: my $locknamesettings;
4158: $datatable .= &insttypes_row($settings,$types,$usertypes,
4159: $dom,$numinrow,$othertitle,
1.305 raeburn 4160: 'lockablenames',$rowtotal);
1.131 raeburn 4161: $$rowtotal ++;
1.3 raeburn 4162: } else {
1.44 raeburn 4163: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4164: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4165: 'permanentemail','id');
1.33 raeburn 4166: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4167: my $numrows = 0;
1.26 raeburn 4168: if (ref($types) eq 'ARRAY') {
4169: if (@{$types} > 0) {
4170: $datatable =
4171: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4172: \@fields,$types,\$numrows);
1.30 raeburn 4173: $$rowtotal += @{$types};
1.26 raeburn 4174: }
1.3 raeburn 4175: }
4176: $datatable .=
4177: &usertype_update_row($settings,{'default' => $othertitle},
4178: \%fieldtitles,\@fields,['default'],
4179: \$numrows);
1.30 raeburn 4180: $$rowtotal ++;
1.3 raeburn 4181: }
4182: return $datatable;
4183: }
4184:
1.125 raeburn 4185: sub print_autocreate {
4186: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4187: my (%createon,%createoff,%currhash);
1.125 raeburn 4188: my @types = ('xml','req');
4189: if (ref($settings) eq 'HASH') {
4190: foreach my $item (@types) {
4191: $createoff{$item} = ' checked="checked" ';
4192: $createon{$item} = ' ';
4193: if (exists($settings->{$item})) {
4194: if ($settings->{$item}) {
4195: $createon{$item} = ' checked="checked" ';
4196: $createoff{$item} = ' ';
4197: }
4198: }
4199: }
1.210 raeburn 4200: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4201: $currhash{$settings->{'xmldc'}} = 1;
4202: }
1.125 raeburn 4203: } else {
4204: foreach my $item (@types) {
4205: $createoff{$item} = ' checked="checked" ';
4206: $createon{$item} = ' ';
4207: }
4208: }
4209: $$rowtotal += 2;
1.191 raeburn 4210: my $numinrow = 2;
1.125 raeburn 4211: my $datatable='<tr class="LC_odd_row">'.
4212: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4213: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4214: '<input type="radio" name="autocreate_xml"'.
4215: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4216: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4217: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4218: '</td></tr><tr>'.
4219: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4220: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4221: '<input type="radio" name="autocreate_req"'.
4222: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4223: '<label><input type="radio" name="autocreate_req"'.
4224: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4225: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4226: 'autocreate_xmldc',%currhash);
1.247 raeburn 4227: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4228: if ($numdc > 1) {
1.247 raeburn 4229: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4230: '</td><td class="LC_left_item">';
1.125 raeburn 4231: } else {
1.247 raeburn 4232: $datatable .= &mt('Course creation processed as:').
4233: '</td><td class="LC_right_item">';
1.125 raeburn 4234: }
1.247 raeburn 4235: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4236: $$rowtotal += $rows;
1.125 raeburn 4237: return $datatable;
4238: }
4239:
1.23 raeburn 4240: sub print_directorysrch {
1.277 raeburn 4241: my ($position,$dom,$settings,$rowtotal) = @_;
4242: my $datatable;
4243: if ($position eq 'top') {
4244: my $instsrchon = ' ';
4245: my $instsrchoff = ' checked="checked" ';
4246: my ($exacton,$containson,$beginson);
4247: my $instlocalon = ' ';
4248: my $instlocaloff = ' checked="checked" ';
4249: if (ref($settings) eq 'HASH') {
4250: if ($settings->{'available'} eq '1') {
4251: $instsrchon = $instsrchoff;
4252: $instsrchoff = ' ';
4253: }
4254: if ($settings->{'localonly'} eq '1') {
4255: $instlocalon = $instlocaloff;
4256: $instlocaloff = ' ';
4257: }
4258: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4259: foreach my $type (@{$settings->{'searchtypes'}}) {
4260: if ($type eq 'exact') {
4261: $exacton = ' checked="checked" ';
4262: } elsif ($type eq 'contains') {
4263: $containson = ' checked="checked" ';
4264: } elsif ($type eq 'begins') {
4265: $beginson = ' checked="checked" ';
4266: }
4267: }
4268: } else {
4269: if ($settings->{'searchtypes'} eq 'exact') {
4270: $exacton = ' checked="checked" ';
4271: } elsif ($settings->{'searchtypes'} eq 'contains') {
4272: $containson = ' checked="checked" ';
4273: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4274: $exacton = ' checked="checked" ';
4275: $containson = ' checked="checked" ';
4276: }
4277: }
1.277 raeburn 4278: }
4279: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4280: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4281:
4282: my $numinrow = 4;
4283: my $cansrchrow = 0;
4284: $datatable='<tr class="LC_odd_row">'.
4285: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4286: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4287: '<input type="radio" name="dirsrch_available"'.
4288: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4289: '<label><input type="radio" name="dirsrch_available"'.
4290: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4291: '</tr><tr>'.
4292: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4293: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4294: '<input type="radio" name="dirsrch_instlocalonly"'.
4295: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4296: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4297: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4298: '</tr>';
4299: $$rowtotal += 2;
4300: if (ref($usertypes) eq 'HASH') {
4301: if (keys(%{$usertypes}) > 0) {
4302: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4303: $numinrow,$othertitle,'cansearch',
4304: $rowtotal);
1.277 raeburn 4305: $cansrchrow = 1;
1.25 raeburn 4306: }
1.23 raeburn 4307: }
1.277 raeburn 4308: if ($cansrchrow) {
4309: $$rowtotal ++;
4310: $datatable .= '<tr>';
4311: } else {
4312: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4313: }
1.277 raeburn 4314: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4315: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4316: foreach my $title (@{$titleorder}) {
4317: if (defined($searchtitles->{$title})) {
4318: my $check = ' ';
4319: if (ref($settings) eq 'HASH') {
4320: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4321: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4322: $check = ' checked="checked" ';
4323: }
1.39 raeburn 4324: }
1.25 raeburn 4325: }
1.277 raeburn 4326: $datatable .= '<td class="LC_left_item">'.
4327: '<span class="LC_nobreak"><label>'.
4328: '<input type="checkbox" name="searchby" '.
4329: 'value="'.$title.'"'.$check.'/>'.
4330: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4331: }
4332: }
1.277 raeburn 4333: $datatable .= '</tr></table></td></tr>';
4334: $$rowtotal ++;
4335: if ($cansrchrow) {
4336: $datatable .= '<tr class="LC_odd_row">';
4337: } else {
4338: $datatable .= '<tr>';
4339: }
4340: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4341: '<td class="LC_left_item" colspan="2">'.
4342: '<span class="LC_nobreak"><label>'.
4343: '<input type="checkbox" name="searchtypes" '.
4344: $exacton.' value="exact" />'.&mt('Exact match').
4345: '</label> '.
4346: '<label><input type="checkbox" name="searchtypes" '.
4347: $beginson.' value="begins" />'.&mt('Begins with').
4348: '</label> '.
4349: '<label><input type="checkbox" name="searchtypes" '.
4350: $containson.' value="contains" />'.&mt('Contains').
4351: '</label></span></td></tr>';
4352: $$rowtotal ++;
1.26 raeburn 4353: } else {
1.277 raeburn 4354: my $domsrchon = ' checked="checked" ';
4355: my $domsrchoff = ' ';
4356: my $domlocalon = ' ';
4357: my $domlocaloff = ' checked="checked" ';
4358: if (ref($settings) eq 'HASH') {
4359: if ($settings->{'lclocalonly'} eq '1') {
4360: $domlocalon = $domlocaloff;
4361: $domlocaloff = ' ';
4362: }
4363: if ($settings->{'lcavailable'} eq '0') {
4364: $domsrchoff = $domsrchon;
4365: $domsrchon = ' ';
4366: }
4367: }
4368: $datatable='<tr class="LC_odd_row">'.
4369: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4370: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4371: '<input type="radio" name="dirsrch_domavailable"'.
4372: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4373: '<label><input type="radio" name="dirsrch_domavailable"'.
4374: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4375: '</tr><tr>'.
4376: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4377: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4378: '<input type="radio" name="dirsrch_domlocalonly"'.
4379: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4380: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4381: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4382: '</tr>';
4383: $$rowtotal += 2;
1.26 raeburn 4384: }
1.25 raeburn 4385: return $datatable;
4386: }
4387:
1.28 raeburn 4388: sub print_contacts {
1.286 raeburn 4389: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4390: my $datatable;
4391: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4392: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4393: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4394: if ($position eq 'top') {
4395: if (ref($settings) eq 'HASH') {
4396: foreach my $item (@contacts) {
4397: if (exists($settings->{$item})) {
4398: $to{$item} = $settings->{$item};
4399: }
4400: }
4401: }
4402: } elsif ($position eq 'middle') {
4403: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4404: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4405: foreach my $type (@mailings) {
4406: $otheremails{$type} = '';
4407: }
1.340 raeburn 4408: } elsif ($position eq 'lower') {
4409: if (ref($settings) eq 'HASH') {
4410: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4411: %lonstatus = %{$settings->{'lonstatus'}};
4412: }
4413: }
1.286 raeburn 4414: } else {
4415: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4416: foreach my $type (@mailings) {
4417: $otheremails{$type} = '';
4418: }
1.286 raeburn 4419: $bccemails{'helpdeskmail'} = '';
4420: $bccemails{'otherdomsmail'} = '';
4421: $includestr{'helpdeskmail'} = '';
4422: $includestr{'otherdomsmail'} = '';
4423: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4424: }
1.28 raeburn 4425: if (ref($settings) eq 'HASH') {
1.340 raeburn 4426: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4427: foreach my $type (@mailings) {
4428: if (exists($settings->{$type})) {
4429: if (ref($settings->{$type}) eq 'HASH') {
4430: foreach my $item (@contacts) {
4431: if ($settings->{$type}{$item}) {
4432: $checked{$type}{$item} = ' checked="checked" ';
4433: }
4434: }
4435: $otheremails{$type} = $settings->{$type}{'others'};
4436: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4437: $bccemails{$type} = $settings->{$type}{'bcc'};
4438: if ($settings->{$type}{'include'} ne '') {
4439: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4440: $includestr{$type} = &unescape($includestr{$type});
4441: }
4442: }
4443: }
4444: } elsif ($type eq 'lonstatusmail') {
4445: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4446: }
1.28 raeburn 4447: }
4448: }
1.286 raeburn 4449: if ($position eq 'bottom') {
4450: foreach my $type (@mailings) {
4451: $bccemails{$type} = $settings->{$type}{'bcc'};
4452: if ($settings->{$type}{'include'} ne '') {
4453: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4454: $includestr{$type} = &unescape($includestr{$type});
4455: }
4456: }
4457: if (ref($settings->{'helpform'}) eq 'HASH') {
4458: if (ref($fields) eq 'ARRAY') {
4459: foreach my $field (@{$fields}) {
4460: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4461: }
1.286 raeburn 4462: }
4463: if (exists($settings->{'helpform'}{'maxsize'})) {
4464: $maxsize = $settings->{'helpform'}{'maxsize'};
4465: } else {
1.289 raeburn 4466: $maxsize = '1.0';
1.286 raeburn 4467: }
4468: } else {
4469: if (ref($fields) eq 'ARRAY') {
4470: foreach my $field (@{$fields}) {
4471: $currfield{$field} = 'yes';
1.134 raeburn 4472: }
1.28 raeburn 4473: }
1.286 raeburn 4474: $maxsize = '1.0';
1.28 raeburn 4475: }
4476: }
4477: } else {
1.286 raeburn 4478: if ($position eq 'top') {
4479: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4480: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4481: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4482: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4483: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4484: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4485: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4486: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4487: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4488: } elsif ($position eq 'bottom') {
4489: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4490: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4491: if (ref($fields) eq 'ARRAY') {
4492: foreach my $field (@{$fields}) {
4493: $currfield{$field} = 'yes';
4494: }
4495: }
4496: $maxsize = '1.0';
4497: }
1.28 raeburn 4498: }
4499: my ($titles,$short_titles) = &contact_titles();
4500: my $rownum = 0;
4501: my $css_class;
1.286 raeburn 4502: if ($position eq 'top') {
4503: foreach my $item (@contacts) {
4504: $css_class = $rownum%2?' class="LC_odd_row"':'';
4505: $datatable .= '<tr'.$css_class.'>'.
4506: '<td><span class="LC_nobreak">'.$titles->{$item}.
4507: '</span></td><td class="LC_right_item">'.
4508: '<input type="text" name="'.$item.'" value="'.
4509: $to{$item}.'" /></td></tr>';
4510: $rownum ++;
4511: }
1.315 raeburn 4512: } elsif ($position eq 'bottom') {
4513: $css_class = $rownum%2?' class="LC_odd_row"':'';
4514: $datatable .= '<tr'.$css_class.'>'.
4515: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4516: &mt('(e-mail, subject, and description always shown)').
4517: '</td><td class="LC_left_item">';
4518: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4519: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4520: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4521: foreach my $field (@{$fields}) {
4522: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4523: if (($field eq 'screenshot') || ($field eq 'cc')) {
4524: $datatable .= ' '.&mt('(logged-in users)');
4525: }
4526: $datatable .='</td><td>';
4527: my $clickaction;
4528: if ($field eq 'screenshot') {
4529: $clickaction = ' onclick="screenshotSize(this);"';
4530: }
4531: if (ref($possoptions->{$field}) eq 'ARRAY') {
4532: foreach my $option (@{$possoptions->{$field}}) {
4533: my $checked;
4534: if ($currfield{$field} eq $option) {
4535: $checked = ' checked="checked"';
4536: }
4537: $datatable .= '<span class="LC_nobreak"><label>'.
4538: '<input type="radio" name="helpform_'.$field.'" '.
4539: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4540: '</label></span>'.(' 'x2);
4541: }
4542: }
4543: if ($field eq 'screenshot') {
4544: my $display;
4545: if ($currfield{$field} eq 'no') {
4546: $display = ' style="display:none"';
4547: }
1.334 raeburn 4548: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4549: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4550: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4551: }
4552: $datatable .= '</td></tr>';
4553: }
4554: $datatable .= '</table>';
4555: }
4556: $datatable .= '</td></tr>'."\n";
4557: $rownum ++;
4558: }
1.340 raeburn 4559: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4560: foreach my $type (@mailings) {
4561: $css_class = $rownum%2?' class="LC_odd_row"':'';
4562: $datatable .= '<tr'.$css_class.'>'.
4563: '<td><span class="LC_nobreak">'.
4564: $titles->{$type}.': </span></td>'.
4565: '<td class="LC_left_item">';
4566: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4567: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4568: }
4569: $datatable .= '<span class="LC_nobreak">';
4570: foreach my $item (@contacts) {
4571: $datatable .= '<label>'.
4572: '<input type="checkbox" name="'.$type.'"'.
4573: $checked{$type}{$item}.
4574: ' value="'.$item.'" />'.$short_titles->{$item}.
4575: '</label> ';
4576: }
4577: $datatable .= '</span><br />'.&mt('Others').': '.
4578: '<input type="text" name="'.$type.'_others" '.
4579: 'value="'.$otheremails{$type}.'" />';
4580: my %locchecked;
4581: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4582: foreach my $loc ('s','b') {
4583: if ($includeloc{$type} eq $loc) {
4584: $locchecked{$loc} = ' checked="checked"';
4585: last;
4586: }
4587: }
4588: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4589: '<input type="text" name="'.$type.'_bcc" '.
4590: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4591: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4592: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4593: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4594: '<span class="LC_nobreak">'.&mt('Location:').' '.
4595: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4596: (' 'x2).
4597: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4598: '</span></fieldset>';
4599: }
4600: $datatable .= '</td></tr>'."\n";
4601: $rownum ++;
4602: }
1.28 raeburn 4603: }
1.286 raeburn 4604: if ($position eq 'middle') {
4605: my %choices;
1.340 raeburn 4606: my $corelink = &core_link_msu();
4607: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4608: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4609: $corelink);
4610: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4611: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4612: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4613: 'reportupdates' => 'on',
4614: 'reportstatus' => 'on');
1.286 raeburn 4615: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4616: \%choices,$rownum);
4617: $datatable .= $reports;
1.340 raeburn 4618: } elsif ($position eq 'lower') {
1.378 raeburn 4619: my (%current,%excluded,%weights);
1.340 raeburn 4620: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4621: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4622: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4623: } else {
1.378 raeburn 4624: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4625: }
4626: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4627: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4628: } else {
1.378 raeburn 4629: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4630: }
4631: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4632: foreach my $type ('E','W','N','U') {
1.340 raeburn 4633: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4634: $weights{$type} = $lonstatus{'weights'}{$type};
4635: } else {
4636: $weights{$type} = $defaults->{$type};
4637: }
4638: }
4639: } else {
1.341 raeburn 4640: foreach my $type ('E','W','N','U') {
1.340 raeburn 4641: $weights{$type} = $defaults->{$type};
4642: }
4643: }
4644: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4645: if (@{$lonstatus{'excluded'}} > 0) {
4646: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4647: }
4648: }
1.425 raeburn 4649: foreach my $item ('errorthreshold','errorsysmail') {
1.378 raeburn 4650: $css_class = $rownum%2?' class="LC_odd_row"':'';
4651: $datatable .= '<tr'.$css_class.'>'.
4652: '<td class="LC_left_item"><span class="LC_nobreak">'.
4653: $titles->{$item}.
4654: '</span></td><td class="LC_left_item">'.
4655: '<input type="text" name="'.$item.'" value="'.
4656: $current{$item}.'" size="5" /></td></tr>';
4657: $rownum ++;
4658: }
1.340 raeburn 4659: $css_class = $rownum%2?' class="LC_odd_row"':'';
4660: $datatable .= '<tr'.$css_class.'>'.
4661: '<td class="LC_left_item">'.
4662: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4663: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4664: foreach my $type ('E','W','N','U') {
1.340 raeburn 4665: $datatable .= '<td>'.$names->{$type}.'<br />'.
4666: '<input type="text" name="errorweights_'.$type.'" value="'.
4667: $weights{$type}.'" size="5" /></td>';
4668: }
4669: $datatable .= '</tr></table></tr>';
4670: $rownum ++;
4671: $css_class = $rownum%2?' class="LC_odd_row"':'';
4672: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4673: $titles->{'errorexcluded'}.'</td>'.
4674: '<td class="LC_left_item"><table>';
4675: my $numinrow = 4;
4676: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4677: for (my $i=0; $i<@ids; $i++) {
4678: my $rem = $i%($numinrow);
4679: if ($rem == 0) {
4680: if ($i > 0) {
4681: $datatable .= '</tr>';
4682: }
4683: $datatable .= '<tr>';
4684: }
4685: my $check;
4686: if ($excluded{$ids[$i]}) {
4687: $check = ' checked="checked" ';
4688: }
4689: $datatable .= '<td class="LC_left_item">'.
4690: '<span class="LC_nobreak"><label>'.
4691: '<input type="checkbox" name="errorexcluded" '.
4692: 'value="'.$ids[$i].'"'.$check.' />'.
4693: $ids[$i].'</label></span></td>';
4694: }
4695: my $colsleft = $numinrow - @ids%($numinrow);
4696: if ($colsleft > 1 ) {
4697: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4698: ' </td>';
4699: } elsif ($colsleft == 1) {
4700: $datatable .= '<td class="LC_left_item"> </td>';
4701: }
4702: $datatable .= '</tr></table></td></tr>';
4703: $rownum ++;
1.286 raeburn 4704: } elsif ($position eq 'bottom') {
1.315 raeburn 4705: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4706: my (@posstypes,%usertypeshash);
4707: if (ref($types) eq 'ARRAY') {
4708: @posstypes = @{$types};
4709: }
4710: if (@posstypes) {
4711: if (ref($usertypes) eq 'HASH') {
4712: %usertypeshash = %{$usertypes};
4713: }
4714: my @overridden;
4715: my $numinrow = 4;
4716: if (ref($settings) eq 'HASH') {
4717: if (ref($settings->{'overrides'}) eq 'HASH') {
4718: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4719: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4720: push(@overridden,$key);
4721: foreach my $item (@contacts) {
4722: if ($settings->{'overrides'}{$key}{$item}) {
4723: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4724: }
4725: }
4726: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4727: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4728: $includeloc{'override_'.$key} = '';
4729: $includestr{'override_'.$key} = '';
4730: if ($settings->{'overrides'}{$key}{'include'} ne '') {
1.425 raeburn 4731: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
1.315 raeburn 4732: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4733: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4734: }
1.286 raeburn 4735: }
4736: }
4737: }
1.315 raeburn 4738: }
4739: my $customclass = 'LC_helpdesk_override';
4740: my $optionsprefix = 'LC_options_helpdesk_';
4741:
4742: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4743: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4744: $numinrow,$othertitle,'overrides',
4745: \$rownum,$onclicktypes,$customclass);
4746: $rownum ++;
4747: $usertypeshash{'default'} = $othertitle;
4748: foreach my $status (@posstypes) {
4749: my $css_class;
4750: if ($rownum%2) {
4751: $css_class = 'LC_odd_row ';
4752: }
4753: $css_class .= $customclass;
4754: my $rowid = $optionsprefix.$status;
4755: my $hidden = 1;
4756: my $currstyle = 'display:none';
4757: if (grep(/^\Q$status\E$/,@overridden)) {
4758: $currstyle = 'display:table-row';
4759: $hidden = 0;
4760: }
4761: my $key = 'override_'.$status;
4762: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4763: $includeloc{$key},$includestr{$key},$status,$rowid,
4764: $usertypeshash{$status},$css_class,$currstyle,
4765: \@contacts,$short_titles);
4766: unless ($hidden) {
4767: $rownum ++;
1.286 raeburn 4768: }
4769: }
1.134 raeburn 4770: }
1.28 raeburn 4771: }
1.30 raeburn 4772: $$rowtotal += $rownum;
1.28 raeburn 4773: return $datatable;
4774: }
4775:
1.340 raeburn 4776: sub core_link_msu {
4777: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4778: &mt('LON-CAPA core group - MSU'),600,500);
4779: }
4780:
1.315 raeburn 4781: sub overridden_helpdesk {
4782: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4783: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4784: my $class = 'LC_left_item';
4785: if ($css_class) {
4786: $css_class = ' class="'.$css_class.'"';
4787: }
4788: if ($rowid) {
4789: $rowid = ' id="'.$rowid.'"';
4790: }
4791: if ($rowstyle) {
4792: $rowstyle = ' style="'.$rowstyle.'"';
4793: }
4794: my ($output,$description);
4795: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4796: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4797: "<td>$description</td>\n".
4798: '<td class="'.$class.'" colspan="2">'.
4799: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4800: '<span class="LC_nobreak">';
4801: if (ref($contacts) eq 'ARRAY') {
4802: foreach my $item (@{$contacts}) {
4803: my $check;
4804: if (ref($checked) eq 'HASH') {
4805: $check = $checked->{$item};
4806: }
4807: my $title;
4808: if (ref($short_titles) eq 'HASH') {
1.425 raeburn 4809: $title = $short_titles->{$item};
1.315 raeburn 4810: }
4811: $output .= '<label>'.
4812: '<input type="checkbox" name="override_'.$type.'"'.$check.
4813: ' value="'.$item.'" />'.$title.'</label> ';
4814: }
4815: }
4816: $output .= '</span><br />'.&mt('Others').': '.
4817: '<input type="text" name="override_'.$type.'_others" '.
4818: 'value="'.$otheremails.'" />';
4819: my %locchecked;
4820: foreach my $loc ('s','b') {
4821: if ($includeloc eq $loc) {
4822: $locchecked{$loc} = ' checked="checked"';
4823: last;
4824: }
4825: }
4826: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4827: '<input type="text" name="override_'.$type.'_bcc" '.
4828: 'value="'.$bccemails.'" /></fieldset>'.
4829: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4830: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4831: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4832: '<span class="LC_nobreak">'.&mt('Location:').' '.
4833: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4834: (' 'x2).
4835: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4836: '</span></fieldset>'.
4837: '</td></tr>'."\n";
4838: return $output;
4839: }
4840:
1.286 raeburn 4841: sub contacts_javascript {
4842: return <<"ENDSCRIPT";
4843:
4844: <script type="text/javascript">
4845: // <![CDATA[
4846:
4847: function screenshotSize(field) {
4848: if (document.getElementById('help_screenshotsize')) {
4849: if (field.value == 'no') {
1.289 raeburn 4850: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4851: } else {
4852: document.getElementById('help_screenshotsize').style.display="";
4853: }
4854: }
4855: return;
4856: }
4857:
1.315 raeburn 4858: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4859: if (form.elements[checkbox].length != undefined) {
4860: var count = 0;
4861: if (docount) {
4862: for (var i=0; i<form.elements[checkbox].length; i++) {
4863: if (form.elements[checkbox][i].checked) {
4864: count ++;
4865: }
4866: }
4867: }
4868: for (var i=0; i<form.elements[checkbox].length; i++) {
4869: var type = form.elements[checkbox][i].value;
4870: if (document.getElementById(prefix+type)) {
4871: if (form.elements[checkbox][i].checked) {
4872: document.getElementById(prefix+type).style.display = 'table-row';
4873: if (count % 2 == 1) {
4874: document.getElementById(prefix+type).className = target+' LC_odd_row';
4875: } else {
4876: document.getElementById(prefix+type).className = target;
4877: }
4878: count ++;
4879: } else {
4880: document.getElementById(prefix+type).style.display = 'none';
4881: }
4882: }
4883: }
4884: }
4885: return;
4886: }
4887:
1.286 raeburn 4888: // ]]>
4889: </script>
4890:
4891: ENDSCRIPT
4892: }
4893:
1.118 jms 4894: sub print_helpsettings {
1.282 raeburn 4895: my ($position,$dom,$settings,$rowtotal) = @_;
4896: my $confname = $dom.'-domainconfig';
1.285 raeburn 4897: my $formname = 'display';
1.168 raeburn 4898: my ($datatable,$itemcount);
1.282 raeburn 4899: if ($position eq 'top') {
4900: $itemcount = 1;
4901: my (%choices,%defaultchecked,@toggles);
4902: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4903: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4904: &mt('LON-CAPA bug tracker'),600,500));
4905: %defaultchecked = ('submitbugs' => 'on');
4906: @toggles = ('submitbugs');
4907: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4908: \%choices,$itemcount);
4909: $$rowtotal ++;
4910: } else {
4911: my $css_class;
4912: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4913: my (%customroles,%ordered,%current);
1.301 raeburn 4914: if (ref($settings) eq 'HASH') {
4915: if (ref($settings->{'adhoc'}) eq 'HASH') {
4916: %current = %{$settings->{'adhoc'}};
4917: }
1.285 raeburn 4918: }
4919: my $count = 0;
4920: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4921: if ($key=~/^rolesdef\_(\w+)$/) {
4922: my $rolename = $1;
1.285 raeburn 4923: my (%privs,$order);
1.282 raeburn 4924: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4925: $customroles{$rolename} = \%privs;
1.285 raeburn 4926: if (ref($current{$rolename}) eq 'HASH') {
4927: $order = $current{$rolename}{'order'};
4928: }
4929: if ($order eq '') {
4930: $order = $count;
4931: }
4932: $ordered{$order} = $rolename;
4933: $count++;
4934: }
4935: }
4936: my $maxnum = scalar(keys(%ordered));
4937: my @roles_by_num = ();
4938: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4939: push(@roles_by_num,$item);
4940: }
4941: my $context = 'domprefs';
4942: my $crstype = 'Course';
4943: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4944: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4945: my ($numstatustypes,@jsarray);
4946: if (ref($types) eq 'ARRAY') {
4947: if (@{$types} > 0) {
4948: $numstatustypes = scalar(@{$types});
4949: push(@accesstypes,'status');
4950: @jsarray = ('bystatus');
1.282 raeburn 4951: }
4952: }
1.290 raeburn 4953: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4954: if (keys(%domhelpdesk)) {
4955: push(@accesstypes,('inc','exc'));
4956: push(@jsarray,('notinc','notexc'));
4957: }
4958: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4959: my $context = 'domprefs';
4960: my $crstype = 'Course';
1.285 raeburn 4961: my $prefix = 'helproles_';
4962: my $add_class = 'LC_hidden';
4963: foreach my $num (@roles_by_num) {
4964: my $role = $ordered{$num};
4965: my ($desc,$access,@statuses);
4966: if (ref($current{$role}) eq 'HASH') {
4967: $desc = $current{$role}{'desc'};
4968: $access = $current{$role}{'access'};
4969: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4970: @statuses = @{$current{$role}{'insttypes'}};
4971: }
4972: }
4973: if ($desc eq '') {
4974: $desc = $role;
4975: }
4976: my $identifier = 'custhelp'.$num;
1.282 raeburn 4977: my %full=();
4978: my %levels= (
4979: course => {},
4980: domain => {},
4981: system => {},
4982: );
4983: my %levelscurrent=(
4984: course => {},
4985: domain => {},
4986: system => {},
4987: );
4988: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4989: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4990: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4991: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4992: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4993: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4994: for (my $k=0; $k<=$maxnum; $k++) {
4995: my $vpos = $k+1;
4996: my $selstr;
4997: if ($k == $num) {
4998: $selstr = ' selected="selected" ';
4999: }
5000: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5001: }
5002: $datatable .= '</select>'.(' 'x2).
5003: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
5004: '</td>'.
5005: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5006: &mt('Name shown to users:').
5007: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
5008: '</fieldset>'.
5009: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
5010: $othertitle,$usertypes,$types,\%domhelpdesk).
5011: '<fieldset>'.
5012: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 5013: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 5014: \%levelscurrent,$identifier,
5015: 'LC_hidden',$prefix.$num.'_privs').
5016: '</fieldset></td>';
1.282 raeburn 5017: $itemcount ++;
5018: }
5019: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5020: my $newcust = 'custhelp'.$count;
5021: my (%privs,%levelscurrent);
5022: my %full=();
5023: my %levels= (
5024: course => {},
5025: domain => {},
5026: system => {},
5027: );
5028: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
5029: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5030: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5031: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5032: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5033: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5034: for (my $k=0; $k<$maxnum+1; $k++) {
5035: my $vpos = $k+1;
5036: my $selstr;
5037: if ($k == $maxnum) {
5038: $selstr = ' selected="selected" ';
5039: }
5040: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5041: }
5042: $datatable .= '</select> '."\n".
1.282 raeburn 5043: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5044: '</label></span></td>'.
1.285 raeburn 5045: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5046: '<span class="LC_nobreak">'.
5047: &mt('Internal name:').
5048: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5049: '</span>'.(' 'x4).
5050: '<span class="LC_nobreak">'.
5051: &mt('Name shown to users:').
5052: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5053: '</span></fieldset>'.
5054: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5055: $usertypes,$types,\%domhelpdesk).
5056: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5057: &Apache::lonuserutils::custom_role_header($context,$crstype,
5058: \@templateroles,$newcust).
5059: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5060: \%levelscurrent,$newcust).
1.334 raeburn 5061: '</fieldset>'.
5062: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5063: '</td></tr>';
1.282 raeburn 5064: $count ++;
5065: $$rowtotal += $count;
5066: }
1.166 raeburn 5067: return $datatable;
1.121 raeburn 5068: }
5069:
1.285 raeburn 5070: sub adhocbutton {
5071: my ($prefix,$num,$field,$visibility) = @_;
5072: my %lt = &Apache::lonlocal::texthash(
5073: show => 'Show details',
5074: hide => 'Hide details',
5075: );
5076: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5077: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5078: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5079: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5080: }
5081:
5082: sub helpsettings_javascript {
5083: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5084: return unless(ref($roles_by_num) eq 'ARRAY');
5085: my %html_js_lt = &Apache::lonlocal::texthash(
5086: show => 'Show details',
5087: hide => 'Hide details',
5088: );
5089: &html_escape(\%html_js_lt);
5090: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5091: return <<"ENDSCRIPT";
5092: <script type="text/javascript">
5093: // <![CDATA[
5094:
5095: function reorderHelpRoles(form,item) {
5096: var changedVal;
5097: $jstext
5098: var newpos = 'helproles_${total}_pos';
5099: var maxh = 1 + $total;
5100: var current = new Array();
5101: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5102: if (item == newpos) {
5103: changedVal = newitemVal;
5104: } else {
5105: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5106: current[newitemVal] = newpos;
5107: }
5108: for (var i=0; i<helproles.length; i++) {
5109: var elementName = 'helproles_'+helproles[i]+'_pos';
5110: if (elementName != item) {
5111: if (form.elements[elementName]) {
5112: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5113: current[currVal] = elementName;
5114: }
5115: }
5116: }
5117: var oldVal;
5118: for (var j=0; j<maxh; j++) {
5119: if (current[j] == undefined) {
5120: oldVal = j;
5121: }
5122: }
5123: if (oldVal < changedVal) {
5124: for (var k=oldVal+1; k<=changedVal ; k++) {
5125: var elementName = current[k];
5126: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5127: }
5128: } else {
5129: for (var k=changedVal; k<oldVal; k++) {
5130: var elementName = current[k];
5131: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5132: }
5133: }
5134: return;
5135: }
5136:
5137: function helpdeskAccess(num) {
5138: var curraccess = null;
5139: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5140: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5141: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5142: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5143: }
5144: }
5145: }
5146: var shown = Array();
5147: var hidden = Array();
5148: if (curraccess == 'none') {
5149: hidden = Array('$hiddenstr');
5150: } else {
5151: if (curraccess == 'status') {
5152: shown = Array('bystatus');
5153: hidden = Array('notinc','notexc');
5154: } else {
5155: if (curraccess == 'exc') {
5156: shown = Array('notexc');
5157: hidden = Array('notinc','bystatus');
5158: }
5159: if (curraccess == 'inc') {
5160: shown = Array('notinc');
5161: hidden = Array('notexc','bystatus');
5162: }
1.293 raeburn 5163: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5164: hidden = Array('notinc','notexc','bystatus');
5165: }
5166: }
5167: }
5168: if (hidden.length > 0) {
5169: for (var i=0; i<hidden.length; i++) {
5170: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5171: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5172: }
5173: }
5174: }
5175: if (shown.length > 0) {
5176: for (var i=0; i<shown.length; i++) {
5177: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5178: if (shown[i] == 'privs') {
5179: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5180: } else {
5181: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5182: }
5183: }
5184: }
5185: }
5186: return;
5187: }
5188:
5189: function toggleHelpdeskItem(num,field) {
5190: if (document.getElementById('helproles_'+num+'_'+field)) {
5191: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5192: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5193: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5194: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5195: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5196: }
5197: } else {
5198: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5199: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5200: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5201: }
5202: }
5203: }
5204: return;
5205: }
5206:
5207: // ]]>
5208: </script>
5209:
5210: ENDSCRIPT
5211: }
5212:
5213: sub helpdeskroles_access {
5214: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5215: $usertypes,$types,$domhelpdesk) = @_;
5216: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5217: my %lt = &Apache::lonlocal::texthash(
5218: 'rou' => 'Role usage',
5219: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5220: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5221: 'dh' => 'All with domain helpdesk role',
5222: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5223: 'none' => 'None',
5224: 'status' => 'Determined based on institutional status',
5225: 'inc' => 'Include all, but exclude specific personnel',
5226: 'exc' => 'Exclude all, but include specific personnel',
5227: );
5228: my %usecheck = (
5229: all => ' checked="checked"',
5230: );
5231: my %displaydiv = (
5232: status => 'none',
5233: inc => 'none',
5234: exc => 'none',
5235: priv => 'block',
5236: );
5237: my $output;
5238: if (ref($current) eq 'HASH') {
5239: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5240: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5241: $usecheck{$current->{access}} = $usecheck{'all'};
5242: delete($usecheck{'all'});
5243: if ($current->{access} =~ /^(status|inc|exc)$/) {
5244: my $access = $1;
5245: $displaydiv{$access} = 'inline';
5246: } elsif ($current->{access} eq 'none') {
5247: $displaydiv{'priv'} = 'none';
5248: }
5249: }
5250: }
5251: }
5252: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5253: '<p>'.$lt{'whi'}.'</p>';
5254: foreach my $access (@{$accesstypes}) {
5255: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5256: ' onclick="helpdeskAccess('."'$num'".');" />'.
5257: $lt{$access}.'</label>';
5258: if ($access eq 'status') {
5259: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5260: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5261: $othertitle,$usertypes,$types).
5262: '</div>';
5263: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5264: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5265: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5266: '</div>';
5267: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5268: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5269: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5270: '</div>';
5271: }
5272: $output .= '</p>';
5273: }
5274: $output .= '</fieldset>';
5275: return $output;
5276: }
5277:
1.121 raeburn 5278: sub radiobutton_prefs {
1.192 raeburn 5279: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5280: $additional,$align,$firstval) = @_;
1.121 raeburn 5281: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5282: (ref($choices) eq 'HASH'));
5283:
1.170 raeburn 5284: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5285:
5286: foreach my $item (@{$toggles}) {
5287: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5288: $checkedon{$item} = ' checked="checked" ';
5289: $checkedoff{$item} = ' ';
1.121 raeburn 5290: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5291: $checkedoff{$item} = ' checked="checked" ';
5292: $checkedon{$item} = ' ';
5293: }
5294: }
5295: if (ref($settings) eq 'HASH') {
1.121 raeburn 5296: foreach my $item (@{$toggles}) {
1.118 jms 5297: if ($settings->{$item} eq '1') {
5298: $checkedon{$item} = ' checked="checked" ';
5299: $checkedoff{$item} = ' ';
5300: } elsif ($settings->{$item} eq '0') {
5301: $checkedoff{$item} = ' checked="checked" ';
5302: $checkedon{$item} = ' ';
5303: }
5304: }
1.121 raeburn 5305: }
1.192 raeburn 5306: if ($onclick) {
5307: $onclick = ' onclick="'.$onclick.'"';
5308: }
1.121 raeburn 5309: foreach my $item (@{$toggles}) {
1.118 jms 5310: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5311: $datatable .=
1.306 raeburn 5312: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5313: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5314: '</span></td>';
5315: if ($align eq 'left') {
5316: $datatable .= '<td class="LC_left_item">';
5317: } else {
5318: $datatable .= '<td class="LC_right_item">';
5319: }
1.385 raeburn 5320: $datatable .= '<span class="LC_nobreak">';
5321: if ($firstval eq 'no') {
5322: $datatable .=
5323: '<label><input type="radio" name="'.
5324: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5325: '</label> <label><input type="radio" name="'.$item.'" '.
5326: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5327: } else {
5328: $datatable .=
5329: '<label><input type="radio" name="'.
5330: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5331: '</label> <label><input type="radio" name="'.$item.'" '.
5332: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5333: }
5334: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5335: $itemcount ++;
1.121 raeburn 5336: }
5337: return ($datatable,$itemcount);
5338: }
5339:
1.267 raeburn 5340: sub print_ltitools {
1.421 raeburn 5341: my ($position,$dom,$settings,$rowtotal) = @_;
5342: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5343: if (ref($settings) eq 'HASH') {
1.421 raeburn 5344: if ($position eq 'top') {
5345: if (exists($settings->{'encrypt'})) {
5346: if (ref($settings->{'encrypt'}) eq 'HASH') {
5347: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5348: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5349: }
5350: }
1.267 raeburn 5351: }
1.421 raeburn 5352: if (exists($settings->{'private'})) {
5353: if (ref($settings->{'private'}) eq 'HASH') {
5354: if (ref($settings->{'private'}) eq 'HASH') {
5355: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5356: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5357: }
5358: }
5359: }
5360: }
1.421 raeburn 5361: } elsif ($position eq 'middle') {
5362: if (exists($settings->{'rules'})) {
5363: if (ref($settings->{'rules'}) eq 'HASH') {
5364: %rules = %{$settings->{'rules'}};
1.273 raeburn 5365: }
5366: }
1.421 raeburn 5367: } else {
5368: foreach my $key ('encrypt','private','rules') {
5369: if (exists($settings->{$key})) {
5370: delete($settings->{$key});
1.267 raeburn 5371: }
5372: }
5373: }
5374: }
1.421 raeburn 5375: my $datatable;
5376: my $itemcount = 1;
5377: if ($position eq 'top') {
5378: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5379: } elsif ($position eq 'middle') {
5380: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5381: $$rowtotal += $itemcount;
5382: } else {
5383: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5384: }
5385: return $datatable;
5386: }
5387:
5388: sub ltitools_names {
5389: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5390: 'title' => 'Title',
5391: 'version' => 'Version',
5392: 'msgtype' => 'Message Type',
1.323 raeburn 5393: 'sigmethod' => 'Signature Method',
1.296 raeburn 5394: 'url' => 'URL',
5395: 'key' => 'Key',
1.322 raeburn 5396: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5397: 'secret' => 'Secret',
1.425 raeburn 5398: 'icon' => 'Icon',
1.324 raeburn 5399: 'user' => 'User',
1.296 raeburn 5400: 'fullname' => 'Full Name',
5401: 'firstname' => 'First Name',
5402: 'lastname' => 'Last Name',
5403: 'email' => 'E-mail',
5404: 'roles' => 'Role',
1.298 raeburn 5405: 'window' => 'Window',
5406: 'tab' => 'Tab',
1.296 raeburn 5407: 'iframe' => 'iFrame',
5408: 'height' => 'Height',
5409: 'width' => 'Width',
5410: 'linktext' => 'Default Link Text',
5411: 'explanation' => 'Default Explanation',
5412: 'passback' => 'Tool can return grades:',
5413: 'roster' => 'Tool can retrieve roster:',
5414: 'crstarget' => 'Display target',
5415: 'crslabel' => 'Course label',
1.425 raeburn 5416: 'crstitle' => 'Course title',
1.296 raeburn 5417: 'crslinktext' => 'Link Text',
5418: 'crsexplanation' => 'Explanation',
1.318 raeburn 5419: 'crsappend' => 'Provider URL',
1.267 raeburn 5420: );
5421: return %lt;
5422: }
5423:
1.421 raeburn 5424: sub secrets_form {
5425: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5426: my @ids=&Apache::lonnet::current_machine_ids();
5427: my %servers = &Apache::lonnet::get_servers($dom,'library');
5428: my $primary = &Apache::lonnet::domain($dom,'primary');
5429: my ($css_class,$extra,$numshown,$itemcount,$output);
5430: $itemcount = 0;
5431: foreach my $hostid (sort(keys(%servers))) {
5432: my ($showextra,$divsty,$switch);
5433: if ($hostid eq $primary) {
5434: if ($context eq 'ltisec') {
5435: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5436: $showextra = 1;
5437: }
5438: if ($encrypt->{'ltisec_crslinkprot'}) {
5439: $showextra = 1;
5440: }
5441: } else {
5442: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5443: $showextra = 1;
5444: }
5445: }
5446: unless (grep(/^\Q$hostid\E$/,@ids)) {
5447: $switch = 1;
5448: }
5449: if ($showextra) {
5450: $numshown ++;
5451: $divsty = 'display:inline-block';
5452: } else {
5453: $divsty = 'display:none';
5454: }
5455: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5456: '<legend>'.$hostid.'</legend>';
5457: if ($switch) {
5458: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5459: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5460: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5461: if (exists($privkeys->{$hostid})) {
5462: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5463: '<span class="LC_nobreak">'.
5464: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5465: '<span class="LC_nobreak">'.&mt('Change?').
5466: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5467: (' 'x2).
5468: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5469: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5470: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5471: '</span></div>';
5472: } else {
5473: $extra .= '<span class="LC_nobreak">'.
5474: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5475: '</span>'."\n";
5476: }
5477: } elsif (exists($privkeys->{$hostid})) {
5478: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5479: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5480: '<span class="LC_nobreak">'.&mt('Change?').
5481: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5482: (' 'x2).
5483: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5484: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5485: '<span class="LC_nobreak">'.&mt('New Key').':'.
5486: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5487: '<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>'.
5488: '</span></div>';
5489: } else {
5490: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5491: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5492: '<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>';
5493: }
5494: $extra .= '</fieldset>';
5495: }
5496: }
5497: my (%choices,@toggles,%defaultchecked);
5498: if ($context eq 'ltisec') {
5499: %choices = &Apache::lonlocal::texthash (
5500: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5501: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5502: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5503: );
5504: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5505: %defaultchecked = (
5506: 'ltisec_crslinkprot' => 'off',
5507: 'ltisec_domlinkprot' => 'off',
5508: 'ltisec_consumers' => 'off',
5509: );
5510: } else {
5511: %choices = &Apache::lonlocal::texthash (
5512: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5513: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5514: );
5515: @toggles = qw(toolsec_crs toolsec_dom);
5516: %defaultchecked = (
5517: 'toolsec_crs' => 'off',
5518: 'toolsec_dom' => 'off',
5519: );
5520: }
5521: my ($onclick,$itemcount);
5522: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5523: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5524: \%choices,$itemcount,$onclick,'','left','no');
5525:
5526: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5527: my $noprivkeysty = 'display:inline-block';
5528: if ($numshown) {
5529: $noprivkeysty = 'display:none';
5530: }
5531: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5532: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5533: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5534: $extra.
5535: '</td></tr>';
5536: $itemcount ++;
5537: $$rowtotal += $itemcount;
5538: return $output;
5539: }
5540:
1.372 raeburn 5541: sub print_proctoring {
5542: my ($dom,$settings,$rowtotal) = @_;
5543: my $itemcount = 1;
5544: my (%ordered,%providernames,%current,%currentdef);
5545: my $confname = $dom.'-domainconfig';
5546: my $switchserver = &check_switchserver($dom,$confname);
5547: if (ref($settings) eq 'HASH') {
5548: foreach my $item (keys(%{$settings})) {
5549: if (ref($settings->{$item}) eq 'HASH') {
5550: my $num = $settings->{$item}{'order'};
5551: $ordered{$num} = $item;
5552: }
5553: }
5554: } else {
5555: %ordered = (
5556: 1 => 'proctorio',
5557: 2 => 'examity',
5558: );
5559: }
5560: %providernames = &proctoring_providernames();
5561: my $maxnum = scalar(keys(%ordered));
5562: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5563: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5564: if (ref($requref) eq 'HASH') {
5565: %requserfields = %{$requref};
5566: }
5567: if (ref($opturef) eq 'HASH') {
5568: %optuserfields = %{$opturef};
5569: }
5570: if (ref($defref) eq 'HASH') {
5571: %defaults = %{$defref};
5572: }
5573: if (ref($extref) eq 'HASH') {
5574: %extended = %{$extref};
5575: }
5576: if (ref($crsref) eq 'HASH') {
5577: %crsconf = %{$crsref};
5578: }
5579: if (ref($rolesref) eq 'ARRAY') {
5580: @courseroles = @{$rolesref};
5581: }
5582: if (ref($ltiref) eq 'ARRAY') {
5583: @ltiroles = @{$ltiref};
5584: }
5585: my $datatable;
5586: my $css_class;
5587: if (keys(%ordered)) {
5588: my @items = sort { $a <=> $b } keys(%ordered);
5589: for (my $i=0; $i<@items; $i++) {
5590: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5591: my $provider = $ordered{$items[$i]};
5592: my $optionsty = 'none';
5593: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5594: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5595: if (ref($settings) eq 'HASH') {
5596: if (ref($settings->{$provider}) eq 'HASH') {
5597: %current = %{$settings->{$provider}};
5598: if ($current{'available'}) {
5599: $optionsty = 'block';
5600: $available = 1;
5601: }
5602: if ($current{'lifetime'} =~ /^\d+$/) {
5603: $lifetime = $current{'lifetime'};
5604: }
5605: if ($current{'version'} =~ /^\d+\.\d+$/) {
5606: $version = $current{'version'};
5607: }
5608: if ($current{'image'} ne '') {
5609: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5610: }
5611: if (ref($current{'fields'}) eq 'ARRAY') {
5612: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5613: }
5614: $userincdom = $current{'incdom'};
5615: if (ref($current{'roles'}) eq 'HASH') {
5616: %rolemaps = %{$current{'roles'}};
5617: $checkedfields{'roles'} = 1;
5618: }
5619: if (ref($current{'defaults'}) eq 'ARRAY') {
5620: foreach my $val (@{$current{'defaults'}}) {
5621: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5622: $inuse{$val} = 1;
5623: } else {
5624: foreach my $poss (keys(%{$extended{$provider}})) {
5625: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5626: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5627: $inuse{$poss} = $val;
5628: last;
5629: }
5630: }
5631: }
5632: }
5633: }
5634: } elsif (ref($current{'defaults'}) eq 'HASH') {
5635: foreach my $key (keys(%{$current{'defaults'}})) {
5636: my $currval = $current{'defaults'}{$key};
5637: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5638: $inuse{$key} = 1;
5639: } else {
5640: my $match;
5641: foreach my $poss (keys(%{$extended{$provider}})) {
5642: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5643: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5644: $inuse{$poss} = $key;
5645: last;
5646: }
5647: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5648: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5649: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5650: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5651: $currentdef{$inner} = $currval;
5652: $match = 1;
5653: last;
5654: }
5655: } elsif ($inner eq $key) {
5656: $currentdef{$key} = $currval;
5657: $match = 1;
5658: last;
5659: }
5660: }
5661: }
5662: last if ($match);
5663: }
5664: }
5665: }
5666: }
5667: if (ref($current{'crsconf'}) eq 'ARRAY') {
5668: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5669: }
5670: }
5671: }
5672: my %lt = &proctoring_titles($provider);
5673: my %fieldtitles = &proctoring_fieldtitles($provider);
5674: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5675: my %checkedavailable = (
5676: yes => '',
5677: no => ' checked="checked"',
5678: );
5679: if ($available) {
5680: $checkedavailable{'yes'} = $checkedavailable{'no'};
5681: $checkedavailable{'no'} = '';
5682: }
5683: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5684: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5685: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5686: for (my $k=0; $k<$maxnum; $k++) {
5687: my $vpos = $k+1;
5688: my $selstr;
5689: if ($k == $i) {
5690: $selstr = ' selected="selected" ';
5691: }
5692: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5693: }
5694: if ($version eq '') {
5695: if ($provider eq 'proctorio') {
5696: $version = '1.0';
5697: } elsif ($provider eq 'examity') {
5698: $version = '1.1';
5699: }
5700: }
5701: if ($lifetime eq '') {
5702: $lifetime = '300';
5703: }
5704: $datatable .=
5705: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5706: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5707: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5708: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5709: '</td>'.
5710: '<td colspan="2">'.
5711: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5712: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5713: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5714: (' 'x2).
5715: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5716: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5717: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5718: (' 'x2).
5719: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5720: '<br />'.
5721: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5722: '<br />'.
5723: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5724: (' 'x2).
5725: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5726: '<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";
5727: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5728: if ($imgsrc) {
5729: $datatable .= $imgsrc.
5730: '<label><input type="checkbox" name="proctoring_image_del"'.
5731: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5732: '<span class="LC_nobreak"> '.&mt('Replace:');
5733: }
5734: $datatable .= ' ';
5735: if ($switchserver) {
5736: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5737: } else {
5738: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5739: }
5740: unless ($imgsrc) {
5741: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5742: }
5743: $datatable .= '</fieldset>'."\n";
5744: if (ref($requserfields{$provider}) eq 'ARRAY') {
5745: if (@{$requserfields{$provider}} > 0) {
5746: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5747: foreach my $field (@{$requserfields{$provider}}) {
5748: $datatable .= '<span class="LC_nobreak">'.
5749: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5750: $lt{$field}.'</label>';
5751: if ($field eq 'user') {
5752: my $seluserdom = '';
5753: my $unseluserdom = ' selected="selected"';
5754: if ($userincdom) {
5755: $seluserdom = $unseluserdom;
5756: $unseluserdom = '';
5757: }
5758: $datatable .= ': '.
5759: '<select name="proctoring_userincdom_'.$provider.'">'.
5760: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5761: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5762: '</select> ';
5763: } else {
5764: $datatable .= ' ';
5765: if ($field eq 'roles') {
5766: $showroles = 1;
5767: }
5768: }
5769: $datatable .= '</span> ';
5770: }
5771: }
5772: $datatable .= '</fieldset>'."\n";
5773: }
5774: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5775: if (@{$optuserfields{$provider}} > 0) {
5776: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5777: foreach my $field (@{$optuserfields{$provider}}) {
5778: my $checked;
5779: if ($checkedfields{$field}) {
5780: $checked = ' checked="checked"';
5781: }
5782: $datatable .= '<span class="LC_nobreak">'.
5783: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5784: }
5785: $datatable .= '</fieldset>'."\n";
5786: }
5787: }
5788: if (ref($defaults{$provider}) eq 'ARRAY') {
5789: if (@{$defaults{$provider}}) {
5790: my (%options,@selectboxes);
5791: if (ref($extended{$provider}) eq 'HASH') {
5792: %options = %{$extended{$provider}};
5793: }
5794: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5795: my ($rem,$numinrow,$dropdowns);
5796: if ($provider eq 'proctorio') {
5797: $datatable .= '<table>';
5798: $numinrow = 4;
5799: }
5800: my $i = 0;
5801: foreach my $field (@{$defaults{$provider}}) {
5802: my $checked;
5803: if ($inuse{$field}) {
5804: $checked = ' checked="checked"';
5805: }
5806: if ($provider eq 'examity') {
5807: if ($field eq 'display') {
5808: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5809: foreach my $option ('iframe','tab','window') {
5810: my $checkdisp;
5811: if ($currentdef{'target'} eq $option) {
5812: $checkdisp = ' checked="checked"';
5813: }
5814: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5815: $fieldtitles{$option}.'</label>'.(' 'x2);
5816: }
5817: $datatable .= (' 'x4);
5818: foreach my $dimen ('width','height') {
5819: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5820: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5821: 'value="'.$currentdef{$dimen}.'" /></label>'.
5822: (' 'x2);
5823: }
5824: $datatable .= '</span><br />'.
5825: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5826: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5827: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5828: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5829: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5830: $currentdef{'explanation'}.
5831: '</textarea></div><div style=""></div><br />';
5832: }
5833: } else {
5834: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5835: my ($output,$selnone);
5836: unless ($checked) {
5837: $selnone = ' selected="selected"';
5838: }
5839: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5840: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5841: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5842: foreach my $option (@{$options{$field}}) {
5843: my $sel;
5844: if ($inuse{$field} eq $option) {
5845: $sel = ' selected="selected"';
5846: }
5847: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5848: }
5849: $output .= '</select></span>';
5850: push(@selectboxes,$output);
5851: } else {
5852: $rem = $i%($numinrow);
5853: if ($rem == 0) {
5854: if ($i > 0) {
5855: $datatable .= '</tr>';
5856: }
5857: $datatable .= '<tr>';
5858: }
5859: $datatable .= '<td class="LC_left_item">'.
5860: '<span class="LC_nobreak">'.
5861: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5862: $fieldtitles{$field}.'</label></span></td>';
5863: $i++;
5864: }
5865: }
5866: }
5867: if ($provider eq 'proctorio') {
5868: if ($numinrow) {
5869: $rem = $i%$numinrow;
5870: }
5871: my $colsleft = $numinrow - $rem;
5872: if ($colsleft > 1) {
5873: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5874: } else {
5875: $datatable .= '<td class="LC_left_item">';
5876: }
5877: $datatable .= ' '.
5878: '</td></tr></table>';
5879: if (@selectboxes) {
5880: $datatable .= '<hr /><table>';
5881: $numinrow = 2;
5882: for (my $i=0; $i<@selectboxes; $i++) {
5883: $rem = $i%($numinrow);
5884: if ($rem == 0) {
5885: if ($i > 0) {
5886: $datatable .= '</tr>';
5887: }
5888: $datatable .= '<tr>';
5889: }
5890: $datatable .= '<td class="LC_left_item">'.
5891: $selectboxes[$i].'</td>';
5892: }
5893: if ($numinrow) {
5894: $rem = $i%$numinrow;
5895: }
5896: $colsleft = $numinrow - $rem;
5897: if ($colsleft > 1) {
5898: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5899: } else {
5900: $datatable .= '<td class="LC_left_item">';
5901: }
5902: $datatable .= ' '.
5903: '</td></tr></table>';
5904: }
5905: }
5906: $datatable .= '</fieldset>';
5907: }
5908: if (ref($crsconf{$provider}) eq 'ARRAY') {
5909: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5910: '<legend>'.&mt('Configurable in course').'</legend>';
5911: my ($rem,$numinrow);
5912: if ($provider eq 'proctorio') {
5913: $datatable .= '<table>';
5914: $numinrow = 4;
5915: }
5916: my $i = 0;
5917: foreach my $item (@{$crsconf{$provider}}) {
5918: my $name;
5919: if ($provider eq 'examity') {
5920: $name = $lt{'crs'.$item};
5921: } elsif ($provider eq 'proctorio') {
5922: $name = $fieldtitles{$item};
5923: $rem = $i%($numinrow);
5924: if ($rem == 0) {
5925: if ($i > 0) {
5926: $datatable .= '</tr>';
5927: }
5928: $datatable .= '<tr>';
5929: }
5930: $datatable .= '<td class="LC_left_item>';
5931: }
5932: my $checked;
5933: if ($crsconfig{$item}) {
5934: $checked = ' checked="checked"';
5935: }
5936: $datatable .= '<span class="LC_nobreak"><label>'.
5937: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5938: $name.'</label></span>';
5939: if ($provider eq 'examity') {
5940: $datatable .= ' ';
5941: }
5942: $datatable .= "\n";
5943: $i++;
5944: }
5945: if ($provider eq 'proctorio') {
5946: if ($numinrow) {
5947: $rem = $i%$numinrow;
5948: }
5949: my $colsleft = $numinrow - $rem;
5950: if ($colsleft > 1) {
5951: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5952: } else {
5953: $datatable .= '<td class="LC_left_item">';
5954: }
5955: $datatable .= ' '.
5956: '</td></tr></table>';
5957: }
5958: $datatable .= '</fieldset>';
5959: }
5960: if ($showroles) {
5961: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5962: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5963: foreach my $role (@courseroles) {
5964: my ($selected,$selectnone);
5965: if (!$rolemaps{$role}) {
5966: $selectnone = ' selected="selected"';
5967: }
5968: $datatable .= '<td style="text-align: center">'.
5969: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5970: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5971: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5972: foreach my $ltirole (@ltiroles) {
5973: unless ($selectnone) {
5974: if ($rolemaps{$role} eq $ltirole) {
5975: $selected = ' selected="selected"';
5976: } else {
5977: $selected = '';
5978: }
5979: }
5980: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5981: }
5982: $datatable .= '</select></td>';
5983: }
5984: $datatable .= '</tr></table></fieldset>'.
5985: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5986: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5987: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5988: '<tr><td></td><td>lms</td>'.
5989: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5990: ' value="Loncapa" disabled="disabled"/></td></tr>';
5991: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5992: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5993: my %custom = %{$settings->{$provider}->{'custom'}};
5994: if (keys(%custom) > 0) {
5995: foreach my $key (sort(keys(%custom))) {
5996: next if ($key eq 'lms');
5997: $datatable .= '<tr><td><span class="LC_nobreak">'.
5998: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5999: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6000: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
6001: ' value="'.$custom{$key}.'" /></td></tr>';
6002: }
6003: }
6004: }
6005: $datatable .= '<tr><td><span class="LC_nobreak">'.
6006: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
6007: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
6008: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
6009: '</table></fieldset></td></tr>'."\n";
6010: }
6011: $datatable .= '</td></tr>';
6012: }
6013: $itemcount ++;
6014: }
6015: }
6016: return $datatable;
6017: }
6018:
6019: sub proctoring_data {
6020: my $requserfields = {
6021: proctorio => ['user'],
6022: examity => ['roles','user'],
6023: };
6024: my $optuserfields = {
6025: proctorio => ['fullname'],
6026: examity => ['fullname','firstname','lastname','email'],
6027: };
6028: my $defaults = {
6029: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6030: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6031: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6032: 'closetabs','onescreen','print','downloads','cache','rightclick',
6033: 'reentry','calculator','whiteboard'],
6034: examity => ['display'],
6035: };
6036: my $extended = {
6037: proctorio => {
6038: verifyid => ['verifyidauto','verifyidlive'],
6039: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6040: tabslinks => ['notabs','linksonly'],
6041: reentry => ['noreentry','agentreentry'],
6042: calculator => ['calculatorbasic','calculatorsci'],
6043: },
6044: examity => {
6045: display => {
6046: target => ['iframe','tab','window'],
6047: width => '',
6048: height => '',
6049: linktext => '',
6050: explanation => '',
6051: },
6052: },
6053: };
6054: my $crsconf = {
6055: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6056: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6057: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6058: 'closetabs','onescreen','print','downloads','cache','rightclick',
6059: 'reentry','calculator','whiteboard'],
6060: examity => ['label','title','target','linktext','explanation','append'],
6061: };
6062: my $courseroles = ['cc','in','ta','ep','st'];
6063: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6064: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6065: }
6066:
6067: sub proctoring_titles {
6068: my ($item) = @_;
6069: my (%common_lt,%custom_lt);
6070: %common_lt = &Apache::lonlocal::texthash (
6071: 'avai' => 'Available?',
6072: 'base' => 'Basic Settings',
6073: 'requ' => 'User data required to be sent on launch',
6074: 'optu' => 'User data optionally sent on launch',
6075: 'udsl' => 'User data sent on launch',
6076: 'defa' => 'Defaults for items configurable in course',
6077: 'sigmethod' => 'Signature Method',
6078: 'key' => 'Key',
6079: 'lifetime' => 'Nonce lifetime (s)',
6080: 'secret' => 'Secret',
6081: 'icon' => 'Icon',
6082: 'fullname' => 'Full Name',
6083: 'visible' => 'Visible input',
6084: 'username' => 'username',
6085: 'user' => 'User',
6086: );
6087: if ($item eq 'proctorio') {
6088: %custom_lt = &Apache::lonlocal::texthash (
6089: 'version' => 'OAuth version',
6090: 'url' => 'API URL',
6091: 'uname:dom' => 'username-domain',
6092: );
6093: } elsif ($item eq 'examity') {
6094: %custom_lt = &Apache::lonlocal::texthash (
6095: 'version' => 'LTI Version',
6096: 'url' => 'URL',
6097: 'uname:dom' => 'username:domain',
6098: 'msgtype' => 'Message Type',
6099: 'firstname' => 'First Name',
6100: 'lastname' => 'Last Name',
6101: 'email' => 'E-mail',
6102: 'roles' => 'Role',
6103: 'crstarget' => 'Display target',
6104: 'crslabel' => 'Course label',
6105: 'crstitle' => 'Course title',
6106: 'crslinktext' => 'Link Text',
6107: 'crsexplanation' => 'Explanation',
6108: 'crsappend' => 'Provider URL',
6109: );
6110: }
6111: my %lt = (%common_lt,%custom_lt);
6112: return %lt;
6113: }
6114:
6115: sub proctoring_fieldtitles {
6116: my ($item) = @_;
6117: if ($item eq 'proctorio') {
6118: return &Apache::lonlocal::texthash (
6119: 'recordvideo' => 'Record video',
6120: 'recordaudio' => 'Record audio',
6121: 'recordscreen' => 'Record screen',
6122: 'recordwebtraffic' => 'Record web traffic',
6123: 'recordroomstart' => 'Record room scan',
6124: 'verifyvideo' => 'Verify webcam',
6125: 'verifyaudio' => 'Verify microphone',
6126: 'verifydesktop' => 'Verify desktop recording',
6127: 'verifyid' => 'Photo ID verification',
6128: 'verifysignature' => 'Require signature',
6129: 'fullscreen' => 'Fullscreen',
6130: 'clipboard' => 'Disable copy/paste',
6131: 'tabslinks' => 'New tabs/windows',
6132: 'closetabs' => 'Close other tabs',
6133: 'onescreen' => 'Limit to single screen',
6134: 'print' => 'Disable Printing',
6135: 'downloads' => 'Disable Downloads',
6136: 'cache' => 'Empty cache after exam',
6137: 'rightclick' => 'Disable right click',
6138: 'reentry' => 'Re-entry to exam',
6139: 'calculator' => 'Onscreen calculator',
6140: 'whiteboard' => 'Onscreen whiteboard',
6141: 'verifyidauto' => 'Automated verification',
6142: 'verifyidlive' => 'Live agent verification',
6143: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6144: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6145: 'fullscreensever' => 'Forced, navigation away ends exam',
6146: 'notabs' => 'Disaallowed',
6147: 'linksonly' => 'Allowed from links in exam',
6148: 'noreentry' => 'Disallowed',
6149: 'agentreentry' => 'Agent required for re-entry',
6150: 'calculatorbasic' => 'Basic',
6151: 'calculatorsci' => 'Scientific',
6152: );
6153: } elsif ($item eq 'examity') {
6154: return &Apache::lonlocal::texthash (
6155: 'target' => 'Display target',
6156: 'window' => 'Window',
6157: 'tab' => 'Tab',
6158: 'iframe' => 'iFrame',
6159: 'height' => 'Height (pixels)',
6160: 'width' => 'Width (pixels)',
6161: 'linktext' => 'Default Link Text',
6162: 'explanation' => 'Default Explanation',
6163: 'append' => 'Provider URL',
6164: );
6165: }
6166: }
6167:
6168: sub proctoring_providernames {
6169: return (
6170: proctorio => 'Proctorio',
6171: examity => 'Examity',
6172: );
6173: }
6174:
1.320 raeburn 6175: sub print_lti {
1.405 raeburn 6176: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6177: my $itemcount = 1;
1.405 raeburn 6178: my ($datatable,$css_class);
6179: my (%rules,%encrypt,%privkeys,%linkprot);
1.320 raeburn 6180: if (ref($settings) eq 'HASH') {
1.405 raeburn 6181: if ($position eq 'top') {
6182: if (exists($settings->{'encrypt'})) {
6183: if (ref($settings->{'encrypt'}) eq 'HASH') {
6184: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6185: if ($key eq 'consumers') {
6186: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6187: } else {
6188: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6189: }
6190: }
6191: }
6192: }
6193: if (exists($settings->{'private'})) {
6194: if (ref($settings->{'private'}) eq 'HASH') {
6195: if (ref($settings->{'private'}) eq 'HASH') {
6196: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6197: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6198: }
6199: }
6200: }
6201: }
6202: } elsif ($position eq 'middle') {
6203: if (exists($settings->{'rules'})) {
6204: if (ref($settings->{'rules'}) eq 'HASH') {
6205: %rules = %{$settings->{'rules'}};
6206: }
6207: }
6208: } elsif ($position eq 'lower') {
6209: if (exists($settings->{'linkprot'})) {
6210: if (ref($settings->{'linkprot'}) eq 'HASH') {
6211: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6212: if ($linkprot{'lock'}) {
6213: delete($linkprot{'lock'});
6214: }
1.405 raeburn 6215: }
6216: }
6217: } else {
6218: foreach my $key ('encrypt','private','rules','linkprot') {
6219: if (exists($settings->{$key})) {
6220: delete($settings->{$key});
1.390 raeburn 6221: }
1.320 raeburn 6222: }
6223: }
6224: }
1.405 raeburn 6225: if ($position eq 'top') {
1.421 raeburn 6226: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
6227: } elsif ($position eq 'middle') {
6228: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
6229: $$rowtotal += $itemcount;
6230: } elsif ($position eq 'lower') {
6231: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
6232: } else {
1.424 raeburn 6233: my ($switchserver,$switchmessage);
6234: $switchserver = &check_switchserver($dom);
6235: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.421 raeburn 6236: my $maxnum = 0;
6237: my %ordered;
6238: if (ref($settings) eq 'HASH') {
6239: foreach my $item (keys(%{$settings})) {
6240: if (ref($settings->{$item}) eq 'HASH') {
6241: my $num = $settings->{$item}{'order'};
6242: if ($num eq '') {
6243: $num = scalar(keys(%{$settings}));
6244: }
6245: $ordered{$num} = $item;
1.405 raeburn 6246: }
1.352 raeburn 6247: }
1.405 raeburn 6248: }
6249: $maxnum = scalar(keys(%ordered));
6250: my %lt = <i_names();
6251: if (keys(%ordered)) {
6252: my @items = sort { $a <=> $b } keys(%ordered);
6253: for (my $i=0; $i<@items; $i++) {
6254: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6255: my $item = $ordered{$items[$i]};
1.424 raeburn 6256: my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
1.405 raeburn 6257: if (ref($settings->{$item}) eq 'HASH') {
6258: $key = $settings->{$item}->{'key'};
1.424 raeburn 6259: $usable = $settings->{$item}->{'usable'};
1.405 raeburn 6260: $lifetime = $settings->{$item}->{'lifetime'};
6261: $consumer = $settings->{$item}->{'consumer'};
6262: $requser = $settings->{$item}->{'requser'};
6263: $crsinc = $settings->{$item}->{'crsinc'};
6264: $current = $settings->{$item};
6265: }
6266: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6267: my %checkedrequser = (
6268: yes => ' checked="checked"',
6269: no => '',
6270: );
6271: if (!$requser) {
6272: $checkedrequser{'no'} = $checkedrequser{'yes'};
6273: $checkedrequser{'yes'} = '';
6274: }
6275: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6276: my %checkedcrsinc = (
1.391 raeburn 6277: yes => ' checked="checked"',
6278: no => '',
1.405 raeburn 6279: );
6280: if (!$crsinc) {
6281: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6282: $checkedcrsinc{'yes'} = '';
6283: }
6284: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6285: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6286: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6287: for (my $k=0; $k<=$maxnum; $k++) {
6288: my $vpos = $k+1;
6289: my $selstr;
6290: if ($k == $i) {
6291: $selstr = ' selected="selected" ';
6292: }
6293: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6294: }
1.405 raeburn 6295: $datatable .= '</select>'.(' 'x2).
6296: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6297: &mt('Delete?').'</label></span></td>'.
6298: '<td colspan="2">'.
6299: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6300: '<span class="LC_nobreak">'.$lt{'consumer'}.
6301: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6302: (' 'x2).
6303: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6304: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6305: (' 'x2).
6306: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.424 raeburn 6307: 'value="'.$lifetime.'" size="3" /></span><br /><br />';
6308: if ($key ne '') {
6309: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6310: if ($switchserver) {
6311: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6312: } else {
6313: $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
6314: }
6315: $datatable .= '</span> '.(' 'x2);
6316: } elsif (!$switchserver) {
6317: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6318: '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
6319: '</span> '.(' 'x2);
6320: }
6321: if ($switchserver) {
6322: if ($usable ne '') {
6323: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6324: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6325: '<span class="LC_nobreak">'.&mt('Change secret?').
6326: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6327: (' 'x2).
6328: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
6329: '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6330: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6331: '</div>';
6332: } elsif ($key eq '') {
6333: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6334: } else {
6335: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6336: }
6337: } else {
6338: if ($usable ne '') {
6339: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6340: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6341: '<span class="LC_nobreak">'.&mt('Change?').
6342: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6343: (' 'x2).
6344: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
6345: '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6346: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6347: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6348: '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label></span></div>';
6349: } else {
6350: $datatable .=
6351: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6352: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6353: '<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>';
6354: }
6355: }
1.425 raeburn 6356: $datatable .= '<br /><br />'.
1.405 raeburn 6357: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6358: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6359: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6360: '<br /><br />'.
6361: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6362: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6363: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6364: (' 'x4).
6365: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6366: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6367: $itemcount ++;
1.320 raeburn 6368: }
6369: }
1.405 raeburn 6370: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6371: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6372: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6373: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6374: '<select name="lti_pos_add"'.$chgstr.'>';
6375: for (my $k=0; $k<$maxnum+1; $k++) {
6376: my $vpos = $k+1;
6377: my $selstr;
6378: if ($k == $maxnum) {
6379: $selstr = ' selected="selected" ';
6380: }
6381: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6382: }
1.405 raeburn 6383: $datatable .= '</select> '."\n".
6384: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6385: '<td colspan="2">'.
6386: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6387: '<span class="LC_nobreak">'.$lt{'consumer'}.
6388: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6389: (' 'x2).
6390: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6391: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6392: (' 'x2).
1.424 raeburn 6393: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
6394: if ($switchserver) {
6395: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6396: } else {
6397: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
6398: (' 'x2).
6399: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
6400: '<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";
6401: }
6402: $datatable .= '<br /><br />'.
1.405 raeburn 6403: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6404: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6405: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6406: '<br /><br />'.
6407: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6408: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6409: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6410: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6411: '</td>'."\n".
6412: '</tr>'."\n";
6413: $itemcount ++;
1.320 raeburn 6414: }
1.405 raeburn 6415: $$rowtotal += $itemcount;
6416: return $datatable;
1.320 raeburn 6417: }
6418:
6419: sub lti_names {
6420: my %lt = &Apache::lonlocal::texthash(
6421: 'version' => 'LTI Version',
6422: 'url' => 'URL',
6423: 'key' => 'Key',
1.322 raeburn 6424: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6425: 'consumer' => 'Consumer',
1.320 raeburn 6426: 'secret' => 'Secret',
1.345 raeburn 6427: 'requser' => "User's identity sent",
1.391 raeburn 6428: 'crsinc' => "Course's identity sent",
1.320 raeburn 6429: 'email' => 'Email address',
6430: 'sourcedid' => 'User ID',
6431: 'other' => 'Other',
6432: 'passback' => 'Can return grades to Consumer:',
6433: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6434: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6435: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6436: );
6437: return %lt;
6438: }
6439:
6440: sub lti_options {
1.325 raeburn 6441: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6442: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6443: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6444: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6445: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6446: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6447: $checked{'mapcrstype'} = {};
6448: $checked{'makeuser'} = {};
6449: $checked{'selfenroll'} = {};
6450: $checked{'crssec'} = {};
6451: $checked{'crssecsrc'} = {};
1.325 raeburn 6452: $checked{'lcauth'} = {};
1.326 raeburn 6453: $checked{'menuitem'} = {};
1.325 raeburn 6454: if ($num eq 'add') {
6455: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6456: }
1.320 raeburn 6457: my $userfieldsty = 'none';
6458: my $crsfieldsty = 'none';
6459: my $crssecfieldsty = 'none';
6460: my $secsrcfieldsty = 'none';
1.363 raeburn 6461: my $callbacksty = 'none';
1.337 raeburn 6462: my $passbacksty = 'none';
1.345 raeburn 6463: my $optionsty = 'block';
1.391 raeburn 6464: my $crssty = 'block';
1.325 raeburn 6465: my $lcauthparm;
6466: my $lcauthparmstyle = 'display:none';
6467: my $lcauthparmtext;
1.326 raeburn 6468: my $menusty;
1.325 raeburn 6469: my $numinrow = 4;
1.326 raeburn 6470: my %menutitles = <imenu_titles();
1.320 raeburn 6471:
6472: if (ref($current) eq 'HASH') {
1.345 raeburn 6473: if (!$current->{'requser'}) {
6474: $optionsty = 'none';
1.391 raeburn 6475: $crssty = 'none';
6476: } elsif (!$current->{'crsinc'}) {
6477: $crssty = 'none';
1.345 raeburn 6478: }
1.320 raeburn 6479: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6480: $checked{'mapuser'}{'sourcedid'} = '';
6481: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
1.425 raeburn 6482: $checked{'mapuser'}{'email'} = ' checked="checked"';
1.320 raeburn 6483: } else {
6484: $checked{'mapuser'}{'other'} = ' checked="checked"';
6485: $userfield = $current->{'mapuser'};
6486: $userfieldsty = 'inline-block';
6487: }
6488: }
6489: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6490: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6491: if ($current->{'mapcrs'} eq 'context_id') {
1.425 raeburn 6492: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
1.320 raeburn 6493: } else {
6494: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6495: $cidfield = $current->{'mapcrs'};
6496: $crsfieldsty = 'inline-block';
6497: }
6498: }
6499: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6500: foreach my $type (@{$current->{'mapcrstype'}}) {
6501: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6502: }
6503: }
1.392 raeburn 6504: if (!$current->{'storecrs'}) {
6505: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6506: $checked{'storecrs'}{'Y'} = '';
6507: }
1.345 raeburn 6508: if ($current->{'makecrs'}) {
1.320 raeburn 6509: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6510: }
1.320 raeburn 6511: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6512: foreach my $role (@{$current->{'makeuser'}}) {
6513: $checked{'makeuser'}{$role} = ' checked="checked"';
6514: }
6515: }
1.325 raeburn 6516: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6517: $checked{'lcauth'}{$1} = ' checked="checked"';
6518: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6519: $lcauthparm = $current->{'lcauthparm'};
1.425 raeburn 6520: $lcauthparmstyle = 'display:table-row';
1.325 raeburn 6521: if ($current->{'lcauth'} eq 'localauth') {
6522: $lcauthparmtext = &mt('Local auth argument');
6523: } else {
6524: $lcauthparmtext = &mt('Kerberos domain');
6525: }
6526: }
6527: }
1.320 raeburn 6528: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6529: foreach my $role (@{$current->{'selfenroll'}}) {
6530: $checked{'selfenroll'}{$role} = ' checked="checked"';
6531: }
6532: }
6533: if (ref($current->{'maproles'}) eq 'HASH') {
6534: %rolemaps = %{$current->{'maproles'}};
6535: }
6536: if ($current->{'section'} ne '') {
1.425 raeburn 6537: $checked{'crssec'}{'Y'} = ' checked="checked"';
1.320 raeburn 6538: $crssecfieldsty = 'inline-block';
6539: if ($current->{'section'} eq 'course_section_sourcedid') {
6540: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6541: } else {
6542: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6543: $crssecsrc = $current->{'section'};
6544: $secsrcfieldsty = 'inline-block';
6545: }
6546: } else {
6547: $checked{'crssec'}{'N'} = ' checked="checked"';
6548: }
1.363 raeburn 6549: if ($current->{'callback'} ne '') {
6550: $callback = $current->{'callback'};
6551: $checked{'callback'}{'Y'} = ' checked="checked"';
6552: $callbacksty = 'inline-block';
6553: } else {
6554: $checked{'callback'}{'N'} = ' checked="checked"';
6555: }
1.326 raeburn 6556: if ($current->{'topmenu'}) {
6557: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6558: } else {
6559: $checked{'topmenu'}{'N'} = ' checked="checked"';
6560: }
6561: if ($current->{'inlinemenu'}) {
6562: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6563: } else {
6564: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6565: }
6566: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6567: $menusty = 'inline-block';
6568: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6569: foreach my $item (@{$current->{'lcmenu'}}) {
6570: if (exists($menutitles{$item})) {
6571: $checked{'menuitem'}{$item} = ' checked="checked"';
6572: }
6573: }
6574: }
6575: } else {
6576: $menusty = 'none';
6577: }
1.320 raeburn 6578: } else {
6579: $checked{'makecrs'}{'N'} = ' checked="checked"';
6580: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6581: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6582: $checked{'topmenu'}{'N'} = ' checked="checked"';
1.425 raeburn 6583: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
1.326 raeburn 6584: $checked{'menuitem'}{'grades'} = ' checked="checked"';
1.425 raeburn 6585: $menusty = 'inline-block';
1.320 raeburn 6586: }
1.325 raeburn 6587: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6588: my %coursetypetitles = &Apache::lonlocal::texthash (
6589: official => 'Official',
6590: unofficial => 'Unofficial',
6591: community => 'Community',
6592: textbook => 'Textbook',
6593: placement => 'Placement Test',
1.325 raeburn 6594: lti => 'LTI Provider',
1.320 raeburn 6595: );
1.325 raeburn 6596: my @authtypes = ('internal','krb4','krb5','localauth');
6597: my %shortauth = (
6598: internal => 'int',
6599: krb4 => 'krb4',
6600: krb5 => 'krb5',
6601: localauth => 'loc'
6602: );
6603: my %authnames = &authtype_names();
1.320 raeburn 6604: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6605: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6606: my @courseroles = ('cc','in','ta','ep','st');
6607: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6608: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6609: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6610: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6611: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6612: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6613: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6614: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6615: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6616: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6617: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6618: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6619: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6620: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6621: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6622: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6623: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6624: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6625: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6626: foreach my $option ('sourcedid','email','other') {
6627: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6628: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6629: ($option eq 'other' ? '' : (' 'x2) );
6630: }
6631: $output .= '</span></div>'.
6632: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6633: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6634: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6635: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6636: foreach my $ltirole (@ltiroles) {
6637: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
1.425 raeburn 6638: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
1.320 raeburn 6639: }
6640: $output .= '</fieldset>'.
1.391 raeburn 6641: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6642: '<table>'.
6643: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6644: '</table>'.
6645: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6646: '<td class="LC_left_item">';
6647: foreach my $auth ('lti',@authtypes) {
6648: my $authtext;
6649: if ($auth eq 'lti') {
6650: $authtext = &mt('None');
6651: } else {
6652: $authtext = $authnames{$shortauth{$auth}};
6653: }
6654: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6655: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6656: $authtext.'</label></span> ';
6657: }
6658: $output .= '</td></tr>'.
6659: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6660: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6661: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6662: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6663: '</table></fieldset>'.
1.391 raeburn 6664: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6665: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6666: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6667: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6668: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6669: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6670: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6671: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6672: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6673: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6674: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6675: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6676: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6677: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6678: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6679: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6680: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6681: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6682: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6683: (' 'x2);
6684: }
6685: $output .= '</span></div></fieldset>'.
6686: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6687: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6688: &mt('Unique course identifier').': ';
6689: foreach my $option ('course_offering_sourcedid','context_id','other') {
6690: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6691: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6692: ($option eq 'other' ? '' : (' 'x2) );
6693: }
1.334 raeburn 6694: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6695: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6696: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6697: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6698: foreach my $type (@coursetypes) {
6699: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6700: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6701: (' 'x2);
6702: }
1.392 raeburn 6703: $output .= '</span><br /><br />'.
6704: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6705: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6706: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6707: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6708: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6709: '</fieldset>'.
1.391 raeburn 6710: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6711: foreach my $ltirole (@lticourseroles) {
6712: my ($selected,$selectnone);
6713: if ($rolemaps{$ltirole} eq '') {
6714: $selectnone = ' selected="selected"';
6715: }
6716: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6717: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6718: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6719: foreach my $role (@courseroles) {
6720: unless ($selectnone) {
6721: if ($rolemaps{$ltirole} eq $role) {
6722: $selected = ' selected="selected"';
6723: } else {
6724: $selected = '';
6725: }
6726: }
6727: $output .= '<option value="'.$role.'"'.$selected.'>'.
6728: &Apache::lonnet::plaintext($role,'Course').
6729: '</option>';
6730: }
6731: $output .= '</select></td>';
6732: }
6733: $output .= '</tr></table></fieldset>'.
6734: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6735: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6736: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6737: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6738: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6739: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6740: '</fieldset>'.
1.391 raeburn 6741: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6742: foreach my $lticrsrole (@lticourseroles) {
6743: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6744: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6745: }
6746: $output .= '</fieldset>'.
1.391 raeburn 6747: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6748: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6749: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6750: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6751: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6752: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6753: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6754: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6755: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6756: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6757: &mt('Standard field').'</label>'.(' 'x2).
6758: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6759: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6760: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6761: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6762: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6763: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6764: foreach my $extra ('roster','passback') {
1.320 raeburn 6765: my $checkedon = '';
6766: my $checkedoff = ' checked="checked"';
1.337 raeburn 6767: if ($extra eq 'passback') {
6768: $pb1p1chk = ' checked="checked"';
6769: $pb1p0chk = '';
1.425 raeburn 6770: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
1.337 raeburn 6771: } else {
1.425 raeburn 6772: $onclickpb = '';
1.337 raeburn 6773: }
1.320 raeburn 6774: if (ref($current) eq 'HASH') {
6775: if (($current->{$extra})) {
6776: $checkedon = $checkedoff;
6777: $checkedoff = '';
1.337 raeburn 6778: if ($extra eq 'passback') {
6779: $passbacksty = 'inline-block';
6780: }
6781: if ($current->{'passbackformat'} eq '1.0') {
6782: $pb1p0chk = ' checked="checked"';
6783: $pb1p1chk = '';
6784: }
1.320 raeburn 6785: }
6786: }
6787: $output .= $lt{$extra}.' '.
1.337 raeburn 6788: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6789: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6790: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6791: &mt('Yes').'</label><br />';
6792: }
1.337 raeburn 6793: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6794: '<span class="LC_nobreak">'.&mt('Grade format').
6795: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6796: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6797: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6798: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6799: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6800: $output .= '</span></div></fieldset>';
1.320 raeburn 6801: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6802: #
6803: # $output .= '</fieldset>'.
6804: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6805: return $output;
6806: }
6807:
1.326 raeburn 6808: sub ltimenu_titles {
6809: return &Apache::lonlocal::texthash(
6810: fullname => 'Full name',
6811: coursetitle => 'Course title',
6812: role => 'Role',
6813: logout => 'Logout',
6814: grades => 'Grades',
6815: );
6816: }
6817:
1.121 raeburn 6818: sub print_coursedefaults {
1.139 raeburn 6819: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6820: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6821: my $itemcount = 1;
1.192 raeburn 6822: my %choices = &Apache::lonlocal::texthash (
6823: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6824: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.428 raeburn 6825: coursequota => 'Default cumulative quota for all group portfolio spaces in course',
1.192 raeburn 6826: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6827: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6828: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6829: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6830: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6831: texengine => 'Default method to display mathematics',
1.257 raeburn 6832: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6833: canclone => "People who may clone a course (besides course's owner and coordinators)",
6834: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6835: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422 raeburn 6836: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6837: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
1.192 raeburn 6838: );
1.198 raeburn 6839: my %staticdefaults = (
6840: anonsurvey_threshold => 10,
6841: uploadquota => 500,
1.428 raeburn 6842: coursequota => 20,
1.257 raeburn 6843: postsubmit => 60,
1.276 raeburn 6844: mysqltables => 172800,
1.422 raeburn 6845: domexttool => 1,
6846: exttool => 0,
1.198 raeburn 6847: );
1.139 raeburn 6848: if ($position eq 'top') {
1.257 raeburn 6849: %defaultchecked = (
6850: 'canuse_pdfforms' => 'off',
6851: 'uselcmath' => 'on',
6852: 'usejsme' => 'on',
1.398 raeburn 6853: 'inline_chem' => 'on',
1.289 raeburn 6854: 'canclone' => 'none',
1.257 raeburn 6855: );
1.398 raeburn 6856: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6857: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6858: if (ref($settings) eq 'HASH') {
6859: if ($settings->{'texengine'}) {
6860: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6861: $deftex = $settings->{'texengine'};
6862: }
6863: }
6864: }
6865: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6866: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6867: '<span class="LC_nobreak">'.$choices{'texengine'}.
6868: '</span></td><td class="LC_right_item">'.
6869: '<select name="texengine">'."\n";
6870: my %texoptions = (
6871: MathJax => 'MathJax',
6872: mimetex => &mt('Convert to Images'),
6873: tth => &mt('TeX to HTML'),
6874: );
6875: foreach my $renderer ('MathJax','mimetex','tth') {
6876: my $selected = '';
6877: if ($renderer eq $deftex) {
6878: $selected = ' selected="selected"';
6879: }
6880: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6881: }
6882: $mathdisp .= '</select></td></tr>'."\n";
6883: $itemcount ++;
1.139 raeburn 6884: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6885: \%choices,$itemcount);
1.314 raeburn 6886: $datatable = $mathdisp.$datatable;
1.264 raeburn 6887: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6888: $datatable .=
1.306 raeburn 6889: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6890: '<span class="LC_nobreak">'.$choices{'canclone'}.
6891: '</span></td><td class="LC_left_item">';
6892: my $currcanclone = 'none';
6893: my $onclick;
6894: my @cloneoptions = ('none','domain');
1.380 raeburn 6895: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6896: none => 'No additional course requesters',
6897: domain => "Any course requester in course's domain",
6898: instcode => 'Course requests for official courses ...',
6899: );
6900: my (%codedefaults,@code_order,@posscodes);
6901: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6902: \@code_order) eq 'ok') {
6903: if (@code_order > 0) {
6904: push(@cloneoptions,'instcode');
6905: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6906: }
6907: }
6908: if (ref($settings) eq 'HASH') {
6909: if ($settings->{'canclone'}) {
6910: if (ref($settings->{'canclone'}) eq 'HASH') {
6911: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6912: if (@code_order > 0) {
6913: $currcanclone = 'instcode';
6914: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6915: }
6916: }
6917: } elsif ($settings->{'canclone'} eq 'domain') {
6918: $currcanclone = $settings->{'canclone'};
6919: }
6920: }
1.289 raeburn 6921: }
1.264 raeburn 6922: foreach my $option (@cloneoptions) {
6923: my ($checked,$additional);
6924: if ($currcanclone eq $option) {
6925: $checked = ' checked="checked"';
6926: }
6927: if ($option eq 'instcode') {
6928: if (@code_order) {
6929: my $show = 'none';
6930: if ($checked) {
6931: $show = 'block';
6932: }
1.317 raeburn 6933: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6934: &mt('Institutional codes for new and cloned course have identical:').
6935: '<br />';
6936: foreach my $item (@code_order) {
6937: my $codechk;
6938: if ($checked) {
6939: if (grep(/^\Q$item\E$/,@posscodes)) {
6940: $codechk = ' checked="checked"';
6941: }
6942: }
6943: $additional .= '<label>'.
6944: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6945: $item.'</label>';
6946: }
6947: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6948: }
6949: }
6950: $datatable .=
6951: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6952: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6953: '</label> '.$additional.'</span><br />';
6954: }
6955: $datatable .= '</td>'.
6956: '</tr>';
6957: $itemcount ++;
1.139 raeburn 6958: } else {
6959: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 6960: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
6961: %deftimeout,%currmysql);
1.192 raeburn 6962: my $currusecredits = 0;
1.257 raeburn 6963: my $postsubmitclient = 1;
1.405 raeburn 6964: my $ltiauth = 0;
1.422 raeburn 6965: my %domexttool;
6966: my %exttool;
1.271 raeburn 6967: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6968: if (ref($settings) eq 'HASH') {
1.404 raeburn 6969: if ($settings->{'ltiauth'}) {
6970: $ltiauth = 1;
1.405 raeburn 6971: }
1.422 raeburn 6972: if (ref($settings->{'domexttool'}) eq 'HASH') {
6973: foreach my $type (@types) {
6974: if ($settings->{'domexttool'}->{$type}) {
6975: $domexttool{$type} = ' checked="checked"';
6976: }
6977: }
6978: } else {
6979: foreach my $type (@types) {
6980: if ($staticdefaults{'domexttool'}) {
6981: $domexttool{$type} = ' checked="checked"';
6982: }
6983: }
6984: }
6985: if (ref($settings->{'exttool'}) eq 'HASH') {
6986: foreach my $type (@types) {
6987: if ($settings->{'exttool'}->{$type}) {
6988: $exttool{$type} = ' checked="checked"';
6989: }
6990: }
6991: }
1.139 raeburn 6992: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 6993: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6994: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6995: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6996: }
6997: }
1.428 raeburn 6998: if (ref($settings->{'coursequota'}) eq 'HASH') {
6999: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7000: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7001: }
7002: }
1.192 raeburn 7003: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7004: foreach my $type (@types) {
7005: next if ($type eq 'community');
7006: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7007: if ($defcredits{$type} ne '') {
7008: $currusecredits = 1;
7009: }
7010: }
7011: }
7012: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7013: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7014: $postsubmitclient = 0;
7015: foreach my $type (@types) {
7016: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7017: }
7018: } else {
7019: foreach my $type (@types) {
7020: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7021: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7022: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7023: } else {
7024: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7025: }
7026: } else {
7027: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7028: }
7029: }
7030: }
7031: } else {
7032: foreach my $type (@types) {
7033: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7034: }
7035: }
1.276 raeburn 7036: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7037: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7038: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7039: }
7040: } else {
7041: foreach my $type (@types) {
7042: $currmysql{$type} = $staticdefaults{'mysqltables'};
7043: }
7044: }
1.258 raeburn 7045: } else {
7046: foreach my $type (@types) {
7047: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7048: if ($staticdefaults{'domexttool'}) {
7049: $domexttool{$type} = ' checked="checked"';
7050: }
1.258 raeburn 7051: }
1.139 raeburn 7052: }
7053: if (!$currdefresponder) {
1.198 raeburn 7054: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7055: } elsif ($currdefresponder < 1) {
7056: $currdefresponder = 1;
7057: }
1.198 raeburn 7058: foreach my $type (@types) {
7059: if ($curruploadquota{$type} eq '') {
7060: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7061: }
1.428 raeburn 7062: if ($currcoursequota{$type} eq '') {
7063: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7064: }
1.198 raeburn 7065: }
1.139 raeburn 7066: $datatable .=
1.192 raeburn 7067: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7068: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7069: '</span></td>'.
7070: '<td class="LC_right_item"><span class="LC_nobreak">'.
7071: '<input type="text" name="anonsurvey_threshold"'.
7072: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7073: '</td></tr>'."\n";
7074: $itemcount ++;
7075: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7076: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7077: $choices{'uploadquota'}.
7078: '</span></td>'.
1.306 raeburn 7079: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7080: '<table><tr>';
1.198 raeburn 7081: foreach my $type (@types) {
1.306 raeburn 7082: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7083: '<input type="text" name="uploadquota_'.$type.'"'.
7084: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7085: }
7086: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7087: $itemcount ++;
1.428 raeburn 7088: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7089: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7090: $choices{'coursequota'}.
7091: '</span></td>'.
7092: '<td style="text-align: right" class="LC_right_item">'.
7093: '<table><tr>';
7094: foreach my $type (@types) {
7095: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7096: '<input type="text" name="coursequota_'.$type.'"'.
7097: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7098: }
7099: $datatable .= '</tr></table></td></tr>'."\n";
7100: $itemcount ++;
1.236 raeburn 7101: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7102: my $display = 'none';
1.192 raeburn 7103: if ($currusecredits) {
7104: $display = 'block';
7105: }
7106: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7107: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7108: foreach my $type (@types) {
7109: next if ($type eq 'community');
1.306 raeburn 7110: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7111: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7112: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7113: }
7114: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7115: %defaultchecked = ('coursecredits' => 'off');
7116: @toggles = ('coursecredits');
7117: my $current = {
7118: 'coursecredits' => $currusecredits,
7119: };
7120: (my $table,$itemcount) =
7121: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7122: \%choices,$itemcount,$onclick,$additional,'left');
7123: $datatable .= $table;
7124: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7125: my $display = 'none';
7126: if ($postsubmitclient) {
7127: $display = 'block';
7128: }
7129: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7130: &mt('Number of seconds submit is disabled').'<br />'.
7131: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7132: '<table><tr>';
1.257 raeburn 7133: foreach my $type (@types) {
1.306 raeburn 7134: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7135: '<input type="text" name="'.$type.'_timeout" value="'.
7136: $deftimeout{$type}.'" size="5" /></td>';
7137: }
7138: $additional .= '</tr></table></div>'."\n";
7139: %defaultchecked = ('postsubmit' => 'on');
7140: @toggles = ('postsubmit');
1.280 raeburn 7141: $current = {
7142: 'postsubmit' => $postsubmitclient,
7143: };
1.257 raeburn 7144: ($table,$itemcount) =
7145: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7146: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7147: $datatable .= $table;
1.276 raeburn 7148: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7149: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7150: $choices{'mysqltables'}.
7151: '</span></td>'.
1.306 raeburn 7152: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7153: '<table><tr>';
7154: foreach my $type (@types) {
1.306 raeburn 7155: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7156: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7157: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7158: }
7159: $datatable .= '</tr></table></td></tr>'."\n";
7160: $itemcount ++;
1.404 raeburn 7161: %defaultchecked = ('ltiauth' => 'off');
7162: @toggles = ('ltiauth');
7163: $current = {
7164: 'ltiauth' => $ltiauth,
7165: };
7166: ($table,$itemcount) =
7167: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7168: \%choices,$itemcount,undef,undef,'left');
7169: $datatable .= $table;
1.422 raeburn 7170: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7171: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7172: $choices{'domexttool'}.
7173: '</span></td>'.
7174: '<td style="text-align: right" class="LC_right_item">'.
7175: '<table><tr>';
7176: foreach my $type (@types) {
7177: $datatable .= '<td style="text-align: left">'.
7178: '<span class="LC_nobreak">'.
7179: '<input type="checkbox" name="domexttool"'.
7180: ' value="'.$type.'"'.$domexttool{$type}.' />'.
7181: &mt($type).'</span></td>'."\n";
7182: }
7183: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7184: $itemcount ++;
1.422 raeburn 7185: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7186: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7187: $choices{'exttool'}.
7188: '</span></td>'.
7189: '<td style="text-align: right" class="LC_right_item">'.
7190: '<table><tr>';
7191: foreach my $type (@types) {
7192: $datatable .= '<td style="text-align: left">'.
7193: '<span class="LC_nobreak">'.
7194: '<input type="checkbox" name="exttool"'.
7195: ' value="'.$type.'"'.$exttool{$type}.' />'.
7196: &mt($type).'</span></td>'."\n";
7197: }
7198: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7199: }
1.192 raeburn 7200: $$rowtotal += $itemcount;
1.121 raeburn 7201: return $datatable;
1.118 jms 7202: }
7203:
1.429 ! raeburn 7204: sub print_authordefaults {
! 7205: my ($position,$dom,$settings,$rowtotal) = @_;
! 7206: my ($css_class,$datatable,%checkedon,%checkedoff);
! 7207: my $itemcount = 1;
! 7208: my %titles = &authordefaults_titles();
! 7209: if ($position eq 'top') {
! 7210: my %defaultchecked = (
! 7211: 'nocodemirror' => 'off',
! 7212: 'domcoordacc' => 'on',
! 7213: );
! 7214: my @toggles = ('nocodemirror','domcoordacc');
! 7215: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
! 7216: \%titles,$itemcount);
! 7217: my %staticdefaults = (
! 7218: 'copyright' => 'default',
! 7219: 'sourceavail' => 'closed',
! 7220: );
! 7221: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 7222: my %currrights;
! 7223: foreach my $item ('copyright','sourceavail') {
! 7224: $currrights{$item} = $staticdefaults{$item};
! 7225: if (ref($settings) eq 'HASH') {
! 7226: if (exists($settings->{$item})) {
! 7227: $currrights{$item} = $settings->{$item};
! 7228: }
! 7229: }
! 7230: }
! 7231: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
! 7232: '<span class="LC_nobreak">'.$titles{'copyright'}.
! 7233: '</span></td><td class="LC_right_item">'.
! 7234: &selectbox('copyright',$currrights{'copyright'},'',
! 7235: \&Apache::loncommon::copyrightdescription,
! 7236: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
! 7237: '</td></tr>'."\n";
! 7238: $itemcount ++;
! 7239: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 7240: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
! 7241: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
! 7242: '</span></td><td class="LC_right_item">'.
! 7243: &selectbox('sourceavail',$currrights{'sourceavail'},'',
! 7244: \&Apache::loncommon::source_copyrightdescription,
! 7245: (&Apache::loncommon::source_copyrightids)).
! 7246: '</td></tr>'."\n";
! 7247: } else {
! 7248: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
! 7249: my $curreditors;
! 7250: my %staticdefaults = (
! 7251: editors => ['edit','xml'],
! 7252: authorquota => 500,
! 7253: webdav => 0,
! 7254: );
! 7255: my $curreditors = $staticdefaults{'editors'};
! 7256: if ((ref($settings) eq 'HASH') &&
! 7257: (ref($settings->{'editors'}) eq 'ARRAY')) {
! 7258: $curreditors = $settings->{'editors'};
! 7259: } else {
! 7260: $curreditors = $staticdefaults{'editors'};
! 7261: }
! 7262: my @editors = ('edit','xml','daxe');
! 7263: $datatable = '<tr'.$css_class.'>'."\n".
! 7264: '<td>'.$titles{'editors'}.'</td>'."\n".
! 7265: '<td class="LC_left_item">'."\n".
! 7266: '<span class="LC_nobreak">';
! 7267: foreach my $editor (@editors) {
! 7268: my $checked;
! 7269: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
! 7270: $checked = ' checked="checked"';
! 7271: }
! 7272: $datatable .= '<label>'.
! 7273: '<input type="checkbox" name="author_editors" '.
! 7274: $checked.' value="'.$editor.'" '.
! 7275: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
! 7276: $titles{$editor}.'</label> ';
! 7277: }
! 7278: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
! 7279: $itemcount ++;
! 7280: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 7281: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 7282: my @insttypes;
! 7283: if (ref($types) eq 'ARRAY') {
! 7284: @insttypes = @{$types};
! 7285: }
! 7286: my $typecount = 0;
! 7287: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
! 7288: my @items = ('webdav','authorquota');
! 7289: my %quotas;
! 7290: if (ref($domconf{'quotas'}) eq 'HASH') {
! 7291: %quotas = %{$domconf{'quotas'}};
! 7292: foreach my $item (@items) {
! 7293: if (ref($quotas{$item}) eq 'HASH') {
! 7294: foreach my $type (@insttypes,'default') {
! 7295: if ($item eq 'authorquota') {
! 7296: if ($quotas{$item}{$type} !~ /^\d+$/) {
! 7297: $quotas{$item}{$type} = $staticdefaults{$item};
! 7298: }
! 7299: } elsif ($item eq 'webdav') {
! 7300: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
! 7301: $quotas{$item}{$type} = $staticdefaults{$item};
! 7302: }
! 7303: }
! 7304: }
! 7305: } else {
! 7306: foreach my $type (@insttypes,'default') {
! 7307: $quotas{$item}{$type} = $staticdefaults{$item};
! 7308: }
! 7309: }
! 7310: }
! 7311: } else {
! 7312: foreach my $item (@items) {
! 7313: foreach my $type (@insttypes,'default') {
! 7314: $quotas{$item}{$type} = $staticdefaults{$item};
! 7315: }
! 7316: }
! 7317: }
! 7318: if (ref($usertypes) eq 'HASH') {
! 7319: my $numinrow = 4;
! 7320: my $onclick = '';
! 7321: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
! 7322: $numinrow,$othertitle,'authorquota',
! 7323: \$itemcount,$onclick);
! 7324: $itemcount ++;
! 7325: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
! 7326: $numinrow,$othertitle,'webdav',
! 7327: \$itemcount);
! 7328: $itemcount ++;
! 7329: }
! 7330: my $checkedno = ' checked="checked"';
! 7331: my ($checkedon,$checkedoff);
! 7332: if (ref($quotas{'webdav'}) eq 'HASH') {
! 7333: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
! 7334: if ($quotas{'webdav'}{'_LC_adv'}) {
! 7335: $checkedon = $checkedno;
! 7336: } else {
! 7337: $checkedoff = $checkedno;
! 7338: }
! 7339: undef($checkedno);
! 7340: }
! 7341: }
! 7342: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 7343: $datatable .= '<tr'.$css_class.'>'.
! 7344: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
! 7345: $titles{'webdav_LC_adv_over'}.
! 7346: '</td>'.
! 7347: '<td class="LC_left_item">';
! 7348: foreach my $option ('none','off','on') {
! 7349: my ($text,$val,$checked);
! 7350: if ($option eq 'none') {
! 7351: $text = $titles{'none'};
! 7352: $val = '';
! 7353: $checked = $checkedno;
! 7354: } elsif ($option eq 'off') {
! 7355: $text = $titles{'overoff'};
! 7356: $val = 0;
! 7357: $checked = $checkedoff;
! 7358: } elsif ($option eq 'on') {
! 7359: $text = $titles{'overon'};
! 7360: $val = 1;
! 7361: $checked = $checkedon;
! 7362: }
! 7363: $datatable .= '<span class="LC_nobreak"><label>'.
! 7364: '<input type="radio" name="webdav_LC_adv"'.
! 7365: ' value="'.$val.'"'.$checked.' />'.
! 7366: $text.'</label></span> ';
! 7367: }
! 7368: $datatable .= '</td></tr>';
! 7369: $itemcount ++;
! 7370: }
! 7371: $$rowtotal += $itemcount;
! 7372: return $datatable;
! 7373: }
! 7374:
! 7375: sub authordefaults_titles {
! 7376: return &Apache::lonlocal::texthash(
! 7377: copyright => 'Copyright/Distribution',
! 7378: sourceavail => ' Source Available',
! 7379: editors => 'Available Editors',
! 7380: webdav => 'WebDAV',
! 7381: authorquota => 'Authoring Space quotas (MB)',
! 7382: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
! 7383: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
! 7384: edit => 'Standard editor (Edit)',
! 7385: xml => 'Text editor (EditXML)',
! 7386: daxe => 'Daxe editor (Daxe)',
! 7387: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
! 7388: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
! 7389: none => 'No override set',
! 7390: overon => 'Override -- webDAV on',
! 7391: overoff => 'Override -- webDAV off',
! 7392: );
! 7393: }
! 7394:
! 7395: sub selectbox {
! 7396: my ($name,$value,$readonly,$functionref,@idlist)=@_;
! 7397: my $selout = '<select name="'.$name.'">';
! 7398: foreach my $id (@idlist) {
! 7399: $selout.='<option value="'.$id.'"';
! 7400: if ($id eq $value) {
! 7401: $selout.=' selected="selected"';
! 7402: }
! 7403: if ($readonly) {
! 7404: $selout .= ' disabled="disabled"';
! 7405: }
! 7406: $selout.='>'.&{$functionref}($id).'</option>';
! 7407: }
! 7408: $selout.='</select>';
! 7409: return $selout;
! 7410: }
! 7411:
1.231 raeburn 7412: sub print_selfenrollment {
7413: my ($position,$dom,$settings,$rowtotal) = @_;
7414: my ($css_class,$datatable);
7415: my $itemcount = 1;
1.271 raeburn 7416: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7417: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7418: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7419: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7420: my @rows;
7421: my $key;
7422: if ($position eq 'top') {
7423: $key = 'admin';
7424: if (ref($rowsref) eq 'ARRAY') {
7425: @rows = @{$rowsref};
7426: }
7427: } elsif ($position eq 'middle') {
7428: $key = 'default';
7429: @rows = ('types','registered','approval','limit');
7430: }
7431: foreach my $row (@rows) {
7432: if (defined($titlesref->{$row})) {
7433: $itemcount ++;
7434: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7435: $datatable .= '<tr'.$css_class.'>'.
7436: '<td>'.$titlesref->{$row}.'</td>'.
7437: '<td class="LC_left_item">'.
7438: '<table><tr>';
7439: my (%current,%currentcap);
7440: if (ref($settings) eq 'HASH') {
7441: if (ref($settings->{$key}) eq 'HASH') {
7442: foreach my $type (@types) {
7443: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7444: $current{$type} = $settings->{$key}->{$type}->{$row};
7445: }
7446: if (($row eq 'limit') && ($key eq 'default')) {
7447: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7448: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7449: }
7450: }
7451: }
7452: }
7453: }
7454: my %roles = (
7455: '0' => &Apache::lonnet::plaintext('dc'),
7456: );
7457:
7458: foreach my $type (@types) {
7459: unless (($row eq 'registered') && ($key eq 'default')) {
7460: $datatable .= '<th>'.&mt($type).'</th>';
7461: }
7462: }
7463: unless (($row eq 'registered') && ($key eq 'default')) {
7464: $datatable .= '</tr><tr>';
7465: }
7466: foreach my $type (@types) {
7467: if ($type eq 'community') {
7468: $roles{'1'} = &mt('Community personnel');
7469: } else {
7470: $roles{'1'} = &mt('Course personnel');
7471: }
7472: $datatable .= '<td style="vertical-align: top">';
7473: if ($position eq 'top') {
7474: my %checked;
7475: if ($current{$type} eq '0') {
7476: $checked{'0'} = ' checked="checked"';
7477: } else {
7478: $checked{'1'} = ' checked="checked"';
7479: }
7480: foreach my $role ('1','0') {
7481: $datatable .= '<span class="LC_nobreak"><label>'.
7482: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7483: 'value="'.$role.'"'.$checked{$role}.' />'.
7484: $roles{$role}.'</label></span> ';
7485: }
7486: } else {
7487: if ($row eq 'types') {
7488: my %checked;
7489: if ($current{$type} =~ /^(all|dom)$/) {
7490: $checked{$1} = ' checked="checked"';
7491: } else {
7492: $checked{''} = ' checked="checked"';
7493: }
7494: foreach my $val ('','dom','all') {
7495: $datatable .= '<span class="LC_nobreak"><label>'.
7496: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7497: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7498: }
7499: } elsif ($row eq 'registered') {
7500: my %checked;
7501: if ($current{$type} eq '1') {
7502: $checked{'1'} = ' checked="checked"';
7503: } else {
7504: $checked{'0'} = ' checked="checked"';
7505: }
7506: foreach my $val ('0','1') {
7507: $datatable .= '<span class="LC_nobreak"><label>'.
7508: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7509: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7510: }
7511: } elsif ($row eq 'approval') {
7512: my %checked;
7513: if ($current{$type} =~ /^([12])$/) {
7514: $checked{$1} = ' checked="checked"';
7515: } else {
7516: $checked{'0'} = ' checked="checked"';
7517: }
7518: for my $val (0..2) {
7519: $datatable .= '<span class="LC_nobreak"><label>'.
7520: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7521: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7522: }
7523: } elsif ($row eq 'limit') {
7524: my %checked;
7525: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7526: $checked{$1} = ' checked="checked"';
7527: } else {
7528: $checked{'none'} = ' checked="checked"';
7529: }
7530: my $cap;
7531: if ($currentcap{$type} =~ /^\d+$/) {
7532: $cap = $currentcap{$type};
7533: }
7534: foreach my $val ('none','allstudents','selfenrolled') {
7535: $datatable .= '<span class="LC_nobreak"><label>'.
7536: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7537: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7538: }
7539: $datatable .= '<br />'.
7540: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7541: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7542: '</span>';
7543: }
7544: }
7545: $datatable .= '</td>';
7546: }
7547: $datatable .= '</tr>';
7548: }
7549: $datatable .= '</table></td></tr>';
7550: }
7551: } elsif ($position eq 'bottom') {
1.235 raeburn 7552: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7553: }
7554: $$rowtotal += $itemcount;
7555: return $datatable;
7556: }
7557:
7558: sub print_validation_rows {
7559: my ($caller,$dom,$settings,$rowtotal) = @_;
7560: my ($itemsref,$namesref,$fieldsref);
7561: if ($caller eq 'selfenroll') {
7562: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7563: } elsif ($caller eq 'requestcourses') {
7564: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7565: }
7566: my %currvalidation;
7567: if (ref($settings) eq 'HASH') {
7568: if (ref($settings->{'validation'}) eq 'HASH') {
7569: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7570: }
1.235 raeburn 7571: }
7572: my $datatable;
7573: my $itemcount = 0;
7574: foreach my $item (@{$itemsref}) {
7575: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7576: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7577: $namesref->{$item}.
7578: '</span></td>'.
7579: '<td class="LC_left_item">';
7580: if (($item eq 'url') || ($item eq 'button')) {
7581: $datatable .= '<span class="LC_nobreak">'.
7582: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7583: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7584: } elsif ($item eq 'fields') {
7585: my @currfields;
7586: if (ref($currvalidation{$item}) eq 'ARRAY') {
7587: @currfields = @{$currvalidation{$item}};
7588: }
7589: foreach my $field (@{$fieldsref}) {
7590: my $check = '';
7591: if (grep(/^\Q$field\E$/,@currfields)) {
7592: $check = ' checked="checked"';
7593: }
7594: $datatable .= '<span class="LC_nobreak"><label>'.
7595: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7596: ' value="'.$field.'"'.$check.' />'.$field.
7597: '</label></span> ';
7598: }
7599: } elsif ($item eq 'markup') {
1.334 raeburn 7600: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7601: $currvalidation{$item}.
1.231 raeburn 7602: '</textarea>';
1.235 raeburn 7603: }
7604: $datatable .= '</td></tr>'."\n";
7605: if (ref($rowtotal)) {
1.231 raeburn 7606: $itemcount ++;
7607: }
7608: }
1.235 raeburn 7609: if ($caller eq 'requestcourses') {
7610: my %currhash;
1.248 raeburn 7611: if (ref($settings) eq 'HASH') {
7612: if (ref($settings->{'validation'}) eq 'HASH') {
7613: if ($settings->{'validation'}{'dc'} ne '') {
7614: $currhash{$settings->{'validation'}{'dc'}} = 1;
7615: }
1.235 raeburn 7616: }
7617: }
7618: my $numinrow = 2;
7619: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7620: 'validationdc',%currhash);
1.247 raeburn 7621: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7622: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7623: if ($numdc > 1) {
1.247 raeburn 7624: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7625: } else {
1.247 raeburn 7626: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7627: }
1.247 raeburn 7628: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7629: $itemcount ++;
7630: }
7631: if (ref($rowtotal)) {
7632: $$rowtotal += $itemcount;
7633: }
1.231 raeburn 7634: return $datatable;
7635: }
7636:
1.357 raeburn 7637: sub print_privacy {
7638: my ($position,$dom,$settings,$rowtotal) = @_;
7639: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7640: my $itemcount = 0;
1.417 raeburn 7641: if ($position eq 'top') {
7642: $numinrow = 2;
7643: } else {
1.357 raeburn 7644: @items = ('domain','author','course','community');
7645: %names = &Apache::lonlocal::texthash (
7646: domain => 'Assigned domain role(s)',
7647: author => 'Assigned co-author role(s)',
7648: course => 'Assigned course role(s)',
1.416 raeburn 7649: community => 'Assigned community role(s)',
1.357 raeburn 7650: );
7651: $numinrow = 4;
7652: ($othertitle,$usertypes,$types) =
7653: &Apache::loncommon::sorted_inst_types($dom);
7654: }
7655: if (($position eq 'top') || ($position eq 'middle')) {
7656: my (%by_ip,%by_location,@intdoms,@instdoms);
7657: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7658: if ($position eq 'top') {
7659: my %curr;
7660: my @options = ('none','user','domain','auto');
7661: my %titles = &Apache::lonlocal::texthash (
7662: none => 'Not allowed',
7663: user => 'User authorizes',
7664: domain => 'DC authorizes',
7665: auto => 'Unrestricted',
7666: instdom => 'Other domain shares institution/provider',
7667: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7668: notify => 'Notify when role needs authorization',
1.357 raeburn 7669: );
7670: my %names = &Apache::lonlocal::texthash (
7671: domain => 'Domain role',
7672: author => 'Co-author role',
7673: course => 'Course role',
7674: community => 'Community role',
7675: );
7676: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7677: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7678: foreach my $domtype ('instdom','extdom') {
7679: my (%checked,$skip);
7680: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7681: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7682: '<td class="LC_left_item">';
7683: if ($domtype eq 'instdom') {
7684: unless (@instdoms > 1) {
7685: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7686: $skip = 1;
7687: }
7688: } elsif ($domtype eq 'extdom') {
7689: if (keys(%by_location) == 0) {
7690: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7691: $skip = 1;
7692: }
7693: }
7694: unless ($skip) {
7695: foreach my $roletype ('domain','author','course','community') {
7696: $checked{'auto'} = ' checked="checked"';
7697: if (ref($settings) eq 'HASH') {
7698: if (ref($settings->{approval}) eq 'HASH') {
7699: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7700: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7701: $checked{$1} = ' checked="checked"';
7702: $checked{'auto'} = '';
7703: }
7704: }
7705: }
7706: }
7707: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7708: foreach my $option (@options) {
7709: $datatable .= '<span class="LC_nobreak"><label>'.
7710: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7711: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7712: '</label></span> ';
7713: }
7714: $datatable .= '</fieldset>';
7715: }
7716: }
7717: $datatable .= '</td></tr>';
7718: $itemcount ++;
7719: }
1.417 raeburn 7720: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7721: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7722: '<td class="LC_left_item">';
7723: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7724: my %curr;
7725: if (ref($settings) eq 'HASH') {
7726: if ($settings->{'notify'} ne '') {
7727: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7728: }
7729: }
7730: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7731: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7732: 'privacy_notify',%curr);
7733: if ($numdc > 0) {
7734: $datatable .= $table;
7735: } else {
7736: $datatable .= &mt('There are no active Domain Coordinators');
7737: }
7738: } else {
7739: $datatable .= &mt('Nothing to set here, as there are no other domains');
7740: }
7741: $datatable .='</td></tr>';
1.357 raeburn 7742: } elsif ($position eq 'middle') {
7743: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7744: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7745: foreach my $item (@{$types}) {
7746: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7747: $numinrow,$itemcount,'','','','','',
7748: '',$usertypes->{$item});
7749: $itemcount ++;
7750: }
7751: }
7752: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7753: $numinrow,$itemcount,'','','','','',
7754: '',$othertitle);
7755: $itemcount ++;
7756: } else {
1.360 raeburn 7757: my (@insttypes,%insttitles);
7758: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7759: @insttypes = @{$types};
7760: %insttitles = %{$usertypes};
7761: }
7762: foreach my $item (@insttypes,'default') {
7763: my $title;
7764: if ($item eq 'default') {
7765: $title = $othertitle;
7766: } else {
7767: $title = $insttitles{$item};
7768: }
7769: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7770: $datatable .= '<tr'.$css_class.'>'.
7771: '<td class="LC_left_item">'.$title.'</td>'.
7772: '<td class="LC_left_item">'.
7773: &mt('Nothing to set here, as there are no other domains').
7774: '</td></tr>';
7775: $itemcount ++;
7776: }
1.357 raeburn 7777: }
7778: }
7779: } else {
7780: my $prefix;
7781: if ($position eq 'lower') {
7782: $prefix = 'priv';
7783: } else {
7784: $prefix = 'unpriv';
7785: }
7786: foreach my $item (@items) {
7787: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7788: $numinrow,$itemcount,'','','','','',
7789: '',$names{$item});
7790: $itemcount ++;
7791: }
7792: }
7793: if (ref($rowtotal)) {
7794: $$rowtotal += $itemcount;
7795: }
7796: return $datatable;
7797: }
7798:
1.354 raeburn 7799: sub print_passwords {
7800: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7801: my ($datatable,$css_class);
7802: my $itemcount = 0;
7803: my %titles = &Apache::lonlocal::texthash (
7804: captcha => '"Forgot Password" CAPTCHA validation',
7805: link => 'Reset link expiration (hours)',
7806: case => 'Case-sensitive usernames/e-mail',
7807: prelink => 'Information required (form 1)',
7808: postlink => 'Information required (form 2)',
7809: emailsrc => 'LON-CAPA e-mail address type(s)',
7810: customtext => 'Domain specific text (HTML)',
7811: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7812: intauth_check => 'Check bcrypt cost if authenticated',
7813: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7814: permanent => 'Permanent e-mail address',
7815: critical => 'Critical notification address',
7816: notify => 'Notification address',
7817: min => 'Minimum password length',
7818: max => 'Maximum password length',
7819: chars => 'Required characters',
7820: expire => 'Password expiration (days)',
1.356 raeburn 7821: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7822: );
7823: if ($position eq 'top') {
7824: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7825: my $shownlinklife = 2;
7826: my $prelink = 'both';
7827: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7828: if (ref($settings) eq 'HASH') {
7829: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7830: $shownlinklife = $settings->{resetlink};
7831: }
7832: if (ref($settings->{resetcase}) eq 'ARRAY') {
7833: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7834: }
7835: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7836: $prelink = $settings->{resetprelink};
7837: }
7838: if (ref($settings->{resetpostlink}) eq 'HASH') {
7839: %postlink = %{$settings->{resetpostlink}};
7840: }
7841: if (ref($settings->{resetemail}) eq 'ARRAY') {
7842: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7843: }
7844: if ($settings->{resetremove}) {
7845: $nostdtext = 1;
7846: }
7847: if ($settings->{resetcustom}) {
7848: $customurl = $settings->{resetcustom};
7849: }
7850: } else {
7851: if (ref($types) eq 'ARRAY') {
7852: foreach my $item (@{$types}) {
7853: $casesens{$item} = 1;
7854: $postlink{$item} = ['username','email'];
7855: }
7856: }
7857: $casesens{'default'} = 1;
7858: $postlink{'default'} = ['username','email'];
7859: $prelink = 'both';
7860: %emailsrc = (
7861: permanent => 1,
7862: critical => 1,
7863: notify => 1,
7864: );
7865: }
7866: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7867: $itemcount ++;
7868: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7869: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7870: '<td class="LC_left_item">'.
7871: '<input type="textbox" value="'.$shownlinklife.'" '.
7872: 'name="passwords_link" size="3" /></td></tr>';
7873: $itemcount ++;
7874: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7875: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7876: '<td class="LC_left_item">';
7877: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7878: foreach my $item (@{$types}) {
7879: my $checkedcase;
7880: if ($casesens{$item}) {
7881: $checkedcase = ' checked="checked"';
7882: }
7883: $datatable .= '<span class="LC_nobreak"><label>'.
7884: '<input type="checkbox" name="passwords_case_sensitive" value="'.
7885: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 7886: '</span> ';
1.354 raeburn 7887: }
7888: }
7889: my $checkedcase;
7890: if ($casesens{'default'}) {
7891: $checkedcase = ' checked="checked"';
7892: }
7893: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7894: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
7895: $othertitle.'</label></span></td>';
7896: $itemcount ++;
7897: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7898: my %checkedpre = (
7899: both => ' checked="checked"',
7900: either => '',
7901: );
7902: if ($prelink eq 'either') {
7903: $checkedpre{either} = ' checked="checked"';
7904: $checkedpre{both} = '';
7905: }
7906: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7907: '<td class="LC_left_item"><span class="LC_nobreak">'.
7908: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7909: &mt('Both username and e-mail address').'</label></span> '.
7910: '<span class="LC_nobreak"><label>'.
7911: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7912: &mt('Either username or e-mail address').'</label></span></td></tr>';
7913: $itemcount ++;
7914: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7915: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7916: '<td class="LC_left_item">';
7917: my %postlinked;
7918: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7919: foreach my $item (@{$types}) {
7920: undef(%postlinked);
7921: $datatable .= '<fieldset style="display: inline-block;">'.
7922: '<legend>'.$usertypes->{$item}.'</legend>';
7923: if (ref($postlink{$item}) eq 'ARRAY') {
7924: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7925: }
7926: foreach my $field ('email','username') {
7927: my $checked;
7928: if ($postlinked{$field}) {
7929: $checked = ' checked="checked"';
7930: }
7931: $datatable .= '<span class="LC_nobreak"><label>'.
7932: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7933: $field.'"'.$checked.' />'.$field.'</label>'.
7934: '<span> ';
7935: }
7936: $datatable .= '</fieldset>';
7937: }
7938: }
7939: if (ref($postlink{'default'}) eq 'ARRAY') {
7940: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7941: }
7942: $datatable .= '<fieldset style="display: inline-block;">'.
7943: '<legend>'.$othertitle.'</legend>';
7944: foreach my $field ('email','username') {
7945: my $checked;
7946: if ($postlinked{$field}) {
7947: $checked = ' checked="checked"';
7948: }
7949: $datatable .= '<span class="LC_nobreak"><label>'.
7950: '<input type="checkbox" name="passwords_postlink_default" value="'.
7951: $field.'"'.$checked.' />'.$field.'</label>'.
7952: '<span> ';
7953: }
7954: $datatable .= '</fieldset></td></tr>';
7955: $itemcount ++;
7956: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7957: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7958: '<td class="LC_left_item">';
7959: foreach my $type ('permanent','critical','notify') {
7960: my $checkedemail;
7961: if ($emailsrc{$type}) {
7962: $checkedemail = ' checked="checked"';
7963: }
7964: $datatable .= '<span class="LC_nobreak"><label>'.
7965: '<input type="checkbox" name="passwords_emailsrc" value="'.
7966: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
7967: '<span> ';
7968: }
7969: $datatable .= '</td></tr>';
7970: $itemcount ++;
7971: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7972: my $switchserver = &check_switchserver($dom,$confname);
7973: my ($showstd,$noshowstd);
7974: if ($nostdtext) {
7975: $noshowstd = ' checked="checked"';
7976: } else {
7977: $showstd = ' checked="checked"';
7978: }
7979: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
7980: '<td class="LC_left_item"><span class="LC_nobreak">'.
7981: &mt('Retain standard text:').
7982: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
7983: &mt('Yes').'</label>'.' '.
7984: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
7985: &mt('No').'</label></span><br />'.
7986: '<span class="LC_fontsize_small">'.
7987: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
7988: &mt('Include custom text:');
7989: if ($customurl) {
1.369 raeburn 7990: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 7991: undef,undef,undef,undef,'background-color:#ffffff');
7992: $datatable .= '<span class="LC_nobreak"> '.$link.
7993: '<label><input type="checkbox" name="passwords_custom_del"'.
7994: ' value="1" />'.&mt('Delete?').'</label></span>'.
7995: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
7996: }
7997: if ($switchserver) {
7998: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
7999: } else {
8000: $datatable .='<span class="LC_nobreak"> '.
8001: '<input type="file" name="passwords_customfile" /></span>';
8002: }
8003: $datatable .= '</td></tr>';
8004: } elsif ($position eq 'middle') {
8005: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8006: my @items = ('intauth_cost','intauth_check','intauth_switch');
8007: my %defaults;
8008: if (ref($domconf{'defaults'}) eq 'HASH') {
8009: %defaults = %{$domconf{'defaults'}};
8010: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8011: $defaults{'intauth_cost'} = 10;
8012: }
8013: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8014: $defaults{'intauth_check'} = 0;
8015: }
8016: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8017: $defaults{'intauth_switch'} = 0;
8018: }
8019: } else {
8020: %defaults = (
8021: 'intauth_cost' => 10,
8022: 'intauth_check' => 0,
8023: 'intauth_switch' => 0,
8024: );
8025: }
8026: foreach my $item (@items) {
8027: if ($itemcount%2) {
8028: $css_class = '';
8029: } else {
8030: $css_class = ' class="LC_odd_row" ';
8031: }
8032: $datatable .= '<tr'.$css_class.'>'.
8033: '<td><span class="LC_nobreak">'.$titles{$item}.
8034: '</span></td><td class="LC_left_item" colspan="3">';
8035: if ($item eq 'intauth_switch') {
8036: my @options = (0,1,2);
8037: my %optiondesc = &Apache::lonlocal::texthash (
8038: 0 => 'No',
8039: 1 => 'Yes',
8040: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8041: );
8042: $datatable .= '<table width="100%">';
8043: foreach my $option (@options) {
8044: my $checked = ' ';
8045: if ($defaults{$item} eq $option) {
8046: $checked = ' checked="checked"';
8047: }
8048: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8049: '<label><input type="radio" name="'.$item.
8050: '" value="'.$option.'"'.$checked.' />'.
8051: $optiondesc{$option}.'</label></span></td></tr>';
8052: }
8053: $datatable .= '</table>';
8054: } elsif ($item eq 'intauth_check') {
8055: my @options = (0,1,2);
8056: my %optiondesc = &Apache::lonlocal::texthash (
8057: 0 => 'No',
8058: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8059: 2 => 'Yes, disallow login if stored cost is less than domain default',
8060: );
8061: $datatable .= '<table width="100%">';
8062: foreach my $option (@options) {
8063: my $checked = ' ';
8064: my $onclick;
8065: if ($defaults{$item} eq $option) {
8066: $checked = ' checked="checked"';
8067: }
8068: if ($option == 2) {
8069: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8070: }
8071: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8072: '<label><input type="radio" name="'.$item.
8073: '" value="'.$option.'"'.$checked.$onclick.' />'.
8074: $optiondesc{$option}.'</label></span></td></tr>';
8075: }
8076: $datatable .= '</table>';
8077: } else {
8078: $datatable .= '<input type="text" name="'.$item.'" value="'.
8079: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8080: }
8081: $datatable .= '</td></tr>';
8082: $itemcount ++;
8083: }
8084: } elsif ($position eq 'lower') {
1.405 raeburn 8085: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8086: } else {
1.359 raeburn 8087: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8088: my %ownerchg = (
8089: by => {},
8090: for => {},
8091: );
8092: my %ownertitles = &Apache::lonlocal::texthash (
8093: by => 'Course owner status(es) allowed',
8094: for => 'Student status(es) allowed',
8095: );
1.354 raeburn 8096: if (ref($settings) eq 'HASH') {
1.359 raeburn 8097: if (ref($settings->{crsownerchg}) eq 'HASH') {
8098: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8099: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8100: }
8101: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8102: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8103: }
1.354 raeburn 8104: }
8105: }
8106: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8107: $datatable .= '<tr '.$css_class.'>'.
8108: '<td>'.
8109: &mt('Requirements').'<ul>'.
1.359 raeburn 8110: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8111: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8112: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8113: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8114: '</ul>'.
8115: '</td>'.
1.359 raeburn 8116: '<td class="LC_left_item">';
8117: foreach my $item ('by','for') {
8118: $datatable .= '<fieldset style="display: inline-block;">'.
8119: '<legend>'.$ownertitles{$item}.'</legend>';
8120: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8121: foreach my $type (@{$types}) {
8122: my $checked;
8123: if ($ownerchg{$item}{$type}) {
8124: $checked = ' checked="checked"';
8125: }
8126: $datatable .= '<span class="LC_nobreak"><label>'.
8127: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8128: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8129: '</span> ';
1.359 raeburn 8130: }
8131: }
8132: my $checked;
8133: if ($ownerchg{$item}{'default'}) {
8134: $checked = ' checked="checked"';
8135: }
8136: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8137: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8138: $othertitle.'</label></span></fieldset>';
8139: }
8140: $datatable .= '</td></tr>';
1.354 raeburn 8141: }
8142: return $datatable;
8143: }
8144:
1.405 raeburn 8145: sub password_rules {
8146: my ($prefix,$itemcountref,$settings) = @_;
8147: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8148: my %titles;
8149: if ($prefix eq 'passwords') {
8150: %titles = &Apache::lonlocal::texthash (
8151: min => 'Minimum password length',
8152: max => 'Maximum password length',
8153: chars => 'Required characters',
8154: );
1.421 raeburn 8155: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8156: %titles = &Apache::lonlocal::texthash (
8157: min => 'Minimum secret length',
8158: max => 'Maximum secret length',
8159: chars => 'Required characters',
8160: );
8161: }
8162: $min = $Apache::lonnet::passwdmin;
8163: my $datatable;
8164: my $itemcount;
8165: if (ref($itemcountref)) {
8166: $itemcount = $$itemcountref;
8167: }
8168: if (ref($settings) eq 'HASH') {
8169: if ($settings->{min}) {
8170: $min = $settings->{min};
8171: }
8172: if ($settings->{max}) {
8173: $max = $settings->{max};
8174: }
8175: if (ref($settings->{chars}) eq 'ARRAY') {
8176: map { $chars{$_} = 1; } (@{$settings->{chars}});
8177: }
1.425 raeburn 8178: if ($prefix eq 'passwords') {
1.405 raeburn 8179: if ($settings->{expire}) {
8180: $expire = $settings->{expire};
8181: }
8182: if ($settings->{numsaved}) {
8183: $numsaved = $settings->{numsaved};
8184: }
8185: }
8186: }
8187: my %rulenames = &Apache::lonlocal::texthash(
8188: uc => 'At least one upper case letter',
8189: lc => 'At least one lower case letter',
8190: num => 'At least one number',
8191: spec => 'At least one non-alphanumeric',
8192: );
8193: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8194: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8195: '<td class="LC_left_item"><span class="LC_nobreak">'.
8196: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8197: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8198: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8199: '</span></td></tr>';
8200: $itemcount ++;
8201: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8202: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8203: '<td class="LC_left_item"><span class="LC_nobreak">'.
8204: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8205: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8206: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8207: '</span></td></tr>';
8208: $itemcount ++;
8209: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8210: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8211: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8212: '</span></td>';
8213: my $numinrow = 2;
8214: my @possrules = ('uc','lc','num','spec');
8215: $datatable .= '<td class="LC_left_item"><table>';
8216: for (my $i=0; $i<@possrules; $i++) {
8217: my ($rem,$checked);
8218: if ($chars{$possrules[$i]}) {
8219: $checked = ' checked="checked"';
8220: }
8221: $rem = $i%($numinrow);
8222: if ($rem == 0) {
8223: if ($i > 0) {
8224: $datatable .= '</tr>';
8225: }
8226: $datatable .= '<tr>';
8227: }
8228: $datatable .= '<td><span class="LC_nobreak"><label>'.
8229: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8230: $rulenames{$possrules[$i]}.'</label></span></td>';
8231: }
8232: my $rem = @possrules%($numinrow);
8233: my $colsleft = $numinrow - $rem;
8234: if ($colsleft > 1 ) {
8235: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8236: ' </td>';
8237: } elsif ($colsleft == 1) {
8238: $datatable .= '<td class="LC_left_item"> </td>';
8239: }
8240: $datatable .='</table></td></tr>';
8241: $itemcount ++;
8242: if ($prefix eq 'passwords') {
8243: $titles{'expire'} = &mt('Password expiration (days)');
8244: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8245: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8246: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8247: '<td class="LC_left_item"><span class="LC_nobreak">'.
8248: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8249: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8250: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8251: '</span></td></tr>';
8252: $itemcount ++;
8253: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8254: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8255: '<td class="LC_left_item"><span class="LC_nobreak">'.
8256: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8257: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8258: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8259: '</span></td></tr>';
8260: $itemcount ++;
8261: }
8262: if (ref($itemcountref)) {
8263: $$itemcountref += $itemcount;
8264: }
8265: return $datatable;
8266: }
8267:
1.373 raeburn 8268: sub print_wafproxy {
8269: my ($position,$dom,$settings,$rowtotal) = @_;
8270: my $css_class;
8271: my $itemcount = 0;
8272: my $datatable;
8273: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8274: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8275: my %lt = &wafproxy_titles();
1.373 raeburn 8276: foreach my $server (sort(keys(%servers))) {
8277: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8278: next if ($serverhome eq '');
1.373 raeburn 8279: my $serverdom;
8280: if ($serverhome ne $server) {
8281: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8282: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8283: $othercontrol{$server} = $serverdom;
8284: }
1.373 raeburn 8285: } else {
8286: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8287: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8288: if ($serverdom ne $dom) {
8289: $othercontrol{$server} = $serverdom;
8290: } else {
8291: $setdom = 1;
8292: if (ref($settings) eq 'HASH') {
8293: if (ref($settings->{'alias'}) eq 'HASH') {
8294: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8295: if ($aliases{$dom} ne '') {
8296: $showdom = 1;
8297: }
1.373 raeburn 8298: }
1.388 raeburn 8299: if (ref($settings->{'saml'}) eq 'HASH') {
8300: $saml{$dom} = $settings->{'saml'};
8301: }
1.373 raeburn 8302: }
8303: }
8304: }
8305: }
1.381 raeburn 8306: if ($setdom) {
8307: %{$values{$dom}} = ();
8308: if (ref($settings) eq 'HASH') {
8309: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8310: $values{$dom}{$item} = $settings->{$item};
8311: }
8312: }
8313: }
1.373 raeburn 8314: if (keys(%othercontrol)) {
8315: %otherdoms = reverse(%othercontrol);
8316: foreach my $domain (keys(%otherdoms)) {
8317: %{$values{$domain}} = ();
8318: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8319: if (ref($config{'wafproxy'}) eq 'HASH') {
8320: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8321: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8322: $saml{$domain} = $config{'wafproxy'}{'saml'};
8323: }
1.383 raeburn 8324: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8325: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8326: }
8327: }
8328: }
8329: }
8330: if ($position eq 'top') {
8331: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8332: my %aliasinfo;
1.373 raeburn 8333: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8334: $itemcount ++;
8335: my $dom_in_effect;
8336: my $aliasrows = '<tr>'.
1.383 raeburn 8337: '<td class="LC_left_item" style="vertical-align: baseline;">'.
8338: &mt('Hostname').': '.
8339: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
1.373 raeburn 8340: if ($othercontrol{$server}) {
1.381 raeburn 8341: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8342: my ($current,$forsaml);
1.383 raeburn 8343: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8344: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8345: }
1.388 raeburn 8346: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8347: if ($saml{$dom_in_effect}{$server}) {
8348: $forsaml = 1;
8349: }
8350: }
1.383 raeburn 8351: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8352: &mt('Alias').': ';
1.373 raeburn 8353: if ($current) {
1.381 raeburn 8354: $aliasrows .= $current;
1.388 raeburn 8355: if ($forsaml) {
1.396 raeburn 8356: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8357: }
1.373 raeburn 8358: } else {
1.383 raeburn 8359: $aliasrows .= &mt('None');
1.373 raeburn 8360: }
1.383 raeburn 8361: $aliasrows .= ' <span class="LC_small">('.
8362: &mt('controlled by domain: [_1]',
8363: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8364: } else {
1.381 raeburn 8365: $dom_in_effect = $dom;
1.388 raeburn 8366: my ($current,$samlon,$samloff);
8367: $samloff = ' checked="checked"';
1.373 raeburn 8368: if (ref($aliases{$dom}) eq 'HASH') {
8369: if ($aliases{$dom}{$server}) {
8370: $current = $aliases{$dom}{$server};
8371: }
8372: }
1.388 raeburn 8373: if (ref($saml{$dom}) eq 'HASH') {
8374: if ($saml{$dom}{$server}) {
8375: $samlon = $samloff;
8376: undef($samloff);
8377: }
8378: }
1.383 raeburn 8379: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8380: &mt('Alias').': '.
1.381 raeburn 8381: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8382: 'value="'.$current.'" size="30" />'.
8383: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8384: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8385: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8386: &mt('No').'</label> <label>'.
1.388 raeburn 8387: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8388: &mt('Yes').'</label></span>'.
1.425 raeburn 8389: '</td>';
1.381 raeburn 8390: }
8391: $aliasrows .= '</tr>';
8392: $aliasinfo{$dom_in_effect} .= $aliasrows;
8393: }
8394: if ($aliasinfo{$dom}) {
8395: my ($onclick,$wafon,$wafoff,$showtable);
8396: $onclick = ' onclick="javascript:toggleWAF();"';
8397: $wafoff = ' checked="checked"';
8398: $showtable = ' style="display:none";';
8399: if ($showdom) {
8400: $wafon = $wafoff;
8401: $wafoff = '';
8402: $showtable = ' style="display:inline;"';
8403: }
8404: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8405: $datatable = '<tr'.$css_class.'>'.
8406: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8407: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8408: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8409: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8410: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8411: &mt('No').'</label></span></td>'.
8412: '<td class="LC_left_item">'.
8413: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8414: '</table></td></tr>';
8415: $itemcount++;
8416: }
1.383 raeburn 8417: if (keys(%otherdoms)) {
8418: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8419: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8420: $datatable .= '<tr'.$css_class.'>'.
8421: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8422: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8423: '</table></td></tr>';
1.381 raeburn 8424: $itemcount++;
1.373 raeburn 8425: }
8426: }
8427: } else {
1.383 raeburn 8428: my %ip_methods = &remoteip_methods();
1.373 raeburn 8429: if ($setdom) {
8430: $itemcount ++;
8431: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8432: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8433: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8434: $wafstyle = ' style="display:none;"';
8435: $nowafstyle = ' style="display:table-row;"';
8436: $currwafdisplay = ' style="display: none"';
8437: $wafrangestyle = ' style="display: none"';
8438: $curr_remotip = 'n';
1.382 raeburn 8439: $ssltossl = ' checked="checked"';
1.381 raeburn 8440: if ($showdom) {
8441: $wafstyle = ' style="display:table-row;"';
8442: $nowafstyle = ' style="display:none;"';
8443: if (keys(%{$values{$dom}})) {
8444: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8445: $curr_remotip = $values{$dom}{remoteip};
8446: }
8447: if ($curr_remotip eq 'h') {
8448: $currwafdisplay = ' style="display:table-row"';
8449: $wafrangestyle = ' style="display:inline-block;"';
8450: }
1.382 raeburn 8451: if ($values{$dom}{'sslopt'}) {
8452: $alltossl = ' checked="checked"';
8453: $ssltossl = '';
8454: }
1.381 raeburn 8455: }
8456: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8457: $vpndircheck = ' checked="checked"';
8458: $currwafvpn = ' style="display:table-row;"';
8459: $wafrangestyle = ' style="display:inline-block;"';
8460: } else {
8461: $vpnaliascheck = ' checked="checked"';
8462: $currwafvpn = ' style="display:none;"';
8463: }
8464: }
8465: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8466: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8467: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8468: '</tr>'.
8469: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8470: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8471: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8472: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8473: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8474: '<td class="LC_left_item"><table>'.
8475: '<tr>'.
8476: '<td valign="top">'.$lt{'remoteip'}.': '.
8477: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8478: foreach my $option ('m','h','n') {
8479: my $sel;
8480: if ($option eq $curr_remotip) {
8481: $sel = ' selected="selected"';
8482: }
8483: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8484: $ip_methods{$option}.'</option>';
8485: }
8486: $datatable .= '</select></td></tr>'."\n".
8487: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8488: $lt{'ipheader'}.': '.
8489: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8490: 'name="wafproxy_ipheader" />'.
8491: '</td></tr>'."\n".
8492: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8493: $lt{'trusted'}.':<br />'.
1.381 raeburn 8494: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8495: $values{$dom}{'trusted'}.'</textarea>'.
8496: '</td></tr>'."\n".
8497: '<tr><td><hr /></td></tr>'."\n".
8498: '<tr>'.
8499: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8500: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8501: $lt{'vpndirect'}.'</label>'.(' 'x2).
8502: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8503: $lt{'vpnaliased'}.'</label></span></td></tr>';
8504: foreach my $item ('vpnint','vpnext') {
8505: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8506: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8507: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8508: $values{$dom}{$item}.'</textarea>'.
8509: '</td></tr>'."\n";
1.373 raeburn 8510: }
1.382 raeburn 8511: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8512: '<tr>'.
8513: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8514: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8515: $lt{'alltossl'}.'</label>'.(' 'x2).
8516: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8517: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8518: '</table></td></tr>';
1.373 raeburn 8519: }
8520: if (keys(%otherdoms)) {
8521: foreach my $domain (sort(keys(%otherdoms))) {
8522: $itemcount ++;
8523: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8524: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8525: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8526: '<td class="LC_left_item"><table>';
1.382 raeburn 8527: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8528: my $showval = &mt('None');
1.382 raeburn 8529: if ($item eq 'ssl') {
8530: $showval = $lt{'ssltossl'};
8531: }
1.373 raeburn 8532: if ($values{$domain}{$item}) {
1.381 raeburn 8533: $showval = $values{$domain}{$item};
1.382 raeburn 8534: if ($item eq 'ssl') {
8535: $showval = $lt{'alltossl'};
1.383 raeburn 8536: } elsif ($item eq 'remoteip') {
8537: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8538: }
1.373 raeburn 8539: }
8540: $datatable .= '<tr>'.
8541: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8542: }
1.381 raeburn 8543: $datatable .= '</table></td></tr>';
1.373 raeburn 8544: }
8545: }
8546: }
8547: $$rowtotal += $itemcount;
8548: return $datatable;
8549: }
8550:
8551: sub wafproxy_titles {
8552: return &Apache::lonlocal::texthash(
1.381 raeburn 8553: remoteip => "Method for determining user's IP",
8554: ipheader => 'Request header containing remote IP',
8555: trusted => 'Trusted IP range(s)',
8556: vpnaccess => 'Access from institutional VPN',
8557: vpndirect => 'via regular hostname (no WAF)',
8558: vpnaliased => 'via aliased hostname (WAF)',
8559: vpnint => 'Internal IP Range(s) for VPN sessions',
8560: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8561: sslopt => 'Forwarding http/https',
1.381 raeburn 8562: alltossl => 'WAF forwards both http and https requests to https',
8563: ssltossl => 'WAF forwards http requests to http and https to https',
8564: );
8565: }
8566:
8567: sub remoteip_methods {
8568: return &Apache::lonlocal::texthash(
8569: m => 'Use Apache mod_remoteip',
8570: h => 'Use headers parsed by LON-CAPA',
8571: n => 'Not in use',
1.373 raeburn 8572: );
8573: }
8574:
1.137 raeburn 8575: sub print_usersessions {
8576: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8577: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8578: my (%by_ip,%by_location,@intdoms,@instdoms);
8579: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8580:
8581: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8582: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8583: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8584: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8585: if ($position eq 'top') {
1.152 raeburn 8586: if (keys(%serverhomes) > 1) {
1.145 raeburn 8587: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8588: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8589: if (ref($settings) eq 'HASH') {
8590: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8591: $curroffloadnow = $settings->{'offloadnow'};
8592: }
1.371 raeburn 8593: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8594: $curroffloadoth = $settings->{'offloadoth'};
8595: }
1.261 raeburn 8596: }
1.371 raeburn 8597: my $other_insts = scalar(keys(%by_location));
8598: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8599: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8600: } else {
1.140 raeburn 8601: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8602: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8603: '</td></tr>';
1.140 raeburn 8604: }
1.137 raeburn 8605: } else {
1.279 raeburn 8606: my %titles = &usersession_titles();
8607: my ($prefix,@types);
8608: if ($position eq 'bottom') {
8609: $prefix = 'remote';
8610: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8611: } else {
1.279 raeburn 8612: $prefix = 'hosted';
8613: @types = ('excludedomain','includedomain');
8614: }
8615: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8616: }
8617: $$rowtotal += $itemcount;
8618: return $datatable;
8619: }
8620:
8621: sub rules_by_location {
8622: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8623: my ($datatable,$itemcount,$css_class);
8624: if (keys(%{$by_location}) == 0) {
8625: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8626: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8627: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8628: '</td></tr>';
8629: $itemcount = 1;
8630: } else {
8631: $itemcount = 0;
8632: my $numinrow = 5;
8633: my (%current,%checkedon,%checkedoff);
8634: my @locations = sort(keys(%{$by_location}));
8635: foreach my $type (@{$types}) {
8636: $checkedon{$type} = '';
8637: $checkedoff{$type} = ' checked="checked"';
8638: }
8639: if (ref($settings) eq 'HASH') {
8640: if (ref($settings->{$prefix}) eq 'HASH') {
8641: foreach my $key (keys(%{$settings->{$prefix}})) {
8642: $current{$key} = $settings->{$prefix}{$key};
8643: if ($key eq 'version') {
8644: if ($current{$key} ne '') {
1.145 raeburn 8645: $checkedon{$key} = ' checked="checked"';
8646: $checkedoff{$key} = '';
8647: }
1.279 raeburn 8648: } elsif (ref($current{$key}) eq 'ARRAY') {
8649: $checkedon{$key} = ' checked="checked"';
8650: $checkedoff{$key} = '';
1.137 raeburn 8651: }
8652: }
8653: }
1.279 raeburn 8654: }
8655: foreach my $type (@{$types}) {
8656: next if ($type ne 'version' && !@locations);
8657: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8658: $datatable .= '<tr'.$css_class.'>
8659: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8660: <span class="LC_nobreak">
8661: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8662: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8663: if ($type eq 'version') {
8664: my @lcversions = &Apache::lonnet::all_loncaparevs();
8665: my $selector = '<select name="'.$prefix.'_version">';
8666: foreach my $version (@lcversions) {
8667: my $selected = '';
8668: if ($current{'version'} eq $version) {
8669: $selected = ' selected="selected"';
1.145 raeburn 8670: }
1.279 raeburn 8671: $selector .= ' <option value="'.$version.'"'.
8672: $selected.'>'.$version.'</option>';
8673: }
8674: $selector .= '</select> ';
8675: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8676: } else {
8677: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8678: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8679: ' />'.(' 'x2).
8680: '<input type="button" value="'.&mt('uncheck all').'" '.
8681: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8682: "\n".
8683: '</div><div><table>';
8684: my $rem;
8685: for (my $i=0; $i<@locations; $i++) {
8686: my ($showloc,$value,$checkedtype);
8687: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8688: my $ip = $by_location->{$locations[$i]}->[0];
8689: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8690: $value = join(':',@{$by_ip->{$ip}});
8691: $showloc = join(', ',@{$by_ip->{$ip}});
8692: if (ref($current{$type}) eq 'ARRAY') {
8693: foreach my $loc (@{$by_ip->{$ip}}) {
8694: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8695: $checkedtype = ' checked="checked"';
8696: last;
1.145 raeburn 8697: }
1.138 raeburn 8698: }
8699: }
8700: }
1.137 raeburn 8701: }
1.279 raeburn 8702: $rem = $i%($numinrow);
8703: if ($rem == 0) {
8704: if ($i > 0) {
8705: $datatable .= '</tr>';
8706: }
8707: $datatable .= '<tr>';
8708: }
8709: $datatable .= '<td class="LC_left_item">'.
8710: '<span class="LC_nobreak"><label>'.
8711: '<input type="checkbox" name="'.$prefix.'_'.$type.
8712: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8713: '</label></span></td>';
8714: }
8715: $rem = @locations%($numinrow);
8716: my $colsleft = $numinrow - $rem;
8717: if ($colsleft > 1 ) {
8718: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8719: ' </td>';
8720: } elsif ($colsleft == 1) {
8721: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8722: }
1.279 raeburn 8723: $datatable .= '</tr></table>';
1.137 raeburn 8724: }
1.279 raeburn 8725: $datatable .= '</td></tr>';
8726: $itemcount ++;
1.137 raeburn 8727: }
8728: }
1.279 raeburn 8729: return ($datatable,$itemcount);
1.137 raeburn 8730: }
8731:
1.275 raeburn 8732: sub print_ssl {
8733: my ($position,$dom,$settings,$rowtotal) = @_;
8734: my ($css_class,$datatable);
8735: my $itemcount = 1;
8736: if ($position eq 'top') {
1.281 raeburn 8737: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8738: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8739: my $same_institution;
8740: if ($intdom ne '') {
8741: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8742: if (ref($internet_names) eq 'ARRAY') {
8743: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8744: $same_institution = 1;
8745: }
8746: }
8747: }
1.275 raeburn 8748: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8749: $datatable = '<tr'.$css_class.'><td colspan="2">';
8750: if ($same_institution) {
8751: my %domservers = &Apache::lonnet::get_servers($dom);
8752: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8753: } else {
8754: $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.");
8755: }
8756: $datatable .= '</td></tr>';
1.275 raeburn 8757: $itemcount ++;
8758: } else {
8759: my %titles = &ssl_titles();
8760: my (%by_ip,%by_location,@intdoms,@instdoms);
8761: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8762: my @alldoms = &Apache::lonnet::all_domains();
8763: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8764: my @domservers = &Apache::lonnet::get_servers($dom);
8765: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8766: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8767: if (($position eq 'connto') || ($position eq 'connfrom')) {
8768: my $legacy;
8769: unless (ref($settings) eq 'HASH') {
8770: my $name;
8771: if ($position eq 'connto') {
8772: $name = 'loncAllowInsecure';
8773: } else {
8774: $name = 'londAllowInsecure';
8775: }
8776: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8777: my @ids=&Apache::lonnet::current_machine_ids();
8778: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8779: my %what = (
8780: $name => 1,
8781: );
8782: my ($result,$returnhash) =
8783: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8784: if ($result eq 'ok') {
8785: if (ref($returnhash) eq 'HASH') {
8786: $legacy = $returnhash->{$name};
8787: }
8788: }
8789: } else {
8790: $legacy = $Apache::lonnet::perlvar{$name};
8791: }
8792: }
1.275 raeburn 8793: foreach my $type ('dom','intdom','other') {
8794: my %checked;
8795: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8796: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8797: '<td class="LC_right_item">';
8798: my $skip;
8799: if ($type eq 'dom') {
8800: unless (keys(%servers) > 1) {
8801: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8802: $skip = 1;
8803: }
8804: }
8805: if ($type eq 'intdom') {
8806: unless (@instdoms > 1) {
8807: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8808: $skip = 1;
8809: }
8810: } elsif ($type eq 'other') {
8811: if (keys(%by_location) == 0) {
8812: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8813: $skip = 1;
8814: }
8815: }
8816: unless ($skip) {
8817: $checked{'yes'} = ' checked="checked"';
8818: if (ref($settings) eq 'HASH') {
1.293 raeburn 8819: if (ref($settings->{$position}) eq 'HASH') {
8820: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8821: $checked{$1} = $checked{'yes'};
8822: delete($checked{'yes'});
8823: }
8824: }
1.293 raeburn 8825: } else {
8826: if ($legacy == 0) {
8827: $checked{'req'} = $checked{'yes'};
8828: delete($checked{'yes'});
8829: }
1.275 raeburn 8830: }
8831: foreach my $option ('no','yes','req') {
8832: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8833: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8834: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8835: '</label></span>'.(' 'x2);
8836: }
8837: }
8838: $datatable .= '</td></tr>';
8839: $itemcount ++;
8840: }
8841: } else {
8842: my $prefix = 'replication';
8843: my @types = ('certreq','nocertreq');
1.279 raeburn 8844: if (keys(%by_location) == 0) {
8845: $datatable .= '<tr'.$css_class.'><td>'.
8846: &mt('Nothing to set here, as there are no other institutions').
8847: '</td></tr>';
8848: $itemcount ++;
1.275 raeburn 8849: } else {
1.279 raeburn 8850: ($datatable,$itemcount) =
8851: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8852: }
8853: }
8854: }
8855: $$rowtotal += $itemcount;
8856: return $datatable;
8857: }
8858:
8859: sub ssl_titles {
8860: return &Apache::lonlocal::texthash (
8861: dom => 'LON-CAPA servers/VMs from same domain',
8862: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8863: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8864: connto => 'Connections to other servers',
8865: connfrom => 'Connections from other servers',
1.275 raeburn 8866: replication => 'Replicating content to other institutions',
8867: certreq => 'Client certificate required, but specific domains exempt',
8868: nocertreq => 'No client certificate required, except for specific domains',
8869: no => 'SSL not used',
8870: yes => 'SSL Optional (used if available)',
8871: req => 'SSL Required',
8872: );
1.279 raeburn 8873: }
8874:
8875: sub print_trust {
8876: my ($prefix,$dom,$settings,$rowtotal) = @_;
8877: my ($css_class,$datatable,%checked,%choices);
8878: my (%by_ip,%by_location,@intdoms,@instdoms);
8879: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8880: my $itemcount = 1;
8881: my %titles = &trust_titles();
8882: my @types = ('exc','inc');
8883: if ($prefix eq 'top') {
8884: $prefix = 'content';
8885: } elsif ($prefix eq 'bottom') {
8886: $prefix = 'msg';
8887: }
8888: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8889: $$rowtotal += $itemcount;
8890: return $datatable;
8891: }
8892:
8893: sub trust_titles {
8894: return &Apache::lonlocal::texthash(
8895: content => "Access to this domain's content by others",
8896: shared => "Access to other domain's content by this domain",
8897: enroll => "Enrollment in this domain's courses by others",
8898: othcoau => "Co-author roles in this domain for others",
8899: coaurem => "Co-author roles for this domain's users elsewhere",
8900: domroles => "Domain roles in this domain assignable to others",
8901: catalog => "Course Catalog for this domain displayed elsewhere",
8902: reqcrs => "Requests for creation of courses in this domain by others",
8903: msg => "Users in other domains can send messages to this domain",
8904: exc => "Allow all, but exclude specific domains",
8905: inc => "Deny all, but include specific domains",
8906: );
1.275 raeburn 8907: }
8908:
1.138 raeburn 8909: sub build_location_hashes {
1.275 raeburn 8910: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 8911: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 8912: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 8913: my %iphost = &Apache::lonnet::get_iphost();
8914: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
8915: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
8916: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
8917: foreach my $id (@{$iphost{$primary_ip}}) {
8918: my $intdom = &Apache::lonnet::internet_dom($id);
8919: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
8920: push(@{$intdoms},$intdom);
8921: }
8922: }
8923: }
8924: foreach my $ip (keys(%iphost)) {
8925: if (ref($iphost{$ip}) eq 'ARRAY') {
8926: foreach my $id (@{$iphost{$ip}}) {
8927: my $location = &Apache::lonnet::internet_dom($id);
8928: if ($location) {
1.275 raeburn 8929: if (grep(/^\Q$location\E$/,@{$intdoms})) {
8930: my $dom = &Apache::lonnet::host_domain($id);
8931: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
8932: push(@{$instdoms},$dom);
8933: }
8934: next;
8935: }
1.138 raeburn 8936: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8937: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
8938: push(@{$by_ip->{$ip}},$location);
8939: }
8940: } else {
8941: $by_ip->{$ip} = [$location];
8942: }
8943: }
8944: }
8945: }
8946: }
8947: foreach my $ip (sort(keys(%{$by_ip}))) {
8948: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8949: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
8950: my $first = $by_ip->{$ip}->[0];
8951: if (ref($by_location->{$first}) eq 'ARRAY') {
8952: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
8953: push(@{$by_location->{$first}},$ip);
8954: }
8955: } else {
8956: $by_location->{$first} = [$ip];
8957: }
8958: }
8959: }
8960: return;
8961: }
8962:
1.145 raeburn 8963: sub current_offloads_to {
8964: my ($dom,$settings,$servers) = @_;
8965: my (%spareid,%otherdomconfigs);
1.152 raeburn 8966: if (ref($servers) eq 'HASH') {
1.145 raeburn 8967: foreach my $lonhost (sort(keys(%{$servers}))) {
8968: my $gotspares;
1.152 raeburn 8969: if (ref($settings) eq 'HASH') {
8970: if (ref($settings->{'spares'}) eq 'HASH') {
8971: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
8972: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
8973: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
8974: $gotspares = 1;
8975: }
1.145 raeburn 8976: }
8977: }
8978: unless ($gotspares) {
8979: my $gotspares;
8980: my $serverhomeID =
8981: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
8982: my $serverhomedom =
8983: &Apache::lonnet::host_domain($serverhomeID);
8984: if ($serverhomedom ne $dom) {
8985: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
8986: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8987: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8988: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8989: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8990: $gotspares = 1;
8991: }
8992: }
8993: } else {
8994: $otherdomconfigs{$serverhomedom} =
8995: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
8996: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
8997: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8998: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8999: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9000: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9001: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9002: $gotspares = 1;
9003: }
9004: }
9005: }
9006: }
9007: }
9008: }
9009: }
9010: unless ($gotspares) {
9011: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9012: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9013: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9014: } else {
9015: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9016: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9017: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9018: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9019: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9020: } else {
1.150 raeburn 9021: my %what = (
9022: spareid => 1,
9023: );
9024: my ($result,$returnhash) =
9025: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9026: if ($result eq 'ok') {
9027: if (ref($returnhash) eq 'HASH') {
9028: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9029: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9030: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9031: }
9032: }
1.145 raeburn 9033: }
9034: }
9035: }
9036: }
9037: }
9038: }
9039: return %spareid;
9040: }
9041:
9042: sub spares_row {
1.371 raeburn 9043: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9044: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9045: my $css_class;
9046: my $numinrow = 4;
9047: my $itemcount = 1;
9048: my $datatable;
1.152 raeburn 9049: my %typetitles = &sparestype_titles();
9050: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9051: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9052: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9053: my ($othercontrol,$serverdom);
9054: if ($serverhome ne $server) {
9055: $serverdom = &Apache::lonnet::host_domain($serverhome);
9056: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9057: } else {
9058: $serverdom = &Apache::lonnet::host_domain($server);
9059: if ($serverdom ne $dom) {
9060: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9061: }
9062: }
9063: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9064: my ($checkednow,$checkedoth);
1.261 raeburn 9065: if (ref($curroffloadnow) eq 'HASH') {
9066: if ($curroffloadnow->{$server}) {
9067: $checkednow = ' checked="checked"';
9068: }
9069: }
1.371 raeburn 9070: if (ref($curroffloadoth) eq 'HASH') {
9071: if ($curroffloadoth->{$server}) {
9072: $checkedoth = ' checked="checked"';
9073: }
9074: }
1.145 raeburn 9075: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9076: $datatable .= '<tr'.$css_class.'>
9077: <td rowspan="2">
1.183 bisitz 9078: <span class="LC_nobreak">'.
9079: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9080: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9081: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9082: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9083: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9084: "\n";
1.371 raeburn 9085: if ($other_insts) {
9086: $datatable .= '<br />'.
9087: '<span class="LC_nobreak">'."\n".
9088: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9089: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9090: "\n";
9091: }
1.145 raeburn 9092: my (%current,%canselect);
1.152 raeburn 9093: my @choices =
9094: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9095: foreach my $type ('primary','default') {
9096: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9097: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9098: my @spares = @{$spareid->{$server}{$type}};
9099: if (@spares > 0) {
1.152 raeburn 9100: if ($othercontrol) {
9101: $current{$type} = join(', ',@spares);
9102: } else {
9103: $current{$type} .= '<table>';
9104: my $numspares = scalar(@spares);
9105: for (my $i=0; $i<@spares; $i++) {
9106: my $rem = $i%($numinrow);
9107: if ($rem == 0) {
9108: if ($i > 0) {
9109: $current{$type} .= '</tr>';
9110: }
9111: $current{$type} .= '<tr>';
1.145 raeburn 9112: }
1.152 raeburn 9113: $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'".');" /> '.
9114: $spareid->{$server}{$type}[$i].
9115: '</label></td>'."\n";
9116: }
9117: my $rem = @spares%($numinrow);
9118: my $colsleft = $numinrow - $rem;
9119: if ($colsleft > 1 ) {
9120: $current{$type} .= '<td colspan="'.$colsleft.
9121: '" class="LC_left_item">'.
9122: ' </td>';
9123: } elsif ($colsleft == 1) {
9124: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9125: }
1.152 raeburn 9126: $current{$type} .= '</tr></table>';
1.150 raeburn 9127: }
1.145 raeburn 9128: }
9129: }
9130: if ($current{$type} eq '') {
9131: $current{$type} = &mt('None specified');
9132: }
1.152 raeburn 9133: if ($othercontrol) {
9134: if ($type eq 'primary') {
9135: $canselect{$type} = $othercontrol;
9136: }
9137: } else {
9138: $canselect{$type} =
9139: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9140: '<select name="newspare_'.$type.'_'.$server.'" '.
9141: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9142: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9143: if (@choices > 0) {
9144: foreach my $lonhost (@choices) {
9145: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9146: }
9147: }
9148: $canselect{$type} .= '</select>'."\n";
9149: }
9150: } else {
9151: $current{$type} = &mt('Could not be determined');
9152: if ($type eq 'primary') {
9153: $canselect{$type} = $othercontrol;
9154: }
1.145 raeburn 9155: }
1.152 raeburn 9156: if ($type eq 'default') {
9157: $datatable .= '<tr'.$css_class.'>';
9158: }
9159: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9160: '<td>'.$current{$type}.'</td>'."\n".
9161: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9162: }
9163: $itemcount ++;
9164: }
9165: }
9166: $$rowtotal += $itemcount;
9167: return $datatable;
9168: }
9169:
1.152 raeburn 9170: sub possible_newspares {
9171: my ($server,$currspares,$serverhomes,$altids) = @_;
9172: my $serverhostname = &Apache::lonnet::hostname($server);
9173: my %excluded;
9174: if ($serverhostname ne '') {
9175: %excluded = (
9176: $serverhostname => 1,
9177: );
9178: }
9179: if (ref($currspares) eq 'HASH') {
9180: foreach my $type (keys(%{$currspares})) {
9181: if (ref($currspares->{$type}) eq 'ARRAY') {
9182: if (@{$currspares->{$type}} > 0) {
9183: foreach my $curr (@{$currspares->{$type}}) {
9184: my $hostname = &Apache::lonnet::hostname($curr);
9185: $excluded{$hostname} = 1;
9186: }
9187: }
9188: }
9189: }
9190: }
9191: my @choices;
9192: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9193: if (keys(%{$serverhomes}) > 1) {
9194: foreach my $name (sort(keys(%{$serverhomes}))) {
9195: unless ($excluded{$name}) {
9196: if (exists($altids->{$serverhomes->{$name}})) {
9197: push(@choices,$altids->{$serverhomes->{$name}});
9198: } else {
9199: push(@choices,$serverhomes->{$name});
1.145 raeburn 9200: }
9201: }
9202: }
9203: }
9204: }
1.152 raeburn 9205: return sort(@choices);
1.145 raeburn 9206: }
9207:
1.150 raeburn 9208: sub print_loadbalancing {
9209: my ($dom,$settings,$rowtotal) = @_;
9210: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9211: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9212: my $numinrow = 1;
9213: my $datatable;
9214: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9215: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9216: if (ref($settings) eq 'HASH') {
9217: %existing = %{$settings};
9218: }
9219: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9220: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9221: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9222: } else {
9223: return;
9224: }
9225: my ($othertitle,$usertypes,$types) =
9226: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9227: my $rownum = 8;
1.150 raeburn 9228: if (ref($types) eq 'ARRAY') {
9229: $rownum += scalar(@{$types});
9230: }
1.171 raeburn 9231: my @css_class = ('LC_odd_row','LC_even_row');
9232: my $balnum = 0;
9233: my $islast;
9234: my (@toshow,$disabledtext);
9235: if (keys(%currbalancer) > 0) {
9236: @toshow = sort(keys(%currbalancer));
9237: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9238: push(@toshow,'');
9239: }
9240: } else {
9241: @toshow = ('');
9242: $disabledtext = &mt('No existing load balancer');
9243: }
9244: foreach my $lonhost (@toshow) {
9245: if ($balnum == scalar(@toshow)-1) {
9246: $islast = 1;
9247: } else {
9248: $islast = 0;
9249: }
9250: my $cssidx = $balnum%2;
9251: my $targets_div_style = 'display: none';
9252: my $disabled_div_style = 'display: block';
9253: my $homedom_div_style = 'display: none';
9254: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9255: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9256: '<p>';
9257: if ($lonhost eq '') {
1.210 raeburn 9258: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9259: if (keys(%currbalancer) > 0) {
9260: $datatable .= &mt('Add balancer:');
9261: } else {
9262: $datatable .= &mt('Enable balancer:');
9263: }
9264: $datatable .= ' '.
9265: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9266: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9267: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9268: '<option value="" selected="selected">'.&mt('None').
9269: '</option>'."\n";
9270: foreach my $server (sort(keys(%servers))) {
9271: next if ($currbalancer{$server});
9272: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9273: }
1.210 raeburn 9274: $datatable .=
1.171 raeburn 9275: '</select>'."\n".
9276: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9277: } else {
9278: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9279: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9280: &mt('Stop balancing').'</label>'.
9281: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9282: $targets_div_style = 'display: block';
9283: $disabled_div_style = 'display: none';
9284: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9285: $homedom_div_style = 'display: block';
9286: }
9287: }
1.306 raeburn 9288: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9289: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9290: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9291: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9292: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9293: my @sparestypes = ('primary','default');
9294: my %typetitles = &sparestype_titles();
1.284 raeburn 9295: my %hostherechecked = (
9296: no => ' checked="checked"',
9297: );
1.342 raeburn 9298: my %balcookiechecked = (
1.425 raeburn 9299: no => ' checked="checked"',
1.342 raeburn 9300: );
1.171 raeburn 9301: foreach my $sparetype (@sparestypes) {
9302: my $targettable;
9303: for (my $i=0; $i<$numspares; $i++) {
9304: my $checked;
9305: if (ref($currtargets{$lonhost}) eq 'HASH') {
9306: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9307: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9308: $checked = ' checked="checked"';
9309: }
9310: }
9311: }
9312: my ($chkboxval,$disabled);
9313: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9314: $chkboxval = $spares[$i];
9315: }
9316: if (exists($currbalancer{$spares[$i]})) {
9317: $disabled = ' disabled="disabled"';
9318: }
1.210 raeburn 9319: $targettable .=
1.253 raeburn 9320: '<td><span class="LC_nobreak"><label>'.
9321: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9322: $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 9323: '</span></label></span></td>';
1.171 raeburn 9324: my $rem = $i%($numinrow);
9325: if ($rem == 0) {
9326: if (($i > 0) && ($i < $numspares-1)) {
9327: $targettable .= '</tr>';
9328: }
9329: if ($i < $numspares-1) {
9330: $targettable .= '<tr>';
1.150 raeburn 9331: }
9332: }
9333: }
1.171 raeburn 9334: if ($targettable ne '') {
9335: my $rem = $numspares%($numinrow);
9336: my $colsleft = $numinrow - $rem;
9337: if ($colsleft > 1 ) {
9338: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9339: ' </td>';
9340: } elsif ($colsleft == 1) {
9341: $targettable .= '<td class="LC_left_item"> </td>';
9342: }
9343: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9344: '<table><tr>'.$targettable.'</tr></table><br />';
9345: }
1.284 raeburn 9346: $hostherechecked{$sparetype} = '';
9347: if (ref($currtargets{$lonhost}) eq 'HASH') {
9348: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9349: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9350: $hostherechecked{$sparetype} = ' checked="checked"';
9351: $hostherechecked{'no'} = '';
9352: }
9353: }
9354: }
9355: }
1.342 raeburn 9356: if ($currcookies{$lonhost}) {
9357: %balcookiechecked = (
9358: yes => ' checked="checked"',
9359: );
9360: }
1.284 raeburn 9361: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9362: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9363: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9364: foreach my $sparetype (@sparestypes) {
9365: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9366: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9367: '</i></label><br />';
1.171 raeburn 9368: }
1.342 raeburn 9369: $datatable .= &mt('Use balancer cookie').'<br />'.
9370: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9371: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9372: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9373: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9374: '</div></td></tr>'.
1.171 raeburn 9375: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9376: $othertitle,$usertypes,$types,\%servers,
9377: \%currbalancer,$lonhost,
9378: $targets_div_style,$homedom_div_style,
9379: $css_class[$cssidx],$balnum,$islast);
9380: $$rowtotal += $rownum;
9381: $balnum ++;
9382: }
9383: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9384: return $datatable;
9385: }
9386:
9387: sub get_loadbalancers_config {
1.342 raeburn 9388: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9389: return unless ((ref($servers) eq 'HASH') &&
9390: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9391: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9392: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9393: if (keys(%{$existing}) > 0) {
9394: my $oldlonhost;
9395: foreach my $key (sort(keys(%{$existing}))) {
9396: if ($key eq 'lonhost') {
9397: $oldlonhost = $existing->{'lonhost'};
9398: $currbalancer->{$oldlonhost} = 1;
9399: } elsif ($key eq 'targets') {
9400: if ($oldlonhost) {
9401: $currtargets->{$oldlonhost} = $existing->{'targets'};
9402: }
9403: } elsif ($key eq 'rules') {
9404: if ($oldlonhost) {
9405: $currrules->{$oldlonhost} = $existing->{'rules'};
9406: }
9407: } elsif (ref($existing->{$key}) eq 'HASH') {
9408: $currbalancer->{$key} = 1;
9409: $currtargets->{$key} = $existing->{$key}{'targets'};
9410: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9411: if ($existing->{$key}{'cookie'}) {
9412: $currcookies->{$key} = 1;
9413: }
1.150 raeburn 9414: }
9415: }
1.171 raeburn 9416: } else {
9417: my ($balancerref,$targetsref) =
9418: &Apache::lonnet::get_lonbalancer_config($servers);
9419: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9420: foreach my $server (sort(keys(%{$balancerref}))) {
9421: $currbalancer->{$server} = 1;
9422: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9423: }
9424: }
9425: }
1.171 raeburn 9426: return;
1.150 raeburn 9427: }
9428:
9429: sub loadbalancing_rules {
9430: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9431: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9432: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9433: my $output;
1.171 raeburn 9434: my $num = 0;
1.210 raeburn 9435: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9436: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9437: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9438: foreach my $type (@{$alltypes}) {
1.171 raeburn 9439: $num ++;
1.150 raeburn 9440: my $current;
9441: if (ref($currrules) eq 'HASH') {
9442: $current = $currrules->{$type};
9443: }
1.253 raeburn 9444: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9445: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9446: $current = '';
9447: }
9448: }
9449: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9450: $servers,$currbalancer,$lonhost,$dom,
9451: $targets_div_style,$homedom_div_style,
9452: $css_class,$balnum,$num,$islast);
1.150 raeburn 9453: }
9454: }
9455: return $output;
9456: }
9457:
9458: sub loadbalancing_titles {
9459: my ($dom,$intdom,$usertypes,$types) = @_;
9460: my %othertypes = (
9461: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9462: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9463: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9464: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9465: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9466: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9467: );
1.209 raeburn 9468: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9469: my @available;
1.150 raeburn 9470: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9471: @available = @{$types};
1.150 raeburn 9472: }
1.302 raeburn 9473: unless (grep(/^default$/,@available)) {
9474: push(@available,'default');
9475: }
9476: unshift(@alltypes,@available);
1.150 raeburn 9477: my %titles;
9478: foreach my $type (@alltypes) {
9479: if ($type =~ /^_LC_/) {
9480: $titles{$type} = $othertypes{$type};
9481: } elsif ($type eq 'default') {
9482: $titles{$type} = &mt('All users from [_1]',$dom);
9483: if (ref($types) eq 'ARRAY') {
9484: if (@{$types} > 0) {
9485: $titles{$type} = &mt('Other users from [_1]',$dom);
9486: }
9487: }
9488: } elsif (ref($usertypes) eq 'HASH') {
9489: $titles{$type} = $usertypes->{$type};
9490: }
9491: }
9492: return (\@alltypes,\%othertypes,\%titles);
9493: }
9494:
9495: sub loadbalance_rule_row {
1.171 raeburn 9496: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9497: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9498: my @rulenames;
1.150 raeburn 9499: my %ruletitles = &offloadtype_text();
1.209 raeburn 9500: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9501: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9502: } else {
1.209 raeburn 9503: @rulenames = ('default','homeserver');
9504: if ($type eq '_LC_external') {
9505: push(@rulenames,'externalbalancer');
9506: } else {
9507: push(@rulenames,'specific');
9508: }
9509: push(@rulenames,'none');
1.150 raeburn 9510: }
9511: my $style = $targets_div_style;
1.253 raeburn 9512: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9513: $style = $homedom_div_style;
9514: }
1.171 raeburn 9515: my $space;
9516: if ($islast && $num == 1) {
1.317 raeburn 9517: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9518: }
1.210 raeburn 9519: my $output =
1.306 raeburn 9520: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9521: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9522: '<td valaign="top">'.$space.
9523: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9524: for (my $i=0; $i<@rulenames; $i++) {
9525: my $rule = $rulenames[$i];
9526: my ($checked,$extra);
9527: if ($rulenames[$i] eq 'default') {
9528: $rule = '';
9529: }
9530: if ($rulenames[$i] eq 'specific') {
9531: if (ref($servers) eq 'HASH') {
9532: my $default;
9533: if (($current ne '') && (exists($servers->{$current}))) {
9534: $checked = ' checked="checked"';
9535: }
9536: unless ($checked) {
9537: $default = ' selected="selected"';
9538: }
1.210 raeburn 9539: $extra =
1.171 raeburn 9540: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9541: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9542: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9543: '<option value=""'.$default.'></option>'."\n";
9544: foreach my $server (sort(keys(%{$servers}))) {
9545: if (ref($currbalancer) eq 'HASH') {
9546: next if (exists($currbalancer->{$server}));
9547: }
1.150 raeburn 9548: my $selected;
1.171 raeburn 9549: if ($server eq $current) {
1.150 raeburn 9550: $selected = ' selected="selected"';
9551: }
1.171 raeburn 9552: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9553: }
9554: $extra .= '</select>';
9555: }
9556: } elsif ($rule eq $current) {
9557: $checked = ' checked="checked"';
9558: }
9559: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9560: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9561: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9562: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9563: ')"'.$checked.' /> ';
9564: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9565: $output .= $ruletitles{'particular'};
9566: } else {
9567: $output .= $ruletitles{$rulenames[$i]};
9568: }
9569: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9570: }
9571: $output .= '</div></td></tr>'."\n";
9572: return $output;
9573: }
9574:
9575: sub offloadtype_text {
9576: my %ruletitles = &Apache::lonlocal::texthash (
9577: 'default' => 'Offloads to default destinations',
9578: 'homeserver' => "Offloads to user's home server",
9579: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9580: 'specific' => 'Offloads to specific server',
1.161 raeburn 9581: 'none' => 'No offload',
1.209 raeburn 9582: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9583: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9584: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9585: );
9586: return %ruletitles;
9587: }
9588:
9589: sub sparestype_titles {
9590: my %typestitles = &Apache::lonlocal::texthash (
9591: 'primary' => 'primary',
9592: 'default' => 'default',
9593: );
9594: return %typestitles;
9595: }
9596:
1.28 raeburn 9597: sub contact_titles {
9598: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9599: 'supportemail' => 'Support E-mail address',
9600: 'adminemail' => 'Default Server Admin E-mail address',
9601: 'errormail' => 'Error reports to be e-mailed to',
9602: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9603: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9604: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9605: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9606: 'requestsmail' => 'E-mail from course requests requiring approval',
9607: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9608: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9609: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9610: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9611: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9612: 'errorweights' => 'Weights used to compute error count',
9613: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9614: );
9615: my %short_titles = &Apache::lonlocal::texthash (
9616: adminemail => 'Admin E-mail address',
9617: supportemail => 'Support E-mail',
9618: );
9619: return (\%titles,\%short_titles);
9620: }
9621:
1.286 raeburn 9622: sub helpform_fields {
9623: my %titles = &Apache::lonlocal::texthash (
9624: 'username' => 'Name',
9625: 'user' => 'Username/domain',
9626: 'phone' => 'Phone',
9627: 'cc' => 'Cc e-mail',
9628: 'course' => 'Course Details',
9629: 'section' => 'Sections',
1.289 raeburn 9630: 'screenshot' => 'File upload',
1.286 raeburn 9631: );
9632: my @fields = ('username','phone','user','course','section','cc','screenshot');
9633: my %possoptions = (
9634: username => ['yes','no','req'],
1.289 raeburn 9635: phone => ['yes','no','req'],
1.286 raeburn 9636: user => ['yes','no'],
1.289 raeburn 9637: cc => ['yes','no'],
1.286 raeburn 9638: course => ['yes','no'],
9639: section => ['yes','no'],
9640: screenshot => ['yes','no'],
9641: );
9642: my %fieldoptions = &Apache::lonlocal::texthash (
9643: 'yes' => 'Optional',
9644: 'req' => 'Required',
9645: 'no' => "Not shown",
9646: );
9647: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9648: }
9649:
1.72 raeburn 9650: sub tool_titles {
9651: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9652: aboutme => 'Personal web page',
1.86 raeburn 9653: blog => 'Blog',
9654: portfolio => 'Portfolio',
1.413 raeburn 9655: timezone => 'Can set time zone',
1.88 bisitz 9656: official => 'Official courses (with institutional codes)',
9657: unofficial => 'Unofficial courses',
1.98 raeburn 9658: community => 'Communities',
1.216 raeburn 9659: textbook => 'Textbook courses',
1.271 raeburn 9660: placement => 'Placement tests',
1.86 raeburn 9661: );
1.72 raeburn 9662: return %titles;
9663: }
9664:
1.101 raeburn 9665: sub courserequest_titles {
9666: my %titles = &Apache::lonlocal::texthash (
9667: official => 'Official',
9668: unofficial => 'Unofficial',
9669: community => 'Communities',
1.216 raeburn 9670: textbook => 'Textbook',
1.271 raeburn 9671: placement => 'Placement tests',
1.325 raeburn 9672: lti => 'LTI Provider',
1.101 raeburn 9673: norequest => 'Not allowed',
1.325 raeburn 9674: approval => 'Approval by DC',
1.101 raeburn 9675: validate => 'With validation',
9676: autolimit => 'Numerical limit',
1.103 raeburn 9677: unlimited => '(blank for unlimited)',
1.101 raeburn 9678: );
9679: return %titles;
9680: }
9681:
1.163 raeburn 9682: sub authorrequest_titles {
9683: my %titles = &Apache::lonlocal::texthash (
9684: norequest => 'Not allowed',
9685: approval => 'Approval by Dom. Coord.',
9686: automatic => 'Automatic approval',
9687: );
9688: return %titles;
1.210 raeburn 9689: }
1.163 raeburn 9690:
1.101 raeburn 9691: sub courserequest_conditions {
9692: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9693: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9694: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9695: );
9696: return %conditions;
9697: }
9698:
9699:
1.27 raeburn 9700: sub print_usercreation {
1.30 raeburn 9701: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9702: my $numinrow = 4;
1.28 raeburn 9703: my $datatable;
9704: if ($position eq 'top') {
1.30 raeburn 9705: $$rowtotal ++;
1.34 raeburn 9706: my $rowcount = 0;
1.32 raeburn 9707: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9708: if (ref($rules) eq 'HASH') {
9709: if (keys(%{$rules}) > 0) {
1.32 raeburn 9710: $datatable .= &user_formats_row('username',$settings,$rules,
9711: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9712: $$rowtotal ++;
1.32 raeburn 9713: $rowcount ++;
9714: }
9715: }
9716: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9717: if (ref($idrules) eq 'HASH') {
9718: if (keys(%{$idrules}) > 0) {
9719: $datatable .= &user_formats_row('id',$settings,$idrules,
9720: $idruleorder,$numinrow,$rowcount);
9721: $$rowtotal ++;
9722: $rowcount ++;
1.28 raeburn 9723: }
9724: }
1.39 raeburn 9725: if ($rowcount == 0) {
9726: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9727: $$rowtotal ++;
9728: $rowcount ++;
9729: }
1.34 raeburn 9730: } elsif ($position eq 'middle') {
1.224 raeburn 9731: my @creators = ('author','course','requestcrs');
1.37 raeburn 9732: my ($rules,$ruleorder) =
9733: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9734: my %lt = &usercreation_types();
9735: my %checked;
9736: if (ref($settings) eq 'HASH') {
9737: if (ref($settings->{'cancreate'}) eq 'HASH') {
9738: foreach my $item (@creators) {
9739: $checked{$item} = $settings->{'cancreate'}{$item};
9740: }
9741: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9742: foreach my $item (@creators) {
9743: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9744: $checked{$item} = 'none';
9745: }
9746: }
9747: }
9748: }
9749: my $rownum = 0;
9750: foreach my $item (@creators) {
9751: $rownum ++;
1.224 raeburn 9752: if ($checked{$item} eq '') {
9753: $checked{$item} = 'any';
1.34 raeburn 9754: }
9755: my $css_class;
9756: if ($rownum%2) {
9757: $css_class = '';
9758: } else {
9759: $css_class = ' class="LC_odd_row" ';
9760: }
9761: $datatable .= '<tr'.$css_class.'>'.
9762: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9763: '</span></td><td style="text-align: right">';
1.224 raeburn 9764: my @options = ('any');
9765: if (ref($rules) eq 'HASH') {
9766: if (keys(%{$rules}) > 0) {
9767: push(@options,('official','unofficial'));
1.37 raeburn 9768: }
9769: }
1.224 raeburn 9770: push(@options,'none');
1.37 raeburn 9771: foreach my $option (@options) {
1.50 raeburn 9772: my $type = 'radio';
1.34 raeburn 9773: my $check = ' ';
1.224 raeburn 9774: if ($checked{$item} eq $option) {
9775: $check = ' checked="checked" ';
1.34 raeburn 9776: }
9777: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9778: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9779: $item.'" value="'.$option.'"'.$check.'/> '.
9780: $lt{$option}.'</label> </span>';
9781: }
9782: $datatable .= '</td></tr>';
9783: }
1.28 raeburn 9784: } else {
9785: my @contexts = ('author','course','domain');
1.325 raeburn 9786: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9787: my %checked;
9788: if (ref($settings) eq 'HASH') {
9789: if (ref($settings->{'authtypes'}) eq 'HASH') {
9790: foreach my $item (@contexts) {
9791: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9792: foreach my $auth (@authtypes) {
9793: if ($settings->{'authtypes'}{$item}{$auth}) {
9794: $checked{$item}{$auth} = ' checked="checked" ';
9795: }
9796: }
9797: }
9798: }
1.27 raeburn 9799: }
1.35 raeburn 9800: } else {
9801: foreach my $item (@contexts) {
1.36 raeburn 9802: foreach my $auth (@authtypes) {
1.35 raeburn 9803: $checked{$item}{$auth} = ' checked="checked" ';
9804: }
9805: }
1.27 raeburn 9806: }
1.28 raeburn 9807: my %title = &context_names();
9808: my %authname = &authtype_names();
9809: my $rownum = 0;
9810: my $css_class;
9811: foreach my $item (@contexts) {
9812: if ($rownum%2) {
9813: $css_class = '';
9814: } else {
9815: $css_class = ' class="LC_odd_row" ';
9816: }
1.30 raeburn 9817: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9818: '<td>'.$title{$item}.
9819: '</td><td class="LC_left_item">'.
9820: '<span class="LC_nobreak">';
9821: foreach my $auth (@authtypes) {
9822: $datatable .= '<label>'.
9823: '<input type="checkbox" name="'.$item.'_auth" '.
9824: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9825: $authname{$auth}.'</label> ';
9826: }
9827: $datatable .= '</span></td></tr>';
9828: $rownum ++;
1.27 raeburn 9829: }
1.30 raeburn 9830: $$rowtotal += $rownum;
1.27 raeburn 9831: }
9832: return $datatable;
9833: }
9834:
1.224 raeburn 9835: sub print_selfcreation {
9836: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9837: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9838: $emaildomain,$datatable);
1.224 raeburn 9839: if (ref($settings) eq 'HASH') {
9840: if (ref($settings->{'cancreate'}) eq 'HASH') {
9841: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9842: if (ref($createsettings) eq 'HASH') {
9843: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9844: @selfcreate = @{$createsettings->{'selfcreate'}};
9845: } elsif ($createsettings->{'selfcreate'} ne '') {
9846: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9847: @selfcreate = ('email','login','sso');
9848: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9849: @selfcreate = ($createsettings->{'selfcreate'});
9850: }
9851: }
9852: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9853: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9854: }
1.305 raeburn 9855: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9856: $emailoptions = $createsettings->{'emailoptions'};
9857: }
1.303 raeburn 9858: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9859: $emailverified = $createsettings->{'emailverified'};
9860: }
9861: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9862: $emaildomain = $createsettings->{'emaildomain'};
9863: }
1.224 raeburn 9864: }
9865: }
9866: }
9867: my %radiohash;
9868: my $numinrow = 4;
9869: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9870: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9871: if ($position eq 'top') {
9872: my %choices = &Apache::lonlocal::texthash (
9873: cancreate_login => 'Institutional Login',
9874: cancreate_sso => 'Institutional Single Sign On',
9875: );
9876: my @toggles = sort(keys(%choices));
9877: my %defaultchecked = (
9878: 'cancreate_login' => 'off',
9879: 'cancreate_sso' => 'off',
9880: );
1.228 raeburn 9881: my ($onclick,$itemcount);
1.224 raeburn 9882: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9883: \%choices,$itemcount,$onclick);
1.228 raeburn 9884: $$rowtotal += $itemcount;
1.425 raeburn 9885:
1.224 raeburn 9886: if (ref($usertypes) eq 'HASH') {
9887: if (keys(%{$usertypes}) > 0) {
9888: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9889: $dom,$numinrow,$othertitle,
1.305 raeburn 9890: 'statustocreate',$rowtotal);
1.224 raeburn 9891: $$rowtotal ++;
9892: }
9893: }
1.240 raeburn 9894: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
9895: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9896: $fieldtitles{'inststatus'} = &mt('Institutional status');
9897: my $rem;
9898: my $numperrow = 2;
9899: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
9900: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 9901: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 9902: '<td class="LC_left_item">'."\n".
1.334 raeburn 9903: '<table>'."\n";
1.240 raeburn 9904: for (my $i=0; $i<@fields; $i++) {
9905: $rem = $i%($numperrow);
9906: if ($rem == 0) {
9907: if ($i > 0) {
9908: $datatable .= '</tr>';
9909: }
9910: $datatable .= '<tr>';
9911: }
9912: my $currval;
1.248 raeburn 9913: if (ref($createsettings) eq 'HASH') {
9914: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
9915: $currval = $createsettings->{'shibenv'}{$fields[$i]};
9916: }
1.240 raeburn 9917: }
9918: $datatable .= '<td class="LC_left_item">'.
9919: '<span class="LC_nobreak">'.
9920: '<input type="text" name="shibenv_'.$fields[$i].'" '.
9921: 'value="'.$currval.'" size="10" /> '.
9922: $fieldtitles{$fields[$i]}.'</span></td>';
9923: }
9924: my $colsleft = $numperrow - $rem;
9925: if ($colsleft > 1 ) {
9926: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9927: ' </td>';
9928: } elsif ($colsleft == 1) {
9929: $datatable .= '<td class="LC_left_item"> </td>';
9930: }
9931: $datatable .= '</tr></table></td></tr>';
9932: $$rowtotal ++;
1.224 raeburn 9933: } elsif ($position eq 'middle') {
9934: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 9935: my @posstypes;
1.224 raeburn 9936: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9937: @posstypes = @{$types};
9938: }
9939: unless (grep(/^default$/,@posstypes)) {
9940: push(@posstypes,'default');
9941: }
9942: my %usertypeshash;
9943: if (ref($usertypes) eq 'HASH') {
9944: %usertypeshash = %{$usertypes};
9945: }
9946: $usertypeshash{'default'} = $othertitle;
9947: foreach my $status (@posstypes) {
9948: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
9949: $numinrow,$$rowtotal,\%usertypeshash);
9950: $$rowtotal ++;
1.224 raeburn 9951: }
9952: } else {
1.236 raeburn 9953: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 9954: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 9955: );
9956: my @toggles = sort(keys(%choices));
9957: my %defaultchecked = (
9958: 'cancreate_email' => 'off',
9959: );
1.305 raeburn 9960: my $customclass = 'LC_selfcreate_email';
9961: my $classprefix = 'LC_canmodify_emailusername_';
9962: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 9963: my $display = 'none';
1.305 raeburn 9964: my $rowstyle = 'display:none';
1.236 raeburn 9965: if (grep(/^\Qemail\E$/,@selfcreate)) {
9966: $display = 'block';
1.305 raeburn 9967: $rowstyle = 'display:table-row';
1.236 raeburn 9968: }
1.305 raeburn 9969: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
9970: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9971: \%choices,$$rowtotal,$onclick);
9972: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
9973: $rowstyle);
9974: $$rowtotal ++;
9975: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
9976: $rowstyle);
9977: $$rowtotal ++;
9978: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 9979: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 9980: my ($emailrules,$emailruleorder) =
9981: &Apache::lonnet::inst_userrules($dom,'email');
9982: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9983: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9984: if (ref($types) eq 'ARRAY') {
9985: @posstypes = @{$types};
9986: }
9987: if (@posstypes) {
9988: unless (grep(/^default$/,@posstypes)) {
9989: push(@posstypes,'default');
1.302 raeburn 9990: }
9991: if (ref($usertypes) eq 'HASH') {
9992: %usertypeshash = %{$usertypes};
9993: }
1.305 raeburn 9994: my $currassign;
9995: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
9996: $currassign = {
9997: selfassign => $domdefaults{'inststatusguest'},
9998: };
9999: @ordered = @{$domdefaults{'inststatusguest'}};
10000: } else {
10001: $currassign = { selfassign => [] };
10002: }
10003: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10004: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10005: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10006: $numinrow,$othertitle,'selfassign',
10007: $rowtotal,$onclicktypes,$customclass,
10008: $rowstyle);
10009: $$rowtotal ++;
1.302 raeburn 10010: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10011: foreach my $status (@posstypes) {
10012: my $css_class;
10013: if ($$rowtotal%2) {
10014: $css_class = 'LC_odd_row ';
10015: }
10016: $css_class .= $customclass;
10017: my $rowid = $optionsprefix.$status;
10018: my $hidden = 1;
10019: my $currstyle = 'display:none';
10020: if (grep(/^\Q$status\E$/,@ordered)) {
10021: $currstyle = $rowstyle;
1.425 raeburn 10022: $hidden = 0;
1.305 raeburn 10023: }
10024: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10025: $emailrules,$emailruleorder,$settings,$status,$rowid,
10026: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10027: unless ($hidden) {
10028: $$rowtotal ++;
10029: }
1.224 raeburn 10030: }
1.302 raeburn 10031: } else {
1.305 raeburn 10032: my $css_class;
10033: if ($$rowtotal%2) {
10034: $css_class = 'LC_odd_row ';
10035: }
10036: $css_class .= $customclass;
1.302 raeburn 10037: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10038: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10039: $emailrules,$emailruleorder,$settings,'default','',
10040: $othertitle,$css_class,$rowstyle,$intdom);
10041: $$rowtotal ++;
1.224 raeburn 10042: }
10043: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10044: $numinrow = 1;
1.305 raeburn 10045: if (@posstypes) {
10046: foreach my $status (@posstypes) {
10047: my $rowid = $classprefix.$status;
10048: my $datarowstyle = 'display:none';
1.425 raeburn 10049: if (grep(/^\Q$status\E$/,@ordered)) {
10050: $datarowstyle = $rowstyle;
1.305 raeburn 10051: }
10052: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10053: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10054: $infotitles,$rowid,$customclass,$datarowstyle);
10055: unless ($datarowstyle eq 'display:none') {
10056: $$rowtotal ++;
10057: }
1.224 raeburn 10058: }
1.305 raeburn 10059: } else {
10060: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10061: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10062: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10063: }
10064: }
10065: return $datatable;
10066: }
10067:
1.305 raeburn 10068: sub selfcreate_javascript {
10069: return <<"ENDSCRIPT";
10070:
10071: <script type="text/javascript">
10072: // <![CDATA[
10073:
10074: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10075: var x = document.getElementsByClassName(target);
10076: var insttypes = 0;
10077: var insttypeRegExp = new RegExp(prefix);
10078: if ((x.length != undefined) && (x.length > 0)) {
10079: if (form.elements[radio].length != undefined) {
10080: for (var i=0; i<form.elements[radio].length; i++) {
10081: if (form.elements[radio][i].checked) {
10082: if (form.elements[radio][i].value == 1) {
10083: for (var j=0; j<x.length; j++) {
10084: if (x[j].id == 'undefined') {
10085: x[j].style.display = 'table-row';
10086: } else if (insttypeRegExp.test(x[j].id)) {
10087: insttypes ++;
10088: } else {
10089: x[j].style.display = 'table-row';
10090: }
10091: }
10092: } else {
10093: for (var j=0; j<x.length; j++) {
10094: x[j].style.display = 'none';
10095: }
1.236 raeburn 10096: }
1.305 raeburn 10097: break;
10098: }
10099: }
10100: if (insttypes > 0) {
10101: toggleDataRow(form,checkbox,target,altprefix);
10102: toggleDataRow(form,checkbox,target,prefix,1);
10103: }
10104: }
10105: }
10106: return;
10107: }
10108:
10109: function toggleDataRow(form,checkbox,target,prefix,docount) {
10110: if (form.elements[checkbox].length != undefined) {
10111: var count = 0;
10112: if (docount) {
10113: for (var i=0; i<form.elements[checkbox].length; i++) {
10114: if (form.elements[checkbox][i].checked) {
10115: count ++;
1.236 raeburn 10116: }
1.305 raeburn 10117: }
10118: }
10119: for (var i=0; i<form.elements[checkbox].length; i++) {
10120: var type = form.elements[checkbox][i].value;
10121: if (document.getElementById(prefix+type)) {
10122: if (form.elements[checkbox][i].checked) {
10123: document.getElementById(prefix+type).style.display = 'table-row';
10124: if (count % 2 == 1) {
10125: document.getElementById(prefix+type).className = target+' LC_odd_row';
10126: } else {
10127: document.getElementById(prefix+type).className = target;
1.236 raeburn 10128: }
1.305 raeburn 10129: count ++;
1.236 raeburn 10130: } else {
1.305 raeburn 10131: document.getElementById(prefix+type).style.display = 'none';
10132: }
10133: }
10134: }
10135: }
10136: return;
10137: }
10138:
10139: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10140: var caller = radio+'_'+status;
10141: if (form.elements[caller].length != undefined) {
10142: for (var i=0; i<form.elements[caller].length; i++) {
10143: if (form.elements[caller][i].checked) {
10144: if (document.getElementById(altprefix+'_inst_'+status)) {
10145: var curr = form.elements[caller][i].value;
10146: if (prefix) {
10147: document.getElementById(prefix+'_'+status).style.display = 'none';
10148: }
10149: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10150: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10151: if (curr == 'custom') {
1.425 raeburn 10152: if (prefix) {
1.305 raeburn 10153: document.getElementById(prefix+'_'+status).style.display = 'inline';
10154: }
10155: } else if (curr == 'inst') {
10156: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10157: } else if (curr == 'noninst') {
10158: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10159: }
1.305 raeburn 10160: break;
1.236 raeburn 10161: }
10162: }
10163: }
10164: }
10165: }
10166:
1.305 raeburn 10167: // ]]>
10168: </script>
10169:
10170: ENDSCRIPT
10171: }
10172:
10173: sub noninst_users {
10174: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10175: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10176: my $class = 'LC_left_item';
10177: if ($css_class) {
1.425 raeburn 10178: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10179: }
10180: if ($rowid) {
10181: $rowid = ' id="'.$rowid.'"';
10182: }
10183: if ($rowstyle) {
10184: $rowstyle = ' style="'.$rowstyle.'"';
10185: }
10186: my ($output,$description);
10187: if ($type eq 'default') {
10188: $description = &mt('Requests for: [_1]',$typetitle);
10189: } else {
10190: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10191: }
10192: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10193: "<td>$description</td>\n".
1.305 raeburn 10194: '<td class="'.$class.'" colspan="2">'.
10195: '<table><tr>';
1.425 raeburn 10196: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10197: approve => 'Processing',
10198: email => 'E-mail',
10199: username => 'Username',
10200: );
10201: foreach my $item ('approve','email','username') {
10202: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10203: }
1.305 raeburn 10204: $output .= '</tr><tr>';
10205: foreach my $item ('approve','email','username') {
1.306 raeburn 10206: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10207: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10208: if ($item eq 'approve') {
10209: %choices = &Apache::lonlocal::texthash (
10210: automatic => 'Automatically approved',
10211: approval => 'Queued for approval',
10212: );
10213: @options = ('automatic','approval');
10214: $hashref = $processing;
10215: $defoption = 'automatic';
10216: $name = 'cancreate_emailprocess_'.$type;
10217: } elsif ($item eq 'email') {
10218: %choices = &Apache::lonlocal::texthash (
10219: any => 'Any e-mail',
10220: inst => 'Institutional only',
10221: noninst => 'Non-institutional only',
10222: custom => 'Custom restrictions',
10223: );
10224: @options = ('any','inst','noninst');
10225: my $showcustom;
10226: if (ref($emailrules) eq 'HASH') {
10227: if (keys(%{$emailrules}) > 0) {
10228: push(@options,'custom');
10229: $showcustom = 'cancreate_emailrule';
10230: if (ref($settings) eq 'HASH') {
10231: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10232: foreach my $rule (@{$settings->{'email_rule'}}) {
10233: if (exists($emailrules->{$rule})) {
10234: $hascustom ++;
10235: }
10236: }
10237: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10238: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10239: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10240: if (exists($emailrules->{$rule})) {
10241: $hascustom ++;
10242: }
10243: }
10244: }
10245: }
10246: }
10247: }
10248: }
10249: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10250: "'cancreate_emaildomain','$type'".');"';
10251: $hashref = $emailoptions;
10252: $defoption = 'any';
10253: $name = 'cancreate_emailoptions_'.$type;
10254: } elsif ($item eq 'username') {
10255: %choices = &Apache::lonlocal::texthash (
10256: all => 'Same as e-mail',
10257: first => 'Omit @domain',
10258: free => 'Free to choose',
10259: );
10260: @options = ('all','first','free');
10261: $hashref = $emailverified;
10262: $defoption = 'all';
10263: $name = 'cancreate_usernameoptions_'.$type;
10264: }
10265: foreach my $option (@options) {
10266: my $checked;
10267: if (ref($hashref) eq 'HASH') {
10268: if ($type eq '') {
10269: if (!exists($hashref->{'default'})) {
10270: if ($option eq $defoption) {
10271: $checked = ' checked="checked"';
10272: }
10273: } else {
10274: if ($hashref->{'default'} eq $option) {
10275: $checked = ' checked="checked"';
10276: }
1.303 raeburn 10277: }
10278: } else {
1.305 raeburn 10279: if (!exists($hashref->{$type})) {
10280: if ($option eq $defoption) {
10281: $checked = ' checked="checked"';
10282: }
10283: } else {
10284: if ($hashref->{$type} eq $option) {
10285: $checked = ' checked="checked"';
10286: }
1.303 raeburn 10287: }
10288: }
1.305 raeburn 10289: } elsif (($item eq 'email') && ($hascustom)) {
10290: if ($option eq 'custom') {
10291: $checked = ' checked="checked"';
10292: }
10293: } elsif ($option eq $defoption) {
10294: $checked = ' checked="checked"';
10295: }
10296: $output .= '<span class="LC_nobreak"><label>'.
10297: '<input type="radio" name="'.$name.'"'.
10298: $checked.' value="'.$option.'"'.$onclick.' />'.
10299: $choices{$option}.'</label></span><br />';
10300: if ($item eq 'email') {
10301: if ($option eq 'custom') {
10302: my $id = 'cancreate_emailrule_'.$type;
10303: my $display = 'none';
10304: if ($checked) {
10305: $display = 'inline';
1.303 raeburn 10306: }
1.305 raeburn 10307: my $numinrow = 2;
10308: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10309: '<legend>'.&mt('Disallow').'</legend><table>'.
10310: &user_formats_row('email',$settings,$emailrules,
10311: $emailruleorder,$numinrow,'',$type);
10312: '</table></fieldset>';
10313: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10314: my %text = &Apache::lonlocal::texthash (
10315: inst => 'must end:',
10316: noninst => 'cannot end:',
10317: );
10318: my $value;
10319: if (ref($emaildomain) eq 'HASH') {
10320: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10321: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10322: }
10323: }
1.305 raeburn 10324: if ($value eq '') {
10325: $value = '@'.$intdom;
10326: }
10327: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10328: my $display = 'none';
10329: if ($checked) {
10330: $display = 'inline';
10331: }
10332: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10333: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10334: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10335: '</div>';
1.303 raeburn 10336: }
10337: }
10338: }
1.305 raeburn 10339: $output .= '</td>'."\n";
1.303 raeburn 10340: }
1.305 raeburn 10341: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10342: return $output;
10343: }
10344:
1.165 raeburn 10345: sub captcha_choice {
1.305 raeburn 10346: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10347: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10348: $vertext,$currver);
1.165 raeburn 10349: my %lt = &captcha_phrases();
10350: $keyentry = 'hidden';
1.354 raeburn 10351: my $colspan=2;
1.165 raeburn 10352: if ($context eq 'cancreate') {
1.224 raeburn 10353: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10354: } elsif ($context eq 'login') {
10355: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10356: } elsif ($context eq 'passwords') {
10357: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10358: $colspan=1;
1.165 raeburn 10359: }
10360: if (ref($settings) eq 'HASH') {
10361: if ($settings->{'captcha'}) {
10362: $checked{$settings->{'captcha'}} = ' checked="checked"';
10363: } else {
10364: $checked{'original'} = ' checked="checked"';
10365: }
10366: if ($settings->{'captcha'} eq 'recaptcha') {
10367: $pubtext = $lt{'pub'};
10368: $privtext = $lt{'priv'};
10369: $keyentry = 'text';
1.269 raeburn 10370: $vertext = $lt{'ver'};
10371: $currver = $settings->{'recaptchaversion'};
10372: if ($currver ne '2') {
10373: $currver = 1;
10374: }
1.165 raeburn 10375: }
10376: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10377: $currpub = $settings->{'recaptchakeys'}{'public'};
10378: $currpriv = $settings->{'recaptchakeys'}{'private'};
10379: }
10380: } else {
10381: $checked{'original'} = ' checked="checked"';
10382: }
1.305 raeburn 10383: my $css_class;
10384: if ($itemcount%2) {
10385: $css_class = 'LC_odd_row';
10386: }
10387: if ($customcss) {
10388: $css_class .= " $customcss";
10389: }
10390: $css_class =~ s/^\s+//;
10391: if ($css_class) {
10392: $css_class = ' class="'.$css_class.'"';
10393: }
10394: if ($rowstyle) {
10395: $css_class .= ' style="'.$rowstyle.'"';
10396: }
1.169 raeburn 10397: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10398: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10399: '<table><tr><td>'."\n";
10400: foreach my $option ('original','recaptcha','notused') {
10401: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10402: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10403: $lt{$option}.'</label></span>';
10404: unless ($option eq 'notused') {
10405: $output .= (' 'x2)."\n";
10406: }
10407: }
10408: #
10409: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10410: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10411: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10412: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10413: #
1.165 raeburn 10414: $output .= '</td></tr>'."\n".
1.305 raeburn 10415: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10416: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10417: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10418: $currpub.'" size="40" /></span><br />'."\n".
10419: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10420: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10421: $currpriv.'" size="40" /></span><br />'.
10422: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10423: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10424: $currver.'" size="3" /></span><br />'.
10425: '</td></tr></table>'."\n".
1.165 raeburn 10426: '</td></tr>';
10427: return $output;
10428: }
10429:
1.32 raeburn 10430: sub user_formats_row {
1.305 raeburn 10431: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10432: my $output;
10433: my %text = (
10434: 'username' => 'new usernames',
10435: 'id' => 'IDs',
10436: );
1.409 raeburn 10437: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10438: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10439: $output = '<tr '.$css_class.'>'.
10440: '<td><span class="LC_nobreak">'.
10441: &mt("Format rules to check for $text{$type}: ").
10442: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10443: }
1.27 raeburn 10444: my $rem;
10445: if (ref($ruleorder) eq 'ARRAY') {
10446: for (my $i=0; $i<@{$ruleorder}; $i++) {
10447: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10448: my $rem = $i%($numinrow);
10449: if ($rem == 0) {
10450: if ($i > 0) {
10451: $output .= '</tr>';
10452: }
10453: $output .= '<tr>';
10454: }
10455: my $check = ' ';
1.39 raeburn 10456: if (ref($settings) eq 'HASH') {
10457: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10458: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10459: $check = ' checked="checked" ';
10460: }
1.305 raeburn 10461: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10462: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10463: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10464: $check = ' checked="checked" ';
10465: }
10466: }
1.27 raeburn 10467: }
10468: }
1.305 raeburn 10469: my $name = $type.'_rule';
10470: if ($type eq 'email') {
10471: $name .= '_'.$status;
10472: }
1.27 raeburn 10473: $output .= '<td class="LC_left_item">'.
10474: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10475: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10476: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10477: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10478: }
10479: }
10480: $rem = @{$ruleorder}%($numinrow);
10481: }
1.305 raeburn 10482: my $colsleft;
10483: if ($rem) {
10484: $colsleft = $numinrow - $rem;
10485: }
1.27 raeburn 10486: if ($colsleft > 1 ) {
10487: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10488: ' </td>';
10489: } elsif ($colsleft == 1) {
10490: $output .= '<td class="LC_left_item"> </td>';
10491: }
1.409 raeburn 10492: $output .= '</tr>';
10493: unless (($type eq 'email') || ($type eq 'unamemap')) {
10494: $output .= '</table></td></tr>';
1.305 raeburn 10495: }
1.27 raeburn 10496: return $output;
10497: }
10498:
1.34 raeburn 10499: sub usercreation_types {
10500: my %lt = &Apache::lonlocal::texthash (
10501: author => 'When adding a co-author',
10502: course => 'When adding a user to a course',
1.100 raeburn 10503: requestcrs => 'When requesting a course',
1.34 raeburn 10504: any => 'Any',
10505: official => 'Institutional only ',
10506: unofficial => 'Non-institutional only',
10507: none => 'None',
10508: );
10509: return %lt;
1.48 raeburn 10510: }
1.34 raeburn 10511:
1.224 raeburn 10512: sub selfcreation_types {
10513: my %lt = &Apache::lonlocal::texthash (
10514: selfcreate => 'User creates own account',
10515: any => 'Any',
10516: official => 'Institutional only ',
10517: unofficial => 'Non-institutional only',
10518: email => 'E-mail address',
10519: login => 'Institutional Login',
10520: sso => 'SSO',
10521: );
10522: }
10523:
1.28 raeburn 10524: sub authtype_names {
10525: my %lt = &Apache::lonlocal::texthash(
10526: int => 'Internal',
10527: krb4 => 'Kerberos 4',
10528: krb5 => 'Kerberos 5',
10529: loc => 'Local',
1.325 raeburn 10530: lti => 'LTI',
1.28 raeburn 10531: );
10532: return %lt;
10533: }
10534:
10535: sub context_names {
10536: my %context_title = &Apache::lonlocal::texthash(
10537: author => 'Creating users when an Author',
10538: course => 'Creating users when in a course',
10539: domain => 'Creating users when a Domain Coordinator',
10540: );
10541: return %context_title;
10542: }
10543:
1.33 raeburn 10544: sub print_usermodification {
10545: my ($position,$dom,$settings,$rowtotal) = @_;
10546: my $numinrow = 4;
10547: my ($context,$datatable,$rowcount);
10548: if ($position eq 'top') {
10549: $rowcount = 0;
10550: $context = 'author';
10551: foreach my $role ('ca','aa') {
10552: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10553: $numinrow,$rowcount);
10554: $$rowtotal ++;
10555: $rowcount ++;
10556: }
1.230 raeburn 10557: } elsif ($position eq 'bottom') {
1.33 raeburn 10558: $context = 'course';
10559: $rowcount = 0;
10560: foreach my $role ('st','ep','ta','in','cr') {
10561: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10562: $numinrow,$rowcount);
10563: $$rowtotal ++;
10564: $rowcount ++;
10565: }
10566: }
10567: return $datatable;
10568: }
10569:
1.43 raeburn 10570: sub print_defaults {
1.236 raeburn 10571: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10572: my $rownum = 0;
1.294 raeburn 10573: my ($datatable,$css_class,$titles);
10574: unless ($position eq 'bottom') {
10575: $titles = &defaults_titles($dom);
10576: }
1.236 raeburn 10577: if ($position eq 'top') {
10578: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10579: 'datelocale_def','portal_def');
10580: my %defaults;
10581: if (ref($settings) eq 'HASH') {
10582: %defaults = %{$settings};
1.43 raeburn 10583: } else {
1.236 raeburn 10584: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10585: foreach my $item (@items) {
10586: $defaults{$item} = $domdefaults{$item};
10587: }
1.43 raeburn 10588: }
1.236 raeburn 10589: foreach my $item (@items) {
10590: if ($rownum%2) {
10591: $css_class = '';
10592: } else {
10593: $css_class = ' class="LC_odd_row" ';
10594: }
10595: $datatable .= '<tr'.$css_class.'>'.
10596: '<td><span class="LC_nobreak">'.$titles->{$item}.
10597: '</span></td><td class="LC_right_item" colspan="3">';
10598: if ($item eq 'auth_def') {
1.325 raeburn 10599: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10600: my %shortauth = (
10601: internal => 'int',
10602: krb4 => 'krb4',
10603: krb5 => 'krb5',
1.325 raeburn 10604: localauth => 'loc',
10605: lti => 'lti',
1.236 raeburn 10606: );
10607: my %authnames = &authtype_names();
10608: foreach my $auth (@authtypes) {
10609: my $checked = ' ';
10610: if ($defaults{$item} eq $auth) {
10611: $checked = ' checked="checked" ';
10612: }
10613: $datatable .= '<label><input type="radio" name="'.$item.
10614: '" value="'.$auth.'"'.$checked.'/>'.
10615: $authnames{$shortauth{$auth}}.'</label> ';
10616: }
10617: } elsif ($item eq 'timezone_def') {
10618: my $includeempty = 1;
10619: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10620: } elsif ($item eq 'datelocale_def') {
10621: my $includeempty = 1;
10622: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10623: } elsif ($item eq 'lang_def') {
1.263 raeburn 10624: my $includeempty = 1;
10625: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10626: } elsif ($item eq 'portal_def') {
10627: $datatable .= '<input type="text" name="'.$item.'" value="'.
10628: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10629: my $portalsty = 'none';
10630: if ($defaults{$item}) {
10631: $portalsty = 'block';
10632: }
10633: foreach my $field ('email','web') {
10634: my $checkedoff = ' checked="checked"';
10635: my $checkedon;
10636: if ($defaults{$item.'_'.$field}) {
10637: $checkedon = $checkedoff;
10638: $checkedoff = '';
1.425 raeburn 10639: }
1.414 raeburn 10640: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10641: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10642: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10643: (' 'x2).
10644: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10645: '</div>';
10646: }
1.236 raeburn 10647: } else {
1.414 raeburn 10648: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10649: }
1.236 raeburn 10650: $datatable .= '</td></tr>';
10651: $rownum ++;
10652: }
1.409 raeburn 10653: } elsif ($position eq 'middle') {
1.294 raeburn 10654: my %defaults;
10655: if (ref($settings) eq 'HASH') {
1.354 raeburn 10656: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10657: my $maxnum = @{$settings->{'inststatusorder'}};
10658: for (my $i=0; $i<$maxnum; $i++) {
10659: $css_class = $rownum%2?' class="LC_odd_row"':'';
10660: my $item = $settings->{'inststatusorder'}->[$i];
10661: my $title = $settings->{'inststatustypes'}->{$item};
10662: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10663: $datatable .= '<tr'.$css_class.'>'.
10664: '<td><span class="LC_nobreak">'.
10665: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10666: for (my $k=0; $k<=$maxnum; $k++) {
10667: my $vpos = $k+1;
10668: my $selstr;
10669: if ($k == $i) {
10670: $selstr = ' selected="selected" ';
10671: }
10672: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10673: }
10674: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10675: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10676: &mt('delete').'</span></td>'.
1.380 raeburn 10677: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10678: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10679: '</span></td></tr>';
10680: }
10681: $css_class = $rownum%2?' class="LC_odd_row"':'';
10682: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10683: $datatable .= '<tr '.$css_class.'>'.
10684: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10685: for (my $k=0; $k<=$maxnum; $k++) {
10686: my $vpos = $k+1;
10687: my $selstr;
10688: if ($k == $maxnum) {
10689: $selstr = ' selected="selected" ';
10690: }
10691: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10692: }
10693: $datatable .= '</select> '.&mt('Internal ID:').
10694: '<input type="text" size="10" name="addinststatus" value="" />'.
10695: ' '.&mt('(new)').
10696: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10697: &mt('Name displayed').':'.
1.354 raeburn 10698: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10699: '</tr>'."\n";
10700: $rownum ++;
1.294 raeburn 10701: }
1.354 raeburn 10702: }
1.409 raeburn 10703: } else {
10704: my ($unamemaprules,$ruleorder) =
10705: &Apache::lonnet::inst_userrules($dom,'unamemap');
10706: $css_class = $rownum%2?' class="LC_odd_row"':'';
10707: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10708: my $numinrow = 2;
10709: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10710: &user_formats_row('unamemap',$settings,$unamemaprules,
10711: $ruleorder,$numinrow).
10712: '</table></td></tr>';
10713: }
10714: if ($datatable eq '') {
10715: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10716: &mt('No rules set for domain in customized localenroll.pm').
10717: '</td></tr>';
10718: }
1.354 raeburn 10719: }
10720: $$rowtotal += $rownum;
1.43 raeburn 10721: return $datatable;
10722: }
10723:
1.168 raeburn 10724: sub get_languages_hash {
10725: my %langchoices;
10726: foreach my $id (&Apache::loncommon::languageids()) {
10727: my $code = &Apache::loncommon::supportedlanguagecode($id);
10728: if ($code ne '') {
10729: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10730: }
10731: }
10732: return %langchoices;
10733: }
10734:
1.43 raeburn 10735: sub defaults_titles {
1.141 raeburn 10736: my ($dom) = @_;
1.43 raeburn 10737: my %titles = &Apache::lonlocal::texthash (
10738: 'auth_def' => 'Default authentication type',
10739: 'auth_arg_def' => 'Default authentication argument',
10740: 'lang_def' => 'Default language',
1.54 raeburn 10741: 'timezone_def' => 'Default timezone',
1.68 raeburn 10742: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10743: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10744: 'email' => 'Email links use portal URL',
10745: 'web' => 'Public web links use portal URL',
1.294 raeburn 10746: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10747: 'intauth_check' => 'Check bcrypt cost if authenticated',
10748: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10749: );
1.141 raeburn 10750: if ($dom) {
10751: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10752: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10753: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10754: $protocol = 'http' if ($protocol ne 'https');
10755: if ($uint_dom) {
10756: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10757: $uint_dom);
10758: }
10759: }
1.43 raeburn 10760: return (\%titles);
10761: }
10762:
1.346 raeburn 10763: sub print_scantron {
10764: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10765: if ($position eq 'top') {
10766: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10767: } else {
10768: return &print_scantronconfig($dom,$settings,\$rowtotal);
10769: }
10770: }
10771:
10772: sub scantron_javascript {
10773: return <<"ENDSCRIPT";
10774:
10775: <script type="text/javascript">
10776: // <![CDATA[
10777:
10778: function toggleScantron(form) {
1.347 raeburn 10779: var csvfieldset = new Array();
1.346 raeburn 10780: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10781: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10782: }
10783: if (document.getElementById('scantroncsv_options')) {
10784: csvfieldset.push(document.getElementById('scantroncsv_options'));
10785: }
10786: if (csvfieldset.length) {
1.346 raeburn 10787: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10788: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10789: if (scantroncsv.checked) {
1.347 raeburn 10790: for (var i=0; i<csvfieldset.length; i++) {
10791: csvfieldset[i].style.display = 'block';
10792: }
1.346 raeburn 10793: } else {
1.347 raeburn 10794: for (var i=0; i<csvfieldset.length; i++) {
10795: csvfieldset[i].style.display = 'none';
10796: }
1.346 raeburn 10797: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10798: if (csvselects.length) {
10799: for (var j=0; j<csvselects.length; j++) {
10800: csvselects[j].selectedIndex = 0;
10801: }
10802: }
10803: }
10804: }
10805: }
10806: return;
10807: }
10808: // ]]>
10809: </script>
10810:
10811: ENDSCRIPT
10812:
10813: }
10814:
1.46 raeburn 10815: sub print_scantronformat {
10816: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10817: my $itemcount = 1;
1.60 raeburn 10818: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10819: %confhash);
1.46 raeburn 10820: my $switchserver = &check_switchserver($dom,$confname);
10821: my %lt = &Apache::lonlocal::texthash (
1.95 www 10822: default => 'Default bubblesheet format file error',
10823: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10824: );
10825: my %scantronfiles = (
10826: default => 'default.tab',
10827: custom => 'custom.tab',
10828: );
10829: foreach my $key (keys(%scantronfiles)) {
10830: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10831: .$scantronfiles{$key};
10832: }
10833: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10834: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10835: if (!$switchserver) {
10836: my $servadm = $r->dir_config('lonAdmEMail');
10837: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10838: if ($configuserok eq 'ok') {
10839: if ($author_ok eq 'ok') {
10840: my %legacyfile = (
1.346 raeburn 10841: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10842: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10843: );
10844: my %md5chk;
10845: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10846: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10847: chomp($md5chk{$type});
1.46 raeburn 10848: }
10849: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10850: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10851: ($scantronurls{$type},my $error) =
1.46 raeburn 10852: &legacy_scantronformat($r,$dom,$confname,
10853: $type,$legacyfile{$type},
10854: $scantronurls{$type},
10855: $scantronfiles{$type});
1.60 raeburn 10856: if ($error ne '') {
10857: $error{$type} = $error;
10858: }
10859: }
10860: if (keys(%error) == 0) {
10861: $is_custom = 1;
1.346 raeburn 10862: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10863: $scantronurls{'custom'};
1.346 raeburn 10864: my $putresult =
1.60 raeburn 10865: &Apache::lonnet::put_dom('configuration',
10866: \%confhash,$dom);
10867: if ($putresult ne 'ok') {
1.346 raeburn 10868: $error{'custom'} =
1.60 raeburn 10869: '<span class="LC_error">'.
10870: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10871: }
1.46 raeburn 10872: }
10873: } else {
1.60 raeburn 10874: ($scantronurls{'default'},my $error) =
1.46 raeburn 10875: &legacy_scantronformat($r,$dom,$confname,
10876: 'default',$legacyfile{'default'},
10877: $scantronurls{'default'},
10878: $scantronfiles{'default'});
1.60 raeburn 10879: if ($error eq '') {
10880: $confhash{'scantron'}{'scantronformat'} = '';
10881: my $putresult =
10882: &Apache::lonnet::put_dom('configuration',
10883: \%confhash,$dom);
10884: if ($putresult ne 'ok') {
10885: $error{'default'} =
10886: '<span class="LC_error">'.
10887: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10888: }
10889: } else {
10890: $error{'default'} = $error;
10891: }
1.46 raeburn 10892: }
10893: }
10894: }
10895: } else {
1.95 www 10896: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 10897: }
10898: }
10899: if (ref($settings) eq 'HASH') {
10900: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
10901: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
10902: if ((!@info) || ($info[0] eq 'no_such_dir')) {
10903: $scantronurl = '';
10904: } else {
10905: $scantronurl = $settings->{'scantronformat'};
10906: }
10907: $is_custom = 1;
10908: } else {
10909: $scantronurl = $scantronurls{'default'};
10910: }
10911: } else {
1.60 raeburn 10912: if ($is_custom) {
10913: $scantronurl = $scantronurls{'custom'};
10914: } else {
10915: $scantronurl = $scantronurls{'default'};
10916: }
1.46 raeburn 10917: }
10918: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10919: $datatable .= '<tr'.$css_class.'>';
10920: if (!$is_custom) {
1.65 raeburn 10921: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
10922: '<span class="LC_nobreak">';
1.46 raeburn 10923: if ($scantronurl) {
1.199 raeburn 10924: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
10925: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 10926: } else {
10927: $datatable = &mt('File unavailable for display');
10928: }
1.65 raeburn 10929: $datatable .= '</span></td>';
1.60 raeburn 10930: if (keys(%error) == 0) {
1.306 raeburn 10931: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 10932: if (!$switchserver) {
10933: $datatable .= &mt('Upload:').'<br />';
10934: }
10935: } else {
10936: my $errorstr;
10937: foreach my $key (sort(keys(%error))) {
10938: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10939: }
10940: $datatable .= '<td>'.$errorstr;
10941: }
1.46 raeburn 10942: } else {
10943: if (keys(%error) > 0) {
10944: my $errorstr;
10945: foreach my $key (sort(keys(%error))) {
10946: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10947: }
1.60 raeburn 10948: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 10949: } elsif ($scantronurl) {
1.199 raeburn 10950: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
10951: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 10952: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 10953: $link.
10954: '<label><input type="checkbox" name="scantronformat_del"'.
10955: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 10956: '<td><span class="LC_nobreak"> '.
10957: &mt('Replace:').'</span><br />';
1.46 raeburn 10958: }
10959: }
10960: if (keys(%error) == 0) {
10961: if ($switchserver) {
10962: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
10963: } else {
1.65 raeburn 10964: $datatable .='<span class="LC_nobreak"> '.
10965: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 10966: }
10967: }
10968: $datatable .= '</td></tr>';
10969: $$rowtotal ++;
10970: return $datatable;
10971: }
10972:
10973: sub legacy_scantronformat {
10974: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
10975: my ($url,$error);
10976: my @statinfo = &Apache::lonnet::stat_file($newurl);
10977: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 10978: my $modified = [];
1.46 raeburn 10979: (my $result,$url) =
1.421 raeburn 10980: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
10981: 'scantron','','',$newfile,$modified);
10982: if ($result eq 'ok') {
10983: &update_modify_urls($r,$modified);
10984: } else {
1.130 raeburn 10985: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 10986: }
10987: }
10988: return ($url,$error);
10989: }
1.43 raeburn 10990:
1.346 raeburn 10991: sub print_scantronconfig {
10992: my ($dom,$settings,$rowtotal) = @_;
10993: my $itemcount = 2;
10994: my $is_checked = ' checked="checked"';
1.347 raeburn 10995: my %optionson = (
10996: hdr => ' checked="checked"',
10997: pad => ' checked="checked"',
10998: rem => ' checked="checked"',
10999: );
11000: my %optionsoff = (
11001: hdr => '',
11002: pad => '',
11003: rem => '',
11004: );
1.346 raeburn 11005: my $currcsvsty = 'none';
1.347 raeburn 11006: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11007: my @fields = &scantroncsv_fields();
11008: my %titles = &scantronconfig_titles();
11009: if (ref($settings) eq 'HASH') {
11010: if (ref($settings->{config}) eq 'HASH') {
11011: if ($settings->{config}->{dat}) {
11012: $checked{'dat'} = $is_checked;
11013: }
11014: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11015: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11016: %csvfields = %{$settings->{config}->{csv}->{fields}};
11017: if (keys(%csvfields) > 0) {
11018: $checked{'csv'} = $is_checked;
11019: $currcsvsty = 'block';
11020: }
11021: }
11022: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11023: %csvoptions = %{$settings->{config}->{csv}->{options}};
11024: foreach my $option (keys(%optionson)) {
11025: unless ($csvoptions{$option}) {
11026: $optionsoff{$option} = $optionson{$option};
11027: $optionson{$option} = '';
11028: }
11029: }
1.346 raeburn 11030: }
11031: }
11032: } else {
11033: $checked{'dat'} = $is_checked;
11034: }
11035: } else {
11036: $checked{'dat'} = $is_checked;
11037: }
11038: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11039: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11040: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11041: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11042: foreach my $item ('dat','csv') {
11043: my $id;
11044: if ($item eq 'csv') {
11045: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11046: }
1.346 raeburn 11047: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11048: $titles{$item}.'</label>'.(' 'x3);
11049: if ($item eq 'csv') {
11050: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11051: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11052: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11053: foreach my $col (@fields) {
11054: my $selnone;
11055: if ($csvfields{$col} eq '') {
11056: $selnone = ' selected="selected"';
11057: }
11058: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11059: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11060: '<option value=""'.$selnone.'></option>';
11061: for (my $i=0; $i<20; $i++) {
11062: my $shown = $i+1;
11063: my $sel;
11064: unless ($selnone) {
11065: if (exists($csvfields{$col})) {
11066: if ($csvfields{$col} == $i) {
11067: $sel = ' selected="selected"';
11068: }
11069: }
11070: }
11071: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11072: }
11073: $datatable .= '</select></td></tr>';
11074: }
1.347 raeburn 11075: $datatable .= '</table></fieldset>'.
11076: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11077: '<legend>'.&mt('CSV Options').'</legend>';
11078: foreach my $option ('hdr','pad','rem') {
11079: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11080: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11081: &mt('Yes').'</label>'.(' 'x2)."\n".
11082: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11083: }
11084: $datatable .= '</fieldset>';
1.346 raeburn 11085: $itemcount ++;
11086: }
11087: }
11088: $datatable .= '</td></tr>';
11089: $$rowtotal ++;
11090: return $datatable;
11091: }
11092:
11093: sub scantronconfig_titles {
11094: return &Apache::lonlocal::texthash(
11095: dat => 'Standard format (.dat)',
11096: csv => 'Comma separated values (.csv)',
1.347 raeburn 11097: hdr => 'Remove first line in file (contains column titles)',
11098: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11099: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11100: CODE => 'CODE',
11101: ID => 'Student ID',
11102: PaperID => 'Paper ID',
11103: FirstName => 'First Name',
11104: LastName => 'Last Name',
11105: FirstQuestion => 'First Question Response',
11106: Section => 'Section',
11107: );
11108: }
11109:
11110: sub scantroncsv_fields {
11111: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11112: }
11113:
1.49 raeburn 11114: sub print_coursecategories {
1.57 raeburn 11115: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11116: my $datatable;
11117: if ($position eq 'top') {
1.238 raeburn 11118: my (%checked);
11119: my @catitems = ('unauth','auth');
11120: my @cattypes = ('std','domonly','codesrch','none');
11121: $checked{'unauth'} = 'std';
11122: $checked{'auth'} = 'std';
11123: if (ref($settings) eq 'HASH') {
11124: foreach my $type (@cattypes) {
11125: if ($type eq $settings->{'unauth'}) {
11126: $checked{'unauth'} = $type;
11127: }
11128: if ($type eq $settings->{'auth'}) {
11129: $checked{'auth'} = $type;
11130: }
11131: }
11132: }
11133: my %lt = &Apache::lonlocal::texthash (
11134: unauth => 'Catalog type for unauthenticated users',
11135: auth => 'Catalog type for authenticated users',
11136: none => 'No catalog',
11137: std => 'Standard catalog',
11138: domonly => 'Domain-only catalog',
11139: codesrch => "Code search form",
11140: );
11141: my $itemcount = 0;
11142: foreach my $item (@catitems) {
11143: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11144: $datatable .= '<tr '.$css_class.'>'.
11145: '<td>'.$lt{$item}.'</td>'.
11146: '<td class="LC_right_item"><span class="LC_nobreak">';
11147: foreach my $type (@cattypes) {
11148: my $ischecked;
11149: if ($checked{$item} eq $type) {
11150: $ischecked=' checked="checked"';
11151: }
11152: $datatable .= '<label>'.
11153: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11154: ' />'.$lt{$type}.'</label> ';
11155: }
1.327 raeburn 11156: $datatable .= '</span></td></tr>';
1.238 raeburn 11157: $itemcount ++;
11158: }
11159: $$rowtotal += $itemcount;
11160: } elsif ($position eq 'middle') {
1.57 raeburn 11161: my $toggle_cats_crs = ' ';
11162: my $toggle_cats_dom = ' checked="checked" ';
11163: my $can_cat_crs = ' ';
11164: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11165: my $toggle_catscomm_comm = ' ';
11166: my $toggle_catscomm_dom = ' checked="checked" ';
11167: my $can_catcomm_comm = ' ';
11168: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11169: my $toggle_catsplace_place = ' ';
11170: my $toggle_catsplace_dom = ' checked="checked" ';
11171: my $can_catplace_place = ' ';
11172: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11173:
1.57 raeburn 11174: if (ref($settings) eq 'HASH') {
11175: if ($settings->{'togglecats'} eq 'crs') {
11176: $toggle_cats_crs = $toggle_cats_dom;
11177: $toggle_cats_dom = ' ';
11178: }
11179: if ($settings->{'categorize'} eq 'crs') {
11180: $can_cat_crs = $can_cat_dom;
11181: $can_cat_dom = ' ';
11182: }
1.120 raeburn 11183: if ($settings->{'togglecatscomm'} eq 'comm') {
11184: $toggle_catscomm_comm = $toggle_catscomm_dom;
11185: $toggle_catscomm_dom = ' ';
11186: }
11187: if ($settings->{'categorizecomm'} eq 'comm') {
11188: $can_catcomm_comm = $can_catcomm_dom;
11189: $can_catcomm_dom = ' ';
11190: }
1.272 raeburn 11191: if ($settings->{'togglecatsplace'} eq 'place') {
11192: $toggle_catsplace_place = $toggle_catsplace_dom;
11193: $toggle_catsplace_dom = ' ';
11194: }
11195: if ($settings->{'categorizeplace'} eq 'place') {
11196: $can_catplace_place = $can_catplace_dom;
11197: $can_catplace_dom = ' ';
11198: }
1.57 raeburn 11199: }
11200: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11201: togglecats => 'Show/Hide a course in catalog',
11202: togglecatscomm => 'Show/Hide a community in catalog',
11203: togglecatsplace => 'Show/Hide a placement test in catalog',
11204: categorize => 'Assign a category to a course',
11205: categorizecomm => 'Assign a category to a community',
11206: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11207: );
11208: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11209: dom => 'Set in Domain',
11210: crs => 'Set in Course',
11211: comm => 'Set in Community',
11212: place => 'Set in Placement Test',
1.57 raeburn 11213: );
11214: $datatable = '<tr class="LC_odd_row">'.
11215: '<td>'.$title{'togglecats'}.'</td>'.
11216: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11217: '<input type="radio" name="togglecats"'.
11218: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11219: '<label><input type="radio" name="togglecats"'.
11220: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11221: '</tr><tr>'.
11222: '<td>'.$title{'categorize'}.'</td>'.
11223: '<td class="LC_right_item"><span class="LC_nobreak">'.
11224: '<label><input type="radio" name="categorize"'.
11225: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11226: '<label><input type="radio" name="categorize"'.
11227: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11228: '</tr><tr class="LC_odd_row">'.
11229: '<td>'.$title{'togglecatscomm'}.'</td>'.
11230: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11231: '<input type="radio" name="togglecatscomm"'.
11232: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11233: '<label><input type="radio" name="togglecatscomm"'.
11234: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11235: '</tr><tr>'.
11236: '<td>'.$title{'categorizecomm'}.'</td>'.
11237: '<td class="LC_right_item"><span class="LC_nobreak">'.
11238: '<label><input type="radio" name="categorizecomm"'.
11239: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11240: '<label><input type="radio" name="categorizecomm"'.
11241: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11242: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11243: '<td>'.$title{'togglecatsplace'}.'</td>'.
11244: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11245: '<input type="radio" name="togglecatsplace"'.
11246: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11247: '<label><input type="radio" name="togglecatscomm"'.
11248: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11249: '</tr><tr>'.
11250: '<td>'.$title{'categorizeplace'}.'</td>'.
11251: '<td class="LC_right_item"><span class="LC_nobreak">'.
11252: '<label><input type="radio" name="categorizeplace"'.
11253: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11254: '<label><input type="radio" name="categorizeplace"'.
11255: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11256: '</tr>';
1.272 raeburn 11257: $$rowtotal += 6;
1.57 raeburn 11258: } else {
11259: my $css_class;
11260: my $itemcount = 1;
11261: my $cathash;
11262: if (ref($settings) eq 'HASH') {
11263: $cathash = $settings->{'cats'};
11264: }
11265: if (ref($cathash) eq 'HASH') {
11266: my (@cats,@trails,%allitems,%idx,@jsarray);
11267: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11268: \%allitems,\%idx,\@jsarray);
11269: my $maxdepth = scalar(@cats);
11270: my $colattrib = '';
11271: if ($maxdepth > 2) {
11272: $colattrib = ' colspan="2" ';
11273: }
11274: my @path;
11275: if (@cats > 0) {
11276: if (ref($cats[0]) eq 'ARRAY') {
11277: my $numtop = @{$cats[0]};
11278: my $maxnum = $numtop;
1.120 raeburn 11279: my %default_names = (
11280: instcode => &mt('Official courses'),
11281: communities => &mt('Communities'),
1.272 raeburn 11282: placement => &mt('Placement Tests'),
1.120 raeburn 11283: );
11284:
11285: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11286: ($cathash->{'instcode::0'} eq '') ||
11287: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11288: ($cathash->{'communities::0'} eq '') ||
11289: (!grep(/^placement$/,@{$cats[0]})) ||
11290: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11291: $maxnum ++;
11292: }
11293: my $lastidx;
11294: for (my $i=0; $i<$numtop; $i++) {
11295: my $parent = $cats[0][$i];
11296: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11297: my $item = &escape($parent).'::0';
11298: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11299: $lastidx = $idx{$item};
11300: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11301: .'<select name="'.$item.'"'.$chgstr.'>';
11302: for (my $k=0; $k<=$maxnum; $k++) {
11303: my $vpos = $k+1;
11304: my $selstr;
11305: if ($k == $i) {
11306: $selstr = ' selected="selected" ';
11307: }
11308: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11309: }
1.214 raeburn 11310: $datatable .= '</select></span></td><td>';
1.272 raeburn 11311: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11312: $datatable .= '<span class="LC_nobreak">'
11313: .$default_names{$parent}.'</span>';
11314: if ($parent eq 'instcode') {
11315: $datatable .= '<br /><span class="LC_nobreak">('
11316: .&mt('with institutional codes')
11317: .')</span></td><td'.$colattrib.'>';
11318: } else {
11319: $datatable .= '<table><tr><td>';
11320: }
11321: $datatable .= '<span class="LC_nobreak">'
11322: .'<label><input type="radio" name="'
11323: .$parent.'" value="1" checked="checked" />'
11324: .&mt('Display').'</label>';
11325: if ($parent eq 'instcode') {
11326: $datatable .= ' ';
11327: } else {
11328: $datatable .= '</span></td></tr><tr><td>'
11329: .'<span class="LC_nobreak">';
11330: }
11331: $datatable .= '<label><input type="radio" name="'
11332: .$parent.'" value="0" />'
11333: .&mt('Do not display').'</label></span>';
1.272 raeburn 11334: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11335: $datatable .= '</td></tr></table>';
11336: }
11337: $datatable .= '</td>';
1.57 raeburn 11338: } else {
11339: $datatable .= $parent
1.214 raeburn 11340: .' <span class="LC_nobreak"><label>'
11341: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11342: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11343: }
11344: my $depth = 1;
11345: push(@path,$parent);
11346: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11347: pop(@path);
11348: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11349: $itemcount ++;
11350: }
1.48 raeburn 11351: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11352: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11353: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11354: for (my $k=0; $k<=$maxnum; $k++) {
11355: my $vpos = $k+1;
11356: my $selstr;
1.57 raeburn 11357: if ($k == $numtop) {
1.48 raeburn 11358: $selstr = ' selected="selected" ';
11359: }
11360: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11361: }
1.59 bisitz 11362: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11363: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11364: .'</tr>'."\n";
1.48 raeburn 11365: $itemcount ++;
1.272 raeburn 11366: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11367: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11368: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11369: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11370: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11371: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11372: for (my $k=0; $k<=$maxnum; $k++) {
11373: my $vpos = $k+1;
11374: my $selstr;
11375: if ($k == $maxnum) {
11376: $selstr = ' selected="selected" ';
11377: }
11378: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11379: }
1.120 raeburn 11380: $datatable .= '</select></span></td>'.
11381: '<td><span class="LC_nobreak">'.
11382: $default_names{$default}.'</span>';
11383: if ($default eq 'instcode') {
11384: $datatable .= '<br /><span class="LC_nobreak">('
11385: .&mt('with institutional codes').')</span>';
11386: }
11387: $datatable .= '</td>'
11388: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11389: .&mt('Display').'</label> '
11390: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11391: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11392: }
11393: }
11394: }
1.57 raeburn 11395: } else {
11396: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11397: }
11398: } else {
1.327 raeburn 11399: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11400: .&initialize_categories($itemcount);
1.48 raeburn 11401: }
1.57 raeburn 11402: $$rowtotal += $itemcount;
1.48 raeburn 11403: }
11404: return $datatable;
11405: }
11406:
1.69 raeburn 11407: sub print_serverstatuses {
11408: my ($dom,$settings,$rowtotal) = @_;
11409: my $datatable;
11410: my @pages = &serverstatus_pages();
11411: my (%namedaccess,%machineaccess);
11412: foreach my $type (@pages) {
11413: $namedaccess{$type} = '';
11414: $machineaccess{$type}= '';
11415: }
11416: if (ref($settings) eq 'HASH') {
11417: foreach my $type (@pages) {
11418: if (exists($settings->{$type})) {
11419: if (ref($settings->{$type}) eq 'HASH') {
11420: foreach my $key (keys(%{$settings->{$type}})) {
11421: if ($key eq 'namedusers') {
11422: $namedaccess{$type} = $settings->{$type}->{$key};
11423: } elsif ($key eq 'machines') {
11424: $machineaccess{$type} = $settings->{$type}->{$key};
11425: }
11426: }
11427: }
11428: }
11429: }
11430: }
1.81 raeburn 11431: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11432: my $rownum = 0;
11433: my $css_class;
11434: foreach my $type (@pages) {
11435: $rownum ++;
11436: $css_class = $rownum%2?' class="LC_odd_row"':'';
11437: $datatable .= '<tr'.$css_class.'>'.
11438: '<td><span class="LC_nobreak">'.
11439: $titles->{$type}.'</span></td>'.
11440: '<td class="LC_left_item">'.
11441: '<input type="text" name="'.$type.'_namedusers" '.
11442: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11443: '<td class="LC_right_item">'.
11444: '<span class="LC_nobreak">'.
11445: '<input type="text" name="'.$type.'_machines" '.
11446: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11447: '</span></td></tr>'."\n";
1.69 raeburn 11448: }
11449: $$rowtotal += $rownum;
11450: return $datatable;
11451: }
11452:
11453: sub serverstatus_pages {
11454: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11455: 'checksums','clusterstatus','certstatus','metadata_keywords',
11456: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11457: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11458: }
11459:
1.236 raeburn 11460: sub defaults_javascript {
11461: my ($settings) = @_;
1.354 raeburn 11462: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11463: my $portal_js = <<"ENDPORTAL";
11464:
11465: function portalExtras(caller) {
11466: var x = caller.value;
11467: var y = new Array('email','web');
1.425 raeburn 11468: for (var i=0; i<y.length; i++) {
1.414 raeburn 11469: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11470: var z = document.getElementById('portal_def_'+y[i]+'_div');
11471: if (x.length > 0) {
11472: z.style.display = 'block';
11473: } else {
11474: z.style.display = 'none';
11475: }
11476: }
11477: }
11478: }
11479: ENDPORTAL
1.236 raeburn 11480: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11481: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11482: if ($maxnum eq '') {
11483: $maxnum = 0;
11484: }
11485: $maxnum ++;
1.249 raeburn 11486: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11487: return <<"ENDSCRIPT";
11488: <script type="text/javascript">
11489: // <![CDATA[
11490: function reorderTypes(form,caller) {
11491: var changedVal;
11492: $jstext
11493: var newpos = 'addinststatus_pos';
11494: var current = new Array;
11495: var maxh = $maxnum;
11496: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11497: var oldVal;
11498: if (caller == newpos) {
11499: changedVal = newitemVal;
11500: } else {
11501: var curritem = 'inststatus_pos_'+caller;
11502: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11503: current[newitemVal] = newpos;
11504: }
11505: for (var i=0; i<inststatuses.length; i++) {
11506: if (inststatuses[i] != caller) {
11507: var elementName = 'inststatus_pos_'+inststatuses[i];
11508: if (form.elements[elementName]) {
11509: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11510: current[currVal] = elementName;
11511: }
11512: }
11513: }
11514: for (var j=0; j<maxh; j++) {
11515: if (current[j] == undefined) {
11516: oldVal = j;
11517: }
11518: }
11519: if (oldVal < changedVal) {
11520: for (var k=oldVal+1; k<=changedVal ; k++) {
11521: var elementName = current[k];
11522: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11523: }
11524: } else {
11525: for (var k=changedVal; k<oldVal; k++) {
11526: var elementName = current[k];
11527: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11528: }
11529: }
11530: return;
11531: }
11532:
1.414 raeburn 11533: $portal_js
11534:
11535: // ]]>
11536: </script>
11537:
11538: ENDSCRIPT
11539: } else {
11540: return <<"ENDSCRIPT";
11541: <script type="text/javascript">
11542: // <![CDATA[
11543: $portal_js
1.236 raeburn 11544: // ]]>
11545: </script>
11546:
11547: ENDSCRIPT
11548: }
1.354 raeburn 11549: return;
11550: }
11551:
11552: sub passwords_javascript {
1.405 raeburn 11553: my ($prefix) = @_;
11554: my %intalert;
11555: if ($prefix eq 'passwords') {
11556: %intalert = &Apache::lonlocal::texthash (
11557: 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.',
11558: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11559: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11560: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11561: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11562: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11563: );
1.421 raeburn 11564: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11565: %intalert = &Apache::lonlocal::texthash (
11566: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11567: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11568: );
11569: }
1.365 raeburn 11570: &js_escape(\%intalert);
11571: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11572: my $intauthjs;
1.405 raeburn 11573: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11574:
11575: function warnIntAuth(field) {
11576: if (field.name == 'intauth_check') {
11577: if (field.value == '2') {
1.365 raeburn 11578: alert('$intalert{authcheck}');
1.354 raeburn 11579: }
11580: }
11581: if (field.name == 'intauth_cost') {
11582: field.value.replace(/\s/g,'');
11583: if (field.value != '') {
11584: var regexdigit=/^\\d+\$/;
11585: if (!regexdigit.test(field.value)) {
1.365 raeburn 11586: alert('$intalert{authcost}');
11587: }
11588: }
11589: }
11590: return;
11591: }
11592:
1.405 raeburn 11593: ENDSCRIPT
11594:
11595: }
11596:
11597: $intauthjs .= <<"ENDSCRIPT";
11598:
11599: function warnInt$prefix(field) {
1.365 raeburn 11600: field.value.replace(/^\s+/,'');
11601: field.value.replace(/\s+\$/,'');
11602: var regexdigit=/^\\d+\$/;
1.408 raeburn 11603: if (field.name == '${prefix}_min') {
1.365 raeburn 11604: if (field.value == '') {
11605: alert('$intalert{passmin}');
11606: field.value = '$defmin';
11607: } else {
11608: if (!regexdigit.test(field.value)) {
11609: alert('$intalert{passmin}');
11610: field.value = '$defmin';
11611: }
1.366 raeburn 11612: var minval = parseInt(field.value,10);
1.365 raeburn 11613: if (minval < $defmin) {
11614: alert('$intalert{passmin}');
11615: field.value = '$defmin';
11616: }
11617: }
11618: } else {
11619: if (field.value == '0') {
11620: field.value = '';
11621: }
11622: if (field.value != '') {
1.408 raeburn 11623: if (field.name == '${prefix}_expire') {
1.365 raeburn 11624: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11625: if (!regexpposnum.test(field.value)) {
11626: alert('$intalert{passexp}');
11627: field.value = '';
11628: } else {
11629: var expval = parseFloat(field.value);
11630: if (expval == 0) {
11631: alert('$intalert{passexp}');
11632: field.value = '';
11633: }
11634: }
11635: } else {
11636: if (!regexdigit.test(field.value)) {
1.408 raeburn 11637: if (field.name == '${prefix}_max') {
1.365 raeburn 11638: alert('$intalert{passmax}');
11639: } else {
1.408 raeburn 11640: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11641: alert('$intalert{passnum}');
11642: }
11643: }
1.370 raeburn 11644: field.value = '';
1.365 raeburn 11645: }
1.354 raeburn 11646: }
11647: }
11648: }
11649: return;
11650: }
11651:
11652: ENDSCRIPT
11653: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11654: }
11655:
1.49 raeburn 11656: sub coursecategories_javascript {
11657: my ($settings) = @_;
1.57 raeburn 11658: my ($output,$jstext,$cathash);
1.49 raeburn 11659: if (ref($settings) eq 'HASH') {
1.57 raeburn 11660: $cathash = $settings->{'cats'};
11661: }
11662: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11663: my (@cats,@jsarray,%idx);
1.57 raeburn 11664: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11665: if (@jsarray > 0) {
11666: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11667: for (my $i=0; $i<@jsarray; $i++) {
11668: if (ref($jsarray[$i]) eq 'ARRAY') {
11669: my $catstr = join('","',@{$jsarray[$i]});
11670: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11671: }
11672: }
11673: }
11674: } else {
11675: $jstext = ' var categories = Array(1);'."\n".
11676: ' categories[0] = Array("instcode_pos");'."\n";
11677: }
1.237 bisitz 11678: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11679: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11680: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11681: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11682: &js_escape(\$instcode_reserved);
11683: &js_escape(\$communities_reserved);
1.272 raeburn 11684: &js_escape(\$placement_reserved);
1.265 damieng 11685: &js_escape(\$choose_again);
1.49 raeburn 11686: $output = <<"ENDSCRIPT";
11687: <script type="text/javascript">
1.109 raeburn 11688: // <![CDATA[
1.49 raeburn 11689: function reorderCats(form,parent,item,idx) {
11690: var changedVal;
11691: $jstext
11692: var newpos = 'addcategory_pos';
11693: if (parent == '') {
11694: var has_instcode = 0;
11695: var maxtop = categories[idx].length;
11696: for (var j=0; j<maxtop; j++) {
11697: if (categories[idx][j] == 'instcode::0') {
11698: has_instcode == 1;
11699: }
11700: }
11701: if (has_instcode == 0) {
11702: categories[idx][maxtop] = 'instcode_pos';
11703: }
11704: } else {
11705: newpos += '_'+parent;
11706: }
11707: var maxh = 1 + categories[idx].length;
11708: var current = new Array;
11709: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11710: if (item == newpos) {
11711: changedVal = newitemVal;
11712: } else {
11713: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11714: current[newitemVal] = newpos;
11715: }
11716: for (var i=0; i<categories[idx].length; i++) {
11717: var elementName = categories[idx][i];
11718: if (elementName != item) {
11719: if (form.elements[elementName]) {
11720: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11721: current[currVal] = elementName;
11722: }
11723: }
11724: }
11725: var oldVal;
11726: for (var j=0; j<maxh; j++) {
11727: if (current[j] == undefined) {
11728: oldVal = j;
11729: }
11730: }
11731: if (oldVal < changedVal) {
11732: for (var k=oldVal+1; k<=changedVal ; k++) {
11733: var elementName = current[k];
11734: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11735: }
11736: } else {
11737: for (var k=changedVal; k<oldVal; k++) {
11738: var elementName = current[k];
11739: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11740: }
11741: }
11742: return;
11743: }
1.120 raeburn 11744:
11745: function categoryCheck(form) {
11746: if (form.elements['addcategory_name'].value == 'instcode') {
11747: alert('$instcode_reserved\\n$choose_again');
11748: return false;
11749: }
11750: if (form.elements['addcategory_name'].value == 'communities') {
11751: alert('$communities_reserved\\n$choose_again');
11752: return false;
11753: }
1.272 raeburn 11754: if (form.elements['addcategory_name'].value == 'placement') {
11755: alert('$placement_reserved\\n$choose_again');
11756: return false;
11757: }
1.120 raeburn 11758: return true;
11759: }
11760:
1.109 raeburn 11761: // ]]>
1.49 raeburn 11762: </script>
11763:
11764: ENDSCRIPT
11765: return $output;
11766: }
11767:
1.48 raeburn 11768: sub initialize_categories {
11769: my ($itemcount) = @_;
1.120 raeburn 11770: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11771: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11772: instcode => 'Official courses (with institutional codes)',
11773: communities => 'Communities',
1.272 raeburn 11774: placement => 'Placement Tests',
1.120 raeburn 11775: );
1.328 raeburn 11776: my %selnum = (
11777: instcode => '0',
11778: communities => '1',
11779: placement => '2',
11780: );
11781: my %selected;
1.272 raeburn 11782: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11783: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11784: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11785: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11786: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11787: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11788: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11789: .'<option value="0"'.$selected{'0'}.'>1</option>'
11790: .'<option value="1"'.$selected{'1'}.'>2</option>'
11791: .'<option value="2"'.$selected{'2'}.'>3</option>'
11792: .'<option value="3">4</option></select> '
1.120 raeburn 11793: .$default_names{$default}
11794: .'</span></td><td><span class="LC_nobreak">'
11795: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11796: .&mt('Display').'</label> <label>'
11797: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11798: .'</label></span></td></tr>';
1.120 raeburn 11799: $itemcount ++;
11800: }
1.48 raeburn 11801: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11802: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11803: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11804: .'<select name="addcategory_pos"'.$chgstr.'>'
11805: .'<option value="0">1</option>'
11806: .'<option value="1">2</option>'
1.328 raeburn 11807: .'<option value="2">3</option>'
11808: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11809: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11810: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11811: .'</td></tr>';
1.48 raeburn 11812: return $datatable;
11813: }
11814:
11815: sub build_category_rows {
1.49 raeburn 11816: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11817: my ($text,$name,$item,$chgstr);
1.48 raeburn 11818: if (ref($cats) eq 'ARRAY') {
11819: my $maxdepth = scalar(@{$cats});
11820: if (ref($cats->[$depth]) eq 'HASH') {
11821: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11822: my $numchildren = @{$cats->[$depth]{$parent}};
11823: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11824: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11825: my ($idxnum,$parent_name,$parent_item);
11826: my $higher = $depth - 1;
11827: if ($higher == 0) {
11828: $parent_name = &escape($parent).'::'.$higher;
11829: } else {
11830: if (ref($path) eq 'ARRAY') {
11831: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11832: }
11833: }
11834: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11835: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11836: if ($j < $numchildren) {
1.48 raeburn 11837: $name = $cats->[$depth]{$parent}[$j];
11838: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11839: $idxnum = $idx->{$item};
11840: } else {
11841: $name = $parent_name;
11842: $item = $parent_item;
1.48 raeburn 11843: }
1.49 raeburn 11844: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11845: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11846: for (my $i=0; $i<=$numchildren; $i++) {
11847: my $vpos = $i+1;
11848: my $selstr;
11849: if ($j == $i) {
11850: $selstr = ' selected="selected" ';
11851: }
11852: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11853: }
11854: $text .= '</select> ';
11855: if ($j < $numchildren) {
11856: my $deeper = $depth+1;
11857: $text .= $name.' '
11858: .'<label><input type="checkbox" name="deletecategory" value="'
11859: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11860: if(ref($path) eq 'ARRAY') {
11861: push(@{$path},$name);
1.49 raeburn 11862: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11863: pop(@{$path});
11864: }
11865: } else {
1.330 raeburn 11866: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11867: if ($j == $numchildren) {
11868: $text .= $name;
11869: } else {
11870: $text .= $item;
11871: }
11872: $text .= '" value="" />';
11873: }
11874: $text .= '</td></tr>';
11875: }
11876: $text .= '</table></td>';
11877: } else {
11878: my $higher = $depth-1;
11879: if ($higher == 0) {
11880: $name = &escape($parent).'::'.$higher;
11881: } else {
11882: if (ref($path) eq 'ARRAY') {
11883: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11884: }
11885: }
11886: my $colspan;
11887: if ($parent ne 'instcode') {
11888: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11889: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11890: }
11891: }
11892: }
11893: }
11894: return $text;
11895: }
11896:
1.33 raeburn 11897: sub modifiable_userdata_row {
1.305 raeburn 11898: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 11899: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 11900: my ($role,$rolename,$statustype);
11901: $role = $item;
1.224 raeburn 11902: if ($context eq 'cancreate') {
1.305 raeburn 11903: if ($item =~ /^(emailusername)_(.+)$/) {
11904: $role = $1;
11905: $statustype = $2;
1.228 raeburn 11906: if (ref($usertypes) eq 'HASH') {
11907: if ($usertypes->{$statustype}) {
11908: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
11909: } else {
11910: $rolename = &mt('Data provided by user');
11911: }
11912: }
1.224 raeburn 11913: }
11914: } elsif ($context eq 'selfcreate') {
1.63 raeburn 11915: if (ref($usertypes) eq 'HASH') {
11916: $rolename = $usertypes->{$role};
11917: } else {
11918: $rolename = $role;
11919: }
1.325 raeburn 11920: } elsif ($context eq 'lti') {
11921: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 11922: } elsif ($context eq 'privacy') {
11923: $rolename = $itemdesc;
1.33 raeburn 11924: } else {
1.63 raeburn 11925: if ($role eq 'cr') {
11926: $rolename = &mt('Custom role');
11927: } else {
11928: $rolename = &Apache::lonnet::plaintext($role);
11929: }
1.33 raeburn 11930: }
1.224 raeburn 11931: my (@fields,%fieldtitles);
11932: if (ref($fieldsref) eq 'ARRAY') {
11933: @fields = @{$fieldsref};
11934: } else {
11935: @fields = ('lastname','firstname','middlename','generation',
11936: 'permanentemail','id');
11937: }
11938: if ((ref($titlesref) eq 'HASH')) {
11939: %fieldtitles = %{$titlesref};
11940: } else {
11941: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11942: }
1.33 raeburn 11943: my $output;
1.305 raeburn 11944: my $css_class;
11945: if ($rowcount%2) {
11946: $css_class = 'LC_odd_row';
11947: }
11948: if ($customcss) {
11949: $css_class .= " $customcss";
11950: }
11951: $css_class =~ s/^\s+//;
11952: if ($css_class) {
11953: $css_class = ' class="'.$css_class.'"';
11954: }
11955: if ($rowstyle) {
11956: $css_class .= ' style="'.$rowstyle.'"';
11957: }
11958: if ($rowid) {
11959: $rowid = ' id="'.$rowid.'"';
11960: }
11961: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 11962: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
11963: '<td class="LC_left_item" colspan="2"><table>';
11964: my $rem;
11965: my %checks;
11966: if (ref($settings) eq 'HASH') {
1.325 raeburn 11967: my $hashref;
11968: if ($context eq 'lti') {
11969: if (ref($settings) eq 'HASH') {
11970: $hashref = $settings->{'instdata'};
11971: }
1.357 raeburn 11972: } elsif ($context eq 'privacy') {
11973: my ($key,$inner) = split(/_/,$role);
11974: if (ref($settings) eq 'HASH') {
11975: if (ref($settings->{$key}) eq 'HASH') {
11976: $hashref = $settings->{$key}->{$inner};
11977: }
11978: }
1.325 raeburn 11979: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 11980: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 11981: $hashref = $settings->{'lti_instdata'};
11982: }
11983: if ($role eq 'emailusername') {
11984: if ($statustype) {
11985: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
11986: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 11987: }
1.325 raeburn 11988: }
11989: }
11990: }
1.425 raeburn 11991: if (ref($hashref) eq 'HASH') {
1.325 raeburn 11992: foreach my $field (@fields) {
11993: if ($hashref->{$field}) {
11994: if ($role eq 'emailusername') {
11995: $checks{$field} = $hashref->{$field};
11996: } else {
11997: $checks{$field} = ' checked="checked" ';
1.33 raeburn 11998: }
11999: }
12000: }
12001: }
12002: }
1.305 raeburn 12003: my $total = scalar(@fields);
12004: for (my $i=0; $i<$total; $i++) {
12005: $rem = $i%($numinrow);
1.33 raeburn 12006: if ($rem == 0) {
12007: if ($i > 0) {
12008: $output .= '</tr>';
12009: }
12010: $output .= '<tr>';
12011: }
12012: my $check = ' ';
1.228 raeburn 12013: unless ($role eq 'emailusername') {
12014: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12015: $check = $checks{$fields[$i]};
1.357 raeburn 12016: } elsif ($context eq 'privacy') {
12017: if ($role =~ /^priv_(domain|course)$/) {
12018: if (ref($settings) ne 'HASH') {
12019: $check = ' checked="checked" ';
12020: }
12021: } elsif ($role =~ /^priv_(author|community)$/) {
12022: if (ref($settings) ne 'HASH') {
12023: unless ($fields[$i] eq 'id') {
12024: $check = ' checked="checked" ';
12025: }
12026: }
12027: } elsif ($role =~ /^(unpriv|othdom)_/) {
12028: if (ref($settings) ne 'HASH') {
12029: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12030: $check = ' checked="checked" ';
12031: }
12032: }
12033: }
1.325 raeburn 12034: } elsif ($context ne 'lti') {
1.228 raeburn 12035: if ($role eq 'st') {
12036: if (ref($settings) ne 'HASH') {
12037: $check = ' checked="checked" ';
12038: }
1.33 raeburn 12039: }
12040: }
12041: }
12042: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12043: '<span class="LC_nobreak">';
1.325 raeburn 12044: my $prefix = 'canmodify';
1.228 raeburn 12045: if ($role eq 'emailusername') {
12046: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12047: $checks{$fields[$i]} = 'omit';
12048: }
12049: foreach my $option ('required','optional','omit') {
12050: my $checked='';
12051: if ($checks{$fields[$i]} eq $option) {
12052: $checked='checked="checked" ';
12053: }
12054: $output .= '<label>'.
1.325 raeburn 12055: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12056: &mt($option).'</label>'.(' ' x2);
12057: }
12058: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12059: } else {
1.325 raeburn 12060: if ($context eq 'lti') {
12061: $prefix = 'lti';
1.357 raeburn 12062: } elsif ($context eq 'privacy') {
12063: $prefix = 'privacy';
1.325 raeburn 12064: }
1.228 raeburn 12065: $output .= '<label>'.
1.325 raeburn 12066: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12067: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12068: '</label>';
12069: }
12070: $output .= '</span></td>';
1.33 raeburn 12071: }
1.305 raeburn 12072: $rem = $total%$numinrow;
12073: my $colsleft;
12074: if ($rem) {
12075: $colsleft = $numinrow - $rem;
12076: }
12077: if ($colsleft > 1) {
1.33 raeburn 12078: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12079: ' </td>';
12080: } elsif ($colsleft == 1) {
12081: $output .= '<td class="LC_left_item"> </td>';
12082: }
12083: $output .= '</tr></table></td></tr>';
12084: return $output;
12085: }
1.28 raeburn 12086:
1.93 raeburn 12087: sub insttypes_row {
1.305 raeburn 12088: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12089: $customcss,$rowstyle) = @_;
1.93 raeburn 12090: my %lt = &Apache::lonlocal::texthash (
1.429 ! raeburn 12091: cansearch => 'Users allowed to search',
1.93 raeburn 12092: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 ! raeburn 12093: lockablenames => 'User preference to lock name',
! 12094: selfassign => 'Self-reportable affiliations',
! 12095: overrides => "Override domain's helpdesk settings based on requester's affiliation",
! 12096: webdav => 'WebDAV access available',
! 12097: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12098: );
1.429 ! raeburn 12099: my ($showdom,$defaultquota);
1.93 raeburn 12100: if ($context eq 'cansearch') {
12101: $showdom = ' ('.$dom.')';
1.429 ! raeburn 12102: } elsif ($context eq 'authorquota') {
! 12103: $defaultquota = 500;
1.93 raeburn 12104: }
1.165 raeburn 12105: my $class = 'LC_left_item';
12106: if ($context eq 'statustocreate') {
12107: $class = 'LC_right_item';
12108: }
1.305 raeburn 12109: my $css_class;
12110: if ($$rowtotal%2) {
12111: $css_class = 'LC_odd_row';
12112: }
12113: if ($customcss) {
12114: $css_class .= ' '.$customcss;
12115: }
12116: $css_class =~ s/^\s+//;
12117: if ($css_class) {
12118: $css_class = ' class="'.$css_class.'"';
12119: }
12120: if ($rowstyle) {
12121: $css_class .= ' style="'.$rowstyle.'"';
12122: }
12123: if ($onclick) {
12124: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12125: }
12126: my $output = '<tr'.$css_class.'>'.
12127: '<td>'.$lt{$context}.$showdom.
12128: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12129: my $rem;
12130: if (ref($types) eq 'ARRAY') {
12131: for (my $i=0; $i<@{$types}; $i++) {
12132: if (defined($usertypes->{$types->[$i]})) {
12133: my $rem = $i%($numinrow);
12134: if ($rem == 0) {
12135: if ($i > 0) {
12136: $output .= '</tr>';
12137: }
12138: $output .= '<tr>';
1.23 raeburn 12139: }
1.429 ! raeburn 12140: if ($context eq 'authorquota') {
! 12141: my $currquota;
! 12142: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
! 12143: $currquota = $settings->{$context}->{$types->[$i]};
! 12144: } else {
! 12145: $currquota = $defaultquota;
! 12146: }
! 12147: $output .= '<td class="LC_left_item">'."\n".
! 12148: '<label><span class="LC_nobreak">'."\n".
! 12149: $usertypes->{$types->[$i]}.'</span><br />'."\n".
! 12150: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
! 12151: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
! 12152: '</label></td>';
! 12153: } else {
! 12154: my $check = ' ';
! 12155: if (ref($settings) eq 'HASH') {
! 12156: if (ref($settings->{$context}) eq 'ARRAY') {
! 12157: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
! 12158: $check = ' checked="checked" ';
! 12159: }
! 12160: } elsif (ref($settings->{$context}) eq 'HASH') {
! 12161: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
! 12162: $check = ' checked="checked" ';
! 12163: } elsif ($context eq 'webdav') {
! 12164: if ($settings->{$context}->{$types->[$i]}) {
! 12165: $check = ' checked="checked" ';
! 12166: }
! 12167: }
! 12168: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12169: $check = ' checked="checked" ';
12170: }
1.26 raeburn 12171: }
1.429 ! raeburn 12172: $output .= '<td class="LC_left_item">'.
! 12173: '<span class="LC_nobreak"><label>'.
! 12174: '<input type="checkbox" name="'.$context.'" '.
! 12175: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
! 12176: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12177: }
12178: }
12179: }
1.26 raeburn 12180: $rem = @{$types}%($numinrow);
1.23 raeburn 12181: }
12182: my $colsleft = $numinrow - $rem;
1.315 raeburn 12183: if ($context eq 'overrides') {
12184: if ($colsleft > 1) {
12185: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12186: } else {
12187: $output .= '<td class="LC_left_item">';
12188: }
1.425 raeburn 12189: $output .= ' ';
1.23 raeburn 12190: } else {
1.334 raeburn 12191: if ($rem == 0) {
1.315 raeburn 12192: $output .= '<tr>';
12193: }
12194: if ($colsleft > 1) {
12195: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12196: } else {
12197: $output .= '<td class="LC_left_item">';
12198: }
1.429 ! raeburn 12199: if ($context eq 'authorquota') {
! 12200: my $currquota = 500;
! 12201: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
! 12202: if ($settings->{$context}{'default'} =~ /^\d+$/) {
! 12203: $currquota = $settings->{$context}{'default'};
! 12204: }
! 12205: }
! 12206: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
! 12207: '<input type="text" name="'.$context.'_default" '.
! 12208: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
! 12209: '</label>';
! 12210: } else {
! 12211: my $defcheck = ' ';
! 12212: if (ref($settings) eq 'HASH') {
! 12213: if (ref($settings->{$context}) eq 'ARRAY') {
! 12214: if (grep(/^default$/,@{$settings->{$context}})) {
! 12215: $defcheck = ' checked="checked" ';
! 12216: }
! 12217: } elsif (ref($settings->{$context}) eq 'HASH') {
! 12218: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
! 12219: $defcheck = ' checked="checked" ';
! 12220: } elsif ($context eq 'webdav') {
! 12221: if ($settings->{$context}->{'default'}) {
! 12222: $defcheck = ' checked="checked" ';
! 12223: }
! 12224: }
! 12225: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12226: $defcheck = ' checked="checked" ';
12227: }
1.99 raeburn 12228: }
1.429 ! raeburn 12229: $output .= '<span class="LC_nobreak"><label>'.
! 12230: '<input type="checkbox" name="'.$context.'" '.
! 12231: 'value="default"'.$defcheck.$onclick.'/>'.
! 12232: $othertitle.'</label></span>';
1.26 raeburn 12233: }
1.23 raeburn 12234: }
1.315 raeburn 12235: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12236: return $output;
1.23 raeburn 12237: }
12238:
12239: sub sorted_searchtitles {
12240: my %searchtitles = &Apache::lonlocal::texthash(
12241: 'uname' => 'username',
12242: 'lastname' => 'last name',
12243: 'lastfirst' => 'last name, first name',
12244: );
12245: my @titleorder = ('uname','lastname','lastfirst');
12246: return (\%searchtitles,\@titleorder);
12247: }
12248:
1.25 raeburn 12249: sub sorted_searchtypes {
12250: my %srchtypes_desc = (
12251: exact => 'is exact match',
12252: contains => 'contains ..',
12253: begins => 'begins with ..',
12254: );
12255: my @srchtypeorder = ('exact','begins','contains');
12256: return (\%srchtypes_desc,\@srchtypeorder);
12257: }
12258:
1.3 raeburn 12259: sub usertype_update_row {
12260: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12261: my $datatable;
12262: my $numinrow = 4;
12263: foreach my $type (@{$types}) {
12264: if (defined($usertypes->{$type})) {
12265: $$rownums ++;
12266: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12267: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12268: '</td><td class="LC_left_item"><table>';
12269: for (my $i=0; $i<@{$fields}; $i++) {
12270: my $rem = $i%($numinrow);
12271: if ($rem == 0) {
12272: if ($i > 0) {
12273: $datatable .= '</tr>';
12274: }
12275: $datatable .= '<tr>';
12276: }
12277: my $check = ' ';
1.39 raeburn 12278: if (ref($settings) eq 'HASH') {
12279: if (ref($settings->{'fields'}) eq 'HASH') {
12280: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12281: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12282: $check = ' checked="checked" ';
12283: }
1.3 raeburn 12284: }
12285: }
12286: }
12287:
12288: if ($i == @{$fields}-1) {
12289: my $colsleft = $numinrow - $rem;
12290: if ($colsleft > 1) {
12291: $datatable .= '<td colspan="'.$colsleft.'">';
12292: } else {
12293: $datatable .= '<td>';
12294: }
12295: } else {
12296: $datatable .= '<td>';
12297: }
1.8 raeburn 12298: $datatable .= '<span class="LC_nobreak"><label>'.
12299: '<input type="checkbox" name="updateable_'.$type.
12300: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12301: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12302: }
12303: $datatable .= '</tr></table></td></tr>';
12304: }
12305: }
12306: return $datatable;
1.1 raeburn 12307: }
12308:
12309: sub modify_login {
1.205 raeburn 12310: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12311: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12312: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12313: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12314: %title = ( coursecatalog => 'Display course catalog',
12315: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12316: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12317: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12318: loginheader => 'Log-in box header',
12319: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12320: @offon = ('off','on');
1.112 raeburn 12321: if (ref($domconfig{login}) eq 'HASH') {
12322: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12323: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12324: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12325: }
12326: }
1.386 raeburn 12327: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12328: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12329: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12330: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12331: $saml{$lonhost} = 1;
12332: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12333: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12334: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12335: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12336: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12337: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12338: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12339: }
12340: }
12341: }
1.112 raeburn 12342: }
1.9 raeburn 12343: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12344: \%domconfig,\%loginhash);
1.188 raeburn 12345: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12346: foreach my $item (@toggles) {
12347: $loginhash{login}{$item} = $env{'form.'.$item};
12348: }
1.41 raeburn 12349: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12350: if (ref($colchanges{'login'}) eq 'HASH') {
12351: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12352: \%loginhash);
12353: }
1.110 raeburn 12354:
1.149 raeburn 12355: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12356: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12357: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12358: if (keys(%servers) > 1) {
12359: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12360: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12361: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12362: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12363: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12364: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12365: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12366: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12367: $changes{'loginvia'}{$lonhost} = 1;
12368: } else {
12369: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12370: $changes{'loginvia'}{$lonhost} = 1;
12371: }
12372: } else {
12373: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12374: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12375: $changes{'loginvia'}{$lonhost} = 1;
12376: }
12377: }
12378: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12379: foreach my $item (@loginvia_attribs) {
12380: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12381: }
12382: } else {
12383: foreach my $item (@loginvia_attribs) {
12384: my $new = $env{'form.'.$lonhost.'_'.$item};
12385: if (($item eq 'serverpath') && ($new eq 'custom')) {
12386: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12387: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12388: $new = '/';
12389: }
12390: }
12391: if (($item eq 'custompath') &&
12392: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12393: $new = '';
12394: }
12395: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12396: $changes{'loginvia'}{$lonhost} = 1;
12397: }
12398: if ($item eq 'exempt') {
1.256 raeburn 12399: $new = &check_exempt_addresses($new);
1.128 raeburn 12400: }
12401: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12402: }
12403: }
1.112 raeburn 12404: } else {
1.128 raeburn 12405: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12406: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12407: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12408: foreach my $item (@loginvia_attribs) {
12409: my $new = $env{'form.'.$lonhost.'_'.$item};
12410: if (($item eq 'serverpath') && ($new eq 'custom')) {
12411: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12412: $new = '/';
12413: }
12414: }
12415: if (($item eq 'custompath') &&
12416: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12417: $new = '';
12418: }
12419: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12420: }
1.110 raeburn 12421: }
12422: }
12423: }
12424: }
1.119 raeburn 12425:
1.168 raeburn 12426: my $servadm = $r->dir_config('lonAdmEMail');
12427: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12428: if (ref($domconfig{'login'}) eq 'HASH') {
12429: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12430: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12431: if ($lang eq 'nolang') {
12432: push(@currlangs,$lang);
12433: } elsif (defined($langchoices{$lang})) {
12434: push(@currlangs,$lang);
12435: } else {
12436: next;
12437: }
12438: }
12439: }
12440: }
12441: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12442: if (@currlangs > 0) {
12443: foreach my $lang (@currlangs) {
12444: if (grep(/^\Q$lang\E$/,@delurls)) {
12445: $changes{'helpurl'}{$lang} = 1;
12446: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12447: $changes{'helpurl'}{$lang} = 1;
12448: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12449: push(@newlangs,$lang);
12450: } else {
12451: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12452: }
12453: }
12454: }
12455: unless (grep(/^nolang$/,@currlangs)) {
12456: if ($env{'form.loginhelpurl_nolang.filename'}) {
12457: $changes{'helpurl'}{'nolang'} = 1;
12458: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12459: push(@newlangs,'nolang');
12460: }
12461: }
12462: if ($env{'form.loginhelpurl_add_lang'}) {
12463: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12464: ($env{'form.loginhelpurl_add_file.filename'})) {
12465: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12466: $addedfile = $env{'form.loginhelpurl_add_lang'};
12467: }
12468: }
12469: if ((@newlangs > 0) || ($addedfile)) {
12470: my $error;
12471: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12472: if ($configuserok eq 'ok') {
12473: if ($switchserver) {
12474: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12475: } elsif ($author_ok eq 'ok') {
12476: my @allnew = @newlangs;
12477: if ($addedfile ne '') {
12478: push(@allnew,$addedfile);
12479: }
1.421 raeburn 12480: my $modified = [];
1.168 raeburn 12481: foreach my $lang (@allnew) {
12482: my $formelem = 'loginhelpurl_'.$lang;
12483: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12484: $formelem = 'loginhelpurl_add_file';
12485: }
1.425 raeburn 12486: (my $result,$newurl{$lang}) =
1.421 raeburn 12487: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12488: "help/$lang",'','',$newfile{$lang},
12489: $modified);
1.168 raeburn 12490: if ($result eq 'ok') {
12491: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12492: $changes{'helpurl'}{$lang} = 1;
12493: } else {
12494: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12495: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12496: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12497: (!grep(/^\Q$lang\E$/,@delurls))) {
12498: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12499: }
12500: }
12501: }
1.421 raeburn 12502: &update_modify_urls($r,$modified);
1.168 raeburn 12503: } else {
12504: $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);
12505: }
12506: } else {
12507: $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);
12508: }
12509: if ($error) {
12510: &Apache::lonnet::logthis($error);
12511: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12512: }
12513: }
1.256 raeburn 12514:
12515: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12516: if (ref($domconfig{'login'}) eq 'HASH') {
12517: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12518: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12519: if ($domservers{$lonhost}) {
12520: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12521: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12522: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12523: }
12524: }
12525: }
12526: }
12527: }
12528: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12529: foreach my $lonhost (sort(keys(%domservers))) {
12530: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12531: $changes{'headtag'}{$lonhost} = 1;
12532: } else {
12533: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12534: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12535: }
12536: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12537: push(@newhosts,$lonhost);
12538: } elsif ($currheadtagurls{$lonhost}) {
12539: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12540: if ($currexempt{$lonhost}) {
1.289 raeburn 12541: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12542: $changes{'headtag'}{$lonhost} = 1;
12543: }
12544: } elsif ($possexempt{$lonhost}) {
12545: $changes{'headtag'}{$lonhost} = 1;
12546: }
12547: if ($possexempt{$lonhost}) {
12548: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12549: }
12550: }
12551: }
12552: }
12553: if (@newhosts) {
12554: my $error;
12555: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12556: if ($configuserok eq 'ok') {
12557: if ($switchserver) {
12558: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12559: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12560: my $modified = [];
1.256 raeburn 12561: foreach my $lonhost (@newhosts) {
12562: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12563: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12564: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12565: "login/headtag/$lonhost",'','',
12566: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12567: $modified);
1.256 raeburn 12568: if ($result eq 'ok') {
12569: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12570: $changes{'headtag'}{$lonhost} = 1;
12571: if ($possexempt{$lonhost}) {
12572: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12573: }
12574: } else {
12575: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12576: $newheadtagurls{$lonhost},$result);
12577: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12578: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12579: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12580: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12581: }
12582: }
12583: }
1.421 raeburn 12584: &update_modify_urls($r,$modified);
1.256 raeburn 12585: } else {
12586: $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);
12587: }
12588: } else {
12589: $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);
12590: }
12591: if ($error) {
12592: &Apache::lonnet::logthis($error);
12593: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12594: }
12595: }
1.386 raeburn 12596: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12597: my @newsamlimgs;
12598: foreach my $lonhost (keys(%domservers)) {
12599: if ($env{'form.saml_'.$lonhost}) {
12600: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12601: push(@newsamlimgs,$lonhost);
12602: }
1.412 raeburn 12603: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12604: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12605: }
12606: if ($saml{$lonhost}) {
1.412 raeburn 12607: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12608: $env{'form.saml_window_'.$lonhost} = '';
12609: }
1.386 raeburn 12610: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12611: #FIXME Need to obsolete published image
12612: delete($currsaml{$lonhost}{'img'});
12613: $changes{'saml'}{$lonhost} = 1;
12614: }
12615: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12616: $changes{'saml'}{$lonhost} = 1;
12617: }
12618: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12619: $changes{'saml'}{$lonhost} = 1;
12620: }
12621: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12622: $changes{'saml'}{$lonhost} = 1;
12623: }
12624: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12625: $changes{'saml'}{$lonhost} = 1;
12626: }
1.412 raeburn 12627: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12628: $changes{'saml'}{$lonhost} = 1;
12629: }
1.386 raeburn 12630: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12631: $changes{'saml'}{$lonhost} = 1;
12632: }
12633: } else {
12634: $changes{'saml'}{$lonhost} = 1;
12635: }
1.412 raeburn 12636: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12637: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12638: }
12639: } else {
1.425 raeburn 12640: if ($saml{$lonhost}) {
1.389 raeburn 12641: $changes{'saml'}{$lonhost} = 1;
12642: delete($currsaml{$lonhost});
12643: }
1.386 raeburn 12644: }
12645: }
12646: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12647: unless (exists($domservers{$posshost})) {
12648: delete($currsaml{$posshost});
1.386 raeburn 12649: }
12650: }
12651: %{$loginhash{'login'}{'saml'}} = %currsaml;
12652: if (@newsamlimgs) {
12653: my $error;
12654: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12655: if ($configuserok eq 'ok') {
12656: if ($switchserver) {
12657: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12658: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12659: my $modified = [];
1.386 raeburn 12660: foreach my $lonhost (@newsamlimgs) {
12661: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12662: my ($result,$imgurl) =
1.421 raeburn 12663: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12664: "login/saml/$lonhost",'','',
12665: $env{'form.saml_img_'.$lonhost.'.filename'},
12666: $modified);
1.386 raeburn 12667: if ($result eq 'ok') {
12668: $currsaml{$lonhost}{'img'} = $imgurl;
12669: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12670: $changes{'saml'}{$lonhost} = 1;
12671: } else {
12672: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12673: $lonhost,$result);
12674: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12675: }
12676: }
1.421 raeburn 12677: &update_modify_urls($r,$modified);
1.386 raeburn 12678: } else {
12679: $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);
12680: }
12681: } else {
12682: $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);
12683: }
12684: if ($error) {
12685: &Apache::lonnet::logthis($error);
12686: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12687: }
12688: }
1.169 raeburn 12689: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12690:
12691: my $defaulthelpfile = '/adm/loginproblems.html';
12692: my $defaulttext = &mt('Default in use');
12693:
1.1 raeburn 12694: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12695: $dom);
12696: if ($putresult eq 'ok') {
1.188 raeburn 12697: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12698: my %defaultchecked = (
12699: 'coursecatalog' => 'on',
1.188 raeburn 12700: 'helpdesk' => 'on',
1.42 raeburn 12701: 'adminmail' => 'off',
1.43 raeburn 12702: 'newuser' => 'off',
1.42 raeburn 12703: );
1.55 raeburn 12704: if (ref($domconfig{'login'}) eq 'HASH') {
12705: foreach my $item (@toggles) {
12706: if ($defaultchecked{$item} eq 'on') {
12707: if (($domconfig{'login'}{$item} eq '0') &&
12708: ($env{'form.'.$item} eq '1')) {
12709: $changes{$item} = 1;
12710: } elsif (($domconfig{'login'}{$item} eq '' ||
12711: $domconfig{'login'}{$item} eq '1') &&
12712: ($env{'form.'.$item} eq '0')) {
12713: $changes{$item} = 1;
12714: }
12715: } elsif ($defaultchecked{$item} eq 'off') {
12716: if (($domconfig{'login'}{$item} eq '1') &&
12717: ($env{'form.'.$item} eq '0')) {
12718: $changes{$item} = 1;
12719: } elsif (($domconfig{'login'}{$item} eq '' ||
12720: $domconfig{'login'}{$item} eq '0') &&
12721: ($env{'form.'.$item} eq '1')) {
12722: $changes{$item} = 1;
12723: }
1.42 raeburn 12724: }
12725: }
1.41 raeburn 12726: }
1.6 raeburn 12727: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12728: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12729: if (exists($changes{'saml'})) {
12730: my $hostid_in_use;
12731: my @hosts = &Apache::lonnet::current_machine_ids();
12732: if (@hosts > 1) {
12733: foreach my $hostid (@hosts) {
12734: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12735: $hostid_in_use = $hostid;
12736: last;
12737: }
12738: }
12739: } else {
12740: $hostid_in_use = $r->dir_config('lonHostID');
12741: }
12742: if (($hostid_in_use) &&
12743: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12744: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12745: }
12746: if (ref($lastactref) eq 'HASH') {
12747: if (ref($changes{'saml'}) eq 'HASH') {
12748: my %updates;
12749: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12750: $lastactref->{'samllanding'} = \%updates;
12751: }
12752: }
12753: }
1.212 raeburn 12754: if (ref($lastactref) eq 'HASH') {
12755: $lastactref->{'domainconfig'} = 1;
12756: }
1.1 raeburn 12757: $resulttext = &mt('Changes made:').'<ul>';
12758: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12759: if ($item eq 'loginvia') {
1.112 raeburn 12760: if (ref($changes{$item}) eq 'HASH') {
12761: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12762: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12763: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12764: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12765: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12766: $protocol = 'http' if ($protocol ne 'https');
12767: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12768:
12769: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12770: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12771: } else {
12772: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12773: }
12774: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12775: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12776: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12777: }
12778: $resulttext .= '</li>';
12779: } else {
12780: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12781: }
1.112 raeburn 12782: } else {
1.128 raeburn 12783: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12784: }
12785: }
1.128 raeburn 12786: $resulttext .= '</ul></li>';
1.112 raeburn 12787: }
1.168 raeburn 12788: } elsif ($item eq 'helpurl') {
12789: if (ref($changes{$item}) eq 'HASH') {
12790: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12791: if (grep(/^\Q$lang\E$/,@delurls)) {
12792: my ($chg,$link);
12793: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12794: if ($lang eq 'nolang') {
12795: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12796: } else {
12797: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12798: }
12799: $resulttext .= '<li>'.$chg.'</li>';
12800: } else {
12801: my $chg;
12802: if ($lang eq 'nolang') {
12803: $chg = &mt('custom log-in help file for no preferred language');
12804: } else {
12805: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12806: }
12807: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12808: $loginhash{'login'}{'helpurl'}{$lang}.
12809: '?inhibitmenu=yes',$chg,600,500).
12810: '</li>';
12811: }
12812: }
12813: }
1.256 raeburn 12814: } elsif ($item eq 'headtag') {
12815: if (ref($changes{$item}) eq 'HASH') {
12816: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12817: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12818: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12819: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12820: $resulttext .= '<li><a href="'.
12821: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12822: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12823: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12824: if ($possexempt{$lonhost}) {
12825: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12826: } else {
12827: $resulttext .= &mt('included for any client IP');
12828: }
12829: $resulttext .= '</li>';
12830: }
12831: }
12832: }
1.386 raeburn 12833: } elsif ($item eq 'saml') {
12834: if (ref($changes{$item}) eq 'HASH') {
12835: my %notlt = (
12836: text => 'Text for log-in by SSO',
12837: img => 'SSO button image',
12838: alt => 'Alt text for button image',
12839: url => 'SSO URL',
12840: title => 'Tooltip for SSO link',
1.412 raeburn 12841: window => 'Pop-up window if iframe',
1.386 raeburn 12842: notsso => 'Text for non-SSO log-in',
12843: );
12844: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12845: if (ref($currsaml{$lonhost}) eq 'HASH') {
12846: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12847: '<ul>';
1.412 raeburn 12848: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 12849: if ($currsaml{$lonhost}{$key} eq '') {
12850: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12851: } else {
12852: my $value = "'$currsaml{$lonhost}{$key}'";
12853: if ($key eq 'img') {
12854: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 12855: } elsif ($key eq 'window') {
12856: $value = 'On';
1.386 raeburn 12857: }
12858: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12859: $value).'</li>';
12860: }
12861: }
12862: $resulttext .= '</ul></li>';
12863: } else {
12864: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12865: }
12866: }
12867: }
1.169 raeburn 12868: } elsif ($item eq 'captcha') {
12869: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12870: my $chgtxt;
1.169 raeburn 12871: if ($loginhash{'login'}{$item} eq 'notused') {
12872: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12873: } else {
12874: my %captchas = &captcha_phrases();
12875: if ($captchas{$loginhash{'login'}{$item}}) {
12876: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12877: } else {
12878: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12879: }
12880: }
12881: $resulttext .= '<li>'.$chgtxt.'</li>';
12882: }
12883: } elsif ($item eq 'recaptchakeys') {
12884: if (ref($loginhash{'login'}) eq 'HASH') {
12885: my ($privkey,$pubkey);
12886: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
12887: $pubkey = $loginhash{'login'}{$item}{'public'};
12888: $privkey = $loginhash{'login'}{$item}{'private'};
12889: }
12890: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
12891: if (!$pubkey) {
12892: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
12893: } else {
12894: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12895: }
12896: if (!$privkey) {
12897: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
12898: } else {
1.251 raeburn 12899: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 12900: }
12901: $chgtxt .= '</ul>';
12902: $resulttext .= '<li>'.$chgtxt.'</li>';
12903: }
1.269 raeburn 12904: } elsif ($item eq 'recaptchaversion') {
12905: if (ref($loginhash{'login'}) eq 'HASH') {
12906: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 12907: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 12908: '</li>';
12909: }
12910: }
1.41 raeburn 12911: } else {
12912: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
12913: }
1.1 raeburn 12914: }
1.6 raeburn 12915: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 12916: } else {
12917: $resulttext = &mt('No changes made to log-in page settings');
12918: }
12919: } else {
1.11 albertel 12920: $resulttext = '<span class="LC_error">'.
12921: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12922: }
1.6 raeburn 12923: if ($errors) {
1.9 raeburn 12924: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 12925: $errors.'</ul>';
12926: }
12927: return $resulttext;
12928: }
12929:
1.256 raeburn 12930: sub check_exempt_addresses {
12931: my ($iplist) = @_;
12932: $iplist =~ s/^\s+//;
12933: $iplist =~ s/\s+$//;
12934: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
12935: my (@okips,$new);
12936: foreach my $ip (@poss_ips) {
12937: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
12938: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
12939: push(@okips,$ip);
12940: }
12941: }
12942: }
12943: if (@okips > 0) {
12944: $new = join(',',@okips);
12945: } else {
12946: $new = '';
12947: }
12948: return $new;
12949: }
12950:
1.6 raeburn 12951: sub color_font_choices {
12952: my %choices =
12953: &Apache::lonlocal::texthash (
12954: img => "Header",
12955: bgs => "Background colors",
12956: links => "Link colors",
1.55 raeburn 12957: images => "Images",
1.6 raeburn 12958: font => "Font color",
1.201 raeburn 12959: fontmenu => "Font menu",
1.76 raeburn 12960: pgbg => "Page",
1.6 raeburn 12961: tabbg => "Header",
12962: sidebg => "Border",
12963: link => "Link",
12964: alink => "Active link",
12965: vlink => "Visited link",
12966: );
12967: return %choices;
12968: }
12969:
1.394 raeburn 12970: sub modify_ipaccess {
12971: my ($dom,$lastactref,%domconfig) = @_;
12972: my (@allpos,%changes,%confhash,$errors,$resulttext);
12973: my (@items,%deletions,%itemids,@warnings);
12974: my ($typeorder,$types) = &commblocktype_text();
12975: if ($env{'form.ipaccess_add'}) {
12976: my $name = $env{'form.ipaccess_name_add'};
12977: my ($newid,$error) = &get_ipaccess_id($dom,$name);
12978: if ($newid) {
12979: $itemids{'add'} = $newid;
12980: push(@items,'add');
12981: $changes{$newid} = 1;
12982: } else {
12983: $error = &mt('Failed to acquire unique ID for new IP access control item');
12984: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12985: }
12986: }
12987: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
12988: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
12989: if (@todelete) {
12990: map { $deletions{$_} = 1; } @todelete;
12991: }
12992: my $maxnum = $env{'form.ipaccess_maxnum'};
12993: for (my $i=0; $i<$maxnum; $i++) {
12994: my $itemid = $env{'form.ipaccess_id_'.$i};
12995: $itemid =~ s/\D+//g;
12996: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12997: if ($deletions{$itemid}) {
12998: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
12999: } else {
13000: push(@items,$i);
13001: $itemids{$i} = $itemid;
13002: }
13003: }
13004: }
13005: }
13006: foreach my $idx (@items) {
13007: my $itemid = $itemids{$idx};
13008: next unless ($itemid);
13009: my %current;
13010: unless ($idx eq 'add') {
13011: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13012: %current = %{$domconfig{'ipaccess'}{$itemid}};
13013: }
13014: }
13015: my $position = $env{'form.ipaccess_pos_'.$itemid};
13016: $position =~ s/\D+//g;
13017: if ($position ne '') {
13018: $allpos[$position] = $itemid;
13019: }
13020: my $name = $env{'form.ipaccess_name_'.$idx};
13021: $name =~ s/^\s+|\s+$//g;
13022: $confhash{$itemid}{'name'} = $name;
13023: my $possrange = $env{'form.ipaccess_range_'.$idx};
13024: $possrange =~ s/^\s+|\s+$//g;
13025: unless ($possrange eq '') {
13026: $possrange =~ s/[\r\n]+/\s/g;
13027: $possrange =~ s/\s*-\s*/-/g;
13028: $possrange =~ s/\s+/,/g;
13029: $possrange =~ s/,+/,/g;
13030: if ($possrange ne '') {
13031: my (@ok,$count);
1.425 raeburn 13032: $count = 0;
1.394 raeburn 13033: foreach my $poss (split(/\,/,$possrange)) {
13034: $count ++;
13035: $poss = &validate_ip_pattern($poss);
13036: if ($poss ne '') {
13037: push(@ok,$poss);
13038: }
13039: }
13040: my $diff = $count - scalar(@ok);
13041: if ($diff) {
13042: $errors .= '<li><span class="LC_error">'.
13043: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13044: $diff,$name).
13045: '</span></li>';
13046: }
13047: if (@ok) {
13048: my @cidr_list;
13049: foreach my $item (@ok) {
13050: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13051: }
13052: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13053: }
13054: }
13055: }
13056: foreach my $field ('name','ip') {
13057: unless (($idx eq 'add') || ($changes{$itemid})) {
13058: if ($current{$field} ne $confhash{$itemid}{$field}) {
13059: $changes{$itemid} = 1;
13060: last;
13061: }
13062: }
13063: }
13064: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13065:
1.394 raeburn 13066: my %commblocks;
1.425 raeburn 13067: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13068: foreach my $type (@{$typeorder}) {
13069: if ($commblocks{$type}) {
13070: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13071: }
13072: unless (($idx eq 'add') || ($changes{$itemid})) {
13073: if (ref($current{'commblocks'}) eq 'HASH') {
13074: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13075: $changes{$itemid} = 1;
13076: }
13077: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13078: $changes{$itemid} = 1;
13079: }
13080: }
13081: }
13082: $confhash{$itemid}{'courses'} = {};
13083: my %crsdeletions;
13084: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13085: if (@delcrs) {
13086: map { $crsdeletions{$_} = 1; } @delcrs;
13087: }
13088: if (ref($current{'courses'}) eq 'HASH') {
13089: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13090: if ($crsdeletions{$cid}) {
13091: $changes{$itemid} = 1;
13092: } else {
13093: $confhash{$itemid}{'courses'}{$cid} = 1;
13094: }
13095: }
13096: }
13097: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13098: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13099: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13100: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13101: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13102: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13103: $errors .= '<li><span class="LC_error">'.
13104: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13105: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13106: '</span></li>';
13107: } else {
13108: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13109: $changes{$itemid} = 1;
13110: }
13111: }
13112: }
13113: if (@allpos > 0) {
13114: my $idx = 0;
13115: foreach my $itemid (@allpos) {
13116: if ($itemid ne '') {
13117: $confhash{$itemid}{'order'} = $idx;
13118: unless ($changes{$itemid}) {
13119: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13120: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13121: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13122: $changes{$itemid} = 1;
13123: }
13124: }
13125: }
13126: }
13127: $idx ++;
13128: }
13129: }
13130: }
13131: if (keys(%changes)) {
13132: my %defaultshash = (
13133: ipaccess => \%confhash,
13134: );
13135: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13136: $dom);
13137: if ($putresult eq 'ok') {
13138: my $cachetime = 1800;
13139: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13140: if (ref($lastactref) eq 'HASH') {
13141: $lastactref->{'ipaccess'} = 1;
13142: }
13143: $resulttext = &mt('Changes made:').'<ul>';
13144: my %bynum;
13145: foreach my $itemid (sort(keys(%changes))) {
13146: if (ref($confhash{$itemid}) eq 'HASH') {
13147: my $position = $confhash{$itemid}{'order'};
13148: if ($position =~ /^\d+$/) {
13149: $bynum{$position} = $itemid;
13150: }
13151: }
13152: }
13153: if (keys(%deletions)) {
13154: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13155: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13156: }
13157: }
13158: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13159: my $itemid = $bynum{$pos};
13160: if (ref($confhash{$itemid}) eq 'HASH') {
13161: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13162: my $position = $pos + 1;
13163: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13164: if ($confhash{$itemid}{'ip'} eq '') {
13165: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13166: } else {
13167: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13168: }
13169: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13170: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13171: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13172: '</li>';
13173: } else {
13174: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13175: }
13176: if (keys(%{$confhash{$itemid}{'courses'}})) {
13177: my @courses;
13178: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13179: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13180: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13181: }
13182: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13183: join('</li><li>',@courses).'</li></ul>';
13184: } else {
13185: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13186: }
1.395 raeburn 13187: $resulttext .= '</ul></li>';
1.394 raeburn 13188: }
13189: }
1.395 raeburn 13190: $resulttext .= '</ul>';
1.394 raeburn 13191: } else {
13192: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13193: }
13194: } else {
13195: $resulttext = &mt('No changes made');
13196: }
13197: if ($errors) {
13198: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13199: $errors.'</ul></p>';
13200: }
13201: return $resulttext;
13202: }
13203:
13204: sub get_ipaccess_id {
13205: my ($domain,$location) = @_;
13206: # get lock on ipaccess db
13207: my $lockhash = {
13208: lock => $env{'user.name'}.
13209: ':'.$env{'user.domain'},
13210: };
13211: my $tries = 0;
13212: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13213: my ($id,$error);
13214:
13215: while (($gotlock ne 'ok') && ($tries<10)) {
13216: $tries ++;
13217: sleep (0.1);
13218: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13219: }
13220: if ($gotlock eq 'ok') {
13221: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13222: if ($currids{'lock'}) {
13223: delete($currids{'lock'});
13224: if (keys(%currids)) {
13225: my @curr = sort { $a <=> $b } keys(%currids);
13226: if ($curr[-1] =~ /^\d+$/) {
13227: $id = 1 + $curr[-1];
13228: }
13229: } else {
13230: $id = 1;
13231: }
13232: if ($id) {
13233: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13234: $error = 'nostore';
13235: }
13236: } else {
13237: $error = 'nonumber';
13238: }
13239: }
13240: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13241: } else {
13242: $error = 'nolock';
13243: }
13244: return ($id,$error);
13245: }
13246:
1.429 ! raeburn 13247: sub modify_authordefaults {
! 13248: my ($dom,$lastactref,%domconfig) = @_;
! 13249: #
! 13250: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
! 13251: #
! 13252: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
! 13253: if (ref($domconfig{'quotas'}) eq 'HASH') {
! 13254: foreach my $key (keys(%{$domconfig{'quotas'}})) {
! 13255: if ($key =~ /^webdav|authorquota$/) {
! 13256: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
! 13257: } else {
! 13258: $save_quotas{$key} = $domconfig{'quotas'}{$key};
! 13259: }
! 13260: }
! 13261: }
! 13262: my %staticdefaults = (
! 13263: 'copyright' => 'default',
! 13264: 'sourceavail' => 'closed',
! 13265: 'nocodemirror' => 'off',
! 13266: 'domcoordacc' => 'on',
! 13267: 'editors' => ['edit','xml'].
! 13268: 'authorquota' => 500,
! 13269: 'webdav' => 0,
! 13270: );
! 13271: my %titles = &authordefaults_titles();
! 13272: foreach my $item ('nocodemirror','domcoordacc') {
! 13273: if ($env{'form.'.$item} =~ /^(0|1)$/) {
! 13274: $confhash{$item} = $env{'form.'.$item};
! 13275: }
! 13276: }
! 13277: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
! 13278: $confhash{'copyright'} = $1;
! 13279: }
! 13280: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
! 13281: $confhash{'sourceavail'} = $1;
! 13282: }
! 13283: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
! 13284: my @okeditors = ('edit','xml','daxe');
! 13285: my @editors;
! 13286: foreach my $item (@posseditors) {
! 13287: if (grep(/^\Q$item\E$/,@okeditors)) {
! 13288: push(@editors,$item);
! 13289: }
! 13290: }
! 13291: $confhash{'editors'} = \@editors;
! 13292:
! 13293: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 13294: my @insttypes;
! 13295: if (ref($types) eq 'ARRAY') {
! 13296: @insttypes = @{$types};
! 13297: }
! 13298: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
! 13299: my %webdav;
! 13300: map { $webdav{$_} = 1; } @webdavon;
! 13301: foreach my $type (@insttypes,'default') {
! 13302: my $possquota = $env{'form.authorquota_'.$type};
! 13303: if ($possquota =~ /^\d+$/) {
! 13304: $save_quotas{'authorquota'}{$type} = $possquota;
! 13305: }
! 13306: if ($webdav{$type}) {
! 13307: $save_quotas{'webdav'}{$type} = 1;
! 13308: } else {
! 13309: $save_quotas{'webdav'}{$type} = 0;
! 13310: }
! 13311: }
! 13312: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
! 13313: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
! 13314: }
! 13315: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
! 13316: foreach my $item ('nocodemirror','domcoordacc','copyright','sourceavail') {
! 13317: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
! 13318: $changes{$item} = 1;
! 13319: }
! 13320: }
! 13321: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
! 13322: my @diffs =
! 13323: &Apache::loncommon::compare_arrays($confhash{'editors'},
! 13324: $domconfig{'authordefaults'}{'editors'});
! 13325: unless (@diffs == 0) {
! 13326: $changes{'editors'} = 1;
! 13327: }
! 13328: } else {
! 13329: my @diffs =
! 13330: &Apache::loncommon::compare_arrays($confhash{'editors'},
! 13331: $staticdefaults{'editors'});
! 13332: unless (@diffs == 0) {
! 13333: $changes{'editors'} = 1;
! 13334: }
! 13335: }
! 13336: } else {
! 13337: my @offon = ('off','on');
! 13338: foreach my $item ('nocodemirror','domcoordacc') {
! 13339: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
! 13340: $changes{$item} = 1;
! 13341: }
! 13342: }
! 13343: foreach my $item ('copyright','sourceavail') {
! 13344: if ($confhash{$item} ne $staticdefaults{$item}) {
! 13345: $changes{$item} = 1;
! 13346: }
! 13347: }
! 13348: }
! 13349: foreach my $key ('authorquota','webdav') {
! 13350: if (ref($curr_quotas{$key}) eq 'HASH') {
! 13351: foreach my $type (@insttypes,'default') {
! 13352: if (exists($save_quotas{$key}{$type})) {
! 13353: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
! 13354: $changes{$key}{$type} = 1;
! 13355: }
! 13356: } elsif (exists($curr_quotas{$key}{$type})) {
! 13357: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
! 13358: } else {
! 13359: $save_quotas{$key}{$type} = $staticdefaults{$key};
! 13360: }
! 13361: }
! 13362: } else {
! 13363: foreach my $type (@insttypes,'default') {
! 13364: if (exists($save_quotas{$key}{$type})) {
! 13365: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
! 13366: $changes{$key}{$type} = 1;
! 13367: }
! 13368: } else {
! 13369: $save_quotas{$key}{$type} = $staticdefaults{$key};
! 13370: }
! 13371: }
! 13372: }
! 13373: }
! 13374: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
! 13375: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
! 13376: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
! 13377: $changes{'webdav_LC_adv'} = 1;
! 13378: }
! 13379: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
! 13380: $changes{'webdav_LC_adv'} = 1;
! 13381: }
! 13382: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
! 13383: $changes{'webdav_LC_adv'} = 1;
! 13384: }
! 13385: my %confighash = (
! 13386: quotas => \%save_quotas,
! 13387: authordefaults => \%confhash,
! 13388: );
! 13389: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
! 13390: $dom);
! 13391: my $resulttext;
! 13392: if ($putresult eq 'ok') {
! 13393: if (keys(%changes)) {
! 13394: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
! 13395: ($changes{'webdav_LC_adv'})) {
! 13396: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
! 13397: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
! 13398: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
! 13399: }
! 13400: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
! 13401: (ref($save_quotas{'webdav'}) eq 'HASH')) {
! 13402: $domdefaults{'webdav'} = $save_quotas{'webdav'};
! 13403: }
! 13404: my $cachetime = 24*60*60;
! 13405: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
! 13406: if (ref($lastactref) eq 'HASH') {
! 13407: $lastactref->{'domdefaults'} = 1;
! 13408: }
! 13409: }
! 13410: $resulttext = &mt('Changes made:').'<ul>';
! 13411: my $authoroverride;
! 13412: foreach my $key ('nocodemirror','domcoordacc','copyright','sourceavail') {
! 13413: if (exists($changes{$key})) {
! 13414: my $shown;
! 13415: unless ($authoroverride) {
! 13416: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
! 13417: $authoroverride = 1;
! 13418: }
! 13419: if (($key eq 'nocodemirror') || ($key eq 'domcoordacc')) {
! 13420: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
! 13421: } elsif ($key eq 'copyright') {
! 13422: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
! 13423: } elsif ($key eq 'sourceavail') {
! 13424: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
! 13425: }
! 13426: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
! 13427: }
! 13428: }
! 13429: if ($authoroverride) {
! 13430: $resulttext .= '</ul></li>';
! 13431: }
! 13432: my $domcoordoverride;
! 13433: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv') {
! 13434: if (exists($changes{$key})) {
! 13435: my $shown;
! 13436: unless ($domcoordoverride) {
! 13437: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
! 13438: $domcoordoverride = 1;
! 13439: }
! 13440: if ($key eq 'editors') {
! 13441: if (@{$confhash{'editors'}}) {
! 13442: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
! 13443: } else {
! 13444: $shown = &mt('None');
! 13445: }
! 13446: } elsif ($key eq 'authorquota') {
! 13447: foreach my $type (@insttypes) {
! 13448: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
! 13449: }
! 13450: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
! 13451: } elsif ($key eq 'webdav') {
! 13452: foreach my $type (@insttypes) {
! 13453: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
! 13454: }
! 13455: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
! 13456: } elsif ($key eq 'webdav_LC_adv') {
! 13457: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
! 13458: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
! 13459: } else {
! 13460: $shown = $titles{'none'};
! 13461: }
! 13462: }
! 13463: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
! 13464: }
! 13465: }
! 13466: if ($domcoordoverride) {
! 13467: $resulttext .= '</ul></li>';
! 13468: }
! 13469: } else {
! 13470: $resulttext = &mt('No changes made to Authoring Space defaults');
! 13471: }
! 13472: }
! 13473: return $resulttext;
! 13474: }
! 13475:
1.6 raeburn 13476: sub modify_rolecolors {
1.205 raeburn 13477: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13478: my ($resulttext,%rolehash);
13479: $rolehash{'rolecolors'} = {};
1.55 raeburn 13480: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13481: if ($domconfig{'rolecolors'} eq '') {
13482: $domconfig{'rolecolors'} = {};
13483: }
13484: }
1.9 raeburn 13485: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13486: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13487: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13488: $dom);
13489: if ($putresult eq 'ok') {
13490: if (keys(%changes) > 0) {
1.41 raeburn 13491: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13492: if (ref($lastactref) eq 'HASH') {
13493: $lastactref->{'domainconfig'} = 1;
13494: }
1.6 raeburn 13495: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13496: $rolehash{'rolecolors'});
13497: } else {
13498: $resulttext = &mt('No changes made to default color schemes');
13499: }
13500: } else {
1.11 albertel 13501: $resulttext = '<span class="LC_error">'.
13502: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13503: }
13504: if ($errors) {
13505: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13506: $errors.'</ul>';
13507: }
13508: return $resulttext;
13509: }
13510:
13511: sub modify_colors {
1.9 raeburn 13512: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13513: my (%changes,%choices);
1.51 raeburn 13514: my @bgs;
1.6 raeburn 13515: my @links = ('link','alink','vlink');
1.41 raeburn 13516: my @logintext;
1.6 raeburn 13517: my @images;
13518: my $servadm = $r->dir_config('lonAdmEMail');
13519: my $errors;
1.200 raeburn 13520: my %defaults;
1.6 raeburn 13521: foreach my $role (@{$roles}) {
13522: if ($role eq 'login') {
1.12 raeburn 13523: %choices = &login_choices();
1.41 raeburn 13524: @logintext = ('textcol','bgcol');
1.12 raeburn 13525: } else {
13526: %choices = &color_font_choices();
13527: }
13528: if ($role eq 'login') {
1.41 raeburn 13529: @images = ('img','logo','domlogo','login');
1.51 raeburn 13530: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13531: } else {
13532: @images = ('img');
1.200 raeburn 13533: @bgs = ('pgbg','tabbg','sidebg');
13534: }
13535: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
13536: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
13537: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13538: }
13539: if ($role eq 'login') {
13540: foreach my $item (@logintext) {
1.234 raeburn 13541: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13542: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13543: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13544: }
13545: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13546: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13547: }
13548: }
13549: } else {
1.234 raeburn 13550: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13551: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13552: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13553: }
13554: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13555: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13556: }
1.6 raeburn 13557: }
1.200 raeburn 13558: foreach my $item (@bgs) {
1.234 raeburn 13559: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13560: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13561: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13562: }
13563: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13564: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13565: }
13566: }
13567: foreach my $item (@links) {
1.234 raeburn 13568: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13569: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13570: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13571: }
13572: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13573: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13574: }
1.6 raeburn 13575: }
1.46 raeburn 13576: my ($configuserok,$author_ok,$switchserver) =
13577: &config_check($dom,$confname,$servadm);
1.9 raeburn 13578: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13579: if (ref($domconfig->{$role}) ne 'HASH') {
13580: $domconfig->{$role} = {};
13581: }
1.8 raeburn 13582: foreach my $img (@images) {
1.402 raeburn 13583: if ($role eq 'login') {
13584: if (($img eq 'img') || ($img eq 'logo')) {
13585: if (defined($env{'form.login_showlogo_'.$img})) {
13586: $confhash->{$role}{'showlogo'}{$img} = 1;
13587: } else {
13588: $confhash->{$role}{'showlogo'}{$img} = 0;
13589: }
13590: }
13591: if ($env{'form.login_alt_'.$img} ne '') {
13592: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13593: }
1.402 raeburn 13594: }
1.18 albertel 13595: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13596: && !defined($domconfig->{$role}{$img})
13597: && !$env{'form.'.$role.'_del_'.$img}
13598: && $env{'form.'.$role.'_import_'.$img}) {
13599: # import the old configured image from the .tab setting
13600: # if they haven't provided a new one
13601: $domconfig->{$role}{$img} =
13602: $env{'form.'.$role.'_import_'.$img};
13603: }
1.6 raeburn 13604: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13605: my $error;
1.6 raeburn 13606: if ($configuserok eq 'ok') {
1.9 raeburn 13607: if ($switchserver) {
1.12 raeburn 13608: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13609: } else {
13610: if ($author_ok eq 'ok') {
1.421 raeburn 13611: my $modified = [];
1.9 raeburn 13612: my ($result,$logourl) =
1.421 raeburn 13613: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13614: $dom,$confname,$img,$width,$height,
13615: '',$modified);
1.9 raeburn 13616: if ($result eq 'ok') {
13617: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13618: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13619: &update_modify_urls($r,$modified);
1.9 raeburn 13620: } else {
1.12 raeburn 13621: $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 13622: }
13623: } else {
1.46 raeburn 13624: $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 13625: }
13626: }
13627: } else {
1.46 raeburn 13628: $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 13629: }
13630: if ($error) {
1.8 raeburn 13631: &Apache::lonnet::logthis($error);
1.11 albertel 13632: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13633: }
13634: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13635: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13636: my $error;
13637: if ($configuserok eq 'ok') {
13638: # is confname an author?
13639: if ($switchserver eq '') {
13640: if ($author_ok eq 'ok') {
1.421 raeburn 13641: my $modified = [];
1.9 raeburn 13642: my ($result,$logourl) =
1.421 raeburn 13643: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13644: $dom,$confname,$img,$width,$height,
13645: '',$modified);
1.9 raeburn 13646: if ($result eq 'ok') {
13647: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13648: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13649: &update_modify_urls($r,$modified);
1.9 raeburn 13650: }
13651: }
13652: }
13653: }
1.6 raeburn 13654: }
13655: }
13656: }
13657: if (ref($domconfig) eq 'HASH') {
13658: if (ref($domconfig->{$role}) eq 'HASH') {
13659: foreach my $img (@images) {
13660: if ($domconfig->{$role}{$img} ne '') {
13661: if ($env{'form.'.$role.'_del_'.$img}) {
13662: $confhash->{$role}{$img} = '';
1.12 raeburn 13663: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13664: } else {
1.9 raeburn 13665: if ($confhash->{$role}{$img} eq '') {
13666: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13667: }
1.6 raeburn 13668: }
13669: } else {
13670: if ($env{'form.'.$role.'_del_'.$img}) {
13671: $confhash->{$role}{$img} = '';
1.12 raeburn 13672: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13673: }
13674: }
1.402 raeburn 13675: if ($role eq 'login') {
13676: if (($img eq 'logo') || ($img eq 'img')) {
13677: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13678: if ($confhash->{$role}{'showlogo'}{$img} ne
13679: $domconfig->{$role}{'showlogo'}{$img}) {
13680: $changes{$role}{'showlogo'}{$img} = 1;
13681: }
13682: } else {
13683: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13684: $changes{$role}{'showlogo'}{$img} = 1;
13685: }
1.70 raeburn 13686: }
1.402 raeburn 13687: }
13688: if ($img ne 'login') {
13689: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13690: if ($confhash->{$role}{'alttext'}{$img} ne
13691: $domconfig->{$role}{'alttext'}{$img}) {
13692: $changes{$role}{'alttext'}{$img} = 1;
13693: }
13694: } else {
13695: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13696: $changes{$role}{'alttext'}{$img} = 1;
13697: }
1.70 raeburn 13698: }
13699: }
13700: }
13701: }
1.6 raeburn 13702: if ($domconfig->{$role}{'font'} ne '') {
13703: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13704: $changes{$role}{'font'} = 1;
13705: }
13706: } else {
13707: if ($confhash->{$role}{'font'}) {
13708: $changes{$role}{'font'} = 1;
13709: }
13710: }
1.107 raeburn 13711: if ($role ne 'login') {
13712: if ($domconfig->{$role}{'fontmenu'} ne '') {
13713: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13714: $changes{$role}{'fontmenu'} = 1;
13715: }
13716: } else {
13717: if ($confhash->{$role}{'fontmenu'}) {
13718: $changes{$role}{'fontmenu'} = 1;
13719: }
1.97 tempelho 13720: }
13721: }
1.6 raeburn 13722: foreach my $item (@bgs) {
13723: if ($domconfig->{$role}{$item} ne '') {
13724: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13725: $changes{$role}{'bgs'}{$item} = 1;
13726: }
13727: } else {
13728: if ($confhash->{$role}{$item}) {
13729: $changes{$role}{'bgs'}{$item} = 1;
13730: }
13731: }
13732: }
13733: foreach my $item (@links) {
13734: if ($domconfig->{$role}{$item} ne '') {
13735: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13736: $changes{$role}{'links'}{$item} = 1;
13737: }
13738: } else {
13739: if ($confhash->{$role}{$item}) {
13740: $changes{$role}{'links'}{$item} = 1;
13741: }
13742: }
13743: }
1.41 raeburn 13744: foreach my $item (@logintext) {
13745: if ($domconfig->{$role}{$item} ne '') {
13746: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13747: $changes{$role}{'logintext'}{$item} = 1;
13748: }
13749: } else {
13750: if ($confhash->{$role}{$item}) {
13751: $changes{$role}{'logintext'}{$item} = 1;
13752: }
13753: }
13754: }
1.6 raeburn 13755: } else {
13756: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13757: \@logintext,$confhash,\%changes);
1.6 raeburn 13758: }
13759: } else {
13760: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13761: \@logintext,$confhash,\%changes);
1.6 raeburn 13762: }
13763: }
13764: return ($errors,%changes);
13765: }
13766:
1.46 raeburn 13767: sub config_check {
13768: my ($dom,$confname,$servadm) = @_;
13769: my ($configuserok,$author_ok,$switchserver,%currroles);
13770: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13771: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13772: $confname,$servadm);
13773: if ($configuserok eq 'ok') {
13774: $switchserver = &check_switchserver($dom,$confname);
13775: if ($switchserver eq '') {
13776: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13777: }
13778: }
13779: return ($configuserok,$author_ok,$switchserver);
13780: }
13781:
1.6 raeburn 13782: sub default_change_checker {
1.41 raeburn 13783: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13784: foreach my $item (@{$links}) {
13785: if ($confhash->{$role}{$item}) {
13786: $changes->{$role}{'links'}{$item} = 1;
13787: }
13788: }
13789: foreach my $item (@{$bgs}) {
13790: if ($confhash->{$role}{$item}) {
13791: $changes->{$role}{'bgs'}{$item} = 1;
13792: }
13793: }
1.41 raeburn 13794: foreach my $item (@{$logintext}) {
13795: if ($confhash->{$role}{$item}) {
13796: $changes->{$role}{'logintext'}{$item} = 1;
13797: }
13798: }
1.6 raeburn 13799: foreach my $img (@{$images}) {
13800: if ($env{'form.'.$role.'_del_'.$img}) {
13801: $confhash->{$role}{$img} = '';
1.12 raeburn 13802: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13803: }
1.70 raeburn 13804: if ($role eq 'login') {
13805: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13806: $changes->{$role}{'showlogo'}{$img} = 1;
13807: }
1.402 raeburn 13808: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13809: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13810: $changes->{$role}{'alttext'}{$img} = 1;
13811: }
13812: }
1.70 raeburn 13813: }
1.6 raeburn 13814: }
13815: if ($confhash->{$role}{'font'}) {
13816: $changes->{$role}{'font'} = 1;
13817: }
1.48 raeburn 13818: }
1.6 raeburn 13819:
13820: sub display_colorchgs {
13821: my ($dom,$changes,$roles,$confhash) = @_;
13822: my (%choices,$resulttext);
13823: if (!grep(/^login$/,@{$roles})) {
13824: $resulttext = &mt('Changes made:').'<br />';
13825: }
13826: foreach my $role (@{$roles}) {
13827: if ($role eq 'login') {
13828: %choices = &login_choices();
13829: } else {
13830: %choices = &color_font_choices();
13831: }
13832: if (ref($changes->{$role}) eq 'HASH') {
13833: if ($role ne 'login') {
13834: $resulttext .= '<h4>'.&mt($role).'</h4>';
13835: }
13836: foreach my $key (sort(keys(%{$changes->{$role}}))) {
13837: if ($role ne 'login') {
13838: $resulttext .= '<ul>';
13839: }
13840: if (ref($changes->{$role}{$key}) eq 'HASH') {
13841: if ($role ne 'login') {
13842: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
13843: }
13844: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 13845: if (($role eq 'login') && ($key eq 'showlogo')) {
13846: if ($confhash->{$role}{$key}{$item}) {
13847: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
13848: } else {
13849: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
13850: }
1.402 raeburn 13851: } elsif (($role eq 'login') && ($key eq 'alttext')) {
13852: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 13853: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 13854: $confhash->{$role}{$key}{$item}).'</li>';
13855: } else {
13856: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
13857: }
1.70 raeburn 13858: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 13859: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
13860: } else {
1.12 raeburn 13861: my $newitem = $confhash->{$role}{$item};
13862: if ($key eq 'images') {
1.306 raeburn 13863: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 13864: }
13865: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 13866: }
13867: }
13868: if ($role ne 'login') {
13869: $resulttext .= '</ul></li>';
13870: }
13871: } else {
13872: if ($confhash->{$role}{$key} eq '') {
13873: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
13874: } else {
13875: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
13876: }
13877: }
13878: if ($role ne 'login') {
13879: $resulttext .= '</ul>';
13880: }
13881: }
13882: }
13883: }
1.3 raeburn 13884: return $resulttext;
1.1 raeburn 13885: }
13886:
1.9 raeburn 13887: sub thumb_dimensions {
13888: return ('200','50');
13889: }
13890:
1.16 raeburn 13891: sub check_dimensions {
13892: my ($inputfile) = @_;
13893: my ($fullwidth,$fullheight);
13894: if ($inputfile =~ m|^[/\w.\-]+$|) {
13895: if (open(PIPE,"identify $inputfile 2>&1 |")) {
13896: my $imageinfo = <PIPE>;
13897: if (!close(PIPE)) {
13898: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
13899: }
13900: chomp($imageinfo);
13901: my ($fullsize) =
1.21 raeburn 13902: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 13903: if ($fullsize) {
13904: ($fullwidth,$fullheight) = split(/x/,$fullsize);
13905: }
13906: }
13907: }
13908: return ($fullwidth,$fullheight);
13909: }
13910:
1.9 raeburn 13911: sub check_configuser {
13912: my ($uhome,$dom,$confname,$servadm) = @_;
13913: my ($configuserok,%currroles);
13914: if ($uhome eq 'no_host') {
13915: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 13916: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 13917: $configuserok =
13918: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
13919: $configpass,'','','','','',undef,$servadm);
13920: } else {
13921: $configuserok = 'ok';
13922: %currroles =
13923: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
13924: }
13925: return ($configuserok,%currroles);
13926: }
13927:
13928: sub check_authorstatus {
13929: my ($dom,$confname,%currroles) = @_;
13930: my $author_ok;
1.40 raeburn 13931: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 13932: my $start = time;
13933: my $end = 0;
13934: $author_ok =
13935: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 13936: 'au',$end,$start,'','','domconfig');
1.9 raeburn 13937: } else {
13938: $author_ok = 'ok';
13939: }
13940: return $author_ok;
13941: }
13942:
1.421 raeburn 13943: sub update_modify_urls {
13944: my ($r,$modified) = @_;
13945: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
13946: push(@{$modified_urls},$modified);
13947: unless ($registered_cleanup) {
13948: my $handlers = $r->get_handlers('PerlCleanupHandler');
13949: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
13950: $registered_cleanup=1;
1.9 raeburn 13951: }
13952: }
1.155 raeburn 13953: }
13954:
13955: sub notifysubscribed {
13956: foreach my $targetsource (@{$modified_urls}){
13957: next unless (ref($targetsource) eq 'ARRAY');
13958: my ($target,$source)=@{$targetsource};
13959: if ($source ne '') {
1.316 raeburn 13960: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 13961: print $logfh "\nCleanup phase: Notifications\n";
13962: my @subscribed=&subscribed_hosts($target);
13963: foreach my $subhost (@subscribed) {
13964: print $logfh "\nNotifying host ".$subhost.':';
13965: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
13966: print $logfh $reply;
13967: }
13968: my @subscribedmeta=&subscribed_hosts("$target.meta");
13969: foreach my $subhost (@subscribedmeta) {
13970: print $logfh "\nNotifying host for metadata only ".$subhost.':';
13971: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
13972: $subhost);
13973: print $logfh $reply;
13974: }
13975: print $logfh "\n============ Done ============\n";
1.160 raeburn 13976: close($logfh);
1.155 raeburn 13977: }
13978: }
13979: }
13980: return OK;
13981: }
13982:
13983: sub subscribed_hosts {
13984: my ($target) = @_;
13985: my @subscribed;
1.316 raeburn 13986: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 13987: while (my $subline=<$fh>) {
13988: if ($subline =~ /^($match_lonid):/) {
13989: my $host = $1;
13990: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
13991: unless (grep(/^\Q$host\E$/,@subscribed)) {
13992: push(@subscribed,$host);
13993: }
13994: }
13995: }
13996: }
13997: }
13998: return @subscribed;
1.9 raeburn 13999: }
14000:
14001: sub check_switchserver {
14002: my ($dom,$confname) = @_;
1.424 raeburn 14003: my ($allowed,$switchserver,$home);
14004: if ($confname eq '') {
1.9 raeburn 14005: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14006: } else {
14007: $home = &Apache::lonnet::homeserver($confname,$dom);
14008: if ($home eq 'no_host') {
14009: $home = &Apache::lonnet::domain($dom,'primary');
14010: }
1.9 raeburn 14011: }
14012: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14013: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14014: if (!$allowed) {
1.426 raeburn 14015: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14016: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14017: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14018: }
14019: return $switchserver;
14020: }
14021:
1.1 raeburn 14022: sub modify_quotas {
1.216 raeburn 14023: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14024: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14025: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14026: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14027: $validationfieldsref);
1.86 raeburn 14028: if ($action eq 'quotas') {
1.429 ! raeburn 14029: $context = 'tools';
1.163 raeburn 14030: } else {
1.86 raeburn 14031: $context = $action;
14032: }
14033: if ($context eq 'requestcourses') {
1.325 raeburn 14034: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14035: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14036: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14037: %titles = &courserequest_titles();
14038: $toolregexp = join('|',@usertools);
14039: %conditions = &courserequest_conditions();
1.216 raeburn 14040: $confname = $dom.'-domainconfig';
14041: my $servadm = $r->dir_config('lonAdmEMail');
14042: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14043: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14044: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14045: } elsif ($context eq 'requestauthor') {
14046: @usertools = ('author');
14047: %titles = &authorrequest_titles();
1.86 raeburn 14048: } else {
1.429 ! raeburn 14049: @usertools = ('aboutme','blog','portfolio','timezone');
1.101 raeburn 14050: %titles = &tool_titles();
1.86 raeburn 14051: }
1.212 raeburn 14052: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14053: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14054: foreach my $key (keys(%env)) {
1.101 raeburn 14055: if ($context eq 'requestcourses') {
14056: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14057: my $item = $1;
14058: my $type = $2;
14059: if ($type =~ /^limit_(.+)/) {
14060: $limithash{$item}{$1} = $env{$key};
14061: } else {
14062: $confhash{$item}{$type} = $env{$key};
14063: }
14064: }
1.163 raeburn 14065: } elsif ($context eq 'requestauthor') {
14066: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14067: $confhash{$1} = $env{$key};
14068: }
1.101 raeburn 14069: } else {
1.86 raeburn 14070: if ($key =~ /^form\.quota_(.+)$/) {
14071: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14072: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14073: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14074: }
1.72 raeburn 14075: }
14076: }
1.163 raeburn 14077: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14078: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14079: @approvalnotify = sort(@approvalnotify);
14080: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14081: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14082: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14083: foreach my $type (@hasuniquecode) {
14084: if (grep(/^\Q$type\E$/,@crstypes)) {
14085: $confhash{'uniquecode'}{$type} = 1;
14086: }
1.216 raeburn 14087: }
1.242 raeburn 14088: my (%newbook,%allpos);
1.216 raeburn 14089: if ($context eq 'requestcourses') {
1.242 raeburn 14090: foreach my $type ('textbooks','templates') {
14091: @{$allpos{$type}} = ();
14092: my $invalid;
14093: if ($type eq 'textbooks') {
14094: $invalid = &mt('Invalid LON-CAPA course for textbook');
14095: } else {
14096: $invalid = &mt('Invalid LON-CAPA course for template');
14097: }
14098: if ($env{'form.'.$type.'_addbook'}) {
14099: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14100: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14101: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14102: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14103: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14104: } else {
14105: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14106: my $position = $env{'form.'.$type.'_addbook_pos'};
14107: $position =~ s/\D+//g;
14108: if ($position ne '') {
14109: $allpos{$type}[$position] = $newbook{$type};
14110: }
1.216 raeburn 14111: }
1.242 raeburn 14112: } else {
14113: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14114: }
14115: }
1.242 raeburn 14116: }
1.216 raeburn 14117: }
1.102 raeburn 14118: if (ref($domconfig{$action}) eq 'HASH') {
14119: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14120: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14121: $changes{'notify'}{'approval'} = 1;
14122: }
14123: } else {
1.144 raeburn 14124: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14125: $changes{'notify'}{'approval'} = 1;
14126: }
14127: }
1.218 raeburn 14128: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14129: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14130: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14131: unless ($confhash{'uniquecode'}{$crstype}) {
14132: $changes{'uniquecode'} = 1;
14133: }
14134: }
14135: unless ($changes{'uniquecode'}) {
14136: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14137: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14138: $changes{'uniquecode'} = 1;
14139: }
14140: }
14141: }
14142: } else {
14143: $changes{'uniquecode'} = 1;
14144: }
14145: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14146: $changes{'uniquecode'} = 1;
1.216 raeburn 14147: }
14148: if ($context eq 'requestcourses') {
1.242 raeburn 14149: foreach my $type ('textbooks','templates') {
14150: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14151: my %deletions;
14152: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14153: if (@todelete) {
14154: map { $deletions{$_} = 1; } @todelete;
14155: }
14156: my %imgdeletions;
14157: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14158: if (@todeleteimages) {
14159: map { $imgdeletions{$_} = 1; } @todeleteimages;
14160: }
14161: my $maxnum = $env{'form.'.$type.'_maxnum'};
14162: for (my $i=0; $i<=$maxnum; $i++) {
14163: my $itemid = $env{'form.'.$type.'_id_'.$i};
14164: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14165: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14166: if ($deletions{$key}) {
14167: if ($domconfig{$action}{$type}{$key}{'image'}) {
14168: #FIXME need to obsolete item in RES space
14169: }
14170: next;
14171: } else {
14172: my $newpos = $env{'form.'.$itemid};
14173: $newpos =~ s/\D+//g;
1.243 raeburn 14174: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14175: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14176: ($type eq 'templates'));
1.242 raeburn 14177: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14178: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14179: $changes{$type}{$key} = 1;
14180: }
14181: }
14182: $allpos{$type}[$newpos] = $key;
14183: }
14184: if ($imgdeletions{$key}) {
14185: $changes{$type}{$key} = 1;
1.216 raeburn 14186: #FIXME need to obsolete item in RES space
1.242 raeburn 14187: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14188: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14189: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14190: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14191: } else {
14192: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14193: $cdom,$cnum,$type,$configuserok,
14194: $switchserver,$author_ok);
14195: if ($imgurl) {
14196: $confhash{$type}{$key}{'image'} = $imgurl;
14197: $changes{$type}{$key} = 1;
14198: }
14199: if ($error) {
14200: &Apache::lonnet::logthis($error);
14201: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14202: }
14203: }
1.242 raeburn 14204: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14205: $confhash{$type}{$key}{'image'} =
14206: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14207: }
14208: }
14209: }
14210: }
14211: }
14212: }
1.102 raeburn 14213: } else {
1.144 raeburn 14214: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14215: $changes{'notify'}{'approval'} = 1;
14216: }
1.218 raeburn 14217: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14218: $changes{'uniquecode'} = 1;
14219: }
14220: }
14221: if ($context eq 'requestcourses') {
1.242 raeburn 14222: foreach my $type ('textbooks','templates') {
14223: if ($newbook{$type}) {
14224: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14225: foreach my $item ('subject','title','publisher','author') {
14226: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14227: ($type eq 'template'));
1.242 raeburn 14228: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14229: if ($env{'form.'.$type.'_addbook_'.$item}) {
14230: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14231: }
14232: }
14233: if ($type eq 'textbooks') {
14234: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14235: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14236: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14237: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14238: } else {
14239: my ($imageurl,$error) =
14240: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14241: $configuserok,$switchserver,$author_ok);
14242: if ($imageurl) {
14243: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14244: }
14245: if ($error) {
14246: &Apache::lonnet::logthis($error);
14247: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14248: }
1.242 raeburn 14249: }
14250: }
1.216 raeburn 14251: }
14252: }
1.242 raeburn 14253: if (@{$allpos{$type}} > 0) {
14254: my $idx = 0;
14255: foreach my $item (@{$allpos{$type}}) {
14256: if ($item ne '') {
14257: $confhash{$type}{$item}{'order'} = $idx;
14258: if (ref($domconfig{$action}) eq 'HASH') {
14259: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14260: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14261: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14262: $changes{$type}{$item} = 1;
14263: }
1.216 raeburn 14264: }
14265: }
14266: }
1.242 raeburn 14267: $idx ++;
1.216 raeburn 14268: }
14269: }
14270: }
14271: }
1.235 raeburn 14272: if (ref($validationitemsref) eq 'ARRAY') {
14273: foreach my $item (@{$validationitemsref}) {
14274: if ($item eq 'fields') {
14275: my @changed;
14276: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14277: if (@{$confhash{'validation'}{$item}} > 0) {
14278: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14279: }
1.266 raeburn 14280: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14281: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14282: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14283: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14284: $domconfig{'requestcourses'}{'validation'}{$item});
14285: } else {
14286: @changed = @{$confhash{'validation'}{$item}};
14287: }
1.235 raeburn 14288: } else {
14289: @changed = @{$confhash{'validation'}{$item}};
14290: }
14291: } else {
14292: @changed = @{$confhash{'validation'}{$item}};
14293: }
14294: if (@changed) {
14295: if ($confhash{'validation'}{$item}) {
14296: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14297: } else {
14298: $changes{'validation'}{$item} = &mt('None');
14299: }
14300: }
14301: } else {
14302: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14303: if ($item eq 'markup') {
14304: if ($env{'form.requestcourses_validation_'.$item}) {
14305: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14306: }
14307: }
1.266 raeburn 14308: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14309: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14310: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14311: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14312: }
14313: } else {
14314: if ($confhash{'validation'}{$item} ne '') {
14315: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14316: }
1.235 raeburn 14317: }
14318: } else {
14319: if ($confhash{'validation'}{$item} ne '') {
14320: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14321: }
14322: }
14323: }
14324: }
14325: }
14326: if ($env{'form.validationdc'}) {
14327: my $newval = $env{'form.validationdc'};
1.285 raeburn 14328: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14329: if (exists($domcoords{$newval})) {
14330: $confhash{'validation'}{'dc'} = $newval;
14331: }
14332: }
14333: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14334: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14335: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14336: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14337: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14338: if ($confhash{'validation'}{'dc'} eq '') {
14339: $changes{'validation'}{'dc'} = &mt('None');
14340: } else {
14341: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14342: }
1.235 raeburn 14343: }
1.266 raeburn 14344: } elsif ($confhash{'validation'}{'dc'} ne '') {
14345: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14346: }
14347: } elsif ($confhash{'validation'}{'dc'} ne '') {
14348: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14349: }
14350: } elsif ($confhash{'validation'}{'dc'} ne '') {
14351: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14352: }
1.266 raeburn 14353: } else {
14354: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14355: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14356: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14357: $changes{'validation'}{'dc'} = &mt('None');
14358: }
14359: }
1.235 raeburn 14360: }
14361: }
1.102 raeburn 14362: }
14363: } else {
1.86 raeburn 14364: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14365: }
1.72 raeburn 14366: foreach my $item (@usertools) {
14367: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14368: my $unset;
1.101 raeburn 14369: if ($context eq 'requestcourses') {
1.104 raeburn 14370: $unset = '0';
14371: if ($type eq '_LC_adv') {
14372: $unset = '';
14373: }
1.101 raeburn 14374: if ($confhash{$item}{$type} eq 'autolimit') {
14375: $confhash{$item}{$type} .= '=';
14376: unless ($limithash{$item}{$type} =~ /\D/) {
14377: $confhash{$item}{$type} .= $limithash{$item}{$type};
14378: }
14379: }
1.163 raeburn 14380: } elsif ($context eq 'requestauthor') {
14381: $unset = '0';
14382: if ($type eq '_LC_adv') {
14383: $unset = '';
14384: }
1.72 raeburn 14385: } else {
1.101 raeburn 14386: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14387: $confhash{$item}{$type} = 1;
14388: } else {
14389: $confhash{$item}{$type} = 0;
14390: }
1.72 raeburn 14391: }
1.86 raeburn 14392: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14393: if ($action eq 'requestauthor') {
14394: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14395: $changes{$type} = 1;
14396: }
14397: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14398: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14399: $changes{$item}{$type} = 1;
14400: }
14401: } else {
14402: if ($context eq 'requestcourses') {
1.104 raeburn 14403: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14404: $changes{$item}{$type} = 1;
14405: }
14406: } else {
14407: if (!$confhash{$item}{$type}) {
14408: $changes{$item}{$type} = 1;
14409: }
14410: }
14411: }
14412: } else {
14413: if ($context eq 'requestcourses') {
1.104 raeburn 14414: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14415: $changes{$item}{$type} = 1;
14416: }
1.163 raeburn 14417: } elsif ($context eq 'requestauthor') {
14418: if ($confhash{$type} ne $unset) {
14419: $changes{$type} = 1;
14420: }
1.72 raeburn 14421: } else {
14422: if (!$confhash{$item}{$type}) {
14423: $changes{$item}{$type} = 1;
14424: }
14425: }
14426: }
1.1 raeburn 14427: }
14428: }
1.163 raeburn 14429: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14430: if (ref($domconfig{'quotas'}) eq 'HASH') {
14431: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14432: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14433: if (exists($confhash{'defaultquota'}{$key})) {
14434: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14435: $changes{'defaultquota'}{$key} = 1;
14436: }
14437: } else {
14438: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14439: }
14440: }
1.86 raeburn 14441: } else {
14442: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14443: if (exists($confhash{'defaultquota'}{$key})) {
14444: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14445: $changes{'defaultquota'}{$key} = 1;
14446: }
14447: } else {
14448: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14449: }
1.1 raeburn 14450: }
14451: }
1.197 raeburn 14452: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 ! raeburn 14453: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
! 14454: }
! 14455: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
! 14456: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14457: }
1.1 raeburn 14458: }
1.86 raeburn 14459: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14460: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14461: if (ref($domconfig{'quotas'}) eq 'HASH') {
14462: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14463: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14464: $changes{'defaultquota'}{$key} = 1;
14465: }
14466: } else {
14467: if (!exists($domconfig{'quotas'}{$key})) {
14468: $changes{'defaultquota'}{$key} = 1;
14469: }
1.72 raeburn 14470: }
14471: } else {
1.86 raeburn 14472: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14473: }
1.1 raeburn 14474: }
14475: }
14476: }
1.72 raeburn 14477:
1.163 raeburn 14478: if ($context eq 'requestauthor') {
14479: $domdefaults{'requestauthor'} = \%confhash;
14480: } else {
14481: foreach my $key (keys(%confhash)) {
1.242 raeburn 14482: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14483: $domdefaults{$key} = $confhash{$key};
14484: }
1.163 raeburn 14485: }
1.72 raeburn 14486: }
1.163 raeburn 14487:
1.1 raeburn 14488: my %quotahash = (
1.86 raeburn 14489: $action => { %confhash }
1.1 raeburn 14490: );
14491: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14492: $dom);
14493: if ($putresult eq 'ok') {
14494: if (keys(%changes) > 0) {
1.72 raeburn 14495: my $cachetime = 24*60*60;
14496: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14497: if (ref($lastactref) eq 'HASH') {
14498: $lastactref->{'domdefaults'} = 1;
14499: }
1.1 raeburn 14500: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14501: unless (($context eq 'requestcourses') ||
1.163 raeburn 14502: ($context eq 'requestauthor')) {
1.86 raeburn 14503: if (ref($changes{'defaultquota'}) eq 'HASH') {
14504: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14505: foreach my $type (@{$types},'default') {
14506: if (defined($changes{'defaultquota'}{$type})) {
14507: my $typetitle = $usertypes->{$type};
14508: if ($type eq 'default') {
14509: $typetitle = $othertitle;
14510: }
1.213 raeburn 14511: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14512: }
14513: }
1.86 raeburn 14514: $resulttext .= '</ul></li>';
1.72 raeburn 14515: }
14516: }
1.80 raeburn 14517: my %newenv;
1.72 raeburn 14518: foreach my $item (@usertools) {
1.163 raeburn 14519: my (%haschgs,%inconf);
14520: if ($context eq 'requestauthor') {
14521: %haschgs = %changes;
1.210 raeburn 14522: %inconf = %confhash;
1.163 raeburn 14523: } else {
14524: if (ref($changes{$item}) eq 'HASH') {
14525: %haschgs = %{$changes{$item}};
14526: }
14527: if (ref($confhash{$item}) eq 'HASH') {
14528: %inconf = %{$confhash{$item}};
14529: }
14530: }
14531: if (keys(%haschgs) > 0) {
1.80 raeburn 14532: my $newacc =
14533: &Apache::lonnet::usertools_access($env{'user.name'},
14534: $env{'user.domain'},
1.86 raeburn 14535: $item,'reload',$context);
1.210 raeburn 14536: if (($context eq 'requestcourses') ||
1.163 raeburn 14537: ($context eq 'requestauthor')) {
1.108 raeburn 14538: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14539: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14540: }
14541: } else {
14542: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14543: $newenv{'environment.availabletools.'.$item} = $newacc;
14544: }
1.80 raeburn 14545: }
1.163 raeburn 14546: unless ($context eq 'requestauthor') {
14547: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14548: }
1.72 raeburn 14549: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14550: if ($haschgs{$type}) {
1.72 raeburn 14551: my $typetitle = $usertypes->{$type};
14552: if ($type eq 'default') {
14553: $typetitle = $othertitle;
14554: } elsif ($type eq '_LC_adv') {
14555: $typetitle = 'LON-CAPA Advanced Users';
14556: }
1.163 raeburn 14557: if ($inconf{$type}) {
1.101 raeburn 14558: if ($context eq 'requestcourses') {
14559: my $cond;
1.163 raeburn 14560: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14561: if ($1 eq '') {
14562: $cond = &mt('(Automatic processing of any request).');
14563: } else {
14564: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14565: }
14566: } else {
1.163 raeburn 14567: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14568: }
14569: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14570: } elsif ($context eq 'requestauthor') {
14571: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14572: $titles{$inconf{$type}},$typetitle);
14573:
1.101 raeburn 14574: } else {
14575: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14576: }
1.72 raeburn 14577: } else {
1.104 raeburn 14578: if ($type eq '_LC_adv') {
1.163 raeburn 14579: if ($inconf{$type} eq '0') {
1.104 raeburn 14580: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14581: } else {
14582: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14583: }
14584: } else {
14585: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14586: }
1.72 raeburn 14587: }
14588: }
1.26 raeburn 14589: }
1.163 raeburn 14590: unless ($context eq 'requestauthor') {
14591: $resulttext .= '</ul></li>';
14592: }
1.26 raeburn 14593: }
1.1 raeburn 14594: }
1.163 raeburn 14595: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14596: if (ref($changes{'notify'}) eq 'HASH') {
14597: if ($changes{'notify'}{'approval'}) {
14598: if (ref($confhash{'notify'}) eq 'HASH') {
14599: if ($confhash{'notify'}{'approval'}) {
14600: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14601: } else {
1.163 raeburn 14602: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14603: }
14604: }
14605: }
14606: }
14607: }
1.216 raeburn 14608: if ($action eq 'requestcourses') {
14609: my @offon = ('off','on');
14610: if ($changes{'uniquecode'}) {
1.218 raeburn 14611: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14612: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14613: $resulttext .= '<li>'.
14614: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14615: '</li>';
14616: } else {
14617: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14618: '</li>';
14619: }
1.216 raeburn 14620: }
1.242 raeburn 14621: foreach my $type ('textbooks','templates') {
14622: if (ref($changes{$type}) eq 'HASH') {
14623: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14624: foreach my $key (sort(keys(%{$changes{$type}}))) {
14625: my %coursehash = &Apache::lonnet::coursedescription($key);
14626: my $coursetitle = $coursehash{'description'};
14627: my $position = $confhash{$type}{$key}{'order'} + 1;
14628: $resulttext .= '<li>';
1.243 raeburn 14629: foreach my $item ('subject','title','publisher','author') {
14630: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14631: ($type eq 'templates'));
1.242 raeburn 14632: my $name = $item.':';
14633: $name =~ s/^(\w)/\U$1/;
14634: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14635: }
14636: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14637: if ($type eq 'textbooks') {
14638: if ($confhash{$type}{$key}{'image'}) {
14639: $resulttext .= ' '.&mt('Image: [_1]',
14640: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14641: ' alt="Textbook cover" />').'<br />';
14642: }
14643: }
14644: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14645: }
1.242 raeburn 14646: $resulttext .= '</ul></li>';
1.216 raeburn 14647: }
14648: }
1.235 raeburn 14649: if (ref($changes{'validation'}) eq 'HASH') {
14650: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14651: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14652: foreach my $item (@{$validationitemsref}) {
14653: if (exists($changes{'validation'}{$item})) {
14654: if ($item eq 'markup') {
14655: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14656: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14657: } else {
14658: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14659: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14660: }
14661: }
14662: }
14663: if (exists($changes{'validation'}{'dc'})) {
14664: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14665: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14666: }
14667: }
14668: }
1.216 raeburn 14669: }
1.1 raeburn 14670: $resulttext .= '</ul>';
1.80 raeburn 14671: if (keys(%newenv)) {
14672: &Apache::lonnet::appenv(\%newenv);
14673: }
1.1 raeburn 14674: } else {
1.86 raeburn 14675: if ($context eq 'requestcourses') {
14676: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14677: } elsif ($context eq 'requestauthor') {
14678: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14679: } else {
1.90 weissno 14680: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14681: }
1.1 raeburn 14682: }
14683: } else {
1.11 albertel 14684: $resulttext = '<span class="LC_error">'.
14685: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14686: }
1.216 raeburn 14687: if ($errors) {
14688: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14689: '<ul>'.$errors.'</ul></p>';
14690: }
1.3 raeburn 14691: return $resulttext;
1.1 raeburn 14692: }
14693:
1.216 raeburn 14694: sub process_textbook_image {
1.242 raeburn 14695: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14696: my $filename = $env{'form.'.$caller.'.filename'};
14697: my ($error,$url);
14698: my ($width,$height) = (50,50);
14699: if ($configuserok eq 'ok') {
14700: if ($switchserver) {
14701: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14702: $switchserver);
14703: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14704: my $modified = [];
1.216 raeburn 14705: my ($result,$imageurl) =
1.421 raeburn 14706: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14707: "$type/$cdom/$cnum/cover",$width,$height,
14708: '',$modified);
1.216 raeburn 14709: if ($result eq 'ok') {
14710: $url = $imageurl;
1.421 raeburn 14711: &update_modify_urls($r,$modified);
1.216 raeburn 14712: } else {
14713: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14714: }
14715: } else {
14716: $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);
14717: }
14718: } else {
14719: $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);
14720: }
14721: return ($url,$error);
14722: }
14723:
1.267 raeburn 14724: sub modify_ltitools {
14725: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14726: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14727: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14728:
1.267 raeburn 14729: my $confname = $dom.'-domainconfig';
14730: my $servadm = $r->dir_config('lonAdmEMail');
14731: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14732:
14733: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14734: my $toolserror =
14735: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14736: $lastactref,$configuserok,$switchserver,$author_ok);
14737:
14738: my $home = &Apache::lonnet::domain($dom,'primary');
14739: unless (($home eq 'no_host') || ($home eq '')) {
14740: my @ids=&Apache::lonnet::current_machine_ids();
14741: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14742: }
14743:
14744: if (keys(%ltitoolschg)) {
14745: foreach my $id (keys(%ltitoolschg)) {
14746: if (ref($ltitoolschg{$id}) eq 'HASH') {
14747: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14748: if (($inner eq 'secret') || ($inner eq 'key')) {
14749: if ($is_home) {
14750: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14751: }
14752: }
14753: }
1.267 raeburn 14754: }
1.421 raeburn 14755: }
14756: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14757: if (keys(%ltitoolschg)) {
14758: %newltitools = %ltitoolschg;
14759: }
14760: }
14761: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14762: foreach my $id (%{$domconfig{'ltitools'}}) {
14763: next if ($id !~ /^\d+$/);
14764: unless (exists($ltitoolschg{$id})) {
14765: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14766: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14767: if (($inner eq 'secret') || ($inner eq 'key')) {
14768: if ($is_home) {
14769: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14770: }
14771: } else {
14772: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14773: }
14774: }
14775: } else {
14776: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14777: }
1.421 raeburn 14778: }
14779: }
14780: }
14781: if ($toolserror) {
14782: $errors = '<li>'.$toolserror.'</li>';
14783: }
14784: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14785: $resulttext = &mt('No changes made.');
14786: if ($errors) {
14787: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14788: $errors.'</ul>';
14789: }
14790: return $resulttext;
14791: }
14792: my %ltitoolshash = (
14793: $action => { %newltitools }
14794: );
14795: if (keys(%secchanges)) {
14796: $ltitoolshash{'toolsec'} = \%newtoolsec;
14797: }
14798: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14799: if ($putresult eq 'ok') {
14800: my %keystore;
14801: if ($is_home) {
14802: my %toolsenchash = (
14803: $action => { %newtoolsenc }
14804: );
14805: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 14806: my $cachetime = 24*60*60;
14807: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 14808: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
14809: }
14810: $resulttext = &mt('Changes made:').'<ul>';
14811: if (keys(%secchanges) > 0) {
1.423 raeburn 14812: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 14813: }
14814: if (keys(%ltitoolschg) > 0) {
14815: $resulttext .= $ltitoolsoutput;
14816: }
1.423 raeburn 14817: my $cachetime = 24*60*60;
14818: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
14819: if (ref($lastactref) eq 'HASH') {
14820: $lastactref->{'ltitools'} = 1;
14821: }
1.421 raeburn 14822: } else {
14823: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14824: }
14825: if ($errors) {
14826: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14827: $errors.'</ul></p>';
14828: }
14829: return $resulttext;
14830: }
14831:
14832: sub fetch_secrets {
14833: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
14834: my %keyset;
14835: %{$currsec} = ();
14836: $newsec->{'private'}{'keys'} = [];
14837: $newsec->{'encrypt'} = {};
14838: $newsec->{'rules'} = {};
14839: if ($context eq 'ltisec') {
14840: $newsec->{'linkprot'} = {};
14841: }
14842: if (ref($domconfig->{$context}) eq 'HASH') {
14843: %{$currsec} = %{$domconfig->{$context}};
14844: if ($context eq 'ltisec') {
14845: if (ref($currsec->{'linkprot'}) eq 'HASH') {
14846: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
14847: unless ($id =~ /^\d+$/) {
14848: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 14849: }
1.267 raeburn 14850: }
14851: }
1.421 raeburn 14852: }
14853: if (ref($currsec->{'private'}) eq 'HASH') {
14854: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
14855: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
14856: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 14857: }
1.421 raeburn 14858: }
14859: }
14860: my @items= ('crs','dom');
14861: if ($context eq 'ltisec') {
14862: push(@items,'consumers');
14863: }
14864: foreach my $item (@items) {
14865: my $formelement;
14866: if (($context eq 'toolsec') || ($item eq 'consumers')) {
14867: $formelement = 'form.'.$context.'_'.$item;
14868: } else {
14869: $formelement = 'form.'.$context.'_'.$item.'linkprot';
14870: }
14871: if ($env{$formelement}) {
14872: $newsec->{'encrypt'}{$item} = 1;
14873: if (ref($currsec->{'encrypt'}) eq 'HASH') {
14874: unless ($currsec->{'encrypt'}{$item}) {
14875: $secchanges->{'encrypt'} = 1;
14876: }
14877: } else {
14878: $secchanges->{'encrypt'} = 1;
1.267 raeburn 14879: }
1.421 raeburn 14880: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
14881: if ($currsec->{'encrypt'}{$item}) {
14882: $secchanges->{'encrypt'} = 1;
1.323 raeburn 14883: }
1.421 raeburn 14884: }
14885: }
14886: my $secrets;
14887: if ($context eq 'ltisec') {
14888: $secrets = 'ltisecrets';
14889: } else {
14890: $secrets = 'toolsecrets';
14891: }
14892: unless (exists($currsec->{'rules'})) {
14893: $currsec->{'rules'} = {};
14894: }
14895: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
14896:
14897: my @ids=&Apache::lonnet::current_machine_ids();
14898: my %servers = &Apache::lonnet::get_servers($dom,'library');
14899:
14900: foreach my $hostid (keys(%servers)) {
14901: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
14902: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
14903: if (exists($env{$keyitem})) {
14904: $env{$keyitem} =~ s/(`)/'/g;
14905: if ($keyset{$hostid}) {
14906: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
14907: if ($env{$keyitem} ne '') {
14908: $secchanges->{'private'} = 1;
14909: $newkeyset->{$hostid} = $env{$keyitem};
14910: }
1.296 raeburn 14911: }
1.421 raeburn 14912: } elsif ($env{$keyitem} ne '') {
14913: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
14914: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 14915: }
1.421 raeburn 14916: $secchanges->{'private'} = 1;
14917: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 14918: }
14919: }
1.421 raeburn 14920: }
14921: }
14922: }
14923:
14924: sub store_security {
1.424 raeburn 14925: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 14926: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
14927: (ref($keystore) eq 'HASH'));
14928: if (keys(%{$secchanges})) {
14929: if ($secchanges->{'private'}) {
14930: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
14931: foreach my $hostid (keys(%{$newkeyset})) {
14932: my $storehash = {
14933: key => $newkeyset->{$hostid},
14934: who => $env{'user.name'}.':'.$env{'user.domain'},
14935: };
14936: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
14937: $dom,$hostid);
14938: }
14939: }
14940: }
14941: }
14942:
14943: sub lti_security_results {
1.423 raeburn 14944: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 14945: my $output;
1.423 raeburn 14946: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14947: my $needs_update;
1.421 raeburn 14948: foreach my $item (keys(%{$secchanges})) {
14949: if ($item eq 'encrypt') {
1.423 raeburn 14950: $needs_update = 1;
1.421 raeburn 14951: my %encrypted;
14952: if ($context eq 'lti') {
14953: %encrypted = (
14954: crs => {
14955: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
14956: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
14957: },
14958: dom => {
14959: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
14960: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
14961: },
14962: consumers => {
14963: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
14964: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
14965: },
14966: );
1.267 raeburn 14967: } else {
1.421 raeburn 14968: %encrypted = (
14969: crs => {
14970: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
14971: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
14972: },
14973: dom => {
14974: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
14975: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
14976: },
14977: );
14978:
14979: }
14980: my @types= ('crs','dom');
14981: if ($context eq 'lti') {
1.423 raeburn 14982: foreach my $type (@types) {
14983: undef($domdefaults{'linkprotenc_'.$type});
14984: }
1.421 raeburn 14985: push(@types,'consumers');
1.423 raeburn 14986: undef($domdefaults{'ltienc_consumers'});
14987: } elsif ($context eq 'ltitools') {
14988: foreach my $type (@types) {
14989: undef($domdefaults{'toolenc_'.$type});
14990: }
1.267 raeburn 14991: }
1.421 raeburn 14992: foreach my $type (@types) {
14993: my $shown = $encrypted{$type}{'off'};
14994: if (ref($newsec->{$item}) eq 'HASH') {
14995: if ($newsec->{$item}{$type}) {
1.423 raeburn 14996: if ($context eq 'lti') {
14997: if ($type eq 'consumers') {
14998: $domdefaults{'ltienc_consumers'} = 1;
14999: } else {
15000: $domdefaults{'linkprotenc_'.$type} = 1;
15001: }
15002: } elsif ($context eq 'ltitools') {
15003: $domdefaults{'toolenc_'.$type} = 1;
15004: }
1.421 raeburn 15005: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15006: }
1.267 raeburn 15007: }
1.421 raeburn 15008: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15009: }
1.421 raeburn 15010: } elsif ($item eq 'rules') {
15011: my %titles = &Apache::lonlocal::texthash(
15012: min => 'Minimum password length',
15013: max => 'Maximum password length',
15014: chars => 'Required characters',
15015: );
15016: foreach my $rule ('min','max') {
15017: if ($newsec->{rules}{$rule} eq '') {
15018: if ($rule eq 'min') {
15019: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15020: ' '.&mt('Default of [_1] will be used',
15021: $Apache::lonnet::passwdmin).'</li>';
15022: } else {
15023: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15024: }
15025: } else {
15026: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15027: }
15028: }
15029: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15030: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15031: my %rulenames = &Apache::lonlocal::texthash(
15032: uc => 'At least one upper case letter',
15033: lc => 'At least one lower case letter',
15034: num => 'At least one number',
15035: spec => 'At least one non-alphanumeric',
15036: );
15037: my $needed = '<ul><li>'.
15038: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15039: '</li></ul>';
15040: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15041: } else {
15042: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15043: }
1.421 raeburn 15044: } else {
15045: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15046: }
1.421 raeburn 15047: } elsif ($item eq 'private') {
1.423 raeburn 15048: $needs_update = 1;
15049: if ($context eq 'lti') {
15050: undef($domdefaults{'ltiprivhosts'});
15051: } elsif ($context eq 'ltitools') {
15052: undef($domdefaults{'toolprivhosts'});
15053: }
1.421 raeburn 15054: if (keys(%{$newkeyset})) {
1.423 raeburn 15055: my @privhosts;
1.421 raeburn 15056: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15057: if ($keystore->{$hostid} eq 'ok') {
15058: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15059: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15060: push(@privhosts,$hostid);
15061: }
15062: }
15063: }
15064: if (@privhosts) {
15065: if ($context eq 'lti') {
15066: $domdefaults{'ltiprivhosts'} = \@privhosts;
15067: } elsif ($context eq 'ltitools') {
15068: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15069: }
15070: }
15071: }
1.421 raeburn 15072: } elsif ($item eq 'linkprot') {
15073: next;
1.267 raeburn 15074: }
15075: }
1.423 raeburn 15076: if ($needs_update) {
15077: my $cachetime = 24*60*60;
15078: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15079: }
1.421 raeburn 15080: return $output;
15081: }
15082:
15083: sub modify_proctoring {
15084: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15085: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15086: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15087: my $confname = $dom.'-domainconfig';
15088: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15089: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15090: my %providernames = &proctoring_providernames();
15091: my $maxnum = scalar(keys(%providernames));
15092:
15093: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15094: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15095: if (ref($requref) eq 'HASH') {
15096: %requserfields = %{$requref};
15097: }
15098: if (ref($opturef) eq 'HASH') {
15099: %optuserfields = %{$opturef};
15100: }
15101: if (ref($defref) eq 'HASH') {
15102: %defaults = %{$defref};
15103: }
15104: if (ref($extref) eq 'HASH') {
15105: %extended = %{$extref};
15106: }
15107: if (ref($crsref) eq 'HASH') {
15108: %crsconf = %{$crsref};
15109: }
15110: if (ref($rolesref) eq 'ARRAY') {
15111: @courseroles = @{$rolesref};
15112: }
15113: if (ref($ltiref) eq 'ARRAY') {
15114: @ltiroles = @{$ltiref};
15115: }
15116:
15117: if (ref($domconfig{$action}) eq 'HASH') {
15118: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15119: if (@todeleteimages) {
15120: map { $imgdeletions{$_} = 1; } @todeleteimages;
15121: }
15122: }
15123: my %customadds;
15124: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15125: if (@newcustom) {
15126: map { $customadds{$_} = 1; } @newcustom;
15127: }
15128: foreach my $provider (sort(keys(%providernames))) {
15129: $confhash{$provider} = {};
15130: my $pos = $env{'form.proctoring_pos_'.$provider};
15131: $pos =~ s/\D+//g;
15132: $allpos[$pos] = $provider;
15133: my (%current,%currentenc);
15134: my $showroles = 0;
15135: if (ref($domconfig{$action}) eq 'HASH') {
15136: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15137: %current = %{$domconfig{$action}{$provider}};
15138: foreach my $item ('key','secret') {
15139: $currentenc{$item} = $current{$item};
15140: delete($current{$item});
15141: }
15142: }
15143: }
15144: if ($env{'form.proctoring_available_'.$provider}) {
15145: $confhash{$provider}{'available'} = 1;
15146: unless ($current{'available'}) {
15147: $changes{$provider} = 1;
15148: }
15149: } else {
15150: %{$confhash{$provider}} = %current;
15151: %{$encconfhash{$provider}} = %currentenc;
15152: $confhash{$provider}{'available'} = 0;
15153: if ($current{'available'}) {
15154: $changes{$provider} = 1;
15155: }
15156: }
15157: if ($confhash{$provider}{'available'}) {
15158: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15159: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15160: if ($field eq 'lifetime') {
15161: if ($possval =~ /^\d+$/) {
15162: $confhash{$provider}{$field} = $possval;
15163: }
15164: } elsif ($field eq 'version') {
15165: if ($possval =~ /^\d+\.\d+$/) {
15166: $confhash{$provider}{$field} = $possval;
15167: }
15168: } elsif ($field eq 'sigmethod') {
15169: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15170: $confhash{$provider}{$field} = $possval;
15171: }
15172: } elsif ($field eq 'url') {
15173: $confhash{$provider}{$field} = $possval;
15174: } elsif (($field eq 'key') || ($field eq 'secret')) {
15175: $encconfhash{$provider}{$field} = $possval;
15176: unless ($currentenc{$field} eq $possval) {
15177: $changes{$provider} = 1;
15178: }
15179: }
15180: unless (($field eq 'key') || ($field eq 'secret')) {
15181: unless ($current{$field} eq $confhash{$provider}{$field}) {
15182: $changes{$provider} = 1;
15183: }
15184: }
15185: }
15186: if ($imgdeletions{$provider}) {
15187: $changes{$provider} = 1;
15188: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15189: my ($imageurl,$error) =
15190: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15191: $configuserok,$switchserver,$author_ok);
15192: if ($imageurl) {
15193: $confhash{$provider}{'image'} = $imageurl;
15194: $changes{$provider} = 1;
15195: }
15196: if ($error) {
15197: &Apache::lonnet::logthis($error);
15198: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15199: }
15200: } elsif (exists($current{'image'})) {
15201: $confhash{$provider}{'image'} = $current{'image'};
15202: }
15203: if (ref($requserfields{$provider}) eq 'ARRAY') {
15204: if (@{$requserfields{$provider}} > 0) {
15205: if (grep(/^user$/,@{$requserfields{$provider}})) {
15206: if ($env{'form.proctoring_userincdom_'.$provider}) {
15207: $confhash{$provider}{'incdom'} = 1;
15208: }
15209: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15210: $changes{$provider} = 1;
15211: }
15212: }
15213: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15214: $showroles = 1;
15215: }
15216: }
15217: }
15218: $confhash{$provider}{'fields'} = [];
15219: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15220: if (@{$optuserfields{$provider}} > 0) {
15221: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15222: foreach my $field (@{$optuserfields{$provider}}) {
15223: if (grep(/^\Q$field\E$/,@optfields)) {
15224: push(@{$confhash{$provider}{'fields'}},$field);
15225: }
15226: }
15227: }
15228: if (ref($current{'fields'}) eq 'ARRAY') {
15229: unless ($changes{$provider}) {
15230: my @new = sort(@{$confhash{$provider}{'fields'}});
15231: my @old = sort(@{$current{'fields'}});
15232: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15233: if (@diffs) {
15234: $changes{$provider} = 1;
15235: }
15236: }
15237: } elsif (@{$confhash{$provider}{'fields'}}) {
15238: $changes{$provider} = 1;
15239: }
15240: }
15241: if (ref($defaults{$provider}) eq 'ARRAY') {
15242: if (@{$defaults{$provider}} > 0) {
15243: my %options;
15244: if (ref($extended{$provider}) eq 'HASH') {
15245: %options = %{$extended{$provider}};
15246: }
15247: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15248: foreach my $field (@{$defaults{$provider}}) {
15249: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15250: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15251: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15252: push(@{$confhash{$provider}{'defaults'}},$poss);
15253: }
15254: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15255: foreach my $inner (keys(%{$options{$field}})) {
15256: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15257: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15258: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15259: $confhash{$provider}{'defaults'}{$inner} = $poss;
15260: }
15261: } else {
15262: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15263: }
15264: }
15265: } else {
15266: if (grep(/^\Q$field\E$/,@checked)) {
15267: push(@{$confhash{$provider}{'defaults'}},$field);
15268: }
15269: }
15270: }
15271: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15272: if (ref($current{'defaults'}) eq 'ARRAY') {
15273: unless ($changes{$provider}) {
15274: my @new = sort(@{$confhash{$provider}{'defaults'}});
15275: my @old = sort(@{$current{'defaults'}});
15276: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15277: if (@diffs) {
15278: $changes{$provider} = 1;
15279: }
15280: }
15281: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15282: if (@{$current{'defaults'}}) {
15283: $changes{$provider} = 1;
15284: }
15285: }
15286: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15287: if (ref($current{'defaults'}) eq 'HASH') {
15288: unless ($changes{$provider}) {
15289: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15290: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15291: $changes{$provider} = 1;
15292: last;
15293: }
15294: }
15295: }
15296: unless ($changes{$provider}) {
15297: foreach my $key (keys(%{$current{'defaults'}})) {
15298: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15299: $changes{$provider} = 1;
15300: last;
15301: }
15302: }
15303: }
15304: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15305: $changes{$provider} = 1;
15306: }
15307: }
15308: }
15309: }
15310: if (ref($crsconf{$provider}) eq 'ARRAY') {
15311: if (@{$crsconf{$provider}} > 0) {
15312: $confhash{$provider}{'crsconf'} = [];
15313: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15314: foreach my $crsfield (@{$crsconf{$provider}}) {
15315: if (grep(/^\Q$crsfield\E$/,@checked)) {
15316: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15317: }
15318: }
15319: if (ref($current{'crsconf'}) eq 'ARRAY') {
15320: unless ($changes{$provider}) {
15321: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15322: my @old = sort(@{$current{'crsconf'}});
15323: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15324: if (@diffs) {
15325: $changes{$provider} = 1;
15326: }
15327: }
15328: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15329: $changes{$provider} = 1;
15330: }
15331: }
15332: }
15333: if ($showroles) {
15334: $confhash{$provider}{'roles'} = {};
15335: foreach my $role (@courseroles) {
15336: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15337: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15338: $confhash{$provider}{'roles'}{$role} = $poss;
15339: }
15340: }
15341: unless ($changes{$provider}) {
15342: if (ref($current{'roles'}) eq 'HASH') {
15343: foreach my $role (keys(%{$current{'roles'}})) {
15344: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15345: $changes{$provider} = 1;
15346: last
15347: }
15348: }
15349: unless ($changes{$provider}) {
15350: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15351: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15352: $changes{$provider} = 1;
15353: last;
15354: }
15355: }
15356: }
15357: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15358: $changes{$provider} = 1;
15359: }
15360: }
15361: }
15362: if (ref($current{'custom'}) eq 'HASH') {
15363: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15364: foreach my $key (keys(%{$current{'custom'}})) {
15365: if (grep(/^\Q$key\E$/,@customdels)) {
15366: $changes{$provider} = 1;
15367: } else {
15368: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15369: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15370: $changes{$provider} = 1;
15371: }
15372: }
15373: }
15374: }
15375: if ($customadds{$provider}) {
15376: my $name = $env{'form.proctoring_custom_name_'.$provider};
15377: $name =~ s/(`)/'/g;
15378: $name =~ s/^\s+//;
15379: $name =~ s/\s+$//;
15380: my $value = $env{'form.proctoring_custom_value_'.$provider};
15381: $value =~ s/(`)/'/g;
15382: $value =~ s/^\s+//;
15383: $value =~ s/\s+$//;
15384: if ($name ne '') {
15385: $confhash{$provider}{'custom'}{$name} = $value;
15386: $changes{$provider} = 1;
15387: }
15388: }
15389: }
15390: }
15391: if (@allpos > 0) {
15392: my $idx = 0;
15393: foreach my $provider (@allpos) {
15394: if ($provider ne '') {
15395: $confhash{$provider}{'order'} = $idx;
15396: unless ($changes{$provider}) {
15397: if (ref($domconfig{$action}) eq 'HASH') {
15398: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15399: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15400: $changes{$provider} = 1;
15401: }
15402: }
15403: }
15404: }
15405: $idx ++;
15406: }
15407: }
15408: }
15409: my %proc_hash = (
15410: $action => { %confhash }
15411: );
15412: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15413: $dom);
15414: if ($putresult eq 'ok') {
15415: my %proc_enchash = (
15416: $action => { %encconfhash }
15417: );
1.384 raeburn 15418: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15419: if (keys(%changes) > 0) {
15420: my $cachetime = 24*60*60;
15421: my %procall = %confhash;
15422: foreach my $provider (keys(%procall)) {
15423: if (ref($encconfhash{$provider}) eq 'HASH') {
15424: foreach my $key ('key','secret') {
15425: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15426: }
15427: }
15428: }
15429: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15430: if (ref($lastactref) eq 'HASH') {
15431: $lastactref->{'proctoring'} = 1;
15432: }
15433: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15434: my %bynum;
15435: foreach my $provider (sort(keys(%changes))) {
15436: my $position = $confhash{$provider}{'order'};
15437: $bynum{$position} = $provider;
15438: }
15439: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15440: my $provider = $bynum{$pos};
15441: my %lt = &proctoring_titles($provider);
15442: my %fieldtitles = &proctoring_fieldtitles($provider);
15443: if (!$confhash{$provider}{'available'}) {
15444: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15445: } else {
15446: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15447: if ($confhash{$provider}{'image'}) {
15448: $resulttext .= ' '.
15449: '<img src="'.$confhash{$provider}{'image'}.'"'.
15450: ' alt="'.&mt('Proctoring icon').'" />';
15451: }
15452: $resulttext .= '<ul>';
15453: my $position = $pos + 1;
15454: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15455: foreach my $key ('version','sigmethod','url','lifetime') {
15456: if ($confhash{$provider}{$key} ne '') {
15457: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15458: }
15459: }
15460: if ($encconfhash{$provider}{'key'} ne '') {
15461: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15462: }
15463: if ($encconfhash{$provider}{'secret'} ne '') {
15464: $resulttext .= '<li>'.$lt{'secret'}.': ';
15465: my $num = length($encconfhash{$provider}{'secret'});
15466: $resulttext .= ('*'x$num).'</li>';
15467: }
15468: my (@fields,$showroles);
15469: if (ref($requserfields{$provider}) eq 'ARRAY') {
15470: push(@fields,@{$requserfields{$provider}});
15471: }
15472: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15473: push(@fields,@{$confhash{$provider}{'fields'}});
15474: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15475: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15476: }
15477: if (@fields) {
15478: if (grep(/^roles$/,@fields)) {
15479: $showroles = 1;
15480: }
15481: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15482: join('", "', map { $lt{$_}; } @fields).'"</li>';
15483: }
15484: if (ref($requserfields{$provider}) eq 'ARRAY') {
15485: if (grep(/^user$/,@{$requserfields{$provider}})) {
15486: if ($confhash{$provider}{'incdom'}) {
15487: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15488: } else {
15489: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15490: }
15491: }
15492: }
15493: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15494: if (@{$confhash{$provider}{'defaults'}} > 0) {
15495: $resulttext .= '<li>'.$lt{'defa'};
15496: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15497: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15498: }
15499: $resulttext =~ s/,$//;
15500: $resulttext .= '</li>';
15501: }
15502: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15503: if (keys(%{$confhash{$provider}{'defaults'}})) {
15504: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15505: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15506: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15507: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15508: }
15509: }
15510: $resulttext .= '</ul></li>';
15511: }
15512: }
15513: if (ref($crsconf{$provider}) eq 'ARRAY') {
15514: if (@{$crsconf{$provider}} > 0) {
15515: $resulttext .= '<li>'.&mt('Configurable in course:');
15516: my $numconfig = 0;
15517: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15518: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15519: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15520: $numconfig ++;
15521: if ($provider eq 'examity') {
15522: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15523: } else {
15524: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15525: }
15526: }
15527: $resulttext =~ s/,$//;
15528: }
15529: }
15530: if (!$numconfig) {
15531: $resulttext .= ' '.&mt('None');
15532: }
15533: $resulttext .= '</li>';
15534: }
15535: }
15536: if ($showroles) {
15537: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15538: my $rolemaps;
15539: foreach my $role (@courseroles) {
15540: if ($confhash{$provider}{'roles'}{$role}) {
15541: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15542: $confhash{$provider}{'roles'}{$role}.',';
15543: }
15544: }
15545: if ($rolemaps) {
15546: $rolemaps =~ s/,$//;
15547: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15548: }
15549: }
15550: }
15551: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15552: my $customlist;
15553: if (keys(%{$confhash{$provider}{'custom'}})) {
15554: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15555: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15556: }
15557: $customlist =~ s/,$//;
15558: }
15559: if ($customlist) {
15560: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15561: }
15562: }
15563: $resulttext .= '</ul></li>';
15564: }
15565: }
15566: $resulttext .= '</ul>';
15567: } else {
15568: $resulttext = &mt('No changes made.');
15569: }
15570: } else {
15571: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15572: }
15573: if ($errors) {
15574: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15575: $errors.'</ul>';
15576: }
15577: return $resulttext;
15578: }
15579:
15580: sub process_proctoring_image {
15581: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15582: my $filename = $env{'form.'.$caller.'.filename'};
15583: my ($error,$url);
15584: my ($width,$height) = (21,21);
15585: if ($configuserok eq 'ok') {
15586: if ($switchserver) {
15587: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15588: $switchserver);
15589: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15590: my $modified = [];
1.372 raeburn 15591: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15592: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15593: "proctoring/$provider/icon",$width,$height,
15594: '',$modified);
1.372 raeburn 15595: if ($result eq 'ok') {
15596: if ($madethumb) {
15597: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15598: my $imagethumb = "$path/tn-".$imagefile;
15599: $url = $imagethumb;
15600: } else {
15601: $url = $imageurl;
15602: }
1.421 raeburn 15603: &update_modify_urls($r,$modified);
1.372 raeburn 15604: } else {
15605: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15606: }
15607: } else {
15608: $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);
15609: }
15610: } else {
15611: $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);
15612: }
15613: return ($url,$error);
15614: }
15615:
1.320 raeburn 15616: sub modify_lti {
15617: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15618: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15619: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15620: my (%posslti,%posslticrs,%posscrstype);
15621: my @courseroles = ('cc','in','ta','ep','st');
15622: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15623: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15624: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15625: my %coursetypetitles = &Apache::lonlocal::texthash (
15626: official => 'Official',
15627: unofficial => 'Unofficial',
15628: community => 'Community',
15629: textbook => 'Textbook',
15630: placement => 'Placement Test',
1.392 raeburn 15631: lti => 'LTI Provider',
1.320 raeburn 15632: );
1.325 raeburn 15633: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15634: my %lt = <i_names();
15635: map { $posslti{$_} = 1; } @ltiroles;
15636: map { $posslticrs{$_} = 1; } @lticourseroles;
15637: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15638:
1.326 raeburn 15639: my %menutitles = <imenu_titles();
1.421 raeburn 15640: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15641:
1.421 raeburn 15642: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15643:
1.406 raeburn 15644: my (%linkprotchg,$linkprotoutput,$is_home);
15645: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15646: \%linkprotchg,'domain');
15647: my $home = &Apache::lonnet::domain($dom,'primary');
15648: unless (($home eq 'no_host') || ($home eq '')) {
15649: my @ids=&Apache::lonnet::current_machine_ids();
15650: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15651: }
15652:
15653: if (keys(%linkprotchg)) {
15654: $secchanges{'linkprot'} = 1;
15655: my %oldlinkprot;
15656: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15657: %oldlinkprot = %{$currltisec{'linkprot'}};
15658: }
15659: foreach my $id (keys(%linkprotchg)) {
15660: if (ref($linkprotchg{$id}) eq 'HASH') {
15661: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15662: if (($inner eq 'secret') || ($inner eq 'key')) {
15663: if ($is_home) {
15664: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15665: }
15666: }
15667: }
15668: } else {
15669: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15670: }
15671: }
15672: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15673: if (keys(%linkprotchg)) {
15674: %{$newltisec{'linkprot'}} = %linkprotchg;
15675: }
15676: }
15677: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15678: foreach my $id (%{$currltisec{'linkprot'}}) {
15679: next if ($id !~ /^\d+$/);
15680: unless (exists($linkprotchg{$id})) {
15681: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15682: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15683: if (($inner eq 'secret') || ($inner eq 'key')) {
15684: if ($is_home) {
15685: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15686: }
15687: } else {
15688: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15689: }
15690: }
15691: } else {
15692: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15693: }
15694: }
15695: }
15696: }
15697: if ($proterror) {
15698: $errors .= '<li>'.$proterror.'</li>';
15699: }
1.320 raeburn 15700: my (@items,%deletions,%itemids);
15701: if ($env{'form.lti_add'}) {
15702: my $consumer = $env{'form.lti_consumer_add'};
15703: $consumer =~ s/(`)/'/g;
15704: ($newid,my $error) = &get_lti_id($dom,$consumer);
15705: if ($newid) {
15706: $itemids{'add'} = $newid;
15707: push(@items,'add');
15708: $changes{$newid} = 1;
15709: } else {
15710: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
15711: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15712: }
15713: }
15714: if (ref($domconfig{$action}) eq 'HASH') {
15715: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15716: if (@todelete) {
15717: map { $deletions{$_} = 1; } @todelete;
15718: }
15719: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15720: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15721: my $itemid = $env{'form.lti_id_'.$i};
15722: $itemid =~ s/\D+//g;
15723: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15724: if ($deletions{$itemid}) {
15725: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15726: } else {
1.390 raeburn 15727: push(@items,$i);
15728: $itemids{$i} = $itemid;
1.320 raeburn 15729: }
15730: }
15731: }
15732: }
1.424 raeburn 15733: my (%keystore,$secstored);
15734: if ($is_home) {
15735: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
15736: }
15737:
15738: my ($cipher,$privnum);
15739: if ((@items > 0) && ($is_home)) {
15740: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
15741: $newltisec{'encrypt'},$keystore{$home});
15742: }
1.320 raeburn 15743: foreach my $idx (@items) {
15744: my $itemid = $itemids{$idx};
15745: next unless ($itemid);
1.424 raeburn 15746: my %currlti;
15747: unless ($idx eq 'add') {
15748: if (ref($domconfig{$action}) eq 'HASH') {
15749: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15750: %currlti = %{$domconfig{$action}{$itemid}};
15751: }
15752: }
15753: }
1.390 raeburn 15754: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 15755: $position =~ s/\D+//g;
15756: if ($position ne '') {
15757: $allpos[$position] = $itemid;
15758: }
1.424 raeburn 15759: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 15760: my $formitem = 'form.lti_'.$item.'_'.$idx;
15761: $env{$formitem} =~ s/(`)/'/g;
15762: if ($item eq 'lifetime') {
15763: $env{$formitem} =~ s/[^\d.]//g;
15764: }
15765: if ($env{$formitem} ne '') {
1.424 raeburn 15766: $confhash{$itemid}{$item} = $env{$formitem};
15767: unless (($idx eq 'add') || ($changes{$itemid})) {
15768: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
15769: $changes{$itemid} = 1;
1.320 raeburn 15770: }
15771: }
15772: }
15773: }
15774: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
15775: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
15776: }
1.345 raeburn 15777: if ($confhash{$itemid}{'requser'}) {
15778: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 15779: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 15780: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
15781: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
15782: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
15783: my $mapuser = $env{'form.lti_customuser_'.$idx};
15784: $mapuser =~ s/(`)/'/g;
1.405 raeburn 15785: $mapuser =~ s/^\s+|\s+$//g;
15786: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 15787: }
15788: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
15789: my @makeuser;
15790: foreach my $ltirole (sort(@possmakeuser)) {
15791: if ($posslti{$ltirole}) {
15792: push(@makeuser,$ltirole);
15793: }
15794: }
15795: $confhash{$itemid}{'makeuser'} = \@makeuser;
15796: if (@makeuser) {
15797: my $lcauth = $env{'form.lti_lcauth_'.$idx};
15798: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
15799: $confhash{$itemid}{'lcauth'} = $lcauth;
15800: if ($lcauth ne 'internal') {
15801: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
15802: $lcauthparm =~ s/^(\s+|\s+)$//g;
15803: $lcauthparm =~ s/`//g;
15804: if ($lcauthparm ne '') {
15805: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
15806: }
15807: }
15808: } else {
15809: $confhash{$itemid}{'lcauth'} = 'lti';
15810: }
1.320 raeburn 15811: }
1.345 raeburn 15812: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
15813: if (@possinstdata) {
15814: foreach my $field (@possinstdata) {
15815: if (exists($fieldtitles{$field})) {
15816: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 15817: }
15818: }
15819: }
1.363 raeburn 15820: if ($env{'form.lti_callback_'.$idx}) {
15821: if ($env{'form.lti_callbackparam_'.$idx}) {
15822: my $callback = $env{'form.lti_callbackparam_'.$idx};
15823: $callback =~ s/^\s+|\s+$//g;
15824: $confhash{$itemid}{'callback'} = $callback;
15825: }
15826: }
1.391 raeburn 15827: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 15828: if ($env{'form.lti_'.$field.'_'.$idx}) {
15829: $confhash{$itemid}{$field} = 1;
15830: }
1.320 raeburn 15831: }
1.345 raeburn 15832: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
15833: $confhash{$itemid}{lcmenu} = [];
15834: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
15835: foreach my $field (@possmenu) {
15836: if (exists($menutitles{$field})) {
15837: if ($field eq 'grades') {
15838: next unless ($env{'form.lti_inlinemenu_'.$idx});
15839: }
15840: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 15841: }
15842: }
15843: }
1.391 raeburn 15844: if ($confhash{$itemid}{'crsinc'}) {
15845: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
15846: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
15847: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
15848: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
15849: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
15850: $mapcrs =~ s/(`)/'/g;
15851: $mapcrs =~ s/^\s+|\s+$//g;
15852: $confhash{$itemid}{'mapcrs'} = $mapcrs;
15853: }
15854: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
15855: my @crstypes;
15856: foreach my $type (sort(@posstypes)) {
15857: if ($posscrstype{$type}) {
15858: push(@crstypes,$type);
15859: }
15860: }
15861: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 15862: if ($env{'form.lti_storecrs_'.$idx}) {
15863: $confhash{$itemid}{'storecrs'} = 1;
15864: }
1.391 raeburn 15865: if ($env{'form.lti_makecrs_'.$idx}) {
15866: $confhash{$itemid}{'makecrs'} = 1;
15867: }
15868: foreach my $ltirole (@lticourseroles) {
15869: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
15870: if (grep(/^\Q$possrole\E$/,@courseroles)) {
15871: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
15872: }
15873: }
15874: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
15875: my @selfenroll;
15876: foreach my $type (sort(@possenroll)) {
15877: if ($posslticrs{$type}) {
15878: push(@selfenroll,$type);
15879: }
15880: }
15881: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
15882: if ($env{'form.lti_crssec_'.$idx}) {
15883: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
15884: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
15885: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
15886: my $section = $env{'form.lti_customsection_'.$idx};
15887: $section =~ s/(`)/'/g;
15888: $section =~ s/^\s+|\s+$//g;
15889: if ($section ne '') {
15890: $confhash{$itemid}{'section'} = $section;
15891: }
15892: }
15893: }
15894: foreach my $field ('passback','roster') {
15895: if ($env{'form.lti_'.$field.'_'.$idx}) {
15896: $confhash{$itemid}{$field} = 1;
15897: }
15898: }
15899: if ($env{'form.lti_passback_'.$idx}) {
15900: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
15901: $confhash{$itemid}{'passbackformat'} = '1.0';
15902: } else {
15903: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 15904: }
15905: }
1.391 raeburn 15906: }
15907: unless (($idx eq 'add') || ($changes{$itemid})) {
15908: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 15909: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 15910: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 15911: $changes{$itemid} = 1;
15912: }
1.345 raeburn 15913: }
15914: unless ($changes{$itemid}) {
1.424 raeburn 15915: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
15916: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 15917: $changes{$itemid} = 1;
15918: }
15919: }
1.345 raeburn 15920: }
1.391 raeburn 15921: foreach my $field ('mapcrstype','selfenroll') {
15922: unless ($changes{$itemid}) {
1.424 raeburn 15923: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 15924: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 15925: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 15926: $confhash{$itemid}{$field});
15927: if (@diffs) {
15928: $changes{$itemid} = 1;
15929: }
1.424 raeburn 15930: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 15931: $changes{$itemid} = 1;
15932: }
15933: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15934: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 15935: $changes{$itemid} = 1;
15936: }
15937: }
1.391 raeburn 15938: }
15939: }
15940: unless ($changes{$itemid}) {
1.424 raeburn 15941: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 15942: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 15943: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
15944: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 15945: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 15946: $changes{$itemid} = 1;
15947: last;
15948: }
15949: }
1.391 raeburn 15950: unless ($changes{$itemid}) {
15951: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
15952: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 15953: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 15954: $changes{$itemid} = 1;
15955: last;
15956: }
15957: }
15958: }
1.424 raeburn 15959: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 15960: $changes{$itemid} = 1;
1.345 raeburn 15961: }
1.391 raeburn 15962: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15963: unless ($changes{$itemid}) {
15964: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
15965: $changes{$itemid} = 1;
15966: }
15967: }
15968: }
15969: }
15970: }
15971: unless ($changes{$itemid}) {
15972: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 15973: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 15974: $changes{$itemid} = 1;
1.320 raeburn 15975: }
1.391 raeburn 15976: }
15977: unless ($changes{$itemid}) {
15978: foreach my $field ('makeuser','lcmenu') {
1.424 raeburn 15979: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 15980: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 15981: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 15982: $confhash{$itemid}{$field});
15983: if (@diffs) {
15984: $changes{$itemid} = 1;
15985: }
1.424 raeburn 15986: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 15987: $changes{$itemid} = 1;
15988: }
15989: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15990: if (@{$confhash{$itemid}{$field}} > 0) {
15991: $changes{$itemid} = 1;
15992: }
1.345 raeburn 15993: }
1.320 raeburn 15994: }
15995: }
15996: }
15997: }
15998: }
1.424 raeburn 15999: if ($is_home) {
16000: my $keyitem = 'form.lti_key_'.$idx;
16001: $env{$keyitem} =~ s/(`)/'/g;
16002: if ($env{$keyitem} ne '') {
16003: $ltienc{$itemid}{'key'} = $env{$keyitem};
16004: unless ($changes{$itemid}) {
16005: if ($currlti{'key'} ne $env{$keyitem}) {
16006: $changes{$itemid} = 1;
16007: }
16008: }
16009: }
16010: my $secretitem = 'form.lti_secret_'.$idx;
16011: $env{$secretitem} =~ s/(`)/'/g;
16012: if ($currlti{'usable'}) {
16013: if ($env{'form.lti_changesecret_'.$idx}) {
16014: if ($env{$secretitem} ne '') {
16015: if ($privnum && $cipher) {
16016: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16017: $confhash{$itemid}{'cipher'} = $privnum;
16018: } else {
16019: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16020: }
16021: $changes{$itemid} = 1;
16022: }
16023: } else {
16024: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16025: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16026: }
16027: if (ref($ltienc{$itemid}) eq 'HASH') {
16028: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16029: $confhash{$itemid}{'usable'} = 1;
16030: }
16031: }
16032: } elsif ($env{$secretitem} ne '') {
16033: if ($privnum && $cipher) {
16034: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16035: $confhash{$itemid}{'cipher'} = $privnum;
16036: } else {
16037: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16038: }
16039: if (ref($ltienc{$itemid}) eq 'HASH') {
16040: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16041: $confhash{$itemid}{'usable'} = 1;
16042: }
16043: }
16044: $changes{$itemid} = 1;
16045: }
16046: }
16047: unless ($changes{$itemid}) {
16048: foreach my $key (keys(%currlti)) {
16049: if (ref($currlti{$key}) eq 'HASH') {
16050: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16051: foreach my $innerkey (keys(%{$currlti{$key}})) {
16052: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16053: $changes{$itemid} = 1;
16054: last;
16055: }
16056: }
16057: } elsif (keys(%{$currlti{$key}}) > 0) {
16058: $changes{$itemid} = 1;
16059: }
16060: }
16061: last if ($changes{$itemid});
16062: }
16063: }
1.320 raeburn 16064: }
16065: if (@allpos > 0) {
16066: my $idx = 0;
16067: foreach my $itemid (@allpos) {
16068: if ($itemid ne '') {
16069: $confhash{$itemid}{'order'} = $idx;
16070: if (ref($domconfig{$action}) eq 'HASH') {
16071: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16072: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16073: $changes{$itemid} = 1;
16074: }
16075: }
16076: }
16077: $idx ++;
16078: }
16079: }
16080: }
1.424 raeburn 16081:
16082: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16083: return &mt('No changes made.');
16084: }
16085:
1.320 raeburn 16086: my %ltihash = (
1.405 raeburn 16087: $action => { %confhash }
16088: );
1.424 raeburn 16089: my %ltienchash;
16090:
16091: if ($is_home) {
16092: %ltienchash = (
16093: $action => { %ltienc }
16094: );
16095: }
1.405 raeburn 16096: if (keys(%secchanges)) {
16097: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16098: if ($secchanges{'linkprot'}) {
16099: if ($is_home) {
16100: $ltienchash{'linkprot'} = \%newltienc;
16101: }
16102: }
1.405 raeburn 16103: }
16104: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16105: if ($putresult eq 'ok') {
1.424 raeburn 16106: if (keys(%ltienchash)) {
16107: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16108: }
16109: $resulttext = &mt('Changes made:').'<ul>';
16110: if (keys(%secchanges) > 0) {
1.423 raeburn 16111: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16112: if (exists($secchanges{'linkprot'})) {
16113: $resulttext .= $linkprotoutput;
1.405 raeburn 16114: }
16115: }
1.320 raeburn 16116: if (keys(%changes) > 0) {
16117: my $cachetime = 24*60*60;
1.424 raeburn 16118: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16119: if (ref($lastactref) eq 'HASH') {
16120: $lastactref->{'lti'} = 1;
16121: }
16122: my %bynum;
16123: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16124: if (ref($confhash{$itemid}) eq 'HASH') {
16125: my $position = $confhash{$itemid}{'order'};
16126: $bynum{$position} = $itemid;
16127: }
1.320 raeburn 16128: }
16129: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16130: my $itemid = $bynum{$pos};
1.424 raeburn 16131: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16132: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16133: my $position = $pos + 1;
16134: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16135: foreach my $item ('version','lifetime') {
16136: if ($confhash{$itemid}{$item} ne '') {
16137: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16138: }
16139: }
1.424 raeburn 16140: if ($ltienc{$itemid}{'key'} ne '') {
16141: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16142: }
1.424 raeburn 16143: if ($ltienc{$itemid}{'secret'} ne '') {
16144: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16145: }
1.345 raeburn 16146: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16147: if ($confhash{$itemid}{'callback'}) {
16148: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16149: } else {
1.392 raeburn 16150: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16151: }
1.345 raeburn 16152: if ($confhash{$itemid}{'mapuser'}) {
16153: my $shownmapuser;
16154: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16155: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16156: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16157: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16158: } else {
16159: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16160: }
1.345 raeburn 16161: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16162: }
1.345 raeburn 16163: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16164: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16165: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16166: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16167: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16168: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16169: } else {
16170: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16171: $confhash{$itemid}{'lcauth'});
16172: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16173: $resulttext .= '; '.&mt('a randomly generated password will be created');
16174: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16175: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16176: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16177: }
16178: } else {
16179: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16180: }
16181: }
16182: $resulttext .= '</li>';
16183: } else {
16184: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16185: }
1.320 raeburn 16186: }
1.345 raeburn 16187: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16188: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16189: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16190: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16191: } else {
1.345 raeburn 16192: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 16193: }
1.320 raeburn 16194: }
1.391 raeburn 16195: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16196: $resulttext .= '<li>'.$lt{$item}.': ';
16197: if ($confhash{$itemid}{$item}) {
16198: $resulttext .= &mt('Yes');
16199: } else {
16200: $resulttext .= &mt('No');
1.337 raeburn 16201: }
1.345 raeburn 16202: $resulttext .= '</li>';
1.320 raeburn 16203: }
1.345 raeburn 16204: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16205: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16206: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16207: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16208: } else {
16209: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16210: }
16211: }
16212: if ($confhash{$itemid}{'crsinc'}) {
16213: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16214: my $rolemaps;
16215: foreach my $role (@ltiroles) {
16216: if ($confhash{$itemid}{'maproles'}{$role}) {
16217: $rolemaps .= (' 'x2).$role.'='.
16218: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16219: 'Course').',';
16220: }
16221: }
16222: if ($rolemaps) {
16223: $rolemaps =~ s/,$//;
16224: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16225: }
16226: }
16227: if ($confhash{$itemid}{'mapcrs'}) {
16228: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16229: }
16230: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16231: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16232: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16233: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16234: '</li>';
16235: } else {
16236: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16237: }
16238: }
1.392 raeburn 16239: if ($confhash{$itemid}{'storecrs'}) {
16240: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16241: }
1.391 raeburn 16242: if ($confhash{$itemid}{'makecrs'}) {
16243: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16244: } else {
16245: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16246: }
16247: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16248: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16249: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16250: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16251: '</li>';
16252: } else {
16253: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16254: }
16255: }
16256: if ($confhash{$itemid}{'section'}) {
16257: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16258: $resulttext .= '<li>'.&mt('User section from standard field:').
16259: ' (course_section_sourcedid)'.'</li>';
16260: } else {
16261: $resulttext .= '<li>'.&mt('User section from:').' '.
16262: $confhash{$itemid}{'section'}.'</li>';
16263: }
1.345 raeburn 16264: } else {
1.391 raeburn 16265: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16266: }
16267: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16268: $resulttext .= '<li>'.$lt{$item}.': ';
16269: if ($confhash{$itemid}{$item}) {
16270: $resulttext .= &mt('Yes');
16271: if ($item eq 'passback') {
16272: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16273: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16274: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16275: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16276: }
16277: }
16278: } else {
16279: $resulttext .= &mt('No');
16280: }
16281: $resulttext .= '</li>';
16282: }
16283: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16284: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16285: $resulttext .= '<li>'.&mt('Menu items:').' '.
16286: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16287: } else {
16288: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16289: }
1.345 raeburn 16290: }
1.326 raeburn 16291: }
16292: }
1.320 raeburn 16293: $resulttext .= '</ul></li>';
16294: }
16295: }
1.424 raeburn 16296: if (keys(%deletions)) {
16297: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16298: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16299: }
16300: }
1.320 raeburn 16301: }
1.405 raeburn 16302: $resulttext .= '</ul>';
1.424 raeburn 16303: if (ref($lastactref) eq 'HASH') {
16304: if (($secchanges{'encrypt'}) || ($secchanges{'private'})) {
16305: $lastactref->{'domdefaults'} = 1;
16306: }
16307: }
1.320 raeburn 16308: } else {
16309: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16310: }
16311: if ($errors) {
16312: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16313: $errors.'</ul>';
16314: }
16315: return $resulttext;
16316: }
16317:
1.424 raeburn 16318: sub get_priv_creds {
16319: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16320: my ($needenc,$cipher,$privnum);
16321: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16322: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16323: $needenc = $encrypt->{'consumers'}
16324: } else {
16325: $needenc = $domdefs{'ltienc_consumers'};
16326: }
16327: if ($needenc) {
16328: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16329: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16330: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16331: my $privkey = $privhash{'key'};
16332: $privnum = $privhash{'version'};
16333: if (($privnum) && ($privkey ne '')) {
16334: $cipher = Crypt::CBC->new({'key' => $privkey,
16335: 'cipher' => 'DES'});
16336: }
16337: }
16338: }
16339: return ($cipher,$privnum);
16340: }
16341:
1.320 raeburn 16342: sub get_lti_id {
16343: my ($domain,$consumer) = @_;
16344: # get lock on lti db
16345: my $lockhash = {
16346: lock => $env{'user.name'}.
16347: ':'.$env{'user.domain'},
16348: };
16349: my $tries = 0;
16350: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
16351: my ($id,$error);
16352:
16353: while (($gotlock ne 'ok') && ($tries<10)) {
16354: $tries ++;
16355: sleep (0.1);
16356: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
16357: }
16358: if ($gotlock eq 'ok') {
16359: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
16360: if ($currids{'lock'}) {
16361: delete($currids{'lock'});
16362: if (keys(%currids)) {
16363: my @curr = sort { $a <=> $b } keys(%currids);
16364: if ($curr[-1] =~ /^\d+$/) {
16365: $id = 1 + $curr[-1];
16366: }
16367: } else {
16368: $id = 1;
16369: }
16370: if ($id) {
16371: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
16372: $error = 'nostore';
16373: }
16374: } else {
16375: $error = 'nonumber';
16376: }
16377: }
16378: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
16379: } else {
16380: $error = 'nolock';
16381: }
16382: return ($id,$error);
16383: }
16384:
1.3 raeburn 16385: sub modify_autoenroll {
1.205 raeburn 16386: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16387: my ($resulttext,%changes);
16388: my %currautoenroll;
16389: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16390: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16391: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16392: }
16393: }
16394: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16395: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16396: sender => 'Sender for notification messages',
1.274 raeburn 16397: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16398: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16399: my @offon = ('off','on');
1.17 raeburn 16400: my $sender_uname = $env{'form.sender_uname'};
16401: my $sender_domain = $env{'form.sender_domain'};
16402: if ($sender_domain eq '') {
16403: $sender_uname = '';
16404: } elsif ($sender_uname eq '') {
16405: $sender_domain = '';
16406: }
1.129 raeburn 16407: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16408: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16409: $autofailsafe =~ s{^\s+|\s+$}{}g;
16410: if ($autofailsafe =~ /\D/) {
16411: undef($autofailsafe);
16412: }
1.274 raeburn 16413: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16414: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16415: $failsafe = 'off';
1.400 raeburn 16416: undef($autofailsafe);
1.274 raeburn 16417: }
1.1 raeburn 16418: my %autoenrollhash = (
1.129 raeburn 16419: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16420: 'sender_uname' => $sender_uname,
16421: 'sender_domain' => $sender_domain,
16422: 'co-owners' => $coowners,
1.399 raeburn 16423: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16424: 'failsafe' => $failsafe,
1.1 raeburn 16425: }
16426: );
1.4 raeburn 16427: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16428: $dom);
1.1 raeburn 16429: if ($putresult eq 'ok') {
16430: if (exists($currautoenroll{'run'})) {
16431: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16432: $changes{'run'} = 1;
16433: }
16434: } elsif ($autorun) {
16435: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16436: $changes{'run'} = 1;
1.1 raeburn 16437: }
16438: }
1.17 raeburn 16439: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16440: $changes{'sender'} = 1;
16441: }
1.17 raeburn 16442: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16443: $changes{'sender'} = 1;
16444: }
1.129 raeburn 16445: if ($currautoenroll{'co-owners'} ne '') {
16446: if ($currautoenroll{'co-owners'} ne $coowners) {
16447: $changes{'coowners'} = 1;
16448: }
16449: } elsif ($coowners) {
16450: $changes{'coowners'} = 1;
1.274 raeburn 16451: }
1.399 raeburn 16452: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16453: $changes{'autofailsafe'} = 1;
16454: }
1.399 raeburn 16455: if ($currautoenroll{'failsafe'} ne $failsafe) {
16456: $changes{'failsafe'} = 1;
16457: }
1.1 raeburn 16458: if (keys(%changes) > 0) {
16459: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16460: if ($changes{'run'}) {
1.1 raeburn 16461: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16462: }
16463: if ($changes{'sender'}) {
1.17 raeburn 16464: if ($sender_uname eq '' || $sender_domain eq '') {
16465: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16466: } else {
16467: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16468: }
1.1 raeburn 16469: }
1.129 raeburn 16470: if ($changes{'coowners'}) {
16471: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16472: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16473: if (ref($lastactref) eq 'HASH') {
16474: $lastactref->{'domainconfig'} = 1;
16475: }
1.129 raeburn 16476: }
1.274 raeburn 16477: if ($changes{'autofailsafe'}) {
1.399 raeburn 16478: if ($autofailsafe ne '') {
16479: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16480: } else {
1.399 raeburn 16481: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16482: }
1.399 raeburn 16483: }
16484: if ($changes{'failsafe'}) {
16485: if ($failsafe eq 'off') {
16486: unless ($changes{'autofailsafe'}) {
16487: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16488: }
16489: } elsif ($failsafe eq 'zero') {
16490: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16491: } else {
16492: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16493: }
16494: }
16495: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16496: &Apache::lonnet::get_domain_defaults($dom,1);
16497: if (ref($lastactref) eq 'HASH') {
16498: $lastactref->{'domdefaults'} = 1;
16499: }
16500: }
1.1 raeburn 16501: $resulttext .= '</ul>';
16502: } else {
16503: $resulttext = &mt('No changes made to auto-enrollment settings');
16504: }
16505: } else {
1.11 albertel 16506: $resulttext = '<span class="LC_error">'.
16507: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16508: }
1.3 raeburn 16509: return $resulttext;
1.1 raeburn 16510: }
16511:
16512: sub modify_autoupdate {
1.3 raeburn 16513: my ($dom,%domconfig) = @_;
1.1 raeburn 16514: my ($resulttext,%currautoupdate,%fields,%changes);
16515: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16516: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16517: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16518: }
16519: }
16520: my @offon = ('off','on');
16521: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16522: run => 'Auto-update:',
16523: classlists => 'Updates to user information in classlists?',
16524: unexpired => 'Skip updates for users without active or future roles?',
16525: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16526: );
1.44 raeburn 16527: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16528: my %fieldtitles = &Apache::lonlocal::texthash (
16529: id => 'Student/Employee ID',
1.20 raeburn 16530: permanentemail => 'E-mail address',
1.1 raeburn 16531: lastname => 'Last Name',
16532: firstname => 'First Name',
16533: middlename => 'Middle Name',
1.132 raeburn 16534: generation => 'Generation',
1.1 raeburn 16535: );
1.142 raeburn 16536: $othertitle = &mt('All users');
1.1 raeburn 16537: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16538: $othertitle = &mt('Other users');
1.1 raeburn 16539: }
16540: foreach my $key (keys(%env)) {
16541: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16542: my ($usertype,$item) = ($1,$2);
16543: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16544: if ($usertype eq 'default') {
16545: push(@{$fields{$1}},$2);
16546: } elsif (ref($types) eq 'ARRAY') {
16547: if (grep(/^\Q$usertype\E$/,@{$types})) {
16548: push(@{$fields{$1}},$2);
16549: }
16550: }
16551: }
1.1 raeburn 16552: }
16553: }
1.131 raeburn 16554: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16555: @lockablenames = sort(@lockablenames);
16556: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16557: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16558: if (@changed) {
16559: $changes{'lockablenames'} = 1;
16560: }
16561: } else {
16562: if (@lockablenames) {
16563: $changes{'lockablenames'} = 1;
16564: }
16565: }
1.1 raeburn 16566: my %updatehash = (
16567: autoupdate => { run => $env{'form.autoupdate_run'},
16568: classlists => $env{'form.classlists'},
1.385 raeburn 16569: unexpired => $env{'form.unexpired'},
1.1 raeburn 16570: fields => {%fields},
1.131 raeburn 16571: lockablenames => \@lockablenames,
1.1 raeburn 16572: }
16573: );
1.385 raeburn 16574: my $lastactivedays;
16575: if ($env{'form.lastactive'}) {
16576: $lastactivedays = $env{'form.lastactivedays'};
16577: $lastactivedays =~ s/^\s+|\s+$//g;
16578: unless ($lastactivedays =~ /^\d+$/) {
16579: undef($lastactivedays);
16580: $env{'form.lastactive'} = 0;
16581: }
16582: }
16583: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16584: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16585: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16586: if (exists($updatehash{autoupdate}{$key})) {
16587: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16588: $changes{$key} = 1;
16589: }
16590: }
16591: } elsif ($key eq 'fields') {
16592: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16593: foreach my $item (@{$types},'default') {
1.1 raeburn 16594: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16595: my $change = 0;
16596: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16597: if (!exists($fields{$item})) {
16598: $change = 1;
1.132 raeburn 16599: last;
1.1 raeburn 16600: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16601: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16602: $change = 1;
1.132 raeburn 16603: last;
1.1 raeburn 16604: }
16605: }
16606: }
16607: if ($change) {
16608: push(@{$changes{$key}},$item);
16609: }
1.26 raeburn 16610: }
1.1 raeburn 16611: }
16612: }
1.131 raeburn 16613: } elsif ($key eq 'lockablenames') {
16614: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16615: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16616: if (@changed) {
16617: $changes{'lockablenames'} = 1;
16618: }
16619: } else {
16620: if (@lockablenames) {
16621: $changes{'lockablenames'} = 1;
16622: }
16623: }
16624: }
16625: }
16626: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16627: if (@lockablenames) {
16628: $changes{'lockablenames'} = 1;
1.1 raeburn 16629: }
16630: }
1.385 raeburn 16631: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16632: if ($updatehash{'autoupdate'}{'unexpired'}) {
16633: $changes{'unexpired'} = 1;
16634: }
16635: }
16636: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16637: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16638: $changes{'lastactive'} = 1;
16639: }
16640: }
1.26 raeburn 16641: foreach my $item (@{$types},'default') {
16642: if (defined($fields{$item})) {
16643: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16644: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16645: my $change = 0;
16646: if (ref($fields{$item}) eq 'ARRAY') {
16647: foreach my $type (@{$fields{$item}}) {
16648: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16649: $change = 1;
16650: last;
16651: }
16652: }
16653: }
16654: if ($change) {
16655: push(@{$changes{'fields'}},$item);
16656: }
16657: } else {
1.26 raeburn 16658: push(@{$changes{'fields'}},$item);
16659: }
16660: } else {
16661: push(@{$changes{'fields'}},$item);
1.1 raeburn 16662: }
16663: }
16664: }
16665: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16666: $dom);
16667: if ($putresult eq 'ok') {
16668: if (keys(%changes) > 0) {
16669: $resulttext = &mt('Changes made:').'<ul>';
16670: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16671: if ($key eq 'lockablenames') {
16672: $resulttext .= '<li>';
16673: if (@lockablenames) {
16674: $usertypes->{'default'} = $othertitle;
16675: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16676: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16677: } else {
16678: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16679: }
16680: $resulttext .= '</li>';
16681: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16682: foreach my $item (@{$changes{$key}}) {
16683: my @newvalues;
16684: foreach my $type (@{$fields{$item}}) {
16685: push(@newvalues,$fieldtitles{$type});
16686: }
1.3 raeburn 16687: my $newvaluestr;
16688: if (@newvalues > 0) {
16689: $newvaluestr = join(', ',@newvalues);
16690: } else {
16691: $newvaluestr = &mt('none');
1.6 raeburn 16692: }
1.1 raeburn 16693: if ($item eq 'default') {
1.26 raeburn 16694: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16695: } else {
1.26 raeburn 16696: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16697: }
16698: }
16699: } else {
16700: my $newvalue;
16701: if ($key eq 'run') {
16702: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16703: } elsif ($key eq 'lastactive') {
16704: $newvalue = $offon[$env{'form.lastactive'}];
16705: unless ($lastactivedays eq '') {
16706: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16707: }
1.1 raeburn 16708: } else {
16709: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16710: }
1.1 raeburn 16711: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16712: }
16713: }
16714: $resulttext .= '</ul>';
16715: } else {
1.3 raeburn 16716: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16717: }
16718: } else {
1.11 albertel 16719: $resulttext = '<span class="LC_error">'.
16720: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16721: }
1.3 raeburn 16722: return $resulttext;
1.1 raeburn 16723: }
16724:
1.125 raeburn 16725: sub modify_autocreate {
16726: my ($dom,%domconfig) = @_;
16727: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
16728: if (ref($domconfig{'autocreate'}) eq 'HASH') {
16729: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
16730: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
16731: }
16732: }
16733: my %title= ( xml => 'Auto-creation of courses in XML course description files',
16734: req => 'Auto-creation of validated requests for official courses',
16735: xmldc => 'Identity of course creator of courses from XML files',
16736: );
16737: my @types = ('xml','req');
16738: foreach my $item (@types) {
16739: $newvals{$item} = $env{'form.autocreate_'.$item};
16740: $newvals{$item} =~ s/\D//g;
16741: $newvals{$item} = 0 if ($newvals{$item} eq '');
16742: }
16743: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 16744: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 16745: unless (exists($domcoords{$newvals{'xmldc'}})) {
16746: $newvals{'xmldc'} = '';
16747: }
16748: %autocreatehash = (
16749: autocreate => { xml => $newvals{'xml'},
16750: req => $newvals{'req'},
16751: }
16752: );
16753: if ($newvals{'xmldc'} ne '') {
16754: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
16755: }
16756: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
16757: $dom);
16758: if ($putresult eq 'ok') {
16759: my @items = @types;
16760: if ($newvals{'xml'}) {
16761: push(@items,'xmldc');
16762: }
16763: foreach my $item (@items) {
16764: if (exists($currautocreate{$item})) {
16765: if ($currautocreate{$item} ne $newvals{$item}) {
16766: $changes{$item} = 1;
16767: }
16768: } elsif ($newvals{$item}) {
16769: $changes{$item} = 1;
16770: }
16771: }
16772: if (keys(%changes) > 0) {
16773: my @offon = ('off','on');
16774: $resulttext = &mt('Changes made:').'<ul>';
16775: foreach my $item (@types) {
16776: if ($changes{$item}) {
16777: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 16778: $resulttext .= '<li>'.
16779: &mt("$title{$item} set to [_1]$newtxt [_2]",
16780: '<b>','</b>').
16781: '</li>';
1.125 raeburn 16782: }
16783: }
16784: if ($changes{'xmldc'}) {
16785: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
16786: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 16787: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 16788: }
16789: $resulttext .= '</ul>';
16790: } else {
16791: $resulttext = &mt('No changes made to auto-creation settings');
16792: }
16793: } else {
16794: $resulttext = '<span class="LC_error">'.
16795: &mt('An error occurred: [_1]',$putresult).'</span>';
16796: }
16797: return $resulttext;
16798: }
16799:
1.23 raeburn 16800: sub modify_directorysrch {
1.295 raeburn 16801: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 16802: my ($resulttext,%changes);
16803: my %currdirsrch;
16804: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
16805: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
16806: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
16807: }
16808: }
1.277 raeburn 16809: my %title = ( available => 'Institutional directory search available',
16810: localonly => 'Other domains can search institution',
16811: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 16812: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 16813: searchby => 'Search types',
16814: searchtypes => 'Search latitude');
16815: my @offon = ('off','on');
1.24 raeburn 16816: my @otherdoms = ('Yes','No');
1.23 raeburn 16817:
1.25 raeburn 16818: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 16819: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
16820: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
16821:
1.44 raeburn 16822: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 16823: if (keys(%{$usertypes}) == 0) {
16824: @cansearch = ('default');
16825: } else {
16826: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
16827: foreach my $type (@{$currdirsrch{'cansearch'}}) {
16828: if (!grep(/^\Q$type\E$/,@cansearch)) {
16829: push(@{$changes{'cansearch'}},$type);
16830: }
1.23 raeburn 16831: }
1.26 raeburn 16832: foreach my $type (@cansearch) {
16833: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
16834: push(@{$changes{'cansearch'}},$type);
16835: }
1.23 raeburn 16836: }
1.26 raeburn 16837: } else {
16838: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 16839: }
16840: }
16841:
16842: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
16843: foreach my $by (@{$currdirsrch{'searchby'}}) {
16844: if (!grep(/^\Q$by\E$/,@searchby)) {
16845: push(@{$changes{'searchby'}},$by);
16846: }
16847: }
16848: foreach my $by (@searchby) {
16849: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
16850: push(@{$changes{'searchby'}},$by);
16851: }
16852: }
16853: } else {
16854: push(@{$changes{'searchby'}},@searchby);
16855: }
1.25 raeburn 16856:
16857: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
16858: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
16859: if (!grep(/^\Q$type\E$/,@searchtypes)) {
16860: push(@{$changes{'searchtypes'}},$type);
16861: }
16862: }
16863: foreach my $type (@searchtypes) {
16864: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
16865: push(@{$changes{'searchtypes'}},$type);
16866: }
16867: }
16868: } else {
16869: if (exists($currdirsrch{'searchtypes'})) {
16870: foreach my $type (@searchtypes) {
16871: if ($type ne $currdirsrch{'searchtypes'}) {
16872: push(@{$changes{'searchtypes'}},$type);
16873: }
16874: }
16875: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
16876: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
16877: }
16878: } else {
16879: push(@{$changes{'searchtypes'}},@searchtypes);
16880: }
16881: }
16882:
1.23 raeburn 16883: my %dirsrch_hash = (
16884: directorysrch => { available => $env{'form.dirsrch_available'},
16885: cansearch => \@cansearch,
1.277 raeburn 16886: localonly => $env{'form.dirsrch_instlocalonly'},
16887: lclocalonly => $env{'form.dirsrch_domlocalonly'},
16888: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 16889: searchby => \@searchby,
1.25 raeburn 16890: searchtypes => \@searchtypes,
1.23 raeburn 16891: }
16892: );
16893: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
16894: $dom);
16895: if ($putresult eq 'ok') {
16896: if (exists($currdirsrch{'available'})) {
16897: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
16898: $changes{'available'} = 1;
16899: }
16900: } else {
16901: if ($env{'form.dirsrch_available'} eq '1') {
16902: $changes{'available'} = 1;
16903: }
16904: }
1.277 raeburn 16905: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 16906: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
16907: $changes{'lcavailable'} = 1;
16908: }
1.277 raeburn 16909: } else {
16910: if ($env{'form.dirsrch_lcavailable'} eq '1') {
16911: $changes{'lcavailable'} = 1;
16912: }
16913: }
1.24 raeburn 16914: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 16915: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
16916: $changes{'localonly'} = 1;
16917: }
1.24 raeburn 16918: } else {
1.277 raeburn 16919: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 16920: $changes{'localonly'} = 1;
16921: }
16922: }
1.277 raeburn 16923: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 16924: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
16925: $changes{'lclocalonly'} = 1;
16926: }
1.277 raeburn 16927: } else {
16928: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
16929: $changes{'lclocalonly'} = 1;
16930: }
16931: }
1.23 raeburn 16932: if (keys(%changes) > 0) {
16933: $resulttext = &mt('Changes made:').'<ul>';
16934: if ($changes{'available'}) {
16935: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
16936: }
1.277 raeburn 16937: if ($changes{'lcavailable'}) {
16938: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
16939: }
1.24 raeburn 16940: if ($changes{'localonly'}) {
1.277 raeburn 16941: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 16942: }
1.277 raeburn 16943: if ($changes{'lclocalonly'}) {
16944: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 16945: }
1.23 raeburn 16946: if (ref($changes{'cansearch'}) eq 'ARRAY') {
16947: my $chgtext;
1.26 raeburn 16948: if (ref($usertypes) eq 'HASH') {
16949: if (keys(%{$usertypes}) > 0) {
16950: foreach my $type (@{$types}) {
16951: if (grep(/^\Q$type\E$/,@cansearch)) {
16952: $chgtext .= $usertypes->{$type}.'; ';
16953: }
16954: }
16955: if (grep(/^default$/,@cansearch)) {
16956: $chgtext .= $othertitle;
16957: } else {
16958: $chgtext =~ s/\; $//;
16959: }
1.210 raeburn 16960: $resulttext .=
1.178 raeburn 16961: '<li>'.
16962: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
16963: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
16964: '</li>';
1.23 raeburn 16965: }
16966: }
16967: }
16968: if (ref($changes{'searchby'}) eq 'ARRAY') {
16969: my ($searchtitles,$titleorder) = &sorted_searchtitles();
16970: my $chgtext;
16971: foreach my $type (@{$titleorder}) {
16972: if (grep(/^\Q$type\E$/,@searchby)) {
16973: if (defined($searchtitles->{$type})) {
16974: $chgtext .= $searchtitles->{$type}.'; ';
16975: }
16976: }
16977: }
16978: $chgtext =~ s/\; $//;
16979: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
16980: }
1.25 raeburn 16981: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
16982: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
16983: my $chgtext;
16984: foreach my $type (@{$srchtypeorder}) {
16985: if (grep(/^\Q$type\E$/,@searchtypes)) {
16986: if (defined($srchtypes_desc->{$type})) {
16987: $chgtext .= $srchtypes_desc->{$type}.'; ';
16988: }
16989: }
16990: }
16991: $chgtext =~ s/\; $//;
1.178 raeburn 16992: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 16993: }
16994: $resulttext .= '</ul>';
1.295 raeburn 16995: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
16996: if (ref($lastactref) eq 'HASH') {
16997: $lastactref->{'directorysrch'} = 1;
16998: }
1.23 raeburn 16999: } else {
1.277 raeburn 17000: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17001: }
17002: } else {
17003: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17004: &mt('An error occurred: [_1]',$putresult).'</span>';
17005: }
17006: return $resulttext;
17007: }
17008:
1.28 raeburn 17009: sub modify_contacts {
1.205 raeburn 17010: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17011: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17012: if (ref($domconfig{'contacts'}) eq 'HASH') {
17013: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17014: $currsetting{$key} = $domconfig{'contacts'}{$key};
17015: }
17016: }
1.286 raeburn 17017: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17018: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17019: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17020: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17021: my @toggles = ('reporterrors','reportupdates','reportstatus');
17022: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17023: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17024: foreach my $type (@mailings) {
17025: @{$newsetting{$type}} =
17026: &Apache::loncommon::get_env_multiple('form.'.$type);
17027: foreach my $item (@contacts) {
17028: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17029: $contacts_hash{contacts}{$type}{$item} = 1;
17030: } else {
17031: $contacts_hash{contacts}{$type}{$item} = 0;
17032: }
1.289 raeburn 17033: }
1.28 raeburn 17034: $others{$type} = $env{'form.'.$type.'_others'};
17035: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17036: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17037: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17038: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17039: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17040: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17041: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17042: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17043: }
1.134 raeburn 17044: }
1.28 raeburn 17045: }
17046: foreach my $item (@contacts) {
17047: $to{$item} = $env{'form.'.$item};
17048: $contacts_hash{'contacts'}{$item} = $to{$item};
17049: }
1.203 raeburn 17050: foreach my $item (@toggles) {
17051: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17052: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17053: }
17054: }
1.340 raeburn 17055: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17056: foreach my $item (@lonstatus) {
17057: if ($item eq 'excluded') {
17058: my (%serverhomes,@excluded);
17059: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17060: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17061: if (@possexcluded) {
17062: foreach my $id (sort(@possexcluded)) {
17063: if ($serverhomes{$id}) {
17064: push(@excluded,$id);
17065: }
17066: }
17067: }
17068: if (@excluded) {
17069: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17070: }
17071: } elsif ($item eq 'weights') {
1.377 raeburn 17072: foreach my $type ('E','W','N','U') {
1.340 raeburn 17073: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17074: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17075: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17076: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17077: $env{'form.error'.$item.'_'.$type};
17078: }
17079: }
17080: }
17081: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17082: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17083: if ($env{'form.error'.$item} =~ /^\d+$/) {
17084: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17085: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17086: }
17087: }
17088: }
17089: }
1.286 raeburn 17090: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17091: foreach my $field (@{$fields}) {
17092: if (ref($possoptions->{$field}) eq 'ARRAY') {
17093: my $value = $env{'form.helpform_'.$field};
17094: $value =~ s/^\s+|\s+$//g;
17095: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17096: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17097: if ($field eq 'screenshot') {
17098: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17099: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17100: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17101: }
17102: }
17103: }
17104: }
17105: }
17106: }
1.315 raeburn 17107: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17108: my (@statuses,%usertypeshash,@overrides);
17109: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17110: @statuses = @{$types};
17111: if (ref($usertypes) eq 'HASH') {
17112: %usertypeshash = %{$usertypes};
17113: }
17114: }
17115: if (@statuses) {
17116: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17117: foreach my $type (@possoverrides) {
17118: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17119: push(@overrides,$type);
17120: }
17121: }
17122: if (@overrides) {
17123: foreach my $type (@overrides) {
17124: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17125: foreach my $item (@contacts) {
17126: if (grep(/^\Q$item\E$/,@standard)) {
17127: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17128: $newsetting{'override_'.$type}{$item} = 1;
17129: } else {
17130: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17131: $newsetting{'override_'.$type}{$item} = 0;
17132: }
17133: }
17134: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17135: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17136: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17137: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17138: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17139: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17140: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17141: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17142: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17143: }
1.425 raeburn 17144: }
1.315 raeburn 17145: }
17146: }
1.28 raeburn 17147: if (keys(%currsetting) > 0) {
17148: foreach my $item (@contacts) {
17149: if ($to{$item} ne $currsetting{$item}) {
17150: $changes{$item} = 1;
17151: }
17152: }
17153: foreach my $type (@mailings) {
17154: foreach my $item (@contacts) {
17155: if (ref($currsetting{$type}) eq 'HASH') {
17156: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17157: push(@{$changes{$type}},$item);
17158: }
17159: } else {
17160: push(@{$changes{$type}},@{$newsetting{$type}});
17161: }
17162: }
17163: if ($others{$type} ne $currsetting{$type}{'others'}) {
17164: push(@{$changes{$type}},'others');
17165: }
1.289 raeburn 17166: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17167: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17168: push(@{$changes{$type}},'bcc');
17169: }
1.286 raeburn 17170: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17171: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17172: push(@{$changes{$type}},'include');
17173: }
17174: }
17175: }
17176: if (ref($fields) eq 'ARRAY') {
17177: if (ref($currsetting{'helpform'}) eq 'HASH') {
17178: foreach my $field (@{$fields}) {
17179: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17180: push(@{$changes{'helpform'}},$field);
17181: }
17182: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17183: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17184: push(@{$changes{'helpform'}},'maxsize');
17185: }
17186: }
17187: }
17188: } else {
17189: foreach my $field (@{$fields}) {
17190: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17191: push(@{$changes{'helpform'}},$field);
17192: }
17193: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17194: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17195: push(@{$changes{'helpform'}},'maxsize');
17196: }
17197: }
17198: }
1.134 raeburn 17199: }
1.28 raeburn 17200: }
1.315 raeburn 17201: if (@statuses) {
1.425 raeburn 17202: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17203: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17204: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17205: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17206: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17207: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17208: push(@{$changes{'overrides'}},$key);
17209: last;
17210: }
17211: }
17212: } else {
17213: push(@{$changes{'overrides'}},$key);
17214: }
17215: }
17216: }
17217: foreach my $key (@overrides) {
17218: unless (exists($currsetting{'overrides'}{$key})) {
17219: push(@{$changes{'overrides'}},$key);
17220: }
17221: }
17222: } else {
17223: foreach my $key (@overrides) {
1.425 raeburn 17224: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17225: }
17226: }
17227: }
1.340 raeburn 17228: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17229: foreach my $key ('excluded','weights','threshold','sysmail') {
17230: if ($key eq 'excluded') {
17231: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17232: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17233: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17234: (@{$currsetting{'lonstatus'}{$key}})) {
17235: my @diffs =
17236: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17237: $currsetting{'lonstatus'}{$key});
17238: if (@diffs) {
17239: push(@{$changes{'lonstatus'}},$key);
17240: }
17241: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17242: push(@{$changes{'lonstatus'}},$key);
17243: }
17244: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17245: (@{$currsetting{'lonstatus'}{$key}})) {
17246: push(@{$changes{'lonstatus'}},$key);
17247: }
17248: } elsif ($key eq 'weights') {
17249: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17250: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17251: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17252: foreach my $type ('E','W','N','U') {
1.340 raeburn 17253: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17254: $currsetting{'lonstatus'}{$key}{$type}) {
17255: push(@{$changes{'lonstatus'}},$key);
17256: last;
17257: }
17258: }
17259: } else {
1.341 raeburn 17260: foreach my $type ('E','W','N','U') {
1.340 raeburn 17261: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17262: push(@{$changes{'lonstatus'}},$key);
17263: last;
17264: }
17265: }
17266: }
17267: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17268: foreach my $type ('E','W','N','U') {
1.340 raeburn 17269: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17270: push(@{$changes{'lonstatus'}},$key);
17271: last;
17272: }
17273: }
17274: }
17275: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17276: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17277: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17278: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17279: push(@{$changes{'lonstatus'}},$key);
17280: }
17281: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17282: push(@{$changes{'lonstatus'}},$key);
17283: }
17284: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17285: push(@{$changes{'lonstatus'}},$key);
17286: }
17287: }
17288: }
17289: } else {
17290: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17291: foreach my $key ('excluded','weights','threshold','sysmail') {
17292: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17293: push(@{$changes{'lonstatus'}},$key);
17294: }
17295: }
17296: }
17297: }
1.28 raeburn 17298: } else {
17299: my %default;
17300: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17301: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17302: $default{'errormail'} = 'adminemail';
17303: $default{'packagesmail'} = 'adminemail';
17304: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17305: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17306: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17307: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17308: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17309: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17310: foreach my $item (@contacts) {
17311: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17312: $changes{$item} = 1;
1.203 raeburn 17313: }
1.28 raeburn 17314: }
17315: foreach my $type (@mailings) {
17316: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17317: push(@{$changes{$type}},@{$newsetting{$type}});
17318: }
17319: if ($others{$type} ne '') {
17320: push(@{$changes{$type}},'others');
1.134 raeburn 17321: }
1.286 raeburn 17322: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17323: if ($bcc{$type} ne '') {
17324: push(@{$changes{$type}},'bcc');
17325: }
1.286 raeburn 17326: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17327: push(@{$changes{$type}},'include');
17328: }
1.134 raeburn 17329: }
1.28 raeburn 17330: }
1.286 raeburn 17331: if (ref($fields) eq 'ARRAY') {
17332: foreach my $field (@{$fields}) {
17333: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17334: push(@{$changes{'helpform'}},$field);
17335: }
17336: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17337: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17338: push(@{$changes{'helpform'}},'maxsize');
17339: }
17340: }
17341: }
1.289 raeburn 17342: }
1.340 raeburn 17343: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17344: foreach my $key ('excluded','weights','threshold','sysmail') {
17345: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17346: push(@{$changes{'lonstatus'}},$key);
17347: }
17348: }
17349: }
1.28 raeburn 17350: }
1.203 raeburn 17351: foreach my $item (@toggles) {
17352: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17353: $changes{$item} = 1;
17354: } elsif ((!$env{'form.'.$item}) &&
17355: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17356: $changes{$item} = 1;
17357: }
17358: }
1.28 raeburn 17359: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17360: $dom);
17361: if ($putresult eq 'ok') {
17362: if (keys(%changes) > 0) {
1.205 raeburn 17363: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17364: if (ref($lastactref) eq 'HASH') {
17365: $lastactref->{'domainconfig'} = 1;
17366: }
1.28 raeburn 17367: my ($titles,$short_titles) = &contact_titles();
17368: $resulttext = &mt('Changes made:').'<ul>';
17369: foreach my $item (@contacts) {
17370: if ($changes{$item}) {
17371: $resulttext .= '<li>'.$titles->{$item}.
17372: &mt(' set to: ').
17373: '<span class="LC_cusr_emph">'.
17374: $to{$item}.'</span></li>';
17375: }
17376: }
17377: foreach my $type (@mailings) {
17378: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17379: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17380: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17381: } else {
17382: $resulttext .= '<li>'.$titles->{$type}.': ';
17383: }
1.28 raeburn 17384: my @text;
17385: foreach my $item (@{$newsetting{$type}}) {
17386: push(@text,$short_titles->{$item});
17387: }
17388: if ($others{$type} ne '') {
17389: push(@text,$others{$type});
17390: }
1.286 raeburn 17391: if (@text) {
17392: $resulttext .= '<span class="LC_cusr_emph">'.
17393: join(', ',@text).'</span>';
17394: }
17395: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17396: if ($bcc{$type} ne '') {
1.286 raeburn 17397: my $bcctext;
17398: if (@text) {
1.289 raeburn 17399: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17400: } else {
17401: $bcctext = '(Bcc)';
17402: }
17403: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17404: } elsif (!@text) {
17405: $resulttext .= &mt('No one');
1.425 raeburn 17406: }
1.289 raeburn 17407: if ($includestr{$type} ne '') {
1.286 raeburn 17408: if ($includeloc{$type} eq 'b') {
17409: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17410: } elsif ($includeloc{$type} eq 's') {
17411: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17412: }
1.134 raeburn 17413: }
1.286 raeburn 17414: } elsif (!@text) {
17415: $resulttext .= &mt('No recipients');
1.134 raeburn 17416: }
17417: $resulttext .= '</li>';
1.28 raeburn 17418: }
17419: }
1.315 raeburn 17420: if (ref($changes{'overrides'}) eq 'ARRAY') {
17421: my @deletions;
17422: foreach my $type (@{$changes{'overrides'}}) {
17423: if ($usertypeshash{$type}) {
17424: if (grep(/^\Q$type\E/,@overrides)) {
17425: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17426: $usertypeshash{$type}).'<ul><li>';
17427: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17428: my @text;
17429: foreach my $item (@contacts) {
1.425 raeburn 17430: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17431: push(@text,$short_titles->{$item});
17432: }
17433: }
17434: if ($newsetting{'override_'.$type}{'others'} ne '') {
17435: push(@text,$newsetting{'override_'.$type}{'others'});
17436: }
1.425 raeburn 17437:
1.315 raeburn 17438: if (@text) {
17439: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17440: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17441: }
17442: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17443: my $bcctext;
17444: if (@text) {
17445: $bcctext = ' '.&mt('with Bcc to');
17446: } else {
17447: $bcctext = '(Bcc)';
17448: }
17449: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17450: } elsif (!@text) {
17451: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17452: }
17453: $resulttext .= '</li>';
17454: if ($newsetting{'override_'.$type}{'include'} ne '') {
17455: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17456: if ($loc eq 'b') {
17457: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17458: } elsif ($loc eq 's') {
17459: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17460: }
17461: }
17462: }
17463: $resulttext .= '</li></ul></li>';
17464: } else {
17465: push(@deletions,$usertypeshash{$type});
17466: }
17467: }
17468: }
17469: if (@deletions) {
17470: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17471: join(', ',@deletions)).'</li>';
17472: }
17473: }
1.203 raeburn 17474: my @offon = ('off','on');
1.340 raeburn 17475: my $corelink = &core_link_msu();
1.203 raeburn 17476: if ($changes{'reporterrors'}) {
17477: $resulttext .= '<li>'.
17478: &mt('E-mail error reports to [_1] set to "'.
17479: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17480: $corelink).
1.203 raeburn 17481: '</li>';
17482: }
17483: if ($changes{'reportupdates'}) {
17484: $resulttext .= '<li>'.
17485: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17486: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17487: $corelink).
1.203 raeburn 17488: '</li>';
17489: }
1.340 raeburn 17490: if ($changes{'reportstatus'}) {
17491: $resulttext .= '<li>'.
17492: &mt('E-mail status if errors above threshold to [_1] set to "'.
17493: $offon[$env{'form.reportstatus'}].'".',
17494: $corelink).
17495: '</li>';
17496: }
17497: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17498: $resulttext .= '<li>'.
17499: &mt('Nightly status check e-mail settings').':<ul>';
17500: my (%defval,%use_def,%shown);
17501: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17502: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17503: $defval{'weights'} =
1.341 raeburn 17504: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17505: $defval{'excluded'} = &mt('None');
17506: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17507: foreach my $item ('threshold','sysmail','weights','excluded') {
17508: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17509: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17510: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17511: } elsif ($item eq 'weights') {
17512: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17513: foreach my $type ('E','W','N','U') {
1.340 raeburn 17514: $shown{$item} .= $lonstatus_names->{$type}.'=';
17515: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17516: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17517: } else {
17518: $shown{$item} .= $lonstatus_defs->{$type};
17519: }
17520: $shown{$item} .= ', ';
17521: }
17522: $shown{$item} =~ s/, $//;
17523: } else {
17524: $shown{$item} = $defval{$item};
17525: }
17526: } elsif ($item eq 'excluded') {
17527: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17528: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17529: } else {
17530: $shown{$item} = $defval{$item};
17531: }
17532: }
17533: } else {
17534: $shown{$item} = $defval{$item};
17535: }
17536: }
17537: } else {
17538: foreach my $item ('threshold','weights','excluded','sysmail') {
17539: $shown{$item} = $defval{$item};
17540: }
17541: }
17542: foreach my $item ('threshold','weights','excluded','sysmail') {
17543: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17544: $shown{$item}).'</li>';
17545: }
17546: $resulttext .= '</ul></li>';
17547: }
1.286 raeburn 17548: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17549: my (@optional,@required,@unused,$maxsizechg);
17550: foreach my $field (@{$changes{'helpform'}}) {
17551: if ($field eq 'maxsize') {
17552: $maxsizechg = 1;
17553: next;
17554: }
17555: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17556: push(@optional,$field);
1.286 raeburn 17557: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17558: push(@unused,$field);
17559: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17560: push(@required,$field);
1.286 raeburn 17561: }
17562: }
17563: if (@optional) {
17564: $resulttext .= '<li>'.
17565: &mt('Help form fields changed to "Optional": [_1].',
17566: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17567: '</li>';
17568: }
17569: if (@required) {
17570: $resulttext .= '<li>'.
17571: &mt('Help form fields changed to "Required": [_1].',
17572: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17573: '</li>';
17574: }
17575: if (@unused) {
17576: $resulttext .= '<li>'.
17577: &mt('Help form fields changed to "Not shown": [_1].',
17578: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17579: '</li>';
17580: }
17581: if ($maxsizechg) {
17582: $resulttext .= '<li>'.
17583: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17584: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17585: '</li>';
17586: }
17587: }
1.28 raeburn 17588: $resulttext .= '</ul>';
17589: } else {
1.288 raeburn 17590: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17591: }
17592: } else {
17593: $resulttext = '<span class="LC_error">'.
17594: &mt('An error occurred: [_1].',$putresult).'</span>';
17595: }
17596: return $resulttext;
17597: }
17598:
1.357 raeburn 17599: sub modify_privacy {
1.427 raeburn 17600: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17601: my ($resulttext,%current,%changes);
17602: if (ref($domconfig{'privacy'}) eq 'HASH') {
17603: %current = %{$domconfig{'privacy'}};
17604: }
17605: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17606: my @items = ('domain','author','course','community');
17607: my %names = &Apache::lonlocal::texthash (
17608: domain => 'Assigned domain role(s)',
17609: author => 'Assigned co-author role(s)',
17610: course => 'Assigned course role(s)',
1.416 raeburn 17611: community => 'Assigned community role(s)',
1.357 raeburn 17612: );
17613: my %roles = &Apache::lonlocal::texthash (
17614: domain => 'Domain role',
17615: author => 'Co-author role',
17616: course => 'Course role',
17617: community => 'Community role',
17618: );
17619: my %titles = &Apache::lonlocal::texthash (
17620: approval => 'Approval for role in different domain',
17621: othdom => 'User information available in other domain',
17622: priv => 'Information viewable by privileged user in same domain',
17623: unpriv => 'Information viewable by unprivileged user in same domain',
17624: instdom => 'Other domain shares institution/provider',
17625: extdom => 'Other domain has different institution/provider',
17626: none => 'Not allowed',
17627: user => 'User authorizes',
17628: domain => 'Domain Coordinator authorizes',
17629: auto => 'Unrestricted',
1.418 raeburn 17630: notify => 'Notify when role needs authorization',
1.357 raeburn 17631: );
17632: my %fieldnames = &Apache::lonlocal::texthash (
17633: id => 'Student/Employee ID',
17634: permanentemail => 'E-mail address',
17635: lastname => 'Last Name',
17636: firstname => 'First Name',
17637: middlename => 'Middle Name',
17638: generation => 'Generation',
17639: );
17640: my ($othertitle,$usertypes,$types) =
17641: &Apache::loncommon::sorted_inst_types($dom);
17642: my (%by_ip,%by_location,@intdoms,@instdoms);
17643: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17644:
17645: my %privacyhash = (
17646: 'approval' => {
17647: instdom => {},
17648: extdom => {},
17649: },
17650: 'othdom' => {},
17651: 'priv' => {},
17652: 'unpriv' => {},
17653: );
17654: foreach my $item (@items) {
17655: if (@instdoms > 1) {
1.416 raeburn 17656: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17657: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17658: }
17659: if (ref($current{'approval'}) eq 'HASH') {
17660: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17661: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17662: $changes{'approval'} = 1;
17663: }
17664: }
17665: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17666: $changes{'approval'} = 1;
17667: }
17668: }
17669: if (keys(%by_location) > 0) {
17670: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17671: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17672: }
17673: if (ref($current{'approval'}) eq 'HASH') {
17674: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17675: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17676: $changes{'approval'} = 1;
17677: }
17678: }
17679: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17680: $changes{'approval'} = 1;
17681: }
17682: }
17683: foreach my $status ('priv','unpriv') {
17684: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17685: my @newvalues;
17686: foreach my $field (@possibles) {
17687: if (grep(/^\Q$field\E$/,@fields)) {
17688: $privacyhash{$status}{$item}{$field} = 1;
17689: push(@newvalues,$field);
17690: }
17691: }
17692: @newvalues = sort(@newvalues);
17693: if (ref($current{$status}) eq 'HASH') {
17694: if (ref($current{$status}{$item}) eq 'HASH') {
17695: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17696: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17697: if (@diffs > 0) {
17698: $changes{$status} = 1;
17699: }
17700: }
17701: } else {
17702: my @stdfields;
17703: foreach my $field (@fields) {
17704: if ($field eq 'id') {
17705: next if ($status eq 'unpriv');
17706: next if (($status eq 'priv') && ($item eq 'community'));
17707: }
17708: push(@stdfields,$field);
17709: }
17710: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17711: if (@diffs > 0) {
17712: $changes{$status} = 1;
17713: }
17714: }
17715: }
17716: }
17717: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17718: my @statuses;
17719: if (ref($types) eq 'ARRAY') {
17720: @statuses = @{$types};
17721: }
17722: foreach my $type (@statuses,'default') {
17723: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17724: my @newvalues;
17725: foreach my $field (sort(@possfields)) {
17726: if (grep(/^\Q$field\E$/,@fields)) {
17727: $privacyhash{'othdom'}{$type}{$field} = 1;
17728: push(@newvalues,$field);
17729: }
17730: }
17731: @newvalues = sort(@newvalues);
17732: if (ref($current{'othdom'}) eq 'HASH') {
17733: if (ref($current{'othdom'}{$type}) eq 'HASH') {
17734: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
17735: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17736: if (@diffs > 0) {
17737: $changes{'othdom'} = 1;
17738: }
17739: }
17740: } else {
17741: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
17742: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17743: if (@diffs > 0) {
17744: $changes{'othdom'} = 1;
17745: }
17746: }
17747: }
1.417 raeburn 17748: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
17749: my %notify;
17750: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
17751: if (exists($domcoords{$possdc})) {
17752: $notify{$possdc} = 1;
17753: }
17754: }
17755: my $notify = join(',',sort(keys(%notify)));
17756: if ($current{'notify'} ne $notify) {
17757: $changes{'notify'} = 1;
17758: }
17759: $privacyhash{'notify'} = $notify;
1.357 raeburn 17760: }
17761: my %confighash = (
17762: privacy => \%privacyhash,
17763: );
17764: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17765: if ($putresult eq 'ok') {
17766: if (keys(%changes) > 0) {
17767: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 17768: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 17769: if ($changes{$key}) {
17770: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17771: if ($key eq 'approval') {
17772: if (keys(%{$privacyhash{$key}{instdom}})) {
17773: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
17774: foreach my $item (@items) {
17775: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
17776: }
17777: $resulttext .= '</ul></li>';
17778: }
17779: if (keys(%{$privacyhash{$key}{extdom}})) {
17780: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
17781: foreach my $item (@items) {
17782: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
17783: }
17784: $resulttext .= '</ul></li>';
17785: }
1.417 raeburn 17786: } elsif ($key eq 'notify') {
17787: if ($privacyhash{$key}) {
17788: foreach my $dc (split(/,/,$privacyhash{$key})) {
17789: my ($dcname,$dcdom) = split(/:/,$dc);
17790: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
17791: }
17792: } else {
17793: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
17794: }
1.357 raeburn 17795: } elsif ($key eq 'othdom') {
17796: my @statuses;
17797: if (ref($types) eq 'ARRAY') {
17798: @statuses = @{$types};
17799: }
17800: if (ref($privacyhash{$key}) eq 'HASH') {
17801: foreach my $status (@statuses,'default') {
17802: if ($status eq 'default') {
17803: $resulttext .= '<li>'.$othertitle.': ';
17804: } elsif (ref($usertypes) eq 'HASH') {
17805: $resulttext .= '<li>'.$usertypes->{$status}.': ';
17806: } else {
17807: next;
17808: }
17809: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
17810: if (keys(%{$privacyhash{$key}{$status}})) {
17811: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
17812: } else {
17813: $resulttext .= &mt('none');
17814: }
17815: }
17816: $resulttext .= '</li>';
17817: }
17818: }
17819: } else {
17820: foreach my $item (@items) {
17821: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
17822: $resulttext .= '<li>'.$names{$item}.': ';
17823: if (keys(%{$privacyhash{$key}{$item}})) {
17824: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
17825: } else {
17826: $resulttext .= &mt('none');
17827: }
17828: $resulttext .= '</li>';
17829: }
17830: }
17831: }
17832: $resulttext .= '</ul></li>';
17833: }
17834: }
1.421 raeburn 17835: $resulttext .= '</ul>';
1.427 raeburn 17836: if ($changes{'approval'}) {
17837: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
17838: delete($domdefaults{'userapprovals'});
17839: if (ref($privacyhash{'approval'}) eq 'HASH') {
17840: foreach my $domtype ('instdom','extdom') {
17841: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
17842: foreach my $roletype ('domain','author','course','community') {
17843: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
17844: $domdefaults{'userapprovals'} = 1;
17845: last;
17846: }
17847: }
17848: }
17849: last if ($domdefaults{'userapprovals'});
17850: }
17851: }
17852: my $cachetime = 24*60*60;
17853: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17854: if (ref($lastactref) eq 'HASH') {
17855: $lastactref->{'domdefaults'} = 1;
17856: }
17857: }
1.357 raeburn 17858: } else {
17859: $resulttext = &mt('No changes made to user information settings');
17860: }
17861: } else {
17862: $resulttext = '<span class="LC_error">'.
17863: &mt('An error occurred: [_1]',$putresult).'</span>';
17864: }
17865: return $resulttext;
17866: }
17867:
1.354 raeburn 17868: sub modify_passwords {
17869: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 17870: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
17871: $updatedefaults,$updateconf);
1.354 raeburn 17872: my $customfn = 'resetpw.html';
17873: if (ref($domconfig{'passwords'}) eq 'HASH') {
17874: %current = %{$domconfig{'passwords'}};
17875: }
17876: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17877: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17878: if (ref($types) eq 'ARRAY') {
17879: @oktypes = @{$types};
17880: }
17881: push(@oktypes,'default');
17882:
17883: my %titles = &Apache::lonlocal::texthash (
17884: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
17885: intauth_check => 'Check bcrypt cost if authenticated',
17886: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
17887: permanent => 'Permanent e-mail address',
17888: critical => 'Critical notification address',
17889: notify => 'Notification address',
17890: min => 'Minimum password length',
17891: max => 'Maximum password length',
17892: chars => 'Required characters',
17893: expire => 'Password expiration (days)',
1.356 raeburn 17894: numsaved => 'Number of previous passwords to save',
1.354 raeburn 17895: reset => 'Resetting Forgotten Password',
17896: intauth => 'Encryption of Stored Passwords (Internal Auth)',
17897: rules => 'Rules for LON-CAPA Passwords',
17898: crsownerchg => 'Course Owner Changing Student Passwords',
17899: username => 'Username',
17900: email => 'E-mail address',
17901: );
17902:
17903: #
17904: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
17905: #
17906: my (%curr_defaults,%save_defaults);
17907: if (ref($domconfig{'defaults'}) eq 'HASH') {
17908: foreach my $key (keys(%{$domconfig{'defaults'}})) {
17909: if ($key =~ /^intauth_(cost|check|switch)$/) {
17910: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
17911: } else {
17912: $save_defaults{$key} = $domconfig{'defaults'}{$key};
17913: }
17914: }
17915: }
17916: my %staticdefaults = (
17917: 'resetlink' => 2,
17918: 'resetcase' => \@oktypes,
17919: 'resetprelink' => 'both',
17920: 'resetemail' => ['critical','notify','permanent'],
17921: 'intauth_cost' => 10,
17922: 'intauth_check' => 0,
17923: 'intauth_switch' => 0,
17924: );
1.365 raeburn 17925: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 17926: foreach my $type (@oktypes) {
17927: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
17928: }
17929: my $linklife = $env{'form.passwords_link'};
17930: $linklife =~ s/^\s+|\s+$//g;
17931: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
17932: $newvalues{'resetlink'} = $linklife;
17933: if ($current{'resetlink'}) {
17934: if ($current{'resetlink'} ne $linklife) {
17935: $changes{'reset'} = 1;
17936: }
1.368 raeburn 17937: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17938: if ($staticdefaults{'resetlink'} ne $linklife) {
17939: $changes{'reset'} = 1;
17940: }
17941: }
17942: } elsif ($current{'resetlink'}) {
17943: $changes{'reset'} = 1;
17944: }
17945: my @casesens;
17946: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
17947: foreach my $case (sort(@posscase)) {
17948: if (grep(/^\Q$case\E$/,@oktypes)) {
17949: push(@casesens,$case);
17950: }
17951: }
17952: $newvalues{'resetcase'} = \@casesens;
17953: if (ref($current{'resetcase'}) eq 'ARRAY') {
17954: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
17955: if (@diffs > 0) {
17956: $changes{'reset'} = 1;
17957: }
1.368 raeburn 17958: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17959: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
17960: if (@diffs > 0) {
17961: $changes{'reset'} = 1;
17962: }
17963: }
17964: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
17965: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
17966: if (exists($current{'resetprelink'})) {
17967: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
17968: $changes{'reset'} = 1;
17969: }
1.368 raeburn 17970: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17971: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
17972: $changes{'reset'} = 1;
17973: }
17974: }
17975: } elsif ($current{'resetprelink'}) {
17976: $changes{'reset'} = 1;
17977: }
17978: foreach my $type (@oktypes) {
17979: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
17980: my @postlink;
17981: foreach my $item (sort(@possplink)) {
17982: if ($item =~ /^(email|username)$/) {
17983: push(@postlink,$item);
17984: }
17985: }
17986: $newvalues{'resetpostlink'}{$type} = \@postlink;
17987: unless ($changes{'reset'}) {
17988: if (ref($current{'resetpostlink'}) eq 'HASH') {
17989: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
17990: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
17991: if (@diffs > 0) {
17992: $changes{'reset'} = 1;
17993: }
17994: } else {
17995: $changes{'reset'} = 1;
17996: }
1.368 raeburn 17997: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17998: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
17999: if (@diffs > 0) {
18000: $changes{'reset'} = 1;
18001: }
18002: }
18003: }
18004: }
18005: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18006: my @resetemail;
18007: foreach my $item (sort(@possemailsrc)) {
18008: if ($item =~ /^(permanent|critical|notify)$/) {
18009: push(@resetemail,$item);
18010: }
18011: }
18012: $newvalues{'resetemail'} = \@resetemail;
18013: unless ($changes{'reset'}) {
18014: if (ref($current{'resetemail'}) eq 'ARRAY') {
18015: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18016: if (@diffs > 0) {
18017: $changes{'reset'} = 1;
18018: }
1.368 raeburn 18019: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18020: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18021: if (@diffs > 0) {
18022: $changes{'reset'} = 1;
18023: }
18024: }
18025: }
18026: if ($env{'form.passwords_stdtext'} == 0) {
18027: $newvalues{'resetremove'} = 1;
18028: unless ($current{'resetremove'}) {
18029: $changes{'reset'} = 1;
18030: }
18031: } elsif ($current{'resetremove'}) {
18032: $changes{'reset'} = 1;
18033: }
18034: if ($env{'form.passwords_customfile.filename'} ne '') {
18035: my $servadm = $r->dir_config('lonAdmEMail');
18036: my ($configuserok,$author_ok,$switchserver) =
18037: &config_check($dom,$confname,$servadm);
18038: my $error;
18039: if ($configuserok eq 'ok') {
18040: if ($switchserver) {
18041: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18042: } else {
18043: if ($author_ok eq 'ok') {
1.421 raeburn 18044: my $modified = [];
1.354 raeburn 18045: my ($result,$customurl) =
1.421 raeburn 18046: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18047: $confname,'customtext/resetpw','','',$customfn,
18048: $modified);
1.354 raeburn 18049: if ($result eq 'ok') {
18050: $newvalues{'resetcustom'} = $customurl;
18051: $changes{'reset'} = 1;
1.421 raeburn 18052: &update_modify_urls($r,$modified);
1.354 raeburn 18053: } else {
18054: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18055: }
18056: } else {
18057: $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);
18058: }
18059: }
18060: } else {
18061: $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);
18062: }
18063: if ($error) {
18064: &Apache::lonnet::logthis($error);
18065: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18066: }
18067: } elsif ($current{'resetcustom'}) {
18068: if ($env{'form.passwords_custom_del'}) {
18069: $changes{'reset'} = 1;
18070: } else {
18071: $newvalues{'resetcustom'} = $current{'resetcustom'};
18072: }
18073: }
18074: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18075: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18076: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18077: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18078: $changes{'intauth'} = 1;
18079: }
18080: } else {
18081: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18082: }
18083: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18084: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18085: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18086: $changes{'intauth'} = 1;
18087: }
18088: } else {
18089: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18090: }
18091: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18092: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18093: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18094: $changes{'intauth'} = 1;
18095: }
18096: } else {
18097: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18098: }
18099: foreach my $item ('cost','check','switch') {
18100: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18101: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18102: $updatedefaults = 1;
18103: }
18104: }
1.405 raeburn 18105: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18106: my %crsownerchg = (
18107: by => [],
18108: for => [],
18109: );
18110: foreach my $item ('by','for') {
18111: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18112: foreach my $type (sort(@posstypes)) {
18113: if (grep(/^\Q$type\E$/,@oktypes)) {
18114: push(@{$crsownerchg{$item}},$type);
18115: }
18116: }
18117: }
18118: $newvalues{'crsownerchg'} = \%crsownerchg;
18119: if (ref($current{'crsownerchg'}) eq 'HASH') {
18120: foreach my $item ('by','for') {
18121: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18122: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18123: if (@diffs > 0) {
18124: $changes{'crsownerchg'} = 1;
18125: last;
18126: }
18127: }
18128: }
1.368 raeburn 18129: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18130: foreach my $item ('by','for') {
18131: if (@{$crsownerchg{$item}} > 0) {
18132: $changes{'crsownerchg'} = 1;
18133: last;
18134: }
1.354 raeburn 18135: }
18136: }
18137:
18138: my %confighash = (
18139: defaults => \%save_defaults,
18140: passwords => \%newvalues,
18141: );
18142: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18143:
18144: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18145: if ($putresult eq 'ok') {
18146: if (keys(%changes) > 0) {
18147: $resulttext = &mt('Changes made: ').'<ul>';
18148: foreach my $key ('reset','intauth','rules','crsownerchg') {
18149: if ($changes{$key}) {
1.355 raeburn 18150: unless ($key eq 'intauth') {
18151: $updateconf = 1;
18152: }
1.354 raeburn 18153: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18154: if ($key eq 'reset') {
18155: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18156: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18157: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18158: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18159: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18160: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18161: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18162: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18163: }
1.354 raeburn 18164: } else {
18165: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18166: }
18167: if ($confighash{'passwords'}{'resetlink'}) {
18168: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18169: } else {
18170: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18171: &mt('Will default to 2 hours').'</li>';
18172: }
18173: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18174: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18175: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18176: } else {
18177: my $casesens;
18178: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18179: if ($type eq 'default') {
18180: $casesens .= $othertitle.', ';
18181: } elsif ($usertypes->{$type} ne '') {
18182: $casesens .= $usertypes->{$type}.', ';
18183: }
18184: }
18185: $casesens =~ s/\Q, \E$//;
18186: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18187: }
18188: } else {
18189: $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>';
18190: }
18191: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18192: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18193: } else {
18194: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18195: }
18196: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18197: my $output;
18198: if (ref($types) eq 'ARRAY') {
18199: foreach my $type (@{$types}) {
18200: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18201: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18202: $output .= $usertypes->{$type}.' -- '.&mt('none');
18203: } else {
18204: $output .= $usertypes->{$type}.' -- '.
18205: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18206: }
18207: }
18208: }
18209: }
18210: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18211: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18212: $output .= $othertitle.' -- '.&mt('none');
18213: } else {
18214: $output .= $othertitle.' -- '.
18215: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18216: }
18217: }
18218: if ($output) {
18219: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18220: } else {
18221: $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>';
18222: }
18223: } else {
18224: $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>';
18225: }
18226: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18227: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18228: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18229: } else {
18230: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18231: }
18232: } else {
1.379 raeburn 18233: $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 18234: }
18235: if ($confighash{'passwords'}{'resetremove'}) {
18236: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18237: } else {
18238: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18239: }
18240: if ($confighash{'passwords'}{'resetcustom'}) {
18241: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18242: &mt('custom text'),600,500,undef,undef,
18243: undef,undef,'background-color:#ffffff');
18244: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18245: } else {
18246: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18247: }
18248: } elsif ($key eq 'intauth') {
18249: foreach my $item ('cost','switch','check') {
18250: my $value = $save_defaults{$key.'_'.$item};
18251: if ($item eq 'switch') {
18252: my %optiondesc = &Apache::lonlocal::texthash (
18253: 0 => 'No',
18254: 1 => 'Yes',
18255: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18256: );
18257: if ($value =~ /^(0|1|2)$/) {
18258: $value = $optiondesc{$value};
18259: } else {
18260: $value = &mt('none -- defaults to No');
18261: }
18262: } elsif ($item eq 'check') {
18263: my %optiondesc = &Apache::lonlocal::texthash (
18264: 0 => 'No',
18265: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18266: 2 => 'Yes, disallow login if stored cost is less than domain default',
18267: );
18268: if ($value =~ /^(0|1|2)$/) {
18269: $value = $optiondesc{$value};
18270: } else {
18271: $value = &mt('none -- defaults to No');
18272: }
18273: }
18274: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18275: }
18276: } elsif ($key eq 'rules') {
1.356 raeburn 18277: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18278: if ($confighash{'passwords'}{$rule} eq '') {
18279: if ($rule eq 'min') {
1.356 raeburn 18280: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18281: ' '.&mt('Default of [_1] will be used',
18282: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18283: } else {
18284: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18285: }
18286: } else {
18287: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18288: }
18289: }
1.370 raeburn 18290: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18291: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18292: my %rulenames = &Apache::lonlocal::texthash(
18293: uc => 'At least one upper case letter',
18294: lc => 'At least one lower case letter',
18295: num => 'At least one number',
18296: spec => 'At least one non-alphanumeric',
18297: );
18298: my $needed = '<ul><li>'.
18299: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18300: '</li></ul>';
1.370 raeburn 18301: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18302: } else {
18303: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18304: }
18305: } else {
18306: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18307: }
1.354 raeburn 18308: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18309: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18310: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18311: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18312: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18313: } else {
18314: my %crsownerstr;
18315: foreach my $item ('by','for') {
18316: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18317: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18318: if ($type eq 'default') {
18319: $crsownerstr{$item} .= $othertitle.', ';
18320: } elsif ($usertypes->{$type} ne '') {
18321: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18322: }
18323: }
18324: $crsownerstr{$item} =~ s/\Q, \E$//;
18325: }
18326: }
18327: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18328: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18329: }
1.354 raeburn 18330: } else {
1.359 raeburn 18331: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18332: }
18333: }
18334: $resulttext .= '</ul></li>';
18335: }
18336: }
18337: $resulttext .= '</ul>';
18338: } else {
18339: $resulttext = &mt('No changes made to password settings');
18340: }
1.355 raeburn 18341: my $cachetime = 24*60*60;
1.354 raeburn 18342: if ($updatedefaults) {
18343: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18344: if (ref($lastactref) eq 'HASH') {
18345: $lastactref->{'domdefaults'} = 1;
18346: }
18347: }
1.355 raeburn 18348: if ($updateconf) {
18349: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18350: if (ref($lastactref) eq 'HASH') {
18351: $lastactref->{'passwdconf'} = 1;
18352: }
18353: }
1.354 raeburn 18354: } else {
18355: $resulttext = '<span class="LC_error">'.
18356: &mt('An error occurred: [_1]',$putresult).'</span>';
18357: }
18358: if ($errors) {
18359: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18360: $errors.'</ul></p>';
18361: }
18362: return $resulttext;
18363: }
18364:
1.405 raeburn 18365: sub password_rule_changes {
18366: my ($prefix,$newvalues,$current,$changes) = @_;
18367: return unless ((ref($newvalues) eq 'HASH') &&
18368: (ref($current) eq 'HASH') &&
18369: (ref($changes) eq 'HASH'));
18370: my (@rules,%staticdefaults);
18371: if ($prefix eq 'passwords') {
18372: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18373: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18374: @rules = ('min','max');
18375: }
18376: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18377: foreach my $rule (@rules) {
18378: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18379: my $ruleok;
18380: if ($rule eq 'expire') {
18381: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18382: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18383: $ruleok = 1;
18384: }
18385: } elsif ($rule eq 'min') {
18386: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18387: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18388: $ruleok = 1;
18389: }
18390: }
18391: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18392: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18393: $ruleok = 1;
18394: }
18395: if ($ruleok) {
18396: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18397: if (exists($current->{$rule})) {
18398: if ($newvalues->{$rule} ne $current->{$rule}) {
18399: $changes->{'rules'} = 1;
18400: }
18401: } elsif ($rule eq 'min') {
18402: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18403: $changes->{'rules'} = 1;
18404: }
18405: } else {
18406: $changes->{'rules'} = 1;
18407: }
18408: } elsif (exists($current->{$rule})) {
18409: $changes->{'rules'} = 1;
18410: }
18411: }
18412: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18413: my @chars;
18414: foreach my $item (sort(@posschars)) {
18415: if ($item =~ /^(uc|lc|num|spec)$/) {
18416: push(@chars,$item);
18417: }
18418: }
18419: $newvalues->{'chars'} = \@chars;
18420: unless ($changes->{'rules'}) {
18421: if (ref($current->{'chars'}) eq 'ARRAY') {
18422: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18423: if (@diffs > 0) {
18424: $changes->{'rules'} = 1;
18425: }
18426: } else {
18427: if (@chars > 0) {
18428: $changes->{'rules'} = 1;
18429: }
18430: }
18431: }
18432: return;
18433: }
18434:
1.28 raeburn 18435: sub modify_usercreation {
1.27 raeburn 18436: my ($dom,%domconfig) = @_;
1.224 raeburn 18437: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18438: my $warningmsg;
1.27 raeburn 18439: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18440: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18441: if ($key eq 'cancreate') {
18442: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18443: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18444: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18445: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18446: } else {
1.224 raeburn 18447: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18448: }
18449: }
18450: }
18451: } elsif ($key eq 'email_rule') {
18452: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18453: } else {
18454: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18455: }
1.27 raeburn 18456: }
18457: }
18458: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18459: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18460: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18461: foreach my $item(@contexts) {
1.224 raeburn 18462: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18463: }
1.34 raeburn 18464: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18465: foreach my $item (@contexts) {
1.224 raeburn 18466: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18467: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18468: }
1.27 raeburn 18469: }
1.34 raeburn 18470: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18471: foreach my $item (@contexts) {
1.43 raeburn 18472: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18473: if ($cancreate{$item} ne 'any') {
18474: push(@{$changes{'cancreate'}},$item);
18475: }
18476: } else {
18477: if ($cancreate{$item} ne 'none') {
18478: push(@{$changes{'cancreate'}},$item);
18479: }
1.27 raeburn 18480: }
18481: }
18482: } else {
1.43 raeburn 18483: foreach my $item (@contexts) {
1.34 raeburn 18484: push(@{$changes{'cancreate'}},$item);
18485: }
1.27 raeburn 18486: }
1.34 raeburn 18487:
1.27 raeburn 18488: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18489: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18490: if (!grep(/^\Q$type\E$/,@username_rule)) {
18491: push(@{$changes{'username_rule'}},$type);
18492: }
18493: }
18494: foreach my $type (@username_rule) {
18495: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18496: push(@{$changes{'username_rule'}},$type);
18497: }
18498: }
18499: } else {
18500: push(@{$changes{'username_rule'}},@username_rule);
18501: }
18502:
1.32 raeburn 18503: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18504: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18505: if (!grep(/^\Q$type\E$/,@id_rule)) {
18506: push(@{$changes{'id_rule'}},$type);
18507: }
18508: }
18509: foreach my $type (@id_rule) {
18510: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18511: push(@{$changes{'id_rule'}},$type);
18512: }
18513: }
18514: } else {
18515: push(@{$changes{'id_rule'}},@id_rule);
18516: }
18517:
1.43 raeburn 18518: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18519: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18520: my %authhash;
1.43 raeburn 18521: foreach my $item (@authen_contexts) {
1.28 raeburn 18522: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18523: foreach my $auth (@authtypes) {
18524: if (grep(/^\Q$auth\E$/,@authallowed)) {
18525: $authhash{$item}{$auth} = 1;
18526: } else {
18527: $authhash{$item}{$auth} = 0;
18528: }
18529: }
18530: }
18531: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18532: foreach my $item (@authen_contexts) {
1.28 raeburn 18533: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18534: foreach my $auth (@authtypes) {
18535: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18536: push(@{$changes{'authtypes'}},$item);
18537: last;
18538: }
18539: }
18540: }
18541: }
18542: } else {
1.43 raeburn 18543: foreach my $item (@authen_contexts) {
1.28 raeburn 18544: push(@{$changes{'authtypes'}},$item);
18545: }
18546: }
18547:
1.224 raeburn 18548: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18549: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18550: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18551: $save_usercreate{'id_rule'} = \@id_rule;
18552: $save_usercreate{'username_rule'} = \@username_rule,
18553: $save_usercreate{'authtypes'} = \%authhash;
18554:
1.27 raeburn 18555: my %usercreation_hash = (
1.224 raeburn 18556: usercreation => \%save_usercreate,
18557: );
1.27 raeburn 18558:
18559: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18560: $dom);
1.50 raeburn 18561:
1.224 raeburn 18562: if ($putresult eq 'ok') {
18563: if (keys(%changes) > 0) {
18564: $resulttext = &mt('Changes made:').'<ul>';
18565: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18566: my %lt = &usercreation_types();
18567: foreach my $type (@{$changes{'cancreate'}}) {
18568: my $chgtext = $lt{$type}.', ';
18569: if ($cancreate{$type} eq 'none') {
18570: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18571: } elsif ($cancreate{$type} eq 'any') {
18572: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18573: } elsif ($cancreate{$type} eq 'official') {
18574: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18575: } elsif ($cancreate{$type} eq 'unofficial') {
18576: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18577: }
18578: $resulttext .= '<li>'.$chgtext.'</li>';
18579: }
18580: }
18581: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18582: my ($rules,$ruleorder) =
18583: &Apache::lonnet::inst_userrules($dom,'username');
18584: my $chgtext = '<ul>';
18585: foreach my $type (@username_rule) {
18586: if (ref($rules->{$type}) eq 'HASH') {
18587: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18588: }
18589: }
18590: $chgtext .= '</ul>';
18591: if (@username_rule > 0) {
18592: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18593: } else {
18594: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18595: }
18596: }
18597: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18598: my ($idrules,$idruleorder) =
18599: &Apache::lonnet::inst_userrules($dom,'id');
18600: my $chgtext = '<ul>';
18601: foreach my $type (@id_rule) {
18602: if (ref($idrules->{$type}) eq 'HASH') {
18603: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18604: }
18605: }
18606: $chgtext .= '</ul>';
18607: if (@id_rule > 0) {
18608: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18609: } else {
18610: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18611: }
18612: }
18613: my %authname = &authtype_names();
18614: my %context_title = &context_names();
18615: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18616: my $chgtext = '<ul>';
18617: foreach my $type (@{$changes{'authtypes'}}) {
18618: my @allowed;
18619: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18620: foreach my $auth (@authtypes) {
18621: if ($authhash{$type}{$auth}) {
18622: push(@allowed,$authname{$auth});
18623: }
18624: }
18625: if (@allowed > 0) {
18626: $chgtext .= join(', ',@allowed).'</li>';
18627: } else {
18628: $chgtext .= &mt('none').'</li>';
18629: }
18630: }
18631: $chgtext .= '</ul>';
18632: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18633: $resulttext .= '</li>';
18634: }
18635: $resulttext .= '</ul>';
18636: } else {
18637: $resulttext = &mt('No changes made to user creation settings');
18638: }
18639: } else {
18640: $resulttext = '<span class="LC_error">'.
18641: &mt('An error occurred: [_1]',$putresult).'</span>';
18642: }
18643: if ($warningmsg ne '') {
18644: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18645: }
18646: return $resulttext;
18647: }
18648:
18649: sub modify_selfcreation {
1.305 raeburn 18650: my ($dom,$lastactref,%domconfig) = @_;
18651: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18652: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18653: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18654: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18655: if (ref($typesref) eq 'ARRAY') {
18656: @types = @{$typesref};
18657: }
18658: if (ref($usertypesref) eq 'HASH') {
18659: %usertypes = %{$usertypesref};
1.228 raeburn 18660: }
1.303 raeburn 18661: $usertypes{'default'} = $othertitle;
1.224 raeburn 18662: #
18663: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18664: #
18665: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18666: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18667: if ($key eq 'cancreate') {
18668: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18669: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18670: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18671: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18672: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18673: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18674: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18675: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18676: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18677: } else {
18678: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18679: }
18680: }
18681: }
18682: } elsif ($key eq 'email_rule') {
18683: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18684: } else {
18685: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18686: }
18687: }
18688: }
18689: #
18690: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18691: #
18692: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18693: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18694: if ($key eq 'selfcreate') {
18695: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18696: } else {
18697: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18698: }
18699: }
18700: }
1.305 raeburn 18701: #
18702: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18703: #
18704: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18705: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18706: if ($key eq 'inststatusguest') {
18707: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18708: } else {
18709: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18710: }
18711: }
18712: }
1.224 raeburn 18713:
18714: my @contexts = ('selfcreate');
18715: @{$cancreate{'selfcreate'}} = ();
18716: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18717: if (@types) {
18718: @{$cancreate{'statustocreate'}} = ();
18719: }
1.236 raeburn 18720: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18721: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18722: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18723: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18724: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18725: my %selfcreatetypes = (
18726: sso => 'users authenticated by institutional single sign on',
18727: login => 'users authenticated by institutional log-in',
1.303 raeburn 18728: email => 'users verified by e-mail',
1.50 raeburn 18729: );
1.224 raeburn 18730: #
18731: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18732: # is permitted.
18733: #
1.305 raeburn 18734: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 18735:
1.305 raeburn 18736: my (@statuses,%email_rule);
1.228 raeburn 18737: foreach my $item ('login','sso','email') {
1.224 raeburn 18738: if ($item eq 'email') {
1.236 raeburn 18739: if ($env{'form.cancreate_email'}) {
1.305 raeburn 18740: if (@types) {
18741: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
18742: foreach my $status (@poss_statuses) {
18743: if (grep(/^\Q$status\E$/,(@types,'default'))) {
18744: push(@statuses,$status);
18745: }
18746: }
18747: $save_inststatus{'inststatusguest'} = \@statuses;
18748: } else {
18749: push(@statuses,'default');
18750: }
18751: if (@statuses) {
18752: my %curr_rule;
18753: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
18754: foreach my $type (@statuses) {
18755: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 18756: }
1.305 raeburn 18757: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
18758: foreach my $type (@statuses) {
18759: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
18760: }
18761: }
18762: push(@{$cancreate{'selfcreate'}},'email');
18763: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
18764: my %curremaildom;
18765: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
18766: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
18767: }
18768: foreach my $type (@statuses) {
18769: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
18770: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
18771: }
18772: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
18773: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
18774: }
18775: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
18776: #
18777: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
18778: #
18779: my $chosen = $1;
18780: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
18781: my $emaildom;
18782: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 18783: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 18784: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
18785: if (ref($curremaildom{$type}) eq 'HASH') {
18786: if (exists($curremaildom{$type}{$chosen})) {
18787: if ($curremaildom{$type}{$chosen} ne $emaildom) {
18788: push(@{$changes{'cancreate'}},'emaildomain');
18789: }
18790: } elsif ($emaildom ne '') {
18791: push(@{$changes{'cancreate'}},'emaildomain');
18792: }
18793: } elsif ($emaildom ne '') {
18794: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 18795: }
1.305 raeburn 18796: }
18797: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18798: } elsif ($chosen eq 'custom') {
18799: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
18800: $email_rule{$type} = [];
18801: if (ref($emailrules) eq 'HASH') {
18802: foreach my $rule (@possemail_rules) {
18803: if (exists($emailrules->{$rule})) {
18804: push(@{$email_rule{$type}},$rule);
18805: }
18806: }
18807: }
18808: if (@{$email_rule{$type}}) {
18809: $cancreate{'emailoptions'}{$type} = 'custom';
18810: if (ref($curr_rule{$type}) eq 'ARRAY') {
18811: if (@{$curr_rule{$type}} > 0) {
18812: foreach my $rule (@{$curr_rule{$type}}) {
18813: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
18814: push(@{$changes{'email_rule'}},$type);
18815: }
18816: }
18817: }
18818: foreach my $type (@{$email_rule{$type}}) {
18819: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
18820: push(@{$changes{'email_rule'}},$type);
18821: }
18822: }
18823: } else {
18824: push(@{$changes{'email_rule'}},$type);
18825: }
18826: }
18827: } else {
18828: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18829: }
18830: }
18831: }
18832: if (@types) {
18833: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18834: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
18835: if (@changed) {
18836: push(@{$changes{'inststatus'}},'inststatusguest');
18837: }
18838: } else {
18839: push(@{$changes{'inststatus'}},'inststatusguest');
18840: }
18841: }
18842: } else {
18843: delete($env{'form.cancreate_email'});
18844: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18845: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18846: push(@{$changes{'inststatus'}},'inststatusguest');
18847: }
18848: }
18849: }
18850: } else {
18851: $save_inststatus{'inststatusguest'} = [];
18852: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18853: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18854: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 18855: }
18856: }
1.224 raeburn 18857: }
18858: } else {
18859: if ($env{'form.cancreate_'.$item}) {
18860: push(@{$cancreate{'selfcreate'}},$item);
18861: }
18862: }
18863: }
1.305 raeburn 18864: my (%userinfo,%savecaptcha);
1.224 raeburn 18865: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
18866: #
1.228 raeburn 18867: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
18868: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 18869: #
1.236 raeburn 18870:
1.244 raeburn 18871: if ($env{'form.cancreate_email'}) {
1.228 raeburn 18872: push(@contexts,'emailusername');
1.305 raeburn 18873: if (@statuses) {
18874: foreach my $type (@statuses) {
1.228 raeburn 18875: if (ref($infofields) eq 'ARRAY') {
18876: foreach my $field (@{$infofields}) {
18877: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
18878: $cancreate{'emailusername'}{$type}{$field} = $1;
18879: }
18880: }
1.224 raeburn 18881: }
18882: }
18883: }
18884: #
18885: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 18886: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 18887: #
18888:
18889: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
18890: @approvalnotify = sort(@approvalnotify);
18891: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
18892: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18893: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
18894: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
18895: push(@{$changes{'cancreate'}},'notify');
18896: }
18897: } else {
18898: if ($cancreate{'notify'}{'approval'}) {
18899: push(@{$changes{'cancreate'}},'notify');
18900: }
18901: }
18902: } elsif ($cancreate{'notify'}{'approval'}) {
18903: push(@{$changes{'cancreate'}},'notify');
18904: }
18905:
18906: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
18907: }
18908: #
1.236 raeburn 18909: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 18910: # institutional log-in.
18911: #
18912: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
18913: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
18914: ($domdefaults{'auth_def'} eq 'localauth'))) {
18915: $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.').' '.
18916: &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.');
18917: }
18918: }
18919: my @fields = ('lastname','firstname','middlename','generation',
18920: 'permanentemail','id');
1.240 raeburn 18921: my @shibfields = (@fields,'inststatus');
1.224 raeburn 18922: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18923: #
18924: # Where usernames may created for institutional log-in and/or institutional single sign on:
18925: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
18926: # may self-create accounts
18927: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
18928: # which the user may supply, if institutional data is unavailable.
18929: #
18930: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 18931: if (@types) {
1.305 raeburn 18932: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
18933: push(@contexts,'statustocreate');
1.303 raeburn 18934: foreach my $type (@types) {
1.224 raeburn 18935: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
18936: foreach my $field (@fields) {
18937: if (grep(/^\Q$field\E$/,@modifiable)) {
18938: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
18939: } else {
18940: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
18941: }
18942: }
18943: }
18944: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 18945: foreach my $type (@types) {
1.224 raeburn 18946: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
18947: foreach my $field (@fields) {
18948: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
18949: $curr_usermodify{'selfcreate'}{$type}{$field}) {
18950: push(@{$changes{'selfcreate'}},$type);
18951: last;
18952: }
18953: }
18954: }
18955: }
18956: } else {
1.303 raeburn 18957: foreach my $type (@types) {
1.224 raeburn 18958: push(@{$changes{'selfcreate'}},$type);
18959: }
18960: }
18961: }
1.240 raeburn 18962: foreach my $field (@shibfields) {
18963: if ($env{'form.shibenv_'.$field} ne '') {
18964: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
18965: }
18966: }
18967: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18968: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
18969: foreach my $field (@shibfields) {
18970: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
18971: push(@{$changes{'cancreate'}},'shibenv');
18972: }
18973: }
18974: } else {
18975: foreach my $field (@shibfields) {
18976: if ($env{'form.shibenv_'.$field}) {
18977: push(@{$changes{'cancreate'}},'shibenv');
18978: last;
18979: }
18980: }
18981: }
18982: }
1.224 raeburn 18983: }
18984: foreach my $item (@contexts) {
18985: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
18986: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
18987: if (ref($cancreate{$item}) eq 'ARRAY') {
18988: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
18989: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18990: push(@{$changes{'cancreate'}},$item);
18991: }
18992: }
18993: }
18994: }
18995: if (ref($cancreate{$item}) eq 'ARRAY') {
18996: foreach my $type (@{$cancreate{$item}}) {
18997: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
18998: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18999: push(@{$changes{'cancreate'}},$item);
19000: }
19001: }
19002: }
19003: }
19004: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19005: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19006: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19007: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19008: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19009: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19010: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19011: push(@{$changes{'cancreate'}},$item);
19012: }
19013: }
19014: }
1.305 raeburn 19015: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19016: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19017: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19018: push(@{$changes{'cancreate'}},$item);
19019: }
1.224 raeburn 19020: }
19021: }
19022: }
1.305 raeburn 19023: foreach my $type (keys(%{$cancreate{$item}})) {
19024: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19025: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19026: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19027: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19028: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19029: push(@{$changes{'cancreate'}},$item);
19030: }
19031: }
19032: } else {
19033: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19034: push(@{$changes{'cancreate'}},$item);
19035: }
19036: }
19037: }
1.305 raeburn 19038: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19039: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19040: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19041: push(@{$changes{'cancreate'}},$item);
19042: }
1.224 raeburn 19043: }
19044: }
19045: }
19046: }
19047: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19048: if (ref($cancreate{$item}) eq 'ARRAY') {
19049: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19050: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19051: push(@{$changes{'cancreate'}},$item);
19052: }
19053: }
1.305 raeburn 19054: }
19055: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19056: if (ref($cancreate{$item}) eq 'HASH') {
19057: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19058: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19059: }
19060: }
19061: } elsif ($item eq 'emailusername') {
1.228 raeburn 19062: if (ref($cancreate{$item}) eq 'HASH') {
19063: foreach my $type (keys(%{$cancreate{$item}})) {
19064: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19065: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19066: if ($cancreate{$item}{$type}{$field}) {
19067: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19068: push(@{$changes{'cancreate'}},$item);
19069: }
19070: last;
19071: }
19072: }
19073: }
19074: }
1.224 raeburn 19075: }
19076: }
19077: }
19078: #
19079: # Populate %save_usercreate hash with updates to self-creation configuration.
19080: #
19081: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19082: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19083: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19084: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19085: if (ref($cancreate{'notify'}) eq 'HASH') {
19086: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19087: }
1.236 raeburn 19088: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19089: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19090: }
1.303 raeburn 19091: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19092: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19093: }
1.305 raeburn 19094: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19095: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19096: }
1.303 raeburn 19097: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19098: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19099: }
1.224 raeburn 19100: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19101: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19102: }
1.240 raeburn 19103: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19104: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19105: }
1.224 raeburn 19106: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19107: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19108:
19109: my %userconfig_hash = (
19110: usercreation => \%save_usercreate,
19111: usermodification => \%save_usermodify,
1.305 raeburn 19112: inststatus => \%save_inststatus,
1.224 raeburn 19113: );
1.305 raeburn 19114:
1.224 raeburn 19115: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19116: $dom);
19117: #
1.305 raeburn 19118: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19119: #
1.27 raeburn 19120: if ($putresult eq 'ok') {
19121: if (keys(%changes) > 0) {
19122: $resulttext = &mt('Changes made:').'<ul>';
19123: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19124: my %lt = &selfcreation_types();
1.34 raeburn 19125: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19126: my $chgtext = '';
1.45 raeburn 19127: if ($type eq 'selfcreate') {
1.50 raeburn 19128: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19129: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19130: } else {
1.224 raeburn 19131: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19132: '<ul>';
1.50 raeburn 19133: foreach my $case (@{$cancreate{$type}}) {
19134: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19135: }
19136: $chgtext .= '</ul>';
1.100 raeburn 19137: if (ref($cancreate{$type}) eq 'ARRAY') {
19138: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19139: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19140: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19141: $chgtext .= '<span class="LC_warning">'.
19142: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19143: '</span><br />';
19144: }
19145: }
19146: }
19147: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19148: if (!@statuses) {
19149: $chgtext .= '<span class="LC_warning">'.
19150: &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.").
19151: '</span><br />';
1.303 raeburn 19152:
1.100 raeburn 19153: }
19154: }
19155: }
1.43 raeburn 19156: }
1.240 raeburn 19157: } elsif ($type eq 'shibenv') {
19158: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19159: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19160: } else {
19161: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19162: '<ul>';
19163: foreach my $field (@shibfields) {
19164: next if ($cancreate{$type}{$field} eq '');
19165: if ($field eq 'inststatus') {
19166: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19167: } else {
19168: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19169: }
19170: }
19171: $chgtext .= '</ul>';
1.303 raeburn 19172: }
1.93 raeburn 19173: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19174: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19175: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19176: if (@{$cancreate{'selfcreate'}} > 0) {
19177: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19178: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19179: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19180: $chgtext .= '<br />'.
19181: '<span class="LC_warning">'.
19182: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19183: '</span>';
19184: }
1.303 raeburn 19185: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19186: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19187: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19188: } else {
19189: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19190: }
19191: $chgtext .= '<ul>';
19192: foreach my $case (@{$cancreate{$type}}) {
19193: if ($case eq 'default') {
19194: $chgtext .= '<li>'.$othertitle.'</li>';
19195: } else {
1.303 raeburn 19196: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19197: }
19198: }
1.100 raeburn 19199: $chgtext .= '</ul>';
19200: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19201: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19202: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19203: '</span>';
1.100 raeburn 19204: }
19205: }
19206: } else {
19207: if (@{$cancreate{$type}} == 0) {
19208: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19209: } else {
19210: $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 19211: }
19212: }
1.303 raeburn 19213: $chgtext .= '<br />';
1.93 raeburn 19214: }
1.236 raeburn 19215: } elsif ($type eq 'selfcreateprocessing') {
19216: my %choices = &Apache::lonlocal::texthash (
19217: automatic => 'Automatic approval',
19218: approval => 'Queued for approval',
19219: );
1.305 raeburn 19220: if (@types) {
19221: if (@statuses) {
1.425 raeburn 19222: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19223: '<ul>';
1.305 raeburn 19224: foreach my $status (@statuses) {
19225: if ($status eq 'default') {
19226: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19227: } else {
1.305 raeburn 19228: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19229: }
19230: }
19231: $chgtext .= '</ul>';
19232: }
19233: } else {
19234: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19235: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19236: }
19237: } elsif ($type eq 'emailverified') {
19238: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19239: all => 'Same as e-mail',
19240: first => 'Omit @domain',
19241: free => 'Free to choose',
1.303 raeburn 19242: );
1.305 raeburn 19243: if (@types) {
19244: if (@statuses) {
1.303 raeburn 19245: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19246: '<ul>';
1.305 raeburn 19247: foreach my $status (@statuses) {
1.362 raeburn 19248: if ($status eq 'default') {
1.305 raeburn 19249: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19250: } else {
1.305 raeburn 19251: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19252: }
19253: }
19254: $chgtext .= '</ul>';
19255: }
19256: } else {
1.305 raeburn 19257: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19258: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19259: }
1.305 raeburn 19260: } elsif ($type eq 'emailoptions') {
19261: my %options = &Apache::lonlocal::texthash (
19262: any => 'Any e-mail',
19263: inst => 'Institutional only',
19264: noninst => 'Non-institutional only',
19265: custom => 'Custom restrictions',
19266: );
19267: if (@types) {
19268: if (@statuses) {
19269: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19270: '<ul>';
19271: foreach my $status (@statuses) {
19272: if ($type eq 'default') {
19273: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19274: } else {
19275: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19276: }
19277: }
1.305 raeburn 19278: $chgtext .= '</ul>';
19279: }
19280: } else {
19281: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19282: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19283: } else {
19284: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19285: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19286: }
1.305 raeburn 19287: }
19288: } elsif ($type eq 'emaildomain') {
19289: my $output;
19290: if (@statuses) {
19291: foreach my $type (@statuses) {
19292: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19293: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19294: if ($type eq 'default') {
19295: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19296: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19297: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19298: } else {
19299: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19300: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19301: }
1.303 raeburn 19302: } else {
1.305 raeburn 19303: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19304: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19305: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19306: } else {
19307: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19308: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19309: }
1.303 raeburn 19310: }
1.305 raeburn 19311: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19312: if ($type eq 'default') {
19313: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19314: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19315: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19316: } else {
19317: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19318: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19319: }
1.303 raeburn 19320: } else {
1.305 raeburn 19321: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19322: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19323: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19324: } else {
19325: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19326: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19327: }
1.303 raeburn 19328: }
19329: }
19330: }
19331: }
1.305 raeburn 19332: }
19333: if ($output ne '') {
19334: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19335: '<ul>'.$output.'</ul>';
1.236 raeburn 19336: }
1.165 raeburn 19337: } elsif ($type eq 'captcha') {
1.224 raeburn 19338: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19339: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19340: } else {
19341: my %captchas = &captcha_phrases();
1.224 raeburn 19342: if ($captchas{$savecaptcha{$type}}) {
19343: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19344: } else {
1.210 raeburn 19345: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19346: }
19347: }
19348: } elsif ($type eq 'recaptchakeys') {
19349: my ($privkey,$pubkey);
1.224 raeburn 19350: if (ref($savecaptcha{$type}) eq 'HASH') {
19351: $pubkey = $savecaptcha{$type}{'public'};
19352: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19353: }
19354: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19355: if (!$pubkey) {
19356: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19357: } else {
19358: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19359: }
19360: if (!$privkey) {
19361: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19362: } else {
19363: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19364: }
19365: $chgtext .= '</ul>';
1.269 raeburn 19366: } elsif ($type eq 'recaptchaversion') {
19367: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19368: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19369: }
1.224 raeburn 19370: } elsif ($type eq 'emailusername') {
19371: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19372: if (@statuses) {
19373: foreach my $type (@statuses) {
1.228 raeburn 19374: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19375: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19376: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19377: '<ul>';
19378: foreach my $field (@{$infofields}) {
19379: if ($cancreate{'emailusername'}{$type}{$field}) {
19380: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19381: }
19382: }
1.245 raeburn 19383: $chgtext .= '</ul>';
19384: } else {
1.303 raeburn 19385: $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 19386: }
19387: } else {
1.303 raeburn 19388: $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 19389: }
19390: }
19391: }
19392: }
19393: } elsif ($type eq 'notify') {
1.303 raeburn 19394: my $numapprove = 0;
1.224 raeburn 19395: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19396: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19397: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19398: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19399: $numapprove ++;
1.224 raeburn 19400: }
19401: }
1.43 raeburn 19402: }
1.303 raeburn 19403: unless ($numapprove) {
19404: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19405: }
1.34 raeburn 19406: }
1.224 raeburn 19407: if ($chgtext) {
19408: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19409: }
19410: }
19411: }
1.305 raeburn 19412: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19413: my ($emailrules,$emailruleorder) =
19414: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19415: foreach my $type (@{$changes{'email_rule'}}) {
19416: if (ref($email_rule{$type}) eq 'ARRAY') {
19417: my $chgtext = '<ul>';
19418: foreach my $rule (@{$email_rule{$type}}) {
19419: if (ref($emailrules->{$rule}) eq 'HASH') {
19420: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19421: }
19422: }
19423: $chgtext .= '</ul>';
1.310 raeburn 19424: my $typename;
1.305 raeburn 19425: if (@types) {
19426: if ($type eq 'default') {
19427: $typename = $othertitle;
19428: } else {
19429: $typename = $usertypes{$type};
1.425 raeburn 19430: }
1.305 raeburn 19431: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19432: }
19433: if (@{$email_rule{$type}} > 0) {
19434: $resulttext .= '<li>'.
19435: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19436: $usertypes{$type}).
19437: $chgtext.
19438: '</li>';
19439: } else {
19440: $resulttext .= '<li>'.
1.310 raeburn 19441: &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 19442: '</li>'.
1.310 raeburn 19443: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19444: }
1.43 raeburn 19445: }
19446: }
1.305 raeburn 19447: }
19448: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19449: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19450: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19451: my $chgtext = '<ul>';
19452: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19453: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19454: }
19455: $chgtext .= '</ul>';
19456: $resulttext .= '<li>'.
19457: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19458: $chgtext.
19459: '</li>';
19460: } else {
19461: $resulttext .= '<li>'.
19462: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19463: '</li>';
19464: }
1.43 raeburn 19465: }
19466: }
1.224 raeburn 19467: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19468: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19469: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19470: foreach my $type (@{$changes{'selfcreate'}}) {
19471: my $typename = $type;
1.303 raeburn 19472: if (keys(%usertypes) > 0) {
19473: if ($usertypes{$type} ne '') {
19474: $typename = $usertypes{$type};
1.224 raeburn 19475: }
19476: }
19477: my @modifiable;
19478: $resulttext .= '<li>'.
19479: &mt('Self-creation of account by users with status: [_1]',
19480: '<span class="LC_cusr_emph">'.$typename.'</span>').
19481: ' - '.&mt('modifiable fields (if institutional data blank): ');
19482: foreach my $field (@fields) {
19483: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19484: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19485: }
19486: }
1.224 raeburn 19487: if (@modifiable > 0) {
19488: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19489: } else {
1.224 raeburn 19490: $resulttext .= &mt('none');
1.43 raeburn 19491: }
1.224 raeburn 19492: $resulttext .= '</li>';
1.28 raeburn 19493: }
1.224 raeburn 19494: $resulttext .= '</ul></li>';
1.28 raeburn 19495: }
1.27 raeburn 19496: $resulttext .= '</ul>';
1.305 raeburn 19497: my $cachetime = 24*60*60;
19498: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19499: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19500: if (ref($lastactref) eq 'HASH') {
19501: $lastactref->{'domdefaults'} = 1;
19502: }
1.27 raeburn 19503: } else {
1.224 raeburn 19504: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19505: }
19506: } else {
19507: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19508: &mt('An error occurred: [_1]',$putresult).'</span>';
19509: }
1.43 raeburn 19510: if ($warningmsg ne '') {
19511: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19512: }
1.23 raeburn 19513: return $resulttext;
19514: }
19515:
1.165 raeburn 19516: sub process_captcha {
1.369 raeburn 19517: my ($container,$changes,$newsettings,$currsettings) = @_;
19518: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19519: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19520: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19521: $newsettings->{'captcha'} = 'original';
19522: }
1.369 raeburn 19523: my %current;
19524: if (ref($currsettings) eq 'HASH') {
19525: %current = %{$currsettings};
19526: }
19527: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19528: if ($container eq 'cancreate') {
1.169 raeburn 19529: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19530: push(@{$changes->{'cancreate'}},'captcha');
19531: } elsif (!defined($changes->{'cancreate'})) {
19532: $changes->{'cancreate'} = ['captcha'];
19533: }
1.368 raeburn 19534: } elsif ($container eq 'passwords') {
19535: $changes->{'reset'} = 1;
1.169 raeburn 19536: } else {
19537: $changes->{'captcha'} = 1;
1.165 raeburn 19538: }
19539: }
1.269 raeburn 19540: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19541: if ($newsettings->{'captcha'} eq 'recaptcha') {
19542: $newpub = $env{'form.'.$container.'_recaptchapub'};
19543: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19544: $newpub =~ s/[^\w\-]//g;
19545: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19546: $newsettings->{'recaptchakeys'} = {
19547: public => $newpub,
19548: private => $newpriv,
19549: };
1.269 raeburn 19550: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19551: $newversion =~ s/\D//g;
19552: if ($newversion ne '2') {
19553: $newversion = 1;
19554: }
19555: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19556: }
1.369 raeburn 19557: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19558: $currpub = $current{'recaptchakeys'}{'public'};
19559: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19560: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19561: $newsettings->{'recaptchakeys'} = {
19562: public => '',
19563: private => '',
19564: }
19565: }
1.165 raeburn 19566: }
1.369 raeburn 19567: if ($current{'captcha'} eq 'recaptcha') {
19568: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19569: if ($currversion ne '2') {
19570: $currversion = 1;
19571: }
19572: }
19573: if ($currversion ne $newversion) {
19574: if ($container eq 'cancreate') {
19575: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19576: push(@{$changes->{'cancreate'}},'recaptchaversion');
19577: } elsif (!defined($changes->{'cancreate'})) {
19578: $changes->{'cancreate'} = ['recaptchaversion'];
19579: }
1.368 raeburn 19580: } elsif ($container eq 'passwords') {
19581: $changes->{'reset'} = 1;
1.269 raeburn 19582: } else {
19583: $changes->{'recaptchaversion'} = 1;
19584: }
19585: }
1.165 raeburn 19586: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19587: if ($container eq 'cancreate') {
19588: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19589: push(@{$changes->{'cancreate'}},'recaptchakeys');
19590: } elsif (!defined($changes->{'cancreate'})) {
19591: $changes->{'cancreate'} = ['recaptchakeys'];
19592: }
1.368 raeburn 19593: } elsif ($container eq 'passwords') {
19594: $changes->{'reset'} = 1;
1.169 raeburn 19595: } else {
1.210 raeburn 19596: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19597: }
19598: }
19599: return;
19600: }
19601:
1.33 raeburn 19602: sub modify_usermodification {
19603: my ($dom,%domconfig) = @_;
1.224 raeburn 19604: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19605: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19606: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19607: if ($key eq 'selfcreate') {
19608: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19609: } else {
19610: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19611: }
1.33 raeburn 19612: }
19613: }
1.224 raeburn 19614: my @contexts = ('author','course');
1.33 raeburn 19615: my %context_title = (
19616: author => 'In author context',
19617: course => 'In course context',
19618: );
19619: my @fields = ('lastname','firstname','middlename','generation',
19620: 'permanentemail','id');
19621: my %roles = (
19622: author => ['ca','aa'],
19623: course => ['st','ep','ta','in','cr'],
19624: );
19625: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19626: foreach my $context (@contexts) {
19627: foreach my $role (@{$roles{$context}}) {
19628: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
19629: foreach my $item (@fields) {
19630: if (grep(/^\Q$item\E$/,@modifiable)) {
19631: $modifyhash{$context}{$role}{$item} = 1;
19632: } else {
19633: $modifyhash{$context}{$role}{$item} = 0;
19634: }
19635: }
19636: }
19637: if (ref($curr_usermodification{$context}) eq 'HASH') {
19638: foreach my $role (@{$roles{$context}}) {
19639: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19640: foreach my $field (@fields) {
19641: if ($modifyhash{$context}{$role}{$field} ne
19642: $curr_usermodification{$context}{$role}{$field}) {
19643: push(@{$changes{$context}},$role);
19644: last;
19645: }
19646: }
19647: }
19648: }
19649: } else {
19650: foreach my $context (@contexts) {
19651: foreach my $role (@{$roles{$context}}) {
19652: push(@{$changes{$context}},$role);
19653: }
19654: }
19655: }
19656: }
19657: my %usermodification_hash = (
19658: usermodification => \%modifyhash,
19659: );
19660: my $putresult = &Apache::lonnet::put_dom('configuration',
19661: \%usermodification_hash,$dom);
19662: if ($putresult eq 'ok') {
19663: if (keys(%changes) > 0) {
19664: $resulttext = &mt('Changes made: ').'<ul>';
19665: foreach my $context (@contexts) {
19666: if (ref($changes{$context}) eq 'ARRAY') {
19667: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19668: if (ref($changes{$context}) eq 'ARRAY') {
19669: foreach my $role (@{$changes{$context}}) {
19670: my $rolename;
1.224 raeburn 19671: if ($role eq 'cr') {
19672: $rolename = &mt('Custom');
1.33 raeburn 19673: } else {
1.224 raeburn 19674: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19675: }
19676: my @modifiable;
1.224 raeburn 19677: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19678: foreach my $field (@fields) {
19679: if ($modifyhash{$context}{$role}{$field}) {
19680: push(@modifiable,$fieldtitles{$field});
19681: }
19682: }
19683: if (@modifiable > 0) {
19684: $resulttext .= join(', ',@modifiable);
19685: } else {
19686: $resulttext .= &mt('none');
19687: }
19688: $resulttext .= '</li>';
19689: }
19690: $resulttext .= '</ul></li>';
19691: }
19692: }
19693: }
19694: $resulttext .= '</ul>';
19695: } else {
19696: $resulttext = &mt('No changes made to user modification settings');
19697: }
19698: } else {
19699: $resulttext = '<span class="LC_error">'.
19700: &mt('An error occurred: [_1]',$putresult).'</span>';
19701: }
19702: return $resulttext;
19703: }
19704:
1.43 raeburn 19705: sub modify_defaults {
1.212 raeburn 19706: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19707: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19708: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19709: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19710: 'portal_def');
1.325 raeburn 19711: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19712: foreach my $item (@items) {
19713: $newvalues{$item} = $env{'form.'.$item};
19714: if ($item eq 'auth_def') {
19715: if ($newvalues{$item} ne '') {
19716: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19717: push(@errors,$item);
19718: }
19719: }
19720: } elsif ($item eq 'lang_def') {
19721: if ($newvalues{$item} ne '') {
19722: if ($newvalues{$item} =~ /^(\w+)/) {
19723: my $langcode = $1;
1.103 raeburn 19724: if ($langcode ne 'x_chef') {
19725: if (code2language($langcode) eq '') {
19726: push(@errors,$item);
19727: }
1.43 raeburn 19728: }
19729: } else {
19730: push(@errors,$item);
19731: }
19732: }
1.54 raeburn 19733: } elsif ($item eq 'timezone_def') {
19734: if ($newvalues{$item} ne '') {
1.62 raeburn 19735: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 19736: push(@errors,$item);
19737: }
19738: }
1.68 raeburn 19739: } elsif ($item eq 'datelocale_def') {
19740: if ($newvalues{$item} ne '') {
19741: my @datelocale_ids = DateTime::Locale->ids();
19742: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
19743: push(@errors,$item);
19744: }
19745: }
1.141 raeburn 19746: } elsif ($item eq 'portal_def') {
19747: if ($newvalues{$item} ne '') {
1.414 raeburn 19748: 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])\/?$/) {
19749: foreach my $field ('email','web') {
19750: if ($env{'form.'.$item.'_'.$field}) {
19751: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
19752: }
19753: }
19754: } else {
1.141 raeburn 19755: push(@errors,$item);
19756: }
19757: }
1.43 raeburn 19758: }
19759: if (grep(/^\Q$item\E$/,@errors)) {
19760: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 19761: if ($item eq 'portal_def') {
19762: if ($domdefaults{$item}) {
19763: foreach my $field ('email','web') {
19764: if (exists($domdefaults{$item.'_'.$field})) {
19765: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
19766: }
19767: }
19768: }
19769: }
1.43 raeburn 19770: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
19771: $changes{$item} = 1;
19772: }
1.414 raeburn 19773: if ($item eq 'portal_def') {
19774: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 19775: if ($newvalues{$item} eq '') {
1.414 raeburn 19776: foreach my $field ('email','web') {
19777: if (exists($domdefaults{$item.'_'.$field})) {
19778: delete($domdefaults{$item.'_'.$field});
19779: }
19780: }
19781: } else {
19782: unless ($changes{$item}) {
19783: foreach my $field ('email','web') {
19784: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
19785: $changes{$item} = 1;
19786: last;
19787: }
19788: }
19789: }
19790: foreach my $field ('email','web') {
19791: if ($newvalues{$item.'_'.$field}) {
19792: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
19793: } elsif (exists($domdefaults{$item.'_'.$field})) {
19794: delete($domdefaults{$item.'_'.$field});
19795: }
19796: }
19797: }
19798: }
19799: }
1.72 raeburn 19800: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 19801: }
1.354 raeburn 19802: my %staticdefaults = (
19803: 'intauth_cost' => 10,
19804: 'intauth_check' => 0,
19805: 'intauth_switch' => 0,
19806: );
19807: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
19808: if (exists($domdefaults{$item})) {
19809: $newvalues{$item} = $domdefaults{$item};
19810: } else {
19811: $newvalues{$item} = $staticdefaults{$item};
19812: }
19813: }
1.409 raeburn 19814: my ($unamemaprules,$ruleorder);
19815: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
19816: if (@possunamemaprules) {
19817: ($unamemaprules,$ruleorder) =
19818: &Apache::lonnet::inst_userrules($dom,'unamemap');
19819: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
19820: if (@{$ruleorder} > 0) {
19821: my %possrules;
19822: map { $possrules{$_} = 1; } @possunamemaprules;
19823: foreach my $rule (@{$ruleorder}) {
19824: if ($possrules{$rule}) {
19825: push(@{$newvalues{'unamemap_rule'}},$rule);
19826: }
19827: }
19828: }
19829: }
19830: }
19831: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
19832: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19833: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
19834: $newvalues{'unamemap_rule'});
19835: if (@rulediffs) {
19836: $changes{'unamemap_rule'} = 1;
19837: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
19838: }
19839: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
19840: $changes{'unamemap_rule'} = 1;
19841: delete($domdefaults{'unamemap_rule'});
19842: }
19843: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19844: if (@{$newvalues{'unamemap_rule'}} > 0) {
19845: $changes{'unamemap_rule'} = 1;
19846: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
19847: }
19848: }
1.43 raeburn 19849: my %defaults_hash = (
1.72 raeburn 19850: defaults => \%newvalues,
19851: );
1.43 raeburn 19852: my $title = &defaults_titles();
1.236 raeburn 19853:
19854: my $currinststatus;
19855: if (ref($domconfig{'inststatus'}) eq 'HASH') {
19856: $currinststatus = $domconfig{'inststatus'};
19857: } else {
19858: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
19859: $currinststatus = {
19860: inststatustypes => $usertypes,
19861: inststatusorder => $types,
19862: inststatusguest => [],
19863: };
19864: }
19865: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
19866: my @allpos;
19867: my %alltypes;
1.305 raeburn 19868: my @inststatusguest;
19869: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
19870: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
19871: unless (grep(/^\Q$type\E$/,@todelete)) {
19872: push(@inststatusguest,$type);
19873: }
19874: }
19875: }
19876: my ($currtitles,$currorder);
1.236 raeburn 19877: if (ref($currinststatus) eq 'HASH') {
19878: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
19879: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
19880: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
19881: if ($currinststatus->{inststatustypes}->{$type} ne '') {
19882: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
19883: }
19884: }
19885: unless (grep(/^\Q$type\E$/,@todelete)) {
19886: my $position = $env{'form.inststatus_pos_'.$type};
19887: $position =~ s/\D+//g;
19888: $allpos[$position] = $type;
19889: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
19890: $alltypes{$type} =~ s/`//g;
19891: }
19892: }
19893: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
19894: $currtitles =~ s/,$//;
19895: }
19896: }
19897: if ($env{'form.addinststatus'}) {
19898: my $newtype = $env{'form.addinststatus'};
19899: $newtype =~ s/\W//g;
19900: unless (exists($alltypes{$newtype})) {
19901: $alltypes{$newtype} = $env{'form.addinststatus_title'};
19902: $alltypes{$newtype} =~ s/`//g;
19903: my $position = $env{'form.addinststatus_pos'};
19904: $position =~ s/\D+//g;
19905: if ($position ne '') {
19906: $allpos[$position] = $newtype;
19907: }
19908: }
19909: }
1.305 raeburn 19910: my @orderedstatus;
1.236 raeburn 19911: foreach my $type (@allpos) {
19912: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
19913: push(@orderedstatus,$type);
19914: }
19915: }
19916: foreach my $type (keys(%alltypes)) {
19917: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
19918: delete($alltypes{$type});
19919: }
19920: }
19921: $defaults_hash{'inststatus'} = {
19922: inststatustypes => \%alltypes,
19923: inststatusorder => \@orderedstatus,
1.305 raeburn 19924: inststatusguest => \@inststatusguest,
1.236 raeburn 19925: };
19926: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
19927: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
19928: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
19929: }
19930: }
19931: if ($currorder ne join(',',@orderedstatus)) {
19932: $changes{'inststatus'}{'inststatusorder'} = 1;
19933: }
19934: my $newtitles;
19935: foreach my $item (@orderedstatus) {
19936: $newtitles .= $alltypes{$item}.',';
19937: }
19938: $newtitles =~ s/,$//;
19939: if ($currtitles ne $newtitles) {
19940: $changes{'inststatus'}{'inststatustypes'} = 1;
19941: }
1.43 raeburn 19942: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
19943: $dom);
19944: if ($putresult eq 'ok') {
19945: if (keys(%changes) > 0) {
19946: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 19947: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 19948: 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";
19949: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 19950: if ($item eq 'inststatus') {
19951: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 19952: if (@orderedstatus) {
1.236 raeburn 19953: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
19954: foreach my $type (@orderedstatus) {
19955: $resulttext .= $alltypes{$type}.', ';
19956: }
19957: $resulttext =~ s/, $//;
19958: $resulttext .= '</li>';
1.305 raeburn 19959: } else {
1.425 raeburn 19960: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 19961: }
19962: }
1.409 raeburn 19963: } elsif ($item eq 'unamemap_rule') {
19964: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19965: my @rulenames;
19966: if (ref($unamemaprules) eq 'HASH') {
19967: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
19968: if (ref($unamemaprules->{$rule}) eq 'HASH') {
19969: push(@rulenames,$unamemaprules->{$rule}->{'name'});
19970: }
19971: }
19972: }
19973: if (@rulenames) {
19974: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
19975: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
19976: '</li>';
19977: } else {
19978: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
19979: }
19980: } else {
19981: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
19982: }
1.236 raeburn 19983: } else {
19984: my $value = $env{'form.'.$item};
19985: if ($value eq '') {
19986: $value = &mt('none');
19987: } elsif ($item eq 'auth_def') {
19988: my %authnames = &authtype_names();
19989: my %shortauth = (
19990: internal => 'int',
19991: krb4 => 'krb4',
19992: krb5 => 'krb5',
19993: localauth => 'loc',
1.325 raeburn 19994: lti => 'lti',
1.236 raeburn 19995: );
19996: $value = $authnames{$shortauth{$value}};
19997: }
19998: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 19999: $mailmsgtext .= "$title->{$item} set to $value\n";
20000: if ($item eq 'portal_def') {
20001: if ($env{'form.'.$item} ne '') {
20002: foreach my $field ('email','web') {
20003: $value = $env{'form.'.$item.'_'.$field};
20004: if ($value) {
20005: $value = &mt('Yes');
20006: } else {
20007: $value = &mt('No');
20008: }
20009: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20010: }
20011: }
20012: }
1.43 raeburn 20013: }
20014: }
20015: $resulttext .= '</ul>';
20016: $mailmsgtext .= "\n";
20017: my $cachetime = 24*60*60;
1.72 raeburn 20018: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20019: if (ref($lastactref) eq 'HASH') {
20020: $lastactref->{'domdefaults'} = 1;
20021: }
1.68 raeburn 20022: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20023: my $notify = 1;
20024: if (ref($domconfig{'contacts'}) eq 'HASH') {
20025: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20026: $notify = 0;
20027: }
20028: }
20029: if ($notify) {
20030: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20031: "LON-CAPA Domain Settings Change - $dom",
20032: $mailmsgtext);
20033: }
1.54 raeburn 20034: }
1.43 raeburn 20035: } else {
1.54 raeburn 20036: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20037: }
20038: } else {
20039: $resulttext = '<span class="LC_error">'.
20040: &mt('An error occurred: [_1]',$putresult).'</span>';
20041: }
20042: if (@errors > 0) {
20043: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20044: foreach my $item (@errors) {
20045: $resulttext .= ' "'.$title->{$item}.'",';
20046: }
20047: $resulttext =~ s/,$//;
20048: }
20049: return $resulttext;
20050: }
20051:
1.46 raeburn 20052: sub modify_scantron {
1.205 raeburn 20053: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20054: my ($resulttext,%confhash,%changes,$errors);
20055: my $custom = 'custom.tab';
20056: my $default = 'default.tab';
20057: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20058: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20059: &config_check($dom,$confname,$servadm);
20060: if ($env{'form.scantronformat.filename'} ne '') {
20061: my $error;
20062: if ($configuserok eq 'ok') {
20063: if ($switchserver) {
1.130 raeburn 20064: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20065: } else {
20066: if ($author_ok eq 'ok') {
1.421 raeburn 20067: my $modified = [];
1.46 raeburn 20068: my ($result,$scantronurl) =
1.421 raeburn 20069: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20070: $confname,'scantron','','',$custom,
20071: $modified);
1.46 raeburn 20072: if ($result eq 'ok') {
20073: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20074: $changes{'scantronformat'} = 1;
1.421 raeburn 20075: &update_modify_urls($r,$modified);
1.46 raeburn 20076: } else {
20077: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20078: }
20079: } else {
20080: $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);
20081: }
20082: }
20083: } else {
20084: $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);
20085: }
20086: if ($error) {
20087: &Apache::lonnet::logthis($error);
20088: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20089: }
20090: }
1.48 raeburn 20091: if (ref($domconfig{'scantron'}) eq 'HASH') {
20092: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20093: if ($env{'form.scantronformat_del'}) {
20094: $confhash{'scantron'}{'scantronformat'} = '';
20095: $changes{'scantronformat'} = 1;
1.347 raeburn 20096: } else {
20097: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20098: }
20099: }
20100: }
1.347 raeburn 20101: my @options = ('hdr','pad','rem');
1.346 raeburn 20102: my @fields = &scantroncsv_fields();
20103: my %titles = &scantronconfig_titles();
1.347 raeburn 20104: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20105: my ($newdat,$currdat,%newcol,%currcol);
20106: if (grep(/^dat$/,@formats)) {
20107: $confhash{'scantron'}{config}{dat} = 1;
20108: $newdat = 1;
20109: } else {
20110: $newdat = 0;
20111: }
20112: if (grep(/^csv$/,@formats)) {
20113: my %bynum;
20114: foreach my $field (@fields) {
20115: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20116: my $posscol = $1;
20117: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20118: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20119: $bynum{$posscol} = $field;
20120: $newcol{$field} = $posscol;
20121: }
20122: }
20123: }
1.347 raeburn 20124: if (keys(%newcol)) {
20125: foreach my $option (@options) {
20126: if ($env{'form.scantroncsv_'.$option}) {
20127: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20128: }
20129: }
20130: }
1.346 raeburn 20131: }
20132: $currdat = 1;
20133: if (ref($domconfig{'scantron'}) eq 'HASH') {
20134: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20135: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20136: $currdat = 0;
20137: }
20138: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20139: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20140: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20141: }
1.346 raeburn 20142: }
20143: }
20144: }
20145: if ($currdat != $newdat) {
20146: $changes{'config'} = 1;
20147: } else {
20148: foreach my $field (@fields) {
20149: if ($currcol{$field} ne '') {
20150: if ($currcol{$field} ne $newcol{$field}) {
20151: $changes{'config'} = 1;
20152: last;
1.347 raeburn 20153: }
1.346 raeburn 20154: } elsif ($newcol{$field} ne '') {
20155: $changes{'config'} = 1;
20156: last;
20157: }
20158: }
20159: }
1.46 raeburn 20160: if (keys(%confhash) > 0) {
20161: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20162: $dom);
20163: if ($putresult eq 'ok') {
20164: if (keys(%changes) > 0) {
1.48 raeburn 20165: if (ref($confhash{'scantron'}) eq 'HASH') {
20166: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20167: if ($changes{'scantronformat'}) {
20168: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20169: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20170: } else {
20171: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20172: }
20173: }
1.347 raeburn 20174: if ($changes{'config'}) {
1.346 raeburn 20175: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20176: if ($confhash{'scantron'}{'config'}{'dat'}) {
20177: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20178: }
20179: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20180: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20181: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20182: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20183: foreach my $field (@fields) {
20184: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20185: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20186: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20187: }
20188: }
20189: $resulttext .= '</ul></li>';
20190: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20191: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20192: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20193: foreach my $option (@options) {
20194: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20195: $resulttext .= '<li>'.$titles{$option}.'</li>';
20196: }
20197: }
20198: $resulttext .= '</ul></li>';
20199: }
1.346 raeburn 20200: }
20201: }
20202: }
20203: }
20204: } else {
20205: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20206: }
1.46 raeburn 20207: }
1.48 raeburn 20208: $resulttext .= '</ul>';
20209: } else {
1.130 raeburn 20210: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20211: }
20212: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20213: if (ref($lastactref) eq 'HASH') {
20214: $lastactref->{'domainconfig'} = 1;
20215: }
1.46 raeburn 20216: } else {
1.346 raeburn 20217: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20218: }
20219: } else {
20220: $resulttext = '<span class="LC_error">'.
20221: &mt('An error occurred: [_1]',$putresult).'</span>';
20222: }
20223: } else {
1.130 raeburn 20224: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20225: }
20226: if ($errors) {
1.353 raeburn 20227: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20228: $errors.'</ul></p>';
1.46 raeburn 20229: }
20230: return $resulttext;
20231: }
20232:
1.48 raeburn 20233: sub modify_coursecategories {
1.239 raeburn 20234: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20235: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20236: $cathash);
1.48 raeburn 20237: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20238: my @catitems = ('unauth','auth');
20239: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20240: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20241: $cathash = $domconfig{'coursecategories'}{'cats'};
20242: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20243: $changes{'togglecats'} = 1;
20244: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20245: }
20246: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20247: $changes{'categorize'} = 1;
20248: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20249: }
1.120 raeburn 20250: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20251: $changes{'togglecatscomm'} = 1;
20252: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20253: }
20254: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20255: $changes{'categorizecomm'} = 1;
20256: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20257:
20258: }
20259: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20260: $changes{'togglecatsplace'} = 1;
20261: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20262: }
20263: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20264: $changes{'categorizeplace'} = 1;
20265: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20266: }
1.238 raeburn 20267: foreach my $item (@catitems) {
20268: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20269: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20270: $changes{$item} = 1;
20271: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20272: }
20273: }
20274: }
1.57 raeburn 20275: } else {
20276: $changes{'togglecats'} = 1;
20277: $changes{'categorize'} = 1;
1.124 raeburn 20278: $changes{'togglecatscomm'} = 1;
20279: $changes{'categorizecomm'} = 1;
1.272 raeburn 20280: $changes{'togglecatsplace'} = 1;
20281: $changes{'categorizeplace'} = 1;
1.87 raeburn 20282: $domconfig{'coursecategories'} = {
20283: togglecats => $env{'form.togglecats'},
20284: categorize => $env{'form.categorize'},
1.124 raeburn 20285: togglecatscomm => $env{'form.togglecatscomm'},
20286: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20287: togglecatsplace => $env{'form.togglecatsplace'},
20288: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20289: };
1.238 raeburn 20290: foreach my $item (@catitems) {
20291: if ($env{'form.coursecat_'.$item} ne 'std') {
20292: $changes{$item} = 1;
20293: }
20294: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20295: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20296: }
20297: }
1.57 raeburn 20298: }
20299: if (ref($cathash) eq 'HASH') {
20300: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20301: push (@deletecategory,'instcode::0');
20302: }
1.120 raeburn 20303: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20304: push(@deletecategory,'communities::0');
20305: }
1.272 raeburn 20306: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20307: push(@deletecategory,'placement::0');
20308: }
1.48 raeburn 20309: }
1.57 raeburn 20310: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20311: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20312: if (@deletecategory > 0) {
20313: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20314: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20315: foreach my $item (@deletecategory) {
1.57 raeburn 20316: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20317: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20318: $deletions{$item} = 1;
1.57 raeburn 20319: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20320: }
20321: }
20322: }
1.57 raeburn 20323: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20324: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20325: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20326: $reorderings{$item} = 1;
1.57 raeburn 20327: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20328: }
20329: if ($env{'form.addcategory_name_'.$item} ne '') {
20330: my $newcat = $env{'form.addcategory_name_'.$item};
20331: my $newdepth = $depth+1;
20332: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20333: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20334: $adds{$newitem} = 1;
20335: }
20336: if ($env{'form.subcat_'.$item} ne '') {
20337: my $newcat = $env{'form.subcat_'.$item};
20338: my $newdepth = $depth+1;
20339: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20340: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20341: $adds{$newitem} = 1;
20342: }
20343: }
20344: }
20345: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20346: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20347: my $newitem = 'instcode::0';
1.57 raeburn 20348: if ($cathash->{$newitem} eq '') {
20349: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20350: $adds{$newitem} = 1;
20351: }
20352: } else {
20353: my $newitem = 'instcode::0';
1.57 raeburn 20354: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20355: $adds{$newitem} = 1;
20356: }
20357: }
1.120 raeburn 20358: if ($env{'form.communities'} eq '1') {
20359: if (ref($cathash) eq 'HASH') {
20360: my $newitem = 'communities::0';
20361: if ($cathash->{$newitem} eq '') {
20362: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20363: $adds{$newitem} = 1;
20364: }
20365: } else {
20366: my $newitem = 'communities::0';
20367: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20368: $adds{$newitem} = 1;
20369: }
20370: }
1.272 raeburn 20371: if ($env{'form.placement'} eq '1') {
20372: if (ref($cathash) eq 'HASH') {
20373: my $newitem = 'placement::0';
20374: if ($cathash->{$newitem} eq '') {
20375: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20376: $adds{$newitem} = 1;
20377: }
20378: } else {
20379: my $newitem = 'placement::0';
20380: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20381: $adds{$newitem} = 1;
20382: }
20383: }
1.48 raeburn 20384: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20385: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20386: ($env{'form.addcategory_name'} ne 'communities') &&
20387: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20388: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20389: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20390: $adds{$newitem} = 1;
20391: }
1.48 raeburn 20392: }
1.57 raeburn 20393: my $putresult;
1.48 raeburn 20394: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20395: if (keys(%deletions) > 0) {
20396: foreach my $key (keys(%deletions)) {
20397: if ($predelallitems{$key} ne '') {
20398: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20399: }
20400: }
20401: }
20402: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20403: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20404: if (ref($chkcats[0]) eq 'ARRAY') {
20405: my $depth = 0;
20406: my $chg = 0;
20407: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20408: my $name = $chkcats[0][$i];
20409: my $item;
20410: if ($name eq '') {
20411: $chg ++;
20412: } else {
20413: $item = &escape($name).'::0';
20414: if ($chg) {
1.57 raeburn 20415: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20416: }
20417: $depth ++;
1.57 raeburn 20418: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20419: $depth --;
20420: }
20421: }
20422: }
1.57 raeburn 20423: }
20424: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20425: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20426: if ($putresult eq 'ok') {
1.57 raeburn 20427: my %title = (
1.120 raeburn 20428: togglecats => 'Show/Hide a course in catalog',
20429: categorize => 'Assign a category to a course',
20430: togglecatscomm => 'Show/Hide a community in catalog',
20431: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20432: );
20433: my %level = (
1.120 raeburn 20434: dom => 'set in Domain ("Modify Course/Community")',
20435: crs => 'set in Course ("Course Configuration")',
20436: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20437: none => 'No catalog',
20438: std => 'Standard catalog',
20439: domonly => 'Domain-only catalog',
20440: codesrch => 'Code search form',
1.57 raeburn 20441: );
1.48 raeburn 20442: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20443: if ($changes{'togglecats'}) {
20444: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20445: }
20446: if ($changes{'categorize'}) {
20447: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20448: }
1.120 raeburn 20449: if ($changes{'togglecatscomm'}) {
20450: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20451: }
20452: if ($changes{'categorizecomm'}) {
20453: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20454: }
1.238 raeburn 20455: if ($changes{'unauth'}) {
20456: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20457: }
20458: if ($changes{'auth'}) {
20459: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20460: }
1.57 raeburn 20461: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20462: my $cathash;
20463: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20464: $cathash = $domconfig{'coursecategories'}{'cats'};
20465: } else {
20466: $cathash = {};
20467: }
20468: my (@cats,@trails,%allitems);
20469: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20470: if (keys(%deletions) > 0) {
20471: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20472: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20473: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20474: }
20475: $resulttext .= '</ul></li>';
20476: }
20477: if (keys(%reorderings) > 0) {
20478: my %sort_by_trail;
20479: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20480: foreach my $key (keys(%reorderings)) {
20481: if ($allitems{$key} ne '') {
20482: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20483: }
1.48 raeburn 20484: }
1.57 raeburn 20485: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20486: $resulttext .= '<li>'.$trails[$trail].'</li>';
20487: }
20488: $resulttext .= '</ul></li>';
1.48 raeburn 20489: }
1.57 raeburn 20490: if (keys(%adds) > 0) {
20491: my %sort_by_trail;
20492: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20493: foreach my $key (keys(%adds)) {
20494: if ($allitems{$key} ne '') {
20495: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20496: }
20497: }
20498: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20499: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20500: }
1.57 raeburn 20501: $resulttext .= '</ul></li>';
1.48 raeburn 20502: }
1.364 raeburn 20503: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20504: if (ref($lastactref) eq 'HASH') {
20505: $lastactref->{'cats'} = 1;
20506: }
1.48 raeburn 20507: }
20508: $resulttext .= '</ul>';
1.239 raeburn 20509: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20510: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20511: if ($changes{'auth'}) {
20512: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20513: }
20514: if ($changes{'unauth'}) {
20515: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20516: }
20517: my $cachetime = 24*60*60;
20518: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20519: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20520: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20521: }
20522: }
1.48 raeburn 20523: } else {
20524: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20525: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20526: }
20527: } else {
1.120 raeburn 20528: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20529: }
20530: return $resulttext;
20531: }
20532:
1.69 raeburn 20533: sub modify_serverstatuses {
20534: my ($dom,%domconfig) = @_;
20535: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20536: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20537: %currserverstatus = %{$domconfig{'serverstatuses'}};
20538: }
20539: my @pages = &serverstatus_pages();
20540: foreach my $type (@pages) {
20541: $newserverstatus{$type}{'namedusers'} = '';
20542: $newserverstatus{$type}{'machines'} = '';
20543: if (defined($env{'form.'.$type.'_namedusers'})) {
20544: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20545: my @okusers;
20546: foreach my $user (@users) {
20547: my ($uname,$udom) = split(/:/,$user);
20548: if (($udom =~ /^$match_domain$/) &&
20549: (&Apache::lonnet::domain($udom)) &&
20550: ($uname =~ /^$match_username$/)) {
20551: if (!grep(/^\Q$user\E/,@okusers)) {
20552: push(@okusers,$user);
20553: }
20554: }
20555: }
20556: if (@okusers > 0) {
20557: @okusers = sort(@okusers);
20558: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20559: }
20560: }
20561: if (defined($env{'form.'.$type.'_machines'})) {
20562: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20563: my @okmachines;
20564: foreach my $ip (@machines) {
20565: my @parts = split(/\./,$ip);
20566: next if (@parts < 4);
20567: my $badip = 0;
20568: for (my $i=0; $i<4; $i++) {
20569: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20570: $badip = 1;
20571: last;
20572: }
20573: }
20574: if (!$badip) {
20575: push(@okmachines,$ip);
20576: }
20577: }
20578: @okmachines = sort(@okmachines);
20579: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20580: }
20581: }
20582: my %serverstatushash = (
20583: serverstatuses => \%newserverstatus,
20584: );
20585: foreach my $type (@pages) {
1.83 raeburn 20586: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20587: my (@current,@new);
1.83 raeburn 20588: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20589: if ($currserverstatus{$type}{$setting} ne '') {
20590: @current = split(/,/,$currserverstatus{$type}{$setting});
20591: }
20592: }
20593: if ($newserverstatus{$type}{$setting} ne '') {
20594: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20595: }
20596: if (@current > 0) {
20597: if (@new > 0) {
20598: foreach my $item (@current) {
20599: if (!grep(/^\Q$item\E$/,@new)) {
20600: $changes{$type}{$setting} = 1;
1.82 raeburn 20601: last;
20602: }
20603: }
1.84 raeburn 20604: foreach my $item (@new) {
20605: if (!grep(/^\Q$item\E$/,@current)) {
20606: $changes{$type}{$setting} = 1;
20607: last;
1.82 raeburn 20608: }
20609: }
20610: } else {
1.83 raeburn 20611: $changes{$type}{$setting} = 1;
1.69 raeburn 20612: }
1.83 raeburn 20613: } elsif (@new > 0) {
20614: $changes{$type}{$setting} = 1;
1.69 raeburn 20615: }
20616: }
20617: }
20618: if (keys(%changes) > 0) {
1.81 raeburn 20619: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20620: my $putresult = &Apache::lonnet::put_dom('configuration',
20621: \%serverstatushash,$dom);
20622: if ($putresult eq 'ok') {
20623: $resulttext .= &mt('Changes made:').'<ul>';
20624: foreach my $type (@pages) {
1.84 raeburn 20625: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20626: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20627: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20628: if ($newserverstatus{$type}{'namedusers'} eq '') {
20629: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20630: } else {
20631: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20632: }
1.84 raeburn 20633: }
20634: if ($changes{$type}{'machines'}) {
1.69 raeburn 20635: if ($newserverstatus{$type}{'machines'} eq '') {
20636: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20637: } else {
20638: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20639: }
20640:
20641: }
20642: $resulttext .= '</ul></li>';
20643: }
20644: }
20645: $resulttext .= '</ul>';
20646: } else {
20647: $resulttext = '<span class="LC_error">'.
20648: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20649:
20650: }
20651: } else {
20652: $resulttext = &mt('No changes made to access to server status pages');
20653: }
20654: return $resulttext;
20655: }
20656:
1.118 jms 20657: sub modify_helpsettings {
1.285 raeburn 20658: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20659: my ($resulttext,$errors,%changes,%helphash);
20660: my %defaultchecked = ('submitbugs' => 'on');
20661: my @offon = ('off','on');
1.118 jms 20662: my @toggles = ('submitbugs');
1.285 raeburn 20663: my %current = ('submitbugs' => '',
20664: 'adhoc' => {},
20665: );
1.118 jms 20666: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20667: %current = %{$domconfig{'helpsettings'}};
20668: }
1.285 raeburn 20669: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20670: foreach my $item (@toggles) {
20671: if ($defaultchecked{$item} eq 'on') {
20672: if ($current{$item} eq '') {
20673: if ($env{'form.'.$item} eq '0') {
20674: $changes{$item} = 1;
20675: }
20676: } elsif ($current{$item} ne $env{'form.'.$item}) {
20677: $changes{$item} = 1;
20678: }
20679: } elsif ($defaultchecked{$item} eq 'off') {
20680: if ($current{$item} eq '') {
20681: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20682: $changes{$item} = 1;
20683: }
1.282 raeburn 20684: } elsif ($current{$item} ne $env{'form.'.$item}) {
20685: $changes{$item} = 1;
20686: }
20687: }
20688: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20689: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20690: }
20691: }
1.285 raeburn 20692: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20693: my $confname = $dom.'-domainconfig';
20694: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20695: my (@allpos,%newsettings,%changedprivs,$newrole);
20696: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20697: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20698: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20699: my %lt = &Apache::lonlocal::texthash(
20700: s => 'system',
20701: d => 'domain',
20702: order => 'Display order',
20703: access => 'Role usage',
1.291 raeburn 20704: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20705: dh => 'All with domain helpdesk role',
20706: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20707: none => 'None',
20708: status => 'Determined based on institutional status',
20709: inc => 'Include all, but exclude specific personnel',
20710: exc => 'Exclude all, but include specific personnel',
20711: );
20712: for (my $num=0; $num<=$maxnum; $num++) {
20713: my ($prefix,$identifier,$rolename,%curr);
20714: if ($num == $maxnum) {
20715: next unless ($env{'form.newcusthelp'} == $maxnum);
20716: $identifier = 'custhelp'.$num;
20717: $prefix = 'helproles_'.$num;
20718: $rolename = $env{'form.custhelpname'.$num};
20719: $rolename=~s/[^A-Za-z0-9]//gs;
20720: next if ($rolename eq '');
20721: next if (exists($existing{'rolesdef_'.$rolename}));
20722: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20723: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20724: $newprivs{'c'},$confname,$dom);
20725: if ($result ne 'ok') {
20726: $errors .= '<li><span class="LC_error">'.
20727: &mt('An error occurred storing the new custom role: [_1]',
20728: $result).'</span></li>';
20729: next;
20730: } else {
20731: $changedprivs{$rolename} = \%newprivs;
20732: $newrole = $rolename;
20733: }
20734: } else {
20735: $prefix = 'helproles_'.$num;
20736: $rolename = $env{'form.'.$prefix};
20737: next if ($rolename eq '');
20738: next unless (exists($existing{'rolesdef_'.$rolename}));
20739: $identifier = 'custhelp'.$num;
20740: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20741: my %currprivs;
1.289 raeburn 20742: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 20743: split(/\_/,$existing{'rolesdef_'.$rolename});
20744: foreach my $level ('c','d','s') {
20745: if ($newprivs{$level} ne $currprivs{$level}) {
20746: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20747: $newprivs{'c'},$confname,$dom);
20748: if ($result ne 'ok') {
20749: $errors .= '<li><span class="LC_error">'.
20750: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
20751: $rolename,$result).'</span></li>';
20752: } else {
20753: $changedprivs{$rolename} = \%newprivs;
20754: }
20755: last;
20756: }
20757: }
20758: if (ref($current{'adhoc'}) eq 'HASH') {
20759: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20760: %curr = %{$current{'adhoc'}{$rolename}};
20761: }
20762: }
20763: }
20764: my $newpos = $env{'form.'.$prefix.'_pos'};
20765: $newpos =~ s/\D+//g;
20766: $allpos[$newpos] = $rolename;
20767: my $newdesc = $env{'form.'.$prefix.'_desc'};
20768: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
20769: if ($curr{'desc'}) {
20770: if ($curr{'desc'} ne $newdesc) {
20771: $changes{'customrole'}{$rolename}{'desc'} = 1;
20772: $newsettings{$rolename}{'desc'} = $newdesc;
20773: }
20774: } elsif ($newdesc ne '') {
20775: $changes{'customrole'}{$rolename}{'desc'} = 1;
20776: $newsettings{$rolename}{'desc'} = $newdesc;
20777: }
20778: my $access = $env{'form.'.$prefix.'_access'};
20779: if (grep(/^\Q$access\E$/,@accesstypes)) {
20780: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
20781: if ($access eq 'status') {
20782: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
20783: if (scalar(@statuses) == 0) {
1.289 raeburn 20784: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 20785: } else {
20786: my (@shownstatus,$numtypes);
20787: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20788: if (ref($types) eq 'ARRAY') {
20789: $numtypes = scalar(@{$types});
20790: foreach my $type (sort(@statuses)) {
20791: if ($type eq 'default') {
20792: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20793: } elsif (grep(/^\Q$type\E$/,@{$types})) {
20794: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20795: push(@shownstatus,$usertypes->{$type});
20796: }
20797: }
20798: }
20799: if (grep(/^default$/,@statuses)) {
20800: push(@shownstatus,$othertitle);
20801: }
20802: if (scalar(@shownstatus) == 1+$numtypes) {
20803: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
20804: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
20805: } else {
20806: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
20807: if (ref($curr{'status'}) eq 'ARRAY') {
20808: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20809: if (@diffs) {
20810: $changes{'customrole'}{$rolename}{$access} = 1;
20811: }
20812: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20813: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 20814: }
1.166 raeburn 20815: }
20816: }
1.285 raeburn 20817: } elsif (($access eq 'inc') || ($access eq 'exc')) {
20818: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
20819: my @newspecstaff;
20820: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20821: foreach my $person (sort(@personnel)) {
20822: if ($domhelpdesk{$person}) {
20823: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
20824: }
20825: }
20826: if (ref($curr{$access}) eq 'ARRAY') {
20827: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20828: if (@diffs) {
20829: $changes{'customrole'}{$rolename}{$access} = 1;
20830: }
20831: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20832: $changes{'customrole'}{$rolename}{$access} = 1;
20833: }
20834: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20835: my ($uname,$udom) = split(/:/,$person);
20836: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
20837: }
20838: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 20839: }
1.285 raeburn 20840: } else {
20841: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
20842: }
20843: unless ($curr{'access'} eq $access) {
20844: $changes{'customrole'}{$rolename}{'access'} = 1;
20845: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 20846: }
20847: }
1.285 raeburn 20848: if (@allpos > 0) {
20849: my $idx = 0;
20850: foreach my $rolename (@allpos) {
20851: if ($rolename ne '') {
20852: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
20853: if (ref($current{'adhoc'}) eq 'HASH') {
20854: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20855: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
20856: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 20857: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 20858: }
20859: }
1.282 raeburn 20860: }
1.285 raeburn 20861: $idx ++;
1.166 raeburn 20862: }
20863: }
1.118 jms 20864: }
1.123 jms 20865: my $putresult;
20866: if (keys(%changes) > 0) {
1.166 raeburn 20867: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 20868: if ($putresult eq 'ok') {
1.285 raeburn 20869: if (ref($helphash{'helpsettings'}) eq 'HASH') {
20870: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
20871: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
20872: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
20873: }
20874: }
20875: my $cachetime = 24*60*60;
20876: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20877: if (ref($lastactref) eq 'HASH') {
20878: $lastactref->{'domdefaults'} = 1;
20879: }
20880: } else {
20881: $errors .= '<li><span class="LC_error">'.
20882: &mt('An error occurred storing the settings: [_1]',
20883: $putresult).'</span></li>';
20884: }
20885: }
20886: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
20887: $resulttext = &mt('Changes made:').'<ul>';
20888: my (%shownprivs,@levelorder);
20889: @levelorder = ('c','d','s');
20890: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 20891: foreach my $item (sort(keys(%changes))) {
20892: if ($item eq 'submitbugs') {
20893: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
20894: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
20895: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 20896: } elsif ($item eq 'customrole') {
20897: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 20898: my @keyorder = ('order','desc','access','status','exc','inc');
20899: my %keytext = &Apache::lonlocal::texthash(
20900: order => 'Order',
20901: desc => 'Role description',
20902: access => 'Role usage',
1.300 droeschl 20903: status => 'Allowed institutional types',
1.285 raeburn 20904: exc => 'Allowed personnel',
20905: inc => 'Disallowed personnel',
20906: );
1.282 raeburn 20907: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 20908: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
20909: if ($role eq $newrole) {
20910: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
20911: $role).'<ul>';
20912: } else {
20913: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20914: $role).'<ul>';
20915: }
20916: foreach my $key (@keyorder) {
20917: if ($changes{'customrole'}{$role}{$key}) {
20918: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
20919: $keytext{$key},$newsettings{$role}{$key}).
20920: '</li>';
20921: }
20922: }
20923: if (ref($changedprivs{$role}) eq 'HASH') {
20924: $shownprivs{$role} = 1;
20925: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
20926: foreach my $level (@levelorder) {
20927: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20928: next if ($item eq '');
20929: my ($priv) = split(/\&/,$item,2);
20930: if (&Apache::lonnet::plaintext($priv)) {
20931: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20932: unless ($level eq 'c') {
20933: $resulttext .= ' ('.$lt{$level}.')';
20934: }
20935: $resulttext .= '</li>';
20936: }
20937: }
20938: }
20939: $resulttext .= '</ul>';
20940: }
20941: $resulttext .= '</ul></li>';
20942: }
20943: }
20944: }
20945: }
20946: }
20947: }
20948: if (keys(%changedprivs)) {
20949: foreach my $role (sort(keys(%changedprivs))) {
20950: unless ($shownprivs{$role}) {
20951: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20952: $role).'<ul>'.
20953: '<li>'.&mt('Privileges set to :').'<ul>';
20954: foreach my $level (@levelorder) {
20955: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20956: next if ($item eq '');
20957: my ($priv) = split(/\&/,$item,2);
20958: if (&Apache::lonnet::plaintext($priv)) {
20959: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20960: unless ($level eq 'c') {
20961: $resulttext .= ' ('.$lt{$level}.')';
20962: }
20963: $resulttext .= '</li>';
20964: }
1.282 raeburn 20965: }
20966: }
1.285 raeburn 20967: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 20968: }
20969: }
20970: }
1.285 raeburn 20971: $resulttext .= '</ul>';
20972: } else {
20973: $resulttext = &mt('No changes made to help settings');
1.118 jms 20974: }
20975: if ($errors) {
1.168 raeburn 20976: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 20977: $errors.'</ul>';
1.118 jms 20978: }
20979: return $resulttext;
20980: }
20981:
1.121 raeburn 20982: sub modify_coursedefaults {
1.212 raeburn 20983: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 20984: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 20985: my %defaultchecked = (
20986: 'canuse_pdfforms' => 'off',
20987: 'uselcmath' => 'on',
1.398 raeburn 20988: 'usejsme' => 'on',
20989: 'inline_chem' => 'on',
1.404 raeburn 20990: 'ltiauth' => 'off',
1.257 raeburn 20991: );
1.404 raeburn 20992: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 20993: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 20994: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 20995: 'coursequota_official','coursequota_unofficial','coursequota_community',
20996: 'coursequota_textbook','coursequota_placement','mysqltables_official',
20997: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
20998: 'mysqltables_placement');
1.271 raeburn 20999: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21000: my %staticdefaults = (
21001: anonsurvey_threshold => 10,
21002: uploadquota => 500,
1.428 raeburn 21003: coursequota => 20,
1.257 raeburn 21004: postsubmit => 60,
1.276 raeburn 21005: mysqltables => 172800,
1.422 raeburn 21006: domexttool => 1,
1.198 raeburn 21007: );
1.314 raeburn 21008: my %texoptions = (
21009: MathJax => 'MathJax',
21010: mimetex => &mt('Convert to Images'),
21011: tth => &mt('TeX to HTML'),
21012: );
1.121 raeburn 21013: $defaultshash{'coursedefaults'} = {};
21014:
21015: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21016: if ($domconfig{'coursedefaults'} eq '') {
21017: $domconfig{'coursedefaults'} = {};
21018: }
21019: }
21020:
21021: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21022: foreach my $item (@toggles) {
21023: if ($defaultchecked{$item} eq 'on') {
21024: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21025: ($env{'form.'.$item} eq '0')) {
21026: $changes{$item} = 1;
1.192 raeburn 21027: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21028: $changes{$item} = 1;
21029: }
21030: } elsif ($defaultchecked{$item} eq 'off') {
21031: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21032: ($env{'form.'.$item} eq '1')) {
21033: $changes{$item} = 1;
21034: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21035: $changes{$item} = 1;
21036: }
21037: }
21038: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21039: }
1.198 raeburn 21040: foreach my $item (@numbers) {
21041: my ($currdef,$newdef);
1.208 raeburn 21042: $newdef = $env{'form.'.$item};
1.198 raeburn 21043: if ($item eq 'anonsurvey_threshold') {
21044: $currdef = $domconfig{'coursedefaults'}{$item};
21045: $newdef =~ s/\D//g;
21046: if ($newdef eq '' || $newdef < 1) {
21047: $newdef = 1;
21048: }
21049: $defaultshash{'coursedefaults'}{$item} = $newdef;
21050: } else {
1.428 raeburn 21051: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21052: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21053: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21054: }
21055: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21056: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21057: }
21058: if ($currdef ne $newdef) {
21059: if ($item eq 'anonsurvey_threshold') {
21060: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21061: $changes{$item} = 1;
21062: }
1.428 raeburn 21063: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21064: my $setting = $1;
1.276 raeburn 21065: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21066: $changes{$setting} = 1;
1.198 raeburn 21067: }
21068: }
1.139 raeburn 21069: }
21070: }
1.314 raeburn 21071: my $texengine;
21072: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21073: $texengine = $env{'form.texengine'};
1.349 raeburn 21074: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21075: if ($currdef eq '') {
21076: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21077: $changes{'texengine'} = 1;
21078: }
1.349 raeburn 21079: } elsif ($currdef ne $texengine) {
1.314 raeburn 21080: $changes{'texengine'} = 1;
21081: }
21082: }
21083: if ($texengine ne '') {
21084: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21085: }
1.264 raeburn 21086: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21087: my @currclonecode;
21088: if (ref($currclone) eq 'HASH') {
21089: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21090: @currclonecode = @{$currclone->{'instcode'}};
21091: }
21092: }
21093: my $newclone;
1.289 raeburn 21094: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21095: $newclone = $env{'form.canclone'};
21096: }
21097: if ($newclone eq 'instcode') {
21098: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21099: my (%codedefaults,@code_order,@clonecode);
21100: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21101: \@code_order);
21102: foreach my $item (@code_order) {
21103: if (grep(/^\Q$item\E$/,@newcodes)) {
21104: push(@clonecode,$item);
21105: }
21106: }
21107: if (@clonecode) {
21108: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21109: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21110: if (@diffs) {
21111: $changes{'canclone'} = 1;
21112: }
21113: } else {
21114: $newclone eq '';
21115: }
21116: } elsif ($newclone ne '') {
1.289 raeburn 21117: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21118: }
1.264 raeburn 21119: if ($newclone ne $currclone) {
21120: $changes{'canclone'} = 1;
21121: }
1.257 raeburn 21122: my %credits;
21123: foreach my $type (@types) {
21124: unless ($type eq 'community') {
21125: $credits{$type} = $env{'form.'.$type.'_credits'};
21126: $credits{$type} =~ s/[^\d.]+//g;
21127: }
21128: }
21129: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21130: ($env{'form.coursecredits'} eq '1')) {
21131: $changes{'coursecredits'} = 1;
21132: foreach my $type (keys(%credits)) {
21133: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21134: }
21135: } else {
1.289 raeburn 21136: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21137: foreach my $type (@types) {
21138: unless ($type eq 'community') {
1.289 raeburn 21139: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21140: $changes{'coursecredits'} = 1;
21141: }
21142: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21143: }
21144: }
21145: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21146: foreach my $type (@types) {
21147: unless ($type eq 'community') {
21148: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21149: $changes{'coursecredits'} = 1;
21150: last;
21151: }
21152: }
21153: }
21154: }
21155: }
21156: if ($env{'form.postsubmit'} eq '1') {
21157: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21158: my %currtimeout;
21159: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21160: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21161: $changes{'postsubmit'} = 1;
21162: }
21163: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21164: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21165: }
21166: } else {
21167: $changes{'postsubmit'} = 1;
21168: }
21169: foreach my $type (@types) {
21170: my $timeout = $env{'form.'.$type.'_timeout'};
21171: $timeout =~ s/\D//g;
21172: if ($timeout == $staticdefaults{'postsubmit'}) {
21173: $timeout = '';
21174: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21175: $timeout = '0';
21176: }
21177: unless ($timeout eq '') {
21178: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21179: }
21180: if (exists($currtimeout{$type})) {
21181: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21182: $changes{'postsubmit'} = 1;
1.257 raeburn 21183: }
21184: } elsif ($timeout ne '') {
21185: $changes{'postsubmit'} = 1;
21186: }
21187: }
21188: } else {
21189: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21190: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21191: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21192: $changes{'postsubmit'} = 1;
21193: }
21194: } else {
21195: $changes{'postsubmit'} = 1;
21196: }
1.192 raeburn 21197: }
1.422 raeburn 21198: my (%newdomexttool,%newexttool,%olddomexttool,%oldexttool);
21199: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21200: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.422 raeburn 21201: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21202: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21203: } else {
21204: foreach my $type (@types) {
21205: if ($staticdefaults{'domexttool'}) {
21206: $olddomexttool{$type} = 1;
21207: } else {
21208: $olddomexttool{$type} = 0;
21209: }
21210: }
21211: }
21212: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21213: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21214: } else {
21215: foreach my $type (@types) {
21216: if ($staticdefaults{'exttool'}) {
21217: $oldexttool{$type} = 1;
21218: } else {
21219: $oldexttool{$type} = 0;
21220: }
21221: }
21222: }
21223: foreach my $type (@types) {
21224: unless ($newdomexttool{$type}) {
21225: $newdomexttool{$type} = 0;
21226: }
21227: unless ($newexttool{$type}) {
21228: $newexttool{$type} = 0;
21229: }
21230: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21231: $changes{'domexttool'} = 1;
21232: }
21233: if ($newexttool{$type} != $oldexttool{$type}) {
21234: $changes{'exttool'} = 1;
21235: }
21236: }
21237: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21238: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.121 raeburn 21239: }
21240: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21241: $dom);
21242: if ($putresult eq 'ok') {
21243: if (keys(%changes) > 0) {
1.213 raeburn 21244: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21245: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21246: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21247: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21248: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.428 raeburn 21249: ($changes{'exttool'}) || ($changes{'coursequota'})) {
1.422 raeburn 21250: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21251: 'ltiauth') {
1.257 raeburn 21252: if ($changes{$item}) {
21253: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21254: }
1.289 raeburn 21255: }
1.192 raeburn 21256: if ($changes{'coursecredits'}) {
21257: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21258: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21259: $domdefaults{$type.'credits'} =
21260: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21261: }
21262: }
21263: }
21264: if ($changes{'postsubmit'}) {
21265: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21266: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21267: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21268: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21269: $domdefaults{$type.'postsubtimeout'} =
21270: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21271: }
21272: }
1.192 raeburn 21273: }
21274: }
1.198 raeburn 21275: if ($changes{'uploadquota'}) {
21276: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21277: foreach my $type (@types) {
21278: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21279: }
21280: }
21281: }
1.428 raeburn 21282: if ($changes{'coursequota'}) {
21283: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21284: foreach my $type (@types) {
21285: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21286: }
21287: }
21288: }
1.264 raeburn 21289: if ($changes{'canclone'}) {
21290: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21291: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21292: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21293: if (@clonecodes) {
21294: $domdefaults{'canclone'} = join('+',@clonecodes);
21295: }
21296: }
21297: } else {
21298: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21299: }
21300: }
1.422 raeburn 21301: if ($changes{'domexttool'}) {
21302: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21303: foreach my $type (@types) {
21304: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21305: }
21306: }
21307: }
21308: if ($changes{'exttool'}) {
21309: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21310: foreach my $type (@types) {
21311: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21312: }
21313: }
21314: }
1.121 raeburn 21315: my $cachetime = 24*60*60;
21316: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21317: if (ref($lastactref) eq 'HASH') {
21318: $lastactref->{'domdefaults'} = 1;
21319: }
1.121 raeburn 21320: }
21321: $resulttext = &mt('Changes made:').'<ul>';
21322: foreach my $item (sort(keys(%changes))) {
21323: if ($item eq 'canuse_pdfforms') {
21324: if ($env{'form.'.$item} eq '1') {
21325: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21326: } else {
21327: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21328: }
1.257 raeburn 21329: } elsif ($item eq 'uselcmath') {
21330: if ($env{'form.'.$item} eq '1') {
21331: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21332: } else {
21333: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21334: }
21335: } elsif ($item eq 'usejsme') {
21336: if ($env{'form.'.$item} eq '1') {
21337: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21338: } else {
1.289 raeburn 21339: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21340: }
1.398 raeburn 21341: } elsif ($item eq 'inline_chem') {
21342: if ($env{'form.'.$item} eq '1') {
21343: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21344: } else {
21345: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21346: }
1.314 raeburn 21347: } elsif ($item eq 'texengine') {
21348: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21349: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21350: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21351: }
1.139 raeburn 21352: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21353: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21354: } elsif ($item eq 'uploadquota') {
21355: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21356: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21357: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21358: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21359: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21360: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21361: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21362: '</ul>'.
21363: '</li>';
21364: } else {
21365: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21366: }
1.428 raeburn 21367: } elsif ($item eq 'coursequota') {
21368: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21369: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21370: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21371: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21372: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21373: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21374: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21375: '</ul>'.
21376: '</li>';
21377: } else {
21378: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21379: }
1.276 raeburn 21380: } elsif ($item eq 'mysqltables') {
21381: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21382: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21383: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21384: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21385: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21386: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21387: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21388: '</ul>'.
21389: '</li>';
21390: } else {
21391: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21392: }
1.257 raeburn 21393: } elsif ($item eq 'postsubmit') {
21394: if ($domdefaults{'postsubmit'} eq 'off') {
21395: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21396: } else {
21397: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21398: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21399: $resulttext .= &mt('durations:').'<ul>';
21400: foreach my $type (@types) {
21401: $resulttext .= '<li>';
21402: my $timeout;
21403: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21404: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21405: }
21406: my $display;
21407: if ($timeout eq '0') {
21408: $display = &mt('unlimited');
21409: } elsif ($timeout eq '') {
21410: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21411: } else {
21412: $display = &mt('[quant,_1,second]',$timeout);
21413: }
21414: if ($type eq 'community') {
21415: $resulttext .= &mt('Communities');
21416: } elsif ($type eq 'official') {
21417: $resulttext .= &mt('Official courses');
21418: } elsif ($type eq 'unofficial') {
21419: $resulttext .= &mt('Unofficial courses');
21420: } elsif ($type eq 'textbook') {
21421: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21422: } elsif ($type eq 'placement') {
21423: $resulttext .= &mt('Placement tests');
1.257 raeburn 21424: }
21425: $resulttext .= ' -- '.$display.'</li>';
21426: }
21427: $resulttext .= '</ul>';
21428: }
1.289 raeburn 21429: $resulttext .= '</li>';
1.257 raeburn 21430: }
1.192 raeburn 21431: } elsif ($item eq 'coursecredits') {
21432: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21433: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21434: ($domdefaults{'unofficialcredits'} eq '') &&
21435: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21436: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21437: } else {
21438: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21439: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21440: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21441: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21442: '</ul>'.
21443: '</li>';
21444: }
21445: } else {
21446: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21447: }
1.264 raeburn 21448: } elsif ($item eq 'canclone') {
21449: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21450: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21451: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21452: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21453: }
21454: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21455: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21456: } else {
1.289 raeburn 21457: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21458: }
1.404 raeburn 21459: } elsif ($item eq 'ltiauth') {
21460: if ($env{'form.'.$item} eq '1') {
21461: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21462: } else {
21463: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21464: }
1.422 raeburn 21465: } elsif ($item eq 'domexttool') {
21466: my @noyes = (&mt('no'),&mt('yes'));
21467: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21468: $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used as follows:').'<ul>'.
21469: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'official'}].'</b>').'</li>'.
21470: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'unofficial'}].'</b>').'</li>'.
21471: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'textbook'}].'</b>').'</li>'.
21472: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'placement'}].'</b>').'</li>'.
21473: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'community'}].'</b>').'</li>'.
21474: '</ul>'.
21475: '</li>';
21476: } else {
21477: $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used in all course types, by default').'</li>';
21478: }
21479: } elsif ($item eq 'exttool') {
21480: my @noyes = (&mt('no'),&mt('yes'));
21481: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21482: $resulttext .= '<li>'.&mt('External Tools can be defined and configured in course containers as follows:').'<ul>'.
21483: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'official'}].'</b>').'</li>'.
21484: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'unofficial'}].'</b>').'</li>'.
21485: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'textbook'}].'</b>').'</li>'.
21486: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'placement'}].'</b>').'</li>'.
21487: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'community'}].'</b>').'</li>'.
21488: '</ul>'.
21489: '</li>';
21490: } else {
21491: $resulttext .= '<li>'.&mt('External Tools can not be defined in any course types, by default').'</li>';
21492: }
1.140 raeburn 21493: }
1.121 raeburn 21494: }
21495: $resulttext .= '</ul>';
21496: } else {
21497: $resulttext = &mt('No changes made to course defaults');
21498: }
21499: } else {
21500: $resulttext = '<span class="LC_error">'.
21501: &mt('An error occurred: [_1]',$putresult).'</span>';
21502: }
21503: return $resulttext;
21504: }
21505:
1.231 raeburn 21506: sub modify_selfenrollment {
21507: my ($dom,$lastactref,%domconfig) = @_;
21508: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21509: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21510: my %titles = &tool_titles();
1.232 raeburn 21511: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21512: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21513: $ordered{'default'} = ['types','registered','approval','limit'];
21514:
21515: my (%roles,%shown,%toplevel);
21516: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21517:
21518: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21519: if ($domconfig{'selfenrollment'} eq '') {
21520: $domconfig{'selfenrollment'} = {};
21521: }
21522: }
21523: %toplevel = (
21524: admin => 'Configuration Rights',
21525: default => 'Default settings',
21526: validation => 'Validation of self-enrollment requests',
21527: );
1.233 raeburn 21528: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21529:
21530: if (ref($ordered{'admin'}) eq 'ARRAY') {
21531: foreach my $item (@{$ordered{'admin'}}) {
21532: foreach my $type (@types) {
21533: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21534: $selfenrollhash{'admin'}{$type}{$item} = 1;
21535: } else {
21536: $selfenrollhash{'admin'}{$type}{$item} = 0;
21537: }
21538: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21539: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21540: if ($selfenrollhash{'admin'}{$type}{$item} ne
21541: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21542: push(@{$changes{'admin'}{$type}},$item);
21543: }
21544: } else {
21545: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21546: push(@{$changes{'admin'}{$type}},$item);
21547: }
21548: }
21549: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21550: push(@{$changes{'admin'}{$type}},$item);
21551: }
21552: }
21553: }
21554: }
21555:
21556: foreach my $item (@{$ordered{'default'}}) {
21557: foreach my $type (@types) {
21558: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21559: if ($item eq 'types') {
21560: unless (($value eq 'all') || ($value eq 'dom')) {
21561: $value = '';
21562: }
21563: } elsif ($item eq 'registered') {
21564: unless ($value eq '1') {
21565: $value = 0;
21566: }
21567: } elsif ($item eq 'approval') {
21568: unless ($value =~ /^[012]$/) {
21569: $value = 0;
21570: }
21571: } else {
21572: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21573: $value = 'none';
21574: }
21575: }
21576: $selfenrollhash{'default'}{$type}{$item} = $value;
21577: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21578: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21579: if ($selfenrollhash{'default'}{$type}{$item} ne
21580: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21581: push(@{$changes{'default'}{$type}},$item);
21582: }
21583: } else {
21584: push(@{$changes{'default'}{$type}},$item);
21585: }
21586: } else {
21587: push(@{$changes{'default'}{$type}},$item);
21588: }
21589: if ($item eq 'limit') {
21590: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21591: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21592: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21593: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21594: }
21595: } else {
21596: $selfenrollhash{'default'}{$type}{'cap'} = '';
21597: }
21598: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21599: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21600: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21601: push(@{$changes{'default'}{$type}},'cap');
21602: }
21603: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21604: push(@{$changes{'default'}{$type}},'cap');
21605: }
21606: }
21607: }
21608: }
21609:
21610: foreach my $item (@{$itemsref}) {
21611: if ($item eq 'fields') {
21612: my @changed;
21613: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21614: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21615: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21616: }
21617: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21618: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21619: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21620: $domconfig{'selfenrollment'}{'validation'}{$item});
21621: } else {
21622: @changed = @{$selfenrollhash{'validation'}{$item}};
21623: }
21624: } else {
21625: @changed = @{$selfenrollhash{'validation'}{$item}};
21626: }
21627: if (@changed) {
21628: if ($selfenrollhash{'validation'}{$item}) {
21629: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21630: } else {
21631: $changes{'validation'}{$item} = &mt('None');
21632: }
21633: }
21634: } else {
21635: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21636: if ($item eq 'markup') {
21637: if ($env{'form.selfenroll_validation_'.$item}) {
21638: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21639: }
21640: }
21641: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21642: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21643: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21644: }
21645: }
21646: }
21647: }
21648:
21649: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21650: $dom);
21651: if ($putresult eq 'ok') {
21652: if (keys(%changes) > 0) {
21653: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21654: $resulttext = &mt('Changes made:').'<ul>';
21655: foreach my $key ('admin','default','validation') {
21656: if (ref($changes{$key}) eq 'HASH') {
21657: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
21658: if ($key eq 'validation') {
21659: foreach my $item (@{$itemsref}) {
21660: if (exists($changes{$key}{$item})) {
21661: if ($item eq 'markup') {
21662: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21663: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
21664: } else {
21665: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21666: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
21667: }
21668: }
21669: }
21670: } else {
21671: foreach my $type (@types) {
21672: if ($type eq 'community') {
21673: $roles{'1'} = &mt('Community personnel');
21674: } else {
21675: $roles{'1'} = &mt('Course personnel');
21676: }
21677: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 21678: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21679: if ($key eq 'admin') {
21680: my @mgrdc = ();
21681: if (ref($ordered{$key}) eq 'ARRAY') {
21682: foreach my $item (@{$ordered{'admin'}}) {
21683: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21684: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
21685: push(@mgrdc,$item);
21686: }
21687: }
21688: }
21689: if (@mgrdc) {
21690: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
21691: } else {
21692: delete($domdefaults{$type.'selfenrolladmdc'});
21693: }
21694: }
21695: } else {
21696: if (ref($ordered{$key}) eq 'ARRAY') {
21697: foreach my $item (@{$ordered{$key}}) {
21698: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21699: $domdefaults{$type.'selfenroll'.$item} =
21700: $selfenrollhash{$key}{$type}{$item};
21701: }
21702: }
21703: }
21704: }
21705: }
1.231 raeburn 21706: $resulttext .= '<li>'.$titles{$type}.'<ul>';
21707: foreach my $item (@{$ordered{$key}}) {
21708: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21709: $resulttext .= '<li>';
21710: if ($key eq 'admin') {
21711: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
21712: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
21713: } else {
21714: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
21715: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
21716: }
21717: $resulttext .= '</li>';
21718: }
21719: }
21720: $resulttext .= '</ul></li>';
21721: }
21722: }
21723: $resulttext .= '</ul></li>';
21724: }
21725: }
1.305 raeburn 21726: }
21727: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
21728: my $cachetime = 24*60*60;
21729: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21730: if (ref($lastactref) eq 'HASH') {
21731: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 21732: }
1.231 raeburn 21733: }
21734: $resulttext .= '</ul>';
21735: } else {
21736: $resulttext = &mt('No changes made to self-enrollment settings');
21737: }
21738: } else {
21739: $resulttext = '<span class="LC_error">'.
21740: &mt('An error occurred: [_1]',$putresult).'</span>';
21741: }
21742: return $resulttext;
21743: }
21744:
1.373 raeburn 21745: sub modify_wafproxy {
21746: my ($dom,$action,$lastactref,%domconfig) = @_;
21747: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 21748: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
21749: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 21750: foreach my $server (sort(keys(%servers))) {
21751: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21752: if ($serverhome eq $server) {
21753: my $serverdom = &Apache::lonnet::host_domain($server);
21754: if ($serverdom eq $dom) {
21755: $canset{$server} = 1;
21756: }
21757: }
21758: }
1.381 raeburn 21759: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
21760: %{$values{$dom}} = ();
21761: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
21762: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
21763: }
1.388 raeburn 21764: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
21765: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
21766: }
1.382 raeburn 21767: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 21768: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
21769: }
21770: }
1.373 raeburn 21771: my $output;
21772: if (keys(%canset)) {
21773: %{$wafproxy{'alias'}} = ();
1.388 raeburn 21774: %{$wafproxy{'saml'}} = ();
1.373 raeburn 21775: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 21776: if ($env{'form.wafproxy_'.$dom}) {
21777: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
21778: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
21779: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
21780: $changes{'alias'} = 1;
21781: }
1.388 raeburn 21782: if ($env{'form.wafproxy_alias_saml_'.$key}) {
21783: $wafproxy{'saml'}{$key} = 1;
21784: }
21785: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
21786: $changes{'saml'} = 1;
21787: }
1.381 raeburn 21788: } else {
21789: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 21790: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 21791: if ($curralias{$key}) {
21792: $changes{'alias'} = 1;
21793: }
1.388 raeburn 21794: if ($currsaml{$key}) {
21795: $changes{'saml'} = 1;
21796: }
1.373 raeburn 21797: }
21798: if ($wafproxy{'alias'}{$key} eq '') {
21799: if ($curralias{$key}) {
21800: $expirecache{$key} = 1;
21801: }
21802: delete($wafproxy{'alias'}{$key});
21803: }
1.388 raeburn 21804: if ($wafproxy{'saml'}{$key} eq '') {
21805: if ($currsaml{$key}) {
21806: $expiresaml{$key} = 1;
21807: }
21808: delete($wafproxy{'saml'}{$key});
21809: }
1.373 raeburn 21810: }
21811: unless (keys(%{$wafproxy{'alias'}})) {
21812: delete($wafproxy{'alias'});
21813: }
1.388 raeburn 21814: unless (keys(%{$wafproxy{'saml'}})) {
21815: delete($wafproxy{'saml'});
21816: }
21817: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 21818: my %warn = (
21819: trusted => 'trusted IP range(s)',
1.381 raeburn 21820: vpnint => 'internal IP range(s) for VPN sessions(s)',
21821: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 21822: );
1.382 raeburn 21823: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21824: my $possible = $env{'form.wafproxy_'.$item};
21825: $possible =~ s/^\s+|\s+$//g;
21826: if ($possible ne '') {
1.381 raeburn 21827: if ($item eq 'remoteip') {
21828: if ($possible =~ /^[mhn]$/) {
21829: $wafproxy{$item} = $possible;
21830: }
21831: } elsif ($item eq 'ipheader') {
21832: if ($wafproxy{'remoteip'} eq 'h') {
21833: $wafproxy{$item} = $possible;
21834: }
1.382 raeburn 21835: } elsif ($item eq 'sslopt') {
21836: if ($possible =~ /^0|1$/) {
21837: $wafproxy{$item} = $possible;
21838: }
1.373 raeburn 21839: } else {
21840: my (@ok,$count);
1.381 raeburn 21841: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
21842: unless ($env{'form.wafproxy_vpnaccess'}) {
21843: $possible = '';
21844: }
21845: } elsif ($item eq 'trusted') {
21846: unless ($wafproxy{'remoteip'} eq 'h') {
21847: $possible = '';
21848: }
21849: }
21850: unless ($possible eq '') {
21851: $possible =~ s/[\r\n]+/\s/g;
21852: $possible =~ s/\s*-\s*/-/g;
21853: $possible =~ s/\s+/,/g;
1.393 raeburn 21854: $possible =~ s/,+/,/g;
1.381 raeburn 21855: }
1.373 raeburn 21856: $count = 0;
1.381 raeburn 21857: if ($possible ne '') {
1.373 raeburn 21858: foreach my $poss (split(/\,/,$possible)) {
21859: $count ++;
1.393 raeburn 21860: $poss = &validate_ip_pattern($poss);
21861: if ($poss ne '') {
1.373 raeburn 21862: push(@ok,$poss);
21863: }
21864: }
21865: my $diff = $count - scalar(@ok);
21866: if ($diff) {
21867: push(@warnings,'<li>'.
21868: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
21869: $diff,$warn{$item}).
21870: '</li>');
21871: }
1.393 raeburn 21872: if (@ok) {
21873: my @cidr_list;
21874: foreach my $item (@ok) {
21875: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
21876: }
21877: $wafproxy{$item} = join(',',@cidr_list);
21878: }
1.373 raeburn 21879: }
21880: }
1.381 raeburn 21881: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 21882: $changes{$item} = 1;
21883: }
1.381 raeburn 21884: } elsif ($currvalue{$item}) {
21885: $changes{$item} = 1;
1.425 raeburn 21886: }
1.381 raeburn 21887: }
21888: } else {
21889: if (keys(%curralias)) {
21890: $changes{'alias'} = 1;
1.388 raeburn 21891: }
21892: if (keys(%currsaml)) {
21893: $changes{'saml'} = 1;
1.425 raeburn 21894: }
1.381 raeburn 21895: if (keys(%currvalue)) {
21896: foreach my $key (keys(%currvalue)) {
21897: $changes{$key} = 1;
1.373 raeburn 21898: }
21899: }
21900: }
21901: if (keys(%changes)) {
21902: my %defaultshash = (
21903: wafproxy => \%wafproxy,
1.425 raeburn 21904: );
1.373 raeburn 21905: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21906: $dom);
21907: if ($putresult eq 'ok') {
21908: my $cachetime = 24*60*60;
21909: my (%domdefaults,$updatedomdefs);
1.382 raeburn 21910: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21911: if ($changes{$item}) {
21912: unless ($updatedomdefs) {
21913: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
21914: $updatedomdefs = 1;
21915: }
21916: if ($wafproxy{$item}) {
21917: $domdefaults{'waf_'.$item} = $wafproxy{$item};
21918: } elsif (exists($domdefaults{'waf_'.$item})) {
21919: delete($domdefaults{'waf_'.$item});
1.425 raeburn 21920: }
1.373 raeburn 21921: }
21922: }
21923: if ($updatedomdefs) {
21924: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21925: if (ref($lastactref) eq 'HASH') {
21926: $lastactref->{'domdefaults'} = 1;
21927: }
21928: }
21929: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
21930: my %updates = %expirecache;
21931: foreach my $key (keys(%expirecache)) {
21932: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
21933: }
21934: if (ref($wafproxy{'alias'}) eq 'HASH') {
21935: my $cachetime = 24*60*60;
21936: foreach my $key (keys(%{$wafproxy{'alias'}})) {
21937: $updates{$key} = 1;
21938: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
21939: $cachetime);
21940: }
21941: }
21942: if (ref($lastactref) eq 'HASH') {
21943: $lastactref->{'proxyalias'} = \%updates;
21944: }
21945: }
1.388 raeburn 21946: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
21947: my %samlupdates = %expiresaml;
21948: foreach my $key (keys(%expiresaml)) {
21949: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
21950: }
21951: if (ref($wafproxy{'saml'}) eq 'HASH') {
21952: my $cachetime = 24*60*60;
21953: foreach my $key (keys(%{$wafproxy{'saml'}})) {
21954: $samlupdates{$key} = 1;
21955: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
21956: $cachetime);
21957: }
21958: }
21959: if (ref($lastactref) eq 'HASH') {
21960: $lastactref->{'proxysaml'} = \%samlupdates;
21961: }
21962: }
1.373 raeburn 21963: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 21964: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21965: if ($changes{$item}) {
21966: if ($item eq 'alias') {
21967: my $numaliased = 0;
21968: if (ref($wafproxy{'alias'}) eq 'HASH') {
21969: my $shown;
21970: if (keys(%{$wafproxy{'alias'}})) {
21971: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
21972: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
21973: &Apache::lonnet::hostname($server),
21974: $wafproxy{'alias'}{$server}).'</li>';
21975: $numaliased ++;
21976: }
21977: if ($numaliased) {
21978: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
21979: '<ul>'.$shown.'</ul>').'</li>';
21980: }
21981: }
21982: }
21983: unless ($numaliased) {
21984: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
21985: }
1.388 raeburn 21986: } elsif ($item eq 'saml') {
1.425 raeburn 21987: my $shown;
1.388 raeburn 21988: if (ref($wafproxy{'saml'}) eq 'HASH') {
21989: if (keys(%{$wafproxy{'saml'}})) {
21990: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
21991: }
21992: }
21993: if ($shown) {
1.396 raeburn 21994: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 21995: $shown).'</li>';
21996: } else {
1.396 raeburn 21997: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 21998: }
1.373 raeburn 21999: } else {
1.381 raeburn 22000: if ($item eq 'remoteip') {
22001: my %ip_methods = &remoteip_methods();
22002: if ($wafproxy{$item} =~ /^[mh]$/) {
22003: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22004: $ip_methods{$wafproxy{$item}}).'</li>';
22005: } else {
22006: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22007: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22008: '</li>';
22009: } else {
22010: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22011: }
22012: }
22013: } elsif ($item eq 'ipheader') {
1.373 raeburn 22014: if ($wafproxy{$item}) {
1.381 raeburn 22015: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22016: $wafproxy{$item}).'</li>';
22017: } else {
1.381 raeburn 22018: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22019: }
22020: } elsif ($item eq 'trusted') {
22021: if ($wafproxy{$item}) {
1.381 raeburn 22022: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22023: $wafproxy{$item}).'</li>';
22024: } else {
22025: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22026: }
1.381 raeburn 22027: } elsif ($item eq 'vpnint') {
22028: if ($wafproxy{$item}) {
22029: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22030: $wafproxy{$item}).'</li>';
22031: } else {
22032: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22033: }
22034: } elsif ($item eq 'vpnext') {
1.373 raeburn 22035: if ($wafproxy{$item}) {
1.381 raeburn 22036: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22037: $wafproxy{$item}).'</li>';
22038: } else {
1.381 raeburn 22039: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22040: }
1.382 raeburn 22041: } elsif ($item eq 'sslopt') {
22042: if ($wafproxy{$item}) {
22043: $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>';
22044: } else {
22045: $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>';
22046: }
1.373 raeburn 22047: }
22048: }
22049: }
22050: }
1.420 raeburn 22051: $output .= '</ul>';
1.373 raeburn 22052: } else {
22053: $output = '<span class="LC_error">'.
22054: &mt('An error occurred: [_1]',$putresult).'</span>';
22055: }
22056: } elsif (keys(%canset)) {
22057: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22058: }
22059: if (@warnings) {
22060: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22061: join("\n",@warnings).'</ul>';
22062: }
22063: return $output;
22064: }
22065:
22066: sub validate_ip_pattern {
22067: my ($pattern) = @_;
22068: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22069: my ($start,$end) = ($1,$2);
22070: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22071: if (($start !~ m{/}) && ($end !~ m{/})) {
22072: return $start.'-'.$end;
22073: }
22074: }
22075: } elsif ($pattern ne '') {
22076: $pattern = &Net::CIDR::cidrvalidate($pattern);
22077: if ($pattern ne '') {
22078: return $pattern;
1.373 raeburn 22079: }
22080: }
1.393 raeburn 22081: return;
1.373 raeburn 22082: }
22083:
1.137 raeburn 22084: sub modify_usersessions {
1.212 raeburn 22085: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22086: my @hostingtypes = ('version','excludedomain','includedomain');
22087: my @offloadtypes = ('primary','default');
22088: my %types = (
22089: remote => \@hostingtypes,
22090: hosted => \@hostingtypes,
22091: spares => \@offloadtypes,
22092: );
22093: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22094: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22095: my (%by_ip,%by_location,@intdoms,@instdoms);
22096: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22097: my @locations = sort(keys(%by_location));
1.137 raeburn 22098: my (%defaultshash,%changes);
22099: foreach my $prefix (@prefixes) {
22100: $defaultshash{'usersessions'}{$prefix} = {};
22101: }
1.212 raeburn 22102: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22103: my $resulttext;
1.138 raeburn 22104: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22105: foreach my $prefix (@prefixes) {
1.145 raeburn 22106: next if ($prefix eq 'spares');
22107: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22108: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22109: if ($type eq 'version') {
22110: my $value = $env{'form.'.$prefix.'_'.$type};
22111: my $okvalue;
22112: if ($value ne '') {
22113: if (grep(/^\Q$value\E$/,@lcversions)) {
22114: $okvalue = $value;
22115: }
22116: }
22117: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22118: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22119: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22120: if ($inuse == 0) {
22121: $changes{$prefix}{$type} = 1;
22122: } else {
22123: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22124: $changes{$prefix}{$type} = 1;
22125: }
22126: if ($okvalue ne '') {
22127: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22128: }
22129: }
22130: } else {
22131: if (($inuse == 1) && ($okvalue ne '')) {
22132: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22133: $changes{$prefix}{$type} = 1;
22134: }
22135: }
22136: } else {
22137: if (($inuse == 1) && ($okvalue ne '')) {
22138: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22139: $changes{$prefix}{$type} = 1;
22140: }
22141: }
22142: } else {
22143: if (($inuse == 1) && ($okvalue ne '')) {
22144: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22145: $changes{$prefix}{$type} = 1;
22146: }
22147: }
22148: } else {
22149: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22150: my @okvals;
22151: foreach my $val (@vals) {
1.138 raeburn 22152: if ($val =~ /:/) {
22153: my @items = split(/:/,$val);
22154: foreach my $item (@items) {
22155: if (ref($by_location{$item}) eq 'ARRAY') {
22156: push(@okvals,$item);
22157: }
22158: }
22159: } else {
22160: if (ref($by_location{$val}) eq 'ARRAY') {
22161: push(@okvals,$val);
22162: }
1.137 raeburn 22163: }
22164: }
22165: @okvals = sort(@okvals);
22166: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22167: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22168: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22169: if ($inuse == 0) {
22170: $changes{$prefix}{$type} = 1;
22171: } else {
22172: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22173: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22174: if (@changed > 0) {
22175: $changes{$prefix}{$type} = 1;
22176: }
22177: }
22178: } else {
22179: if ($inuse == 1) {
22180: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22181: $changes{$prefix}{$type} = 1;
22182: }
22183: }
22184: } else {
22185: if ($inuse == 1) {
22186: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22187: $changes{$prefix}{$type} = 1;
22188: }
22189: }
22190: } else {
22191: if ($inuse == 1) {
22192: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22193: $changes{$prefix}{$type} = 1;
22194: }
22195: }
22196: }
22197: }
22198: }
1.145 raeburn 22199:
22200: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22201: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22202: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22203: my $savespares;
22204:
22205: foreach my $lonhost (sort(keys(%servers))) {
22206: my $serverhomeID =
22207: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22208: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22209: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22210: my %spareschg;
22211: foreach my $type (@{$types{'spares'}}) {
22212: my @okspares;
22213: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22214: foreach my $server (@checked) {
1.152 raeburn 22215: if (&Apache::lonnet::hostname($server) ne '') {
22216: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22217: unless (grep(/^\Q$server\E$/,@okspares)) {
22218: push(@okspares,$server);
22219: }
1.145 raeburn 22220: }
22221: }
22222: }
22223: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22224: my $newspare;
1.152 raeburn 22225: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22226: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22227: $newspare = $new;
22228: }
22229: }
1.152 raeburn 22230: my @spares;
22231: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22232: @spares = sort(@okspares,$newspare);
22233: } else {
22234: @spares = sort(@okspares);
22235: }
22236: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22237: if (ref($spareid{$lonhost}) eq 'HASH') {
22238: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22239: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22240: if (@diffs > 0) {
22241: $spareschg{$type} = 1;
22242: }
22243: }
22244: }
22245: }
22246: if (keys(%spareschg) > 0) {
22247: $changes{'spares'}{$lonhost} = \%spareschg;
22248: }
22249: }
1.261 raeburn 22250: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22251: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22252: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22253: my @okoffload;
22254: if (@offloadnow) {
22255: foreach my $server (@offloadnow) {
22256: if (&Apache::lonnet::hostname($server) ne '') {
22257: unless (grep(/^\Q$server\E$/,@okoffload)) {
22258: push(@okoffload,$server);
22259: }
22260: }
22261: }
22262: if (@okoffload) {
22263: foreach my $lonhost (@okoffload) {
22264: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22265: }
22266: }
22267: }
1.371 raeburn 22268: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22269: my @okoffloadoth;
22270: if (@offloadoth) {
22271: foreach my $server (@offloadoth) {
22272: if (&Apache::lonnet::hostname($server) ne '') {
22273: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22274: push(@okoffloadoth,$server);
22275: }
22276: }
22277: }
22278: if (@okoffloadoth) {
22279: foreach my $lonhost (@okoffloadoth) {
22280: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22281: }
22282: }
22283: }
1.145 raeburn 22284: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22285: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22286: if (ref($changes{'spares'}) eq 'HASH') {
22287: if (keys(%{$changes{'spares'}}) > 0) {
22288: $savespares = 1;
22289: }
22290: }
22291: } else {
22292: $savespares = 1;
22293: }
1.371 raeburn 22294: foreach my $offload ('offloadnow','offloadoth') {
22295: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22296: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22297: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22298: $changes{$offload} = 1;
22299: last;
22300: }
1.261 raeburn 22301: }
1.371 raeburn 22302: unless ($changes{$offload}) {
22303: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22304: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22305: $changes{$offload} = 1;
22306: last;
22307: }
1.261 raeburn 22308: }
22309: }
1.371 raeburn 22310: } else {
22311: if (($offload eq 'offloadnow') && (@okoffload)) {
22312: $changes{'offloadnow'} = 1;
22313: }
22314: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22315: $changes{'offloadoth'} = 1;
22316: }
1.425 raeburn 22317: }
1.371 raeburn 22318: }
22319: } else {
22320: if (@okoffload) {
1.261 raeburn 22321: $changes{'offloadnow'} = 1;
22322: }
1.371 raeburn 22323: if (@okoffloadoth) {
22324: $changes{'offloadoth'} = 1;
22325: }
1.145 raeburn 22326: }
1.147 raeburn 22327: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22328: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22329: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22330: $dom);
22331: if ($putresult eq 'ok') {
22332: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22333: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22334: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22335: }
22336: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22337: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22338: }
1.261 raeburn 22339: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22340: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22341: }
1.371 raeburn 22342: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22343: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22344: }
1.137 raeburn 22345: }
22346: my $cachetime = 24*60*60;
22347: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22348: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22349: if (ref($lastactref) eq 'HASH') {
22350: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22351: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22352: }
1.147 raeburn 22353: if (keys(%changes) > 0) {
22354: my %lt = &usersession_titles();
22355: $resulttext = &mt('Changes made:').'<ul>';
22356: foreach my $prefix (@prefixes) {
22357: if (ref($changes{$prefix}) eq 'HASH') {
22358: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22359: if ($prefix eq 'spares') {
22360: if (ref($changes{$prefix}) eq 'HASH') {
22361: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22362: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22363: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22364: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22365: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22366: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22367: foreach my $type (@{$types{$prefix}}) {
22368: if ($changes{$prefix}{$lonhost}{$type}) {
22369: my $offloadto = &mt('None');
22370: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22371: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22372: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22373: }
1.145 raeburn 22374: }
1.147 raeburn 22375: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22376: }
1.137 raeburn 22377: }
22378: }
1.147 raeburn 22379: $resulttext .= '</li>';
1.137 raeburn 22380: }
22381: }
1.147 raeburn 22382: } else {
22383: foreach my $type (@{$types{$prefix}}) {
22384: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22385: my ($newvalue,$notinuse);
1.147 raeburn 22386: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22387: if (ref($defaultshash{'usersessions'}{$prefix})) {
22388: if ($type eq 'version') {
22389: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22390: } else {
22391: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22392: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22393: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22394: }
22395: } else {
22396: $notinuse = 1;
1.147 raeburn 22397: }
1.145 raeburn 22398: }
22399: }
22400: }
1.147 raeburn 22401: if ($newvalue eq '') {
22402: if ($type eq 'version') {
22403: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22404: } elsif ($notinuse) {
22405: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22406: } else {
22407: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22408: }
1.145 raeburn 22409: } else {
1.147 raeburn 22410: if ($type eq 'version') {
1.344 raeburn 22411: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22412: }
22413: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22414: }
1.137 raeburn 22415: }
22416: }
22417: }
1.147 raeburn 22418: $resulttext .= '</ul>';
1.137 raeburn 22419: }
22420: }
1.261 raeburn 22421: if ($changes{'offloadnow'}) {
22422: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22423: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22424: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22425: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22426: $resulttext .= '<li>'.$lonhost.'</li>';
22427: }
22428: $resulttext .= '</ul>';
22429: } else {
1.371 raeburn 22430: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22431: }
22432: } else {
22433: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22434: }
22435: }
22436: if ($changes{'offloadoth'}) {
22437: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22438: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22439: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22440: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22441: $resulttext .= '<li>'.$lonhost.'</li>';
22442: }
22443: $resulttext .= '</ul>';
22444: } else {
22445: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22446: }
22447: } else {
1.371 raeburn 22448: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22449: }
22450: }
1.147 raeburn 22451: $resulttext .= '</ul>';
22452: } else {
22453: $resulttext = $nochgmsg;
1.137 raeburn 22454: }
22455: } else {
22456: $resulttext = '<span class="LC_error">'.
22457: &mt('An error occurred: [_1]',$putresult).'</span>';
22458: }
22459: } else {
1.147 raeburn 22460: $resulttext = $nochgmsg;
1.137 raeburn 22461: }
22462: return $resulttext;
22463: }
22464:
1.275 raeburn 22465: sub modify_ssl {
22466: my ($dom,$lastactref,%domconfig) = @_;
22467: my (%by_ip,%by_location,@intdoms,@instdoms);
22468: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22469: my @locations = sort(keys(%by_location));
22470: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22471: my (%defaultshash,%changes);
22472: my $action = 'ssl';
1.293 raeburn 22473: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22474: foreach my $prefix (@prefixes) {
22475: $defaultshash{$action}{$prefix} = {};
22476: }
22477: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22478: my $resulttext;
22479: my %iphost = &Apache::lonnet::get_iphost();
22480: my @reptypes = ('certreq','nocertreq');
22481: my @connecttypes = ('dom','intdom','other');
22482: my %types = (
1.293 raeburn 22483: connto => \@connecttypes,
22484: connfrom => \@connecttypes,
22485: replication => \@reptypes,
1.275 raeburn 22486: );
22487: foreach my $prefix (sort(keys(%types))) {
22488: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22489: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22490: my $value = 'yes';
22491: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22492: $value = $env{'form.'.$prefix.'_'.$type};
22493: }
1.335 raeburn 22494: if (ref($domconfig{$action}) eq 'HASH') {
22495: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22496: if ($domconfig{$action}{$prefix}{$type} ne '') {
22497: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22498: $changes{$prefix}{$type} = 1;
22499: }
22500: $defaultshash{$action}{$prefix}{$type} = $value;
22501: } else {
22502: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22503: $changes{$prefix}{$type} = 1;
22504: }
22505: } else {
22506: $defaultshash{$action}{$prefix}{$type} = $value;
22507: $changes{$prefix}{$type} = 1;
22508: }
22509: } else {
22510: $defaultshash{$action}{$prefix}{$type} = $value;
22511: $changes{$prefix}{$type} = 1;
22512: }
22513: if (($type eq 'dom') && (keys(%servers) == 1)) {
22514: delete($changes{$prefix}{$type});
22515: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22516: delete($changes{$prefix}{$type});
22517: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22518: delete($changes{$prefix}{$type});
22519: }
22520: } elsif ($prefix eq 'replication') {
22521: if (@locations > 0) {
22522: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22523: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22524: my @okvals;
22525: foreach my $val (@vals) {
22526: if ($val =~ /:/) {
22527: my @items = split(/:/,$val);
22528: foreach my $item (@items) {
22529: if (ref($by_location{$item}) eq 'ARRAY') {
22530: push(@okvals,$item);
22531: }
22532: }
22533: } else {
22534: if (ref($by_location{$val}) eq 'ARRAY') {
22535: push(@okvals,$val);
22536: }
22537: }
22538: }
22539: @okvals = sort(@okvals);
22540: if (ref($domconfig{$action}) eq 'HASH') {
22541: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22542: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22543: if ($inuse == 0) {
22544: $changes{$prefix}{$type} = 1;
22545: } else {
22546: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22547: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22548: if (@changed > 0) {
22549: $changes{$prefix}{$type} = 1;
22550: }
22551: }
22552: } else {
22553: if ($inuse == 1) {
22554: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22555: $changes{$prefix}{$type} = 1;
22556: }
22557: }
22558: } else {
22559: if ($inuse == 1) {
22560: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22561: $changes{$prefix}{$type} = 1;
22562: }
22563: }
22564: } else {
22565: if ($inuse == 1) {
22566: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22567: $changes{$prefix}{$type} = 1;
22568: }
22569: }
22570: }
22571: }
22572: }
22573: }
1.336 raeburn 22574: if (keys(%changes)) {
22575: foreach my $prefix (keys(%changes)) {
22576: if (ref($changes{$prefix}) eq 'HASH') {
22577: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22578: delete($changes{$prefix});
22579: }
22580: } else {
22581: delete($changes{$prefix});
22582: }
22583: }
22584: }
1.275 raeburn 22585: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22586: if (keys(%changes) > 0) {
22587: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22588: $dom);
22589: if ($putresult eq 'ok') {
22590: if (ref($defaultshash{$action}) eq 'HASH') {
22591: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22592: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22593: }
1.293 raeburn 22594: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22595: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22596: }
22597: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22598: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22599: }
22600: }
22601: my $cachetime = 24*60*60;
22602: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22603: if (ref($lastactref) eq 'HASH') {
22604: $lastactref->{'domdefaults'} = 1;
22605: }
22606: if (keys(%changes) > 0) {
22607: my %titles = &ssl_titles();
22608: $resulttext = &mt('Changes made:').'<ul>';
22609: foreach my $prefix (@prefixes) {
22610: if (ref($changes{$prefix}) eq 'HASH') {
22611: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22612: foreach my $type (@{$types{$prefix}}) {
22613: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22614: my ($newvalue,$notinuse);
1.275 raeburn 22615: if (ref($defaultshash{$action}) eq 'HASH') {
22616: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22617: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22618: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22619: } else {
22620: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22621: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22622: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22623: }
22624: } else {
22625: $notinuse = 1;
1.275 raeburn 22626: }
22627: }
22628: }
1.344 raeburn 22629: if ($notinuse) {
22630: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22631: } elsif ($newvalue eq '') {
1.275 raeburn 22632: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22633: } else {
22634: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22635: }
22636: }
22637: }
22638: }
22639: $resulttext .= '</ul>';
22640: }
22641: }
22642: } else {
22643: $resulttext = $nochgmsg;
22644: }
22645: } else {
22646: $resulttext = '<span class="LC_error">'.
22647: &mt('An error occurred: [_1]',$putresult).'</span>';
22648: }
22649: } else {
22650: $resulttext = $nochgmsg;
22651: }
22652: return $resulttext;
22653: }
22654:
1.279 raeburn 22655: sub modify_trust {
22656: my ($dom,$lastactref,%domconfig) = @_;
22657: my (%by_ip,%by_location,@intdoms,@instdoms);
22658: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22659: my @locations = sort(keys(%by_location));
22660: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
22661: my @types = ('exc','inc');
22662: my (%defaultshash,%changes);
22663: foreach my $prefix (@prefixes) {
22664: $defaultshash{'trust'}{$prefix} = {};
22665: }
22666: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22667: my $resulttext;
22668: foreach my $prefix (@prefixes) {
22669: foreach my $type (@types) {
22670: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22671: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22672: my @okvals;
22673: foreach my $val (@vals) {
22674: if ($val =~ /:/) {
22675: my @items = split(/:/,$val);
22676: foreach my $item (@items) {
22677: if (ref($by_location{$item}) eq 'ARRAY') {
22678: push(@okvals,$item);
22679: }
22680: }
22681: } else {
22682: if (ref($by_location{$val}) eq 'ARRAY') {
22683: push(@okvals,$val);
22684: }
22685: }
22686: }
22687: @okvals = sort(@okvals);
22688: if (ref($domconfig{'trust'}) eq 'HASH') {
22689: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
22690: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22691: if ($inuse == 0) {
22692: $changes{$prefix}{$type} = 1;
22693: } else {
22694: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22695: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
22696: if (@changed > 0) {
22697: $changes{$prefix}{$type} = 1;
22698: }
22699: }
22700: } else {
22701: if ($inuse == 1) {
22702: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22703: $changes{$prefix}{$type} = 1;
22704: }
22705: }
22706: } else {
22707: if ($inuse == 1) {
22708: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22709: $changes{$prefix}{$type} = 1;
22710: }
22711: }
22712: } else {
22713: if ($inuse == 1) {
22714: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22715: $changes{$prefix}{$type} = 1;
22716: }
22717: }
22718: }
22719: }
22720: my $nochgmsg = &mt('No changes made to trust settings.');
22721: if (keys(%changes) > 0) {
22722: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22723: $dom);
22724: if ($putresult eq 'ok') {
22725: if (ref($defaultshash{'trust'}) eq 'HASH') {
22726: foreach my $prefix (@prefixes) {
22727: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
22728: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
22729: }
22730: }
22731: }
22732: my $cachetime = 24*60*60;
22733: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 22734: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 22735: if (ref($lastactref) eq 'HASH') {
22736: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 22737: $lastactref->{'trust'} = 1;
1.279 raeburn 22738: }
22739: if (keys(%changes) > 0) {
22740: my %lt = &trust_titles();
22741: $resulttext = &mt('Changes made:').'<ul>';
22742: foreach my $prefix (@prefixes) {
22743: if (ref($changes{$prefix}) eq 'HASH') {
22744: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22745: foreach my $type (@types) {
22746: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22747: my ($newvalue,$notinuse);
1.279 raeburn 22748: if (ref($defaultshash{'trust'}) eq 'HASH') {
22749: if (ref($defaultshash{'trust'}{$prefix})) {
22750: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22751: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
22752: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
22753: }
1.344 raeburn 22754: } else {
22755: $notinuse = 1;
1.279 raeburn 22756: }
22757: }
22758: }
1.344 raeburn 22759: if ($notinuse) {
22760: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
22761: } elsif ($newvalue eq '') {
1.279 raeburn 22762: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22763: } else {
22764: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
22765: }
22766: }
22767: }
22768: $resulttext .= '</ul>';
22769: }
22770: }
22771: $resulttext .= '</ul>';
22772: } else {
22773: $resulttext = $nochgmsg;
22774: }
22775: } else {
22776: $resulttext = '<span class="LC_error">'.
22777: &mt('An error occurred: [_1]',$putresult).'</span>';
22778: }
22779: } else {
22780: $resulttext = $nochgmsg;
22781: }
22782: return $resulttext;
22783: }
22784:
1.150 raeburn 22785: sub modify_loadbalancing {
22786: my ($dom,%domconfig) = @_;
22787: my $primary_id = &Apache::lonnet::domain($dom,'primary');
22788: my $intdom = &Apache::lonnet::internet_dom($primary_id);
22789: my ($othertitle,$usertypes,$types) =
22790: &Apache::loncommon::sorted_inst_types($dom);
22791: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 22792: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 22793: my @sparestypes = ('primary','default');
22794: my %typetitles = &sparestype_titles();
22795: my $resulttext;
1.342 raeburn 22796: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 22797: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22798: %existing = %{$domconfig{'loadbalancing'}};
22799: }
22800: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 22801: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 22802: my ($saveloadbalancing,%defaultshash,%changes);
22803: my ($alltypes,$othertypes,$titles) =
22804: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
22805: my %ruletitles = &offloadtype_text();
22806: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
22807: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
22808: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
22809: if ($balancer eq '') {
22810: next;
22811: }
1.210 raeburn 22812: if (!exists($servers{$balancer})) {
1.171 raeburn 22813: if (exists($currbalancer{$balancer})) {
22814: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 22815: }
1.171 raeburn 22816: next;
22817: }
22818: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
22819: push(@{$changes{'delete'}},$balancer);
22820: next;
22821: }
22822: if (!exists($currbalancer{$balancer})) {
22823: push(@{$changes{'add'}},$balancer);
22824: }
22825: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
22826: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
22827: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
22828: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22829: $saveloadbalancing = 1;
22830: }
22831: foreach my $sparetype (@sparestypes) {
22832: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
22833: my @offloadto;
22834: foreach my $target (@targets) {
22835: if (($servers{$target}) && ($target ne $balancer)) {
22836: if ($sparetype eq 'default') {
22837: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
22838: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 22839: }
22840: }
1.171 raeburn 22841: unless(grep(/^\Q$target\E$/,@offloadto)) {
22842: push(@offloadto,$target);
22843: }
1.150 raeburn 22844: }
22845: }
1.284 raeburn 22846: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
22847: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
22848: push(@offloadto,$balancer);
22849: }
22850: }
22851: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 22852: }
1.342 raeburn 22853: if ($env{'form.loadbalancing_cookie_'.$i}) {
22854: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 22855: if (exists($currbalancer{$balancer})) {
1.342 raeburn 22856: unless ($currcookies{$balancer}) {
22857: $changes{'curr'}{$balancer}{'cookie'} = 1;
22858: }
22859: }
22860: } elsif (exists($currbalancer{$balancer})) {
22861: if ($currcookies{$balancer}) {
22862: $changes{'curr'}{$balancer}{'cookie'} = 1;
22863: }
22864: }
1.171 raeburn 22865: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 22866: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22867: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
22868: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 22869: if (@targetdiffs > 0) {
1.171 raeburn 22870: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22871: }
1.171 raeburn 22872: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22873: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22874: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22875: }
22876: }
22877: }
22878: } else {
1.171 raeburn 22879: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 22880: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22881: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22882: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22883: $changes{'curr'}{$balancer}{'targets'} = 1;
22884: }
1.150 raeburn 22885: }
22886: }
1.210 raeburn 22887: }
1.150 raeburn 22888: }
22889: my $ishomedom;
1.171 raeburn 22890: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
22891: $ishomedom = 1;
1.150 raeburn 22892: }
22893: if (ref($alltypes) eq 'ARRAY') {
22894: foreach my $type (@{$alltypes}) {
22895: my $rule;
1.210 raeburn 22896: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 22897: (!$ishomedom)) {
1.171 raeburn 22898: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
22899: }
22900: if ($rule eq 'specific') {
1.255 raeburn 22901: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 22902: if (exists($servers{$specifiedhost})) {
1.255 raeburn 22903: $rule = $specifiedhost;
22904: }
1.150 raeburn 22905: }
1.171 raeburn 22906: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
22907: if (ref($currrules{$balancer}) eq 'HASH') {
22908: if ($rule ne $currrules{$balancer}{$type}) {
22909: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22910: }
22911: } elsif ($rule ne '') {
1.171 raeburn 22912: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22913: }
22914: }
22915: }
1.171 raeburn 22916: }
22917: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
22918: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
22919: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
22920: $defaultshash{'loadbalancing'} = {};
22921: }
22922: my $putresult = &Apache::lonnet::put_dom('configuration',
22923: \%defaultshash,$dom);
22924: if ($putresult eq 'ok') {
22925: if (keys(%changes) > 0) {
1.252 raeburn 22926: my %toupdate;
1.171 raeburn 22927: if (ref($changes{'delete'}) eq 'ARRAY') {
22928: foreach my $balancer (sort(@{$changes{'delete'}})) {
22929: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 22930: $toupdate{$balancer} = 1;
1.150 raeburn 22931: }
1.171 raeburn 22932: }
22933: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 22934: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 22935: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 22936: $toupdate{$balancer} = 1;
1.171 raeburn 22937: }
22938: }
22939: if (ref($changes{'curr'}) eq 'HASH') {
22940: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 22941: $toupdate{$balancer} = 1;
1.171 raeburn 22942: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
22943: if ($changes{'curr'}{$balancer}{'targets'}) {
22944: my %offloadstr;
22945: foreach my $sparetype (@sparestypes) {
22946: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22947: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22948: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
22949: }
22950: }
1.150 raeburn 22951: }
1.171 raeburn 22952: if (keys(%offloadstr) == 0) {
22953: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 22954: } else {
1.171 raeburn 22955: my $showoffload;
22956: foreach my $sparetype (@sparestypes) {
22957: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
22958: if (defined($offloadstr{$sparetype})) {
22959: $showoffload .= $offloadstr{$sparetype};
22960: } else {
22961: $showoffload .= &mt('None');
22962: }
22963: $showoffload .= (' 'x3);
22964: }
22965: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 22966: }
22967: }
22968: }
1.171 raeburn 22969: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
22970: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
22971: foreach my $type (@{$alltypes}) {
22972: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
22973: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
22974: my $balancetext;
22975: if ($rule eq '') {
22976: $balancetext = $ruletitles{'default'};
1.209 raeburn 22977: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 22978: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 22979: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 22980: foreach my $sparetype (@sparestypes) {
22981: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22982: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
22983: }
22984: }
1.253 raeburn 22985: foreach my $item (@{$alltypes}) {
22986: next if ($item =~ /^_LC_ipchange/);
22987: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
22988: if ($hasrule eq 'homeserver') {
22989: map { $toupdate{$_} = 1; } (keys(%libraryservers));
22990: } else {
22991: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
22992: if ($servers{$hasrule}) {
22993: $toupdate{$hasrule} = 1;
22994: }
22995: }
22996: }
22997: }
1.254 raeburn 22998: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
22999: $balancetext = $ruletitles{$rule};
23000: } else {
23001: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23002: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23003: if ($receiver) {
23004: $toupdate{$receiver};
23005: }
23006: }
23007: } else {
23008: $balancetext = $ruletitles{$rule};
1.252 raeburn 23009: }
1.171 raeburn 23010: } else {
23011: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23012: }
1.210 raeburn 23013: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23014: }
23015: }
23016: }
23017: }
1.342 raeburn 23018: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23019: if ($currcookies{$balancer}) {
23020: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23021: $balancer).'</li>';
23022: } else {
23023: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23024: $balancer).'</li>';
23025: }
1.342 raeburn 23026: }
1.375 raeburn 23027: }
23028: }
23029: if (keys(%toupdate)) {
23030: my %thismachine;
23031: my $updatedhere;
23032: my $cachetime = 60*60*24;
23033: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23034: foreach my $lonhost (keys(%toupdate)) {
23035: if ($thismachine{$lonhost}) {
23036: unless ($updatedhere) {
23037: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23038: $defaultshash{'loadbalancing'},
23039: $cachetime);
23040: $updatedhere = 1;
1.252 raeburn 23041: }
1.375 raeburn 23042: } else {
23043: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23044: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23045: }
1.150 raeburn 23046: }
1.171 raeburn 23047: }
23048: if ($resulttext ne '') {
23049: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23050: } else {
23051: $resulttext = $nochgmsg;
23052: }
23053: } else {
1.171 raeburn 23054: $resulttext = $nochgmsg;
1.150 raeburn 23055: }
23056: } else {
1.171 raeburn 23057: $resulttext = '<span class="LC_error">'.
23058: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23059: }
23060: } else {
1.171 raeburn 23061: $resulttext = $nochgmsg;
1.150 raeburn 23062: }
23063: return $resulttext;
23064: }
23065:
1.48 raeburn 23066: sub recurse_check {
23067: my ($chkcats,$categories,$depth,$name) = @_;
23068: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23069: my $chg = 0;
23070: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23071: my $category = $chkcats->[$depth]{$name}[$j];
23072: my $item;
23073: if ($category eq '') {
23074: $chg ++;
23075: } else {
23076: my $deeper = $depth + 1;
23077: $item = &escape($category).':'.&escape($name).':'.$depth;
23078: if ($chg) {
23079: $categories->{$item} -= $chg;
23080: }
23081: &recurse_check($chkcats,$categories,$deeper,$category);
23082: $deeper --;
23083: }
23084: }
23085: }
23086: return;
23087: }
23088:
23089: sub recurse_cat_deletes {
23090: my ($item,$coursecategories,$deletions) = @_;
23091: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23092: my $subdepth = $depth + 1;
23093: if (ref($coursecategories) eq 'HASH') {
23094: foreach my $subitem (keys(%{$coursecategories})) {
23095: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23096: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23097: delete($coursecategories->{$subitem});
23098: $deletions->{$subitem} = 1;
23099: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23100: }
1.48 raeburn 23101: }
23102: }
23103: return;
23104: }
23105:
1.125 raeburn 23106: sub active_dc_picker {
1.191 raeburn 23107: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23108: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23109: my @domcoord = keys(%domcoords);
23110: if (keys(%currhash)) {
23111: foreach my $dc (keys(%currhash)) {
23112: unless (exists($domcoords{$dc})) {
23113: push(@domcoord,$dc);
23114: }
23115: }
23116: }
23117: @domcoord = sort(@domcoord);
1.210 raeburn 23118: my $numdcs = scalar(@domcoord);
1.191 raeburn 23119: my $rows = 0;
23120: my $table;
1.125 raeburn 23121: if ($numdcs > 1) {
1.191 raeburn 23122: $table = '<table>';
23123: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23124: my $rem = $i%($numinrow);
23125: if ($rem == 0) {
23126: if ($i > 0) {
1.191 raeburn 23127: $table .= '</tr>';
1.125 raeburn 23128: }
1.191 raeburn 23129: $table .= '<tr>';
23130: $rows ++;
1.125 raeburn 23131: }
1.191 raeburn 23132: my $check = '';
23133: if ($inputtype eq 'radio') {
23134: if (keys(%currhash) == 0) {
23135: if (!$i) {
23136: $check = ' checked="checked"';
23137: }
23138: } elsif (exists($currhash{$domcoord[$i]})) {
23139: $check = ' checked="checked"';
23140: }
23141: } else {
23142: if (exists($currhash{$domcoord[$i]})) {
23143: $check = ' checked="checked"';
1.125 raeburn 23144: }
23145: }
1.191 raeburn 23146: if ($i == @domcoord - 1) {
1.125 raeburn 23147: my $colsleft = $numinrow - $rem;
23148: if ($colsleft > 1) {
1.191 raeburn 23149: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23150: } else {
1.191 raeburn 23151: $table .= '<td class="LC_left_item">';
1.125 raeburn 23152: }
23153: } else {
1.191 raeburn 23154: $table .= '<td class="LC_left_item">';
23155: }
23156: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23157: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23158: $table .= '<span class="LC_nobreak"><label>'.
23159: '<input type="'.$inputtype.'" name="'.$name.'"'.
23160: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23161: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23162: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23163: }
1.219 raeburn 23164: $table .= '</label></span></td>';
1.191 raeburn 23165: }
23166: $table .= '</tr></table>';
23167: } elsif ($numdcs == 1) {
1.219 raeburn 23168: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23169: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23170: if ($inputtype eq 'radio') {
1.247 raeburn 23171: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23172: if ($user ne $dcname.':'.$dcdom) {
23173: $table .= ' ('.$dcname.':'.$dcdom.')';
23174: }
1.191 raeburn 23175: } else {
23176: my $check;
23177: if (exists($currhash{$domcoord[0]})) {
23178: $check = ' checked="checked"';
1.125 raeburn 23179: }
1.247 raeburn 23180: $table = '<span class="LC_nobreak"><label>'.
23181: '<input type="checkbox" name="'.$name.'" '.
23182: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23183: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23184: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23185: }
1.220 raeburn 23186: $table .= '</label></span>';
1.191 raeburn 23187: $rows ++;
1.125 raeburn 23188: }
23189: }
1.191 raeburn 23190: return ($numdcs,$table,$rows);
1.125 raeburn 23191: }
23192:
1.137 raeburn 23193: sub usersession_titles {
23194: return &Apache::lonlocal::texthash(
23195: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23196: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23197: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23198: version => 'LON-CAPA version requirement',
1.138 raeburn 23199: excludedomain => 'Allow all, but exclude specific domains',
23200: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23201: primary => 'Primary (checked first)',
1.154 raeburn 23202: default => 'Default',
1.137 raeburn 23203: );
23204: }
23205:
1.152 raeburn 23206: sub id_for_thisdom {
23207: my (%servers) = @_;
23208: my %altids;
23209: foreach my $server (keys(%servers)) {
23210: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23211: if ($serverhome ne $server) {
23212: $altids{$serverhome} = $server;
23213: }
23214: }
23215: return %altids;
23216: }
23217:
1.150 raeburn 23218: sub count_servers {
23219: my ($currbalancer,%servers) = @_;
23220: my (@spares,$numspares);
23221: foreach my $lonhost (sort(keys(%servers))) {
23222: next if ($currbalancer eq $lonhost);
23223: push(@spares,$lonhost);
23224: }
23225: if ($currbalancer) {
23226: $numspares = scalar(@spares);
23227: } else {
23228: $numspares = scalar(@spares) - 1;
23229: }
23230: return ($numspares,@spares);
23231: }
23232:
23233: sub lonbalance_targets_js {
1.171 raeburn 23234: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23235: my $select = &mt('Select');
23236: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23237: if (ref($servers) eq 'HASH') {
23238: $alltargets = join("','",sort(keys(%{$servers})));
23239: my @homedoms;
23240: foreach my $server (sort(keys(%{$servers}))) {
23241: if (&Apache::lonnet::host_domain($server) eq $dom) {
23242: push(@homedoms,'1');
23243: } else {
23244: push(@homedoms,'0');
23245: }
23246: }
23247: $allishome = join("','",@homedoms);
23248: }
23249: if (ref($types) eq 'ARRAY') {
23250: if (@{$types} > 0) {
23251: @alltypes = @{$types};
23252: }
23253: }
23254: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23255: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23256: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23257: if (ref($settings) eq 'HASH') {
23258: %existing = %{$settings};
23259: }
23260: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23261: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23262: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23263: return <<"END";
23264:
23265: <script type="text/javascript">
23266: // <![CDATA[
23267:
1.171 raeburn 23268: currBalancers = new Array('$balancers');
23269:
23270: function toggleTargets(balnum) {
23271: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23272: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23273: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23274: var prevbalancer = prevhostitem.value;
23275: var baltotal = document.getElementById('loadbalancing_total').value;
23276: prevhostitem.value = balancer;
23277: if (prevbalancer != '') {
23278: var prevIdx = currBalancers.indexOf(prevbalancer);
23279: if (prevIdx != -1) {
23280: currBalancers.splice(prevIdx,1);
23281: }
23282: }
1.150 raeburn 23283: if (balancer == '') {
1.171 raeburn 23284: hideSpares(balnum);
1.150 raeburn 23285: } else {
1.171 raeburn 23286: var currIdx = currBalancers.indexOf(balancer);
23287: if (currIdx == -1) {
23288: currBalancers.push(balancer);
23289: }
1.150 raeburn 23290: var homedoms = new Array('$allishome');
1.171 raeburn 23291: var ishomedom = homedoms[lonhostitem.selectedIndex];
23292: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23293: }
1.171 raeburn 23294: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23295: return;
23296: }
23297:
1.171 raeburn 23298: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23299: var alltargets = new Array('$alltargets');
23300: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23301: var offloadtypes = new Array('primary','default');
23302:
1.171 raeburn 23303: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23304: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23305:
1.151 raeburn 23306: for (var i=0; i<offloadtypes.length; i++) {
23307: var count = 0;
23308: for (var j=0; j<alltargets.length; j++) {
23309: if (alltargets[j] != balancer) {
1.171 raeburn 23310: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23311: item.value = alltargets[j];
23312: item.style.textAlign='left';
23313: item.style.textFace='normal';
23314: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23315: if (currBalancers.indexOf(alltargets[j]) == -1) {
23316: item.disabled = '';
23317: } else {
23318: item.disabled = 'disabled';
23319: item.checked = false;
23320: }
1.151 raeburn 23321: count ++;
23322: }
1.150 raeburn 23323: }
23324: }
1.151 raeburn 23325: for (var k=0; k<insttypes.length; k++) {
23326: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23327: if (ishomedom == 1) {
1.171 raeburn 23328: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23329: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23330: } else {
1.171 raeburn 23331: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23332: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23333: }
23334: } else {
1.171 raeburn 23335: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23336: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23337: }
1.151 raeburn 23338: if ((insttypes[k] != '_LC_external') &&
23339: ((insttypes[k] != '_LC_internetdom') ||
23340: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23341: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23342: item.options.length = 0;
23343: item.options[0] = new Option("","",true,true);
1.210 raeburn 23344: var idx = 0;
1.151 raeburn 23345: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23346: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23347: idx ++;
23348: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23349: }
23350: }
23351: }
23352: }
23353: return;
23354: }
23355:
1.171 raeburn 23356: function hideSpares(balnum) {
1.150 raeburn 23357: var alltargets = new Array('$alltargets');
23358: var insttypes = new Array('$allinsttypes');
23359: var offloadtypes = new Array('primary','default');
23360:
1.171 raeburn 23361: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23362: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23363:
23364: var total = alltargets.length - 1;
23365: for (var i=0; i<offloadtypes; i++) {
23366: for (var j=0; j<total; j++) {
1.171 raeburn 23367: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23368: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23369: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23370: }
1.150 raeburn 23371: }
23372: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23373: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23374: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23375: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23376: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23377: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23378: }
23379: }
23380: return;
23381: }
23382:
1.171 raeburn 23383: function checkOffloads(item,balnum,type) {
1.150 raeburn 23384: var alltargets = new Array('$alltargets');
23385: var offloadtypes = new Array('primary','default');
23386: if (item.checked) {
23387: var total = alltargets.length - 1;
23388: var other;
23389: if (type == offloadtypes[0]) {
1.151 raeburn 23390: other = offloadtypes[1];
1.150 raeburn 23391: } else {
1.151 raeburn 23392: other = offloadtypes[0];
1.150 raeburn 23393: }
23394: for (var i=0; i<total; i++) {
1.171 raeburn 23395: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23396: if (server == item.value) {
1.171 raeburn 23397: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23398: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23399: }
23400: }
23401: }
23402: }
23403: return;
23404: }
23405:
1.171 raeburn 23406: function singleServerToggle(balnum,type) {
23407: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23408: if (offloadtoSelIdx == 0) {
1.171 raeburn 23409: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23410: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23411:
23412: } else {
1.171 raeburn 23413: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23414: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23415: }
23416: return;
23417: }
23418:
1.171 raeburn 23419: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23420: if (type == '_LC_external') {
1.171 raeburn 23421: return;
1.150 raeburn 23422: }
1.171 raeburn 23423: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23424: for (var i=0; i<typesRules.length; i++) {
23425: if (formname.elements[typesRules[i]].checked) {
23426: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23427: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23428: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23429: } else {
1.171 raeburn 23430: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23431: }
23432: }
23433: }
23434: return;
23435: }
23436:
23437: function balancerDeleteChange(balnum) {
23438: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23439: var baltotal = document.getElementById('loadbalancing_total').value;
23440: var addtarget;
23441: var removetarget;
23442: var action = 'delete';
23443: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23444: var lonhost = hostitem.value;
23445: var currIdx = currBalancers.indexOf(lonhost);
23446: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23447: if (currIdx != -1) {
23448: currBalancers.splice(currIdx,1);
23449: }
23450: addtarget = lonhost;
23451: } else {
23452: if (currIdx == -1) {
23453: currBalancers.push(lonhost);
23454: }
23455: removetarget = lonhost;
23456: action = 'undelete';
23457: }
23458: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23459: }
23460: return;
23461: }
23462:
23463: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23464: if (baltotal > 1) {
23465: var offloadtypes = new Array('primary','default');
23466: var alltargets = new Array('$alltargets');
23467: var insttypes = new Array('$allinsttypes');
23468: for (var i=0; i<baltotal; i++) {
23469: if (i != balnum) {
23470: for (var j=0; j<offloadtypes.length; j++) {
23471: var total = alltargets.length - 1;
23472: for (var k=0; k<total; k++) {
23473: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23474: var server = serveritem.value;
23475: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23476: if (server == addtarget) {
23477: serveritem.disabled = '';
23478: }
23479: }
23480: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23481: if (server == removetarget) {
23482: serveritem.disabled = 'disabled';
23483: serveritem.checked = false;
23484: }
23485: }
23486: }
23487: }
23488: for (var j=0; j<insttypes.length; j++) {
23489: if (insttypes[j] != '_LC_external') {
23490: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23491: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23492: var currSel = singleserver.selectedIndex;
23493: var currVal = singleserver.options[currSel].value;
23494: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23495: var numoptions = singleserver.options.length;
23496: var needsnew = 1;
23497: for (var k=0; k<numoptions; k++) {
23498: if (singleserver.options[k] == addtarget) {
23499: needsnew = 0;
23500: break;
23501: }
23502: }
23503: if (needsnew == 1) {
23504: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23505: }
23506: }
23507: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23508: singleserver.options.length = 0;
23509: if ((currVal) && (currVal != removetarget)) {
23510: singleserver.options[0] = new Option("","",false,false);
23511: } else {
23512: singleserver.options[0] = new Option("","",true,true);
23513: }
23514: var idx = 0;
23515: for (var m=0; m<alltargets.length; m++) {
23516: if (currBalancers.indexOf(alltargets[m]) == -1) {
23517: idx ++;
23518: if (currVal == alltargets[m]) {
23519: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23520: } else {
23521: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23522: }
23523: }
23524: }
23525: }
23526: }
23527: }
23528: }
1.150 raeburn 23529: }
23530: }
23531: }
23532: return;
23533: }
23534:
1.152 raeburn 23535: // ]]>
23536: </script>
23537:
23538: END
23539: }
23540:
23541: sub new_spares_js {
23542: my @sparestypes = ('primary','default');
23543: my $types = join("','",@sparestypes);
23544: my $select = &mt('Select');
23545: return <<"END";
23546:
23547: <script type="text/javascript">
23548: // <![CDATA[
23549:
23550: function updateNewSpares(formname,lonhost) {
23551: var types = new Array('$types');
23552: var include = new Array();
23553: var exclude = new Array();
23554: for (var i=0; i<types.length; i++) {
23555: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23556: for (var j=0; j<spareboxes.length; j++) {
23557: if (formname.elements[spareboxes[j]].checked) {
23558: exclude.push(formname.elements[spareboxes[j]].value);
23559: } else {
23560: include.push(formname.elements[spareboxes[j]].value);
23561: }
23562: }
23563: }
23564: for (var i=0; i<types.length; i++) {
23565: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23566: var selIdx = newSpare.selectedIndex;
23567: var currnew = newSpare.options[selIdx].value;
23568: var okSpares = new Array();
23569: for (var j=0; j<newSpare.options.length; j++) {
23570: var possible = newSpare.options[j].value;
23571: if (possible != '') {
23572: if (exclude.indexOf(possible) == -1) {
23573: okSpares.push(possible);
23574: } else {
23575: if (currnew == possible) {
23576: selIdx = 0;
23577: }
23578: }
23579: }
23580: }
23581: for (var k=0; k<include.length; k++) {
23582: if (okSpares.indexOf(include[k]) == -1) {
23583: okSpares.push(include[k]);
23584: }
23585: }
23586: okSpares.sort();
23587: newSpare.options.length = 0;
23588: if (selIdx == 0) {
23589: newSpare.options[0] = new Option("$select","",true,true);
23590: } else {
23591: newSpare.options[0] = new Option("$select","",false,false);
23592: }
23593: for (var m=0; m<okSpares.length; m++) {
23594: var idx = m+1;
23595: var selThis = 0;
23596: if (selIdx != 0) {
23597: if (okSpares[m] == currnew) {
23598: selThis = 1;
23599: }
23600: }
23601: if (selThis == 1) {
23602: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23603: } else {
23604: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23605: }
23606: }
23607: }
23608: return;
23609: }
23610:
23611: function checkNewSpares(lonhost,type) {
23612: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23613: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23614: if (chosen != '') {
1.152 raeburn 23615: var othertype;
23616: var othernewSpare;
23617: if (type == 'primary') {
23618: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23619: }
23620: if (type == 'default') {
23621: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23622: }
23623: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23624: othernewSpare.selectedIndex = 0;
23625: }
23626: }
23627: return;
23628: }
23629:
23630: // ]]>
23631: </script>
23632:
23633: END
23634:
23635: }
23636:
23637: sub common_domprefs_js {
23638: return <<"END";
23639:
23640: <script type="text/javascript">
23641: // <![CDATA[
23642:
1.150 raeburn 23643: function getIndicesByName(formname,item) {
1.152 raeburn 23644: var group = new Array();
1.150 raeburn 23645: for (var i=0;i<formname.elements.length;i++) {
23646: if (formname.elements[i].name == item) {
1.152 raeburn 23647: group.push(formname.elements[i].id);
1.150 raeburn 23648: }
23649: }
1.152 raeburn 23650: return group;
1.150 raeburn 23651: }
23652:
23653: // ]]>
23654: </script>
23655:
23656: END
1.152 raeburn 23657:
1.150 raeburn 23658: }
23659:
1.165 raeburn 23660: sub recaptcha_js {
23661: my %lt = &captcha_phrases();
23662: return <<"END";
23663:
23664: <script type="text/javascript">
23665: // <![CDATA[
23666:
23667: function updateCaptcha(caller,context) {
23668: var privitem;
23669: var pubitem;
23670: var privtext;
23671: var pubtext;
1.269 raeburn 23672: var versionitem;
23673: var versiontext;
1.165 raeburn 23674: if (document.getElementById(context+'_recaptchapub')) {
23675: pubitem = document.getElementById(context+'_recaptchapub');
23676: } else {
23677: return;
23678: }
23679: if (document.getElementById(context+'_recaptchapriv')) {
23680: privitem = document.getElementById(context+'_recaptchapriv');
23681: } else {
23682: return;
23683: }
23684: if (document.getElementById(context+'_recaptchapubtxt')) {
23685: pubtext = document.getElementById(context+'_recaptchapubtxt');
23686: } else {
23687: return;
23688: }
23689: if (document.getElementById(context+'_recaptchaprivtxt')) {
23690: privtext = document.getElementById(context+'_recaptchaprivtxt');
23691: } else {
23692: return;
23693: }
1.269 raeburn 23694: if (document.getElementById(context+'_recaptchaversion')) {
23695: versionitem = document.getElementById(context+'_recaptchaversion');
23696: } else {
23697: return;
23698: }
23699: if (document.getElementById(context+'_recaptchavertxt')) {
23700: versiontext = document.getElementById(context+'_recaptchavertxt');
23701: } else {
23702: return;
23703: }
1.165 raeburn 23704: if (caller.checked) {
23705: if (caller.value == 'recaptcha') {
23706: pubitem.type = 'text';
23707: privitem.type = 'text';
23708: pubitem.size = '40';
23709: privitem.size = '40';
23710: pubtext.innerHTML = "$lt{'pub'}";
23711: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 23712: versionitem.type = 'text';
23713: versionitem.size = '3';
1.289 raeburn 23714: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 23715: } else {
23716: pubitem.type = 'hidden';
23717: privitem.type = 'hidden';
1.269 raeburn 23718: versionitem.type = 'hidden';
1.165 raeburn 23719: pubtext.innerHTML = '';
23720: privtext.innerHTML = '';
1.269 raeburn 23721: versiontext.innerHTML = '';
1.165 raeburn 23722: }
23723: }
23724: return;
23725: }
23726:
23727: // ]]>
23728: </script>
23729:
23730: END
23731:
23732: }
23733:
1.236 raeburn 23734: sub toggle_display_js {
1.192 raeburn 23735: return <<"END";
23736:
23737: <script type="text/javascript">
23738: // <![CDATA[
23739:
1.236 raeburn 23740: function toggleDisplay(domForm,caller) {
23741: if (document.getElementById(caller)) {
23742: var divitem = document.getElementById(caller);
23743: var optionsElement = domForm.coursecredits;
1.264 raeburn 23744: var checkval = 1;
23745: var dispval = 'block';
1.303 raeburn 23746: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 23747: if (caller == 'emailoptions') {
1.372 raeburn 23748: optionsElement = domForm.cancreate_email;
1.236 raeburn 23749: }
1.257 raeburn 23750: if (caller == 'studentsubmission') {
23751: optionsElement = domForm.postsubmit;
23752: }
1.264 raeburn 23753: if (caller == 'cloneinstcode') {
23754: optionsElement = domForm.canclone;
23755: checkval = 'instcode';
23756: }
1.303 raeburn 23757: if (selfcreateRegExp.test(caller)) {
23758: optionsElement = domForm.elements[caller];
23759: checkval = 'other';
23760: dispval = 'inline'
23761: }
1.236 raeburn 23762: if (optionsElement.length) {
1.192 raeburn 23763: var currval;
1.236 raeburn 23764: for (var i=0; i<optionsElement.length; i++) {
23765: if (optionsElement[i].checked) {
23766: currval = optionsElement[i].value;
1.192 raeburn 23767: }
23768: }
1.264 raeburn 23769: if (currval == checkval) {
23770: divitem.style.display = dispval;
1.192 raeburn 23771: } else {
1.236 raeburn 23772: divitem.style.display = 'none';
1.192 raeburn 23773: }
23774: }
23775: }
23776: return;
23777: }
23778:
23779: // ]]>
23780: </script>
23781:
23782: END
23783:
23784: }
23785:
1.165 raeburn 23786: sub captcha_phrases {
23787: return &Apache::lonlocal::texthash (
23788: priv => 'Private key',
23789: pub => 'Public key',
23790: original => 'original (CAPTCHA)',
23791: recaptcha => 'successor (ReCAPTCHA)',
23792: notused => 'unused',
1.289 raeburn 23793: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 23794: );
23795: }
23796:
1.205 raeburn 23797: sub devalidate_remote_domconfs {
1.212 raeburn 23798: my ($dom,$cachekeys) = @_;
23799: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 23800: my %servers = &Apache::lonnet::internet_dom_servers($dom);
23801: my %thismachine;
23802: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 23803: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 23804: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 23805: 'ipaccess','trust');
1.386 raeburn 23806: my %cache_by_lonhost;
23807: if (exists($cachekeys->{'samllanding'})) {
23808: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
23809: my %landing = %{$cachekeys->{'samllanding'}};
23810: my %domservers = &Apache::lonnet::get_servers($dom);
23811: if (keys(%domservers)) {
23812: foreach my $server (keys(%domservers)) {
23813: my @cached;
23814: next if ($thismachine{$server});
23815: if ($landing{$server}) {
23816: push(@cached,&escape('samllanding').':'.&escape($server));
23817: }
23818: if (@cached) {
23819: $cache_by_lonhost{$server} = \@cached;
23820: }
23821: }
23822: }
23823: }
23824: }
1.260 raeburn 23825: if (keys(%servers)) {
1.205 raeburn 23826: foreach my $server (keys(%servers)) {
23827: next if ($thismachine{$server});
1.212 raeburn 23828: my @cached;
23829: foreach my $name (@posscached) {
23830: if ($cachekeys->{$name}) {
1.388 raeburn 23831: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 23832: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 23833: foreach my $key (keys(%{$cachekeys->{$name}})) {
23834: push(@cached,&escape($name).':'.&escape($key));
23835: }
23836: }
23837: } else {
23838: push(@cached,&escape($name).':'.&escape($dom));
23839: }
1.212 raeburn 23840: }
23841: }
1.386 raeburn 23842: if ((exists($cache_by_lonhost{$server})) &&
23843: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
23844: push(@cached,@{$cache_by_lonhost{$server}});
23845: }
1.212 raeburn 23846: if (@cached) {
23847: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
23848: }
1.205 raeburn 23849: }
23850: }
23851: return;
23852: }
23853:
1.3 raeburn 23854: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>