Annotation of loncom/interface/domainprefs.pm, revision 1.432
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.432 ! raeburn 4: # $Id: domainprefs.pm,v 1.431 2023/11/07 11:50:56 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.430 raeburn 2428: @usertools = ('aboutme','blog','portfolio','portaccess','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.432 ! raeburn 6825: coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
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.432 ! raeburn 6838: crsauthor => 'Standard LON-CAPA problems can be created within a course/community (by type)',
1.192 raeburn 6839: );
1.198 raeburn 6840: my %staticdefaults = (
6841: anonsurvey_threshold => 10,
6842: uploadquota => 500,
1.428 raeburn 6843: coursequota => 20,
1.257 raeburn 6844: postsubmit => 60,
1.276 raeburn 6845: mysqltables => 172800,
1.422 raeburn 6846: domexttool => 1,
6847: exttool => 0,
1.432 ! raeburn 6848: crsauthor => 1,
1.198 raeburn 6849: );
1.139 raeburn 6850: if ($position eq 'top') {
1.257 raeburn 6851: %defaultchecked = (
6852: 'canuse_pdfforms' => 'off',
6853: 'uselcmath' => 'on',
6854: 'usejsme' => 'on',
1.398 raeburn 6855: 'inline_chem' => 'on',
1.289 raeburn 6856: 'canclone' => 'none',
1.257 raeburn 6857: );
1.398 raeburn 6858: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6859: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6860: if (ref($settings) eq 'HASH') {
6861: if ($settings->{'texengine'}) {
6862: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6863: $deftex = $settings->{'texengine'};
6864: }
6865: }
6866: }
6867: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6868: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6869: '<span class="LC_nobreak">'.$choices{'texengine'}.
6870: '</span></td><td class="LC_right_item">'.
6871: '<select name="texengine">'."\n";
6872: my %texoptions = (
6873: MathJax => 'MathJax',
6874: mimetex => &mt('Convert to Images'),
6875: tth => &mt('TeX to HTML'),
6876: );
6877: foreach my $renderer ('MathJax','mimetex','tth') {
6878: my $selected = '';
6879: if ($renderer eq $deftex) {
6880: $selected = ' selected="selected"';
6881: }
6882: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6883: }
6884: $mathdisp .= '</select></td></tr>'."\n";
6885: $itemcount ++;
1.139 raeburn 6886: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6887: \%choices,$itemcount);
1.314 raeburn 6888: $datatable = $mathdisp.$datatable;
1.264 raeburn 6889: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6890: $datatable .=
1.306 raeburn 6891: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6892: '<span class="LC_nobreak">'.$choices{'canclone'}.
6893: '</span></td><td class="LC_left_item">';
6894: my $currcanclone = 'none';
6895: my $onclick;
6896: my @cloneoptions = ('none','domain');
1.380 raeburn 6897: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6898: none => 'No additional course requesters',
6899: domain => "Any course requester in course's domain",
6900: instcode => 'Course requests for official courses ...',
6901: );
6902: my (%codedefaults,@code_order,@posscodes);
6903: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6904: \@code_order) eq 'ok') {
6905: if (@code_order > 0) {
6906: push(@cloneoptions,'instcode');
6907: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6908: }
6909: }
6910: if (ref($settings) eq 'HASH') {
6911: if ($settings->{'canclone'}) {
6912: if (ref($settings->{'canclone'}) eq 'HASH') {
6913: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6914: if (@code_order > 0) {
6915: $currcanclone = 'instcode';
6916: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6917: }
6918: }
6919: } elsif ($settings->{'canclone'} eq 'domain') {
6920: $currcanclone = $settings->{'canclone'};
6921: }
6922: }
1.289 raeburn 6923: }
1.264 raeburn 6924: foreach my $option (@cloneoptions) {
6925: my ($checked,$additional);
6926: if ($currcanclone eq $option) {
6927: $checked = ' checked="checked"';
6928: }
6929: if ($option eq 'instcode') {
6930: if (@code_order) {
6931: my $show = 'none';
6932: if ($checked) {
6933: $show = 'block';
6934: }
1.317 raeburn 6935: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6936: &mt('Institutional codes for new and cloned course have identical:').
6937: '<br />';
6938: foreach my $item (@code_order) {
6939: my $codechk;
6940: if ($checked) {
6941: if (grep(/^\Q$item\E$/,@posscodes)) {
6942: $codechk = ' checked="checked"';
6943: }
6944: }
6945: $additional .= '<label>'.
6946: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6947: $item.'</label>';
6948: }
6949: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6950: }
6951: }
6952: $datatable .=
6953: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6954: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6955: '</label> '.$additional.'</span><br />';
6956: }
6957: $datatable .= '</td>'.
6958: '</tr>';
6959: $itemcount ++;
1.139 raeburn 6960: } else {
6961: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 6962: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
6963: %deftimeout,%currmysql);
1.192 raeburn 6964: my $currusecredits = 0;
1.257 raeburn 6965: my $postsubmitclient = 1;
1.405 raeburn 6966: my $ltiauth = 0;
1.422 raeburn 6967: my %domexttool;
6968: my %exttool;
1.432 ! raeburn 6969: my %crsauthor;
1.271 raeburn 6970: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6971: if (ref($settings) eq 'HASH') {
1.404 raeburn 6972: if ($settings->{'ltiauth'}) {
6973: $ltiauth = 1;
1.405 raeburn 6974: }
1.422 raeburn 6975: if (ref($settings->{'domexttool'}) eq 'HASH') {
6976: foreach my $type (@types) {
6977: if ($settings->{'domexttool'}->{$type}) {
6978: $domexttool{$type} = ' checked="checked"';
6979: }
6980: }
6981: } else {
6982: foreach my $type (@types) {
6983: if ($staticdefaults{'domexttool'}) {
6984: $domexttool{$type} = ' checked="checked"';
6985: }
6986: }
6987: }
6988: if (ref($settings->{'exttool'}) eq 'HASH') {
6989: foreach my $type (@types) {
6990: if ($settings->{'exttool'}->{$type}) {
6991: $exttool{$type} = ' checked="checked"';
6992: }
6993: }
6994: }
1.432 ! raeburn 6995: if (ref($settings->{'crsauthor'}) eq 'HASH') {
! 6996: foreach my $type (@types) {
! 6997: if ($settings->{'crsauthor'}->{$type}) {
! 6998: $crsauthor{$type} = ' checked="checked"';
! 6999: }
! 7000: }
! 7001: } else {
! 7002: foreach my $type (@types) {
! 7003: if ($staticdefaults{'crsauthor'}) {
! 7004: $crsauthor{$type} = ' checked="checked"';
! 7005: }
! 7006: }
! 7007: }
1.139 raeburn 7008: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7009: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7010: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7011: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7012: }
7013: }
1.428 raeburn 7014: if (ref($settings->{'coursequota'}) eq 'HASH') {
7015: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7016: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7017: }
7018: }
1.192 raeburn 7019: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7020: foreach my $type (@types) {
7021: next if ($type eq 'community');
7022: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7023: if ($defcredits{$type} ne '') {
7024: $currusecredits = 1;
7025: }
7026: }
7027: }
7028: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7029: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7030: $postsubmitclient = 0;
7031: foreach my $type (@types) {
7032: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7033: }
7034: } else {
7035: foreach my $type (@types) {
7036: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7037: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7038: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7039: } else {
7040: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7041: }
7042: } else {
7043: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7044: }
7045: }
7046: }
7047: } else {
7048: foreach my $type (@types) {
7049: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7050: }
7051: }
1.276 raeburn 7052: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7053: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7054: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7055: }
7056: } else {
7057: foreach my $type (@types) {
7058: $currmysql{$type} = $staticdefaults{'mysqltables'};
7059: }
7060: }
1.258 raeburn 7061: } else {
7062: foreach my $type (@types) {
7063: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7064: if ($staticdefaults{'domexttool'}) {
7065: $domexttool{$type} = ' checked="checked"';
7066: }
1.432 ! raeburn 7067: if ($staticdefaults{'crsauthor'}) {
! 7068: $crsauthor{$type} = ' checked="checked"';
! 7069: }
1.258 raeburn 7070: }
1.139 raeburn 7071: }
7072: if (!$currdefresponder) {
1.198 raeburn 7073: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7074: } elsif ($currdefresponder < 1) {
7075: $currdefresponder = 1;
7076: }
1.198 raeburn 7077: foreach my $type (@types) {
7078: if ($curruploadquota{$type} eq '') {
7079: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7080: }
1.428 raeburn 7081: if ($currcoursequota{$type} eq '') {
7082: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7083: }
1.198 raeburn 7084: }
1.139 raeburn 7085: $datatable .=
1.192 raeburn 7086: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7087: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7088: '</span></td>'.
7089: '<td class="LC_right_item"><span class="LC_nobreak">'.
7090: '<input type="text" name="anonsurvey_threshold"'.
7091: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7092: '</td></tr>'."\n";
7093: $itemcount ++;
7094: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7095: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7096: $choices{'uploadquota'}.
7097: '</span></td>'.
1.306 raeburn 7098: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7099: '<table><tr>';
1.198 raeburn 7100: foreach my $type (@types) {
1.306 raeburn 7101: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7102: '<input type="text" name="uploadquota_'.$type.'"'.
7103: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7104: }
7105: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7106: $itemcount ++;
1.428 raeburn 7107: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7108: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7109: $choices{'coursequota'}.
7110: '</span></td>'.
7111: '<td style="text-align: right" class="LC_right_item">'.
7112: '<table><tr>';
7113: foreach my $type (@types) {
7114: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7115: '<input type="text" name="coursequota_'.$type.'"'.
7116: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7117: }
7118: $datatable .= '</tr></table></td></tr>'."\n";
7119: $itemcount ++;
1.236 raeburn 7120: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7121: my $display = 'none';
1.192 raeburn 7122: if ($currusecredits) {
7123: $display = 'block';
7124: }
7125: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7126: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7127: foreach my $type (@types) {
7128: next if ($type eq 'community');
1.306 raeburn 7129: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7130: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7131: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7132: }
7133: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7134: %defaultchecked = ('coursecredits' => 'off');
7135: @toggles = ('coursecredits');
7136: my $current = {
7137: 'coursecredits' => $currusecredits,
7138: };
7139: (my $table,$itemcount) =
7140: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7141: \%choices,$itemcount,$onclick,$additional,'left');
7142: $datatable .= $table;
7143: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7144: my $display = 'none';
7145: if ($postsubmitclient) {
7146: $display = 'block';
7147: }
7148: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7149: &mt('Number of seconds submit is disabled').'<br />'.
7150: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7151: '<table><tr>';
1.257 raeburn 7152: foreach my $type (@types) {
1.306 raeburn 7153: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7154: '<input type="text" name="'.$type.'_timeout" value="'.
7155: $deftimeout{$type}.'" size="5" /></td>';
7156: }
7157: $additional .= '</tr></table></div>'."\n";
7158: %defaultchecked = ('postsubmit' => 'on');
7159: @toggles = ('postsubmit');
1.280 raeburn 7160: $current = {
7161: 'postsubmit' => $postsubmitclient,
7162: };
1.257 raeburn 7163: ($table,$itemcount) =
7164: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7165: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7166: $datatable .= $table;
1.276 raeburn 7167: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7168: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7169: $choices{'mysqltables'}.
7170: '</span></td>'.
1.306 raeburn 7171: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7172: '<table><tr>';
7173: foreach my $type (@types) {
1.306 raeburn 7174: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7175: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7176: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7177: }
7178: $datatable .= '</tr></table></td></tr>'."\n";
7179: $itemcount ++;
1.404 raeburn 7180: %defaultchecked = ('ltiauth' => 'off');
7181: @toggles = ('ltiauth');
7182: $current = {
7183: 'ltiauth' => $ltiauth,
7184: };
7185: ($table,$itemcount) =
7186: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7187: \%choices,$itemcount,undef,undef,'left');
7188: $datatable .= $table;
1.422 raeburn 7189: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7190: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7191: $choices{'domexttool'}.
7192: '</span></td>'.
7193: '<td style="text-align: right" class="LC_right_item">'.
7194: '<table><tr>';
7195: foreach my $type (@types) {
7196: $datatable .= '<td style="text-align: left">'.
7197: '<span class="LC_nobreak">'.
7198: '<input type="checkbox" name="domexttool"'.
7199: ' value="'.$type.'"'.$domexttool{$type}.' />'.
7200: &mt($type).'</span></td>'."\n";
7201: }
7202: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7203: $itemcount ++;
1.422 raeburn 7204: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7205: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7206: $choices{'exttool'}.
7207: '</span></td>'.
7208: '<td style="text-align: right" class="LC_right_item">'.
7209: '<table><tr>';
7210: foreach my $type (@types) {
7211: $datatable .= '<td style="text-align: left">'.
7212: '<span class="LC_nobreak">'.
7213: '<input type="checkbox" name="exttool"'.
7214: ' value="'.$type.'"'.$exttool{$type}.' />'.
7215: &mt($type).'</span></td>'."\n";
7216: }
7217: $datatable .= '</tr></table></td></tr>'."\n";
1.432 ! raeburn 7218: $itemcount ++;
! 7219: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
! 7220: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
! 7221: $choices{'crsauthor'}.
! 7222: '</span></td>'.
! 7223: '<td style="text-align: right" class="LC_right_item">'.
! 7224: '<table><tr>';
! 7225: foreach my $type (@types) {
! 7226: $datatable .= '<td style="text-align: left">'.
! 7227: '<span class="LC_nobreak">'.
! 7228: '<input type="checkbox" name="crsauthor"'.
! 7229: ' value="'.$type.'"'.$crsauthor{$type}.' />'.
! 7230: &mt($type).'</span></td>'."\n";
! 7231: }
! 7232: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7233: }
1.192 raeburn 7234: $$rowtotal += $itemcount;
1.121 raeburn 7235: return $datatable;
1.118 jms 7236: }
7237:
1.429 raeburn 7238: sub print_authordefaults {
7239: my ($position,$dom,$settings,$rowtotal) = @_;
7240: my ($css_class,$datatable,%checkedon,%checkedoff);
7241: my $itemcount = 1;
7242: my %titles = &authordefaults_titles();
7243: if ($position eq 'top') {
7244: my %defaultchecked = (
7245: 'nocodemirror' => 'off',
7246: 'domcoordacc' => 'on',
7247: );
7248: my @toggles = ('nocodemirror','domcoordacc');
7249: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
7250: \%titles,$itemcount);
7251: my %staticdefaults = (
7252: 'copyright' => 'default',
7253: 'sourceavail' => 'closed',
7254: );
7255: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7256: my %currrights;
7257: foreach my $item ('copyright','sourceavail') {
7258: $currrights{$item} = $staticdefaults{$item};
7259: if (ref($settings) eq 'HASH') {
7260: if (exists($settings->{$item})) {
7261: $currrights{$item} = $settings->{$item};
7262: }
7263: }
7264: }
7265: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7266: '<span class="LC_nobreak">'.$titles{'copyright'}.
7267: '</span></td><td class="LC_right_item">'.
7268: &selectbox('copyright',$currrights{'copyright'},'',
7269: \&Apache::loncommon::copyrightdescription,
7270: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
7271: '</td></tr>'."\n";
7272: $itemcount ++;
7273: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7274: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7275: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
7276: '</span></td><td class="LC_right_item">'.
7277: &selectbox('sourceavail',$currrights{'sourceavail'},'',
7278: \&Apache::loncommon::source_copyrightdescription,
7279: (&Apache::loncommon::source_copyrightids)).
7280: '</td></tr>'."\n";
7281: } else {
7282: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7283: my $curreditors;
7284: my %staticdefaults = (
7285: editors => ['edit','xml'],
7286: authorquota => 500,
7287: webdav => 0,
7288: );
7289: my $curreditors = $staticdefaults{'editors'};
7290: if ((ref($settings) eq 'HASH') &&
7291: (ref($settings->{'editors'}) eq 'ARRAY')) {
7292: $curreditors = $settings->{'editors'};
7293: } else {
7294: $curreditors = $staticdefaults{'editors'};
7295: }
7296: my @editors = ('edit','xml','daxe');
7297: $datatable = '<tr'.$css_class.'>'."\n".
7298: '<td>'.$titles{'editors'}.'</td>'."\n".
7299: '<td class="LC_left_item">'."\n".
7300: '<span class="LC_nobreak">';
7301: foreach my $editor (@editors) {
7302: my $checked;
7303: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
7304: $checked = ' checked="checked"';
7305: }
7306: $datatable .= '<label>'.
7307: '<input type="checkbox" name="author_editors" '.
7308: $checked.' value="'.$editor.'" '.
7309: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
7310: $titles{$editor}.'</label> ';
7311: }
7312: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
7313: $itemcount ++;
7314: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7315: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7316: my @insttypes;
7317: if (ref($types) eq 'ARRAY') {
7318: @insttypes = @{$types};
7319: }
7320: my $typecount = 0;
7321: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
7322: my @items = ('webdav','authorquota');
7323: my %quotas;
7324: if (ref($domconf{'quotas'}) eq 'HASH') {
7325: %quotas = %{$domconf{'quotas'}};
7326: foreach my $item (@items) {
7327: if (ref($quotas{$item}) eq 'HASH') {
7328: foreach my $type (@insttypes,'default') {
7329: if ($item eq 'authorquota') {
7330: if ($quotas{$item}{$type} !~ /^\d+$/) {
7331: $quotas{$item}{$type} = $staticdefaults{$item};
7332: }
7333: } elsif ($item eq 'webdav') {
7334: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
7335: $quotas{$item}{$type} = $staticdefaults{$item};
7336: }
7337: }
7338: }
7339: } else {
7340: foreach my $type (@insttypes,'default') {
7341: $quotas{$item}{$type} = $staticdefaults{$item};
7342: }
7343: }
7344: }
7345: } else {
7346: foreach my $item (@items) {
7347: foreach my $type (@insttypes,'default') {
7348: $quotas{$item}{$type} = $staticdefaults{$item};
7349: }
7350: }
7351: }
7352: if (ref($usertypes) eq 'HASH') {
7353: my $numinrow = 4;
7354: my $onclick = '';
7355: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7356: $numinrow,$othertitle,'authorquota',
7357: \$itemcount,$onclick);
7358: $itemcount ++;
7359: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7360: $numinrow,$othertitle,'webdav',
7361: \$itemcount);
7362: $itemcount ++;
7363: }
7364: my $checkedno = ' checked="checked"';
7365: my ($checkedon,$checkedoff);
7366: if (ref($quotas{'webdav'}) eq 'HASH') {
7367: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
7368: if ($quotas{'webdav'}{'_LC_adv'}) {
7369: $checkedon = $checkedno;
7370: } else {
7371: $checkedoff = $checkedno;
7372: }
7373: undef($checkedno);
7374: }
7375: }
7376: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7377: $datatable .= '<tr'.$css_class.'>'.
7378: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
7379: $titles{'webdav_LC_adv_over'}.
7380: '</td>'.
7381: '<td class="LC_left_item">';
7382: foreach my $option ('none','off','on') {
7383: my ($text,$val,$checked);
7384: if ($option eq 'none') {
7385: $text = $titles{'none'};
7386: $val = '';
7387: $checked = $checkedno;
7388: } elsif ($option eq 'off') {
7389: $text = $titles{'overoff'};
7390: $val = 0;
7391: $checked = $checkedoff;
7392: } elsif ($option eq 'on') {
7393: $text = $titles{'overon'};
7394: $val = 1;
7395: $checked = $checkedon;
7396: }
7397: $datatable .= '<span class="LC_nobreak"><label>'.
7398: '<input type="radio" name="webdav_LC_adv"'.
7399: ' value="'.$val.'"'.$checked.' />'.
7400: $text.'</label></span> ';
7401: }
7402: $datatable .= '</td></tr>';
7403: $itemcount ++;
7404: }
7405: $$rowtotal += $itemcount;
7406: return $datatable;
7407: }
7408:
7409: sub authordefaults_titles {
7410: return &Apache::lonlocal::texthash(
7411: copyright => 'Copyright/Distribution',
7412: sourceavail => ' Source Available',
7413: editors => 'Available Editors',
7414: webdav => 'WebDAV',
7415: authorquota => 'Authoring Space quotas (MB)',
7416: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
7417: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
7418: edit => 'Standard editor (Edit)',
7419: xml => 'Text editor (EditXML)',
7420: daxe => 'Daxe editor (Daxe)',
7421: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
7422: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
7423: none => 'No override set',
7424: overon => 'Override -- webDAV on',
7425: overoff => 'Override -- webDAV off',
7426: );
7427: }
7428:
7429: sub selectbox {
7430: my ($name,$value,$readonly,$functionref,@idlist)=@_;
7431: my $selout = '<select name="'.$name.'">';
7432: foreach my $id (@idlist) {
7433: $selout.='<option value="'.$id.'"';
7434: if ($id eq $value) {
7435: $selout.=' selected="selected"';
7436: }
7437: if ($readonly) {
7438: $selout .= ' disabled="disabled"';
7439: }
7440: $selout.='>'.&{$functionref}($id).'</option>';
7441: }
7442: $selout.='</select>';
7443: return $selout;
7444: }
7445:
1.231 raeburn 7446: sub print_selfenrollment {
7447: my ($position,$dom,$settings,$rowtotal) = @_;
7448: my ($css_class,$datatable);
7449: my $itemcount = 1;
1.271 raeburn 7450: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7451: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7452: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7453: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7454: my @rows;
7455: my $key;
7456: if ($position eq 'top') {
7457: $key = 'admin';
7458: if (ref($rowsref) eq 'ARRAY') {
7459: @rows = @{$rowsref};
7460: }
7461: } elsif ($position eq 'middle') {
7462: $key = 'default';
7463: @rows = ('types','registered','approval','limit');
7464: }
7465: foreach my $row (@rows) {
7466: if (defined($titlesref->{$row})) {
7467: $itemcount ++;
7468: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7469: $datatable .= '<tr'.$css_class.'>'.
7470: '<td>'.$titlesref->{$row}.'</td>'.
7471: '<td class="LC_left_item">'.
7472: '<table><tr>';
7473: my (%current,%currentcap);
7474: if (ref($settings) eq 'HASH') {
7475: if (ref($settings->{$key}) eq 'HASH') {
7476: foreach my $type (@types) {
7477: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7478: $current{$type} = $settings->{$key}->{$type}->{$row};
7479: }
7480: if (($row eq 'limit') && ($key eq 'default')) {
7481: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7482: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7483: }
7484: }
7485: }
7486: }
7487: }
7488: my %roles = (
7489: '0' => &Apache::lonnet::plaintext('dc'),
7490: );
7491:
7492: foreach my $type (@types) {
7493: unless (($row eq 'registered') && ($key eq 'default')) {
7494: $datatable .= '<th>'.&mt($type).'</th>';
7495: }
7496: }
7497: unless (($row eq 'registered') && ($key eq 'default')) {
7498: $datatable .= '</tr><tr>';
7499: }
7500: foreach my $type (@types) {
7501: if ($type eq 'community') {
7502: $roles{'1'} = &mt('Community personnel');
7503: } else {
7504: $roles{'1'} = &mt('Course personnel');
7505: }
7506: $datatable .= '<td style="vertical-align: top">';
7507: if ($position eq 'top') {
7508: my %checked;
7509: if ($current{$type} eq '0') {
7510: $checked{'0'} = ' checked="checked"';
7511: } else {
7512: $checked{'1'} = ' checked="checked"';
7513: }
7514: foreach my $role ('1','0') {
7515: $datatable .= '<span class="LC_nobreak"><label>'.
7516: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7517: 'value="'.$role.'"'.$checked{$role}.' />'.
7518: $roles{$role}.'</label></span> ';
7519: }
7520: } else {
7521: if ($row eq 'types') {
7522: my %checked;
7523: if ($current{$type} =~ /^(all|dom)$/) {
7524: $checked{$1} = ' checked="checked"';
7525: } else {
7526: $checked{''} = ' checked="checked"';
7527: }
7528: foreach my $val ('','dom','all') {
7529: $datatable .= '<span class="LC_nobreak"><label>'.
7530: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7531: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7532: }
7533: } elsif ($row eq 'registered') {
7534: my %checked;
7535: if ($current{$type} eq '1') {
7536: $checked{'1'} = ' checked="checked"';
7537: } else {
7538: $checked{'0'} = ' checked="checked"';
7539: }
7540: foreach my $val ('0','1') {
7541: $datatable .= '<span class="LC_nobreak"><label>'.
7542: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7543: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7544: }
7545: } elsif ($row eq 'approval') {
7546: my %checked;
7547: if ($current{$type} =~ /^([12])$/) {
7548: $checked{$1} = ' checked="checked"';
7549: } else {
7550: $checked{'0'} = ' checked="checked"';
7551: }
7552: for my $val (0..2) {
7553: $datatable .= '<span class="LC_nobreak"><label>'.
7554: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7555: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7556: }
7557: } elsif ($row eq 'limit') {
7558: my %checked;
7559: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7560: $checked{$1} = ' checked="checked"';
7561: } else {
7562: $checked{'none'} = ' checked="checked"';
7563: }
7564: my $cap;
7565: if ($currentcap{$type} =~ /^\d+$/) {
7566: $cap = $currentcap{$type};
7567: }
7568: foreach my $val ('none','allstudents','selfenrolled') {
7569: $datatable .= '<span class="LC_nobreak"><label>'.
7570: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7571: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7572: }
7573: $datatable .= '<br />'.
7574: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7575: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7576: '</span>';
7577: }
7578: }
7579: $datatable .= '</td>';
7580: }
7581: $datatable .= '</tr>';
7582: }
7583: $datatable .= '</table></td></tr>';
7584: }
7585: } elsif ($position eq 'bottom') {
1.235 raeburn 7586: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7587: }
7588: $$rowtotal += $itemcount;
7589: return $datatable;
7590: }
7591:
7592: sub print_validation_rows {
7593: my ($caller,$dom,$settings,$rowtotal) = @_;
7594: my ($itemsref,$namesref,$fieldsref);
7595: if ($caller eq 'selfenroll') {
7596: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7597: } elsif ($caller eq 'requestcourses') {
7598: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7599: }
7600: my %currvalidation;
7601: if (ref($settings) eq 'HASH') {
7602: if (ref($settings->{'validation'}) eq 'HASH') {
7603: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7604: }
1.235 raeburn 7605: }
7606: my $datatable;
7607: my $itemcount = 0;
7608: foreach my $item (@{$itemsref}) {
7609: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7610: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7611: $namesref->{$item}.
7612: '</span></td>'.
7613: '<td class="LC_left_item">';
7614: if (($item eq 'url') || ($item eq 'button')) {
7615: $datatable .= '<span class="LC_nobreak">'.
7616: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7617: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7618: } elsif ($item eq 'fields') {
7619: my @currfields;
7620: if (ref($currvalidation{$item}) eq 'ARRAY') {
7621: @currfields = @{$currvalidation{$item}};
7622: }
7623: foreach my $field (@{$fieldsref}) {
7624: my $check = '';
7625: if (grep(/^\Q$field\E$/,@currfields)) {
7626: $check = ' checked="checked"';
7627: }
7628: $datatable .= '<span class="LC_nobreak"><label>'.
7629: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7630: ' value="'.$field.'"'.$check.' />'.$field.
7631: '</label></span> ';
7632: }
7633: } elsif ($item eq 'markup') {
1.334 raeburn 7634: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7635: $currvalidation{$item}.
1.231 raeburn 7636: '</textarea>';
1.235 raeburn 7637: }
7638: $datatable .= '</td></tr>'."\n";
7639: if (ref($rowtotal)) {
1.231 raeburn 7640: $itemcount ++;
7641: }
7642: }
1.235 raeburn 7643: if ($caller eq 'requestcourses') {
7644: my %currhash;
1.248 raeburn 7645: if (ref($settings) eq 'HASH') {
7646: if (ref($settings->{'validation'}) eq 'HASH') {
7647: if ($settings->{'validation'}{'dc'} ne '') {
7648: $currhash{$settings->{'validation'}{'dc'}} = 1;
7649: }
1.235 raeburn 7650: }
7651: }
7652: my $numinrow = 2;
7653: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7654: 'validationdc',%currhash);
1.247 raeburn 7655: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7656: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7657: if ($numdc > 1) {
1.247 raeburn 7658: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7659: } else {
1.247 raeburn 7660: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7661: }
1.247 raeburn 7662: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7663: $itemcount ++;
7664: }
7665: if (ref($rowtotal)) {
7666: $$rowtotal += $itemcount;
7667: }
1.231 raeburn 7668: return $datatable;
7669: }
7670:
1.357 raeburn 7671: sub print_privacy {
7672: my ($position,$dom,$settings,$rowtotal) = @_;
7673: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7674: my $itemcount = 0;
1.417 raeburn 7675: if ($position eq 'top') {
7676: $numinrow = 2;
7677: } else {
1.357 raeburn 7678: @items = ('domain','author','course','community');
7679: %names = &Apache::lonlocal::texthash (
7680: domain => 'Assigned domain role(s)',
7681: author => 'Assigned co-author role(s)',
7682: course => 'Assigned course role(s)',
1.416 raeburn 7683: community => 'Assigned community role(s)',
1.357 raeburn 7684: );
7685: $numinrow = 4;
7686: ($othertitle,$usertypes,$types) =
7687: &Apache::loncommon::sorted_inst_types($dom);
7688: }
7689: if (($position eq 'top') || ($position eq 'middle')) {
7690: my (%by_ip,%by_location,@intdoms,@instdoms);
7691: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7692: if ($position eq 'top') {
7693: my %curr;
7694: my @options = ('none','user','domain','auto');
7695: my %titles = &Apache::lonlocal::texthash (
7696: none => 'Not allowed',
7697: user => 'User authorizes',
7698: domain => 'DC authorizes',
7699: auto => 'Unrestricted',
7700: instdom => 'Other domain shares institution/provider',
7701: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7702: notify => 'Notify when role needs authorization',
1.357 raeburn 7703: );
7704: my %names = &Apache::lonlocal::texthash (
7705: domain => 'Domain role',
7706: author => 'Co-author role',
7707: course => 'Course role',
7708: community => 'Community role',
7709: );
7710: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7711: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7712: foreach my $domtype ('instdom','extdom') {
7713: my (%checked,$skip);
7714: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7715: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7716: '<td class="LC_left_item">';
7717: if ($domtype eq 'instdom') {
7718: unless (@instdoms > 1) {
7719: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7720: $skip = 1;
7721: }
7722: } elsif ($domtype eq 'extdom') {
7723: if (keys(%by_location) == 0) {
7724: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7725: $skip = 1;
7726: }
7727: }
7728: unless ($skip) {
7729: foreach my $roletype ('domain','author','course','community') {
7730: $checked{'auto'} = ' checked="checked"';
7731: if (ref($settings) eq 'HASH') {
7732: if (ref($settings->{approval}) eq 'HASH') {
7733: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7734: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7735: $checked{$1} = ' checked="checked"';
7736: $checked{'auto'} = '';
7737: }
7738: }
7739: }
7740: }
7741: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7742: foreach my $option (@options) {
7743: $datatable .= '<span class="LC_nobreak"><label>'.
7744: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7745: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7746: '</label></span> ';
7747: }
7748: $datatable .= '</fieldset>';
7749: }
7750: }
7751: $datatable .= '</td></tr>';
7752: $itemcount ++;
7753: }
1.417 raeburn 7754: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7755: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7756: '<td class="LC_left_item">';
7757: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7758: my %curr;
7759: if (ref($settings) eq 'HASH') {
7760: if ($settings->{'notify'} ne '') {
7761: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7762: }
7763: }
7764: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7765: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7766: 'privacy_notify',%curr);
7767: if ($numdc > 0) {
7768: $datatable .= $table;
7769: } else {
7770: $datatable .= &mt('There are no active Domain Coordinators');
7771: }
7772: } else {
7773: $datatable .= &mt('Nothing to set here, as there are no other domains');
7774: }
7775: $datatable .='</td></tr>';
1.357 raeburn 7776: } elsif ($position eq 'middle') {
7777: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7778: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7779: foreach my $item (@{$types}) {
7780: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7781: $numinrow,$itemcount,'','','','','',
7782: '',$usertypes->{$item});
7783: $itemcount ++;
7784: }
7785: }
7786: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7787: $numinrow,$itemcount,'','','','','',
7788: '',$othertitle);
7789: $itemcount ++;
7790: } else {
1.360 raeburn 7791: my (@insttypes,%insttitles);
7792: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7793: @insttypes = @{$types};
7794: %insttitles = %{$usertypes};
7795: }
7796: foreach my $item (@insttypes,'default') {
7797: my $title;
7798: if ($item eq 'default') {
7799: $title = $othertitle;
7800: } else {
7801: $title = $insttitles{$item};
7802: }
7803: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7804: $datatable .= '<tr'.$css_class.'>'.
7805: '<td class="LC_left_item">'.$title.'</td>'.
7806: '<td class="LC_left_item">'.
7807: &mt('Nothing to set here, as there are no other domains').
7808: '</td></tr>';
7809: $itemcount ++;
7810: }
1.357 raeburn 7811: }
7812: }
7813: } else {
7814: my $prefix;
7815: if ($position eq 'lower') {
7816: $prefix = 'priv';
7817: } else {
7818: $prefix = 'unpriv';
7819: }
7820: foreach my $item (@items) {
7821: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7822: $numinrow,$itemcount,'','','','','',
7823: '',$names{$item});
7824: $itemcount ++;
7825: }
7826: }
7827: if (ref($rowtotal)) {
7828: $$rowtotal += $itemcount;
7829: }
7830: return $datatable;
7831: }
7832:
1.354 raeburn 7833: sub print_passwords {
7834: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7835: my ($datatable,$css_class);
7836: my $itemcount = 0;
7837: my %titles = &Apache::lonlocal::texthash (
7838: captcha => '"Forgot Password" CAPTCHA validation',
7839: link => 'Reset link expiration (hours)',
7840: case => 'Case-sensitive usernames/e-mail',
7841: prelink => 'Information required (form 1)',
7842: postlink => 'Information required (form 2)',
7843: emailsrc => 'LON-CAPA e-mail address type(s)',
7844: customtext => 'Domain specific text (HTML)',
7845: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7846: intauth_check => 'Check bcrypt cost if authenticated',
7847: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7848: permanent => 'Permanent e-mail address',
7849: critical => 'Critical notification address',
7850: notify => 'Notification address',
7851: min => 'Minimum password length',
7852: max => 'Maximum password length',
7853: chars => 'Required characters',
7854: expire => 'Password expiration (days)',
1.356 raeburn 7855: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7856: );
7857: if ($position eq 'top') {
7858: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7859: my $shownlinklife = 2;
7860: my $prelink = 'both';
7861: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7862: if (ref($settings) eq 'HASH') {
7863: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7864: $shownlinklife = $settings->{resetlink};
7865: }
7866: if (ref($settings->{resetcase}) eq 'ARRAY') {
7867: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7868: }
7869: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7870: $prelink = $settings->{resetprelink};
7871: }
7872: if (ref($settings->{resetpostlink}) eq 'HASH') {
7873: %postlink = %{$settings->{resetpostlink}};
7874: }
7875: if (ref($settings->{resetemail}) eq 'ARRAY') {
7876: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7877: }
7878: if ($settings->{resetremove}) {
7879: $nostdtext = 1;
7880: }
7881: if ($settings->{resetcustom}) {
7882: $customurl = $settings->{resetcustom};
7883: }
7884: } else {
7885: if (ref($types) eq 'ARRAY') {
7886: foreach my $item (@{$types}) {
7887: $casesens{$item} = 1;
7888: $postlink{$item} = ['username','email'];
7889: }
7890: }
7891: $casesens{'default'} = 1;
7892: $postlink{'default'} = ['username','email'];
7893: $prelink = 'both';
7894: %emailsrc = (
7895: permanent => 1,
7896: critical => 1,
7897: notify => 1,
7898: );
7899: }
7900: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7901: $itemcount ++;
7902: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7903: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7904: '<td class="LC_left_item">'.
7905: '<input type="textbox" value="'.$shownlinklife.'" '.
7906: 'name="passwords_link" size="3" /></td></tr>';
7907: $itemcount ++;
7908: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7909: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7910: '<td class="LC_left_item">';
7911: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7912: foreach my $item (@{$types}) {
7913: my $checkedcase;
7914: if ($casesens{$item}) {
7915: $checkedcase = ' checked="checked"';
7916: }
7917: $datatable .= '<span class="LC_nobreak"><label>'.
7918: '<input type="checkbox" name="passwords_case_sensitive" value="'.
7919: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 7920: '</span> ';
1.354 raeburn 7921: }
7922: }
7923: my $checkedcase;
7924: if ($casesens{'default'}) {
7925: $checkedcase = ' checked="checked"';
7926: }
7927: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7928: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
7929: $othertitle.'</label></span></td>';
7930: $itemcount ++;
7931: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7932: my %checkedpre = (
7933: both => ' checked="checked"',
7934: either => '',
7935: );
7936: if ($prelink eq 'either') {
7937: $checkedpre{either} = ' checked="checked"';
7938: $checkedpre{both} = '';
7939: }
7940: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7941: '<td class="LC_left_item"><span class="LC_nobreak">'.
7942: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7943: &mt('Both username and e-mail address').'</label></span> '.
7944: '<span class="LC_nobreak"><label>'.
7945: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7946: &mt('Either username or e-mail address').'</label></span></td></tr>';
7947: $itemcount ++;
7948: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7949: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7950: '<td class="LC_left_item">';
7951: my %postlinked;
7952: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7953: foreach my $item (@{$types}) {
7954: undef(%postlinked);
7955: $datatable .= '<fieldset style="display: inline-block;">'.
7956: '<legend>'.$usertypes->{$item}.'</legend>';
7957: if (ref($postlink{$item}) eq 'ARRAY') {
7958: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7959: }
7960: foreach my $field ('email','username') {
7961: my $checked;
7962: if ($postlinked{$field}) {
7963: $checked = ' checked="checked"';
7964: }
7965: $datatable .= '<span class="LC_nobreak"><label>'.
7966: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7967: $field.'"'.$checked.' />'.$field.'</label>'.
7968: '<span> ';
7969: }
7970: $datatable .= '</fieldset>';
7971: }
7972: }
7973: if (ref($postlink{'default'}) eq 'ARRAY') {
7974: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7975: }
7976: $datatable .= '<fieldset style="display: inline-block;">'.
7977: '<legend>'.$othertitle.'</legend>';
7978: foreach my $field ('email','username') {
7979: my $checked;
7980: if ($postlinked{$field}) {
7981: $checked = ' checked="checked"';
7982: }
7983: $datatable .= '<span class="LC_nobreak"><label>'.
7984: '<input type="checkbox" name="passwords_postlink_default" value="'.
7985: $field.'"'.$checked.' />'.$field.'</label>'.
7986: '<span> ';
7987: }
7988: $datatable .= '</fieldset></td></tr>';
7989: $itemcount ++;
7990: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7991: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7992: '<td class="LC_left_item">';
7993: foreach my $type ('permanent','critical','notify') {
7994: my $checkedemail;
7995: if ($emailsrc{$type}) {
7996: $checkedemail = ' checked="checked"';
7997: }
7998: $datatable .= '<span class="LC_nobreak"><label>'.
7999: '<input type="checkbox" name="passwords_emailsrc" value="'.
8000: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8001: '<span> ';
8002: }
8003: $datatable .= '</td></tr>';
8004: $itemcount ++;
8005: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8006: my $switchserver = &check_switchserver($dom,$confname);
8007: my ($showstd,$noshowstd);
8008: if ($nostdtext) {
8009: $noshowstd = ' checked="checked"';
8010: } else {
8011: $showstd = ' checked="checked"';
8012: }
8013: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8014: '<td class="LC_left_item"><span class="LC_nobreak">'.
8015: &mt('Retain standard text:').
8016: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8017: &mt('Yes').'</label>'.' '.
8018: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8019: &mt('No').'</label></span><br />'.
8020: '<span class="LC_fontsize_small">'.
8021: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8022: &mt('Include custom text:');
8023: if ($customurl) {
1.369 raeburn 8024: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8025: undef,undef,undef,undef,'background-color:#ffffff');
8026: $datatable .= '<span class="LC_nobreak"> '.$link.
8027: '<label><input type="checkbox" name="passwords_custom_del"'.
8028: ' value="1" />'.&mt('Delete?').'</label></span>'.
8029: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8030: }
8031: if ($switchserver) {
8032: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8033: } else {
8034: $datatable .='<span class="LC_nobreak"> '.
8035: '<input type="file" name="passwords_customfile" /></span>';
8036: }
8037: $datatable .= '</td></tr>';
8038: } elsif ($position eq 'middle') {
8039: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8040: my @items = ('intauth_cost','intauth_check','intauth_switch');
8041: my %defaults;
8042: if (ref($domconf{'defaults'}) eq 'HASH') {
8043: %defaults = %{$domconf{'defaults'}};
8044: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8045: $defaults{'intauth_cost'} = 10;
8046: }
8047: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8048: $defaults{'intauth_check'} = 0;
8049: }
8050: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8051: $defaults{'intauth_switch'} = 0;
8052: }
8053: } else {
8054: %defaults = (
8055: 'intauth_cost' => 10,
8056: 'intauth_check' => 0,
8057: 'intauth_switch' => 0,
8058: );
8059: }
8060: foreach my $item (@items) {
8061: if ($itemcount%2) {
8062: $css_class = '';
8063: } else {
8064: $css_class = ' class="LC_odd_row" ';
8065: }
8066: $datatable .= '<tr'.$css_class.'>'.
8067: '<td><span class="LC_nobreak">'.$titles{$item}.
8068: '</span></td><td class="LC_left_item" colspan="3">';
8069: if ($item eq 'intauth_switch') {
8070: my @options = (0,1,2);
8071: my %optiondesc = &Apache::lonlocal::texthash (
8072: 0 => 'No',
8073: 1 => 'Yes',
8074: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8075: );
8076: $datatable .= '<table width="100%">';
8077: foreach my $option (@options) {
8078: my $checked = ' ';
8079: if ($defaults{$item} eq $option) {
8080: $checked = ' checked="checked"';
8081: }
8082: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8083: '<label><input type="radio" name="'.$item.
8084: '" value="'.$option.'"'.$checked.' />'.
8085: $optiondesc{$option}.'</label></span></td></tr>';
8086: }
8087: $datatable .= '</table>';
8088: } elsif ($item eq 'intauth_check') {
8089: my @options = (0,1,2);
8090: my %optiondesc = &Apache::lonlocal::texthash (
8091: 0 => 'No',
8092: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8093: 2 => 'Yes, disallow login if stored cost is less than domain default',
8094: );
8095: $datatable .= '<table width="100%">';
8096: foreach my $option (@options) {
8097: my $checked = ' ';
8098: my $onclick;
8099: if ($defaults{$item} eq $option) {
8100: $checked = ' checked="checked"';
8101: }
8102: if ($option == 2) {
8103: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8104: }
8105: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8106: '<label><input type="radio" name="'.$item.
8107: '" value="'.$option.'"'.$checked.$onclick.' />'.
8108: $optiondesc{$option}.'</label></span></td></tr>';
8109: }
8110: $datatable .= '</table>';
8111: } else {
8112: $datatable .= '<input type="text" name="'.$item.'" value="'.
8113: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8114: }
8115: $datatable .= '</td></tr>';
8116: $itemcount ++;
8117: }
8118: } elsif ($position eq 'lower') {
1.405 raeburn 8119: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8120: } else {
1.359 raeburn 8121: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8122: my %ownerchg = (
8123: by => {},
8124: for => {},
8125: );
8126: my %ownertitles = &Apache::lonlocal::texthash (
8127: by => 'Course owner status(es) allowed',
8128: for => 'Student status(es) allowed',
8129: );
1.354 raeburn 8130: if (ref($settings) eq 'HASH') {
1.359 raeburn 8131: if (ref($settings->{crsownerchg}) eq 'HASH') {
8132: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8133: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8134: }
8135: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8136: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8137: }
1.354 raeburn 8138: }
8139: }
8140: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8141: $datatable .= '<tr '.$css_class.'>'.
8142: '<td>'.
8143: &mt('Requirements').'<ul>'.
1.359 raeburn 8144: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8145: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8146: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8147: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8148: '</ul>'.
8149: '</td>'.
1.359 raeburn 8150: '<td class="LC_left_item">';
8151: foreach my $item ('by','for') {
8152: $datatable .= '<fieldset style="display: inline-block;">'.
8153: '<legend>'.$ownertitles{$item}.'</legend>';
8154: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8155: foreach my $type (@{$types}) {
8156: my $checked;
8157: if ($ownerchg{$item}{$type}) {
8158: $checked = ' checked="checked"';
8159: }
8160: $datatable .= '<span class="LC_nobreak"><label>'.
8161: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8162: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8163: '</span> ';
1.359 raeburn 8164: }
8165: }
8166: my $checked;
8167: if ($ownerchg{$item}{'default'}) {
8168: $checked = ' checked="checked"';
8169: }
8170: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8171: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8172: $othertitle.'</label></span></fieldset>';
8173: }
8174: $datatable .= '</td></tr>';
1.354 raeburn 8175: }
8176: return $datatable;
8177: }
8178:
1.405 raeburn 8179: sub password_rules {
8180: my ($prefix,$itemcountref,$settings) = @_;
8181: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8182: my %titles;
8183: if ($prefix eq 'passwords') {
8184: %titles = &Apache::lonlocal::texthash (
8185: min => 'Minimum password length',
8186: max => 'Maximum password length',
8187: chars => 'Required characters',
8188: );
1.421 raeburn 8189: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8190: %titles = &Apache::lonlocal::texthash (
8191: min => 'Minimum secret length',
8192: max => 'Maximum secret length',
8193: chars => 'Required characters',
8194: );
8195: }
8196: $min = $Apache::lonnet::passwdmin;
8197: my $datatable;
8198: my $itemcount;
8199: if (ref($itemcountref)) {
8200: $itemcount = $$itemcountref;
8201: }
8202: if (ref($settings) eq 'HASH') {
8203: if ($settings->{min}) {
8204: $min = $settings->{min};
8205: }
8206: if ($settings->{max}) {
8207: $max = $settings->{max};
8208: }
8209: if (ref($settings->{chars}) eq 'ARRAY') {
8210: map { $chars{$_} = 1; } (@{$settings->{chars}});
8211: }
1.425 raeburn 8212: if ($prefix eq 'passwords') {
1.405 raeburn 8213: if ($settings->{expire}) {
8214: $expire = $settings->{expire};
8215: }
8216: if ($settings->{numsaved}) {
8217: $numsaved = $settings->{numsaved};
8218: }
8219: }
8220: }
8221: my %rulenames = &Apache::lonlocal::texthash(
8222: uc => 'At least one upper case letter',
8223: lc => 'At least one lower case letter',
8224: num => 'At least one number',
8225: spec => 'At least one non-alphanumeric',
8226: );
8227: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8228: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8229: '<td class="LC_left_item"><span class="LC_nobreak">'.
8230: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8231: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8232: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8233: '</span></td></tr>';
8234: $itemcount ++;
8235: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8236: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8237: '<td class="LC_left_item"><span class="LC_nobreak">'.
8238: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8239: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8240: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8241: '</span></td></tr>';
8242: $itemcount ++;
8243: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8244: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8245: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8246: '</span></td>';
8247: my $numinrow = 2;
8248: my @possrules = ('uc','lc','num','spec');
8249: $datatable .= '<td class="LC_left_item"><table>';
8250: for (my $i=0; $i<@possrules; $i++) {
8251: my ($rem,$checked);
8252: if ($chars{$possrules[$i]}) {
8253: $checked = ' checked="checked"';
8254: }
8255: $rem = $i%($numinrow);
8256: if ($rem == 0) {
8257: if ($i > 0) {
8258: $datatable .= '</tr>';
8259: }
8260: $datatable .= '<tr>';
8261: }
8262: $datatable .= '<td><span class="LC_nobreak"><label>'.
8263: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8264: $rulenames{$possrules[$i]}.'</label></span></td>';
8265: }
8266: my $rem = @possrules%($numinrow);
8267: my $colsleft = $numinrow - $rem;
8268: if ($colsleft > 1 ) {
8269: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8270: ' </td>';
8271: } elsif ($colsleft == 1) {
8272: $datatable .= '<td class="LC_left_item"> </td>';
8273: }
8274: $datatable .='</table></td></tr>';
8275: $itemcount ++;
8276: if ($prefix eq 'passwords') {
8277: $titles{'expire'} = &mt('Password expiration (days)');
8278: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8279: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8280: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8281: '<td class="LC_left_item"><span class="LC_nobreak">'.
8282: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8283: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8284: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8285: '</span></td></tr>';
8286: $itemcount ++;
8287: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8288: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8289: '<td class="LC_left_item"><span class="LC_nobreak">'.
8290: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8291: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8292: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8293: '</span></td></tr>';
8294: $itemcount ++;
8295: }
8296: if (ref($itemcountref)) {
8297: $$itemcountref += $itemcount;
8298: }
8299: return $datatable;
8300: }
8301:
1.373 raeburn 8302: sub print_wafproxy {
8303: my ($position,$dom,$settings,$rowtotal) = @_;
8304: my $css_class;
8305: my $itemcount = 0;
8306: my $datatable;
8307: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8308: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8309: my %lt = &wafproxy_titles();
1.373 raeburn 8310: foreach my $server (sort(keys(%servers))) {
8311: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8312: next if ($serverhome eq '');
1.373 raeburn 8313: my $serverdom;
8314: if ($serverhome ne $server) {
8315: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8316: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8317: $othercontrol{$server} = $serverdom;
8318: }
1.373 raeburn 8319: } else {
8320: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8321: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8322: if ($serverdom ne $dom) {
8323: $othercontrol{$server} = $serverdom;
8324: } else {
8325: $setdom = 1;
8326: if (ref($settings) eq 'HASH') {
8327: if (ref($settings->{'alias'}) eq 'HASH') {
8328: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8329: if ($aliases{$dom} ne '') {
8330: $showdom = 1;
8331: }
1.373 raeburn 8332: }
1.388 raeburn 8333: if (ref($settings->{'saml'}) eq 'HASH') {
8334: $saml{$dom} = $settings->{'saml'};
8335: }
1.373 raeburn 8336: }
8337: }
8338: }
8339: }
1.381 raeburn 8340: if ($setdom) {
8341: %{$values{$dom}} = ();
8342: if (ref($settings) eq 'HASH') {
8343: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8344: $values{$dom}{$item} = $settings->{$item};
8345: }
8346: }
8347: }
1.373 raeburn 8348: if (keys(%othercontrol)) {
8349: %otherdoms = reverse(%othercontrol);
8350: foreach my $domain (keys(%otherdoms)) {
8351: %{$values{$domain}} = ();
8352: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8353: if (ref($config{'wafproxy'}) eq 'HASH') {
8354: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8355: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8356: $saml{$domain} = $config{'wafproxy'}{'saml'};
8357: }
1.383 raeburn 8358: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8359: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8360: }
8361: }
8362: }
8363: }
8364: if ($position eq 'top') {
8365: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8366: my %aliasinfo;
1.373 raeburn 8367: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8368: $itemcount ++;
8369: my $dom_in_effect;
8370: my $aliasrows = '<tr>'.
1.383 raeburn 8371: '<td class="LC_left_item" style="vertical-align: baseline;">'.
8372: &mt('Hostname').': '.
8373: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
1.373 raeburn 8374: if ($othercontrol{$server}) {
1.381 raeburn 8375: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8376: my ($current,$forsaml);
1.383 raeburn 8377: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8378: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8379: }
1.388 raeburn 8380: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8381: if ($saml{$dom_in_effect}{$server}) {
8382: $forsaml = 1;
8383: }
8384: }
1.383 raeburn 8385: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8386: &mt('Alias').': ';
1.373 raeburn 8387: if ($current) {
1.381 raeburn 8388: $aliasrows .= $current;
1.388 raeburn 8389: if ($forsaml) {
1.396 raeburn 8390: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8391: }
1.373 raeburn 8392: } else {
1.383 raeburn 8393: $aliasrows .= &mt('None');
1.373 raeburn 8394: }
1.383 raeburn 8395: $aliasrows .= ' <span class="LC_small">('.
8396: &mt('controlled by domain: [_1]',
8397: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8398: } else {
1.381 raeburn 8399: $dom_in_effect = $dom;
1.388 raeburn 8400: my ($current,$samlon,$samloff);
8401: $samloff = ' checked="checked"';
1.373 raeburn 8402: if (ref($aliases{$dom}) eq 'HASH') {
8403: if ($aliases{$dom}{$server}) {
8404: $current = $aliases{$dom}{$server};
8405: }
8406: }
1.388 raeburn 8407: if (ref($saml{$dom}) eq 'HASH') {
8408: if ($saml{$dom}{$server}) {
8409: $samlon = $samloff;
8410: undef($samloff);
8411: }
8412: }
1.383 raeburn 8413: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8414: &mt('Alias').': '.
1.381 raeburn 8415: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8416: 'value="'.$current.'" size="30" />'.
8417: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8418: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8419: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8420: &mt('No').'</label> <label>'.
1.388 raeburn 8421: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8422: &mt('Yes').'</label></span>'.
1.425 raeburn 8423: '</td>';
1.381 raeburn 8424: }
8425: $aliasrows .= '</tr>';
8426: $aliasinfo{$dom_in_effect} .= $aliasrows;
8427: }
8428: if ($aliasinfo{$dom}) {
8429: my ($onclick,$wafon,$wafoff,$showtable);
8430: $onclick = ' onclick="javascript:toggleWAF();"';
8431: $wafoff = ' checked="checked"';
8432: $showtable = ' style="display:none";';
8433: if ($showdom) {
8434: $wafon = $wafoff;
8435: $wafoff = '';
8436: $showtable = ' style="display:inline;"';
8437: }
8438: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8439: $datatable = '<tr'.$css_class.'>'.
8440: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8441: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8442: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8443: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8444: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8445: &mt('No').'</label></span></td>'.
8446: '<td class="LC_left_item">'.
8447: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8448: '</table></td></tr>';
8449: $itemcount++;
8450: }
1.383 raeburn 8451: if (keys(%otherdoms)) {
8452: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8453: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8454: $datatable .= '<tr'.$css_class.'>'.
8455: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8456: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8457: '</table></td></tr>';
1.381 raeburn 8458: $itemcount++;
1.373 raeburn 8459: }
8460: }
8461: } else {
1.383 raeburn 8462: my %ip_methods = &remoteip_methods();
1.373 raeburn 8463: if ($setdom) {
8464: $itemcount ++;
8465: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8466: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8467: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8468: $wafstyle = ' style="display:none;"';
8469: $nowafstyle = ' style="display:table-row;"';
8470: $currwafdisplay = ' style="display: none"';
8471: $wafrangestyle = ' style="display: none"';
8472: $curr_remotip = 'n';
1.382 raeburn 8473: $ssltossl = ' checked="checked"';
1.381 raeburn 8474: if ($showdom) {
8475: $wafstyle = ' style="display:table-row;"';
8476: $nowafstyle = ' style="display:none;"';
8477: if (keys(%{$values{$dom}})) {
8478: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8479: $curr_remotip = $values{$dom}{remoteip};
8480: }
8481: if ($curr_remotip eq 'h') {
8482: $currwafdisplay = ' style="display:table-row"';
8483: $wafrangestyle = ' style="display:inline-block;"';
8484: }
1.382 raeburn 8485: if ($values{$dom}{'sslopt'}) {
8486: $alltossl = ' checked="checked"';
8487: $ssltossl = '';
8488: }
1.381 raeburn 8489: }
8490: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8491: $vpndircheck = ' checked="checked"';
8492: $currwafvpn = ' style="display:table-row;"';
8493: $wafrangestyle = ' style="display:inline-block;"';
8494: } else {
8495: $vpnaliascheck = ' checked="checked"';
8496: $currwafvpn = ' style="display:none;"';
8497: }
8498: }
8499: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8500: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8501: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8502: '</tr>'.
8503: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8504: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8505: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8506: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8507: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8508: '<td class="LC_left_item"><table>'.
8509: '<tr>'.
8510: '<td valign="top">'.$lt{'remoteip'}.': '.
8511: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8512: foreach my $option ('m','h','n') {
8513: my $sel;
8514: if ($option eq $curr_remotip) {
8515: $sel = ' selected="selected"';
8516: }
8517: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8518: $ip_methods{$option}.'</option>';
8519: }
8520: $datatable .= '</select></td></tr>'."\n".
8521: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8522: $lt{'ipheader'}.': '.
8523: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8524: 'name="wafproxy_ipheader" />'.
8525: '</td></tr>'."\n".
8526: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8527: $lt{'trusted'}.':<br />'.
1.381 raeburn 8528: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8529: $values{$dom}{'trusted'}.'</textarea>'.
8530: '</td></tr>'."\n".
8531: '<tr><td><hr /></td></tr>'."\n".
8532: '<tr>'.
8533: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8534: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8535: $lt{'vpndirect'}.'</label>'.(' 'x2).
8536: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8537: $lt{'vpnaliased'}.'</label></span></td></tr>';
8538: foreach my $item ('vpnint','vpnext') {
8539: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8540: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8541: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8542: $values{$dom}{$item}.'</textarea>'.
8543: '</td></tr>'."\n";
1.373 raeburn 8544: }
1.382 raeburn 8545: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8546: '<tr>'.
8547: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8548: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8549: $lt{'alltossl'}.'</label>'.(' 'x2).
8550: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8551: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8552: '</table></td></tr>';
1.373 raeburn 8553: }
8554: if (keys(%otherdoms)) {
8555: foreach my $domain (sort(keys(%otherdoms))) {
8556: $itemcount ++;
8557: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8558: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8559: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8560: '<td class="LC_left_item"><table>';
1.382 raeburn 8561: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8562: my $showval = &mt('None');
1.382 raeburn 8563: if ($item eq 'ssl') {
8564: $showval = $lt{'ssltossl'};
8565: }
1.373 raeburn 8566: if ($values{$domain}{$item}) {
1.381 raeburn 8567: $showval = $values{$domain}{$item};
1.382 raeburn 8568: if ($item eq 'ssl') {
8569: $showval = $lt{'alltossl'};
1.383 raeburn 8570: } elsif ($item eq 'remoteip') {
8571: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8572: }
1.373 raeburn 8573: }
8574: $datatable .= '<tr>'.
8575: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8576: }
1.381 raeburn 8577: $datatable .= '</table></td></tr>';
1.373 raeburn 8578: }
8579: }
8580: }
8581: $$rowtotal += $itemcount;
8582: return $datatable;
8583: }
8584:
8585: sub wafproxy_titles {
8586: return &Apache::lonlocal::texthash(
1.381 raeburn 8587: remoteip => "Method for determining user's IP",
8588: ipheader => 'Request header containing remote IP',
8589: trusted => 'Trusted IP range(s)',
8590: vpnaccess => 'Access from institutional VPN',
8591: vpndirect => 'via regular hostname (no WAF)',
8592: vpnaliased => 'via aliased hostname (WAF)',
8593: vpnint => 'Internal IP Range(s) for VPN sessions',
8594: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8595: sslopt => 'Forwarding http/https',
1.381 raeburn 8596: alltossl => 'WAF forwards both http and https requests to https',
8597: ssltossl => 'WAF forwards http requests to http and https to https',
8598: );
8599: }
8600:
8601: sub remoteip_methods {
8602: return &Apache::lonlocal::texthash(
8603: m => 'Use Apache mod_remoteip',
8604: h => 'Use headers parsed by LON-CAPA',
8605: n => 'Not in use',
1.373 raeburn 8606: );
8607: }
8608:
1.137 raeburn 8609: sub print_usersessions {
8610: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8611: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8612: my (%by_ip,%by_location,@intdoms,@instdoms);
8613: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8614:
8615: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8616: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8617: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8618: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8619: if ($position eq 'top') {
1.152 raeburn 8620: if (keys(%serverhomes) > 1) {
1.145 raeburn 8621: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8622: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8623: if (ref($settings) eq 'HASH') {
8624: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8625: $curroffloadnow = $settings->{'offloadnow'};
8626: }
1.371 raeburn 8627: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8628: $curroffloadoth = $settings->{'offloadoth'};
8629: }
1.261 raeburn 8630: }
1.371 raeburn 8631: my $other_insts = scalar(keys(%by_location));
8632: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8633: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8634: } else {
1.140 raeburn 8635: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8636: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8637: '</td></tr>';
1.140 raeburn 8638: }
1.137 raeburn 8639: } else {
1.279 raeburn 8640: my %titles = &usersession_titles();
8641: my ($prefix,@types);
8642: if ($position eq 'bottom') {
8643: $prefix = 'remote';
8644: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8645: } else {
1.279 raeburn 8646: $prefix = 'hosted';
8647: @types = ('excludedomain','includedomain');
8648: }
8649: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8650: }
8651: $$rowtotal += $itemcount;
8652: return $datatable;
8653: }
8654:
8655: sub rules_by_location {
8656: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8657: my ($datatable,$itemcount,$css_class);
8658: if (keys(%{$by_location}) == 0) {
8659: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8660: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8661: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8662: '</td></tr>';
8663: $itemcount = 1;
8664: } else {
8665: $itemcount = 0;
8666: my $numinrow = 5;
8667: my (%current,%checkedon,%checkedoff);
8668: my @locations = sort(keys(%{$by_location}));
8669: foreach my $type (@{$types}) {
8670: $checkedon{$type} = '';
8671: $checkedoff{$type} = ' checked="checked"';
8672: }
8673: if (ref($settings) eq 'HASH') {
8674: if (ref($settings->{$prefix}) eq 'HASH') {
8675: foreach my $key (keys(%{$settings->{$prefix}})) {
8676: $current{$key} = $settings->{$prefix}{$key};
8677: if ($key eq 'version') {
8678: if ($current{$key} ne '') {
1.145 raeburn 8679: $checkedon{$key} = ' checked="checked"';
8680: $checkedoff{$key} = '';
8681: }
1.279 raeburn 8682: } elsif (ref($current{$key}) eq 'ARRAY') {
8683: $checkedon{$key} = ' checked="checked"';
8684: $checkedoff{$key} = '';
1.137 raeburn 8685: }
8686: }
8687: }
1.279 raeburn 8688: }
8689: foreach my $type (@{$types}) {
8690: next if ($type ne 'version' && !@locations);
8691: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8692: $datatable .= '<tr'.$css_class.'>
8693: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8694: <span class="LC_nobreak">
8695: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8696: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8697: if ($type eq 'version') {
8698: my @lcversions = &Apache::lonnet::all_loncaparevs();
8699: my $selector = '<select name="'.$prefix.'_version">';
8700: foreach my $version (@lcversions) {
8701: my $selected = '';
8702: if ($current{'version'} eq $version) {
8703: $selected = ' selected="selected"';
1.145 raeburn 8704: }
1.279 raeburn 8705: $selector .= ' <option value="'.$version.'"'.
8706: $selected.'>'.$version.'</option>';
8707: }
8708: $selector .= '</select> ';
8709: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8710: } else {
8711: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8712: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8713: ' />'.(' 'x2).
8714: '<input type="button" value="'.&mt('uncheck all').'" '.
8715: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8716: "\n".
8717: '</div><div><table>';
8718: my $rem;
8719: for (my $i=0; $i<@locations; $i++) {
8720: my ($showloc,$value,$checkedtype);
8721: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8722: my $ip = $by_location->{$locations[$i]}->[0];
8723: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8724: $value = join(':',@{$by_ip->{$ip}});
8725: $showloc = join(', ',@{$by_ip->{$ip}});
8726: if (ref($current{$type}) eq 'ARRAY') {
8727: foreach my $loc (@{$by_ip->{$ip}}) {
8728: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8729: $checkedtype = ' checked="checked"';
8730: last;
1.145 raeburn 8731: }
1.138 raeburn 8732: }
8733: }
8734: }
1.137 raeburn 8735: }
1.279 raeburn 8736: $rem = $i%($numinrow);
8737: if ($rem == 0) {
8738: if ($i > 0) {
8739: $datatable .= '</tr>';
8740: }
8741: $datatable .= '<tr>';
8742: }
8743: $datatable .= '<td class="LC_left_item">'.
8744: '<span class="LC_nobreak"><label>'.
8745: '<input type="checkbox" name="'.$prefix.'_'.$type.
8746: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8747: '</label></span></td>';
8748: }
8749: $rem = @locations%($numinrow);
8750: my $colsleft = $numinrow - $rem;
8751: if ($colsleft > 1 ) {
8752: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8753: ' </td>';
8754: } elsif ($colsleft == 1) {
8755: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8756: }
1.279 raeburn 8757: $datatable .= '</tr></table>';
1.137 raeburn 8758: }
1.279 raeburn 8759: $datatable .= '</td></tr>';
8760: $itemcount ++;
1.137 raeburn 8761: }
8762: }
1.279 raeburn 8763: return ($datatable,$itemcount);
1.137 raeburn 8764: }
8765:
1.275 raeburn 8766: sub print_ssl {
8767: my ($position,$dom,$settings,$rowtotal) = @_;
8768: my ($css_class,$datatable);
8769: my $itemcount = 1;
8770: if ($position eq 'top') {
1.281 raeburn 8771: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8772: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8773: my $same_institution;
8774: if ($intdom ne '') {
8775: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8776: if (ref($internet_names) eq 'ARRAY') {
8777: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8778: $same_institution = 1;
8779: }
8780: }
8781: }
1.275 raeburn 8782: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8783: $datatable = '<tr'.$css_class.'><td colspan="2">';
8784: if ($same_institution) {
8785: my %domservers = &Apache::lonnet::get_servers($dom);
8786: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8787: } else {
8788: $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.");
8789: }
8790: $datatable .= '</td></tr>';
1.275 raeburn 8791: $itemcount ++;
8792: } else {
8793: my %titles = &ssl_titles();
8794: my (%by_ip,%by_location,@intdoms,@instdoms);
8795: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8796: my @alldoms = &Apache::lonnet::all_domains();
8797: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8798: my @domservers = &Apache::lonnet::get_servers($dom);
8799: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8800: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8801: if (($position eq 'connto') || ($position eq 'connfrom')) {
8802: my $legacy;
8803: unless (ref($settings) eq 'HASH') {
8804: my $name;
8805: if ($position eq 'connto') {
8806: $name = 'loncAllowInsecure';
8807: } else {
8808: $name = 'londAllowInsecure';
8809: }
8810: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8811: my @ids=&Apache::lonnet::current_machine_ids();
8812: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8813: my %what = (
8814: $name => 1,
8815: );
8816: my ($result,$returnhash) =
8817: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8818: if ($result eq 'ok') {
8819: if (ref($returnhash) eq 'HASH') {
8820: $legacy = $returnhash->{$name};
8821: }
8822: }
8823: } else {
8824: $legacy = $Apache::lonnet::perlvar{$name};
8825: }
8826: }
1.275 raeburn 8827: foreach my $type ('dom','intdom','other') {
8828: my %checked;
8829: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8830: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8831: '<td class="LC_right_item">';
8832: my $skip;
8833: if ($type eq 'dom') {
8834: unless (keys(%servers) > 1) {
8835: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8836: $skip = 1;
8837: }
8838: }
8839: if ($type eq 'intdom') {
8840: unless (@instdoms > 1) {
8841: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8842: $skip = 1;
8843: }
8844: } elsif ($type eq 'other') {
8845: if (keys(%by_location) == 0) {
8846: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8847: $skip = 1;
8848: }
8849: }
8850: unless ($skip) {
8851: $checked{'yes'} = ' checked="checked"';
8852: if (ref($settings) eq 'HASH') {
1.293 raeburn 8853: if (ref($settings->{$position}) eq 'HASH') {
8854: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8855: $checked{$1} = $checked{'yes'};
8856: delete($checked{'yes'});
8857: }
8858: }
1.293 raeburn 8859: } else {
8860: if ($legacy == 0) {
8861: $checked{'req'} = $checked{'yes'};
8862: delete($checked{'yes'});
8863: }
1.275 raeburn 8864: }
8865: foreach my $option ('no','yes','req') {
8866: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8867: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8868: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8869: '</label></span>'.(' 'x2);
8870: }
8871: }
8872: $datatable .= '</td></tr>';
8873: $itemcount ++;
8874: }
8875: } else {
8876: my $prefix = 'replication';
8877: my @types = ('certreq','nocertreq');
1.279 raeburn 8878: if (keys(%by_location) == 0) {
8879: $datatable .= '<tr'.$css_class.'><td>'.
8880: &mt('Nothing to set here, as there are no other institutions').
8881: '</td></tr>';
8882: $itemcount ++;
1.275 raeburn 8883: } else {
1.279 raeburn 8884: ($datatable,$itemcount) =
8885: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8886: }
8887: }
8888: }
8889: $$rowtotal += $itemcount;
8890: return $datatable;
8891: }
8892:
8893: sub ssl_titles {
8894: return &Apache::lonlocal::texthash (
8895: dom => 'LON-CAPA servers/VMs from same domain',
8896: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8897: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8898: connto => 'Connections to other servers',
8899: connfrom => 'Connections from other servers',
1.275 raeburn 8900: replication => 'Replicating content to other institutions',
8901: certreq => 'Client certificate required, but specific domains exempt',
8902: nocertreq => 'No client certificate required, except for specific domains',
8903: no => 'SSL not used',
8904: yes => 'SSL Optional (used if available)',
8905: req => 'SSL Required',
8906: );
1.279 raeburn 8907: }
8908:
8909: sub print_trust {
8910: my ($prefix,$dom,$settings,$rowtotal) = @_;
8911: my ($css_class,$datatable,%checked,%choices);
8912: my (%by_ip,%by_location,@intdoms,@instdoms);
8913: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8914: my $itemcount = 1;
8915: my %titles = &trust_titles();
8916: my @types = ('exc','inc');
8917: if ($prefix eq 'top') {
8918: $prefix = 'content';
8919: } elsif ($prefix eq 'bottom') {
8920: $prefix = 'msg';
8921: }
8922: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8923: $$rowtotal += $itemcount;
8924: return $datatable;
8925: }
8926:
8927: sub trust_titles {
8928: return &Apache::lonlocal::texthash(
8929: content => "Access to this domain's content by others",
8930: shared => "Access to other domain's content by this domain",
8931: enroll => "Enrollment in this domain's courses by others",
8932: othcoau => "Co-author roles in this domain for others",
8933: coaurem => "Co-author roles for this domain's users elsewhere",
8934: domroles => "Domain roles in this domain assignable to others",
8935: catalog => "Course Catalog for this domain displayed elsewhere",
8936: reqcrs => "Requests for creation of courses in this domain by others",
8937: msg => "Users in other domains can send messages to this domain",
8938: exc => "Allow all, but exclude specific domains",
8939: inc => "Deny all, but include specific domains",
8940: );
1.275 raeburn 8941: }
8942:
1.138 raeburn 8943: sub build_location_hashes {
1.275 raeburn 8944: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 8945: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 8946: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 8947: my %iphost = &Apache::lonnet::get_iphost();
8948: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
8949: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
8950: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
8951: foreach my $id (@{$iphost{$primary_ip}}) {
8952: my $intdom = &Apache::lonnet::internet_dom($id);
8953: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
8954: push(@{$intdoms},$intdom);
8955: }
8956: }
8957: }
8958: foreach my $ip (keys(%iphost)) {
8959: if (ref($iphost{$ip}) eq 'ARRAY') {
8960: foreach my $id (@{$iphost{$ip}}) {
8961: my $location = &Apache::lonnet::internet_dom($id);
8962: if ($location) {
1.275 raeburn 8963: if (grep(/^\Q$location\E$/,@{$intdoms})) {
8964: my $dom = &Apache::lonnet::host_domain($id);
8965: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
8966: push(@{$instdoms},$dom);
8967: }
8968: next;
8969: }
1.138 raeburn 8970: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8971: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
8972: push(@{$by_ip->{$ip}},$location);
8973: }
8974: } else {
8975: $by_ip->{$ip} = [$location];
8976: }
8977: }
8978: }
8979: }
8980: }
8981: foreach my $ip (sort(keys(%{$by_ip}))) {
8982: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8983: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
8984: my $first = $by_ip->{$ip}->[0];
8985: if (ref($by_location->{$first}) eq 'ARRAY') {
8986: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
8987: push(@{$by_location->{$first}},$ip);
8988: }
8989: } else {
8990: $by_location->{$first} = [$ip];
8991: }
8992: }
8993: }
8994: return;
8995: }
8996:
1.145 raeburn 8997: sub current_offloads_to {
8998: my ($dom,$settings,$servers) = @_;
8999: my (%spareid,%otherdomconfigs);
1.152 raeburn 9000: if (ref($servers) eq 'HASH') {
1.145 raeburn 9001: foreach my $lonhost (sort(keys(%{$servers}))) {
9002: my $gotspares;
1.152 raeburn 9003: if (ref($settings) eq 'HASH') {
9004: if (ref($settings->{'spares'}) eq 'HASH') {
9005: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9006: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9007: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9008: $gotspares = 1;
9009: }
1.145 raeburn 9010: }
9011: }
9012: unless ($gotspares) {
9013: my $gotspares;
9014: my $serverhomeID =
9015: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9016: my $serverhomedom =
9017: &Apache::lonnet::host_domain($serverhomeID);
9018: if ($serverhomedom ne $dom) {
9019: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9020: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9021: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9022: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9023: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9024: $gotspares = 1;
9025: }
9026: }
9027: } else {
9028: $otherdomconfigs{$serverhomedom} =
9029: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9030: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9031: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9032: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9033: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9034: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9035: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9036: $gotspares = 1;
9037: }
9038: }
9039: }
9040: }
9041: }
9042: }
9043: }
9044: unless ($gotspares) {
9045: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9046: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9047: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9048: } else {
9049: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9050: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9051: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9052: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9053: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9054: } else {
1.150 raeburn 9055: my %what = (
9056: spareid => 1,
9057: );
9058: my ($result,$returnhash) =
9059: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9060: if ($result eq 'ok') {
9061: if (ref($returnhash) eq 'HASH') {
9062: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9063: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9064: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9065: }
9066: }
1.145 raeburn 9067: }
9068: }
9069: }
9070: }
9071: }
9072: }
9073: return %spareid;
9074: }
9075:
9076: sub spares_row {
1.371 raeburn 9077: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9078: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9079: my $css_class;
9080: my $numinrow = 4;
9081: my $itemcount = 1;
9082: my $datatable;
1.152 raeburn 9083: my %typetitles = &sparestype_titles();
9084: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9085: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9086: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9087: my ($othercontrol,$serverdom);
9088: if ($serverhome ne $server) {
9089: $serverdom = &Apache::lonnet::host_domain($serverhome);
9090: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9091: } else {
9092: $serverdom = &Apache::lonnet::host_domain($server);
9093: if ($serverdom ne $dom) {
9094: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9095: }
9096: }
9097: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9098: my ($checkednow,$checkedoth);
1.261 raeburn 9099: if (ref($curroffloadnow) eq 'HASH') {
9100: if ($curroffloadnow->{$server}) {
9101: $checkednow = ' checked="checked"';
9102: }
9103: }
1.371 raeburn 9104: if (ref($curroffloadoth) eq 'HASH') {
9105: if ($curroffloadoth->{$server}) {
9106: $checkedoth = ' checked="checked"';
9107: }
9108: }
1.145 raeburn 9109: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9110: $datatable .= '<tr'.$css_class.'>
9111: <td rowspan="2">
1.183 bisitz 9112: <span class="LC_nobreak">'.
9113: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9114: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9115: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9116: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9117: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9118: "\n";
1.371 raeburn 9119: if ($other_insts) {
9120: $datatable .= '<br />'.
9121: '<span class="LC_nobreak">'."\n".
9122: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9123: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9124: "\n";
9125: }
1.145 raeburn 9126: my (%current,%canselect);
1.152 raeburn 9127: my @choices =
9128: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9129: foreach my $type ('primary','default') {
9130: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9131: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9132: my @spares = @{$spareid->{$server}{$type}};
9133: if (@spares > 0) {
1.152 raeburn 9134: if ($othercontrol) {
9135: $current{$type} = join(', ',@spares);
9136: } else {
9137: $current{$type} .= '<table>';
9138: my $numspares = scalar(@spares);
9139: for (my $i=0; $i<@spares; $i++) {
9140: my $rem = $i%($numinrow);
9141: if ($rem == 0) {
9142: if ($i > 0) {
9143: $current{$type} .= '</tr>';
9144: }
9145: $current{$type} .= '<tr>';
1.145 raeburn 9146: }
1.152 raeburn 9147: $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'".');" /> '.
9148: $spareid->{$server}{$type}[$i].
9149: '</label></td>'."\n";
9150: }
9151: my $rem = @spares%($numinrow);
9152: my $colsleft = $numinrow - $rem;
9153: if ($colsleft > 1 ) {
9154: $current{$type} .= '<td colspan="'.$colsleft.
9155: '" class="LC_left_item">'.
9156: ' </td>';
9157: } elsif ($colsleft == 1) {
9158: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9159: }
1.152 raeburn 9160: $current{$type} .= '</tr></table>';
1.150 raeburn 9161: }
1.145 raeburn 9162: }
9163: }
9164: if ($current{$type} eq '') {
9165: $current{$type} = &mt('None specified');
9166: }
1.152 raeburn 9167: if ($othercontrol) {
9168: if ($type eq 'primary') {
9169: $canselect{$type} = $othercontrol;
9170: }
9171: } else {
9172: $canselect{$type} =
9173: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9174: '<select name="newspare_'.$type.'_'.$server.'" '.
9175: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9176: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9177: if (@choices > 0) {
9178: foreach my $lonhost (@choices) {
9179: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9180: }
9181: }
9182: $canselect{$type} .= '</select>'."\n";
9183: }
9184: } else {
9185: $current{$type} = &mt('Could not be determined');
9186: if ($type eq 'primary') {
9187: $canselect{$type} = $othercontrol;
9188: }
1.145 raeburn 9189: }
1.152 raeburn 9190: if ($type eq 'default') {
9191: $datatable .= '<tr'.$css_class.'>';
9192: }
9193: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9194: '<td>'.$current{$type}.'</td>'."\n".
9195: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9196: }
9197: $itemcount ++;
9198: }
9199: }
9200: $$rowtotal += $itemcount;
9201: return $datatable;
9202: }
9203:
1.152 raeburn 9204: sub possible_newspares {
9205: my ($server,$currspares,$serverhomes,$altids) = @_;
9206: my $serverhostname = &Apache::lonnet::hostname($server);
9207: my %excluded;
9208: if ($serverhostname ne '') {
9209: %excluded = (
9210: $serverhostname => 1,
9211: );
9212: }
9213: if (ref($currspares) eq 'HASH') {
9214: foreach my $type (keys(%{$currspares})) {
9215: if (ref($currspares->{$type}) eq 'ARRAY') {
9216: if (@{$currspares->{$type}} > 0) {
9217: foreach my $curr (@{$currspares->{$type}}) {
9218: my $hostname = &Apache::lonnet::hostname($curr);
9219: $excluded{$hostname} = 1;
9220: }
9221: }
9222: }
9223: }
9224: }
9225: my @choices;
9226: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9227: if (keys(%{$serverhomes}) > 1) {
9228: foreach my $name (sort(keys(%{$serverhomes}))) {
9229: unless ($excluded{$name}) {
9230: if (exists($altids->{$serverhomes->{$name}})) {
9231: push(@choices,$altids->{$serverhomes->{$name}});
9232: } else {
9233: push(@choices,$serverhomes->{$name});
1.145 raeburn 9234: }
9235: }
9236: }
9237: }
9238: }
1.152 raeburn 9239: return sort(@choices);
1.145 raeburn 9240: }
9241:
1.150 raeburn 9242: sub print_loadbalancing {
9243: my ($dom,$settings,$rowtotal) = @_;
9244: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9245: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9246: my $numinrow = 1;
9247: my $datatable;
9248: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9249: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9250: if (ref($settings) eq 'HASH') {
9251: %existing = %{$settings};
9252: }
9253: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9254: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9255: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9256: } else {
9257: return;
9258: }
9259: my ($othertitle,$usertypes,$types) =
9260: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9261: my $rownum = 8;
1.150 raeburn 9262: if (ref($types) eq 'ARRAY') {
9263: $rownum += scalar(@{$types});
9264: }
1.171 raeburn 9265: my @css_class = ('LC_odd_row','LC_even_row');
9266: my $balnum = 0;
9267: my $islast;
9268: my (@toshow,$disabledtext);
9269: if (keys(%currbalancer) > 0) {
9270: @toshow = sort(keys(%currbalancer));
9271: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9272: push(@toshow,'');
9273: }
9274: } else {
9275: @toshow = ('');
9276: $disabledtext = &mt('No existing load balancer');
9277: }
9278: foreach my $lonhost (@toshow) {
9279: if ($balnum == scalar(@toshow)-1) {
9280: $islast = 1;
9281: } else {
9282: $islast = 0;
9283: }
9284: my $cssidx = $balnum%2;
9285: my $targets_div_style = 'display: none';
9286: my $disabled_div_style = 'display: block';
9287: my $homedom_div_style = 'display: none';
9288: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9289: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9290: '<p>';
9291: if ($lonhost eq '') {
1.210 raeburn 9292: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9293: if (keys(%currbalancer) > 0) {
9294: $datatable .= &mt('Add balancer:');
9295: } else {
9296: $datatable .= &mt('Enable balancer:');
9297: }
9298: $datatable .= ' '.
9299: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9300: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9301: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9302: '<option value="" selected="selected">'.&mt('None').
9303: '</option>'."\n";
9304: foreach my $server (sort(keys(%servers))) {
9305: next if ($currbalancer{$server});
9306: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9307: }
1.210 raeburn 9308: $datatable .=
1.171 raeburn 9309: '</select>'."\n".
9310: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9311: } else {
9312: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9313: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9314: &mt('Stop balancing').'</label>'.
9315: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9316: $targets_div_style = 'display: block';
9317: $disabled_div_style = 'display: none';
9318: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9319: $homedom_div_style = 'display: block';
9320: }
9321: }
1.306 raeburn 9322: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9323: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9324: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9325: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9326: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9327: my @sparestypes = ('primary','default');
9328: my %typetitles = &sparestype_titles();
1.284 raeburn 9329: my %hostherechecked = (
9330: no => ' checked="checked"',
9331: );
1.342 raeburn 9332: my %balcookiechecked = (
1.425 raeburn 9333: no => ' checked="checked"',
1.342 raeburn 9334: );
1.171 raeburn 9335: foreach my $sparetype (@sparestypes) {
9336: my $targettable;
9337: for (my $i=0; $i<$numspares; $i++) {
9338: my $checked;
9339: if (ref($currtargets{$lonhost}) eq 'HASH') {
9340: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9341: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9342: $checked = ' checked="checked"';
9343: }
9344: }
9345: }
9346: my ($chkboxval,$disabled);
9347: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9348: $chkboxval = $spares[$i];
9349: }
9350: if (exists($currbalancer{$spares[$i]})) {
9351: $disabled = ' disabled="disabled"';
9352: }
1.210 raeburn 9353: $targettable .=
1.253 raeburn 9354: '<td><span class="LC_nobreak"><label>'.
9355: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9356: $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 9357: '</span></label></span></td>';
1.171 raeburn 9358: my $rem = $i%($numinrow);
9359: if ($rem == 0) {
9360: if (($i > 0) && ($i < $numspares-1)) {
9361: $targettable .= '</tr>';
9362: }
9363: if ($i < $numspares-1) {
9364: $targettable .= '<tr>';
1.150 raeburn 9365: }
9366: }
9367: }
1.171 raeburn 9368: if ($targettable ne '') {
9369: my $rem = $numspares%($numinrow);
9370: my $colsleft = $numinrow - $rem;
9371: if ($colsleft > 1 ) {
9372: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9373: ' </td>';
9374: } elsif ($colsleft == 1) {
9375: $targettable .= '<td class="LC_left_item"> </td>';
9376: }
9377: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9378: '<table><tr>'.$targettable.'</tr></table><br />';
9379: }
1.284 raeburn 9380: $hostherechecked{$sparetype} = '';
9381: if (ref($currtargets{$lonhost}) eq 'HASH') {
9382: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9383: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9384: $hostherechecked{$sparetype} = ' checked="checked"';
9385: $hostherechecked{'no'} = '';
9386: }
9387: }
9388: }
9389: }
1.342 raeburn 9390: if ($currcookies{$lonhost}) {
9391: %balcookiechecked = (
9392: yes => ' checked="checked"',
9393: );
9394: }
1.284 raeburn 9395: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9396: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9397: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9398: foreach my $sparetype (@sparestypes) {
9399: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9400: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9401: '</i></label><br />';
1.171 raeburn 9402: }
1.342 raeburn 9403: $datatable .= &mt('Use balancer cookie').'<br />'.
9404: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9405: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9406: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9407: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9408: '</div></td></tr>'.
1.171 raeburn 9409: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9410: $othertitle,$usertypes,$types,\%servers,
9411: \%currbalancer,$lonhost,
9412: $targets_div_style,$homedom_div_style,
9413: $css_class[$cssidx],$balnum,$islast);
9414: $$rowtotal += $rownum;
9415: $balnum ++;
9416: }
9417: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9418: return $datatable;
9419: }
9420:
9421: sub get_loadbalancers_config {
1.342 raeburn 9422: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9423: return unless ((ref($servers) eq 'HASH') &&
9424: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9425: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9426: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9427: if (keys(%{$existing}) > 0) {
9428: my $oldlonhost;
9429: foreach my $key (sort(keys(%{$existing}))) {
9430: if ($key eq 'lonhost') {
9431: $oldlonhost = $existing->{'lonhost'};
9432: $currbalancer->{$oldlonhost} = 1;
9433: } elsif ($key eq 'targets') {
9434: if ($oldlonhost) {
9435: $currtargets->{$oldlonhost} = $existing->{'targets'};
9436: }
9437: } elsif ($key eq 'rules') {
9438: if ($oldlonhost) {
9439: $currrules->{$oldlonhost} = $existing->{'rules'};
9440: }
9441: } elsif (ref($existing->{$key}) eq 'HASH') {
9442: $currbalancer->{$key} = 1;
9443: $currtargets->{$key} = $existing->{$key}{'targets'};
9444: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9445: if ($existing->{$key}{'cookie'}) {
9446: $currcookies->{$key} = 1;
9447: }
1.150 raeburn 9448: }
9449: }
1.171 raeburn 9450: } else {
9451: my ($balancerref,$targetsref) =
9452: &Apache::lonnet::get_lonbalancer_config($servers);
9453: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9454: foreach my $server (sort(keys(%{$balancerref}))) {
9455: $currbalancer->{$server} = 1;
9456: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9457: }
9458: }
9459: }
1.171 raeburn 9460: return;
1.150 raeburn 9461: }
9462:
9463: sub loadbalancing_rules {
9464: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9465: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9466: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9467: my $output;
1.171 raeburn 9468: my $num = 0;
1.210 raeburn 9469: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9470: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9471: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9472: foreach my $type (@{$alltypes}) {
1.171 raeburn 9473: $num ++;
1.150 raeburn 9474: my $current;
9475: if (ref($currrules) eq 'HASH') {
9476: $current = $currrules->{$type};
9477: }
1.253 raeburn 9478: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9479: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9480: $current = '';
9481: }
9482: }
9483: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9484: $servers,$currbalancer,$lonhost,$dom,
9485: $targets_div_style,$homedom_div_style,
9486: $css_class,$balnum,$num,$islast);
1.150 raeburn 9487: }
9488: }
9489: return $output;
9490: }
9491:
9492: sub loadbalancing_titles {
9493: my ($dom,$intdom,$usertypes,$types) = @_;
9494: my %othertypes = (
9495: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9496: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9497: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9498: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9499: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9500: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9501: );
1.209 raeburn 9502: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9503: my @available;
1.150 raeburn 9504: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9505: @available = @{$types};
1.150 raeburn 9506: }
1.302 raeburn 9507: unless (grep(/^default$/,@available)) {
9508: push(@available,'default');
9509: }
9510: unshift(@alltypes,@available);
1.150 raeburn 9511: my %titles;
9512: foreach my $type (@alltypes) {
9513: if ($type =~ /^_LC_/) {
9514: $titles{$type} = $othertypes{$type};
9515: } elsif ($type eq 'default') {
9516: $titles{$type} = &mt('All users from [_1]',$dom);
9517: if (ref($types) eq 'ARRAY') {
9518: if (@{$types} > 0) {
9519: $titles{$type} = &mt('Other users from [_1]',$dom);
9520: }
9521: }
9522: } elsif (ref($usertypes) eq 'HASH') {
9523: $titles{$type} = $usertypes->{$type};
9524: }
9525: }
9526: return (\@alltypes,\%othertypes,\%titles);
9527: }
9528:
9529: sub loadbalance_rule_row {
1.171 raeburn 9530: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9531: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9532: my @rulenames;
1.150 raeburn 9533: my %ruletitles = &offloadtype_text();
1.209 raeburn 9534: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9535: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9536: } else {
1.209 raeburn 9537: @rulenames = ('default','homeserver');
9538: if ($type eq '_LC_external') {
9539: push(@rulenames,'externalbalancer');
9540: } else {
9541: push(@rulenames,'specific');
9542: }
9543: push(@rulenames,'none');
1.150 raeburn 9544: }
9545: my $style = $targets_div_style;
1.253 raeburn 9546: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9547: $style = $homedom_div_style;
9548: }
1.171 raeburn 9549: my $space;
9550: if ($islast && $num == 1) {
1.317 raeburn 9551: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9552: }
1.210 raeburn 9553: my $output =
1.306 raeburn 9554: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9555: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9556: '<td valaign="top">'.$space.
9557: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9558: for (my $i=0; $i<@rulenames; $i++) {
9559: my $rule = $rulenames[$i];
9560: my ($checked,$extra);
9561: if ($rulenames[$i] eq 'default') {
9562: $rule = '';
9563: }
9564: if ($rulenames[$i] eq 'specific') {
9565: if (ref($servers) eq 'HASH') {
9566: my $default;
9567: if (($current ne '') && (exists($servers->{$current}))) {
9568: $checked = ' checked="checked"';
9569: }
9570: unless ($checked) {
9571: $default = ' selected="selected"';
9572: }
1.210 raeburn 9573: $extra =
1.171 raeburn 9574: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9575: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9576: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9577: '<option value=""'.$default.'></option>'."\n";
9578: foreach my $server (sort(keys(%{$servers}))) {
9579: if (ref($currbalancer) eq 'HASH') {
9580: next if (exists($currbalancer->{$server}));
9581: }
1.150 raeburn 9582: my $selected;
1.171 raeburn 9583: if ($server eq $current) {
1.150 raeburn 9584: $selected = ' selected="selected"';
9585: }
1.171 raeburn 9586: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9587: }
9588: $extra .= '</select>';
9589: }
9590: } elsif ($rule eq $current) {
9591: $checked = ' checked="checked"';
9592: }
9593: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9594: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9595: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9596: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9597: ')"'.$checked.' /> ';
9598: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9599: $output .= $ruletitles{'particular'};
9600: } else {
9601: $output .= $ruletitles{$rulenames[$i]};
9602: }
9603: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9604: }
9605: $output .= '</div></td></tr>'."\n";
9606: return $output;
9607: }
9608:
9609: sub offloadtype_text {
9610: my %ruletitles = &Apache::lonlocal::texthash (
9611: 'default' => 'Offloads to default destinations',
9612: 'homeserver' => "Offloads to user's home server",
9613: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9614: 'specific' => 'Offloads to specific server',
1.161 raeburn 9615: 'none' => 'No offload',
1.209 raeburn 9616: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9617: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9618: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9619: );
9620: return %ruletitles;
9621: }
9622:
9623: sub sparestype_titles {
9624: my %typestitles = &Apache::lonlocal::texthash (
9625: 'primary' => 'primary',
9626: 'default' => 'default',
9627: );
9628: return %typestitles;
9629: }
9630:
1.28 raeburn 9631: sub contact_titles {
9632: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9633: 'supportemail' => 'Support E-mail address',
9634: 'adminemail' => 'Default Server Admin E-mail address',
9635: 'errormail' => 'Error reports to be e-mailed to',
9636: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9637: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9638: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9639: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9640: 'requestsmail' => 'E-mail from course requests requiring approval',
9641: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9642: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9643: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9644: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9645: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9646: 'errorweights' => 'Weights used to compute error count',
9647: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9648: );
9649: my %short_titles = &Apache::lonlocal::texthash (
9650: adminemail => 'Admin E-mail address',
9651: supportemail => 'Support E-mail',
9652: );
9653: return (\%titles,\%short_titles);
9654: }
9655:
1.286 raeburn 9656: sub helpform_fields {
9657: my %titles = &Apache::lonlocal::texthash (
9658: 'username' => 'Name',
9659: 'user' => 'Username/domain',
9660: 'phone' => 'Phone',
9661: 'cc' => 'Cc e-mail',
9662: 'course' => 'Course Details',
9663: 'section' => 'Sections',
1.289 raeburn 9664: 'screenshot' => 'File upload',
1.286 raeburn 9665: );
9666: my @fields = ('username','phone','user','course','section','cc','screenshot');
9667: my %possoptions = (
9668: username => ['yes','no','req'],
1.289 raeburn 9669: phone => ['yes','no','req'],
1.286 raeburn 9670: user => ['yes','no'],
1.289 raeburn 9671: cc => ['yes','no'],
1.286 raeburn 9672: course => ['yes','no'],
9673: section => ['yes','no'],
9674: screenshot => ['yes','no'],
9675: );
9676: my %fieldoptions = &Apache::lonlocal::texthash (
9677: 'yes' => 'Optional',
9678: 'req' => 'Required',
9679: 'no' => "Not shown",
9680: );
9681: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9682: }
9683:
1.72 raeburn 9684: sub tool_titles {
9685: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9686: aboutme => 'Personal web page',
1.86 raeburn 9687: blog => 'Blog',
9688: portfolio => 'Portfolio',
1.430 raeburn 9689: portaccess => 'Share portfolio files',
1.413 raeburn 9690: timezone => 'Can set time zone',
1.88 bisitz 9691: official => 'Official courses (with institutional codes)',
9692: unofficial => 'Unofficial courses',
1.98 raeburn 9693: community => 'Communities',
1.216 raeburn 9694: textbook => 'Textbook courses',
1.271 raeburn 9695: placement => 'Placement tests',
1.86 raeburn 9696: );
1.72 raeburn 9697: return %titles;
9698: }
9699:
1.101 raeburn 9700: sub courserequest_titles {
9701: my %titles = &Apache::lonlocal::texthash (
9702: official => 'Official',
9703: unofficial => 'Unofficial',
9704: community => 'Communities',
1.216 raeburn 9705: textbook => 'Textbook',
1.271 raeburn 9706: placement => 'Placement tests',
1.325 raeburn 9707: lti => 'LTI Provider',
1.101 raeburn 9708: norequest => 'Not allowed',
1.325 raeburn 9709: approval => 'Approval by DC',
1.101 raeburn 9710: validate => 'With validation',
9711: autolimit => 'Numerical limit',
1.103 raeburn 9712: unlimited => '(blank for unlimited)',
1.101 raeburn 9713: );
9714: return %titles;
9715: }
9716:
1.163 raeburn 9717: sub authorrequest_titles {
9718: my %titles = &Apache::lonlocal::texthash (
9719: norequest => 'Not allowed',
9720: approval => 'Approval by Dom. Coord.',
9721: automatic => 'Automatic approval',
9722: );
9723: return %titles;
1.210 raeburn 9724: }
1.163 raeburn 9725:
1.101 raeburn 9726: sub courserequest_conditions {
9727: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9728: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9729: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9730: );
9731: return %conditions;
9732: }
9733:
9734:
1.27 raeburn 9735: sub print_usercreation {
1.30 raeburn 9736: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9737: my $numinrow = 4;
1.28 raeburn 9738: my $datatable;
9739: if ($position eq 'top') {
1.30 raeburn 9740: $$rowtotal ++;
1.34 raeburn 9741: my $rowcount = 0;
1.32 raeburn 9742: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9743: if (ref($rules) eq 'HASH') {
9744: if (keys(%{$rules}) > 0) {
1.32 raeburn 9745: $datatable .= &user_formats_row('username',$settings,$rules,
9746: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9747: $$rowtotal ++;
1.32 raeburn 9748: $rowcount ++;
9749: }
9750: }
9751: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9752: if (ref($idrules) eq 'HASH') {
9753: if (keys(%{$idrules}) > 0) {
9754: $datatable .= &user_formats_row('id',$settings,$idrules,
9755: $idruleorder,$numinrow,$rowcount);
9756: $$rowtotal ++;
9757: $rowcount ++;
1.28 raeburn 9758: }
9759: }
1.39 raeburn 9760: if ($rowcount == 0) {
9761: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9762: $$rowtotal ++;
9763: $rowcount ++;
9764: }
1.34 raeburn 9765: } elsif ($position eq 'middle') {
1.224 raeburn 9766: my @creators = ('author','course','requestcrs');
1.37 raeburn 9767: my ($rules,$ruleorder) =
9768: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9769: my %lt = &usercreation_types();
9770: my %checked;
9771: if (ref($settings) eq 'HASH') {
9772: if (ref($settings->{'cancreate'}) eq 'HASH') {
9773: foreach my $item (@creators) {
9774: $checked{$item} = $settings->{'cancreate'}{$item};
9775: }
9776: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9777: foreach my $item (@creators) {
9778: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9779: $checked{$item} = 'none';
9780: }
9781: }
9782: }
9783: }
9784: my $rownum = 0;
9785: foreach my $item (@creators) {
9786: $rownum ++;
1.224 raeburn 9787: if ($checked{$item} eq '') {
9788: $checked{$item} = 'any';
1.34 raeburn 9789: }
9790: my $css_class;
9791: if ($rownum%2) {
9792: $css_class = '';
9793: } else {
9794: $css_class = ' class="LC_odd_row" ';
9795: }
9796: $datatable .= '<tr'.$css_class.'>'.
9797: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9798: '</span></td><td style="text-align: right">';
1.224 raeburn 9799: my @options = ('any');
9800: if (ref($rules) eq 'HASH') {
9801: if (keys(%{$rules}) > 0) {
9802: push(@options,('official','unofficial'));
1.37 raeburn 9803: }
9804: }
1.224 raeburn 9805: push(@options,'none');
1.37 raeburn 9806: foreach my $option (@options) {
1.50 raeburn 9807: my $type = 'radio';
1.34 raeburn 9808: my $check = ' ';
1.224 raeburn 9809: if ($checked{$item} eq $option) {
9810: $check = ' checked="checked" ';
1.34 raeburn 9811: }
9812: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9813: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9814: $item.'" value="'.$option.'"'.$check.'/> '.
9815: $lt{$option}.'</label> </span>';
9816: }
9817: $datatable .= '</td></tr>';
9818: }
1.28 raeburn 9819: } else {
9820: my @contexts = ('author','course','domain');
1.325 raeburn 9821: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9822: my %checked;
9823: if (ref($settings) eq 'HASH') {
9824: if (ref($settings->{'authtypes'}) eq 'HASH') {
9825: foreach my $item (@contexts) {
9826: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9827: foreach my $auth (@authtypes) {
9828: if ($settings->{'authtypes'}{$item}{$auth}) {
9829: $checked{$item}{$auth} = ' checked="checked" ';
9830: }
9831: }
9832: }
9833: }
1.27 raeburn 9834: }
1.35 raeburn 9835: } else {
9836: foreach my $item (@contexts) {
1.36 raeburn 9837: foreach my $auth (@authtypes) {
1.35 raeburn 9838: $checked{$item}{$auth} = ' checked="checked" ';
9839: }
9840: }
1.27 raeburn 9841: }
1.28 raeburn 9842: my %title = &context_names();
9843: my %authname = &authtype_names();
9844: my $rownum = 0;
9845: my $css_class;
9846: foreach my $item (@contexts) {
9847: if ($rownum%2) {
9848: $css_class = '';
9849: } else {
9850: $css_class = ' class="LC_odd_row" ';
9851: }
1.30 raeburn 9852: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9853: '<td>'.$title{$item}.
9854: '</td><td class="LC_left_item">'.
9855: '<span class="LC_nobreak">';
9856: foreach my $auth (@authtypes) {
9857: $datatable .= '<label>'.
9858: '<input type="checkbox" name="'.$item.'_auth" '.
9859: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9860: $authname{$auth}.'</label> ';
9861: }
9862: $datatable .= '</span></td></tr>';
9863: $rownum ++;
1.27 raeburn 9864: }
1.30 raeburn 9865: $$rowtotal += $rownum;
1.27 raeburn 9866: }
9867: return $datatable;
9868: }
9869:
1.224 raeburn 9870: sub print_selfcreation {
9871: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9872: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9873: $emaildomain,$datatable);
1.224 raeburn 9874: if (ref($settings) eq 'HASH') {
9875: if (ref($settings->{'cancreate'}) eq 'HASH') {
9876: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9877: if (ref($createsettings) eq 'HASH') {
9878: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9879: @selfcreate = @{$createsettings->{'selfcreate'}};
9880: } elsif ($createsettings->{'selfcreate'} ne '') {
9881: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9882: @selfcreate = ('email','login','sso');
9883: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9884: @selfcreate = ($createsettings->{'selfcreate'});
9885: }
9886: }
9887: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9888: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9889: }
1.305 raeburn 9890: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9891: $emailoptions = $createsettings->{'emailoptions'};
9892: }
1.303 raeburn 9893: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9894: $emailverified = $createsettings->{'emailverified'};
9895: }
9896: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9897: $emaildomain = $createsettings->{'emaildomain'};
9898: }
1.224 raeburn 9899: }
9900: }
9901: }
9902: my %radiohash;
9903: my $numinrow = 4;
9904: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9905: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9906: if ($position eq 'top') {
9907: my %choices = &Apache::lonlocal::texthash (
9908: cancreate_login => 'Institutional Login',
9909: cancreate_sso => 'Institutional Single Sign On',
9910: );
9911: my @toggles = sort(keys(%choices));
9912: my %defaultchecked = (
9913: 'cancreate_login' => 'off',
9914: 'cancreate_sso' => 'off',
9915: );
1.228 raeburn 9916: my ($onclick,$itemcount);
1.224 raeburn 9917: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9918: \%choices,$itemcount,$onclick);
1.228 raeburn 9919: $$rowtotal += $itemcount;
1.425 raeburn 9920:
1.224 raeburn 9921: if (ref($usertypes) eq 'HASH') {
9922: if (keys(%{$usertypes}) > 0) {
9923: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9924: $dom,$numinrow,$othertitle,
1.305 raeburn 9925: 'statustocreate',$rowtotal);
1.224 raeburn 9926: $$rowtotal ++;
9927: }
9928: }
1.240 raeburn 9929: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
9930: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9931: $fieldtitles{'inststatus'} = &mt('Institutional status');
9932: my $rem;
9933: my $numperrow = 2;
9934: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
9935: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 9936: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 9937: '<td class="LC_left_item">'."\n".
1.334 raeburn 9938: '<table>'."\n";
1.240 raeburn 9939: for (my $i=0; $i<@fields; $i++) {
9940: $rem = $i%($numperrow);
9941: if ($rem == 0) {
9942: if ($i > 0) {
9943: $datatable .= '</tr>';
9944: }
9945: $datatable .= '<tr>';
9946: }
9947: my $currval;
1.248 raeburn 9948: if (ref($createsettings) eq 'HASH') {
9949: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
9950: $currval = $createsettings->{'shibenv'}{$fields[$i]};
9951: }
1.240 raeburn 9952: }
9953: $datatable .= '<td class="LC_left_item">'.
9954: '<span class="LC_nobreak">'.
9955: '<input type="text" name="shibenv_'.$fields[$i].'" '.
9956: 'value="'.$currval.'" size="10" /> '.
9957: $fieldtitles{$fields[$i]}.'</span></td>';
9958: }
9959: my $colsleft = $numperrow - $rem;
9960: if ($colsleft > 1 ) {
9961: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9962: ' </td>';
9963: } elsif ($colsleft == 1) {
9964: $datatable .= '<td class="LC_left_item"> </td>';
9965: }
9966: $datatable .= '</tr></table></td></tr>';
9967: $$rowtotal ++;
1.224 raeburn 9968: } elsif ($position eq 'middle') {
9969: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 9970: my @posstypes;
1.224 raeburn 9971: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9972: @posstypes = @{$types};
9973: }
9974: unless (grep(/^default$/,@posstypes)) {
9975: push(@posstypes,'default');
9976: }
9977: my %usertypeshash;
9978: if (ref($usertypes) eq 'HASH') {
9979: %usertypeshash = %{$usertypes};
9980: }
9981: $usertypeshash{'default'} = $othertitle;
9982: foreach my $status (@posstypes) {
9983: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
9984: $numinrow,$$rowtotal,\%usertypeshash);
9985: $$rowtotal ++;
1.224 raeburn 9986: }
9987: } else {
1.236 raeburn 9988: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 9989: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 9990: );
9991: my @toggles = sort(keys(%choices));
9992: my %defaultchecked = (
9993: 'cancreate_email' => 'off',
9994: );
1.305 raeburn 9995: my $customclass = 'LC_selfcreate_email';
9996: my $classprefix = 'LC_canmodify_emailusername_';
9997: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 9998: my $display = 'none';
1.305 raeburn 9999: my $rowstyle = 'display:none';
1.236 raeburn 10000: if (grep(/^\Qemail\E$/,@selfcreate)) {
10001: $display = 'block';
1.305 raeburn 10002: $rowstyle = 'display:table-row';
1.236 raeburn 10003: }
1.305 raeburn 10004: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10005: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10006: \%choices,$$rowtotal,$onclick);
10007: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10008: $rowstyle);
10009: $$rowtotal ++;
10010: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10011: $rowstyle);
10012: $$rowtotal ++;
10013: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10014: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10015: my ($emailrules,$emailruleorder) =
10016: &Apache::lonnet::inst_userrules($dom,'email');
10017: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10018: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10019: if (ref($types) eq 'ARRAY') {
10020: @posstypes = @{$types};
10021: }
10022: if (@posstypes) {
10023: unless (grep(/^default$/,@posstypes)) {
10024: push(@posstypes,'default');
1.302 raeburn 10025: }
10026: if (ref($usertypes) eq 'HASH') {
10027: %usertypeshash = %{$usertypes};
10028: }
1.305 raeburn 10029: my $currassign;
10030: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10031: $currassign = {
10032: selfassign => $domdefaults{'inststatusguest'},
10033: };
10034: @ordered = @{$domdefaults{'inststatusguest'}};
10035: } else {
10036: $currassign = { selfassign => [] };
10037: }
10038: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10039: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10040: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10041: $numinrow,$othertitle,'selfassign',
10042: $rowtotal,$onclicktypes,$customclass,
10043: $rowstyle);
10044: $$rowtotal ++;
1.302 raeburn 10045: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10046: foreach my $status (@posstypes) {
10047: my $css_class;
10048: if ($$rowtotal%2) {
10049: $css_class = 'LC_odd_row ';
10050: }
10051: $css_class .= $customclass;
10052: my $rowid = $optionsprefix.$status;
10053: my $hidden = 1;
10054: my $currstyle = 'display:none';
10055: if (grep(/^\Q$status\E$/,@ordered)) {
10056: $currstyle = $rowstyle;
1.425 raeburn 10057: $hidden = 0;
1.305 raeburn 10058: }
10059: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10060: $emailrules,$emailruleorder,$settings,$status,$rowid,
10061: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10062: unless ($hidden) {
10063: $$rowtotal ++;
10064: }
1.224 raeburn 10065: }
1.302 raeburn 10066: } else {
1.305 raeburn 10067: my $css_class;
10068: if ($$rowtotal%2) {
10069: $css_class = 'LC_odd_row ';
10070: }
10071: $css_class .= $customclass;
1.302 raeburn 10072: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10073: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10074: $emailrules,$emailruleorder,$settings,'default','',
10075: $othertitle,$css_class,$rowstyle,$intdom);
10076: $$rowtotal ++;
1.224 raeburn 10077: }
10078: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10079: $numinrow = 1;
1.305 raeburn 10080: if (@posstypes) {
10081: foreach my $status (@posstypes) {
10082: my $rowid = $classprefix.$status;
10083: my $datarowstyle = 'display:none';
1.425 raeburn 10084: if (grep(/^\Q$status\E$/,@ordered)) {
10085: $datarowstyle = $rowstyle;
1.305 raeburn 10086: }
10087: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10088: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10089: $infotitles,$rowid,$customclass,$datarowstyle);
10090: unless ($datarowstyle eq 'display:none') {
10091: $$rowtotal ++;
10092: }
1.224 raeburn 10093: }
1.305 raeburn 10094: } else {
10095: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10096: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10097: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10098: }
10099: }
10100: return $datatable;
10101: }
10102:
1.305 raeburn 10103: sub selfcreate_javascript {
10104: return <<"ENDSCRIPT";
10105:
10106: <script type="text/javascript">
10107: // <![CDATA[
10108:
10109: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10110: var x = document.getElementsByClassName(target);
10111: var insttypes = 0;
10112: var insttypeRegExp = new RegExp(prefix);
10113: if ((x.length != undefined) && (x.length > 0)) {
10114: if (form.elements[radio].length != undefined) {
10115: for (var i=0; i<form.elements[radio].length; i++) {
10116: if (form.elements[radio][i].checked) {
10117: if (form.elements[radio][i].value == 1) {
10118: for (var j=0; j<x.length; j++) {
10119: if (x[j].id == 'undefined') {
10120: x[j].style.display = 'table-row';
10121: } else if (insttypeRegExp.test(x[j].id)) {
10122: insttypes ++;
10123: } else {
10124: x[j].style.display = 'table-row';
10125: }
10126: }
10127: } else {
10128: for (var j=0; j<x.length; j++) {
10129: x[j].style.display = 'none';
10130: }
1.236 raeburn 10131: }
1.305 raeburn 10132: break;
10133: }
10134: }
10135: if (insttypes > 0) {
10136: toggleDataRow(form,checkbox,target,altprefix);
10137: toggleDataRow(form,checkbox,target,prefix,1);
10138: }
10139: }
10140: }
10141: return;
10142: }
10143:
10144: function toggleDataRow(form,checkbox,target,prefix,docount) {
10145: if (form.elements[checkbox].length != undefined) {
10146: var count = 0;
10147: if (docount) {
10148: for (var i=0; i<form.elements[checkbox].length; i++) {
10149: if (form.elements[checkbox][i].checked) {
10150: count ++;
1.236 raeburn 10151: }
1.305 raeburn 10152: }
10153: }
10154: for (var i=0; i<form.elements[checkbox].length; i++) {
10155: var type = form.elements[checkbox][i].value;
10156: if (document.getElementById(prefix+type)) {
10157: if (form.elements[checkbox][i].checked) {
10158: document.getElementById(prefix+type).style.display = 'table-row';
10159: if (count % 2 == 1) {
10160: document.getElementById(prefix+type).className = target+' LC_odd_row';
10161: } else {
10162: document.getElementById(prefix+type).className = target;
1.236 raeburn 10163: }
1.305 raeburn 10164: count ++;
1.236 raeburn 10165: } else {
1.305 raeburn 10166: document.getElementById(prefix+type).style.display = 'none';
10167: }
10168: }
10169: }
10170: }
10171: return;
10172: }
10173:
10174: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10175: var caller = radio+'_'+status;
10176: if (form.elements[caller].length != undefined) {
10177: for (var i=0; i<form.elements[caller].length; i++) {
10178: if (form.elements[caller][i].checked) {
10179: if (document.getElementById(altprefix+'_inst_'+status)) {
10180: var curr = form.elements[caller][i].value;
10181: if (prefix) {
10182: document.getElementById(prefix+'_'+status).style.display = 'none';
10183: }
10184: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10185: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10186: if (curr == 'custom') {
1.425 raeburn 10187: if (prefix) {
1.305 raeburn 10188: document.getElementById(prefix+'_'+status).style.display = 'inline';
10189: }
10190: } else if (curr == 'inst') {
10191: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10192: } else if (curr == 'noninst') {
10193: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10194: }
1.305 raeburn 10195: break;
1.236 raeburn 10196: }
10197: }
10198: }
10199: }
10200: }
10201:
1.305 raeburn 10202: // ]]>
10203: </script>
10204:
10205: ENDSCRIPT
10206: }
10207:
10208: sub noninst_users {
10209: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10210: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10211: my $class = 'LC_left_item';
10212: if ($css_class) {
1.425 raeburn 10213: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10214: }
10215: if ($rowid) {
10216: $rowid = ' id="'.$rowid.'"';
10217: }
10218: if ($rowstyle) {
10219: $rowstyle = ' style="'.$rowstyle.'"';
10220: }
10221: my ($output,$description);
10222: if ($type eq 'default') {
10223: $description = &mt('Requests for: [_1]',$typetitle);
10224: } else {
10225: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10226: }
10227: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10228: "<td>$description</td>\n".
1.305 raeburn 10229: '<td class="'.$class.'" colspan="2">'.
10230: '<table><tr>';
1.425 raeburn 10231: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10232: approve => 'Processing',
10233: email => 'E-mail',
10234: username => 'Username',
10235: );
10236: foreach my $item ('approve','email','username') {
10237: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10238: }
1.305 raeburn 10239: $output .= '</tr><tr>';
10240: foreach my $item ('approve','email','username') {
1.306 raeburn 10241: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10242: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10243: if ($item eq 'approve') {
10244: %choices = &Apache::lonlocal::texthash (
10245: automatic => 'Automatically approved',
10246: approval => 'Queued for approval',
10247: );
10248: @options = ('automatic','approval');
10249: $hashref = $processing;
10250: $defoption = 'automatic';
10251: $name = 'cancreate_emailprocess_'.$type;
10252: } elsif ($item eq 'email') {
10253: %choices = &Apache::lonlocal::texthash (
10254: any => 'Any e-mail',
10255: inst => 'Institutional only',
10256: noninst => 'Non-institutional only',
10257: custom => 'Custom restrictions',
10258: );
10259: @options = ('any','inst','noninst');
10260: my $showcustom;
10261: if (ref($emailrules) eq 'HASH') {
10262: if (keys(%{$emailrules}) > 0) {
10263: push(@options,'custom');
10264: $showcustom = 'cancreate_emailrule';
10265: if (ref($settings) eq 'HASH') {
10266: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10267: foreach my $rule (@{$settings->{'email_rule'}}) {
10268: if (exists($emailrules->{$rule})) {
10269: $hascustom ++;
10270: }
10271: }
10272: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10273: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10274: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10275: if (exists($emailrules->{$rule})) {
10276: $hascustom ++;
10277: }
10278: }
10279: }
10280: }
10281: }
10282: }
10283: }
10284: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10285: "'cancreate_emaildomain','$type'".');"';
10286: $hashref = $emailoptions;
10287: $defoption = 'any';
10288: $name = 'cancreate_emailoptions_'.$type;
10289: } elsif ($item eq 'username') {
10290: %choices = &Apache::lonlocal::texthash (
10291: all => 'Same as e-mail',
10292: first => 'Omit @domain',
10293: free => 'Free to choose',
10294: );
10295: @options = ('all','first','free');
10296: $hashref = $emailverified;
10297: $defoption = 'all';
10298: $name = 'cancreate_usernameoptions_'.$type;
10299: }
10300: foreach my $option (@options) {
10301: my $checked;
10302: if (ref($hashref) eq 'HASH') {
10303: if ($type eq '') {
10304: if (!exists($hashref->{'default'})) {
10305: if ($option eq $defoption) {
10306: $checked = ' checked="checked"';
10307: }
10308: } else {
10309: if ($hashref->{'default'} eq $option) {
10310: $checked = ' checked="checked"';
10311: }
1.303 raeburn 10312: }
10313: } else {
1.305 raeburn 10314: if (!exists($hashref->{$type})) {
10315: if ($option eq $defoption) {
10316: $checked = ' checked="checked"';
10317: }
10318: } else {
10319: if ($hashref->{$type} eq $option) {
10320: $checked = ' checked="checked"';
10321: }
1.303 raeburn 10322: }
10323: }
1.305 raeburn 10324: } elsif (($item eq 'email') && ($hascustom)) {
10325: if ($option eq 'custom') {
10326: $checked = ' checked="checked"';
10327: }
10328: } elsif ($option eq $defoption) {
10329: $checked = ' checked="checked"';
10330: }
10331: $output .= '<span class="LC_nobreak"><label>'.
10332: '<input type="radio" name="'.$name.'"'.
10333: $checked.' value="'.$option.'"'.$onclick.' />'.
10334: $choices{$option}.'</label></span><br />';
10335: if ($item eq 'email') {
10336: if ($option eq 'custom') {
10337: my $id = 'cancreate_emailrule_'.$type;
10338: my $display = 'none';
10339: if ($checked) {
10340: $display = 'inline';
1.303 raeburn 10341: }
1.305 raeburn 10342: my $numinrow = 2;
10343: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10344: '<legend>'.&mt('Disallow').'</legend><table>'.
10345: &user_formats_row('email',$settings,$emailrules,
10346: $emailruleorder,$numinrow,'',$type);
10347: '</table></fieldset>';
10348: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10349: my %text = &Apache::lonlocal::texthash (
10350: inst => 'must end:',
10351: noninst => 'cannot end:',
10352: );
10353: my $value;
10354: if (ref($emaildomain) eq 'HASH') {
10355: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10356: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10357: }
10358: }
1.305 raeburn 10359: if ($value eq '') {
10360: $value = '@'.$intdom;
10361: }
10362: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10363: my $display = 'none';
10364: if ($checked) {
10365: $display = 'inline';
10366: }
10367: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10368: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10369: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10370: '</div>';
1.303 raeburn 10371: }
10372: }
10373: }
1.305 raeburn 10374: $output .= '</td>'."\n";
1.303 raeburn 10375: }
1.305 raeburn 10376: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10377: return $output;
10378: }
10379:
1.165 raeburn 10380: sub captcha_choice {
1.305 raeburn 10381: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10382: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10383: $vertext,$currver);
1.165 raeburn 10384: my %lt = &captcha_phrases();
10385: $keyentry = 'hidden';
1.354 raeburn 10386: my $colspan=2;
1.165 raeburn 10387: if ($context eq 'cancreate') {
1.224 raeburn 10388: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10389: } elsif ($context eq 'login') {
10390: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10391: } elsif ($context eq 'passwords') {
10392: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10393: $colspan=1;
1.165 raeburn 10394: }
10395: if (ref($settings) eq 'HASH') {
10396: if ($settings->{'captcha'}) {
10397: $checked{$settings->{'captcha'}} = ' checked="checked"';
10398: } else {
10399: $checked{'original'} = ' checked="checked"';
10400: }
10401: if ($settings->{'captcha'} eq 'recaptcha') {
10402: $pubtext = $lt{'pub'};
10403: $privtext = $lt{'priv'};
10404: $keyentry = 'text';
1.269 raeburn 10405: $vertext = $lt{'ver'};
10406: $currver = $settings->{'recaptchaversion'};
10407: if ($currver ne '2') {
10408: $currver = 1;
10409: }
1.165 raeburn 10410: }
10411: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10412: $currpub = $settings->{'recaptchakeys'}{'public'};
10413: $currpriv = $settings->{'recaptchakeys'}{'private'};
10414: }
10415: } else {
10416: $checked{'original'} = ' checked="checked"';
10417: }
1.305 raeburn 10418: my $css_class;
10419: if ($itemcount%2) {
10420: $css_class = 'LC_odd_row';
10421: }
10422: if ($customcss) {
10423: $css_class .= " $customcss";
10424: }
10425: $css_class =~ s/^\s+//;
10426: if ($css_class) {
10427: $css_class = ' class="'.$css_class.'"';
10428: }
10429: if ($rowstyle) {
10430: $css_class .= ' style="'.$rowstyle.'"';
10431: }
1.169 raeburn 10432: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10433: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10434: '<table><tr><td>'."\n";
10435: foreach my $option ('original','recaptcha','notused') {
10436: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10437: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10438: $lt{$option}.'</label></span>';
10439: unless ($option eq 'notused') {
10440: $output .= (' 'x2)."\n";
10441: }
10442: }
10443: #
10444: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10445: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10446: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10447: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10448: #
1.165 raeburn 10449: $output .= '</td></tr>'."\n".
1.305 raeburn 10450: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10451: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10452: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10453: $currpub.'" size="40" /></span><br />'."\n".
10454: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10455: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10456: $currpriv.'" size="40" /></span><br />'.
10457: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10458: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10459: $currver.'" size="3" /></span><br />'.
10460: '</td></tr></table>'."\n".
1.165 raeburn 10461: '</td></tr>';
10462: return $output;
10463: }
10464:
1.32 raeburn 10465: sub user_formats_row {
1.305 raeburn 10466: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10467: my $output;
10468: my %text = (
10469: 'username' => 'new usernames',
10470: 'id' => 'IDs',
10471: );
1.409 raeburn 10472: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10473: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10474: $output = '<tr '.$css_class.'>'.
10475: '<td><span class="LC_nobreak">'.
10476: &mt("Format rules to check for $text{$type}: ").
10477: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10478: }
1.27 raeburn 10479: my $rem;
10480: if (ref($ruleorder) eq 'ARRAY') {
10481: for (my $i=0; $i<@{$ruleorder}; $i++) {
10482: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10483: my $rem = $i%($numinrow);
10484: if ($rem == 0) {
10485: if ($i > 0) {
10486: $output .= '</tr>';
10487: }
10488: $output .= '<tr>';
10489: }
10490: my $check = ' ';
1.39 raeburn 10491: if (ref($settings) eq 'HASH') {
10492: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10493: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10494: $check = ' checked="checked" ';
10495: }
1.305 raeburn 10496: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10497: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10498: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10499: $check = ' checked="checked" ';
10500: }
10501: }
1.27 raeburn 10502: }
10503: }
1.305 raeburn 10504: my $name = $type.'_rule';
10505: if ($type eq 'email') {
10506: $name .= '_'.$status;
10507: }
1.27 raeburn 10508: $output .= '<td class="LC_left_item">'.
10509: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10510: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10511: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10512: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10513: }
10514: }
10515: $rem = @{$ruleorder}%($numinrow);
10516: }
1.305 raeburn 10517: my $colsleft;
10518: if ($rem) {
10519: $colsleft = $numinrow - $rem;
10520: }
1.27 raeburn 10521: if ($colsleft > 1 ) {
10522: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10523: ' </td>';
10524: } elsif ($colsleft == 1) {
10525: $output .= '<td class="LC_left_item"> </td>';
10526: }
1.409 raeburn 10527: $output .= '</tr>';
10528: unless (($type eq 'email') || ($type eq 'unamemap')) {
10529: $output .= '</table></td></tr>';
1.305 raeburn 10530: }
1.27 raeburn 10531: return $output;
10532: }
10533:
1.34 raeburn 10534: sub usercreation_types {
10535: my %lt = &Apache::lonlocal::texthash (
10536: author => 'When adding a co-author',
10537: course => 'When adding a user to a course',
1.100 raeburn 10538: requestcrs => 'When requesting a course',
1.34 raeburn 10539: any => 'Any',
10540: official => 'Institutional only ',
10541: unofficial => 'Non-institutional only',
10542: none => 'None',
10543: );
10544: return %lt;
1.48 raeburn 10545: }
1.34 raeburn 10546:
1.224 raeburn 10547: sub selfcreation_types {
10548: my %lt = &Apache::lonlocal::texthash (
10549: selfcreate => 'User creates own account',
10550: any => 'Any',
10551: official => 'Institutional only ',
10552: unofficial => 'Non-institutional only',
10553: email => 'E-mail address',
10554: login => 'Institutional Login',
10555: sso => 'SSO',
10556: );
10557: }
10558:
1.28 raeburn 10559: sub authtype_names {
10560: my %lt = &Apache::lonlocal::texthash(
10561: int => 'Internal',
10562: krb4 => 'Kerberos 4',
10563: krb5 => 'Kerberos 5',
10564: loc => 'Local',
1.325 raeburn 10565: lti => 'LTI',
1.28 raeburn 10566: );
10567: return %lt;
10568: }
10569:
10570: sub context_names {
10571: my %context_title = &Apache::lonlocal::texthash(
10572: author => 'Creating users when an Author',
10573: course => 'Creating users when in a course',
10574: domain => 'Creating users when a Domain Coordinator',
10575: );
10576: return %context_title;
10577: }
10578:
1.33 raeburn 10579: sub print_usermodification {
10580: my ($position,$dom,$settings,$rowtotal) = @_;
10581: my $numinrow = 4;
10582: my ($context,$datatable,$rowcount);
10583: if ($position eq 'top') {
10584: $rowcount = 0;
10585: $context = 'author';
10586: foreach my $role ('ca','aa') {
10587: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10588: $numinrow,$rowcount);
10589: $$rowtotal ++;
10590: $rowcount ++;
10591: }
1.230 raeburn 10592: } elsif ($position eq 'bottom') {
1.33 raeburn 10593: $context = 'course';
10594: $rowcount = 0;
10595: foreach my $role ('st','ep','ta','in','cr') {
10596: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10597: $numinrow,$rowcount);
10598: $$rowtotal ++;
10599: $rowcount ++;
10600: }
10601: }
10602: return $datatable;
10603: }
10604:
1.43 raeburn 10605: sub print_defaults {
1.236 raeburn 10606: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10607: my $rownum = 0;
1.294 raeburn 10608: my ($datatable,$css_class,$titles);
10609: unless ($position eq 'bottom') {
10610: $titles = &defaults_titles($dom);
10611: }
1.236 raeburn 10612: if ($position eq 'top') {
10613: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10614: 'datelocale_def','portal_def');
10615: my %defaults;
10616: if (ref($settings) eq 'HASH') {
10617: %defaults = %{$settings};
1.43 raeburn 10618: } else {
1.236 raeburn 10619: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10620: foreach my $item (@items) {
10621: $defaults{$item} = $domdefaults{$item};
10622: }
1.43 raeburn 10623: }
1.236 raeburn 10624: foreach my $item (@items) {
10625: if ($rownum%2) {
10626: $css_class = '';
10627: } else {
10628: $css_class = ' class="LC_odd_row" ';
10629: }
10630: $datatable .= '<tr'.$css_class.'>'.
10631: '<td><span class="LC_nobreak">'.$titles->{$item}.
10632: '</span></td><td class="LC_right_item" colspan="3">';
10633: if ($item eq 'auth_def') {
1.325 raeburn 10634: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10635: my %shortauth = (
10636: internal => 'int',
10637: krb4 => 'krb4',
10638: krb5 => 'krb5',
1.325 raeburn 10639: localauth => 'loc',
10640: lti => 'lti',
1.236 raeburn 10641: );
10642: my %authnames = &authtype_names();
10643: foreach my $auth (@authtypes) {
10644: my $checked = ' ';
10645: if ($defaults{$item} eq $auth) {
10646: $checked = ' checked="checked" ';
10647: }
10648: $datatable .= '<label><input type="radio" name="'.$item.
10649: '" value="'.$auth.'"'.$checked.'/>'.
10650: $authnames{$shortauth{$auth}}.'</label> ';
10651: }
10652: } elsif ($item eq 'timezone_def') {
10653: my $includeempty = 1;
10654: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10655: } elsif ($item eq 'datelocale_def') {
10656: my $includeempty = 1;
10657: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10658: } elsif ($item eq 'lang_def') {
1.263 raeburn 10659: my $includeempty = 1;
10660: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10661: } elsif ($item eq 'portal_def') {
10662: $datatable .= '<input type="text" name="'.$item.'" value="'.
10663: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10664: my $portalsty = 'none';
10665: if ($defaults{$item}) {
10666: $portalsty = 'block';
10667: }
10668: foreach my $field ('email','web') {
10669: my $checkedoff = ' checked="checked"';
10670: my $checkedon;
10671: if ($defaults{$item.'_'.$field}) {
10672: $checkedon = $checkedoff;
10673: $checkedoff = '';
1.425 raeburn 10674: }
1.414 raeburn 10675: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10676: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10677: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10678: (' 'x2).
10679: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10680: '</div>';
10681: }
1.236 raeburn 10682: } else {
1.414 raeburn 10683: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10684: }
1.236 raeburn 10685: $datatable .= '</td></tr>';
10686: $rownum ++;
10687: }
1.409 raeburn 10688: } elsif ($position eq 'middle') {
1.294 raeburn 10689: my %defaults;
10690: if (ref($settings) eq 'HASH') {
1.354 raeburn 10691: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10692: my $maxnum = @{$settings->{'inststatusorder'}};
10693: for (my $i=0; $i<$maxnum; $i++) {
10694: $css_class = $rownum%2?' class="LC_odd_row"':'';
10695: my $item = $settings->{'inststatusorder'}->[$i];
10696: my $title = $settings->{'inststatustypes'}->{$item};
10697: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10698: $datatable .= '<tr'.$css_class.'>'.
10699: '<td><span class="LC_nobreak">'.
10700: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10701: for (my $k=0; $k<=$maxnum; $k++) {
10702: my $vpos = $k+1;
10703: my $selstr;
10704: if ($k == $i) {
10705: $selstr = ' selected="selected" ';
10706: }
10707: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10708: }
10709: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10710: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10711: &mt('delete').'</span></td>'.
1.380 raeburn 10712: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10713: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10714: '</span></td></tr>';
10715: }
10716: $css_class = $rownum%2?' class="LC_odd_row"':'';
10717: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10718: $datatable .= '<tr '.$css_class.'>'.
10719: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10720: for (my $k=0; $k<=$maxnum; $k++) {
10721: my $vpos = $k+1;
10722: my $selstr;
10723: if ($k == $maxnum) {
10724: $selstr = ' selected="selected" ';
10725: }
10726: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10727: }
10728: $datatable .= '</select> '.&mt('Internal ID:').
10729: '<input type="text" size="10" name="addinststatus" value="" />'.
10730: ' '.&mt('(new)').
10731: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10732: &mt('Name displayed').':'.
1.354 raeburn 10733: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10734: '</tr>'."\n";
10735: $rownum ++;
1.294 raeburn 10736: }
1.354 raeburn 10737: }
1.409 raeburn 10738: } else {
10739: my ($unamemaprules,$ruleorder) =
10740: &Apache::lonnet::inst_userrules($dom,'unamemap');
10741: $css_class = $rownum%2?' class="LC_odd_row"':'';
10742: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10743: my $numinrow = 2;
10744: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10745: &user_formats_row('unamemap',$settings,$unamemaprules,
10746: $ruleorder,$numinrow).
10747: '</table></td></tr>';
10748: }
10749: if ($datatable eq '') {
10750: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10751: &mt('No rules set for domain in customized localenroll.pm').
10752: '</td></tr>';
10753: }
1.354 raeburn 10754: }
10755: $$rowtotal += $rownum;
1.43 raeburn 10756: return $datatable;
10757: }
10758:
1.168 raeburn 10759: sub get_languages_hash {
10760: my %langchoices;
10761: foreach my $id (&Apache::loncommon::languageids()) {
10762: my $code = &Apache::loncommon::supportedlanguagecode($id);
10763: if ($code ne '') {
10764: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10765: }
10766: }
10767: return %langchoices;
10768: }
10769:
1.43 raeburn 10770: sub defaults_titles {
1.141 raeburn 10771: my ($dom) = @_;
1.43 raeburn 10772: my %titles = &Apache::lonlocal::texthash (
10773: 'auth_def' => 'Default authentication type',
10774: 'auth_arg_def' => 'Default authentication argument',
10775: 'lang_def' => 'Default language',
1.54 raeburn 10776: 'timezone_def' => 'Default timezone',
1.68 raeburn 10777: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10778: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10779: 'email' => 'Email links use portal URL',
10780: 'web' => 'Public web links use portal URL',
1.294 raeburn 10781: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10782: 'intauth_check' => 'Check bcrypt cost if authenticated',
10783: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10784: );
1.141 raeburn 10785: if ($dom) {
10786: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10787: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10788: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10789: $protocol = 'http' if ($protocol ne 'https');
10790: if ($uint_dom) {
10791: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10792: $uint_dom);
10793: }
10794: }
1.43 raeburn 10795: return (\%titles);
10796: }
10797:
1.346 raeburn 10798: sub print_scantron {
10799: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10800: if ($position eq 'top') {
10801: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10802: } else {
10803: return &print_scantronconfig($dom,$settings,\$rowtotal);
10804: }
10805: }
10806:
10807: sub scantron_javascript {
10808: return <<"ENDSCRIPT";
10809:
10810: <script type="text/javascript">
10811: // <![CDATA[
10812:
10813: function toggleScantron(form) {
1.347 raeburn 10814: var csvfieldset = new Array();
1.346 raeburn 10815: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10816: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10817: }
10818: if (document.getElementById('scantroncsv_options')) {
10819: csvfieldset.push(document.getElementById('scantroncsv_options'));
10820: }
10821: if (csvfieldset.length) {
1.346 raeburn 10822: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10823: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10824: if (scantroncsv.checked) {
1.347 raeburn 10825: for (var i=0; i<csvfieldset.length; i++) {
10826: csvfieldset[i].style.display = 'block';
10827: }
1.346 raeburn 10828: } else {
1.347 raeburn 10829: for (var i=0; i<csvfieldset.length; i++) {
10830: csvfieldset[i].style.display = 'none';
10831: }
1.346 raeburn 10832: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10833: if (csvselects.length) {
10834: for (var j=0; j<csvselects.length; j++) {
10835: csvselects[j].selectedIndex = 0;
10836: }
10837: }
10838: }
10839: }
10840: }
10841: return;
10842: }
10843: // ]]>
10844: </script>
10845:
10846: ENDSCRIPT
10847:
10848: }
10849:
1.46 raeburn 10850: sub print_scantronformat {
10851: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10852: my $itemcount = 1;
1.60 raeburn 10853: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10854: %confhash);
1.46 raeburn 10855: my $switchserver = &check_switchserver($dom,$confname);
10856: my %lt = &Apache::lonlocal::texthash (
1.95 www 10857: default => 'Default bubblesheet format file error',
10858: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10859: );
10860: my %scantronfiles = (
10861: default => 'default.tab',
10862: custom => 'custom.tab',
10863: );
10864: foreach my $key (keys(%scantronfiles)) {
10865: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10866: .$scantronfiles{$key};
10867: }
10868: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10869: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10870: if (!$switchserver) {
10871: my $servadm = $r->dir_config('lonAdmEMail');
10872: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10873: if ($configuserok eq 'ok') {
10874: if ($author_ok eq 'ok') {
10875: my %legacyfile = (
1.346 raeburn 10876: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10877: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10878: );
10879: my %md5chk;
10880: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10881: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10882: chomp($md5chk{$type});
1.46 raeburn 10883: }
10884: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10885: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10886: ($scantronurls{$type},my $error) =
1.46 raeburn 10887: &legacy_scantronformat($r,$dom,$confname,
10888: $type,$legacyfile{$type},
10889: $scantronurls{$type},
10890: $scantronfiles{$type});
1.60 raeburn 10891: if ($error ne '') {
10892: $error{$type} = $error;
10893: }
10894: }
10895: if (keys(%error) == 0) {
10896: $is_custom = 1;
1.346 raeburn 10897: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10898: $scantronurls{'custom'};
1.346 raeburn 10899: my $putresult =
1.60 raeburn 10900: &Apache::lonnet::put_dom('configuration',
10901: \%confhash,$dom);
10902: if ($putresult ne 'ok') {
1.346 raeburn 10903: $error{'custom'} =
1.60 raeburn 10904: '<span class="LC_error">'.
10905: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10906: }
1.46 raeburn 10907: }
10908: } else {
1.60 raeburn 10909: ($scantronurls{'default'},my $error) =
1.46 raeburn 10910: &legacy_scantronformat($r,$dom,$confname,
10911: 'default',$legacyfile{'default'},
10912: $scantronurls{'default'},
10913: $scantronfiles{'default'});
1.60 raeburn 10914: if ($error eq '') {
10915: $confhash{'scantron'}{'scantronformat'} = '';
10916: my $putresult =
10917: &Apache::lonnet::put_dom('configuration',
10918: \%confhash,$dom);
10919: if ($putresult ne 'ok') {
10920: $error{'default'} =
10921: '<span class="LC_error">'.
10922: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10923: }
10924: } else {
10925: $error{'default'} = $error;
10926: }
1.46 raeburn 10927: }
10928: }
10929: }
10930: } else {
1.95 www 10931: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 10932: }
10933: }
10934: if (ref($settings) eq 'HASH') {
10935: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
10936: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
10937: if ((!@info) || ($info[0] eq 'no_such_dir')) {
10938: $scantronurl = '';
10939: } else {
10940: $scantronurl = $settings->{'scantronformat'};
10941: }
10942: $is_custom = 1;
10943: } else {
10944: $scantronurl = $scantronurls{'default'};
10945: }
10946: } else {
1.60 raeburn 10947: if ($is_custom) {
10948: $scantronurl = $scantronurls{'custom'};
10949: } else {
10950: $scantronurl = $scantronurls{'default'};
10951: }
1.46 raeburn 10952: }
10953: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10954: $datatable .= '<tr'.$css_class.'>';
10955: if (!$is_custom) {
1.65 raeburn 10956: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
10957: '<span class="LC_nobreak">';
1.46 raeburn 10958: if ($scantronurl) {
1.199 raeburn 10959: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
10960: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 10961: } else {
10962: $datatable = &mt('File unavailable for display');
10963: }
1.65 raeburn 10964: $datatable .= '</span></td>';
1.60 raeburn 10965: if (keys(%error) == 0) {
1.306 raeburn 10966: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 10967: if (!$switchserver) {
10968: $datatable .= &mt('Upload:').'<br />';
10969: }
10970: } else {
10971: my $errorstr;
10972: foreach my $key (sort(keys(%error))) {
10973: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10974: }
10975: $datatable .= '<td>'.$errorstr;
10976: }
1.46 raeburn 10977: } else {
10978: if (keys(%error) > 0) {
10979: my $errorstr;
10980: foreach my $key (sort(keys(%error))) {
10981: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10982: }
1.60 raeburn 10983: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 10984: } elsif ($scantronurl) {
1.199 raeburn 10985: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
10986: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 10987: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 10988: $link.
10989: '<label><input type="checkbox" name="scantronformat_del"'.
10990: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 10991: '<td><span class="LC_nobreak"> '.
10992: &mt('Replace:').'</span><br />';
1.46 raeburn 10993: }
10994: }
10995: if (keys(%error) == 0) {
10996: if ($switchserver) {
10997: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
10998: } else {
1.65 raeburn 10999: $datatable .='<span class="LC_nobreak"> '.
11000: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11001: }
11002: }
11003: $datatable .= '</td></tr>';
11004: $$rowtotal ++;
11005: return $datatable;
11006: }
11007:
11008: sub legacy_scantronformat {
11009: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11010: my ($url,$error);
11011: my @statinfo = &Apache::lonnet::stat_file($newurl);
11012: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 11013: my $modified = [];
1.46 raeburn 11014: (my $result,$url) =
1.421 raeburn 11015: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
11016: 'scantron','','',$newfile,$modified);
11017: if ($result eq 'ok') {
11018: &update_modify_urls($r,$modified);
11019: } else {
1.130 raeburn 11020: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11021: }
11022: }
11023: return ($url,$error);
11024: }
1.43 raeburn 11025:
1.346 raeburn 11026: sub print_scantronconfig {
11027: my ($dom,$settings,$rowtotal) = @_;
11028: my $itemcount = 2;
11029: my $is_checked = ' checked="checked"';
1.347 raeburn 11030: my %optionson = (
11031: hdr => ' checked="checked"',
11032: pad => ' checked="checked"',
11033: rem => ' checked="checked"',
11034: );
11035: my %optionsoff = (
11036: hdr => '',
11037: pad => '',
11038: rem => '',
11039: );
1.346 raeburn 11040: my $currcsvsty = 'none';
1.347 raeburn 11041: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11042: my @fields = &scantroncsv_fields();
11043: my %titles = &scantronconfig_titles();
11044: if (ref($settings) eq 'HASH') {
11045: if (ref($settings->{config}) eq 'HASH') {
11046: if ($settings->{config}->{dat}) {
11047: $checked{'dat'} = $is_checked;
11048: }
11049: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11050: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11051: %csvfields = %{$settings->{config}->{csv}->{fields}};
11052: if (keys(%csvfields) > 0) {
11053: $checked{'csv'} = $is_checked;
11054: $currcsvsty = 'block';
11055: }
11056: }
11057: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11058: %csvoptions = %{$settings->{config}->{csv}->{options}};
11059: foreach my $option (keys(%optionson)) {
11060: unless ($csvoptions{$option}) {
11061: $optionsoff{$option} = $optionson{$option};
11062: $optionson{$option} = '';
11063: }
11064: }
1.346 raeburn 11065: }
11066: }
11067: } else {
11068: $checked{'dat'} = $is_checked;
11069: }
11070: } else {
11071: $checked{'dat'} = $is_checked;
11072: }
11073: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11074: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11075: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11076: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11077: foreach my $item ('dat','csv') {
11078: my $id;
11079: if ($item eq 'csv') {
11080: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11081: }
1.346 raeburn 11082: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11083: $titles{$item}.'</label>'.(' 'x3);
11084: if ($item eq 'csv') {
11085: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11086: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11087: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11088: foreach my $col (@fields) {
11089: my $selnone;
11090: if ($csvfields{$col} eq '') {
11091: $selnone = ' selected="selected"';
11092: }
11093: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11094: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11095: '<option value=""'.$selnone.'></option>';
11096: for (my $i=0; $i<20; $i++) {
11097: my $shown = $i+1;
11098: my $sel;
11099: unless ($selnone) {
11100: if (exists($csvfields{$col})) {
11101: if ($csvfields{$col} == $i) {
11102: $sel = ' selected="selected"';
11103: }
11104: }
11105: }
11106: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11107: }
11108: $datatable .= '</select></td></tr>';
11109: }
1.347 raeburn 11110: $datatable .= '</table></fieldset>'.
11111: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11112: '<legend>'.&mt('CSV Options').'</legend>';
11113: foreach my $option ('hdr','pad','rem') {
11114: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11115: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11116: &mt('Yes').'</label>'.(' 'x2)."\n".
11117: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11118: }
11119: $datatable .= '</fieldset>';
1.346 raeburn 11120: $itemcount ++;
11121: }
11122: }
11123: $datatable .= '</td></tr>';
11124: $$rowtotal ++;
11125: return $datatable;
11126: }
11127:
11128: sub scantronconfig_titles {
11129: return &Apache::lonlocal::texthash(
11130: dat => 'Standard format (.dat)',
11131: csv => 'Comma separated values (.csv)',
1.347 raeburn 11132: hdr => 'Remove first line in file (contains column titles)',
11133: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11134: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11135: CODE => 'CODE',
11136: ID => 'Student ID',
11137: PaperID => 'Paper ID',
11138: FirstName => 'First Name',
11139: LastName => 'Last Name',
11140: FirstQuestion => 'First Question Response',
11141: Section => 'Section',
11142: );
11143: }
11144:
11145: sub scantroncsv_fields {
11146: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11147: }
11148:
1.49 raeburn 11149: sub print_coursecategories {
1.57 raeburn 11150: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11151: my $datatable;
11152: if ($position eq 'top') {
1.238 raeburn 11153: my (%checked);
11154: my @catitems = ('unauth','auth');
11155: my @cattypes = ('std','domonly','codesrch','none');
11156: $checked{'unauth'} = 'std';
11157: $checked{'auth'} = 'std';
11158: if (ref($settings) eq 'HASH') {
11159: foreach my $type (@cattypes) {
11160: if ($type eq $settings->{'unauth'}) {
11161: $checked{'unauth'} = $type;
11162: }
11163: if ($type eq $settings->{'auth'}) {
11164: $checked{'auth'} = $type;
11165: }
11166: }
11167: }
11168: my %lt = &Apache::lonlocal::texthash (
11169: unauth => 'Catalog type for unauthenticated users',
11170: auth => 'Catalog type for authenticated users',
11171: none => 'No catalog',
11172: std => 'Standard catalog',
11173: domonly => 'Domain-only catalog',
11174: codesrch => "Code search form",
11175: );
11176: my $itemcount = 0;
11177: foreach my $item (@catitems) {
11178: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11179: $datatable .= '<tr '.$css_class.'>'.
11180: '<td>'.$lt{$item}.'</td>'.
11181: '<td class="LC_right_item"><span class="LC_nobreak">';
11182: foreach my $type (@cattypes) {
11183: my $ischecked;
11184: if ($checked{$item} eq $type) {
11185: $ischecked=' checked="checked"';
11186: }
11187: $datatable .= '<label>'.
11188: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11189: ' />'.$lt{$type}.'</label> ';
11190: }
1.327 raeburn 11191: $datatable .= '</span></td></tr>';
1.238 raeburn 11192: $itemcount ++;
11193: }
11194: $$rowtotal += $itemcount;
11195: } elsif ($position eq 'middle') {
1.57 raeburn 11196: my $toggle_cats_crs = ' ';
11197: my $toggle_cats_dom = ' checked="checked" ';
11198: my $can_cat_crs = ' ';
11199: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11200: my $toggle_catscomm_comm = ' ';
11201: my $toggle_catscomm_dom = ' checked="checked" ';
11202: my $can_catcomm_comm = ' ';
11203: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11204: my $toggle_catsplace_place = ' ';
11205: my $toggle_catsplace_dom = ' checked="checked" ';
11206: my $can_catplace_place = ' ';
11207: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11208:
1.57 raeburn 11209: if (ref($settings) eq 'HASH') {
11210: if ($settings->{'togglecats'} eq 'crs') {
11211: $toggle_cats_crs = $toggle_cats_dom;
11212: $toggle_cats_dom = ' ';
11213: }
11214: if ($settings->{'categorize'} eq 'crs') {
11215: $can_cat_crs = $can_cat_dom;
11216: $can_cat_dom = ' ';
11217: }
1.120 raeburn 11218: if ($settings->{'togglecatscomm'} eq 'comm') {
11219: $toggle_catscomm_comm = $toggle_catscomm_dom;
11220: $toggle_catscomm_dom = ' ';
11221: }
11222: if ($settings->{'categorizecomm'} eq 'comm') {
11223: $can_catcomm_comm = $can_catcomm_dom;
11224: $can_catcomm_dom = ' ';
11225: }
1.272 raeburn 11226: if ($settings->{'togglecatsplace'} eq 'place') {
11227: $toggle_catsplace_place = $toggle_catsplace_dom;
11228: $toggle_catsplace_dom = ' ';
11229: }
11230: if ($settings->{'categorizeplace'} eq 'place') {
11231: $can_catplace_place = $can_catplace_dom;
11232: $can_catplace_dom = ' ';
11233: }
1.57 raeburn 11234: }
11235: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11236: togglecats => 'Show/Hide a course in catalog',
11237: togglecatscomm => 'Show/Hide a community in catalog',
11238: togglecatsplace => 'Show/Hide a placement test in catalog',
11239: categorize => 'Assign a category to a course',
11240: categorizecomm => 'Assign a category to a community',
11241: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11242: );
11243: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11244: dom => 'Set in Domain',
11245: crs => 'Set in Course',
11246: comm => 'Set in Community',
11247: place => 'Set in Placement Test',
1.57 raeburn 11248: );
11249: $datatable = '<tr class="LC_odd_row">'.
11250: '<td>'.$title{'togglecats'}.'</td>'.
11251: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11252: '<input type="radio" name="togglecats"'.
11253: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11254: '<label><input type="radio" name="togglecats"'.
11255: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11256: '</tr><tr>'.
11257: '<td>'.$title{'categorize'}.'</td>'.
11258: '<td class="LC_right_item"><span class="LC_nobreak">'.
11259: '<label><input type="radio" name="categorize"'.
11260: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11261: '<label><input type="radio" name="categorize"'.
11262: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11263: '</tr><tr class="LC_odd_row">'.
11264: '<td>'.$title{'togglecatscomm'}.'</td>'.
11265: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11266: '<input type="radio" name="togglecatscomm"'.
11267: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11268: '<label><input type="radio" name="togglecatscomm"'.
11269: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11270: '</tr><tr>'.
11271: '<td>'.$title{'categorizecomm'}.'</td>'.
11272: '<td class="LC_right_item"><span class="LC_nobreak">'.
11273: '<label><input type="radio" name="categorizecomm"'.
11274: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11275: '<label><input type="radio" name="categorizecomm"'.
11276: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11277: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11278: '<td>'.$title{'togglecatsplace'}.'</td>'.
11279: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11280: '<input type="radio" name="togglecatsplace"'.
11281: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11282: '<label><input type="radio" name="togglecatscomm"'.
11283: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11284: '</tr><tr>'.
11285: '<td>'.$title{'categorizeplace'}.'</td>'.
11286: '<td class="LC_right_item"><span class="LC_nobreak">'.
11287: '<label><input type="radio" name="categorizeplace"'.
11288: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11289: '<label><input type="radio" name="categorizeplace"'.
11290: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11291: '</tr>';
1.272 raeburn 11292: $$rowtotal += 6;
1.57 raeburn 11293: } else {
11294: my $css_class;
11295: my $itemcount = 1;
11296: my $cathash;
11297: if (ref($settings) eq 'HASH') {
11298: $cathash = $settings->{'cats'};
11299: }
11300: if (ref($cathash) eq 'HASH') {
11301: my (@cats,@trails,%allitems,%idx,@jsarray);
11302: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11303: \%allitems,\%idx,\@jsarray);
11304: my $maxdepth = scalar(@cats);
11305: my $colattrib = '';
11306: if ($maxdepth > 2) {
11307: $colattrib = ' colspan="2" ';
11308: }
11309: my @path;
11310: if (@cats > 0) {
11311: if (ref($cats[0]) eq 'ARRAY') {
11312: my $numtop = @{$cats[0]};
11313: my $maxnum = $numtop;
1.120 raeburn 11314: my %default_names = (
11315: instcode => &mt('Official courses'),
11316: communities => &mt('Communities'),
1.272 raeburn 11317: placement => &mt('Placement Tests'),
1.120 raeburn 11318: );
11319:
11320: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11321: ($cathash->{'instcode::0'} eq '') ||
11322: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11323: ($cathash->{'communities::0'} eq '') ||
11324: (!grep(/^placement$/,@{$cats[0]})) ||
11325: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11326: $maxnum ++;
11327: }
11328: my $lastidx;
11329: for (my $i=0; $i<$numtop; $i++) {
11330: my $parent = $cats[0][$i];
11331: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11332: my $item = &escape($parent).'::0';
11333: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11334: $lastidx = $idx{$item};
11335: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11336: .'<select name="'.$item.'"'.$chgstr.'>';
11337: for (my $k=0; $k<=$maxnum; $k++) {
11338: my $vpos = $k+1;
11339: my $selstr;
11340: if ($k == $i) {
11341: $selstr = ' selected="selected" ';
11342: }
11343: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11344: }
1.214 raeburn 11345: $datatable .= '</select></span></td><td>';
1.272 raeburn 11346: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11347: $datatable .= '<span class="LC_nobreak">'
11348: .$default_names{$parent}.'</span>';
11349: if ($parent eq 'instcode') {
11350: $datatable .= '<br /><span class="LC_nobreak">('
11351: .&mt('with institutional codes')
11352: .')</span></td><td'.$colattrib.'>';
11353: } else {
11354: $datatable .= '<table><tr><td>';
11355: }
11356: $datatable .= '<span class="LC_nobreak">'
11357: .'<label><input type="radio" name="'
11358: .$parent.'" value="1" checked="checked" />'
11359: .&mt('Display').'</label>';
11360: if ($parent eq 'instcode') {
11361: $datatable .= ' ';
11362: } else {
11363: $datatable .= '</span></td></tr><tr><td>'
11364: .'<span class="LC_nobreak">';
11365: }
11366: $datatable .= '<label><input type="radio" name="'
11367: .$parent.'" value="0" />'
11368: .&mt('Do not display').'</label></span>';
1.272 raeburn 11369: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11370: $datatable .= '</td></tr></table>';
11371: }
11372: $datatable .= '</td>';
1.57 raeburn 11373: } else {
11374: $datatable .= $parent
1.214 raeburn 11375: .' <span class="LC_nobreak"><label>'
11376: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11377: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11378: }
11379: my $depth = 1;
11380: push(@path,$parent);
11381: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11382: pop(@path);
11383: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11384: $itemcount ++;
11385: }
1.48 raeburn 11386: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11387: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11388: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11389: for (my $k=0; $k<=$maxnum; $k++) {
11390: my $vpos = $k+1;
11391: my $selstr;
1.57 raeburn 11392: if ($k == $numtop) {
1.48 raeburn 11393: $selstr = ' selected="selected" ';
11394: }
11395: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11396: }
1.59 bisitz 11397: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11398: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11399: .'</tr>'."\n";
1.48 raeburn 11400: $itemcount ++;
1.272 raeburn 11401: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11402: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11403: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11404: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11405: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11406: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11407: for (my $k=0; $k<=$maxnum; $k++) {
11408: my $vpos = $k+1;
11409: my $selstr;
11410: if ($k == $maxnum) {
11411: $selstr = ' selected="selected" ';
11412: }
11413: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11414: }
1.120 raeburn 11415: $datatable .= '</select></span></td>'.
11416: '<td><span class="LC_nobreak">'.
11417: $default_names{$default}.'</span>';
11418: if ($default eq 'instcode') {
11419: $datatable .= '<br /><span class="LC_nobreak">('
11420: .&mt('with institutional codes').')</span>';
11421: }
11422: $datatable .= '</td>'
11423: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11424: .&mt('Display').'</label> '
11425: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11426: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11427: }
11428: }
11429: }
1.57 raeburn 11430: } else {
11431: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11432: }
11433: } else {
1.327 raeburn 11434: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11435: .&initialize_categories($itemcount);
1.48 raeburn 11436: }
1.57 raeburn 11437: $$rowtotal += $itemcount;
1.48 raeburn 11438: }
11439: return $datatable;
11440: }
11441:
1.69 raeburn 11442: sub print_serverstatuses {
11443: my ($dom,$settings,$rowtotal) = @_;
11444: my $datatable;
11445: my @pages = &serverstatus_pages();
11446: my (%namedaccess,%machineaccess);
11447: foreach my $type (@pages) {
11448: $namedaccess{$type} = '';
11449: $machineaccess{$type}= '';
11450: }
11451: if (ref($settings) eq 'HASH') {
11452: foreach my $type (@pages) {
11453: if (exists($settings->{$type})) {
11454: if (ref($settings->{$type}) eq 'HASH') {
11455: foreach my $key (keys(%{$settings->{$type}})) {
11456: if ($key eq 'namedusers') {
11457: $namedaccess{$type} = $settings->{$type}->{$key};
11458: } elsif ($key eq 'machines') {
11459: $machineaccess{$type} = $settings->{$type}->{$key};
11460: }
11461: }
11462: }
11463: }
11464: }
11465: }
1.81 raeburn 11466: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11467: my $rownum = 0;
11468: my $css_class;
11469: foreach my $type (@pages) {
11470: $rownum ++;
11471: $css_class = $rownum%2?' class="LC_odd_row"':'';
11472: $datatable .= '<tr'.$css_class.'>'.
11473: '<td><span class="LC_nobreak">'.
11474: $titles->{$type}.'</span></td>'.
11475: '<td class="LC_left_item">'.
11476: '<input type="text" name="'.$type.'_namedusers" '.
11477: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11478: '<td class="LC_right_item">'.
11479: '<span class="LC_nobreak">'.
11480: '<input type="text" name="'.$type.'_machines" '.
11481: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11482: '</span></td></tr>'."\n";
1.69 raeburn 11483: }
11484: $$rowtotal += $rownum;
11485: return $datatable;
11486: }
11487:
11488: sub serverstatus_pages {
11489: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11490: 'checksums','clusterstatus','certstatus','metadata_keywords',
11491: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11492: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11493: }
11494:
1.236 raeburn 11495: sub defaults_javascript {
11496: my ($settings) = @_;
1.354 raeburn 11497: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11498: my $portal_js = <<"ENDPORTAL";
11499:
11500: function portalExtras(caller) {
11501: var x = caller.value;
11502: var y = new Array('email','web');
1.425 raeburn 11503: for (var i=0; i<y.length; i++) {
1.414 raeburn 11504: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11505: var z = document.getElementById('portal_def_'+y[i]+'_div');
11506: if (x.length > 0) {
11507: z.style.display = 'block';
11508: } else {
11509: z.style.display = 'none';
11510: }
11511: }
11512: }
11513: }
11514: ENDPORTAL
1.236 raeburn 11515: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11516: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11517: if ($maxnum eq '') {
11518: $maxnum = 0;
11519: }
11520: $maxnum ++;
1.249 raeburn 11521: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11522: return <<"ENDSCRIPT";
11523: <script type="text/javascript">
11524: // <![CDATA[
11525: function reorderTypes(form,caller) {
11526: var changedVal;
11527: $jstext
11528: var newpos = 'addinststatus_pos';
11529: var current = new Array;
11530: var maxh = $maxnum;
11531: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11532: var oldVal;
11533: if (caller == newpos) {
11534: changedVal = newitemVal;
11535: } else {
11536: var curritem = 'inststatus_pos_'+caller;
11537: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11538: current[newitemVal] = newpos;
11539: }
11540: for (var i=0; i<inststatuses.length; i++) {
11541: if (inststatuses[i] != caller) {
11542: var elementName = 'inststatus_pos_'+inststatuses[i];
11543: if (form.elements[elementName]) {
11544: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11545: current[currVal] = elementName;
11546: }
11547: }
11548: }
11549: for (var j=0; j<maxh; j++) {
11550: if (current[j] == undefined) {
11551: oldVal = j;
11552: }
11553: }
11554: if (oldVal < changedVal) {
11555: for (var k=oldVal+1; k<=changedVal ; k++) {
11556: var elementName = current[k];
11557: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11558: }
11559: } else {
11560: for (var k=changedVal; k<oldVal; k++) {
11561: var elementName = current[k];
11562: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11563: }
11564: }
11565: return;
11566: }
11567:
1.414 raeburn 11568: $portal_js
11569:
11570: // ]]>
11571: </script>
11572:
11573: ENDSCRIPT
11574: } else {
11575: return <<"ENDSCRIPT";
11576: <script type="text/javascript">
11577: // <![CDATA[
11578: $portal_js
1.236 raeburn 11579: // ]]>
11580: </script>
11581:
11582: ENDSCRIPT
11583: }
1.354 raeburn 11584: return;
11585: }
11586:
11587: sub passwords_javascript {
1.405 raeburn 11588: my ($prefix) = @_;
11589: my %intalert;
11590: if ($prefix eq 'passwords') {
11591: %intalert = &Apache::lonlocal::texthash (
11592: 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.',
11593: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11594: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11595: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11596: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11597: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11598: );
1.421 raeburn 11599: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11600: %intalert = &Apache::lonlocal::texthash (
11601: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11602: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11603: );
11604: }
1.365 raeburn 11605: &js_escape(\%intalert);
11606: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11607: my $intauthjs;
1.405 raeburn 11608: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11609:
11610: function warnIntAuth(field) {
11611: if (field.name == 'intauth_check') {
11612: if (field.value == '2') {
1.365 raeburn 11613: alert('$intalert{authcheck}');
1.354 raeburn 11614: }
11615: }
11616: if (field.name == 'intauth_cost') {
11617: field.value.replace(/\s/g,'');
11618: if (field.value != '') {
11619: var regexdigit=/^\\d+\$/;
11620: if (!regexdigit.test(field.value)) {
1.365 raeburn 11621: alert('$intalert{authcost}');
11622: }
11623: }
11624: }
11625: return;
11626: }
11627:
1.405 raeburn 11628: ENDSCRIPT
11629:
11630: }
11631:
11632: $intauthjs .= <<"ENDSCRIPT";
11633:
11634: function warnInt$prefix(field) {
1.365 raeburn 11635: field.value.replace(/^\s+/,'');
11636: field.value.replace(/\s+\$/,'');
11637: var regexdigit=/^\\d+\$/;
1.408 raeburn 11638: if (field.name == '${prefix}_min') {
1.365 raeburn 11639: if (field.value == '') {
11640: alert('$intalert{passmin}');
11641: field.value = '$defmin';
11642: } else {
11643: if (!regexdigit.test(field.value)) {
11644: alert('$intalert{passmin}');
11645: field.value = '$defmin';
11646: }
1.366 raeburn 11647: var minval = parseInt(field.value,10);
1.365 raeburn 11648: if (minval < $defmin) {
11649: alert('$intalert{passmin}');
11650: field.value = '$defmin';
11651: }
11652: }
11653: } else {
11654: if (field.value == '0') {
11655: field.value = '';
11656: }
11657: if (field.value != '') {
1.408 raeburn 11658: if (field.name == '${prefix}_expire') {
1.365 raeburn 11659: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11660: if (!regexpposnum.test(field.value)) {
11661: alert('$intalert{passexp}');
11662: field.value = '';
11663: } else {
11664: var expval = parseFloat(field.value);
11665: if (expval == 0) {
11666: alert('$intalert{passexp}');
11667: field.value = '';
11668: }
11669: }
11670: } else {
11671: if (!regexdigit.test(field.value)) {
1.408 raeburn 11672: if (field.name == '${prefix}_max') {
1.365 raeburn 11673: alert('$intalert{passmax}');
11674: } else {
1.408 raeburn 11675: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11676: alert('$intalert{passnum}');
11677: }
11678: }
1.370 raeburn 11679: field.value = '';
1.365 raeburn 11680: }
1.354 raeburn 11681: }
11682: }
11683: }
11684: return;
11685: }
11686:
11687: ENDSCRIPT
11688: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11689: }
11690:
1.49 raeburn 11691: sub coursecategories_javascript {
11692: my ($settings) = @_;
1.57 raeburn 11693: my ($output,$jstext,$cathash);
1.49 raeburn 11694: if (ref($settings) eq 'HASH') {
1.57 raeburn 11695: $cathash = $settings->{'cats'};
11696: }
11697: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11698: my (@cats,@jsarray,%idx);
1.57 raeburn 11699: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11700: if (@jsarray > 0) {
11701: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11702: for (my $i=0; $i<@jsarray; $i++) {
11703: if (ref($jsarray[$i]) eq 'ARRAY') {
11704: my $catstr = join('","',@{$jsarray[$i]});
11705: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11706: }
11707: }
11708: }
11709: } else {
11710: $jstext = ' var categories = Array(1);'."\n".
11711: ' categories[0] = Array("instcode_pos");'."\n";
11712: }
1.237 bisitz 11713: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11714: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11715: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11716: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11717: &js_escape(\$instcode_reserved);
11718: &js_escape(\$communities_reserved);
1.272 raeburn 11719: &js_escape(\$placement_reserved);
1.265 damieng 11720: &js_escape(\$choose_again);
1.49 raeburn 11721: $output = <<"ENDSCRIPT";
11722: <script type="text/javascript">
1.109 raeburn 11723: // <![CDATA[
1.49 raeburn 11724: function reorderCats(form,parent,item,idx) {
11725: var changedVal;
11726: $jstext
11727: var newpos = 'addcategory_pos';
11728: if (parent == '') {
11729: var has_instcode = 0;
11730: var maxtop = categories[idx].length;
11731: for (var j=0; j<maxtop; j++) {
11732: if (categories[idx][j] == 'instcode::0') {
11733: has_instcode == 1;
11734: }
11735: }
11736: if (has_instcode == 0) {
11737: categories[idx][maxtop] = 'instcode_pos';
11738: }
11739: } else {
11740: newpos += '_'+parent;
11741: }
11742: var maxh = 1 + categories[idx].length;
11743: var current = new Array;
11744: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11745: if (item == newpos) {
11746: changedVal = newitemVal;
11747: } else {
11748: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11749: current[newitemVal] = newpos;
11750: }
11751: for (var i=0; i<categories[idx].length; i++) {
11752: var elementName = categories[idx][i];
11753: if (elementName != item) {
11754: if (form.elements[elementName]) {
11755: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11756: current[currVal] = elementName;
11757: }
11758: }
11759: }
11760: var oldVal;
11761: for (var j=0; j<maxh; j++) {
11762: if (current[j] == undefined) {
11763: oldVal = j;
11764: }
11765: }
11766: if (oldVal < changedVal) {
11767: for (var k=oldVal+1; k<=changedVal ; k++) {
11768: var elementName = current[k];
11769: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11770: }
11771: } else {
11772: for (var k=changedVal; k<oldVal; k++) {
11773: var elementName = current[k];
11774: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11775: }
11776: }
11777: return;
11778: }
1.120 raeburn 11779:
11780: function categoryCheck(form) {
11781: if (form.elements['addcategory_name'].value == 'instcode') {
11782: alert('$instcode_reserved\\n$choose_again');
11783: return false;
11784: }
11785: if (form.elements['addcategory_name'].value == 'communities') {
11786: alert('$communities_reserved\\n$choose_again');
11787: return false;
11788: }
1.272 raeburn 11789: if (form.elements['addcategory_name'].value == 'placement') {
11790: alert('$placement_reserved\\n$choose_again');
11791: return false;
11792: }
1.120 raeburn 11793: return true;
11794: }
11795:
1.109 raeburn 11796: // ]]>
1.49 raeburn 11797: </script>
11798:
11799: ENDSCRIPT
11800: return $output;
11801: }
11802:
1.48 raeburn 11803: sub initialize_categories {
11804: my ($itemcount) = @_;
1.120 raeburn 11805: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11806: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11807: instcode => 'Official courses (with institutional codes)',
11808: communities => 'Communities',
1.272 raeburn 11809: placement => 'Placement Tests',
1.120 raeburn 11810: );
1.328 raeburn 11811: my %selnum = (
11812: instcode => '0',
11813: communities => '1',
11814: placement => '2',
11815: );
11816: my %selected;
1.272 raeburn 11817: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11818: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11819: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11820: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11821: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11822: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11823: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11824: .'<option value="0"'.$selected{'0'}.'>1</option>'
11825: .'<option value="1"'.$selected{'1'}.'>2</option>'
11826: .'<option value="2"'.$selected{'2'}.'>3</option>'
11827: .'<option value="3">4</option></select> '
1.120 raeburn 11828: .$default_names{$default}
11829: .'</span></td><td><span class="LC_nobreak">'
11830: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11831: .&mt('Display').'</label> <label>'
11832: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11833: .'</label></span></td></tr>';
1.120 raeburn 11834: $itemcount ++;
11835: }
1.48 raeburn 11836: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11837: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11838: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11839: .'<select name="addcategory_pos"'.$chgstr.'>'
11840: .'<option value="0">1</option>'
11841: .'<option value="1">2</option>'
1.328 raeburn 11842: .'<option value="2">3</option>'
11843: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11844: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11845: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11846: .'</td></tr>';
1.48 raeburn 11847: return $datatable;
11848: }
11849:
11850: sub build_category_rows {
1.49 raeburn 11851: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11852: my ($text,$name,$item,$chgstr);
1.48 raeburn 11853: if (ref($cats) eq 'ARRAY') {
11854: my $maxdepth = scalar(@{$cats});
11855: if (ref($cats->[$depth]) eq 'HASH') {
11856: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11857: my $numchildren = @{$cats->[$depth]{$parent}};
11858: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11859: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11860: my ($idxnum,$parent_name,$parent_item);
11861: my $higher = $depth - 1;
11862: if ($higher == 0) {
11863: $parent_name = &escape($parent).'::'.$higher;
11864: } else {
11865: if (ref($path) eq 'ARRAY') {
11866: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11867: }
11868: }
11869: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11870: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11871: if ($j < $numchildren) {
1.48 raeburn 11872: $name = $cats->[$depth]{$parent}[$j];
11873: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11874: $idxnum = $idx->{$item};
11875: } else {
11876: $name = $parent_name;
11877: $item = $parent_item;
1.48 raeburn 11878: }
1.49 raeburn 11879: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11880: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11881: for (my $i=0; $i<=$numchildren; $i++) {
11882: my $vpos = $i+1;
11883: my $selstr;
11884: if ($j == $i) {
11885: $selstr = ' selected="selected" ';
11886: }
11887: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11888: }
11889: $text .= '</select> ';
11890: if ($j < $numchildren) {
11891: my $deeper = $depth+1;
11892: $text .= $name.' '
11893: .'<label><input type="checkbox" name="deletecategory" value="'
11894: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11895: if(ref($path) eq 'ARRAY') {
11896: push(@{$path},$name);
1.49 raeburn 11897: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11898: pop(@{$path});
11899: }
11900: } else {
1.330 raeburn 11901: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11902: if ($j == $numchildren) {
11903: $text .= $name;
11904: } else {
11905: $text .= $item;
11906: }
11907: $text .= '" value="" />';
11908: }
11909: $text .= '</td></tr>';
11910: }
11911: $text .= '</table></td>';
11912: } else {
11913: my $higher = $depth-1;
11914: if ($higher == 0) {
11915: $name = &escape($parent).'::'.$higher;
11916: } else {
11917: if (ref($path) eq 'ARRAY') {
11918: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11919: }
11920: }
11921: my $colspan;
11922: if ($parent ne 'instcode') {
11923: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11924: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11925: }
11926: }
11927: }
11928: }
11929: return $text;
11930: }
11931:
1.33 raeburn 11932: sub modifiable_userdata_row {
1.305 raeburn 11933: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 11934: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 11935: my ($role,$rolename,$statustype);
11936: $role = $item;
1.224 raeburn 11937: if ($context eq 'cancreate') {
1.305 raeburn 11938: if ($item =~ /^(emailusername)_(.+)$/) {
11939: $role = $1;
11940: $statustype = $2;
1.228 raeburn 11941: if (ref($usertypes) eq 'HASH') {
11942: if ($usertypes->{$statustype}) {
11943: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
11944: } else {
11945: $rolename = &mt('Data provided by user');
11946: }
11947: }
1.224 raeburn 11948: }
11949: } elsif ($context eq 'selfcreate') {
1.63 raeburn 11950: if (ref($usertypes) eq 'HASH') {
11951: $rolename = $usertypes->{$role};
11952: } else {
11953: $rolename = $role;
11954: }
1.325 raeburn 11955: } elsif ($context eq 'lti') {
11956: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 11957: } elsif ($context eq 'privacy') {
11958: $rolename = $itemdesc;
1.33 raeburn 11959: } else {
1.63 raeburn 11960: if ($role eq 'cr') {
11961: $rolename = &mt('Custom role');
11962: } else {
11963: $rolename = &Apache::lonnet::plaintext($role);
11964: }
1.33 raeburn 11965: }
1.224 raeburn 11966: my (@fields,%fieldtitles);
11967: if (ref($fieldsref) eq 'ARRAY') {
11968: @fields = @{$fieldsref};
11969: } else {
11970: @fields = ('lastname','firstname','middlename','generation',
11971: 'permanentemail','id');
11972: }
11973: if ((ref($titlesref) eq 'HASH')) {
11974: %fieldtitles = %{$titlesref};
11975: } else {
11976: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11977: }
1.33 raeburn 11978: my $output;
1.305 raeburn 11979: my $css_class;
11980: if ($rowcount%2) {
11981: $css_class = 'LC_odd_row';
11982: }
11983: if ($customcss) {
11984: $css_class .= " $customcss";
11985: }
11986: $css_class =~ s/^\s+//;
11987: if ($css_class) {
11988: $css_class = ' class="'.$css_class.'"';
11989: }
11990: if ($rowstyle) {
11991: $css_class .= ' style="'.$rowstyle.'"';
11992: }
11993: if ($rowid) {
11994: $rowid = ' id="'.$rowid.'"';
11995: }
11996: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 11997: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
11998: '<td class="LC_left_item" colspan="2"><table>';
11999: my $rem;
12000: my %checks;
12001: if (ref($settings) eq 'HASH') {
1.325 raeburn 12002: my $hashref;
12003: if ($context eq 'lti') {
12004: if (ref($settings) eq 'HASH') {
12005: $hashref = $settings->{'instdata'};
12006: }
1.357 raeburn 12007: } elsif ($context eq 'privacy') {
12008: my ($key,$inner) = split(/_/,$role);
12009: if (ref($settings) eq 'HASH') {
12010: if (ref($settings->{$key}) eq 'HASH') {
12011: $hashref = $settings->{$key}->{$inner};
12012: }
12013: }
1.325 raeburn 12014: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12015: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 12016: $hashref = $settings->{'lti_instdata'};
12017: }
12018: if ($role eq 'emailusername') {
12019: if ($statustype) {
12020: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12021: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12022: }
1.325 raeburn 12023: }
12024: }
12025: }
1.425 raeburn 12026: if (ref($hashref) eq 'HASH') {
1.325 raeburn 12027: foreach my $field (@fields) {
12028: if ($hashref->{$field}) {
12029: if ($role eq 'emailusername') {
12030: $checks{$field} = $hashref->{$field};
12031: } else {
12032: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12033: }
12034: }
12035: }
12036: }
12037: }
1.305 raeburn 12038: my $total = scalar(@fields);
12039: for (my $i=0; $i<$total; $i++) {
12040: $rem = $i%($numinrow);
1.33 raeburn 12041: if ($rem == 0) {
12042: if ($i > 0) {
12043: $output .= '</tr>';
12044: }
12045: $output .= '<tr>';
12046: }
12047: my $check = ' ';
1.228 raeburn 12048: unless ($role eq 'emailusername') {
12049: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12050: $check = $checks{$fields[$i]};
1.357 raeburn 12051: } elsif ($context eq 'privacy') {
12052: if ($role =~ /^priv_(domain|course)$/) {
12053: if (ref($settings) ne 'HASH') {
12054: $check = ' checked="checked" ';
12055: }
12056: } elsif ($role =~ /^priv_(author|community)$/) {
12057: if (ref($settings) ne 'HASH') {
12058: unless ($fields[$i] eq 'id') {
12059: $check = ' checked="checked" ';
12060: }
12061: }
12062: } elsif ($role =~ /^(unpriv|othdom)_/) {
12063: if (ref($settings) ne 'HASH') {
12064: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12065: $check = ' checked="checked" ';
12066: }
12067: }
12068: }
1.325 raeburn 12069: } elsif ($context ne 'lti') {
1.228 raeburn 12070: if ($role eq 'st') {
12071: if (ref($settings) ne 'HASH') {
12072: $check = ' checked="checked" ';
12073: }
1.33 raeburn 12074: }
12075: }
12076: }
12077: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12078: '<span class="LC_nobreak">';
1.325 raeburn 12079: my $prefix = 'canmodify';
1.228 raeburn 12080: if ($role eq 'emailusername') {
12081: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12082: $checks{$fields[$i]} = 'omit';
12083: }
12084: foreach my $option ('required','optional','omit') {
12085: my $checked='';
12086: if ($checks{$fields[$i]} eq $option) {
12087: $checked='checked="checked" ';
12088: }
12089: $output .= '<label>'.
1.325 raeburn 12090: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12091: &mt($option).'</label>'.(' ' x2);
12092: }
12093: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12094: } else {
1.325 raeburn 12095: if ($context eq 'lti') {
12096: $prefix = 'lti';
1.357 raeburn 12097: } elsif ($context eq 'privacy') {
12098: $prefix = 'privacy';
1.325 raeburn 12099: }
1.228 raeburn 12100: $output .= '<label>'.
1.325 raeburn 12101: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12102: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12103: '</label>';
12104: }
12105: $output .= '</span></td>';
1.33 raeburn 12106: }
1.305 raeburn 12107: $rem = $total%$numinrow;
12108: my $colsleft;
12109: if ($rem) {
12110: $colsleft = $numinrow - $rem;
12111: }
12112: if ($colsleft > 1) {
1.33 raeburn 12113: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12114: ' </td>';
12115: } elsif ($colsleft == 1) {
12116: $output .= '<td class="LC_left_item"> </td>';
12117: }
12118: $output .= '</tr></table></td></tr>';
12119: return $output;
12120: }
1.28 raeburn 12121:
1.93 raeburn 12122: sub insttypes_row {
1.305 raeburn 12123: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12124: $customcss,$rowstyle) = @_;
1.93 raeburn 12125: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12126: cansearch => 'Users allowed to search',
1.93 raeburn 12127: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12128: lockablenames => 'User preference to lock name',
12129: selfassign => 'Self-reportable affiliations',
12130: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12131: webdav => 'WebDAV access available',
12132: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12133: );
1.429 raeburn 12134: my ($showdom,$defaultquota);
1.93 raeburn 12135: if ($context eq 'cansearch') {
12136: $showdom = ' ('.$dom.')';
1.429 raeburn 12137: } elsif ($context eq 'authorquota') {
12138: $defaultquota = 500;
1.93 raeburn 12139: }
1.165 raeburn 12140: my $class = 'LC_left_item';
12141: if ($context eq 'statustocreate') {
12142: $class = 'LC_right_item';
12143: }
1.305 raeburn 12144: my $css_class;
12145: if ($$rowtotal%2) {
12146: $css_class = 'LC_odd_row';
12147: }
12148: if ($customcss) {
12149: $css_class .= ' '.$customcss;
12150: }
12151: $css_class =~ s/^\s+//;
12152: if ($css_class) {
12153: $css_class = ' class="'.$css_class.'"';
12154: }
12155: if ($rowstyle) {
12156: $css_class .= ' style="'.$rowstyle.'"';
12157: }
12158: if ($onclick) {
12159: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12160: }
12161: my $output = '<tr'.$css_class.'>'.
12162: '<td>'.$lt{$context}.$showdom.
12163: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12164: my $rem;
12165: if (ref($types) eq 'ARRAY') {
12166: for (my $i=0; $i<@{$types}; $i++) {
12167: if (defined($usertypes->{$types->[$i]})) {
12168: my $rem = $i%($numinrow);
12169: if ($rem == 0) {
12170: if ($i > 0) {
12171: $output .= '</tr>';
12172: }
12173: $output .= '<tr>';
1.23 raeburn 12174: }
1.429 raeburn 12175: if ($context eq 'authorquota') {
12176: my $currquota;
12177: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12178: $currquota = $settings->{$context}->{$types->[$i]};
12179: } else {
12180: $currquota = $defaultquota;
12181: }
12182: $output .= '<td class="LC_left_item">'."\n".
12183: '<label><span class="LC_nobreak">'."\n".
12184: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12185: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12186: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12187: '</label></td>';
12188: } else {
12189: my $check = ' ';
12190: if (ref($settings) eq 'HASH') {
12191: if (ref($settings->{$context}) eq 'ARRAY') {
12192: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12193: $check = ' checked="checked" ';
12194: }
12195: } elsif (ref($settings->{$context}) eq 'HASH') {
12196: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12197: $check = ' checked="checked" ';
12198: } elsif ($context eq 'webdav') {
12199: if ($settings->{$context}->{$types->[$i]}) {
12200: $check = ' checked="checked" ';
12201: }
12202: }
12203: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12204: $check = ' checked="checked" ';
12205: }
1.26 raeburn 12206: }
1.429 raeburn 12207: $output .= '<td class="LC_left_item">'.
12208: '<span class="LC_nobreak"><label>'.
12209: '<input type="checkbox" name="'.$context.'" '.
12210: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12211: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12212: }
12213: }
12214: }
1.26 raeburn 12215: $rem = @{$types}%($numinrow);
1.23 raeburn 12216: }
12217: my $colsleft = $numinrow - $rem;
1.315 raeburn 12218: if ($context eq 'overrides') {
12219: if ($colsleft > 1) {
12220: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12221: } else {
12222: $output .= '<td class="LC_left_item">';
12223: }
1.425 raeburn 12224: $output .= ' ';
1.23 raeburn 12225: } else {
1.334 raeburn 12226: if ($rem == 0) {
1.315 raeburn 12227: $output .= '<tr>';
12228: }
12229: if ($colsleft > 1) {
12230: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12231: } else {
12232: $output .= '<td class="LC_left_item">';
12233: }
1.429 raeburn 12234: if ($context eq 'authorquota') {
12235: my $currquota = 500;
12236: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12237: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12238: $currquota = $settings->{$context}{'default'};
12239: }
12240: }
12241: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12242: '<input type="text" name="'.$context.'_default" '.
12243: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12244: '</label>';
12245: } else {
12246: my $defcheck = ' ';
12247: if (ref($settings) eq 'HASH') {
12248: if (ref($settings->{$context}) eq 'ARRAY') {
12249: if (grep(/^default$/,@{$settings->{$context}})) {
12250: $defcheck = ' checked="checked" ';
12251: }
12252: } elsif (ref($settings->{$context}) eq 'HASH') {
12253: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12254: $defcheck = ' checked="checked" ';
12255: } elsif ($context eq 'webdav') {
12256: if ($settings->{$context}->{'default'}) {
12257: $defcheck = ' checked="checked" ';
12258: }
12259: }
12260: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12261: $defcheck = ' checked="checked" ';
12262: }
1.99 raeburn 12263: }
1.429 raeburn 12264: $output .= '<span class="LC_nobreak"><label>'.
12265: '<input type="checkbox" name="'.$context.'" '.
12266: 'value="default"'.$defcheck.$onclick.'/>'.
12267: $othertitle.'</label></span>';
1.26 raeburn 12268: }
1.23 raeburn 12269: }
1.315 raeburn 12270: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12271: return $output;
1.23 raeburn 12272: }
12273:
12274: sub sorted_searchtitles {
12275: my %searchtitles = &Apache::lonlocal::texthash(
12276: 'uname' => 'username',
12277: 'lastname' => 'last name',
12278: 'lastfirst' => 'last name, first name',
12279: );
12280: my @titleorder = ('uname','lastname','lastfirst');
12281: return (\%searchtitles,\@titleorder);
12282: }
12283:
1.25 raeburn 12284: sub sorted_searchtypes {
12285: my %srchtypes_desc = (
12286: exact => 'is exact match',
12287: contains => 'contains ..',
12288: begins => 'begins with ..',
12289: );
12290: my @srchtypeorder = ('exact','begins','contains');
12291: return (\%srchtypes_desc,\@srchtypeorder);
12292: }
12293:
1.3 raeburn 12294: sub usertype_update_row {
12295: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12296: my $datatable;
12297: my $numinrow = 4;
12298: foreach my $type (@{$types}) {
12299: if (defined($usertypes->{$type})) {
12300: $$rownums ++;
12301: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12302: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12303: '</td><td class="LC_left_item"><table>';
12304: for (my $i=0; $i<@{$fields}; $i++) {
12305: my $rem = $i%($numinrow);
12306: if ($rem == 0) {
12307: if ($i > 0) {
12308: $datatable .= '</tr>';
12309: }
12310: $datatable .= '<tr>';
12311: }
12312: my $check = ' ';
1.39 raeburn 12313: if (ref($settings) eq 'HASH') {
12314: if (ref($settings->{'fields'}) eq 'HASH') {
12315: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12316: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12317: $check = ' checked="checked" ';
12318: }
1.3 raeburn 12319: }
12320: }
12321: }
12322:
12323: if ($i == @{$fields}-1) {
12324: my $colsleft = $numinrow - $rem;
12325: if ($colsleft > 1) {
12326: $datatable .= '<td colspan="'.$colsleft.'">';
12327: } else {
12328: $datatable .= '<td>';
12329: }
12330: } else {
12331: $datatable .= '<td>';
12332: }
1.8 raeburn 12333: $datatable .= '<span class="LC_nobreak"><label>'.
12334: '<input type="checkbox" name="updateable_'.$type.
12335: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12336: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12337: }
12338: $datatable .= '</tr></table></td></tr>';
12339: }
12340: }
12341: return $datatable;
1.1 raeburn 12342: }
12343:
12344: sub modify_login {
1.205 raeburn 12345: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12346: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12347: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12348: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12349: %title = ( coursecatalog => 'Display course catalog',
12350: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12351: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12352: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12353: loginheader => 'Log-in box header',
12354: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12355: @offon = ('off','on');
1.112 raeburn 12356: if (ref($domconfig{login}) eq 'HASH') {
12357: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12358: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12359: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12360: }
12361: }
1.386 raeburn 12362: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12363: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12364: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12365: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12366: $saml{$lonhost} = 1;
12367: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12368: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12369: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12370: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12371: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12372: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12373: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12374: }
12375: }
12376: }
1.112 raeburn 12377: }
1.9 raeburn 12378: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12379: \%domconfig,\%loginhash);
1.188 raeburn 12380: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12381: foreach my $item (@toggles) {
12382: $loginhash{login}{$item} = $env{'form.'.$item};
12383: }
1.41 raeburn 12384: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12385: if (ref($colchanges{'login'}) eq 'HASH') {
12386: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12387: \%loginhash);
12388: }
1.110 raeburn 12389:
1.149 raeburn 12390: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12391: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12392: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12393: if (keys(%servers) > 1) {
12394: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12395: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12396: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12397: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12398: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12399: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12400: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12401: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12402: $changes{'loginvia'}{$lonhost} = 1;
12403: } else {
12404: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12405: $changes{'loginvia'}{$lonhost} = 1;
12406: }
12407: } else {
12408: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12409: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12410: $changes{'loginvia'}{$lonhost} = 1;
12411: }
12412: }
12413: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12414: foreach my $item (@loginvia_attribs) {
12415: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12416: }
12417: } else {
12418: foreach my $item (@loginvia_attribs) {
12419: my $new = $env{'form.'.$lonhost.'_'.$item};
12420: if (($item eq 'serverpath') && ($new eq 'custom')) {
12421: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12422: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12423: $new = '/';
12424: }
12425: }
12426: if (($item eq 'custompath') &&
12427: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12428: $new = '';
12429: }
12430: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12431: $changes{'loginvia'}{$lonhost} = 1;
12432: }
12433: if ($item eq 'exempt') {
1.256 raeburn 12434: $new = &check_exempt_addresses($new);
1.128 raeburn 12435: }
12436: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12437: }
12438: }
1.112 raeburn 12439: } else {
1.128 raeburn 12440: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12441: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12442: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12443: foreach my $item (@loginvia_attribs) {
12444: my $new = $env{'form.'.$lonhost.'_'.$item};
12445: if (($item eq 'serverpath') && ($new eq 'custom')) {
12446: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12447: $new = '/';
12448: }
12449: }
12450: if (($item eq 'custompath') &&
12451: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12452: $new = '';
12453: }
12454: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12455: }
1.110 raeburn 12456: }
12457: }
12458: }
12459: }
1.119 raeburn 12460:
1.168 raeburn 12461: my $servadm = $r->dir_config('lonAdmEMail');
12462: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12463: if (ref($domconfig{'login'}) eq 'HASH') {
12464: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12465: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12466: if ($lang eq 'nolang') {
12467: push(@currlangs,$lang);
12468: } elsif (defined($langchoices{$lang})) {
12469: push(@currlangs,$lang);
12470: } else {
12471: next;
12472: }
12473: }
12474: }
12475: }
12476: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12477: if (@currlangs > 0) {
12478: foreach my $lang (@currlangs) {
12479: if (grep(/^\Q$lang\E$/,@delurls)) {
12480: $changes{'helpurl'}{$lang} = 1;
12481: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12482: $changes{'helpurl'}{$lang} = 1;
12483: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12484: push(@newlangs,$lang);
12485: } else {
12486: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12487: }
12488: }
12489: }
12490: unless (grep(/^nolang$/,@currlangs)) {
12491: if ($env{'form.loginhelpurl_nolang.filename'}) {
12492: $changes{'helpurl'}{'nolang'} = 1;
12493: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12494: push(@newlangs,'nolang');
12495: }
12496: }
12497: if ($env{'form.loginhelpurl_add_lang'}) {
12498: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12499: ($env{'form.loginhelpurl_add_file.filename'})) {
12500: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12501: $addedfile = $env{'form.loginhelpurl_add_lang'};
12502: }
12503: }
12504: if ((@newlangs > 0) || ($addedfile)) {
12505: my $error;
12506: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12507: if ($configuserok eq 'ok') {
12508: if ($switchserver) {
12509: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12510: } elsif ($author_ok eq 'ok') {
12511: my @allnew = @newlangs;
12512: if ($addedfile ne '') {
12513: push(@allnew,$addedfile);
12514: }
1.421 raeburn 12515: my $modified = [];
1.168 raeburn 12516: foreach my $lang (@allnew) {
12517: my $formelem = 'loginhelpurl_'.$lang;
12518: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12519: $formelem = 'loginhelpurl_add_file';
12520: }
1.425 raeburn 12521: (my $result,$newurl{$lang}) =
1.421 raeburn 12522: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12523: "help/$lang",'','',$newfile{$lang},
12524: $modified);
1.168 raeburn 12525: if ($result eq 'ok') {
12526: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12527: $changes{'helpurl'}{$lang} = 1;
12528: } else {
12529: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12530: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12531: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12532: (!grep(/^\Q$lang\E$/,@delurls))) {
12533: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12534: }
12535: }
12536: }
1.421 raeburn 12537: &update_modify_urls($r,$modified);
1.168 raeburn 12538: } else {
12539: $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);
12540: }
12541: } else {
12542: $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);
12543: }
12544: if ($error) {
12545: &Apache::lonnet::logthis($error);
12546: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12547: }
12548: }
1.256 raeburn 12549:
12550: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12551: if (ref($domconfig{'login'}) eq 'HASH') {
12552: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12553: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12554: if ($domservers{$lonhost}) {
12555: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12556: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12557: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12558: }
12559: }
12560: }
12561: }
12562: }
12563: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12564: foreach my $lonhost (sort(keys(%domservers))) {
12565: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12566: $changes{'headtag'}{$lonhost} = 1;
12567: } else {
12568: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12569: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12570: }
12571: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12572: push(@newhosts,$lonhost);
12573: } elsif ($currheadtagurls{$lonhost}) {
12574: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12575: if ($currexempt{$lonhost}) {
1.289 raeburn 12576: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12577: $changes{'headtag'}{$lonhost} = 1;
12578: }
12579: } elsif ($possexempt{$lonhost}) {
12580: $changes{'headtag'}{$lonhost} = 1;
12581: }
12582: if ($possexempt{$lonhost}) {
12583: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12584: }
12585: }
12586: }
12587: }
12588: if (@newhosts) {
12589: my $error;
12590: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12591: if ($configuserok eq 'ok') {
12592: if ($switchserver) {
12593: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12594: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12595: my $modified = [];
1.256 raeburn 12596: foreach my $lonhost (@newhosts) {
12597: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12598: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12599: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12600: "login/headtag/$lonhost",'','',
12601: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12602: $modified);
1.256 raeburn 12603: if ($result eq 'ok') {
12604: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12605: $changes{'headtag'}{$lonhost} = 1;
12606: if ($possexempt{$lonhost}) {
12607: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12608: }
12609: } else {
12610: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12611: $newheadtagurls{$lonhost},$result);
12612: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12613: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12614: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12615: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12616: }
12617: }
12618: }
1.421 raeburn 12619: &update_modify_urls($r,$modified);
1.256 raeburn 12620: } else {
12621: $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);
12622: }
12623: } else {
12624: $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);
12625: }
12626: if ($error) {
12627: &Apache::lonnet::logthis($error);
12628: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12629: }
12630: }
1.386 raeburn 12631: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12632: my @newsamlimgs;
12633: foreach my $lonhost (keys(%domservers)) {
12634: if ($env{'form.saml_'.$lonhost}) {
12635: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12636: push(@newsamlimgs,$lonhost);
12637: }
1.412 raeburn 12638: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12639: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12640: }
12641: if ($saml{$lonhost}) {
1.412 raeburn 12642: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12643: $env{'form.saml_window_'.$lonhost} = '';
12644: }
1.386 raeburn 12645: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12646: #FIXME Need to obsolete published image
12647: delete($currsaml{$lonhost}{'img'});
12648: $changes{'saml'}{$lonhost} = 1;
12649: }
12650: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12651: $changes{'saml'}{$lonhost} = 1;
12652: }
12653: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12654: $changes{'saml'}{$lonhost} = 1;
12655: }
12656: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12657: $changes{'saml'}{$lonhost} = 1;
12658: }
12659: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12660: $changes{'saml'}{$lonhost} = 1;
12661: }
1.412 raeburn 12662: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12663: $changes{'saml'}{$lonhost} = 1;
12664: }
1.386 raeburn 12665: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12666: $changes{'saml'}{$lonhost} = 1;
12667: }
12668: } else {
12669: $changes{'saml'}{$lonhost} = 1;
12670: }
1.412 raeburn 12671: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12672: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12673: }
12674: } else {
1.425 raeburn 12675: if ($saml{$lonhost}) {
1.389 raeburn 12676: $changes{'saml'}{$lonhost} = 1;
12677: delete($currsaml{$lonhost});
12678: }
1.386 raeburn 12679: }
12680: }
12681: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12682: unless (exists($domservers{$posshost})) {
12683: delete($currsaml{$posshost});
1.386 raeburn 12684: }
12685: }
12686: %{$loginhash{'login'}{'saml'}} = %currsaml;
12687: if (@newsamlimgs) {
12688: my $error;
12689: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12690: if ($configuserok eq 'ok') {
12691: if ($switchserver) {
12692: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12693: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12694: my $modified = [];
1.386 raeburn 12695: foreach my $lonhost (@newsamlimgs) {
12696: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12697: my ($result,$imgurl) =
1.421 raeburn 12698: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12699: "login/saml/$lonhost",'','',
12700: $env{'form.saml_img_'.$lonhost.'.filename'},
12701: $modified);
1.386 raeburn 12702: if ($result eq 'ok') {
12703: $currsaml{$lonhost}{'img'} = $imgurl;
12704: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12705: $changes{'saml'}{$lonhost} = 1;
12706: } else {
12707: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12708: $lonhost,$result);
12709: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12710: }
12711: }
1.421 raeburn 12712: &update_modify_urls($r,$modified);
1.386 raeburn 12713: } else {
12714: $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);
12715: }
12716: } else {
12717: $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);
12718: }
12719: if ($error) {
12720: &Apache::lonnet::logthis($error);
12721: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12722: }
12723: }
1.169 raeburn 12724: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12725:
12726: my $defaulthelpfile = '/adm/loginproblems.html';
12727: my $defaulttext = &mt('Default in use');
12728:
1.1 raeburn 12729: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12730: $dom);
12731: if ($putresult eq 'ok') {
1.188 raeburn 12732: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12733: my %defaultchecked = (
12734: 'coursecatalog' => 'on',
1.188 raeburn 12735: 'helpdesk' => 'on',
1.42 raeburn 12736: 'adminmail' => 'off',
1.43 raeburn 12737: 'newuser' => 'off',
1.42 raeburn 12738: );
1.55 raeburn 12739: if (ref($domconfig{'login'}) eq 'HASH') {
12740: foreach my $item (@toggles) {
12741: if ($defaultchecked{$item} eq 'on') {
12742: if (($domconfig{'login'}{$item} eq '0') &&
12743: ($env{'form.'.$item} eq '1')) {
12744: $changes{$item} = 1;
12745: } elsif (($domconfig{'login'}{$item} eq '' ||
12746: $domconfig{'login'}{$item} eq '1') &&
12747: ($env{'form.'.$item} eq '0')) {
12748: $changes{$item} = 1;
12749: }
12750: } elsif ($defaultchecked{$item} eq 'off') {
12751: if (($domconfig{'login'}{$item} eq '1') &&
12752: ($env{'form.'.$item} eq '0')) {
12753: $changes{$item} = 1;
12754: } elsif (($domconfig{'login'}{$item} eq '' ||
12755: $domconfig{'login'}{$item} eq '0') &&
12756: ($env{'form.'.$item} eq '1')) {
12757: $changes{$item} = 1;
12758: }
1.42 raeburn 12759: }
12760: }
1.41 raeburn 12761: }
1.6 raeburn 12762: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12763: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12764: if (exists($changes{'saml'})) {
12765: my $hostid_in_use;
12766: my @hosts = &Apache::lonnet::current_machine_ids();
12767: if (@hosts > 1) {
12768: foreach my $hostid (@hosts) {
12769: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12770: $hostid_in_use = $hostid;
12771: last;
12772: }
12773: }
12774: } else {
12775: $hostid_in_use = $r->dir_config('lonHostID');
12776: }
12777: if (($hostid_in_use) &&
12778: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12779: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12780: }
12781: if (ref($lastactref) eq 'HASH') {
12782: if (ref($changes{'saml'}) eq 'HASH') {
12783: my %updates;
12784: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12785: $lastactref->{'samllanding'} = \%updates;
12786: }
12787: }
12788: }
1.212 raeburn 12789: if (ref($lastactref) eq 'HASH') {
12790: $lastactref->{'domainconfig'} = 1;
12791: }
1.1 raeburn 12792: $resulttext = &mt('Changes made:').'<ul>';
12793: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12794: if ($item eq 'loginvia') {
1.112 raeburn 12795: if (ref($changes{$item}) eq 'HASH') {
12796: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12797: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12798: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12799: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12800: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12801: $protocol = 'http' if ($protocol ne 'https');
12802: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12803:
12804: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12805: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12806: } else {
12807: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12808: }
12809: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12810: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12811: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12812: }
12813: $resulttext .= '</li>';
12814: } else {
12815: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12816: }
1.112 raeburn 12817: } else {
1.128 raeburn 12818: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12819: }
12820: }
1.128 raeburn 12821: $resulttext .= '</ul></li>';
1.112 raeburn 12822: }
1.168 raeburn 12823: } elsif ($item eq 'helpurl') {
12824: if (ref($changes{$item}) eq 'HASH') {
12825: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12826: if (grep(/^\Q$lang\E$/,@delurls)) {
12827: my ($chg,$link);
12828: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12829: if ($lang eq 'nolang') {
12830: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12831: } else {
12832: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12833: }
12834: $resulttext .= '<li>'.$chg.'</li>';
12835: } else {
12836: my $chg;
12837: if ($lang eq 'nolang') {
12838: $chg = &mt('custom log-in help file for no preferred language');
12839: } else {
12840: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12841: }
12842: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12843: $loginhash{'login'}{'helpurl'}{$lang}.
12844: '?inhibitmenu=yes',$chg,600,500).
12845: '</li>';
12846: }
12847: }
12848: }
1.256 raeburn 12849: } elsif ($item eq 'headtag') {
12850: if (ref($changes{$item}) eq 'HASH') {
12851: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12852: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12853: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12854: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12855: $resulttext .= '<li><a href="'.
12856: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12857: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12858: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12859: if ($possexempt{$lonhost}) {
12860: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12861: } else {
12862: $resulttext .= &mt('included for any client IP');
12863: }
12864: $resulttext .= '</li>';
12865: }
12866: }
12867: }
1.386 raeburn 12868: } elsif ($item eq 'saml') {
12869: if (ref($changes{$item}) eq 'HASH') {
12870: my %notlt = (
12871: text => 'Text for log-in by SSO',
12872: img => 'SSO button image',
12873: alt => 'Alt text for button image',
12874: url => 'SSO URL',
12875: title => 'Tooltip for SSO link',
1.412 raeburn 12876: window => 'Pop-up window if iframe',
1.386 raeburn 12877: notsso => 'Text for non-SSO log-in',
12878: );
12879: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12880: if (ref($currsaml{$lonhost}) eq 'HASH') {
12881: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12882: '<ul>';
1.412 raeburn 12883: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 12884: if ($currsaml{$lonhost}{$key} eq '') {
12885: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12886: } else {
12887: my $value = "'$currsaml{$lonhost}{$key}'";
12888: if ($key eq 'img') {
12889: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 12890: } elsif ($key eq 'window') {
12891: $value = 'On';
1.386 raeburn 12892: }
12893: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12894: $value).'</li>';
12895: }
12896: }
12897: $resulttext .= '</ul></li>';
12898: } else {
12899: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12900: }
12901: }
12902: }
1.169 raeburn 12903: } elsif ($item eq 'captcha') {
12904: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12905: my $chgtxt;
1.169 raeburn 12906: if ($loginhash{'login'}{$item} eq 'notused') {
12907: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12908: } else {
12909: my %captchas = &captcha_phrases();
12910: if ($captchas{$loginhash{'login'}{$item}}) {
12911: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12912: } else {
12913: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12914: }
12915: }
12916: $resulttext .= '<li>'.$chgtxt.'</li>';
12917: }
12918: } elsif ($item eq 'recaptchakeys') {
12919: if (ref($loginhash{'login'}) eq 'HASH') {
12920: my ($privkey,$pubkey);
12921: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
12922: $pubkey = $loginhash{'login'}{$item}{'public'};
12923: $privkey = $loginhash{'login'}{$item}{'private'};
12924: }
12925: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
12926: if (!$pubkey) {
12927: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
12928: } else {
12929: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12930: }
12931: if (!$privkey) {
12932: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
12933: } else {
1.251 raeburn 12934: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 12935: }
12936: $chgtxt .= '</ul>';
12937: $resulttext .= '<li>'.$chgtxt.'</li>';
12938: }
1.269 raeburn 12939: } elsif ($item eq 'recaptchaversion') {
12940: if (ref($loginhash{'login'}) eq 'HASH') {
12941: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 12942: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 12943: '</li>';
12944: }
12945: }
1.41 raeburn 12946: } else {
12947: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
12948: }
1.1 raeburn 12949: }
1.6 raeburn 12950: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 12951: } else {
12952: $resulttext = &mt('No changes made to log-in page settings');
12953: }
12954: } else {
1.11 albertel 12955: $resulttext = '<span class="LC_error">'.
12956: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12957: }
1.6 raeburn 12958: if ($errors) {
1.9 raeburn 12959: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 12960: $errors.'</ul>';
12961: }
12962: return $resulttext;
12963: }
12964:
1.256 raeburn 12965: sub check_exempt_addresses {
12966: my ($iplist) = @_;
12967: $iplist =~ s/^\s+//;
12968: $iplist =~ s/\s+$//;
12969: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
12970: my (@okips,$new);
12971: foreach my $ip (@poss_ips) {
12972: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
12973: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
12974: push(@okips,$ip);
12975: }
12976: }
12977: }
12978: if (@okips > 0) {
12979: $new = join(',',@okips);
12980: } else {
12981: $new = '';
12982: }
12983: return $new;
12984: }
12985:
1.6 raeburn 12986: sub color_font_choices {
12987: my %choices =
12988: &Apache::lonlocal::texthash (
12989: img => "Header",
12990: bgs => "Background colors",
12991: links => "Link colors",
1.55 raeburn 12992: images => "Images",
1.6 raeburn 12993: font => "Font color",
1.201 raeburn 12994: fontmenu => "Font menu",
1.76 raeburn 12995: pgbg => "Page",
1.6 raeburn 12996: tabbg => "Header",
12997: sidebg => "Border",
12998: link => "Link",
12999: alink => "Active link",
13000: vlink => "Visited link",
13001: );
13002: return %choices;
13003: }
13004:
1.394 raeburn 13005: sub modify_ipaccess {
13006: my ($dom,$lastactref,%domconfig) = @_;
13007: my (@allpos,%changes,%confhash,$errors,$resulttext);
13008: my (@items,%deletions,%itemids,@warnings);
13009: my ($typeorder,$types) = &commblocktype_text();
13010: if ($env{'form.ipaccess_add'}) {
13011: my $name = $env{'form.ipaccess_name_add'};
13012: my ($newid,$error) = &get_ipaccess_id($dom,$name);
13013: if ($newid) {
13014: $itemids{'add'} = $newid;
13015: push(@items,'add');
13016: $changes{$newid} = 1;
13017: } else {
13018: $error = &mt('Failed to acquire unique ID for new IP access control item');
13019: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13020: }
13021: }
13022: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13023: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13024: if (@todelete) {
13025: map { $deletions{$_} = 1; } @todelete;
13026: }
13027: my $maxnum = $env{'form.ipaccess_maxnum'};
13028: for (my $i=0; $i<$maxnum; $i++) {
13029: my $itemid = $env{'form.ipaccess_id_'.$i};
13030: $itemid =~ s/\D+//g;
13031: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13032: if ($deletions{$itemid}) {
13033: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13034: } else {
13035: push(@items,$i);
13036: $itemids{$i} = $itemid;
13037: }
13038: }
13039: }
13040: }
13041: foreach my $idx (@items) {
13042: my $itemid = $itemids{$idx};
13043: next unless ($itemid);
13044: my %current;
13045: unless ($idx eq 'add') {
13046: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13047: %current = %{$domconfig{'ipaccess'}{$itemid}};
13048: }
13049: }
13050: my $position = $env{'form.ipaccess_pos_'.$itemid};
13051: $position =~ s/\D+//g;
13052: if ($position ne '') {
13053: $allpos[$position] = $itemid;
13054: }
13055: my $name = $env{'form.ipaccess_name_'.$idx};
13056: $name =~ s/^\s+|\s+$//g;
13057: $confhash{$itemid}{'name'} = $name;
13058: my $possrange = $env{'form.ipaccess_range_'.$idx};
13059: $possrange =~ s/^\s+|\s+$//g;
13060: unless ($possrange eq '') {
13061: $possrange =~ s/[\r\n]+/\s/g;
13062: $possrange =~ s/\s*-\s*/-/g;
13063: $possrange =~ s/\s+/,/g;
13064: $possrange =~ s/,+/,/g;
13065: if ($possrange ne '') {
13066: my (@ok,$count);
1.425 raeburn 13067: $count = 0;
1.394 raeburn 13068: foreach my $poss (split(/\,/,$possrange)) {
13069: $count ++;
13070: $poss = &validate_ip_pattern($poss);
13071: if ($poss ne '') {
13072: push(@ok,$poss);
13073: }
13074: }
13075: my $diff = $count - scalar(@ok);
13076: if ($diff) {
13077: $errors .= '<li><span class="LC_error">'.
13078: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13079: $diff,$name).
13080: '</span></li>';
13081: }
13082: if (@ok) {
13083: my @cidr_list;
13084: foreach my $item (@ok) {
13085: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13086: }
13087: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13088: }
13089: }
13090: }
13091: foreach my $field ('name','ip') {
13092: unless (($idx eq 'add') || ($changes{$itemid})) {
13093: if ($current{$field} ne $confhash{$itemid}{$field}) {
13094: $changes{$itemid} = 1;
13095: last;
13096: }
13097: }
13098: }
13099: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13100:
1.394 raeburn 13101: my %commblocks;
1.425 raeburn 13102: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13103: foreach my $type (@{$typeorder}) {
13104: if ($commblocks{$type}) {
13105: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13106: }
13107: unless (($idx eq 'add') || ($changes{$itemid})) {
13108: if (ref($current{'commblocks'}) eq 'HASH') {
13109: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13110: $changes{$itemid} = 1;
13111: }
13112: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13113: $changes{$itemid} = 1;
13114: }
13115: }
13116: }
13117: $confhash{$itemid}{'courses'} = {};
13118: my %crsdeletions;
13119: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13120: if (@delcrs) {
13121: map { $crsdeletions{$_} = 1; } @delcrs;
13122: }
13123: if (ref($current{'courses'}) eq 'HASH') {
13124: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13125: if ($crsdeletions{$cid}) {
13126: $changes{$itemid} = 1;
13127: } else {
13128: $confhash{$itemid}{'courses'}{$cid} = 1;
13129: }
13130: }
13131: }
13132: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13133: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13134: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13135: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13136: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13137: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13138: $errors .= '<li><span class="LC_error">'.
13139: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13140: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13141: '</span></li>';
13142: } else {
13143: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13144: $changes{$itemid} = 1;
13145: }
13146: }
13147: }
13148: if (@allpos > 0) {
13149: my $idx = 0;
13150: foreach my $itemid (@allpos) {
13151: if ($itemid ne '') {
13152: $confhash{$itemid}{'order'} = $idx;
13153: unless ($changes{$itemid}) {
13154: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13155: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13156: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13157: $changes{$itemid} = 1;
13158: }
13159: }
13160: }
13161: }
13162: $idx ++;
13163: }
13164: }
13165: }
13166: if (keys(%changes)) {
13167: my %defaultshash = (
13168: ipaccess => \%confhash,
13169: );
13170: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13171: $dom);
13172: if ($putresult eq 'ok') {
13173: my $cachetime = 1800;
13174: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13175: if (ref($lastactref) eq 'HASH') {
13176: $lastactref->{'ipaccess'} = 1;
13177: }
13178: $resulttext = &mt('Changes made:').'<ul>';
13179: my %bynum;
13180: foreach my $itemid (sort(keys(%changes))) {
13181: if (ref($confhash{$itemid}) eq 'HASH') {
13182: my $position = $confhash{$itemid}{'order'};
13183: if ($position =~ /^\d+$/) {
13184: $bynum{$position} = $itemid;
13185: }
13186: }
13187: }
13188: if (keys(%deletions)) {
13189: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13190: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13191: }
13192: }
13193: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13194: my $itemid = $bynum{$pos};
13195: if (ref($confhash{$itemid}) eq 'HASH') {
13196: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13197: my $position = $pos + 1;
13198: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13199: if ($confhash{$itemid}{'ip'} eq '') {
13200: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13201: } else {
13202: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13203: }
13204: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13205: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13206: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13207: '</li>';
13208: } else {
13209: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13210: }
13211: if (keys(%{$confhash{$itemid}{'courses'}})) {
13212: my @courses;
13213: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13214: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13215: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13216: }
13217: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13218: join('</li><li>',@courses).'</li></ul>';
13219: } else {
13220: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13221: }
1.395 raeburn 13222: $resulttext .= '</ul></li>';
1.394 raeburn 13223: }
13224: }
1.395 raeburn 13225: $resulttext .= '</ul>';
1.394 raeburn 13226: } else {
13227: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13228: }
13229: } else {
13230: $resulttext = &mt('No changes made');
13231: }
13232: if ($errors) {
13233: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13234: $errors.'</ul></p>';
13235: }
13236: return $resulttext;
13237: }
13238:
13239: sub get_ipaccess_id {
13240: my ($domain,$location) = @_;
13241: # get lock on ipaccess db
13242: my $lockhash = {
13243: lock => $env{'user.name'}.
13244: ':'.$env{'user.domain'},
13245: };
13246: my $tries = 0;
13247: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13248: my ($id,$error);
13249:
13250: while (($gotlock ne 'ok') && ($tries<10)) {
13251: $tries ++;
13252: sleep (0.1);
13253: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13254: }
13255: if ($gotlock eq 'ok') {
13256: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13257: if ($currids{'lock'}) {
13258: delete($currids{'lock'});
13259: if (keys(%currids)) {
13260: my @curr = sort { $a <=> $b } keys(%currids);
13261: if ($curr[-1] =~ /^\d+$/) {
13262: $id = 1 + $curr[-1];
13263: }
13264: } else {
13265: $id = 1;
13266: }
13267: if ($id) {
13268: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13269: $error = 'nostore';
13270: }
13271: } else {
13272: $error = 'nonumber';
13273: }
13274: }
13275: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13276: } else {
13277: $error = 'nolock';
13278: }
13279: return ($id,$error);
13280: }
13281:
1.429 raeburn 13282: sub modify_authordefaults {
13283: my ($dom,$lastactref,%domconfig) = @_;
13284: #
13285: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13286: #
13287: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13288: if (ref($domconfig{'quotas'}) eq 'HASH') {
13289: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13290: if ($key =~ /^webdav|authorquota$/) {
13291: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13292: } else {
13293: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13294: }
13295: }
13296: }
13297: my %staticdefaults = (
13298: 'copyright' => 'default',
13299: 'sourceavail' => 'closed',
13300: 'nocodemirror' => 'off',
13301: 'domcoordacc' => 'on',
13302: 'editors' => ['edit','xml'].
13303: 'authorquota' => 500,
13304: 'webdav' => 0,
13305: );
13306: my %titles = &authordefaults_titles();
13307: foreach my $item ('nocodemirror','domcoordacc') {
13308: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13309: $confhash{$item} = $env{'form.'.$item};
13310: }
13311: }
13312: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13313: $confhash{'copyright'} = $1;
13314: }
13315: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13316: $confhash{'sourceavail'} = $1;
13317: }
13318: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13319: my @okeditors = ('edit','xml','daxe');
13320: my @editors;
13321: foreach my $item (@posseditors) {
13322: if (grep(/^\Q$item\E$/,@okeditors)) {
13323: push(@editors,$item);
13324: }
13325: }
13326: $confhash{'editors'} = \@editors;
13327:
13328: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13329: my @insttypes;
13330: if (ref($types) eq 'ARRAY') {
13331: @insttypes = @{$types};
13332: }
13333: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13334: my %webdav;
13335: map { $webdav{$_} = 1; } @webdavon;
13336: foreach my $type (@insttypes,'default') {
13337: my $possquota = $env{'form.authorquota_'.$type};
13338: if ($possquota =~ /^\d+$/) {
13339: $save_quotas{'authorquota'}{$type} = $possquota;
13340: }
13341: if ($webdav{$type}) {
13342: $save_quotas{'webdav'}{$type} = 1;
13343: } else {
13344: $save_quotas{'webdav'}{$type} = 0;
13345: }
13346: }
13347: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13348: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13349: }
13350: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
13351: foreach my $item ('nocodemirror','domcoordacc','copyright','sourceavail') {
13352: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13353: $changes{$item} = 1;
13354: }
13355: }
13356: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
13357: my @diffs =
13358: &Apache::loncommon::compare_arrays($confhash{'editors'},
13359: $domconfig{'authordefaults'}{'editors'});
13360: unless (@diffs == 0) {
13361: $changes{'editors'} = 1;
13362: }
13363: } else {
13364: my @diffs =
13365: &Apache::loncommon::compare_arrays($confhash{'editors'},
13366: $staticdefaults{'editors'});
13367: unless (@diffs == 0) {
13368: $changes{'editors'} = 1;
13369: }
13370: }
13371: } else {
13372: my @offon = ('off','on');
13373: foreach my $item ('nocodemirror','domcoordacc') {
13374: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
13375: $changes{$item} = 1;
13376: }
13377: }
13378: foreach my $item ('copyright','sourceavail') {
13379: if ($confhash{$item} ne $staticdefaults{$item}) {
13380: $changes{$item} = 1;
13381: }
13382: }
13383: }
13384: foreach my $key ('authorquota','webdav') {
13385: if (ref($curr_quotas{$key}) eq 'HASH') {
13386: foreach my $type (@insttypes,'default') {
13387: if (exists($save_quotas{$key}{$type})) {
13388: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13389: $changes{$key}{$type} = 1;
13390: }
13391: } elsif (exists($curr_quotas{$key}{$type})) {
13392: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13393: } else {
13394: $save_quotas{$key}{$type} = $staticdefaults{$key};
13395: }
13396: }
13397: } else {
13398: foreach my $type (@insttypes,'default') {
13399: if (exists($save_quotas{$key}{$type})) {
13400: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13401: $changes{$key}{$type} = 1;
13402: }
13403: } else {
13404: $save_quotas{$key}{$type} = $staticdefaults{$key};
13405: }
13406: }
13407: }
13408: }
13409: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13410: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13411: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
13412: $changes{'webdav_LC_adv'} = 1;
13413: }
13414: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13415: $changes{'webdav_LC_adv'} = 1;
13416: }
13417: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13418: $changes{'webdav_LC_adv'} = 1;
13419: }
13420: my %confighash = (
13421: quotas => \%save_quotas,
13422: authordefaults => \%confhash,
13423: );
13424: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13425: $dom);
13426: my $resulttext;
13427: if ($putresult eq 'ok') {
13428: if (keys(%changes)) {
1.431 raeburn 13429: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13430: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
13431: ($changes{'webdav_LC_adv'})) {
13432: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13433: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13434: }
13435: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13436: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13437: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13438: }
13439: }
13440: $resulttext = &mt('Changes made:').'<ul>';
13441: my $authoroverride;
13442: foreach my $key ('nocodemirror','domcoordacc','copyright','sourceavail') {
13443: if (exists($changes{$key})) {
1.431 raeburn 13444: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13445: my $shown;
13446: unless ($authoroverride) {
13447: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13448: $authoroverride = 1;
13449: }
13450: if (($key eq 'nocodemirror') || ($key eq 'domcoordacc')) {
13451: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13452: } elsif ($key eq 'copyright') {
13453: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13454: } elsif ($key eq 'sourceavail') {
13455: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13456: }
13457: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
13458: }
13459: }
13460: if ($authoroverride) {
13461: $resulttext .= '</ul></li>';
13462: }
13463: my $domcoordoverride;
13464: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv') {
13465: if (exists($changes{$key})) {
13466: my $shown;
13467: unless ($domcoordoverride) {
13468: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13469: $domcoordoverride = 1;
13470: }
13471: if ($key eq 'editors') {
1.431 raeburn 13472: if (ref($confhash{'editors'}) eq 'ARRAY') {
13473: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
13474: if (@{$confhash{'editors'}}) {
13475: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
13476: } else {
13477: $shown = &mt('None');
13478: }
1.429 raeburn 13479: }
13480: } elsif ($key eq 'authorquota') {
13481: foreach my $type (@insttypes) {
13482: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13483: }
13484: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13485: } elsif ($key eq 'webdav') {
13486: foreach my $type (@insttypes) {
13487: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13488: }
13489: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13490: } elsif ($key eq 'webdav_LC_adv') {
13491: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13492: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13493: } else {
13494: $shown = $titles{'none'};
13495: }
13496: }
13497: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
13498: }
13499: }
13500: if ($domcoordoverride) {
13501: $resulttext .= '</ul></li>';
13502: }
1.431 raeburn 13503: my $cachetime = 24*60*60;
13504: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13505: if (ref($lastactref) eq 'HASH') {
13506: $lastactref->{'domdefaults'} = 1;
13507: }
1.429 raeburn 13508: } else {
13509: $resulttext = &mt('No changes made to Authoring Space defaults');
13510: }
13511: }
13512: return $resulttext;
13513: }
13514:
1.6 raeburn 13515: sub modify_rolecolors {
1.205 raeburn 13516: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13517: my ($resulttext,%rolehash);
13518: $rolehash{'rolecolors'} = {};
1.55 raeburn 13519: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13520: if ($domconfig{'rolecolors'} eq '') {
13521: $domconfig{'rolecolors'} = {};
13522: }
13523: }
1.9 raeburn 13524: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13525: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13526: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13527: $dom);
13528: if ($putresult eq 'ok') {
13529: if (keys(%changes) > 0) {
1.41 raeburn 13530: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13531: if (ref($lastactref) eq 'HASH') {
13532: $lastactref->{'domainconfig'} = 1;
13533: }
1.6 raeburn 13534: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13535: $rolehash{'rolecolors'});
13536: } else {
13537: $resulttext = &mt('No changes made to default color schemes');
13538: }
13539: } else {
1.11 albertel 13540: $resulttext = '<span class="LC_error">'.
13541: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13542: }
13543: if ($errors) {
13544: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13545: $errors.'</ul>';
13546: }
13547: return $resulttext;
13548: }
13549:
13550: sub modify_colors {
1.9 raeburn 13551: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13552: my (%changes,%choices);
1.51 raeburn 13553: my @bgs;
1.6 raeburn 13554: my @links = ('link','alink','vlink');
1.41 raeburn 13555: my @logintext;
1.6 raeburn 13556: my @images;
13557: my $servadm = $r->dir_config('lonAdmEMail');
13558: my $errors;
1.200 raeburn 13559: my %defaults;
1.6 raeburn 13560: foreach my $role (@{$roles}) {
13561: if ($role eq 'login') {
1.12 raeburn 13562: %choices = &login_choices();
1.41 raeburn 13563: @logintext = ('textcol','bgcol');
1.12 raeburn 13564: } else {
13565: %choices = &color_font_choices();
13566: }
13567: if ($role eq 'login') {
1.41 raeburn 13568: @images = ('img','logo','domlogo','login');
1.51 raeburn 13569: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13570: } else {
13571: @images = ('img');
1.200 raeburn 13572: @bgs = ('pgbg','tabbg','sidebg');
13573: }
13574: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
13575: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
13576: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13577: }
13578: if ($role eq 'login') {
13579: foreach my $item (@logintext) {
1.234 raeburn 13580: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13581: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13582: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13583: }
13584: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13585: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13586: }
13587: }
13588: } else {
1.234 raeburn 13589: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13590: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13591: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13592: }
13593: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13594: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13595: }
1.6 raeburn 13596: }
1.200 raeburn 13597: foreach my $item (@bgs) {
1.234 raeburn 13598: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13599: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13600: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13601: }
13602: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13603: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13604: }
13605: }
13606: foreach my $item (@links) {
1.234 raeburn 13607: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13608: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13609: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13610: }
13611: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13612: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13613: }
1.6 raeburn 13614: }
1.46 raeburn 13615: my ($configuserok,$author_ok,$switchserver) =
13616: &config_check($dom,$confname,$servadm);
1.9 raeburn 13617: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13618: if (ref($domconfig->{$role}) ne 'HASH') {
13619: $domconfig->{$role} = {};
13620: }
1.8 raeburn 13621: foreach my $img (@images) {
1.402 raeburn 13622: if ($role eq 'login') {
13623: if (($img eq 'img') || ($img eq 'logo')) {
13624: if (defined($env{'form.login_showlogo_'.$img})) {
13625: $confhash->{$role}{'showlogo'}{$img} = 1;
13626: } else {
13627: $confhash->{$role}{'showlogo'}{$img} = 0;
13628: }
13629: }
13630: if ($env{'form.login_alt_'.$img} ne '') {
13631: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13632: }
1.402 raeburn 13633: }
1.18 albertel 13634: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13635: && !defined($domconfig->{$role}{$img})
13636: && !$env{'form.'.$role.'_del_'.$img}
13637: && $env{'form.'.$role.'_import_'.$img}) {
13638: # import the old configured image from the .tab setting
13639: # if they haven't provided a new one
13640: $domconfig->{$role}{$img} =
13641: $env{'form.'.$role.'_import_'.$img};
13642: }
1.6 raeburn 13643: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13644: my $error;
1.6 raeburn 13645: if ($configuserok eq 'ok') {
1.9 raeburn 13646: if ($switchserver) {
1.12 raeburn 13647: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13648: } else {
13649: if ($author_ok eq 'ok') {
1.421 raeburn 13650: my $modified = [];
1.9 raeburn 13651: my ($result,$logourl) =
1.421 raeburn 13652: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13653: $dom,$confname,$img,$width,$height,
13654: '',$modified);
1.9 raeburn 13655: if ($result eq 'ok') {
13656: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13657: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13658: &update_modify_urls($r,$modified);
1.9 raeburn 13659: } else {
1.12 raeburn 13660: $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 13661: }
13662: } else {
1.46 raeburn 13663: $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 13664: }
13665: }
13666: } else {
1.46 raeburn 13667: $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 13668: }
13669: if ($error) {
1.8 raeburn 13670: &Apache::lonnet::logthis($error);
1.11 albertel 13671: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13672: }
13673: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13674: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13675: my $error;
13676: if ($configuserok eq 'ok') {
13677: # is confname an author?
13678: if ($switchserver eq '') {
13679: if ($author_ok eq 'ok') {
1.421 raeburn 13680: my $modified = [];
1.9 raeburn 13681: my ($result,$logourl) =
1.421 raeburn 13682: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13683: $dom,$confname,$img,$width,$height,
13684: '',$modified);
1.9 raeburn 13685: if ($result eq 'ok') {
13686: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13687: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13688: &update_modify_urls($r,$modified);
1.9 raeburn 13689: }
13690: }
13691: }
13692: }
1.6 raeburn 13693: }
13694: }
13695: }
13696: if (ref($domconfig) eq 'HASH') {
13697: if (ref($domconfig->{$role}) eq 'HASH') {
13698: foreach my $img (@images) {
13699: if ($domconfig->{$role}{$img} ne '') {
13700: if ($env{'form.'.$role.'_del_'.$img}) {
13701: $confhash->{$role}{$img} = '';
1.12 raeburn 13702: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13703: } else {
1.9 raeburn 13704: if ($confhash->{$role}{$img} eq '') {
13705: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13706: }
1.6 raeburn 13707: }
13708: } else {
13709: if ($env{'form.'.$role.'_del_'.$img}) {
13710: $confhash->{$role}{$img} = '';
1.12 raeburn 13711: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13712: }
13713: }
1.402 raeburn 13714: if ($role eq 'login') {
13715: if (($img eq 'logo') || ($img eq 'img')) {
13716: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13717: if ($confhash->{$role}{'showlogo'}{$img} ne
13718: $domconfig->{$role}{'showlogo'}{$img}) {
13719: $changes{$role}{'showlogo'}{$img} = 1;
13720: }
13721: } else {
13722: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13723: $changes{$role}{'showlogo'}{$img} = 1;
13724: }
1.70 raeburn 13725: }
1.402 raeburn 13726: }
13727: if ($img ne 'login') {
13728: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13729: if ($confhash->{$role}{'alttext'}{$img} ne
13730: $domconfig->{$role}{'alttext'}{$img}) {
13731: $changes{$role}{'alttext'}{$img} = 1;
13732: }
13733: } else {
13734: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13735: $changes{$role}{'alttext'}{$img} = 1;
13736: }
1.70 raeburn 13737: }
13738: }
13739: }
13740: }
1.6 raeburn 13741: if ($domconfig->{$role}{'font'} ne '') {
13742: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13743: $changes{$role}{'font'} = 1;
13744: }
13745: } else {
13746: if ($confhash->{$role}{'font'}) {
13747: $changes{$role}{'font'} = 1;
13748: }
13749: }
1.107 raeburn 13750: if ($role ne 'login') {
13751: if ($domconfig->{$role}{'fontmenu'} ne '') {
13752: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13753: $changes{$role}{'fontmenu'} = 1;
13754: }
13755: } else {
13756: if ($confhash->{$role}{'fontmenu'}) {
13757: $changes{$role}{'fontmenu'} = 1;
13758: }
1.97 tempelho 13759: }
13760: }
1.6 raeburn 13761: foreach my $item (@bgs) {
13762: if ($domconfig->{$role}{$item} ne '') {
13763: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13764: $changes{$role}{'bgs'}{$item} = 1;
13765: }
13766: } else {
13767: if ($confhash->{$role}{$item}) {
13768: $changes{$role}{'bgs'}{$item} = 1;
13769: }
13770: }
13771: }
13772: foreach my $item (@links) {
13773: if ($domconfig->{$role}{$item} ne '') {
13774: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13775: $changes{$role}{'links'}{$item} = 1;
13776: }
13777: } else {
13778: if ($confhash->{$role}{$item}) {
13779: $changes{$role}{'links'}{$item} = 1;
13780: }
13781: }
13782: }
1.41 raeburn 13783: foreach my $item (@logintext) {
13784: if ($domconfig->{$role}{$item} ne '') {
13785: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13786: $changes{$role}{'logintext'}{$item} = 1;
13787: }
13788: } else {
13789: if ($confhash->{$role}{$item}) {
13790: $changes{$role}{'logintext'}{$item} = 1;
13791: }
13792: }
13793: }
1.6 raeburn 13794: } else {
13795: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13796: \@logintext,$confhash,\%changes);
1.6 raeburn 13797: }
13798: } else {
13799: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13800: \@logintext,$confhash,\%changes);
1.6 raeburn 13801: }
13802: }
13803: return ($errors,%changes);
13804: }
13805:
1.46 raeburn 13806: sub config_check {
13807: my ($dom,$confname,$servadm) = @_;
13808: my ($configuserok,$author_ok,$switchserver,%currroles);
13809: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13810: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13811: $confname,$servadm);
13812: if ($configuserok eq 'ok') {
13813: $switchserver = &check_switchserver($dom,$confname);
13814: if ($switchserver eq '') {
13815: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13816: }
13817: }
13818: return ($configuserok,$author_ok,$switchserver);
13819: }
13820:
1.6 raeburn 13821: sub default_change_checker {
1.41 raeburn 13822: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13823: foreach my $item (@{$links}) {
13824: if ($confhash->{$role}{$item}) {
13825: $changes->{$role}{'links'}{$item} = 1;
13826: }
13827: }
13828: foreach my $item (@{$bgs}) {
13829: if ($confhash->{$role}{$item}) {
13830: $changes->{$role}{'bgs'}{$item} = 1;
13831: }
13832: }
1.41 raeburn 13833: foreach my $item (@{$logintext}) {
13834: if ($confhash->{$role}{$item}) {
13835: $changes->{$role}{'logintext'}{$item} = 1;
13836: }
13837: }
1.6 raeburn 13838: foreach my $img (@{$images}) {
13839: if ($env{'form.'.$role.'_del_'.$img}) {
13840: $confhash->{$role}{$img} = '';
1.12 raeburn 13841: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13842: }
1.70 raeburn 13843: if ($role eq 'login') {
13844: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13845: $changes->{$role}{'showlogo'}{$img} = 1;
13846: }
1.402 raeburn 13847: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13848: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13849: $changes->{$role}{'alttext'}{$img} = 1;
13850: }
13851: }
1.70 raeburn 13852: }
1.6 raeburn 13853: }
13854: if ($confhash->{$role}{'font'}) {
13855: $changes->{$role}{'font'} = 1;
13856: }
1.48 raeburn 13857: }
1.6 raeburn 13858:
13859: sub display_colorchgs {
13860: my ($dom,$changes,$roles,$confhash) = @_;
13861: my (%choices,$resulttext);
13862: if (!grep(/^login$/,@{$roles})) {
13863: $resulttext = &mt('Changes made:').'<br />';
13864: }
13865: foreach my $role (@{$roles}) {
13866: if ($role eq 'login') {
13867: %choices = &login_choices();
13868: } else {
13869: %choices = &color_font_choices();
13870: }
13871: if (ref($changes->{$role}) eq 'HASH') {
13872: if ($role ne 'login') {
13873: $resulttext .= '<h4>'.&mt($role).'</h4>';
13874: }
13875: foreach my $key (sort(keys(%{$changes->{$role}}))) {
13876: if ($role ne 'login') {
13877: $resulttext .= '<ul>';
13878: }
13879: if (ref($changes->{$role}{$key}) eq 'HASH') {
13880: if ($role ne 'login') {
13881: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
13882: }
13883: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 13884: if (($role eq 'login') && ($key eq 'showlogo')) {
13885: if ($confhash->{$role}{$key}{$item}) {
13886: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
13887: } else {
13888: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
13889: }
1.402 raeburn 13890: } elsif (($role eq 'login') && ($key eq 'alttext')) {
13891: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 13892: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 13893: $confhash->{$role}{$key}{$item}).'</li>';
13894: } else {
13895: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
13896: }
1.70 raeburn 13897: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 13898: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
13899: } else {
1.12 raeburn 13900: my $newitem = $confhash->{$role}{$item};
13901: if ($key eq 'images') {
1.306 raeburn 13902: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 13903: }
13904: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 13905: }
13906: }
13907: if ($role ne 'login') {
13908: $resulttext .= '</ul></li>';
13909: }
13910: } else {
13911: if ($confhash->{$role}{$key} eq '') {
13912: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
13913: } else {
13914: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
13915: }
13916: }
13917: if ($role ne 'login') {
13918: $resulttext .= '</ul>';
13919: }
13920: }
13921: }
13922: }
1.3 raeburn 13923: return $resulttext;
1.1 raeburn 13924: }
13925:
1.9 raeburn 13926: sub thumb_dimensions {
13927: return ('200','50');
13928: }
13929:
1.16 raeburn 13930: sub check_dimensions {
13931: my ($inputfile) = @_;
13932: my ($fullwidth,$fullheight);
13933: if ($inputfile =~ m|^[/\w.\-]+$|) {
13934: if (open(PIPE,"identify $inputfile 2>&1 |")) {
13935: my $imageinfo = <PIPE>;
13936: if (!close(PIPE)) {
13937: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
13938: }
13939: chomp($imageinfo);
13940: my ($fullsize) =
1.21 raeburn 13941: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 13942: if ($fullsize) {
13943: ($fullwidth,$fullheight) = split(/x/,$fullsize);
13944: }
13945: }
13946: }
13947: return ($fullwidth,$fullheight);
13948: }
13949:
1.9 raeburn 13950: sub check_configuser {
13951: my ($uhome,$dom,$confname,$servadm) = @_;
13952: my ($configuserok,%currroles);
13953: if ($uhome eq 'no_host') {
13954: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 13955: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 13956: $configuserok =
13957: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
13958: $configpass,'','','','','',undef,$servadm);
13959: } else {
13960: $configuserok = 'ok';
13961: %currroles =
13962: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
13963: }
13964: return ($configuserok,%currroles);
13965: }
13966:
13967: sub check_authorstatus {
13968: my ($dom,$confname,%currroles) = @_;
13969: my $author_ok;
1.40 raeburn 13970: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 13971: my $start = time;
13972: my $end = 0;
13973: $author_ok =
13974: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 13975: 'au',$end,$start,'','','domconfig');
1.9 raeburn 13976: } else {
13977: $author_ok = 'ok';
13978: }
13979: return $author_ok;
13980: }
13981:
1.421 raeburn 13982: sub update_modify_urls {
13983: my ($r,$modified) = @_;
13984: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
13985: push(@{$modified_urls},$modified);
13986: unless ($registered_cleanup) {
13987: my $handlers = $r->get_handlers('PerlCleanupHandler');
13988: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
13989: $registered_cleanup=1;
1.9 raeburn 13990: }
13991: }
1.155 raeburn 13992: }
13993:
13994: sub notifysubscribed {
13995: foreach my $targetsource (@{$modified_urls}){
13996: next unless (ref($targetsource) eq 'ARRAY');
13997: my ($target,$source)=@{$targetsource};
13998: if ($source ne '') {
1.316 raeburn 13999: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 14000: print $logfh "\nCleanup phase: Notifications\n";
14001: my @subscribed=&subscribed_hosts($target);
14002: foreach my $subhost (@subscribed) {
14003: print $logfh "\nNotifying host ".$subhost.':';
14004: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
14005: print $logfh $reply;
14006: }
14007: my @subscribedmeta=&subscribed_hosts("$target.meta");
14008: foreach my $subhost (@subscribedmeta) {
14009: print $logfh "\nNotifying host for metadata only ".$subhost.':';
14010: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
14011: $subhost);
14012: print $logfh $reply;
14013: }
14014: print $logfh "\n============ Done ============\n";
1.160 raeburn 14015: close($logfh);
1.155 raeburn 14016: }
14017: }
14018: }
14019: return OK;
14020: }
14021:
14022: sub subscribed_hosts {
14023: my ($target) = @_;
14024: my @subscribed;
1.316 raeburn 14025: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 14026: while (my $subline=<$fh>) {
14027: if ($subline =~ /^($match_lonid):/) {
14028: my $host = $1;
14029: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
14030: unless (grep(/^\Q$host\E$/,@subscribed)) {
14031: push(@subscribed,$host);
14032: }
14033: }
14034: }
14035: }
14036: }
14037: return @subscribed;
1.9 raeburn 14038: }
14039:
14040: sub check_switchserver {
14041: my ($dom,$confname) = @_;
1.424 raeburn 14042: my ($allowed,$switchserver,$home);
14043: if ($confname eq '') {
1.9 raeburn 14044: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14045: } else {
14046: $home = &Apache::lonnet::homeserver($confname,$dom);
14047: if ($home eq 'no_host') {
14048: $home = &Apache::lonnet::domain($dom,'primary');
14049: }
1.9 raeburn 14050: }
14051: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14052: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14053: if (!$allowed) {
1.426 raeburn 14054: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14055: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14056: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14057: }
14058: return $switchserver;
14059: }
14060:
1.1 raeburn 14061: sub modify_quotas {
1.216 raeburn 14062: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14063: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14064: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14065: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14066: $validationfieldsref);
1.86 raeburn 14067: if ($action eq 'quotas') {
1.429 raeburn 14068: $context = 'tools';
1.163 raeburn 14069: } else {
1.86 raeburn 14070: $context = $action;
14071: }
14072: if ($context eq 'requestcourses') {
1.325 raeburn 14073: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14074: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14075: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14076: %titles = &courserequest_titles();
14077: $toolregexp = join('|',@usertools);
14078: %conditions = &courserequest_conditions();
1.216 raeburn 14079: $confname = $dom.'-domainconfig';
14080: my $servadm = $r->dir_config('lonAdmEMail');
14081: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14082: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14083: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14084: } elsif ($context eq 'requestauthor') {
14085: @usertools = ('author');
14086: %titles = &authorrequest_titles();
1.86 raeburn 14087: } else {
1.430 raeburn 14088: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14089: %titles = &tool_titles();
1.86 raeburn 14090: }
1.212 raeburn 14091: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14092: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14093: foreach my $key (keys(%env)) {
1.101 raeburn 14094: if ($context eq 'requestcourses') {
14095: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14096: my $item = $1;
14097: my $type = $2;
14098: if ($type =~ /^limit_(.+)/) {
14099: $limithash{$item}{$1} = $env{$key};
14100: } else {
14101: $confhash{$item}{$type} = $env{$key};
14102: }
14103: }
1.163 raeburn 14104: } elsif ($context eq 'requestauthor') {
14105: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14106: $confhash{$1} = $env{$key};
14107: }
1.101 raeburn 14108: } else {
1.86 raeburn 14109: if ($key =~ /^form\.quota_(.+)$/) {
14110: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14111: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14112: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14113: }
1.72 raeburn 14114: }
14115: }
1.163 raeburn 14116: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14117: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14118: @approvalnotify = sort(@approvalnotify);
14119: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14120: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14121: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14122: foreach my $type (@hasuniquecode) {
14123: if (grep(/^\Q$type\E$/,@crstypes)) {
14124: $confhash{'uniquecode'}{$type} = 1;
14125: }
1.216 raeburn 14126: }
1.242 raeburn 14127: my (%newbook,%allpos);
1.216 raeburn 14128: if ($context eq 'requestcourses') {
1.242 raeburn 14129: foreach my $type ('textbooks','templates') {
14130: @{$allpos{$type}} = ();
14131: my $invalid;
14132: if ($type eq 'textbooks') {
14133: $invalid = &mt('Invalid LON-CAPA course for textbook');
14134: } else {
14135: $invalid = &mt('Invalid LON-CAPA course for template');
14136: }
14137: if ($env{'form.'.$type.'_addbook'}) {
14138: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14139: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14140: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14141: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14142: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14143: } else {
14144: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14145: my $position = $env{'form.'.$type.'_addbook_pos'};
14146: $position =~ s/\D+//g;
14147: if ($position ne '') {
14148: $allpos{$type}[$position] = $newbook{$type};
14149: }
1.216 raeburn 14150: }
1.242 raeburn 14151: } else {
14152: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14153: }
14154: }
1.242 raeburn 14155: }
1.216 raeburn 14156: }
1.102 raeburn 14157: if (ref($domconfig{$action}) eq 'HASH') {
14158: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14159: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14160: $changes{'notify'}{'approval'} = 1;
14161: }
14162: } else {
1.144 raeburn 14163: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14164: $changes{'notify'}{'approval'} = 1;
14165: }
14166: }
1.218 raeburn 14167: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14168: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14169: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14170: unless ($confhash{'uniquecode'}{$crstype}) {
14171: $changes{'uniquecode'} = 1;
14172: }
14173: }
14174: unless ($changes{'uniquecode'}) {
14175: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14176: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14177: $changes{'uniquecode'} = 1;
14178: }
14179: }
14180: }
14181: } else {
14182: $changes{'uniquecode'} = 1;
14183: }
14184: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14185: $changes{'uniquecode'} = 1;
1.216 raeburn 14186: }
14187: if ($context eq 'requestcourses') {
1.242 raeburn 14188: foreach my $type ('textbooks','templates') {
14189: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14190: my %deletions;
14191: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14192: if (@todelete) {
14193: map { $deletions{$_} = 1; } @todelete;
14194: }
14195: my %imgdeletions;
14196: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14197: if (@todeleteimages) {
14198: map { $imgdeletions{$_} = 1; } @todeleteimages;
14199: }
14200: my $maxnum = $env{'form.'.$type.'_maxnum'};
14201: for (my $i=0; $i<=$maxnum; $i++) {
14202: my $itemid = $env{'form.'.$type.'_id_'.$i};
14203: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14204: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14205: if ($deletions{$key}) {
14206: if ($domconfig{$action}{$type}{$key}{'image'}) {
14207: #FIXME need to obsolete item in RES space
14208: }
14209: next;
14210: } else {
14211: my $newpos = $env{'form.'.$itemid};
14212: $newpos =~ s/\D+//g;
1.243 raeburn 14213: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14214: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14215: ($type eq 'templates'));
1.242 raeburn 14216: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14217: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14218: $changes{$type}{$key} = 1;
14219: }
14220: }
14221: $allpos{$type}[$newpos] = $key;
14222: }
14223: if ($imgdeletions{$key}) {
14224: $changes{$type}{$key} = 1;
1.216 raeburn 14225: #FIXME need to obsolete item in RES space
1.242 raeburn 14226: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14227: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14228: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14229: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14230: } else {
14231: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14232: $cdom,$cnum,$type,$configuserok,
14233: $switchserver,$author_ok);
14234: if ($imgurl) {
14235: $confhash{$type}{$key}{'image'} = $imgurl;
14236: $changes{$type}{$key} = 1;
14237: }
14238: if ($error) {
14239: &Apache::lonnet::logthis($error);
14240: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14241: }
14242: }
1.242 raeburn 14243: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14244: $confhash{$type}{$key}{'image'} =
14245: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14246: }
14247: }
14248: }
14249: }
14250: }
14251: }
1.102 raeburn 14252: } else {
1.144 raeburn 14253: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14254: $changes{'notify'}{'approval'} = 1;
14255: }
1.218 raeburn 14256: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14257: $changes{'uniquecode'} = 1;
14258: }
14259: }
14260: if ($context eq 'requestcourses') {
1.242 raeburn 14261: foreach my $type ('textbooks','templates') {
14262: if ($newbook{$type}) {
14263: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14264: foreach my $item ('subject','title','publisher','author') {
14265: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14266: ($type eq 'template'));
1.242 raeburn 14267: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14268: if ($env{'form.'.$type.'_addbook_'.$item}) {
14269: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14270: }
14271: }
14272: if ($type eq 'textbooks') {
14273: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14274: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14275: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14276: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14277: } else {
14278: my ($imageurl,$error) =
14279: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14280: $configuserok,$switchserver,$author_ok);
14281: if ($imageurl) {
14282: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14283: }
14284: if ($error) {
14285: &Apache::lonnet::logthis($error);
14286: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14287: }
1.242 raeburn 14288: }
14289: }
1.216 raeburn 14290: }
14291: }
1.242 raeburn 14292: if (@{$allpos{$type}} > 0) {
14293: my $idx = 0;
14294: foreach my $item (@{$allpos{$type}}) {
14295: if ($item ne '') {
14296: $confhash{$type}{$item}{'order'} = $idx;
14297: if (ref($domconfig{$action}) eq 'HASH') {
14298: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14299: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14300: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14301: $changes{$type}{$item} = 1;
14302: }
1.216 raeburn 14303: }
14304: }
14305: }
1.242 raeburn 14306: $idx ++;
1.216 raeburn 14307: }
14308: }
14309: }
14310: }
1.235 raeburn 14311: if (ref($validationitemsref) eq 'ARRAY') {
14312: foreach my $item (@{$validationitemsref}) {
14313: if ($item eq 'fields') {
14314: my @changed;
14315: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14316: if (@{$confhash{'validation'}{$item}} > 0) {
14317: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14318: }
1.266 raeburn 14319: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14320: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14321: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14322: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14323: $domconfig{'requestcourses'}{'validation'}{$item});
14324: } else {
14325: @changed = @{$confhash{'validation'}{$item}};
14326: }
1.235 raeburn 14327: } else {
14328: @changed = @{$confhash{'validation'}{$item}};
14329: }
14330: } else {
14331: @changed = @{$confhash{'validation'}{$item}};
14332: }
14333: if (@changed) {
14334: if ($confhash{'validation'}{$item}) {
14335: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14336: } else {
14337: $changes{'validation'}{$item} = &mt('None');
14338: }
14339: }
14340: } else {
14341: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14342: if ($item eq 'markup') {
14343: if ($env{'form.requestcourses_validation_'.$item}) {
14344: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14345: }
14346: }
1.266 raeburn 14347: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14348: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14349: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14350: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14351: }
14352: } else {
14353: if ($confhash{'validation'}{$item} ne '') {
14354: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14355: }
1.235 raeburn 14356: }
14357: } else {
14358: if ($confhash{'validation'}{$item} ne '') {
14359: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14360: }
14361: }
14362: }
14363: }
14364: }
14365: if ($env{'form.validationdc'}) {
14366: my $newval = $env{'form.validationdc'};
1.285 raeburn 14367: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14368: if (exists($domcoords{$newval})) {
14369: $confhash{'validation'}{'dc'} = $newval;
14370: }
14371: }
14372: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14373: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14374: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14375: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14376: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14377: if ($confhash{'validation'}{'dc'} eq '') {
14378: $changes{'validation'}{'dc'} = &mt('None');
14379: } else {
14380: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14381: }
1.235 raeburn 14382: }
1.266 raeburn 14383: } elsif ($confhash{'validation'}{'dc'} ne '') {
14384: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14385: }
14386: } elsif ($confhash{'validation'}{'dc'} ne '') {
14387: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14388: }
14389: } elsif ($confhash{'validation'}{'dc'} ne '') {
14390: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14391: }
1.266 raeburn 14392: } else {
14393: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14394: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14395: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14396: $changes{'validation'}{'dc'} = &mt('None');
14397: }
14398: }
1.235 raeburn 14399: }
14400: }
1.102 raeburn 14401: }
14402: } else {
1.86 raeburn 14403: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14404: }
1.72 raeburn 14405: foreach my $item (@usertools) {
14406: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14407: my $unset;
1.101 raeburn 14408: if ($context eq 'requestcourses') {
1.104 raeburn 14409: $unset = '0';
14410: if ($type eq '_LC_adv') {
14411: $unset = '';
14412: }
1.101 raeburn 14413: if ($confhash{$item}{$type} eq 'autolimit') {
14414: $confhash{$item}{$type} .= '=';
14415: unless ($limithash{$item}{$type} =~ /\D/) {
14416: $confhash{$item}{$type} .= $limithash{$item}{$type};
14417: }
14418: }
1.163 raeburn 14419: } elsif ($context eq 'requestauthor') {
14420: $unset = '0';
14421: if ($type eq '_LC_adv') {
14422: $unset = '';
14423: }
1.72 raeburn 14424: } else {
1.101 raeburn 14425: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14426: $confhash{$item}{$type} = 1;
14427: } else {
14428: $confhash{$item}{$type} = 0;
14429: }
1.72 raeburn 14430: }
1.86 raeburn 14431: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14432: if ($action eq 'requestauthor') {
14433: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14434: $changes{$type} = 1;
14435: }
14436: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14437: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14438: $changes{$item}{$type} = 1;
14439: }
14440: } else {
14441: if ($context eq 'requestcourses') {
1.104 raeburn 14442: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14443: $changes{$item}{$type} = 1;
14444: }
14445: } else {
14446: if (!$confhash{$item}{$type}) {
14447: $changes{$item}{$type} = 1;
14448: }
14449: }
14450: }
14451: } else {
14452: if ($context eq 'requestcourses') {
1.104 raeburn 14453: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14454: $changes{$item}{$type} = 1;
14455: }
1.163 raeburn 14456: } elsif ($context eq 'requestauthor') {
14457: if ($confhash{$type} ne $unset) {
14458: $changes{$type} = 1;
14459: }
1.72 raeburn 14460: } else {
14461: if (!$confhash{$item}{$type}) {
14462: $changes{$item}{$type} = 1;
14463: }
14464: }
14465: }
1.1 raeburn 14466: }
14467: }
1.163 raeburn 14468: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14469: if (ref($domconfig{'quotas'}) eq 'HASH') {
14470: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14471: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14472: if (exists($confhash{'defaultquota'}{$key})) {
14473: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14474: $changes{'defaultquota'}{$key} = 1;
14475: }
14476: } else {
14477: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14478: }
14479: }
1.86 raeburn 14480: } else {
14481: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14482: if (exists($confhash{'defaultquota'}{$key})) {
14483: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14484: $changes{'defaultquota'}{$key} = 1;
14485: }
14486: } else {
14487: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14488: }
1.1 raeburn 14489: }
14490: }
1.197 raeburn 14491: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14492: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14493: }
14494: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14495: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14496: }
1.1 raeburn 14497: }
1.86 raeburn 14498: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14499: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14500: if (ref($domconfig{'quotas'}) eq 'HASH') {
14501: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14502: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14503: $changes{'defaultquota'}{$key} = 1;
14504: }
14505: } else {
14506: if (!exists($domconfig{'quotas'}{$key})) {
14507: $changes{'defaultquota'}{$key} = 1;
14508: }
1.72 raeburn 14509: }
14510: } else {
1.86 raeburn 14511: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14512: }
1.1 raeburn 14513: }
14514: }
14515: }
1.72 raeburn 14516:
1.163 raeburn 14517: if ($context eq 'requestauthor') {
14518: $domdefaults{'requestauthor'} = \%confhash;
14519: } else {
14520: foreach my $key (keys(%confhash)) {
1.242 raeburn 14521: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14522: $domdefaults{$key} = $confhash{$key};
14523: }
1.163 raeburn 14524: }
1.72 raeburn 14525: }
1.163 raeburn 14526:
1.1 raeburn 14527: my %quotahash = (
1.86 raeburn 14528: $action => { %confhash }
1.1 raeburn 14529: );
14530: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14531: $dom);
14532: if ($putresult eq 'ok') {
14533: if (keys(%changes) > 0) {
1.72 raeburn 14534: my $cachetime = 24*60*60;
14535: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14536: if (ref($lastactref) eq 'HASH') {
14537: $lastactref->{'domdefaults'} = 1;
14538: }
1.1 raeburn 14539: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14540: unless (($context eq 'requestcourses') ||
1.163 raeburn 14541: ($context eq 'requestauthor')) {
1.86 raeburn 14542: if (ref($changes{'defaultquota'}) eq 'HASH') {
14543: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14544: foreach my $type (@{$types},'default') {
14545: if (defined($changes{'defaultquota'}{$type})) {
14546: my $typetitle = $usertypes->{$type};
14547: if ($type eq 'default') {
14548: $typetitle = $othertitle;
14549: }
1.213 raeburn 14550: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14551: }
14552: }
1.86 raeburn 14553: $resulttext .= '</ul></li>';
1.72 raeburn 14554: }
14555: }
1.80 raeburn 14556: my %newenv;
1.72 raeburn 14557: foreach my $item (@usertools) {
1.163 raeburn 14558: my (%haschgs,%inconf);
14559: if ($context eq 'requestauthor') {
14560: %haschgs = %changes;
1.210 raeburn 14561: %inconf = %confhash;
1.163 raeburn 14562: } else {
14563: if (ref($changes{$item}) eq 'HASH') {
14564: %haschgs = %{$changes{$item}};
14565: }
14566: if (ref($confhash{$item}) eq 'HASH') {
14567: %inconf = %{$confhash{$item}};
14568: }
14569: }
14570: if (keys(%haschgs) > 0) {
1.80 raeburn 14571: my $newacc =
14572: &Apache::lonnet::usertools_access($env{'user.name'},
14573: $env{'user.domain'},
1.86 raeburn 14574: $item,'reload',$context);
1.210 raeburn 14575: if (($context eq 'requestcourses') ||
1.163 raeburn 14576: ($context eq 'requestauthor')) {
1.108 raeburn 14577: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14578: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14579: }
14580: } else {
14581: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14582: $newenv{'environment.availabletools.'.$item} = $newacc;
14583: }
1.80 raeburn 14584: }
1.163 raeburn 14585: unless ($context eq 'requestauthor') {
14586: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14587: }
1.72 raeburn 14588: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14589: if ($haschgs{$type}) {
1.72 raeburn 14590: my $typetitle = $usertypes->{$type};
14591: if ($type eq 'default') {
14592: $typetitle = $othertitle;
14593: } elsif ($type eq '_LC_adv') {
14594: $typetitle = 'LON-CAPA Advanced Users';
14595: }
1.163 raeburn 14596: if ($inconf{$type}) {
1.101 raeburn 14597: if ($context eq 'requestcourses') {
14598: my $cond;
1.163 raeburn 14599: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14600: if ($1 eq '') {
14601: $cond = &mt('(Automatic processing of any request).');
14602: } else {
14603: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14604: }
14605: } else {
1.163 raeburn 14606: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14607: }
14608: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14609: } elsif ($context eq 'requestauthor') {
14610: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14611: $titles{$inconf{$type}},$typetitle);
14612:
1.101 raeburn 14613: } else {
14614: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14615: }
1.72 raeburn 14616: } else {
1.104 raeburn 14617: if ($type eq '_LC_adv') {
1.163 raeburn 14618: if ($inconf{$type} eq '0') {
1.104 raeburn 14619: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14620: } else {
14621: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14622: }
14623: } else {
14624: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14625: }
1.72 raeburn 14626: }
14627: }
1.26 raeburn 14628: }
1.163 raeburn 14629: unless ($context eq 'requestauthor') {
14630: $resulttext .= '</ul></li>';
14631: }
1.26 raeburn 14632: }
1.1 raeburn 14633: }
1.163 raeburn 14634: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14635: if (ref($changes{'notify'}) eq 'HASH') {
14636: if ($changes{'notify'}{'approval'}) {
14637: if (ref($confhash{'notify'}) eq 'HASH') {
14638: if ($confhash{'notify'}{'approval'}) {
14639: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14640: } else {
1.163 raeburn 14641: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14642: }
14643: }
14644: }
14645: }
14646: }
1.216 raeburn 14647: if ($action eq 'requestcourses') {
14648: my @offon = ('off','on');
14649: if ($changes{'uniquecode'}) {
1.218 raeburn 14650: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14651: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14652: $resulttext .= '<li>'.
14653: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14654: '</li>';
14655: } else {
14656: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14657: '</li>';
14658: }
1.216 raeburn 14659: }
1.242 raeburn 14660: foreach my $type ('textbooks','templates') {
14661: if (ref($changes{$type}) eq 'HASH') {
14662: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14663: foreach my $key (sort(keys(%{$changes{$type}}))) {
14664: my %coursehash = &Apache::lonnet::coursedescription($key);
14665: my $coursetitle = $coursehash{'description'};
14666: my $position = $confhash{$type}{$key}{'order'} + 1;
14667: $resulttext .= '<li>';
1.243 raeburn 14668: foreach my $item ('subject','title','publisher','author') {
14669: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14670: ($type eq 'templates'));
1.242 raeburn 14671: my $name = $item.':';
14672: $name =~ s/^(\w)/\U$1/;
14673: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14674: }
14675: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14676: if ($type eq 'textbooks') {
14677: if ($confhash{$type}{$key}{'image'}) {
14678: $resulttext .= ' '.&mt('Image: [_1]',
14679: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14680: ' alt="Textbook cover" />').'<br />';
14681: }
14682: }
14683: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14684: }
1.242 raeburn 14685: $resulttext .= '</ul></li>';
1.216 raeburn 14686: }
14687: }
1.235 raeburn 14688: if (ref($changes{'validation'}) eq 'HASH') {
14689: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14690: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14691: foreach my $item (@{$validationitemsref}) {
14692: if (exists($changes{'validation'}{$item})) {
14693: if ($item eq 'markup') {
14694: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14695: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14696: } else {
14697: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14698: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14699: }
14700: }
14701: }
14702: if (exists($changes{'validation'}{'dc'})) {
14703: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14704: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14705: }
14706: }
14707: }
1.216 raeburn 14708: }
1.1 raeburn 14709: $resulttext .= '</ul>';
1.80 raeburn 14710: if (keys(%newenv)) {
14711: &Apache::lonnet::appenv(\%newenv);
14712: }
1.1 raeburn 14713: } else {
1.86 raeburn 14714: if ($context eq 'requestcourses') {
14715: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14716: } elsif ($context eq 'requestauthor') {
14717: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14718: } else {
1.90 weissno 14719: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14720: }
1.1 raeburn 14721: }
14722: } else {
1.11 albertel 14723: $resulttext = '<span class="LC_error">'.
14724: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14725: }
1.216 raeburn 14726: if ($errors) {
14727: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14728: '<ul>'.$errors.'</ul></p>';
14729: }
1.3 raeburn 14730: return $resulttext;
1.1 raeburn 14731: }
14732:
1.216 raeburn 14733: sub process_textbook_image {
1.242 raeburn 14734: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14735: my $filename = $env{'form.'.$caller.'.filename'};
14736: my ($error,$url);
14737: my ($width,$height) = (50,50);
14738: if ($configuserok eq 'ok') {
14739: if ($switchserver) {
14740: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14741: $switchserver);
14742: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14743: my $modified = [];
1.216 raeburn 14744: my ($result,$imageurl) =
1.421 raeburn 14745: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14746: "$type/$cdom/$cnum/cover",$width,$height,
14747: '',$modified);
1.216 raeburn 14748: if ($result eq 'ok') {
14749: $url = $imageurl;
1.421 raeburn 14750: &update_modify_urls($r,$modified);
1.216 raeburn 14751: } else {
14752: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14753: }
14754: } else {
14755: $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);
14756: }
14757: } else {
14758: $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);
14759: }
14760: return ($url,$error);
14761: }
14762:
1.267 raeburn 14763: sub modify_ltitools {
14764: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14765: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14766: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14767:
1.267 raeburn 14768: my $confname = $dom.'-domainconfig';
14769: my $servadm = $r->dir_config('lonAdmEMail');
14770: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14771:
14772: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14773: my $toolserror =
14774: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14775: $lastactref,$configuserok,$switchserver,$author_ok);
14776:
14777: my $home = &Apache::lonnet::domain($dom,'primary');
14778: unless (($home eq 'no_host') || ($home eq '')) {
14779: my @ids=&Apache::lonnet::current_machine_ids();
14780: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14781: }
14782:
14783: if (keys(%ltitoolschg)) {
14784: foreach my $id (keys(%ltitoolschg)) {
14785: if (ref($ltitoolschg{$id}) eq 'HASH') {
14786: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14787: if (($inner eq 'secret') || ($inner eq 'key')) {
14788: if ($is_home) {
14789: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14790: }
14791: }
14792: }
1.267 raeburn 14793: }
1.421 raeburn 14794: }
14795: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14796: if (keys(%ltitoolschg)) {
14797: %newltitools = %ltitoolschg;
14798: }
14799: }
14800: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14801: foreach my $id (%{$domconfig{'ltitools'}}) {
14802: next if ($id !~ /^\d+$/);
14803: unless (exists($ltitoolschg{$id})) {
14804: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14805: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14806: if (($inner eq 'secret') || ($inner eq 'key')) {
14807: if ($is_home) {
14808: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14809: }
14810: } else {
14811: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14812: }
14813: }
14814: } else {
14815: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14816: }
1.421 raeburn 14817: }
14818: }
14819: }
14820: if ($toolserror) {
14821: $errors = '<li>'.$toolserror.'</li>';
14822: }
14823: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14824: $resulttext = &mt('No changes made.');
14825: if ($errors) {
14826: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14827: $errors.'</ul>';
14828: }
14829: return $resulttext;
14830: }
14831: my %ltitoolshash = (
14832: $action => { %newltitools }
14833: );
14834: if (keys(%secchanges)) {
14835: $ltitoolshash{'toolsec'} = \%newtoolsec;
14836: }
14837: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14838: if ($putresult eq 'ok') {
14839: my %keystore;
14840: if ($is_home) {
14841: my %toolsenchash = (
14842: $action => { %newtoolsenc }
14843: );
14844: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 14845: my $cachetime = 24*60*60;
14846: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 14847: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
14848: }
14849: $resulttext = &mt('Changes made:').'<ul>';
14850: if (keys(%secchanges) > 0) {
1.423 raeburn 14851: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 14852: }
14853: if (keys(%ltitoolschg) > 0) {
14854: $resulttext .= $ltitoolsoutput;
14855: }
1.423 raeburn 14856: my $cachetime = 24*60*60;
14857: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
14858: if (ref($lastactref) eq 'HASH') {
14859: $lastactref->{'ltitools'} = 1;
14860: }
1.421 raeburn 14861: } else {
14862: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14863: }
14864: if ($errors) {
14865: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14866: $errors.'</ul></p>';
14867: }
14868: return $resulttext;
14869: }
14870:
14871: sub fetch_secrets {
14872: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
14873: my %keyset;
14874: %{$currsec} = ();
14875: $newsec->{'private'}{'keys'} = [];
14876: $newsec->{'encrypt'} = {};
14877: $newsec->{'rules'} = {};
14878: if ($context eq 'ltisec') {
14879: $newsec->{'linkprot'} = {};
14880: }
14881: if (ref($domconfig->{$context}) eq 'HASH') {
14882: %{$currsec} = %{$domconfig->{$context}};
14883: if ($context eq 'ltisec') {
14884: if (ref($currsec->{'linkprot'}) eq 'HASH') {
14885: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
14886: unless ($id =~ /^\d+$/) {
14887: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 14888: }
1.267 raeburn 14889: }
14890: }
1.421 raeburn 14891: }
14892: if (ref($currsec->{'private'}) eq 'HASH') {
14893: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
14894: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
14895: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 14896: }
1.421 raeburn 14897: }
14898: }
14899: my @items= ('crs','dom');
14900: if ($context eq 'ltisec') {
14901: push(@items,'consumers');
14902: }
14903: foreach my $item (@items) {
14904: my $formelement;
14905: if (($context eq 'toolsec') || ($item eq 'consumers')) {
14906: $formelement = 'form.'.$context.'_'.$item;
14907: } else {
14908: $formelement = 'form.'.$context.'_'.$item.'linkprot';
14909: }
14910: if ($env{$formelement}) {
14911: $newsec->{'encrypt'}{$item} = 1;
14912: if (ref($currsec->{'encrypt'}) eq 'HASH') {
14913: unless ($currsec->{'encrypt'}{$item}) {
14914: $secchanges->{'encrypt'} = 1;
14915: }
14916: } else {
14917: $secchanges->{'encrypt'} = 1;
1.267 raeburn 14918: }
1.421 raeburn 14919: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
14920: if ($currsec->{'encrypt'}{$item}) {
14921: $secchanges->{'encrypt'} = 1;
1.323 raeburn 14922: }
1.421 raeburn 14923: }
14924: }
14925: my $secrets;
14926: if ($context eq 'ltisec') {
14927: $secrets = 'ltisecrets';
14928: } else {
14929: $secrets = 'toolsecrets';
14930: }
14931: unless (exists($currsec->{'rules'})) {
14932: $currsec->{'rules'} = {};
14933: }
14934: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
14935:
14936: my @ids=&Apache::lonnet::current_machine_ids();
14937: my %servers = &Apache::lonnet::get_servers($dom,'library');
14938:
14939: foreach my $hostid (keys(%servers)) {
14940: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
14941: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
14942: if (exists($env{$keyitem})) {
14943: $env{$keyitem} =~ s/(`)/'/g;
14944: if ($keyset{$hostid}) {
14945: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
14946: if ($env{$keyitem} ne '') {
14947: $secchanges->{'private'} = 1;
14948: $newkeyset->{$hostid} = $env{$keyitem};
14949: }
1.296 raeburn 14950: }
1.421 raeburn 14951: } elsif ($env{$keyitem} ne '') {
14952: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
14953: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 14954: }
1.421 raeburn 14955: $secchanges->{'private'} = 1;
14956: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 14957: }
14958: }
1.421 raeburn 14959: }
14960: }
14961: }
14962:
14963: sub store_security {
1.424 raeburn 14964: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 14965: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
14966: (ref($keystore) eq 'HASH'));
14967: if (keys(%{$secchanges})) {
14968: if ($secchanges->{'private'}) {
14969: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
14970: foreach my $hostid (keys(%{$newkeyset})) {
14971: my $storehash = {
14972: key => $newkeyset->{$hostid},
14973: who => $env{'user.name'}.':'.$env{'user.domain'},
14974: };
14975: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
14976: $dom,$hostid);
14977: }
14978: }
14979: }
14980: }
14981:
14982: sub lti_security_results {
1.423 raeburn 14983: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 14984: my $output;
1.423 raeburn 14985: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14986: my $needs_update;
1.421 raeburn 14987: foreach my $item (keys(%{$secchanges})) {
14988: if ($item eq 'encrypt') {
1.423 raeburn 14989: $needs_update = 1;
1.421 raeburn 14990: my %encrypted;
14991: if ($context eq 'lti') {
14992: %encrypted = (
14993: crs => {
14994: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
14995: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
14996: },
14997: dom => {
14998: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
14999: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
15000: },
15001: consumers => {
15002: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
15003: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
15004: },
15005: );
1.267 raeburn 15006: } else {
1.421 raeburn 15007: %encrypted = (
15008: crs => {
15009: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
15010: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
15011: },
15012: dom => {
15013: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
15014: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
15015: },
15016: );
15017:
15018: }
15019: my @types= ('crs','dom');
15020: if ($context eq 'lti') {
1.423 raeburn 15021: foreach my $type (@types) {
15022: undef($domdefaults{'linkprotenc_'.$type});
15023: }
1.421 raeburn 15024: push(@types,'consumers');
1.423 raeburn 15025: undef($domdefaults{'ltienc_consumers'});
15026: } elsif ($context eq 'ltitools') {
15027: foreach my $type (@types) {
15028: undef($domdefaults{'toolenc_'.$type});
15029: }
1.267 raeburn 15030: }
1.421 raeburn 15031: foreach my $type (@types) {
15032: my $shown = $encrypted{$type}{'off'};
15033: if (ref($newsec->{$item}) eq 'HASH') {
15034: if ($newsec->{$item}{$type}) {
1.423 raeburn 15035: if ($context eq 'lti') {
15036: if ($type eq 'consumers') {
15037: $domdefaults{'ltienc_consumers'} = 1;
15038: } else {
15039: $domdefaults{'linkprotenc_'.$type} = 1;
15040: }
15041: } elsif ($context eq 'ltitools') {
15042: $domdefaults{'toolenc_'.$type} = 1;
15043: }
1.421 raeburn 15044: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15045: }
1.267 raeburn 15046: }
1.421 raeburn 15047: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15048: }
1.421 raeburn 15049: } elsif ($item eq 'rules') {
15050: my %titles = &Apache::lonlocal::texthash(
15051: min => 'Minimum password length',
15052: max => 'Maximum password length',
15053: chars => 'Required characters',
15054: );
15055: foreach my $rule ('min','max') {
15056: if ($newsec->{rules}{$rule} eq '') {
15057: if ($rule eq 'min') {
15058: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15059: ' '.&mt('Default of [_1] will be used',
15060: $Apache::lonnet::passwdmin).'</li>';
15061: } else {
15062: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15063: }
15064: } else {
15065: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15066: }
15067: }
15068: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15069: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15070: my %rulenames = &Apache::lonlocal::texthash(
15071: uc => 'At least one upper case letter',
15072: lc => 'At least one lower case letter',
15073: num => 'At least one number',
15074: spec => 'At least one non-alphanumeric',
15075: );
15076: my $needed = '<ul><li>'.
15077: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15078: '</li></ul>';
15079: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15080: } else {
15081: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15082: }
1.421 raeburn 15083: } else {
15084: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15085: }
1.421 raeburn 15086: } elsif ($item eq 'private') {
1.423 raeburn 15087: $needs_update = 1;
15088: if ($context eq 'lti') {
15089: undef($domdefaults{'ltiprivhosts'});
15090: } elsif ($context eq 'ltitools') {
15091: undef($domdefaults{'toolprivhosts'});
15092: }
1.421 raeburn 15093: if (keys(%{$newkeyset})) {
1.423 raeburn 15094: my @privhosts;
1.421 raeburn 15095: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15096: if ($keystore->{$hostid} eq 'ok') {
15097: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15098: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15099: push(@privhosts,$hostid);
15100: }
15101: }
15102: }
15103: if (@privhosts) {
15104: if ($context eq 'lti') {
15105: $domdefaults{'ltiprivhosts'} = \@privhosts;
15106: } elsif ($context eq 'ltitools') {
15107: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15108: }
15109: }
15110: }
1.421 raeburn 15111: } elsif ($item eq 'linkprot') {
15112: next;
1.267 raeburn 15113: }
15114: }
1.423 raeburn 15115: if ($needs_update) {
15116: my $cachetime = 24*60*60;
15117: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15118: }
1.421 raeburn 15119: return $output;
15120: }
15121:
15122: sub modify_proctoring {
15123: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15124: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15125: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15126: my $confname = $dom.'-domainconfig';
15127: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15128: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15129: my %providernames = &proctoring_providernames();
15130: my $maxnum = scalar(keys(%providernames));
15131:
15132: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15133: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15134: if (ref($requref) eq 'HASH') {
15135: %requserfields = %{$requref};
15136: }
15137: if (ref($opturef) eq 'HASH') {
15138: %optuserfields = %{$opturef};
15139: }
15140: if (ref($defref) eq 'HASH') {
15141: %defaults = %{$defref};
15142: }
15143: if (ref($extref) eq 'HASH') {
15144: %extended = %{$extref};
15145: }
15146: if (ref($crsref) eq 'HASH') {
15147: %crsconf = %{$crsref};
15148: }
15149: if (ref($rolesref) eq 'ARRAY') {
15150: @courseroles = @{$rolesref};
15151: }
15152: if (ref($ltiref) eq 'ARRAY') {
15153: @ltiroles = @{$ltiref};
15154: }
15155:
15156: if (ref($domconfig{$action}) eq 'HASH') {
15157: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15158: if (@todeleteimages) {
15159: map { $imgdeletions{$_} = 1; } @todeleteimages;
15160: }
15161: }
15162: my %customadds;
15163: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15164: if (@newcustom) {
15165: map { $customadds{$_} = 1; } @newcustom;
15166: }
15167: foreach my $provider (sort(keys(%providernames))) {
15168: $confhash{$provider} = {};
15169: my $pos = $env{'form.proctoring_pos_'.$provider};
15170: $pos =~ s/\D+//g;
15171: $allpos[$pos] = $provider;
15172: my (%current,%currentenc);
15173: my $showroles = 0;
15174: if (ref($domconfig{$action}) eq 'HASH') {
15175: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15176: %current = %{$domconfig{$action}{$provider}};
15177: foreach my $item ('key','secret') {
15178: $currentenc{$item} = $current{$item};
15179: delete($current{$item});
15180: }
15181: }
15182: }
15183: if ($env{'form.proctoring_available_'.$provider}) {
15184: $confhash{$provider}{'available'} = 1;
15185: unless ($current{'available'}) {
15186: $changes{$provider} = 1;
15187: }
15188: } else {
15189: %{$confhash{$provider}} = %current;
15190: %{$encconfhash{$provider}} = %currentenc;
15191: $confhash{$provider}{'available'} = 0;
15192: if ($current{'available'}) {
15193: $changes{$provider} = 1;
15194: }
15195: }
15196: if ($confhash{$provider}{'available'}) {
15197: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15198: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15199: if ($field eq 'lifetime') {
15200: if ($possval =~ /^\d+$/) {
15201: $confhash{$provider}{$field} = $possval;
15202: }
15203: } elsif ($field eq 'version') {
15204: if ($possval =~ /^\d+\.\d+$/) {
15205: $confhash{$provider}{$field} = $possval;
15206: }
15207: } elsif ($field eq 'sigmethod') {
15208: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15209: $confhash{$provider}{$field} = $possval;
15210: }
15211: } elsif ($field eq 'url') {
15212: $confhash{$provider}{$field} = $possval;
15213: } elsif (($field eq 'key') || ($field eq 'secret')) {
15214: $encconfhash{$provider}{$field} = $possval;
15215: unless ($currentenc{$field} eq $possval) {
15216: $changes{$provider} = 1;
15217: }
15218: }
15219: unless (($field eq 'key') || ($field eq 'secret')) {
15220: unless ($current{$field} eq $confhash{$provider}{$field}) {
15221: $changes{$provider} = 1;
15222: }
15223: }
15224: }
15225: if ($imgdeletions{$provider}) {
15226: $changes{$provider} = 1;
15227: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15228: my ($imageurl,$error) =
15229: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15230: $configuserok,$switchserver,$author_ok);
15231: if ($imageurl) {
15232: $confhash{$provider}{'image'} = $imageurl;
15233: $changes{$provider} = 1;
15234: }
15235: if ($error) {
15236: &Apache::lonnet::logthis($error);
15237: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15238: }
15239: } elsif (exists($current{'image'})) {
15240: $confhash{$provider}{'image'} = $current{'image'};
15241: }
15242: if (ref($requserfields{$provider}) eq 'ARRAY') {
15243: if (@{$requserfields{$provider}} > 0) {
15244: if (grep(/^user$/,@{$requserfields{$provider}})) {
15245: if ($env{'form.proctoring_userincdom_'.$provider}) {
15246: $confhash{$provider}{'incdom'} = 1;
15247: }
15248: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15249: $changes{$provider} = 1;
15250: }
15251: }
15252: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15253: $showroles = 1;
15254: }
15255: }
15256: }
15257: $confhash{$provider}{'fields'} = [];
15258: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15259: if (@{$optuserfields{$provider}} > 0) {
15260: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15261: foreach my $field (@{$optuserfields{$provider}}) {
15262: if (grep(/^\Q$field\E$/,@optfields)) {
15263: push(@{$confhash{$provider}{'fields'}},$field);
15264: }
15265: }
15266: }
15267: if (ref($current{'fields'}) eq 'ARRAY') {
15268: unless ($changes{$provider}) {
15269: my @new = sort(@{$confhash{$provider}{'fields'}});
15270: my @old = sort(@{$current{'fields'}});
15271: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15272: if (@diffs) {
15273: $changes{$provider} = 1;
15274: }
15275: }
15276: } elsif (@{$confhash{$provider}{'fields'}}) {
15277: $changes{$provider} = 1;
15278: }
15279: }
15280: if (ref($defaults{$provider}) eq 'ARRAY') {
15281: if (@{$defaults{$provider}} > 0) {
15282: my %options;
15283: if (ref($extended{$provider}) eq 'HASH') {
15284: %options = %{$extended{$provider}};
15285: }
15286: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15287: foreach my $field (@{$defaults{$provider}}) {
15288: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15289: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15290: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15291: push(@{$confhash{$provider}{'defaults'}},$poss);
15292: }
15293: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15294: foreach my $inner (keys(%{$options{$field}})) {
15295: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15296: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15297: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15298: $confhash{$provider}{'defaults'}{$inner} = $poss;
15299: }
15300: } else {
15301: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15302: }
15303: }
15304: } else {
15305: if (grep(/^\Q$field\E$/,@checked)) {
15306: push(@{$confhash{$provider}{'defaults'}},$field);
15307: }
15308: }
15309: }
15310: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15311: if (ref($current{'defaults'}) eq 'ARRAY') {
15312: unless ($changes{$provider}) {
15313: my @new = sort(@{$confhash{$provider}{'defaults'}});
15314: my @old = sort(@{$current{'defaults'}});
15315: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15316: if (@diffs) {
15317: $changes{$provider} = 1;
15318: }
15319: }
15320: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15321: if (@{$current{'defaults'}}) {
15322: $changes{$provider} = 1;
15323: }
15324: }
15325: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15326: if (ref($current{'defaults'}) eq 'HASH') {
15327: unless ($changes{$provider}) {
15328: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15329: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15330: $changes{$provider} = 1;
15331: last;
15332: }
15333: }
15334: }
15335: unless ($changes{$provider}) {
15336: foreach my $key (keys(%{$current{'defaults'}})) {
15337: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15338: $changes{$provider} = 1;
15339: last;
15340: }
15341: }
15342: }
15343: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15344: $changes{$provider} = 1;
15345: }
15346: }
15347: }
15348: }
15349: if (ref($crsconf{$provider}) eq 'ARRAY') {
15350: if (@{$crsconf{$provider}} > 0) {
15351: $confhash{$provider}{'crsconf'} = [];
15352: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15353: foreach my $crsfield (@{$crsconf{$provider}}) {
15354: if (grep(/^\Q$crsfield\E$/,@checked)) {
15355: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15356: }
15357: }
15358: if (ref($current{'crsconf'}) eq 'ARRAY') {
15359: unless ($changes{$provider}) {
15360: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15361: my @old = sort(@{$current{'crsconf'}});
15362: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15363: if (@diffs) {
15364: $changes{$provider} = 1;
15365: }
15366: }
15367: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15368: $changes{$provider} = 1;
15369: }
15370: }
15371: }
15372: if ($showroles) {
15373: $confhash{$provider}{'roles'} = {};
15374: foreach my $role (@courseroles) {
15375: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15376: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15377: $confhash{$provider}{'roles'}{$role} = $poss;
15378: }
15379: }
15380: unless ($changes{$provider}) {
15381: if (ref($current{'roles'}) eq 'HASH') {
15382: foreach my $role (keys(%{$current{'roles'}})) {
15383: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15384: $changes{$provider} = 1;
15385: last
15386: }
15387: }
15388: unless ($changes{$provider}) {
15389: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15390: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15391: $changes{$provider} = 1;
15392: last;
15393: }
15394: }
15395: }
15396: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15397: $changes{$provider} = 1;
15398: }
15399: }
15400: }
15401: if (ref($current{'custom'}) eq 'HASH') {
15402: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15403: foreach my $key (keys(%{$current{'custom'}})) {
15404: if (grep(/^\Q$key\E$/,@customdels)) {
15405: $changes{$provider} = 1;
15406: } else {
15407: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15408: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15409: $changes{$provider} = 1;
15410: }
15411: }
15412: }
15413: }
15414: if ($customadds{$provider}) {
15415: my $name = $env{'form.proctoring_custom_name_'.$provider};
15416: $name =~ s/(`)/'/g;
15417: $name =~ s/^\s+//;
15418: $name =~ s/\s+$//;
15419: my $value = $env{'form.proctoring_custom_value_'.$provider};
15420: $value =~ s/(`)/'/g;
15421: $value =~ s/^\s+//;
15422: $value =~ s/\s+$//;
15423: if ($name ne '') {
15424: $confhash{$provider}{'custom'}{$name} = $value;
15425: $changes{$provider} = 1;
15426: }
15427: }
15428: }
15429: }
15430: if (@allpos > 0) {
15431: my $idx = 0;
15432: foreach my $provider (@allpos) {
15433: if ($provider ne '') {
15434: $confhash{$provider}{'order'} = $idx;
15435: unless ($changes{$provider}) {
15436: if (ref($domconfig{$action}) eq 'HASH') {
15437: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15438: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15439: $changes{$provider} = 1;
15440: }
15441: }
15442: }
15443: }
15444: $idx ++;
15445: }
15446: }
15447: }
15448: my %proc_hash = (
15449: $action => { %confhash }
15450: );
15451: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15452: $dom);
15453: if ($putresult eq 'ok') {
15454: my %proc_enchash = (
15455: $action => { %encconfhash }
15456: );
1.384 raeburn 15457: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15458: if (keys(%changes) > 0) {
15459: my $cachetime = 24*60*60;
15460: my %procall = %confhash;
15461: foreach my $provider (keys(%procall)) {
15462: if (ref($encconfhash{$provider}) eq 'HASH') {
15463: foreach my $key ('key','secret') {
15464: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15465: }
15466: }
15467: }
15468: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15469: if (ref($lastactref) eq 'HASH') {
15470: $lastactref->{'proctoring'} = 1;
15471: }
15472: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15473: my %bynum;
15474: foreach my $provider (sort(keys(%changes))) {
15475: my $position = $confhash{$provider}{'order'};
15476: $bynum{$position} = $provider;
15477: }
15478: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15479: my $provider = $bynum{$pos};
15480: my %lt = &proctoring_titles($provider);
15481: my %fieldtitles = &proctoring_fieldtitles($provider);
15482: if (!$confhash{$provider}{'available'}) {
15483: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15484: } else {
15485: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15486: if ($confhash{$provider}{'image'}) {
15487: $resulttext .= ' '.
15488: '<img src="'.$confhash{$provider}{'image'}.'"'.
15489: ' alt="'.&mt('Proctoring icon').'" />';
15490: }
15491: $resulttext .= '<ul>';
15492: my $position = $pos + 1;
15493: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15494: foreach my $key ('version','sigmethod','url','lifetime') {
15495: if ($confhash{$provider}{$key} ne '') {
15496: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15497: }
15498: }
15499: if ($encconfhash{$provider}{'key'} ne '') {
15500: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15501: }
15502: if ($encconfhash{$provider}{'secret'} ne '') {
15503: $resulttext .= '<li>'.$lt{'secret'}.': ';
15504: my $num = length($encconfhash{$provider}{'secret'});
15505: $resulttext .= ('*'x$num).'</li>';
15506: }
15507: my (@fields,$showroles);
15508: if (ref($requserfields{$provider}) eq 'ARRAY') {
15509: push(@fields,@{$requserfields{$provider}});
15510: }
15511: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15512: push(@fields,@{$confhash{$provider}{'fields'}});
15513: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15514: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15515: }
15516: if (@fields) {
15517: if (grep(/^roles$/,@fields)) {
15518: $showroles = 1;
15519: }
15520: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15521: join('", "', map { $lt{$_}; } @fields).'"</li>';
15522: }
15523: if (ref($requserfields{$provider}) eq 'ARRAY') {
15524: if (grep(/^user$/,@{$requserfields{$provider}})) {
15525: if ($confhash{$provider}{'incdom'}) {
15526: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15527: } else {
15528: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15529: }
15530: }
15531: }
15532: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15533: if (@{$confhash{$provider}{'defaults'}} > 0) {
15534: $resulttext .= '<li>'.$lt{'defa'};
15535: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15536: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15537: }
15538: $resulttext =~ s/,$//;
15539: $resulttext .= '</li>';
15540: }
15541: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15542: if (keys(%{$confhash{$provider}{'defaults'}})) {
15543: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15544: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15545: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15546: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15547: }
15548: }
15549: $resulttext .= '</ul></li>';
15550: }
15551: }
15552: if (ref($crsconf{$provider}) eq 'ARRAY') {
15553: if (@{$crsconf{$provider}} > 0) {
15554: $resulttext .= '<li>'.&mt('Configurable in course:');
15555: my $numconfig = 0;
15556: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15557: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15558: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15559: $numconfig ++;
15560: if ($provider eq 'examity') {
15561: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15562: } else {
15563: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15564: }
15565: }
15566: $resulttext =~ s/,$//;
15567: }
15568: }
15569: if (!$numconfig) {
15570: $resulttext .= ' '.&mt('None');
15571: }
15572: $resulttext .= '</li>';
15573: }
15574: }
15575: if ($showroles) {
15576: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15577: my $rolemaps;
15578: foreach my $role (@courseroles) {
15579: if ($confhash{$provider}{'roles'}{$role}) {
15580: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15581: $confhash{$provider}{'roles'}{$role}.',';
15582: }
15583: }
15584: if ($rolemaps) {
15585: $rolemaps =~ s/,$//;
15586: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15587: }
15588: }
15589: }
15590: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15591: my $customlist;
15592: if (keys(%{$confhash{$provider}{'custom'}})) {
15593: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15594: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15595: }
15596: $customlist =~ s/,$//;
15597: }
15598: if ($customlist) {
15599: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15600: }
15601: }
15602: $resulttext .= '</ul></li>';
15603: }
15604: }
15605: $resulttext .= '</ul>';
15606: } else {
15607: $resulttext = &mt('No changes made.');
15608: }
15609: } else {
15610: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15611: }
15612: if ($errors) {
15613: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15614: $errors.'</ul>';
15615: }
15616: return $resulttext;
15617: }
15618:
15619: sub process_proctoring_image {
15620: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15621: my $filename = $env{'form.'.$caller.'.filename'};
15622: my ($error,$url);
15623: my ($width,$height) = (21,21);
15624: if ($configuserok eq 'ok') {
15625: if ($switchserver) {
15626: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15627: $switchserver);
15628: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15629: my $modified = [];
1.372 raeburn 15630: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15631: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15632: "proctoring/$provider/icon",$width,$height,
15633: '',$modified);
1.372 raeburn 15634: if ($result eq 'ok') {
15635: if ($madethumb) {
15636: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15637: my $imagethumb = "$path/tn-".$imagefile;
15638: $url = $imagethumb;
15639: } else {
15640: $url = $imageurl;
15641: }
1.421 raeburn 15642: &update_modify_urls($r,$modified);
1.372 raeburn 15643: } else {
15644: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15645: }
15646: } else {
15647: $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);
15648: }
15649: } else {
15650: $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);
15651: }
15652: return ($url,$error);
15653: }
15654:
1.320 raeburn 15655: sub modify_lti {
15656: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15657: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15658: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15659: my (%posslti,%posslticrs,%posscrstype);
15660: my @courseroles = ('cc','in','ta','ep','st');
15661: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15662: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15663: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15664: my %coursetypetitles = &Apache::lonlocal::texthash (
15665: official => 'Official',
15666: unofficial => 'Unofficial',
15667: community => 'Community',
15668: textbook => 'Textbook',
15669: placement => 'Placement Test',
1.392 raeburn 15670: lti => 'LTI Provider',
1.320 raeburn 15671: );
1.325 raeburn 15672: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15673: my %lt = <i_names();
15674: map { $posslti{$_} = 1; } @ltiroles;
15675: map { $posslticrs{$_} = 1; } @lticourseroles;
15676: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15677:
1.326 raeburn 15678: my %menutitles = <imenu_titles();
1.421 raeburn 15679: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15680:
1.421 raeburn 15681: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15682:
1.406 raeburn 15683: my (%linkprotchg,$linkprotoutput,$is_home);
15684: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15685: \%linkprotchg,'domain');
15686: my $home = &Apache::lonnet::domain($dom,'primary');
15687: unless (($home eq 'no_host') || ($home eq '')) {
15688: my @ids=&Apache::lonnet::current_machine_ids();
15689: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15690: }
15691:
15692: if (keys(%linkprotchg)) {
15693: $secchanges{'linkprot'} = 1;
15694: my %oldlinkprot;
15695: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15696: %oldlinkprot = %{$currltisec{'linkprot'}};
15697: }
15698: foreach my $id (keys(%linkprotchg)) {
15699: if (ref($linkprotchg{$id}) eq 'HASH') {
15700: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15701: if (($inner eq 'secret') || ($inner eq 'key')) {
15702: if ($is_home) {
15703: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15704: }
15705: }
15706: }
15707: } else {
15708: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15709: }
15710: }
15711: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15712: if (keys(%linkprotchg)) {
15713: %{$newltisec{'linkprot'}} = %linkprotchg;
15714: }
15715: }
15716: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15717: foreach my $id (%{$currltisec{'linkprot'}}) {
15718: next if ($id !~ /^\d+$/);
15719: unless (exists($linkprotchg{$id})) {
15720: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15721: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15722: if (($inner eq 'secret') || ($inner eq 'key')) {
15723: if ($is_home) {
15724: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15725: }
15726: } else {
15727: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15728: }
15729: }
15730: } else {
15731: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15732: }
15733: }
15734: }
15735: }
15736: if ($proterror) {
15737: $errors .= '<li>'.$proterror.'</li>';
15738: }
1.320 raeburn 15739: my (@items,%deletions,%itemids);
15740: if ($env{'form.lti_add'}) {
15741: my $consumer = $env{'form.lti_consumer_add'};
15742: $consumer =~ s/(`)/'/g;
15743: ($newid,my $error) = &get_lti_id($dom,$consumer);
15744: if ($newid) {
15745: $itemids{'add'} = $newid;
15746: push(@items,'add');
15747: $changes{$newid} = 1;
15748: } else {
15749: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
15750: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15751: }
15752: }
15753: if (ref($domconfig{$action}) eq 'HASH') {
15754: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15755: if (@todelete) {
15756: map { $deletions{$_} = 1; } @todelete;
15757: }
15758: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15759: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15760: my $itemid = $env{'form.lti_id_'.$i};
15761: $itemid =~ s/\D+//g;
15762: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15763: if ($deletions{$itemid}) {
15764: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15765: } else {
1.390 raeburn 15766: push(@items,$i);
15767: $itemids{$i} = $itemid;
1.320 raeburn 15768: }
15769: }
15770: }
15771: }
1.424 raeburn 15772: my (%keystore,$secstored);
15773: if ($is_home) {
15774: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
15775: }
15776:
15777: my ($cipher,$privnum);
15778: if ((@items > 0) && ($is_home)) {
15779: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
15780: $newltisec{'encrypt'},$keystore{$home});
15781: }
1.320 raeburn 15782: foreach my $idx (@items) {
15783: my $itemid = $itemids{$idx};
15784: next unless ($itemid);
1.424 raeburn 15785: my %currlti;
15786: unless ($idx eq 'add') {
15787: if (ref($domconfig{$action}) eq 'HASH') {
15788: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15789: %currlti = %{$domconfig{$action}{$itemid}};
15790: }
15791: }
15792: }
1.390 raeburn 15793: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 15794: $position =~ s/\D+//g;
15795: if ($position ne '') {
15796: $allpos[$position] = $itemid;
15797: }
1.424 raeburn 15798: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 15799: my $formitem = 'form.lti_'.$item.'_'.$idx;
15800: $env{$formitem} =~ s/(`)/'/g;
15801: if ($item eq 'lifetime') {
15802: $env{$formitem} =~ s/[^\d.]//g;
15803: }
15804: if ($env{$formitem} ne '') {
1.424 raeburn 15805: $confhash{$itemid}{$item} = $env{$formitem};
15806: unless (($idx eq 'add') || ($changes{$itemid})) {
15807: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
15808: $changes{$itemid} = 1;
1.320 raeburn 15809: }
15810: }
15811: }
15812: }
15813: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
15814: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
15815: }
1.345 raeburn 15816: if ($confhash{$itemid}{'requser'}) {
15817: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 15818: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 15819: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
15820: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
15821: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
15822: my $mapuser = $env{'form.lti_customuser_'.$idx};
15823: $mapuser =~ s/(`)/'/g;
1.405 raeburn 15824: $mapuser =~ s/^\s+|\s+$//g;
15825: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 15826: }
15827: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
15828: my @makeuser;
15829: foreach my $ltirole (sort(@possmakeuser)) {
15830: if ($posslti{$ltirole}) {
15831: push(@makeuser,$ltirole);
15832: }
15833: }
15834: $confhash{$itemid}{'makeuser'} = \@makeuser;
15835: if (@makeuser) {
15836: my $lcauth = $env{'form.lti_lcauth_'.$idx};
15837: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
15838: $confhash{$itemid}{'lcauth'} = $lcauth;
15839: if ($lcauth ne 'internal') {
15840: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
15841: $lcauthparm =~ s/^(\s+|\s+)$//g;
15842: $lcauthparm =~ s/`//g;
15843: if ($lcauthparm ne '') {
15844: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
15845: }
15846: }
15847: } else {
15848: $confhash{$itemid}{'lcauth'} = 'lti';
15849: }
1.320 raeburn 15850: }
1.345 raeburn 15851: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
15852: if (@possinstdata) {
15853: foreach my $field (@possinstdata) {
15854: if (exists($fieldtitles{$field})) {
15855: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 15856: }
15857: }
15858: }
1.363 raeburn 15859: if ($env{'form.lti_callback_'.$idx}) {
15860: if ($env{'form.lti_callbackparam_'.$idx}) {
15861: my $callback = $env{'form.lti_callbackparam_'.$idx};
15862: $callback =~ s/^\s+|\s+$//g;
15863: $confhash{$itemid}{'callback'} = $callback;
15864: }
15865: }
1.391 raeburn 15866: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 15867: if ($env{'form.lti_'.$field.'_'.$idx}) {
15868: $confhash{$itemid}{$field} = 1;
15869: }
1.320 raeburn 15870: }
1.345 raeburn 15871: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
15872: $confhash{$itemid}{lcmenu} = [];
15873: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
15874: foreach my $field (@possmenu) {
15875: if (exists($menutitles{$field})) {
15876: if ($field eq 'grades') {
15877: next unless ($env{'form.lti_inlinemenu_'.$idx});
15878: }
15879: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 15880: }
15881: }
15882: }
1.391 raeburn 15883: if ($confhash{$itemid}{'crsinc'}) {
15884: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
15885: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
15886: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
15887: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
15888: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
15889: $mapcrs =~ s/(`)/'/g;
15890: $mapcrs =~ s/^\s+|\s+$//g;
15891: $confhash{$itemid}{'mapcrs'} = $mapcrs;
15892: }
15893: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
15894: my @crstypes;
15895: foreach my $type (sort(@posstypes)) {
15896: if ($posscrstype{$type}) {
15897: push(@crstypes,$type);
15898: }
15899: }
15900: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 15901: if ($env{'form.lti_storecrs_'.$idx}) {
15902: $confhash{$itemid}{'storecrs'} = 1;
15903: }
1.391 raeburn 15904: if ($env{'form.lti_makecrs_'.$idx}) {
15905: $confhash{$itemid}{'makecrs'} = 1;
15906: }
15907: foreach my $ltirole (@lticourseroles) {
15908: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
15909: if (grep(/^\Q$possrole\E$/,@courseroles)) {
15910: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
15911: }
15912: }
15913: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
15914: my @selfenroll;
15915: foreach my $type (sort(@possenroll)) {
15916: if ($posslticrs{$type}) {
15917: push(@selfenroll,$type);
15918: }
15919: }
15920: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
15921: if ($env{'form.lti_crssec_'.$idx}) {
15922: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
15923: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
15924: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
15925: my $section = $env{'form.lti_customsection_'.$idx};
15926: $section =~ s/(`)/'/g;
15927: $section =~ s/^\s+|\s+$//g;
15928: if ($section ne '') {
15929: $confhash{$itemid}{'section'} = $section;
15930: }
15931: }
15932: }
15933: foreach my $field ('passback','roster') {
15934: if ($env{'form.lti_'.$field.'_'.$idx}) {
15935: $confhash{$itemid}{$field} = 1;
15936: }
15937: }
15938: if ($env{'form.lti_passback_'.$idx}) {
15939: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
15940: $confhash{$itemid}{'passbackformat'} = '1.0';
15941: } else {
15942: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 15943: }
15944: }
1.391 raeburn 15945: }
15946: unless (($idx eq 'add') || ($changes{$itemid})) {
15947: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 15948: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 15949: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 15950: $changes{$itemid} = 1;
15951: }
1.345 raeburn 15952: }
15953: unless ($changes{$itemid}) {
1.424 raeburn 15954: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
15955: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 15956: $changes{$itemid} = 1;
15957: }
15958: }
1.345 raeburn 15959: }
1.391 raeburn 15960: foreach my $field ('mapcrstype','selfenroll') {
15961: unless ($changes{$itemid}) {
1.424 raeburn 15962: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 15963: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 15964: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 15965: $confhash{$itemid}{$field});
15966: if (@diffs) {
15967: $changes{$itemid} = 1;
15968: }
1.424 raeburn 15969: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 15970: $changes{$itemid} = 1;
15971: }
15972: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15973: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 15974: $changes{$itemid} = 1;
15975: }
15976: }
1.391 raeburn 15977: }
15978: }
15979: unless ($changes{$itemid}) {
1.424 raeburn 15980: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 15981: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 15982: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
15983: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 15984: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 15985: $changes{$itemid} = 1;
15986: last;
15987: }
15988: }
1.391 raeburn 15989: unless ($changes{$itemid}) {
15990: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
15991: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 15992: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 15993: $changes{$itemid} = 1;
15994: last;
15995: }
15996: }
15997: }
1.424 raeburn 15998: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 15999: $changes{$itemid} = 1;
1.345 raeburn 16000: }
1.391 raeburn 16001: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16002: unless ($changes{$itemid}) {
16003: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16004: $changes{$itemid} = 1;
16005: }
16006: }
16007: }
16008: }
16009: }
16010: unless ($changes{$itemid}) {
16011: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 16012: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16013: $changes{$itemid} = 1;
1.320 raeburn 16014: }
1.391 raeburn 16015: }
16016: unless ($changes{$itemid}) {
16017: foreach my $field ('makeuser','lcmenu') {
1.424 raeburn 16018: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16019: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16020: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16021: $confhash{$itemid}{$field});
16022: if (@diffs) {
16023: $changes{$itemid} = 1;
16024: }
1.424 raeburn 16025: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16026: $changes{$itemid} = 1;
16027: }
16028: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16029: if (@{$confhash{$itemid}{$field}} > 0) {
16030: $changes{$itemid} = 1;
16031: }
1.345 raeburn 16032: }
1.320 raeburn 16033: }
16034: }
16035: }
16036: }
16037: }
1.424 raeburn 16038: if ($is_home) {
16039: my $keyitem = 'form.lti_key_'.$idx;
16040: $env{$keyitem} =~ s/(`)/'/g;
16041: if ($env{$keyitem} ne '') {
16042: $ltienc{$itemid}{'key'} = $env{$keyitem};
16043: unless ($changes{$itemid}) {
16044: if ($currlti{'key'} ne $env{$keyitem}) {
16045: $changes{$itemid} = 1;
16046: }
16047: }
16048: }
16049: my $secretitem = 'form.lti_secret_'.$idx;
16050: $env{$secretitem} =~ s/(`)/'/g;
16051: if ($currlti{'usable'}) {
16052: if ($env{'form.lti_changesecret_'.$idx}) {
16053: if ($env{$secretitem} ne '') {
16054: if ($privnum && $cipher) {
16055: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16056: $confhash{$itemid}{'cipher'} = $privnum;
16057: } else {
16058: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16059: }
16060: $changes{$itemid} = 1;
16061: }
16062: } else {
16063: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16064: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16065: }
16066: if (ref($ltienc{$itemid}) eq 'HASH') {
16067: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16068: $confhash{$itemid}{'usable'} = 1;
16069: }
16070: }
16071: } elsif ($env{$secretitem} ne '') {
16072: if ($privnum && $cipher) {
16073: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16074: $confhash{$itemid}{'cipher'} = $privnum;
16075: } else {
16076: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16077: }
16078: if (ref($ltienc{$itemid}) eq 'HASH') {
16079: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16080: $confhash{$itemid}{'usable'} = 1;
16081: }
16082: }
16083: $changes{$itemid} = 1;
16084: }
16085: }
16086: unless ($changes{$itemid}) {
16087: foreach my $key (keys(%currlti)) {
16088: if (ref($currlti{$key}) eq 'HASH') {
16089: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16090: foreach my $innerkey (keys(%{$currlti{$key}})) {
16091: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16092: $changes{$itemid} = 1;
16093: last;
16094: }
16095: }
16096: } elsif (keys(%{$currlti{$key}}) > 0) {
16097: $changes{$itemid} = 1;
16098: }
16099: }
16100: last if ($changes{$itemid});
16101: }
16102: }
1.320 raeburn 16103: }
16104: if (@allpos > 0) {
16105: my $idx = 0;
16106: foreach my $itemid (@allpos) {
16107: if ($itemid ne '') {
16108: $confhash{$itemid}{'order'} = $idx;
16109: if (ref($domconfig{$action}) eq 'HASH') {
16110: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16111: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16112: $changes{$itemid} = 1;
16113: }
16114: }
16115: }
16116: $idx ++;
16117: }
16118: }
16119: }
1.424 raeburn 16120:
16121: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16122: return &mt('No changes made.');
16123: }
16124:
1.320 raeburn 16125: my %ltihash = (
1.405 raeburn 16126: $action => { %confhash }
16127: );
1.424 raeburn 16128: my %ltienchash;
16129:
16130: if ($is_home) {
16131: %ltienchash = (
16132: $action => { %ltienc }
16133: );
16134: }
1.405 raeburn 16135: if (keys(%secchanges)) {
16136: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16137: if ($secchanges{'linkprot'}) {
16138: if ($is_home) {
16139: $ltienchash{'linkprot'} = \%newltienc;
16140: }
16141: }
1.405 raeburn 16142: }
16143: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16144: if ($putresult eq 'ok') {
1.424 raeburn 16145: if (keys(%ltienchash)) {
16146: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16147: }
16148: $resulttext = &mt('Changes made:').'<ul>';
16149: if (keys(%secchanges) > 0) {
1.423 raeburn 16150: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16151: if (exists($secchanges{'linkprot'})) {
16152: $resulttext .= $linkprotoutput;
1.405 raeburn 16153: }
16154: }
1.320 raeburn 16155: if (keys(%changes) > 0) {
16156: my $cachetime = 24*60*60;
1.424 raeburn 16157: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16158: if (ref($lastactref) eq 'HASH') {
16159: $lastactref->{'lti'} = 1;
16160: }
16161: my %bynum;
16162: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16163: if (ref($confhash{$itemid}) eq 'HASH') {
16164: my $position = $confhash{$itemid}{'order'};
16165: $bynum{$position} = $itemid;
16166: }
1.320 raeburn 16167: }
16168: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16169: my $itemid = $bynum{$pos};
1.424 raeburn 16170: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16171: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16172: my $position = $pos + 1;
16173: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16174: foreach my $item ('version','lifetime') {
16175: if ($confhash{$itemid}{$item} ne '') {
16176: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16177: }
16178: }
1.424 raeburn 16179: if ($ltienc{$itemid}{'key'} ne '') {
16180: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16181: }
1.424 raeburn 16182: if ($ltienc{$itemid}{'secret'} ne '') {
16183: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16184: }
1.345 raeburn 16185: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16186: if ($confhash{$itemid}{'callback'}) {
16187: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16188: } else {
1.392 raeburn 16189: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16190: }
1.345 raeburn 16191: if ($confhash{$itemid}{'mapuser'}) {
16192: my $shownmapuser;
16193: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16194: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16195: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16196: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16197: } else {
16198: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16199: }
1.345 raeburn 16200: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16201: }
1.345 raeburn 16202: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16203: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16204: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16205: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16206: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16207: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16208: } else {
16209: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16210: $confhash{$itemid}{'lcauth'});
16211: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16212: $resulttext .= '; '.&mt('a randomly generated password will be created');
16213: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16214: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16215: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16216: }
16217: } else {
16218: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16219: }
16220: }
16221: $resulttext .= '</li>';
16222: } else {
16223: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16224: }
1.320 raeburn 16225: }
1.345 raeburn 16226: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16227: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16228: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16229: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16230: } else {
1.345 raeburn 16231: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 16232: }
1.320 raeburn 16233: }
1.391 raeburn 16234: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16235: $resulttext .= '<li>'.$lt{$item}.': ';
16236: if ($confhash{$itemid}{$item}) {
16237: $resulttext .= &mt('Yes');
16238: } else {
16239: $resulttext .= &mt('No');
1.337 raeburn 16240: }
1.345 raeburn 16241: $resulttext .= '</li>';
1.320 raeburn 16242: }
1.345 raeburn 16243: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16244: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16245: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16246: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16247: } else {
16248: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16249: }
16250: }
16251: if ($confhash{$itemid}{'crsinc'}) {
16252: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16253: my $rolemaps;
16254: foreach my $role (@ltiroles) {
16255: if ($confhash{$itemid}{'maproles'}{$role}) {
16256: $rolemaps .= (' 'x2).$role.'='.
16257: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16258: 'Course').',';
16259: }
16260: }
16261: if ($rolemaps) {
16262: $rolemaps =~ s/,$//;
16263: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16264: }
16265: }
16266: if ($confhash{$itemid}{'mapcrs'}) {
16267: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16268: }
16269: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16270: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16271: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16272: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16273: '</li>';
16274: } else {
16275: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16276: }
16277: }
1.392 raeburn 16278: if ($confhash{$itemid}{'storecrs'}) {
16279: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16280: }
1.391 raeburn 16281: if ($confhash{$itemid}{'makecrs'}) {
16282: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16283: } else {
16284: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16285: }
16286: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16287: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16288: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16289: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16290: '</li>';
16291: } else {
16292: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16293: }
16294: }
16295: if ($confhash{$itemid}{'section'}) {
16296: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16297: $resulttext .= '<li>'.&mt('User section from standard field:').
16298: ' (course_section_sourcedid)'.'</li>';
16299: } else {
16300: $resulttext .= '<li>'.&mt('User section from:').' '.
16301: $confhash{$itemid}{'section'}.'</li>';
16302: }
1.345 raeburn 16303: } else {
1.391 raeburn 16304: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16305: }
16306: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16307: $resulttext .= '<li>'.$lt{$item}.': ';
16308: if ($confhash{$itemid}{$item}) {
16309: $resulttext .= &mt('Yes');
16310: if ($item eq 'passback') {
16311: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16312: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16313: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16314: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16315: }
16316: }
16317: } else {
16318: $resulttext .= &mt('No');
16319: }
16320: $resulttext .= '</li>';
16321: }
16322: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16323: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16324: $resulttext .= '<li>'.&mt('Menu items:').' '.
16325: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16326: } else {
16327: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16328: }
1.345 raeburn 16329: }
1.326 raeburn 16330: }
16331: }
1.320 raeburn 16332: $resulttext .= '</ul></li>';
16333: }
16334: }
1.424 raeburn 16335: if (keys(%deletions)) {
16336: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16337: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16338: }
16339: }
1.320 raeburn 16340: }
1.405 raeburn 16341: $resulttext .= '</ul>';
1.424 raeburn 16342: if (ref($lastactref) eq 'HASH') {
16343: if (($secchanges{'encrypt'}) || ($secchanges{'private'})) {
16344: $lastactref->{'domdefaults'} = 1;
16345: }
16346: }
1.320 raeburn 16347: } else {
16348: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16349: }
16350: if ($errors) {
16351: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16352: $errors.'</ul>';
16353: }
16354: return $resulttext;
16355: }
16356:
1.424 raeburn 16357: sub get_priv_creds {
16358: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16359: my ($needenc,$cipher,$privnum);
16360: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16361: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16362: $needenc = $encrypt->{'consumers'}
16363: } else {
16364: $needenc = $domdefs{'ltienc_consumers'};
16365: }
16366: if ($needenc) {
16367: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16368: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16369: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16370: my $privkey = $privhash{'key'};
16371: $privnum = $privhash{'version'};
16372: if (($privnum) && ($privkey ne '')) {
16373: $cipher = Crypt::CBC->new({'key' => $privkey,
16374: 'cipher' => 'DES'});
16375: }
16376: }
16377: }
16378: return ($cipher,$privnum);
16379: }
16380:
1.320 raeburn 16381: sub get_lti_id {
16382: my ($domain,$consumer) = @_;
16383: # get lock on lti db
16384: my $lockhash = {
16385: lock => $env{'user.name'}.
16386: ':'.$env{'user.domain'},
16387: };
16388: my $tries = 0;
16389: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
16390: my ($id,$error);
16391:
16392: while (($gotlock ne 'ok') && ($tries<10)) {
16393: $tries ++;
16394: sleep (0.1);
16395: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
16396: }
16397: if ($gotlock eq 'ok') {
16398: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
16399: if ($currids{'lock'}) {
16400: delete($currids{'lock'});
16401: if (keys(%currids)) {
16402: my @curr = sort { $a <=> $b } keys(%currids);
16403: if ($curr[-1] =~ /^\d+$/) {
16404: $id = 1 + $curr[-1];
16405: }
16406: } else {
16407: $id = 1;
16408: }
16409: if ($id) {
16410: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
16411: $error = 'nostore';
16412: }
16413: } else {
16414: $error = 'nonumber';
16415: }
16416: }
16417: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
16418: } else {
16419: $error = 'nolock';
16420: }
16421: return ($id,$error);
16422: }
16423:
1.3 raeburn 16424: sub modify_autoenroll {
1.205 raeburn 16425: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16426: my ($resulttext,%changes);
16427: my %currautoenroll;
16428: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16429: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16430: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16431: }
16432: }
16433: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16434: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16435: sender => 'Sender for notification messages',
1.274 raeburn 16436: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16437: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16438: my @offon = ('off','on');
1.17 raeburn 16439: my $sender_uname = $env{'form.sender_uname'};
16440: my $sender_domain = $env{'form.sender_domain'};
16441: if ($sender_domain eq '') {
16442: $sender_uname = '';
16443: } elsif ($sender_uname eq '') {
16444: $sender_domain = '';
16445: }
1.129 raeburn 16446: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16447: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16448: $autofailsafe =~ s{^\s+|\s+$}{}g;
16449: if ($autofailsafe =~ /\D/) {
16450: undef($autofailsafe);
16451: }
1.274 raeburn 16452: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16453: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16454: $failsafe = 'off';
1.400 raeburn 16455: undef($autofailsafe);
1.274 raeburn 16456: }
1.1 raeburn 16457: my %autoenrollhash = (
1.129 raeburn 16458: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16459: 'sender_uname' => $sender_uname,
16460: 'sender_domain' => $sender_domain,
16461: 'co-owners' => $coowners,
1.399 raeburn 16462: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16463: 'failsafe' => $failsafe,
1.1 raeburn 16464: }
16465: );
1.4 raeburn 16466: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16467: $dom);
1.1 raeburn 16468: if ($putresult eq 'ok') {
16469: if (exists($currautoenroll{'run'})) {
16470: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16471: $changes{'run'} = 1;
16472: }
16473: } elsif ($autorun) {
16474: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16475: $changes{'run'} = 1;
1.1 raeburn 16476: }
16477: }
1.17 raeburn 16478: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16479: $changes{'sender'} = 1;
16480: }
1.17 raeburn 16481: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16482: $changes{'sender'} = 1;
16483: }
1.129 raeburn 16484: if ($currautoenroll{'co-owners'} ne '') {
16485: if ($currautoenroll{'co-owners'} ne $coowners) {
16486: $changes{'coowners'} = 1;
16487: }
16488: } elsif ($coowners) {
16489: $changes{'coowners'} = 1;
1.274 raeburn 16490: }
1.399 raeburn 16491: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16492: $changes{'autofailsafe'} = 1;
16493: }
1.399 raeburn 16494: if ($currautoenroll{'failsafe'} ne $failsafe) {
16495: $changes{'failsafe'} = 1;
16496: }
1.1 raeburn 16497: if (keys(%changes) > 0) {
16498: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16499: if ($changes{'run'}) {
1.1 raeburn 16500: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16501: }
16502: if ($changes{'sender'}) {
1.17 raeburn 16503: if ($sender_uname eq '' || $sender_domain eq '') {
16504: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16505: } else {
16506: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16507: }
1.1 raeburn 16508: }
1.129 raeburn 16509: if ($changes{'coowners'}) {
16510: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16511: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16512: if (ref($lastactref) eq 'HASH') {
16513: $lastactref->{'domainconfig'} = 1;
16514: }
1.129 raeburn 16515: }
1.274 raeburn 16516: if ($changes{'autofailsafe'}) {
1.399 raeburn 16517: if ($autofailsafe ne '') {
16518: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16519: } else {
1.399 raeburn 16520: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16521: }
1.399 raeburn 16522: }
16523: if ($changes{'failsafe'}) {
16524: if ($failsafe eq 'off') {
16525: unless ($changes{'autofailsafe'}) {
16526: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16527: }
16528: } elsif ($failsafe eq 'zero') {
16529: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16530: } else {
16531: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16532: }
16533: }
16534: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16535: &Apache::lonnet::get_domain_defaults($dom,1);
16536: if (ref($lastactref) eq 'HASH') {
16537: $lastactref->{'domdefaults'} = 1;
16538: }
16539: }
1.1 raeburn 16540: $resulttext .= '</ul>';
16541: } else {
16542: $resulttext = &mt('No changes made to auto-enrollment settings');
16543: }
16544: } else {
1.11 albertel 16545: $resulttext = '<span class="LC_error">'.
16546: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16547: }
1.3 raeburn 16548: return $resulttext;
1.1 raeburn 16549: }
16550:
16551: sub modify_autoupdate {
1.3 raeburn 16552: my ($dom,%domconfig) = @_;
1.1 raeburn 16553: my ($resulttext,%currautoupdate,%fields,%changes);
16554: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16555: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16556: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16557: }
16558: }
16559: my @offon = ('off','on');
16560: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16561: run => 'Auto-update:',
16562: classlists => 'Updates to user information in classlists?',
16563: unexpired => 'Skip updates for users without active or future roles?',
16564: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16565: );
1.44 raeburn 16566: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16567: my %fieldtitles = &Apache::lonlocal::texthash (
16568: id => 'Student/Employee ID',
1.20 raeburn 16569: permanentemail => 'E-mail address',
1.1 raeburn 16570: lastname => 'Last Name',
16571: firstname => 'First Name',
16572: middlename => 'Middle Name',
1.132 raeburn 16573: generation => 'Generation',
1.1 raeburn 16574: );
1.142 raeburn 16575: $othertitle = &mt('All users');
1.1 raeburn 16576: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16577: $othertitle = &mt('Other users');
1.1 raeburn 16578: }
16579: foreach my $key (keys(%env)) {
16580: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16581: my ($usertype,$item) = ($1,$2);
16582: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16583: if ($usertype eq 'default') {
16584: push(@{$fields{$1}},$2);
16585: } elsif (ref($types) eq 'ARRAY') {
16586: if (grep(/^\Q$usertype\E$/,@{$types})) {
16587: push(@{$fields{$1}},$2);
16588: }
16589: }
16590: }
1.1 raeburn 16591: }
16592: }
1.131 raeburn 16593: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16594: @lockablenames = sort(@lockablenames);
16595: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16596: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16597: if (@changed) {
16598: $changes{'lockablenames'} = 1;
16599: }
16600: } else {
16601: if (@lockablenames) {
16602: $changes{'lockablenames'} = 1;
16603: }
16604: }
1.1 raeburn 16605: my %updatehash = (
16606: autoupdate => { run => $env{'form.autoupdate_run'},
16607: classlists => $env{'form.classlists'},
1.385 raeburn 16608: unexpired => $env{'form.unexpired'},
1.1 raeburn 16609: fields => {%fields},
1.131 raeburn 16610: lockablenames => \@lockablenames,
1.1 raeburn 16611: }
16612: );
1.385 raeburn 16613: my $lastactivedays;
16614: if ($env{'form.lastactive'}) {
16615: $lastactivedays = $env{'form.lastactivedays'};
16616: $lastactivedays =~ s/^\s+|\s+$//g;
16617: unless ($lastactivedays =~ /^\d+$/) {
16618: undef($lastactivedays);
16619: $env{'form.lastactive'} = 0;
16620: }
16621: }
16622: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16623: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16624: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16625: if (exists($updatehash{autoupdate}{$key})) {
16626: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16627: $changes{$key} = 1;
16628: }
16629: }
16630: } elsif ($key eq 'fields') {
16631: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16632: foreach my $item (@{$types},'default') {
1.1 raeburn 16633: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16634: my $change = 0;
16635: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16636: if (!exists($fields{$item})) {
16637: $change = 1;
1.132 raeburn 16638: last;
1.1 raeburn 16639: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16640: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16641: $change = 1;
1.132 raeburn 16642: last;
1.1 raeburn 16643: }
16644: }
16645: }
16646: if ($change) {
16647: push(@{$changes{$key}},$item);
16648: }
1.26 raeburn 16649: }
1.1 raeburn 16650: }
16651: }
1.131 raeburn 16652: } elsif ($key eq 'lockablenames') {
16653: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16654: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16655: if (@changed) {
16656: $changes{'lockablenames'} = 1;
16657: }
16658: } else {
16659: if (@lockablenames) {
16660: $changes{'lockablenames'} = 1;
16661: }
16662: }
16663: }
16664: }
16665: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16666: if (@lockablenames) {
16667: $changes{'lockablenames'} = 1;
1.1 raeburn 16668: }
16669: }
1.385 raeburn 16670: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16671: if ($updatehash{'autoupdate'}{'unexpired'}) {
16672: $changes{'unexpired'} = 1;
16673: }
16674: }
16675: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16676: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16677: $changes{'lastactive'} = 1;
16678: }
16679: }
1.26 raeburn 16680: foreach my $item (@{$types},'default') {
16681: if (defined($fields{$item})) {
16682: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16683: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16684: my $change = 0;
16685: if (ref($fields{$item}) eq 'ARRAY') {
16686: foreach my $type (@{$fields{$item}}) {
16687: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16688: $change = 1;
16689: last;
16690: }
16691: }
16692: }
16693: if ($change) {
16694: push(@{$changes{'fields'}},$item);
16695: }
16696: } else {
1.26 raeburn 16697: push(@{$changes{'fields'}},$item);
16698: }
16699: } else {
16700: push(@{$changes{'fields'}},$item);
1.1 raeburn 16701: }
16702: }
16703: }
16704: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16705: $dom);
16706: if ($putresult eq 'ok') {
16707: if (keys(%changes) > 0) {
16708: $resulttext = &mt('Changes made:').'<ul>';
16709: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16710: if ($key eq 'lockablenames') {
16711: $resulttext .= '<li>';
16712: if (@lockablenames) {
16713: $usertypes->{'default'} = $othertitle;
16714: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16715: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16716: } else {
16717: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16718: }
16719: $resulttext .= '</li>';
16720: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16721: foreach my $item (@{$changes{$key}}) {
16722: my @newvalues;
16723: foreach my $type (@{$fields{$item}}) {
16724: push(@newvalues,$fieldtitles{$type});
16725: }
1.3 raeburn 16726: my $newvaluestr;
16727: if (@newvalues > 0) {
16728: $newvaluestr = join(', ',@newvalues);
16729: } else {
16730: $newvaluestr = &mt('none');
1.6 raeburn 16731: }
1.1 raeburn 16732: if ($item eq 'default') {
1.26 raeburn 16733: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16734: } else {
1.26 raeburn 16735: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16736: }
16737: }
16738: } else {
16739: my $newvalue;
16740: if ($key eq 'run') {
16741: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16742: } elsif ($key eq 'lastactive') {
16743: $newvalue = $offon[$env{'form.lastactive'}];
16744: unless ($lastactivedays eq '') {
16745: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16746: }
1.1 raeburn 16747: } else {
16748: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16749: }
1.1 raeburn 16750: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16751: }
16752: }
16753: $resulttext .= '</ul>';
16754: } else {
1.3 raeburn 16755: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16756: }
16757: } else {
1.11 albertel 16758: $resulttext = '<span class="LC_error">'.
16759: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16760: }
1.3 raeburn 16761: return $resulttext;
1.1 raeburn 16762: }
16763:
1.125 raeburn 16764: sub modify_autocreate {
16765: my ($dom,%domconfig) = @_;
16766: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
16767: if (ref($domconfig{'autocreate'}) eq 'HASH') {
16768: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
16769: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
16770: }
16771: }
16772: my %title= ( xml => 'Auto-creation of courses in XML course description files',
16773: req => 'Auto-creation of validated requests for official courses',
16774: xmldc => 'Identity of course creator of courses from XML files',
16775: );
16776: my @types = ('xml','req');
16777: foreach my $item (@types) {
16778: $newvals{$item} = $env{'form.autocreate_'.$item};
16779: $newvals{$item} =~ s/\D//g;
16780: $newvals{$item} = 0 if ($newvals{$item} eq '');
16781: }
16782: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 16783: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 16784: unless (exists($domcoords{$newvals{'xmldc'}})) {
16785: $newvals{'xmldc'} = '';
16786: }
16787: %autocreatehash = (
16788: autocreate => { xml => $newvals{'xml'},
16789: req => $newvals{'req'},
16790: }
16791: );
16792: if ($newvals{'xmldc'} ne '') {
16793: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
16794: }
16795: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
16796: $dom);
16797: if ($putresult eq 'ok') {
16798: my @items = @types;
16799: if ($newvals{'xml'}) {
16800: push(@items,'xmldc');
16801: }
16802: foreach my $item (@items) {
16803: if (exists($currautocreate{$item})) {
16804: if ($currautocreate{$item} ne $newvals{$item}) {
16805: $changes{$item} = 1;
16806: }
16807: } elsif ($newvals{$item}) {
16808: $changes{$item} = 1;
16809: }
16810: }
16811: if (keys(%changes) > 0) {
16812: my @offon = ('off','on');
16813: $resulttext = &mt('Changes made:').'<ul>';
16814: foreach my $item (@types) {
16815: if ($changes{$item}) {
16816: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 16817: $resulttext .= '<li>'.
16818: &mt("$title{$item} set to [_1]$newtxt [_2]",
16819: '<b>','</b>').
16820: '</li>';
1.125 raeburn 16821: }
16822: }
16823: if ($changes{'xmldc'}) {
16824: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
16825: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 16826: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 16827: }
16828: $resulttext .= '</ul>';
16829: } else {
16830: $resulttext = &mt('No changes made to auto-creation settings');
16831: }
16832: } else {
16833: $resulttext = '<span class="LC_error">'.
16834: &mt('An error occurred: [_1]',$putresult).'</span>';
16835: }
16836: return $resulttext;
16837: }
16838:
1.23 raeburn 16839: sub modify_directorysrch {
1.295 raeburn 16840: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 16841: my ($resulttext,%changes);
16842: my %currdirsrch;
16843: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
16844: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
16845: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
16846: }
16847: }
1.277 raeburn 16848: my %title = ( available => 'Institutional directory search available',
16849: localonly => 'Other domains can search institution',
16850: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 16851: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 16852: searchby => 'Search types',
16853: searchtypes => 'Search latitude');
16854: my @offon = ('off','on');
1.24 raeburn 16855: my @otherdoms = ('Yes','No');
1.23 raeburn 16856:
1.25 raeburn 16857: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 16858: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
16859: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
16860:
1.44 raeburn 16861: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 16862: if (keys(%{$usertypes}) == 0) {
16863: @cansearch = ('default');
16864: } else {
16865: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
16866: foreach my $type (@{$currdirsrch{'cansearch'}}) {
16867: if (!grep(/^\Q$type\E$/,@cansearch)) {
16868: push(@{$changes{'cansearch'}},$type);
16869: }
1.23 raeburn 16870: }
1.26 raeburn 16871: foreach my $type (@cansearch) {
16872: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
16873: push(@{$changes{'cansearch'}},$type);
16874: }
1.23 raeburn 16875: }
1.26 raeburn 16876: } else {
16877: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 16878: }
16879: }
16880:
16881: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
16882: foreach my $by (@{$currdirsrch{'searchby'}}) {
16883: if (!grep(/^\Q$by\E$/,@searchby)) {
16884: push(@{$changes{'searchby'}},$by);
16885: }
16886: }
16887: foreach my $by (@searchby) {
16888: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
16889: push(@{$changes{'searchby'}},$by);
16890: }
16891: }
16892: } else {
16893: push(@{$changes{'searchby'}},@searchby);
16894: }
1.25 raeburn 16895:
16896: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
16897: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
16898: if (!grep(/^\Q$type\E$/,@searchtypes)) {
16899: push(@{$changes{'searchtypes'}},$type);
16900: }
16901: }
16902: foreach my $type (@searchtypes) {
16903: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
16904: push(@{$changes{'searchtypes'}},$type);
16905: }
16906: }
16907: } else {
16908: if (exists($currdirsrch{'searchtypes'})) {
16909: foreach my $type (@searchtypes) {
16910: if ($type ne $currdirsrch{'searchtypes'}) {
16911: push(@{$changes{'searchtypes'}},$type);
16912: }
16913: }
16914: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
16915: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
16916: }
16917: } else {
16918: push(@{$changes{'searchtypes'}},@searchtypes);
16919: }
16920: }
16921:
1.23 raeburn 16922: my %dirsrch_hash = (
16923: directorysrch => { available => $env{'form.dirsrch_available'},
16924: cansearch => \@cansearch,
1.277 raeburn 16925: localonly => $env{'form.dirsrch_instlocalonly'},
16926: lclocalonly => $env{'form.dirsrch_domlocalonly'},
16927: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 16928: searchby => \@searchby,
1.25 raeburn 16929: searchtypes => \@searchtypes,
1.23 raeburn 16930: }
16931: );
16932: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
16933: $dom);
16934: if ($putresult eq 'ok') {
16935: if (exists($currdirsrch{'available'})) {
16936: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
16937: $changes{'available'} = 1;
16938: }
16939: } else {
16940: if ($env{'form.dirsrch_available'} eq '1') {
16941: $changes{'available'} = 1;
16942: }
16943: }
1.277 raeburn 16944: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 16945: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
16946: $changes{'lcavailable'} = 1;
16947: }
1.277 raeburn 16948: } else {
16949: if ($env{'form.dirsrch_lcavailable'} eq '1') {
16950: $changes{'lcavailable'} = 1;
16951: }
16952: }
1.24 raeburn 16953: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 16954: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
16955: $changes{'localonly'} = 1;
16956: }
1.24 raeburn 16957: } else {
1.277 raeburn 16958: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 16959: $changes{'localonly'} = 1;
16960: }
16961: }
1.277 raeburn 16962: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 16963: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
16964: $changes{'lclocalonly'} = 1;
16965: }
1.277 raeburn 16966: } else {
16967: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
16968: $changes{'lclocalonly'} = 1;
16969: }
16970: }
1.23 raeburn 16971: if (keys(%changes) > 0) {
16972: $resulttext = &mt('Changes made:').'<ul>';
16973: if ($changes{'available'}) {
16974: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
16975: }
1.277 raeburn 16976: if ($changes{'lcavailable'}) {
16977: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
16978: }
1.24 raeburn 16979: if ($changes{'localonly'}) {
1.277 raeburn 16980: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 16981: }
1.277 raeburn 16982: if ($changes{'lclocalonly'}) {
16983: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 16984: }
1.23 raeburn 16985: if (ref($changes{'cansearch'}) eq 'ARRAY') {
16986: my $chgtext;
1.26 raeburn 16987: if (ref($usertypes) eq 'HASH') {
16988: if (keys(%{$usertypes}) > 0) {
16989: foreach my $type (@{$types}) {
16990: if (grep(/^\Q$type\E$/,@cansearch)) {
16991: $chgtext .= $usertypes->{$type}.'; ';
16992: }
16993: }
16994: if (grep(/^default$/,@cansearch)) {
16995: $chgtext .= $othertitle;
16996: } else {
16997: $chgtext =~ s/\; $//;
16998: }
1.210 raeburn 16999: $resulttext .=
1.178 raeburn 17000: '<li>'.
17001: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17002: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17003: '</li>';
1.23 raeburn 17004: }
17005: }
17006: }
17007: if (ref($changes{'searchby'}) eq 'ARRAY') {
17008: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17009: my $chgtext;
17010: foreach my $type (@{$titleorder}) {
17011: if (grep(/^\Q$type\E$/,@searchby)) {
17012: if (defined($searchtitles->{$type})) {
17013: $chgtext .= $searchtitles->{$type}.'; ';
17014: }
17015: }
17016: }
17017: $chgtext =~ s/\; $//;
17018: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17019: }
1.25 raeburn 17020: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17021: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17022: my $chgtext;
17023: foreach my $type (@{$srchtypeorder}) {
17024: if (grep(/^\Q$type\E$/,@searchtypes)) {
17025: if (defined($srchtypes_desc->{$type})) {
17026: $chgtext .= $srchtypes_desc->{$type}.'; ';
17027: }
17028: }
17029: }
17030: $chgtext =~ s/\; $//;
1.178 raeburn 17031: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17032: }
17033: $resulttext .= '</ul>';
1.295 raeburn 17034: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17035: if (ref($lastactref) eq 'HASH') {
17036: $lastactref->{'directorysrch'} = 1;
17037: }
1.23 raeburn 17038: } else {
1.277 raeburn 17039: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17040: }
17041: } else {
17042: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17043: &mt('An error occurred: [_1]',$putresult).'</span>';
17044: }
17045: return $resulttext;
17046: }
17047:
1.28 raeburn 17048: sub modify_contacts {
1.205 raeburn 17049: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17050: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17051: if (ref($domconfig{'contacts'}) eq 'HASH') {
17052: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17053: $currsetting{$key} = $domconfig{'contacts'}{$key};
17054: }
17055: }
1.286 raeburn 17056: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17057: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17058: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17059: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17060: my @toggles = ('reporterrors','reportupdates','reportstatus');
17061: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17062: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17063: foreach my $type (@mailings) {
17064: @{$newsetting{$type}} =
17065: &Apache::loncommon::get_env_multiple('form.'.$type);
17066: foreach my $item (@contacts) {
17067: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17068: $contacts_hash{contacts}{$type}{$item} = 1;
17069: } else {
17070: $contacts_hash{contacts}{$type}{$item} = 0;
17071: }
1.289 raeburn 17072: }
1.28 raeburn 17073: $others{$type} = $env{'form.'.$type.'_others'};
17074: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17075: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17076: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17077: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17078: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17079: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17080: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17081: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17082: }
1.134 raeburn 17083: }
1.28 raeburn 17084: }
17085: foreach my $item (@contacts) {
17086: $to{$item} = $env{'form.'.$item};
17087: $contacts_hash{'contacts'}{$item} = $to{$item};
17088: }
1.203 raeburn 17089: foreach my $item (@toggles) {
17090: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17091: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17092: }
17093: }
1.340 raeburn 17094: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17095: foreach my $item (@lonstatus) {
17096: if ($item eq 'excluded') {
17097: my (%serverhomes,@excluded);
17098: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17099: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17100: if (@possexcluded) {
17101: foreach my $id (sort(@possexcluded)) {
17102: if ($serverhomes{$id}) {
17103: push(@excluded,$id);
17104: }
17105: }
17106: }
17107: if (@excluded) {
17108: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17109: }
17110: } elsif ($item eq 'weights') {
1.377 raeburn 17111: foreach my $type ('E','W','N','U') {
1.340 raeburn 17112: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17113: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17114: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17115: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17116: $env{'form.error'.$item.'_'.$type};
17117: }
17118: }
17119: }
17120: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17121: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17122: if ($env{'form.error'.$item} =~ /^\d+$/) {
17123: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17124: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17125: }
17126: }
17127: }
17128: }
1.286 raeburn 17129: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17130: foreach my $field (@{$fields}) {
17131: if (ref($possoptions->{$field}) eq 'ARRAY') {
17132: my $value = $env{'form.helpform_'.$field};
17133: $value =~ s/^\s+|\s+$//g;
17134: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17135: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17136: if ($field eq 'screenshot') {
17137: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17138: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17139: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17140: }
17141: }
17142: }
17143: }
17144: }
17145: }
1.315 raeburn 17146: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17147: my (@statuses,%usertypeshash,@overrides);
17148: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17149: @statuses = @{$types};
17150: if (ref($usertypes) eq 'HASH') {
17151: %usertypeshash = %{$usertypes};
17152: }
17153: }
17154: if (@statuses) {
17155: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17156: foreach my $type (@possoverrides) {
17157: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17158: push(@overrides,$type);
17159: }
17160: }
17161: if (@overrides) {
17162: foreach my $type (@overrides) {
17163: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17164: foreach my $item (@contacts) {
17165: if (grep(/^\Q$item\E$/,@standard)) {
17166: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17167: $newsetting{'override_'.$type}{$item} = 1;
17168: } else {
17169: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17170: $newsetting{'override_'.$type}{$item} = 0;
17171: }
17172: }
17173: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17174: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17175: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17176: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17177: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17178: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17179: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17180: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17181: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17182: }
1.425 raeburn 17183: }
1.315 raeburn 17184: }
17185: }
1.28 raeburn 17186: if (keys(%currsetting) > 0) {
17187: foreach my $item (@contacts) {
17188: if ($to{$item} ne $currsetting{$item}) {
17189: $changes{$item} = 1;
17190: }
17191: }
17192: foreach my $type (@mailings) {
17193: foreach my $item (@contacts) {
17194: if (ref($currsetting{$type}) eq 'HASH') {
17195: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17196: push(@{$changes{$type}},$item);
17197: }
17198: } else {
17199: push(@{$changes{$type}},@{$newsetting{$type}});
17200: }
17201: }
17202: if ($others{$type} ne $currsetting{$type}{'others'}) {
17203: push(@{$changes{$type}},'others');
17204: }
1.289 raeburn 17205: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17206: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17207: push(@{$changes{$type}},'bcc');
17208: }
1.286 raeburn 17209: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17210: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17211: push(@{$changes{$type}},'include');
17212: }
17213: }
17214: }
17215: if (ref($fields) eq 'ARRAY') {
17216: if (ref($currsetting{'helpform'}) eq 'HASH') {
17217: foreach my $field (@{$fields}) {
17218: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17219: push(@{$changes{'helpform'}},$field);
17220: }
17221: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17222: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17223: push(@{$changes{'helpform'}},'maxsize');
17224: }
17225: }
17226: }
17227: } else {
17228: foreach my $field (@{$fields}) {
17229: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17230: push(@{$changes{'helpform'}},$field);
17231: }
17232: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17233: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17234: push(@{$changes{'helpform'}},'maxsize');
17235: }
17236: }
17237: }
1.134 raeburn 17238: }
1.28 raeburn 17239: }
1.315 raeburn 17240: if (@statuses) {
1.425 raeburn 17241: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17242: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17243: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17244: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17245: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17246: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17247: push(@{$changes{'overrides'}},$key);
17248: last;
17249: }
17250: }
17251: } else {
17252: push(@{$changes{'overrides'}},$key);
17253: }
17254: }
17255: }
17256: foreach my $key (@overrides) {
17257: unless (exists($currsetting{'overrides'}{$key})) {
17258: push(@{$changes{'overrides'}},$key);
17259: }
17260: }
17261: } else {
17262: foreach my $key (@overrides) {
1.425 raeburn 17263: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17264: }
17265: }
17266: }
1.340 raeburn 17267: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17268: foreach my $key ('excluded','weights','threshold','sysmail') {
17269: if ($key eq 'excluded') {
17270: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17271: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17272: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17273: (@{$currsetting{'lonstatus'}{$key}})) {
17274: my @diffs =
17275: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17276: $currsetting{'lonstatus'}{$key});
17277: if (@diffs) {
17278: push(@{$changes{'lonstatus'}},$key);
17279: }
17280: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17281: push(@{$changes{'lonstatus'}},$key);
17282: }
17283: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17284: (@{$currsetting{'lonstatus'}{$key}})) {
17285: push(@{$changes{'lonstatus'}},$key);
17286: }
17287: } elsif ($key eq 'weights') {
17288: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17289: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17290: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17291: foreach my $type ('E','W','N','U') {
1.340 raeburn 17292: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17293: $currsetting{'lonstatus'}{$key}{$type}) {
17294: push(@{$changes{'lonstatus'}},$key);
17295: last;
17296: }
17297: }
17298: } else {
1.341 raeburn 17299: foreach my $type ('E','W','N','U') {
1.340 raeburn 17300: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17301: push(@{$changes{'lonstatus'}},$key);
17302: last;
17303: }
17304: }
17305: }
17306: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17307: foreach my $type ('E','W','N','U') {
1.340 raeburn 17308: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17309: push(@{$changes{'lonstatus'}},$key);
17310: last;
17311: }
17312: }
17313: }
17314: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17315: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17316: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17317: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17318: push(@{$changes{'lonstatus'}},$key);
17319: }
17320: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17321: push(@{$changes{'lonstatus'}},$key);
17322: }
17323: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17324: push(@{$changes{'lonstatus'}},$key);
17325: }
17326: }
17327: }
17328: } else {
17329: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17330: foreach my $key ('excluded','weights','threshold','sysmail') {
17331: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17332: push(@{$changes{'lonstatus'}},$key);
17333: }
17334: }
17335: }
17336: }
1.28 raeburn 17337: } else {
17338: my %default;
17339: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17340: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17341: $default{'errormail'} = 'adminemail';
17342: $default{'packagesmail'} = 'adminemail';
17343: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17344: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17345: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17346: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17347: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17348: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17349: foreach my $item (@contacts) {
17350: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17351: $changes{$item} = 1;
1.203 raeburn 17352: }
1.28 raeburn 17353: }
17354: foreach my $type (@mailings) {
17355: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17356: push(@{$changes{$type}},@{$newsetting{$type}});
17357: }
17358: if ($others{$type} ne '') {
17359: push(@{$changes{$type}},'others');
1.134 raeburn 17360: }
1.286 raeburn 17361: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17362: if ($bcc{$type} ne '') {
17363: push(@{$changes{$type}},'bcc');
17364: }
1.286 raeburn 17365: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17366: push(@{$changes{$type}},'include');
17367: }
1.134 raeburn 17368: }
1.28 raeburn 17369: }
1.286 raeburn 17370: if (ref($fields) eq 'ARRAY') {
17371: foreach my $field (@{$fields}) {
17372: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17373: push(@{$changes{'helpform'}},$field);
17374: }
17375: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17376: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17377: push(@{$changes{'helpform'}},'maxsize');
17378: }
17379: }
17380: }
1.289 raeburn 17381: }
1.340 raeburn 17382: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17383: foreach my $key ('excluded','weights','threshold','sysmail') {
17384: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17385: push(@{$changes{'lonstatus'}},$key);
17386: }
17387: }
17388: }
1.28 raeburn 17389: }
1.203 raeburn 17390: foreach my $item (@toggles) {
17391: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17392: $changes{$item} = 1;
17393: } elsif ((!$env{'form.'.$item}) &&
17394: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17395: $changes{$item} = 1;
17396: }
17397: }
1.28 raeburn 17398: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17399: $dom);
17400: if ($putresult eq 'ok') {
17401: if (keys(%changes) > 0) {
1.205 raeburn 17402: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17403: if (ref($lastactref) eq 'HASH') {
17404: $lastactref->{'domainconfig'} = 1;
17405: }
1.28 raeburn 17406: my ($titles,$short_titles) = &contact_titles();
17407: $resulttext = &mt('Changes made:').'<ul>';
17408: foreach my $item (@contacts) {
17409: if ($changes{$item}) {
17410: $resulttext .= '<li>'.$titles->{$item}.
17411: &mt(' set to: ').
17412: '<span class="LC_cusr_emph">'.
17413: $to{$item}.'</span></li>';
17414: }
17415: }
17416: foreach my $type (@mailings) {
17417: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17418: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17419: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17420: } else {
17421: $resulttext .= '<li>'.$titles->{$type}.': ';
17422: }
1.28 raeburn 17423: my @text;
17424: foreach my $item (@{$newsetting{$type}}) {
17425: push(@text,$short_titles->{$item});
17426: }
17427: if ($others{$type} ne '') {
17428: push(@text,$others{$type});
17429: }
1.286 raeburn 17430: if (@text) {
17431: $resulttext .= '<span class="LC_cusr_emph">'.
17432: join(', ',@text).'</span>';
17433: }
17434: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17435: if ($bcc{$type} ne '') {
1.286 raeburn 17436: my $bcctext;
17437: if (@text) {
1.289 raeburn 17438: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17439: } else {
17440: $bcctext = '(Bcc)';
17441: }
17442: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17443: } elsif (!@text) {
17444: $resulttext .= &mt('No one');
1.425 raeburn 17445: }
1.289 raeburn 17446: if ($includestr{$type} ne '') {
1.286 raeburn 17447: if ($includeloc{$type} eq 'b') {
17448: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17449: } elsif ($includeloc{$type} eq 's') {
17450: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17451: }
1.134 raeburn 17452: }
1.286 raeburn 17453: } elsif (!@text) {
17454: $resulttext .= &mt('No recipients');
1.134 raeburn 17455: }
17456: $resulttext .= '</li>';
1.28 raeburn 17457: }
17458: }
1.315 raeburn 17459: if (ref($changes{'overrides'}) eq 'ARRAY') {
17460: my @deletions;
17461: foreach my $type (@{$changes{'overrides'}}) {
17462: if ($usertypeshash{$type}) {
17463: if (grep(/^\Q$type\E/,@overrides)) {
17464: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17465: $usertypeshash{$type}).'<ul><li>';
17466: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17467: my @text;
17468: foreach my $item (@contacts) {
1.425 raeburn 17469: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17470: push(@text,$short_titles->{$item});
17471: }
17472: }
17473: if ($newsetting{'override_'.$type}{'others'} ne '') {
17474: push(@text,$newsetting{'override_'.$type}{'others'});
17475: }
1.425 raeburn 17476:
1.315 raeburn 17477: if (@text) {
17478: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17479: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17480: }
17481: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17482: my $bcctext;
17483: if (@text) {
17484: $bcctext = ' '.&mt('with Bcc to');
17485: } else {
17486: $bcctext = '(Bcc)';
17487: }
17488: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17489: } elsif (!@text) {
17490: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17491: }
17492: $resulttext .= '</li>';
17493: if ($newsetting{'override_'.$type}{'include'} ne '') {
17494: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17495: if ($loc eq 'b') {
17496: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17497: } elsif ($loc eq 's') {
17498: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17499: }
17500: }
17501: }
17502: $resulttext .= '</li></ul></li>';
17503: } else {
17504: push(@deletions,$usertypeshash{$type});
17505: }
17506: }
17507: }
17508: if (@deletions) {
17509: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17510: join(', ',@deletions)).'</li>';
17511: }
17512: }
1.203 raeburn 17513: my @offon = ('off','on');
1.340 raeburn 17514: my $corelink = &core_link_msu();
1.203 raeburn 17515: if ($changes{'reporterrors'}) {
17516: $resulttext .= '<li>'.
17517: &mt('E-mail error reports to [_1] set to "'.
17518: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17519: $corelink).
1.203 raeburn 17520: '</li>';
17521: }
17522: if ($changes{'reportupdates'}) {
17523: $resulttext .= '<li>'.
17524: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17525: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17526: $corelink).
1.203 raeburn 17527: '</li>';
17528: }
1.340 raeburn 17529: if ($changes{'reportstatus'}) {
17530: $resulttext .= '<li>'.
17531: &mt('E-mail status if errors above threshold to [_1] set to "'.
17532: $offon[$env{'form.reportstatus'}].'".',
17533: $corelink).
17534: '</li>';
17535: }
17536: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17537: $resulttext .= '<li>'.
17538: &mt('Nightly status check e-mail settings').':<ul>';
17539: my (%defval,%use_def,%shown);
17540: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17541: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17542: $defval{'weights'} =
1.341 raeburn 17543: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17544: $defval{'excluded'} = &mt('None');
17545: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17546: foreach my $item ('threshold','sysmail','weights','excluded') {
17547: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17548: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17549: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17550: } elsif ($item eq 'weights') {
17551: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17552: foreach my $type ('E','W','N','U') {
1.340 raeburn 17553: $shown{$item} .= $lonstatus_names->{$type}.'=';
17554: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17555: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17556: } else {
17557: $shown{$item} .= $lonstatus_defs->{$type};
17558: }
17559: $shown{$item} .= ', ';
17560: }
17561: $shown{$item} =~ s/, $//;
17562: } else {
17563: $shown{$item} = $defval{$item};
17564: }
17565: } elsif ($item eq 'excluded') {
17566: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17567: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17568: } else {
17569: $shown{$item} = $defval{$item};
17570: }
17571: }
17572: } else {
17573: $shown{$item} = $defval{$item};
17574: }
17575: }
17576: } else {
17577: foreach my $item ('threshold','weights','excluded','sysmail') {
17578: $shown{$item} = $defval{$item};
17579: }
17580: }
17581: foreach my $item ('threshold','weights','excluded','sysmail') {
17582: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17583: $shown{$item}).'</li>';
17584: }
17585: $resulttext .= '</ul></li>';
17586: }
1.286 raeburn 17587: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17588: my (@optional,@required,@unused,$maxsizechg);
17589: foreach my $field (@{$changes{'helpform'}}) {
17590: if ($field eq 'maxsize') {
17591: $maxsizechg = 1;
17592: next;
17593: }
17594: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17595: push(@optional,$field);
1.286 raeburn 17596: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17597: push(@unused,$field);
17598: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17599: push(@required,$field);
1.286 raeburn 17600: }
17601: }
17602: if (@optional) {
17603: $resulttext .= '<li>'.
17604: &mt('Help form fields changed to "Optional": [_1].',
17605: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17606: '</li>';
17607: }
17608: if (@required) {
17609: $resulttext .= '<li>'.
17610: &mt('Help form fields changed to "Required": [_1].',
17611: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17612: '</li>';
17613: }
17614: if (@unused) {
17615: $resulttext .= '<li>'.
17616: &mt('Help form fields changed to "Not shown": [_1].',
17617: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17618: '</li>';
17619: }
17620: if ($maxsizechg) {
17621: $resulttext .= '<li>'.
17622: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17623: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17624: '</li>';
17625: }
17626: }
1.28 raeburn 17627: $resulttext .= '</ul>';
17628: } else {
1.288 raeburn 17629: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17630: }
17631: } else {
17632: $resulttext = '<span class="LC_error">'.
17633: &mt('An error occurred: [_1].',$putresult).'</span>';
17634: }
17635: return $resulttext;
17636: }
17637:
1.357 raeburn 17638: sub modify_privacy {
1.427 raeburn 17639: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17640: my ($resulttext,%current,%changes);
17641: if (ref($domconfig{'privacy'}) eq 'HASH') {
17642: %current = %{$domconfig{'privacy'}};
17643: }
17644: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17645: my @items = ('domain','author','course','community');
17646: my %names = &Apache::lonlocal::texthash (
17647: domain => 'Assigned domain role(s)',
17648: author => 'Assigned co-author role(s)',
17649: course => 'Assigned course role(s)',
1.416 raeburn 17650: community => 'Assigned community role(s)',
1.357 raeburn 17651: );
17652: my %roles = &Apache::lonlocal::texthash (
17653: domain => 'Domain role',
17654: author => 'Co-author role',
17655: course => 'Course role',
17656: community => 'Community role',
17657: );
17658: my %titles = &Apache::lonlocal::texthash (
17659: approval => 'Approval for role in different domain',
17660: othdom => 'User information available in other domain',
17661: priv => 'Information viewable by privileged user in same domain',
17662: unpriv => 'Information viewable by unprivileged user in same domain',
17663: instdom => 'Other domain shares institution/provider',
17664: extdom => 'Other domain has different institution/provider',
17665: none => 'Not allowed',
17666: user => 'User authorizes',
17667: domain => 'Domain Coordinator authorizes',
17668: auto => 'Unrestricted',
1.418 raeburn 17669: notify => 'Notify when role needs authorization',
1.357 raeburn 17670: );
17671: my %fieldnames = &Apache::lonlocal::texthash (
17672: id => 'Student/Employee ID',
17673: permanentemail => 'E-mail address',
17674: lastname => 'Last Name',
17675: firstname => 'First Name',
17676: middlename => 'Middle Name',
17677: generation => 'Generation',
17678: );
17679: my ($othertitle,$usertypes,$types) =
17680: &Apache::loncommon::sorted_inst_types($dom);
17681: my (%by_ip,%by_location,@intdoms,@instdoms);
17682: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17683:
17684: my %privacyhash = (
17685: 'approval' => {
17686: instdom => {},
17687: extdom => {},
17688: },
17689: 'othdom' => {},
17690: 'priv' => {},
17691: 'unpriv' => {},
17692: );
17693: foreach my $item (@items) {
17694: if (@instdoms > 1) {
1.416 raeburn 17695: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17696: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17697: }
17698: if (ref($current{'approval'}) eq 'HASH') {
17699: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17700: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17701: $changes{'approval'} = 1;
17702: }
17703: }
17704: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17705: $changes{'approval'} = 1;
17706: }
17707: }
17708: if (keys(%by_location) > 0) {
17709: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17710: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17711: }
17712: if (ref($current{'approval'}) eq 'HASH') {
17713: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17714: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17715: $changes{'approval'} = 1;
17716: }
17717: }
17718: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17719: $changes{'approval'} = 1;
17720: }
17721: }
17722: foreach my $status ('priv','unpriv') {
17723: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17724: my @newvalues;
17725: foreach my $field (@possibles) {
17726: if (grep(/^\Q$field\E$/,@fields)) {
17727: $privacyhash{$status}{$item}{$field} = 1;
17728: push(@newvalues,$field);
17729: }
17730: }
17731: @newvalues = sort(@newvalues);
17732: if (ref($current{$status}) eq 'HASH') {
17733: if (ref($current{$status}{$item}) eq 'HASH') {
17734: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17735: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17736: if (@diffs > 0) {
17737: $changes{$status} = 1;
17738: }
17739: }
17740: } else {
17741: my @stdfields;
17742: foreach my $field (@fields) {
17743: if ($field eq 'id') {
17744: next if ($status eq 'unpriv');
17745: next if (($status eq 'priv') && ($item eq 'community'));
17746: }
17747: push(@stdfields,$field);
17748: }
17749: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17750: if (@diffs > 0) {
17751: $changes{$status} = 1;
17752: }
17753: }
17754: }
17755: }
17756: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17757: my @statuses;
17758: if (ref($types) eq 'ARRAY') {
17759: @statuses = @{$types};
17760: }
17761: foreach my $type (@statuses,'default') {
17762: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17763: my @newvalues;
17764: foreach my $field (sort(@possfields)) {
17765: if (grep(/^\Q$field\E$/,@fields)) {
17766: $privacyhash{'othdom'}{$type}{$field} = 1;
17767: push(@newvalues,$field);
17768: }
17769: }
17770: @newvalues = sort(@newvalues);
17771: if (ref($current{'othdom'}) eq 'HASH') {
17772: if (ref($current{'othdom'}{$type}) eq 'HASH') {
17773: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
17774: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17775: if (@diffs > 0) {
17776: $changes{'othdom'} = 1;
17777: }
17778: }
17779: } else {
17780: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
17781: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17782: if (@diffs > 0) {
17783: $changes{'othdom'} = 1;
17784: }
17785: }
17786: }
1.417 raeburn 17787: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
17788: my %notify;
17789: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
17790: if (exists($domcoords{$possdc})) {
17791: $notify{$possdc} = 1;
17792: }
17793: }
17794: my $notify = join(',',sort(keys(%notify)));
17795: if ($current{'notify'} ne $notify) {
17796: $changes{'notify'} = 1;
17797: }
17798: $privacyhash{'notify'} = $notify;
1.357 raeburn 17799: }
17800: my %confighash = (
17801: privacy => \%privacyhash,
17802: );
17803: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17804: if ($putresult eq 'ok') {
17805: if (keys(%changes) > 0) {
17806: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 17807: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 17808: if ($changes{$key}) {
17809: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17810: if ($key eq 'approval') {
17811: if (keys(%{$privacyhash{$key}{instdom}})) {
17812: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
17813: foreach my $item (@items) {
17814: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
17815: }
17816: $resulttext .= '</ul></li>';
17817: }
17818: if (keys(%{$privacyhash{$key}{extdom}})) {
17819: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
17820: foreach my $item (@items) {
17821: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
17822: }
17823: $resulttext .= '</ul></li>';
17824: }
1.417 raeburn 17825: } elsif ($key eq 'notify') {
17826: if ($privacyhash{$key}) {
17827: foreach my $dc (split(/,/,$privacyhash{$key})) {
17828: my ($dcname,$dcdom) = split(/:/,$dc);
17829: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
17830: }
17831: } else {
17832: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
17833: }
1.357 raeburn 17834: } elsif ($key eq 'othdom') {
17835: my @statuses;
17836: if (ref($types) eq 'ARRAY') {
17837: @statuses = @{$types};
17838: }
17839: if (ref($privacyhash{$key}) eq 'HASH') {
17840: foreach my $status (@statuses,'default') {
17841: if ($status eq 'default') {
17842: $resulttext .= '<li>'.$othertitle.': ';
17843: } elsif (ref($usertypes) eq 'HASH') {
17844: $resulttext .= '<li>'.$usertypes->{$status}.': ';
17845: } else {
17846: next;
17847: }
17848: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
17849: if (keys(%{$privacyhash{$key}{$status}})) {
17850: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
17851: } else {
17852: $resulttext .= &mt('none');
17853: }
17854: }
17855: $resulttext .= '</li>';
17856: }
17857: }
17858: } else {
17859: foreach my $item (@items) {
17860: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
17861: $resulttext .= '<li>'.$names{$item}.': ';
17862: if (keys(%{$privacyhash{$key}{$item}})) {
17863: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
17864: } else {
17865: $resulttext .= &mt('none');
17866: }
17867: $resulttext .= '</li>';
17868: }
17869: }
17870: }
17871: $resulttext .= '</ul></li>';
17872: }
17873: }
1.421 raeburn 17874: $resulttext .= '</ul>';
1.427 raeburn 17875: if ($changes{'approval'}) {
17876: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
17877: delete($domdefaults{'userapprovals'});
17878: if (ref($privacyhash{'approval'}) eq 'HASH') {
17879: foreach my $domtype ('instdom','extdom') {
17880: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
17881: foreach my $roletype ('domain','author','course','community') {
17882: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
17883: $domdefaults{'userapprovals'} = 1;
17884: last;
17885: }
17886: }
17887: }
17888: last if ($domdefaults{'userapprovals'});
17889: }
17890: }
17891: my $cachetime = 24*60*60;
17892: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17893: if (ref($lastactref) eq 'HASH') {
17894: $lastactref->{'domdefaults'} = 1;
17895: }
17896: }
1.357 raeburn 17897: } else {
17898: $resulttext = &mt('No changes made to user information settings');
17899: }
17900: } else {
17901: $resulttext = '<span class="LC_error">'.
17902: &mt('An error occurred: [_1]',$putresult).'</span>';
17903: }
17904: return $resulttext;
17905: }
17906:
1.354 raeburn 17907: sub modify_passwords {
17908: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 17909: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
17910: $updatedefaults,$updateconf);
1.354 raeburn 17911: my $customfn = 'resetpw.html';
17912: if (ref($domconfig{'passwords'}) eq 'HASH') {
17913: %current = %{$domconfig{'passwords'}};
17914: }
17915: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17916: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17917: if (ref($types) eq 'ARRAY') {
17918: @oktypes = @{$types};
17919: }
17920: push(@oktypes,'default');
17921:
17922: my %titles = &Apache::lonlocal::texthash (
17923: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
17924: intauth_check => 'Check bcrypt cost if authenticated',
17925: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
17926: permanent => 'Permanent e-mail address',
17927: critical => 'Critical notification address',
17928: notify => 'Notification address',
17929: min => 'Minimum password length',
17930: max => 'Maximum password length',
17931: chars => 'Required characters',
17932: expire => 'Password expiration (days)',
1.356 raeburn 17933: numsaved => 'Number of previous passwords to save',
1.354 raeburn 17934: reset => 'Resetting Forgotten Password',
17935: intauth => 'Encryption of Stored Passwords (Internal Auth)',
17936: rules => 'Rules for LON-CAPA Passwords',
17937: crsownerchg => 'Course Owner Changing Student Passwords',
17938: username => 'Username',
17939: email => 'E-mail address',
17940: );
17941:
17942: #
17943: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
17944: #
17945: my (%curr_defaults,%save_defaults);
17946: if (ref($domconfig{'defaults'}) eq 'HASH') {
17947: foreach my $key (keys(%{$domconfig{'defaults'}})) {
17948: if ($key =~ /^intauth_(cost|check|switch)$/) {
17949: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
17950: } else {
17951: $save_defaults{$key} = $domconfig{'defaults'}{$key};
17952: }
17953: }
17954: }
17955: my %staticdefaults = (
17956: 'resetlink' => 2,
17957: 'resetcase' => \@oktypes,
17958: 'resetprelink' => 'both',
17959: 'resetemail' => ['critical','notify','permanent'],
17960: 'intauth_cost' => 10,
17961: 'intauth_check' => 0,
17962: 'intauth_switch' => 0,
17963: );
1.365 raeburn 17964: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 17965: foreach my $type (@oktypes) {
17966: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
17967: }
17968: my $linklife = $env{'form.passwords_link'};
17969: $linklife =~ s/^\s+|\s+$//g;
17970: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
17971: $newvalues{'resetlink'} = $linklife;
17972: if ($current{'resetlink'}) {
17973: if ($current{'resetlink'} ne $linklife) {
17974: $changes{'reset'} = 1;
17975: }
1.368 raeburn 17976: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17977: if ($staticdefaults{'resetlink'} ne $linklife) {
17978: $changes{'reset'} = 1;
17979: }
17980: }
17981: } elsif ($current{'resetlink'}) {
17982: $changes{'reset'} = 1;
17983: }
17984: my @casesens;
17985: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
17986: foreach my $case (sort(@posscase)) {
17987: if (grep(/^\Q$case\E$/,@oktypes)) {
17988: push(@casesens,$case);
17989: }
17990: }
17991: $newvalues{'resetcase'} = \@casesens;
17992: if (ref($current{'resetcase'}) eq 'ARRAY') {
17993: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
17994: if (@diffs > 0) {
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{'resetcase'},\@casesens);
17999: if (@diffs > 0) {
18000: $changes{'reset'} = 1;
18001: }
18002: }
18003: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18004: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18005: if (exists($current{'resetprelink'})) {
18006: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18007: $changes{'reset'} = 1;
18008: }
1.368 raeburn 18009: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18010: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18011: $changes{'reset'} = 1;
18012: }
18013: }
18014: } elsif ($current{'resetprelink'}) {
18015: $changes{'reset'} = 1;
18016: }
18017: foreach my $type (@oktypes) {
18018: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18019: my @postlink;
18020: foreach my $item (sort(@possplink)) {
18021: if ($item =~ /^(email|username)$/) {
18022: push(@postlink,$item);
18023: }
18024: }
18025: $newvalues{'resetpostlink'}{$type} = \@postlink;
18026: unless ($changes{'reset'}) {
18027: if (ref($current{'resetpostlink'}) eq 'HASH') {
18028: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18029: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18030: if (@diffs > 0) {
18031: $changes{'reset'} = 1;
18032: }
18033: } else {
18034: $changes{'reset'} = 1;
18035: }
1.368 raeburn 18036: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18037: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18038: if (@diffs > 0) {
18039: $changes{'reset'} = 1;
18040: }
18041: }
18042: }
18043: }
18044: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18045: my @resetemail;
18046: foreach my $item (sort(@possemailsrc)) {
18047: if ($item =~ /^(permanent|critical|notify)$/) {
18048: push(@resetemail,$item);
18049: }
18050: }
18051: $newvalues{'resetemail'} = \@resetemail;
18052: unless ($changes{'reset'}) {
18053: if (ref($current{'resetemail'}) eq 'ARRAY') {
18054: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18055: if (@diffs > 0) {
18056: $changes{'reset'} = 1;
18057: }
1.368 raeburn 18058: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18059: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18060: if (@diffs > 0) {
18061: $changes{'reset'} = 1;
18062: }
18063: }
18064: }
18065: if ($env{'form.passwords_stdtext'} == 0) {
18066: $newvalues{'resetremove'} = 1;
18067: unless ($current{'resetremove'}) {
18068: $changes{'reset'} = 1;
18069: }
18070: } elsif ($current{'resetremove'}) {
18071: $changes{'reset'} = 1;
18072: }
18073: if ($env{'form.passwords_customfile.filename'} ne '') {
18074: my $servadm = $r->dir_config('lonAdmEMail');
18075: my ($configuserok,$author_ok,$switchserver) =
18076: &config_check($dom,$confname,$servadm);
18077: my $error;
18078: if ($configuserok eq 'ok') {
18079: if ($switchserver) {
18080: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18081: } else {
18082: if ($author_ok eq 'ok') {
1.421 raeburn 18083: my $modified = [];
1.354 raeburn 18084: my ($result,$customurl) =
1.421 raeburn 18085: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18086: $confname,'customtext/resetpw','','',$customfn,
18087: $modified);
1.354 raeburn 18088: if ($result eq 'ok') {
18089: $newvalues{'resetcustom'} = $customurl;
18090: $changes{'reset'} = 1;
1.421 raeburn 18091: &update_modify_urls($r,$modified);
1.354 raeburn 18092: } else {
18093: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18094: }
18095: } else {
18096: $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);
18097: }
18098: }
18099: } else {
18100: $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);
18101: }
18102: if ($error) {
18103: &Apache::lonnet::logthis($error);
18104: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18105: }
18106: } elsif ($current{'resetcustom'}) {
18107: if ($env{'form.passwords_custom_del'}) {
18108: $changes{'reset'} = 1;
18109: } else {
18110: $newvalues{'resetcustom'} = $current{'resetcustom'};
18111: }
18112: }
18113: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18114: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18115: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18116: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18117: $changes{'intauth'} = 1;
18118: }
18119: } else {
18120: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18121: }
18122: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18123: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18124: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18125: $changes{'intauth'} = 1;
18126: }
18127: } else {
18128: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18129: }
18130: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18131: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18132: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18133: $changes{'intauth'} = 1;
18134: }
18135: } else {
18136: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18137: }
18138: foreach my $item ('cost','check','switch') {
18139: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18140: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18141: $updatedefaults = 1;
18142: }
18143: }
1.405 raeburn 18144: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18145: my %crsownerchg = (
18146: by => [],
18147: for => [],
18148: );
18149: foreach my $item ('by','for') {
18150: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18151: foreach my $type (sort(@posstypes)) {
18152: if (grep(/^\Q$type\E$/,@oktypes)) {
18153: push(@{$crsownerchg{$item}},$type);
18154: }
18155: }
18156: }
18157: $newvalues{'crsownerchg'} = \%crsownerchg;
18158: if (ref($current{'crsownerchg'}) eq 'HASH') {
18159: foreach my $item ('by','for') {
18160: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18161: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18162: if (@diffs > 0) {
18163: $changes{'crsownerchg'} = 1;
18164: last;
18165: }
18166: }
18167: }
1.368 raeburn 18168: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18169: foreach my $item ('by','for') {
18170: if (@{$crsownerchg{$item}} > 0) {
18171: $changes{'crsownerchg'} = 1;
18172: last;
18173: }
1.354 raeburn 18174: }
18175: }
18176:
18177: my %confighash = (
18178: defaults => \%save_defaults,
18179: passwords => \%newvalues,
18180: );
18181: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18182:
18183: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18184: if ($putresult eq 'ok') {
18185: if (keys(%changes) > 0) {
18186: $resulttext = &mt('Changes made: ').'<ul>';
18187: foreach my $key ('reset','intauth','rules','crsownerchg') {
18188: if ($changes{$key}) {
1.355 raeburn 18189: unless ($key eq 'intauth') {
18190: $updateconf = 1;
18191: }
1.354 raeburn 18192: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18193: if ($key eq 'reset') {
18194: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18195: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18196: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18197: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18198: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18199: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18200: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18201: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18202: }
1.354 raeburn 18203: } else {
18204: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18205: }
18206: if ($confighash{'passwords'}{'resetlink'}) {
18207: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18208: } else {
18209: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18210: &mt('Will default to 2 hours').'</li>';
18211: }
18212: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18213: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18214: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18215: } else {
18216: my $casesens;
18217: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18218: if ($type eq 'default') {
18219: $casesens .= $othertitle.', ';
18220: } elsif ($usertypes->{$type} ne '') {
18221: $casesens .= $usertypes->{$type}.', ';
18222: }
18223: }
18224: $casesens =~ s/\Q, \E$//;
18225: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18226: }
18227: } else {
18228: $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>';
18229: }
18230: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18231: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18232: } else {
18233: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18234: }
18235: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18236: my $output;
18237: if (ref($types) eq 'ARRAY') {
18238: foreach my $type (@{$types}) {
18239: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18240: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18241: $output .= $usertypes->{$type}.' -- '.&mt('none');
18242: } else {
18243: $output .= $usertypes->{$type}.' -- '.
18244: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18245: }
18246: }
18247: }
18248: }
18249: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18250: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18251: $output .= $othertitle.' -- '.&mt('none');
18252: } else {
18253: $output .= $othertitle.' -- '.
18254: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18255: }
18256: }
18257: if ($output) {
18258: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18259: } else {
18260: $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>';
18261: }
18262: } else {
18263: $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>';
18264: }
18265: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18266: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18267: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18268: } else {
18269: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18270: }
18271: } else {
1.379 raeburn 18272: $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 18273: }
18274: if ($confighash{'passwords'}{'resetremove'}) {
18275: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18276: } else {
18277: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18278: }
18279: if ($confighash{'passwords'}{'resetcustom'}) {
18280: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18281: &mt('custom text'),600,500,undef,undef,
18282: undef,undef,'background-color:#ffffff');
18283: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18284: } else {
18285: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18286: }
18287: } elsif ($key eq 'intauth') {
18288: foreach my $item ('cost','switch','check') {
18289: my $value = $save_defaults{$key.'_'.$item};
18290: if ($item eq 'switch') {
18291: my %optiondesc = &Apache::lonlocal::texthash (
18292: 0 => 'No',
18293: 1 => 'Yes',
18294: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18295: );
18296: if ($value =~ /^(0|1|2)$/) {
18297: $value = $optiondesc{$value};
18298: } else {
18299: $value = &mt('none -- defaults to No');
18300: }
18301: } elsif ($item eq 'check') {
18302: my %optiondesc = &Apache::lonlocal::texthash (
18303: 0 => 'No',
18304: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18305: 2 => 'Yes, disallow login if stored cost is less than domain default',
18306: );
18307: if ($value =~ /^(0|1|2)$/) {
18308: $value = $optiondesc{$value};
18309: } else {
18310: $value = &mt('none -- defaults to No');
18311: }
18312: }
18313: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18314: }
18315: } elsif ($key eq 'rules') {
1.356 raeburn 18316: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18317: if ($confighash{'passwords'}{$rule} eq '') {
18318: if ($rule eq 'min') {
1.356 raeburn 18319: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18320: ' '.&mt('Default of [_1] will be used',
18321: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18322: } else {
18323: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18324: }
18325: } else {
18326: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18327: }
18328: }
1.370 raeburn 18329: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18330: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18331: my %rulenames = &Apache::lonlocal::texthash(
18332: uc => 'At least one upper case letter',
18333: lc => 'At least one lower case letter',
18334: num => 'At least one number',
18335: spec => 'At least one non-alphanumeric',
18336: );
18337: my $needed = '<ul><li>'.
18338: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18339: '</li></ul>';
1.370 raeburn 18340: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18341: } else {
18342: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18343: }
18344: } else {
18345: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18346: }
1.354 raeburn 18347: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18348: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18349: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18350: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18351: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18352: } else {
18353: my %crsownerstr;
18354: foreach my $item ('by','for') {
18355: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18356: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18357: if ($type eq 'default') {
18358: $crsownerstr{$item} .= $othertitle.', ';
18359: } elsif ($usertypes->{$type} ne '') {
18360: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18361: }
18362: }
18363: $crsownerstr{$item} =~ s/\Q, \E$//;
18364: }
18365: }
18366: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18367: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18368: }
1.354 raeburn 18369: } else {
1.359 raeburn 18370: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18371: }
18372: }
18373: $resulttext .= '</ul></li>';
18374: }
18375: }
18376: $resulttext .= '</ul>';
18377: } else {
18378: $resulttext = &mt('No changes made to password settings');
18379: }
1.355 raeburn 18380: my $cachetime = 24*60*60;
1.354 raeburn 18381: if ($updatedefaults) {
18382: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18383: if (ref($lastactref) eq 'HASH') {
18384: $lastactref->{'domdefaults'} = 1;
18385: }
18386: }
1.355 raeburn 18387: if ($updateconf) {
18388: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18389: if (ref($lastactref) eq 'HASH') {
18390: $lastactref->{'passwdconf'} = 1;
18391: }
18392: }
1.354 raeburn 18393: } else {
18394: $resulttext = '<span class="LC_error">'.
18395: &mt('An error occurred: [_1]',$putresult).'</span>';
18396: }
18397: if ($errors) {
18398: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18399: $errors.'</ul></p>';
18400: }
18401: return $resulttext;
18402: }
18403:
1.405 raeburn 18404: sub password_rule_changes {
18405: my ($prefix,$newvalues,$current,$changes) = @_;
18406: return unless ((ref($newvalues) eq 'HASH') &&
18407: (ref($current) eq 'HASH') &&
18408: (ref($changes) eq 'HASH'));
18409: my (@rules,%staticdefaults);
18410: if ($prefix eq 'passwords') {
18411: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18412: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18413: @rules = ('min','max');
18414: }
18415: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18416: foreach my $rule (@rules) {
18417: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18418: my $ruleok;
18419: if ($rule eq 'expire') {
18420: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18421: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18422: $ruleok = 1;
18423: }
18424: } elsif ($rule eq 'min') {
18425: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18426: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18427: $ruleok = 1;
18428: }
18429: }
18430: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18431: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18432: $ruleok = 1;
18433: }
18434: if ($ruleok) {
18435: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18436: if (exists($current->{$rule})) {
18437: if ($newvalues->{$rule} ne $current->{$rule}) {
18438: $changes->{'rules'} = 1;
18439: }
18440: } elsif ($rule eq 'min') {
18441: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18442: $changes->{'rules'} = 1;
18443: }
18444: } else {
18445: $changes->{'rules'} = 1;
18446: }
18447: } elsif (exists($current->{$rule})) {
18448: $changes->{'rules'} = 1;
18449: }
18450: }
18451: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18452: my @chars;
18453: foreach my $item (sort(@posschars)) {
18454: if ($item =~ /^(uc|lc|num|spec)$/) {
18455: push(@chars,$item);
18456: }
18457: }
18458: $newvalues->{'chars'} = \@chars;
18459: unless ($changes->{'rules'}) {
18460: if (ref($current->{'chars'}) eq 'ARRAY') {
18461: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18462: if (@diffs > 0) {
18463: $changes->{'rules'} = 1;
18464: }
18465: } else {
18466: if (@chars > 0) {
18467: $changes->{'rules'} = 1;
18468: }
18469: }
18470: }
18471: return;
18472: }
18473:
1.28 raeburn 18474: sub modify_usercreation {
1.27 raeburn 18475: my ($dom,%domconfig) = @_;
1.224 raeburn 18476: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18477: my $warningmsg;
1.27 raeburn 18478: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18479: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18480: if ($key eq 'cancreate') {
18481: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18482: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18483: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18484: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18485: } else {
1.224 raeburn 18486: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18487: }
18488: }
18489: }
18490: } elsif ($key eq 'email_rule') {
18491: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18492: } else {
18493: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18494: }
1.27 raeburn 18495: }
18496: }
18497: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18498: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18499: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18500: foreach my $item(@contexts) {
1.224 raeburn 18501: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18502: }
1.34 raeburn 18503: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18504: foreach my $item (@contexts) {
1.224 raeburn 18505: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18506: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18507: }
1.27 raeburn 18508: }
1.34 raeburn 18509: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18510: foreach my $item (@contexts) {
1.43 raeburn 18511: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18512: if ($cancreate{$item} ne 'any') {
18513: push(@{$changes{'cancreate'}},$item);
18514: }
18515: } else {
18516: if ($cancreate{$item} ne 'none') {
18517: push(@{$changes{'cancreate'}},$item);
18518: }
1.27 raeburn 18519: }
18520: }
18521: } else {
1.43 raeburn 18522: foreach my $item (@contexts) {
1.34 raeburn 18523: push(@{$changes{'cancreate'}},$item);
18524: }
1.27 raeburn 18525: }
1.34 raeburn 18526:
1.27 raeburn 18527: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18528: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18529: if (!grep(/^\Q$type\E$/,@username_rule)) {
18530: push(@{$changes{'username_rule'}},$type);
18531: }
18532: }
18533: foreach my $type (@username_rule) {
18534: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18535: push(@{$changes{'username_rule'}},$type);
18536: }
18537: }
18538: } else {
18539: push(@{$changes{'username_rule'}},@username_rule);
18540: }
18541:
1.32 raeburn 18542: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18543: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18544: if (!grep(/^\Q$type\E$/,@id_rule)) {
18545: push(@{$changes{'id_rule'}},$type);
18546: }
18547: }
18548: foreach my $type (@id_rule) {
18549: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18550: push(@{$changes{'id_rule'}},$type);
18551: }
18552: }
18553: } else {
18554: push(@{$changes{'id_rule'}},@id_rule);
18555: }
18556:
1.43 raeburn 18557: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18558: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18559: my %authhash;
1.43 raeburn 18560: foreach my $item (@authen_contexts) {
1.28 raeburn 18561: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18562: foreach my $auth (@authtypes) {
18563: if (grep(/^\Q$auth\E$/,@authallowed)) {
18564: $authhash{$item}{$auth} = 1;
18565: } else {
18566: $authhash{$item}{$auth} = 0;
18567: }
18568: }
18569: }
18570: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18571: foreach my $item (@authen_contexts) {
1.28 raeburn 18572: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18573: foreach my $auth (@authtypes) {
18574: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18575: push(@{$changes{'authtypes'}},$item);
18576: last;
18577: }
18578: }
18579: }
18580: }
18581: } else {
1.43 raeburn 18582: foreach my $item (@authen_contexts) {
1.28 raeburn 18583: push(@{$changes{'authtypes'}},$item);
18584: }
18585: }
18586:
1.224 raeburn 18587: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18588: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18589: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18590: $save_usercreate{'id_rule'} = \@id_rule;
18591: $save_usercreate{'username_rule'} = \@username_rule,
18592: $save_usercreate{'authtypes'} = \%authhash;
18593:
1.27 raeburn 18594: my %usercreation_hash = (
1.224 raeburn 18595: usercreation => \%save_usercreate,
18596: );
1.27 raeburn 18597:
18598: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18599: $dom);
1.50 raeburn 18600:
1.224 raeburn 18601: if ($putresult eq 'ok') {
18602: if (keys(%changes) > 0) {
18603: $resulttext = &mt('Changes made:').'<ul>';
18604: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18605: my %lt = &usercreation_types();
18606: foreach my $type (@{$changes{'cancreate'}}) {
18607: my $chgtext = $lt{$type}.', ';
18608: if ($cancreate{$type} eq 'none') {
18609: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18610: } elsif ($cancreate{$type} eq 'any') {
18611: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18612: } elsif ($cancreate{$type} eq 'official') {
18613: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18614: } elsif ($cancreate{$type} eq 'unofficial') {
18615: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18616: }
18617: $resulttext .= '<li>'.$chgtext.'</li>';
18618: }
18619: }
18620: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18621: my ($rules,$ruleorder) =
18622: &Apache::lonnet::inst_userrules($dom,'username');
18623: my $chgtext = '<ul>';
18624: foreach my $type (@username_rule) {
18625: if (ref($rules->{$type}) eq 'HASH') {
18626: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18627: }
18628: }
18629: $chgtext .= '</ul>';
18630: if (@username_rule > 0) {
18631: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18632: } else {
18633: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18634: }
18635: }
18636: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18637: my ($idrules,$idruleorder) =
18638: &Apache::lonnet::inst_userrules($dom,'id');
18639: my $chgtext = '<ul>';
18640: foreach my $type (@id_rule) {
18641: if (ref($idrules->{$type}) eq 'HASH') {
18642: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18643: }
18644: }
18645: $chgtext .= '</ul>';
18646: if (@id_rule > 0) {
18647: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18648: } else {
18649: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18650: }
18651: }
18652: my %authname = &authtype_names();
18653: my %context_title = &context_names();
18654: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18655: my $chgtext = '<ul>';
18656: foreach my $type (@{$changes{'authtypes'}}) {
18657: my @allowed;
18658: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18659: foreach my $auth (@authtypes) {
18660: if ($authhash{$type}{$auth}) {
18661: push(@allowed,$authname{$auth});
18662: }
18663: }
18664: if (@allowed > 0) {
18665: $chgtext .= join(', ',@allowed).'</li>';
18666: } else {
18667: $chgtext .= &mt('none').'</li>';
18668: }
18669: }
18670: $chgtext .= '</ul>';
18671: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18672: $resulttext .= '</li>';
18673: }
18674: $resulttext .= '</ul>';
18675: } else {
18676: $resulttext = &mt('No changes made to user creation settings');
18677: }
18678: } else {
18679: $resulttext = '<span class="LC_error">'.
18680: &mt('An error occurred: [_1]',$putresult).'</span>';
18681: }
18682: if ($warningmsg ne '') {
18683: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18684: }
18685: return $resulttext;
18686: }
18687:
18688: sub modify_selfcreation {
1.305 raeburn 18689: my ($dom,$lastactref,%domconfig) = @_;
18690: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18691: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18692: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18693: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18694: if (ref($typesref) eq 'ARRAY') {
18695: @types = @{$typesref};
18696: }
18697: if (ref($usertypesref) eq 'HASH') {
18698: %usertypes = %{$usertypesref};
1.228 raeburn 18699: }
1.303 raeburn 18700: $usertypes{'default'} = $othertitle;
1.224 raeburn 18701: #
18702: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18703: #
18704: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18705: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18706: if ($key eq 'cancreate') {
18707: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18708: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18709: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18710: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18711: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18712: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18713: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18714: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18715: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18716: } else {
18717: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18718: }
18719: }
18720: }
18721: } elsif ($key eq 'email_rule') {
18722: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18723: } else {
18724: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18725: }
18726: }
18727: }
18728: #
18729: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18730: #
18731: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18732: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18733: if ($key eq 'selfcreate') {
18734: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18735: } else {
18736: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18737: }
18738: }
18739: }
1.305 raeburn 18740: #
18741: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18742: #
18743: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18744: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18745: if ($key eq 'inststatusguest') {
18746: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18747: } else {
18748: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18749: }
18750: }
18751: }
1.224 raeburn 18752:
18753: my @contexts = ('selfcreate');
18754: @{$cancreate{'selfcreate'}} = ();
18755: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18756: if (@types) {
18757: @{$cancreate{'statustocreate'}} = ();
18758: }
1.236 raeburn 18759: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18760: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18761: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18762: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18763: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18764: my %selfcreatetypes = (
18765: sso => 'users authenticated by institutional single sign on',
18766: login => 'users authenticated by institutional log-in',
1.303 raeburn 18767: email => 'users verified by e-mail',
1.50 raeburn 18768: );
1.224 raeburn 18769: #
18770: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18771: # is permitted.
18772: #
1.305 raeburn 18773: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 18774:
1.305 raeburn 18775: my (@statuses,%email_rule);
1.228 raeburn 18776: foreach my $item ('login','sso','email') {
1.224 raeburn 18777: if ($item eq 'email') {
1.236 raeburn 18778: if ($env{'form.cancreate_email'}) {
1.305 raeburn 18779: if (@types) {
18780: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
18781: foreach my $status (@poss_statuses) {
18782: if (grep(/^\Q$status\E$/,(@types,'default'))) {
18783: push(@statuses,$status);
18784: }
18785: }
18786: $save_inststatus{'inststatusguest'} = \@statuses;
18787: } else {
18788: push(@statuses,'default');
18789: }
18790: if (@statuses) {
18791: my %curr_rule;
18792: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
18793: foreach my $type (@statuses) {
18794: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 18795: }
1.305 raeburn 18796: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
18797: foreach my $type (@statuses) {
18798: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
18799: }
18800: }
18801: push(@{$cancreate{'selfcreate'}},'email');
18802: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
18803: my %curremaildom;
18804: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
18805: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
18806: }
18807: foreach my $type (@statuses) {
18808: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
18809: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
18810: }
18811: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
18812: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
18813: }
18814: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
18815: #
18816: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
18817: #
18818: my $chosen = $1;
18819: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
18820: my $emaildom;
18821: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 18822: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 18823: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
18824: if (ref($curremaildom{$type}) eq 'HASH') {
18825: if (exists($curremaildom{$type}{$chosen})) {
18826: if ($curremaildom{$type}{$chosen} ne $emaildom) {
18827: push(@{$changes{'cancreate'}},'emaildomain');
18828: }
18829: } elsif ($emaildom ne '') {
18830: push(@{$changes{'cancreate'}},'emaildomain');
18831: }
18832: } elsif ($emaildom ne '') {
18833: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 18834: }
1.305 raeburn 18835: }
18836: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18837: } elsif ($chosen eq 'custom') {
18838: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
18839: $email_rule{$type} = [];
18840: if (ref($emailrules) eq 'HASH') {
18841: foreach my $rule (@possemail_rules) {
18842: if (exists($emailrules->{$rule})) {
18843: push(@{$email_rule{$type}},$rule);
18844: }
18845: }
18846: }
18847: if (@{$email_rule{$type}}) {
18848: $cancreate{'emailoptions'}{$type} = 'custom';
18849: if (ref($curr_rule{$type}) eq 'ARRAY') {
18850: if (@{$curr_rule{$type}} > 0) {
18851: foreach my $rule (@{$curr_rule{$type}}) {
18852: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
18853: push(@{$changes{'email_rule'}},$type);
18854: }
18855: }
18856: }
18857: foreach my $type (@{$email_rule{$type}}) {
18858: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
18859: push(@{$changes{'email_rule'}},$type);
18860: }
18861: }
18862: } else {
18863: push(@{$changes{'email_rule'}},$type);
18864: }
18865: }
18866: } else {
18867: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18868: }
18869: }
18870: }
18871: if (@types) {
18872: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18873: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
18874: if (@changed) {
18875: push(@{$changes{'inststatus'}},'inststatusguest');
18876: }
18877: } else {
18878: push(@{$changes{'inststatus'}},'inststatusguest');
18879: }
18880: }
18881: } else {
18882: delete($env{'form.cancreate_email'});
18883: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18884: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18885: push(@{$changes{'inststatus'}},'inststatusguest');
18886: }
18887: }
18888: }
18889: } else {
18890: $save_inststatus{'inststatusguest'} = [];
18891: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18892: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18893: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 18894: }
18895: }
1.224 raeburn 18896: }
18897: } else {
18898: if ($env{'form.cancreate_'.$item}) {
18899: push(@{$cancreate{'selfcreate'}},$item);
18900: }
18901: }
18902: }
1.305 raeburn 18903: my (%userinfo,%savecaptcha);
1.224 raeburn 18904: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
18905: #
1.228 raeburn 18906: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
18907: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 18908: #
1.236 raeburn 18909:
1.244 raeburn 18910: if ($env{'form.cancreate_email'}) {
1.228 raeburn 18911: push(@contexts,'emailusername');
1.305 raeburn 18912: if (@statuses) {
18913: foreach my $type (@statuses) {
1.228 raeburn 18914: if (ref($infofields) eq 'ARRAY') {
18915: foreach my $field (@{$infofields}) {
18916: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
18917: $cancreate{'emailusername'}{$type}{$field} = $1;
18918: }
18919: }
1.224 raeburn 18920: }
18921: }
18922: }
18923: #
18924: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 18925: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 18926: #
18927:
18928: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
18929: @approvalnotify = sort(@approvalnotify);
18930: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
18931: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18932: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
18933: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
18934: push(@{$changes{'cancreate'}},'notify');
18935: }
18936: } else {
18937: if ($cancreate{'notify'}{'approval'}) {
18938: push(@{$changes{'cancreate'}},'notify');
18939: }
18940: }
18941: } elsif ($cancreate{'notify'}{'approval'}) {
18942: push(@{$changes{'cancreate'}},'notify');
18943: }
18944:
18945: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
18946: }
18947: #
1.236 raeburn 18948: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 18949: # institutional log-in.
18950: #
18951: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
18952: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
18953: ($domdefaults{'auth_def'} eq 'localauth'))) {
18954: $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.').' '.
18955: &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.');
18956: }
18957: }
18958: my @fields = ('lastname','firstname','middlename','generation',
18959: 'permanentemail','id');
1.240 raeburn 18960: my @shibfields = (@fields,'inststatus');
1.224 raeburn 18961: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18962: #
18963: # Where usernames may created for institutional log-in and/or institutional single sign on:
18964: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
18965: # may self-create accounts
18966: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
18967: # which the user may supply, if institutional data is unavailable.
18968: #
18969: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 18970: if (@types) {
1.305 raeburn 18971: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
18972: push(@contexts,'statustocreate');
1.303 raeburn 18973: foreach my $type (@types) {
1.224 raeburn 18974: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
18975: foreach my $field (@fields) {
18976: if (grep(/^\Q$field\E$/,@modifiable)) {
18977: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
18978: } else {
18979: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
18980: }
18981: }
18982: }
18983: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 18984: foreach my $type (@types) {
1.224 raeburn 18985: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
18986: foreach my $field (@fields) {
18987: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
18988: $curr_usermodify{'selfcreate'}{$type}{$field}) {
18989: push(@{$changes{'selfcreate'}},$type);
18990: last;
18991: }
18992: }
18993: }
18994: }
18995: } else {
1.303 raeburn 18996: foreach my $type (@types) {
1.224 raeburn 18997: push(@{$changes{'selfcreate'}},$type);
18998: }
18999: }
19000: }
1.240 raeburn 19001: foreach my $field (@shibfields) {
19002: if ($env{'form.shibenv_'.$field} ne '') {
19003: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19004: }
19005: }
19006: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19007: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19008: foreach my $field (@shibfields) {
19009: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19010: push(@{$changes{'cancreate'}},'shibenv');
19011: }
19012: }
19013: } else {
19014: foreach my $field (@shibfields) {
19015: if ($env{'form.shibenv_'.$field}) {
19016: push(@{$changes{'cancreate'}},'shibenv');
19017: last;
19018: }
19019: }
19020: }
19021: }
1.224 raeburn 19022: }
19023: foreach my $item (@contexts) {
19024: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19025: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19026: if (ref($cancreate{$item}) eq 'ARRAY') {
19027: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19028: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19029: push(@{$changes{'cancreate'}},$item);
19030: }
19031: }
19032: }
19033: }
19034: if (ref($cancreate{$item}) eq 'ARRAY') {
19035: foreach my $type (@{$cancreate{$item}}) {
19036: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19037: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19038: push(@{$changes{'cancreate'}},$item);
19039: }
19040: }
19041: }
19042: }
19043: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19044: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19045: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19046: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19047: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19048: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19049: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19050: push(@{$changes{'cancreate'}},$item);
19051: }
19052: }
19053: }
1.305 raeburn 19054: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19055: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19056: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19057: push(@{$changes{'cancreate'}},$item);
19058: }
1.224 raeburn 19059: }
19060: }
19061: }
1.305 raeburn 19062: foreach my $type (keys(%{$cancreate{$item}})) {
19063: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19064: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19065: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19066: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19067: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19068: push(@{$changes{'cancreate'}},$item);
19069: }
19070: }
19071: } else {
19072: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19073: push(@{$changes{'cancreate'}},$item);
19074: }
19075: }
19076: }
1.305 raeburn 19077: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19078: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19079: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19080: push(@{$changes{'cancreate'}},$item);
19081: }
1.224 raeburn 19082: }
19083: }
19084: }
19085: }
19086: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19087: if (ref($cancreate{$item}) eq 'ARRAY') {
19088: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19089: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19090: push(@{$changes{'cancreate'}},$item);
19091: }
19092: }
1.305 raeburn 19093: }
19094: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19095: if (ref($cancreate{$item}) eq 'HASH') {
19096: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19097: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19098: }
19099: }
19100: } elsif ($item eq 'emailusername') {
1.228 raeburn 19101: if (ref($cancreate{$item}) eq 'HASH') {
19102: foreach my $type (keys(%{$cancreate{$item}})) {
19103: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19104: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19105: if ($cancreate{$item}{$type}{$field}) {
19106: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19107: push(@{$changes{'cancreate'}},$item);
19108: }
19109: last;
19110: }
19111: }
19112: }
19113: }
1.224 raeburn 19114: }
19115: }
19116: }
19117: #
19118: # Populate %save_usercreate hash with updates to self-creation configuration.
19119: #
19120: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19121: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19122: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19123: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19124: if (ref($cancreate{'notify'}) eq 'HASH') {
19125: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19126: }
1.236 raeburn 19127: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19128: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19129: }
1.303 raeburn 19130: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19131: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19132: }
1.305 raeburn 19133: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19134: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19135: }
1.303 raeburn 19136: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19137: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19138: }
1.224 raeburn 19139: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19140: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19141: }
1.240 raeburn 19142: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19143: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19144: }
1.224 raeburn 19145: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19146: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19147:
19148: my %userconfig_hash = (
19149: usercreation => \%save_usercreate,
19150: usermodification => \%save_usermodify,
1.305 raeburn 19151: inststatus => \%save_inststatus,
1.224 raeburn 19152: );
1.305 raeburn 19153:
1.224 raeburn 19154: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19155: $dom);
19156: #
1.305 raeburn 19157: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19158: #
1.27 raeburn 19159: if ($putresult eq 'ok') {
19160: if (keys(%changes) > 0) {
19161: $resulttext = &mt('Changes made:').'<ul>';
19162: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19163: my %lt = &selfcreation_types();
1.34 raeburn 19164: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19165: my $chgtext = '';
1.45 raeburn 19166: if ($type eq 'selfcreate') {
1.50 raeburn 19167: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19168: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19169: } else {
1.224 raeburn 19170: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19171: '<ul>';
1.50 raeburn 19172: foreach my $case (@{$cancreate{$type}}) {
19173: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19174: }
19175: $chgtext .= '</ul>';
1.100 raeburn 19176: if (ref($cancreate{$type}) eq 'ARRAY') {
19177: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19178: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19179: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19180: $chgtext .= '<span class="LC_warning">'.
19181: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19182: '</span><br />';
19183: }
19184: }
19185: }
19186: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19187: if (!@statuses) {
19188: $chgtext .= '<span class="LC_warning">'.
19189: &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.").
19190: '</span><br />';
1.303 raeburn 19191:
1.100 raeburn 19192: }
19193: }
19194: }
1.43 raeburn 19195: }
1.240 raeburn 19196: } elsif ($type eq 'shibenv') {
19197: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19198: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19199: } else {
19200: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19201: '<ul>';
19202: foreach my $field (@shibfields) {
19203: next if ($cancreate{$type}{$field} eq '');
19204: if ($field eq 'inststatus') {
19205: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19206: } else {
19207: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19208: }
19209: }
19210: $chgtext .= '</ul>';
1.303 raeburn 19211: }
1.93 raeburn 19212: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19213: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19214: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19215: if (@{$cancreate{'selfcreate'}} > 0) {
19216: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19217: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19218: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19219: $chgtext .= '<br />'.
19220: '<span class="LC_warning">'.
19221: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19222: '</span>';
19223: }
1.303 raeburn 19224: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19225: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19226: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19227: } else {
19228: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19229: }
19230: $chgtext .= '<ul>';
19231: foreach my $case (@{$cancreate{$type}}) {
19232: if ($case eq 'default') {
19233: $chgtext .= '<li>'.$othertitle.'</li>';
19234: } else {
1.303 raeburn 19235: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19236: }
19237: }
1.100 raeburn 19238: $chgtext .= '</ul>';
19239: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19240: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19241: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19242: '</span>';
1.100 raeburn 19243: }
19244: }
19245: } else {
19246: if (@{$cancreate{$type}} == 0) {
19247: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19248: } else {
19249: $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 19250: }
19251: }
1.303 raeburn 19252: $chgtext .= '<br />';
1.93 raeburn 19253: }
1.236 raeburn 19254: } elsif ($type eq 'selfcreateprocessing') {
19255: my %choices = &Apache::lonlocal::texthash (
19256: automatic => 'Automatic approval',
19257: approval => 'Queued for approval',
19258: );
1.305 raeburn 19259: if (@types) {
19260: if (@statuses) {
1.425 raeburn 19261: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19262: '<ul>';
1.305 raeburn 19263: foreach my $status (@statuses) {
19264: if ($status eq 'default') {
19265: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19266: } else {
1.305 raeburn 19267: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19268: }
19269: }
19270: $chgtext .= '</ul>';
19271: }
19272: } else {
19273: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19274: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19275: }
19276: } elsif ($type eq 'emailverified') {
19277: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19278: all => 'Same as e-mail',
19279: first => 'Omit @domain',
19280: free => 'Free to choose',
1.303 raeburn 19281: );
1.305 raeburn 19282: if (@types) {
19283: if (@statuses) {
1.303 raeburn 19284: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19285: '<ul>';
1.305 raeburn 19286: foreach my $status (@statuses) {
1.362 raeburn 19287: if ($status eq 'default') {
1.305 raeburn 19288: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19289: } else {
1.305 raeburn 19290: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19291: }
19292: }
19293: $chgtext .= '</ul>';
19294: }
19295: } else {
1.305 raeburn 19296: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19297: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19298: }
1.305 raeburn 19299: } elsif ($type eq 'emailoptions') {
19300: my %options = &Apache::lonlocal::texthash (
19301: any => 'Any e-mail',
19302: inst => 'Institutional only',
19303: noninst => 'Non-institutional only',
19304: custom => 'Custom restrictions',
19305: );
19306: if (@types) {
19307: if (@statuses) {
19308: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19309: '<ul>';
19310: foreach my $status (@statuses) {
19311: if ($type eq 'default') {
19312: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19313: } else {
19314: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19315: }
19316: }
1.305 raeburn 19317: $chgtext .= '</ul>';
19318: }
19319: } else {
19320: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19321: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19322: } else {
19323: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19324: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19325: }
1.305 raeburn 19326: }
19327: } elsif ($type eq 'emaildomain') {
19328: my $output;
19329: if (@statuses) {
19330: foreach my $type (@statuses) {
19331: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19332: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19333: if ($type eq 'default') {
19334: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19335: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19336: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19337: } else {
19338: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19339: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19340: }
1.303 raeburn 19341: } else {
1.305 raeburn 19342: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19343: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19344: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19345: } else {
19346: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19347: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19348: }
1.303 raeburn 19349: }
1.305 raeburn 19350: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19351: if ($type eq 'default') {
19352: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19353: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19354: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19355: } else {
19356: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19357: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19358: }
1.303 raeburn 19359: } else {
1.305 raeburn 19360: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19361: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19362: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19363: } else {
19364: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19365: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19366: }
1.303 raeburn 19367: }
19368: }
19369: }
19370: }
1.305 raeburn 19371: }
19372: if ($output ne '') {
19373: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19374: '<ul>'.$output.'</ul>';
1.236 raeburn 19375: }
1.165 raeburn 19376: } elsif ($type eq 'captcha') {
1.224 raeburn 19377: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19378: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19379: } else {
19380: my %captchas = &captcha_phrases();
1.224 raeburn 19381: if ($captchas{$savecaptcha{$type}}) {
19382: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19383: } else {
1.210 raeburn 19384: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19385: }
19386: }
19387: } elsif ($type eq 'recaptchakeys') {
19388: my ($privkey,$pubkey);
1.224 raeburn 19389: if (ref($savecaptcha{$type}) eq 'HASH') {
19390: $pubkey = $savecaptcha{$type}{'public'};
19391: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19392: }
19393: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19394: if (!$pubkey) {
19395: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19396: } else {
19397: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19398: }
19399: if (!$privkey) {
19400: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19401: } else {
19402: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19403: }
19404: $chgtext .= '</ul>';
1.269 raeburn 19405: } elsif ($type eq 'recaptchaversion') {
19406: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19407: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19408: }
1.224 raeburn 19409: } elsif ($type eq 'emailusername') {
19410: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19411: if (@statuses) {
19412: foreach my $type (@statuses) {
1.228 raeburn 19413: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19414: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19415: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19416: '<ul>';
19417: foreach my $field (@{$infofields}) {
19418: if ($cancreate{'emailusername'}{$type}{$field}) {
19419: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19420: }
19421: }
1.245 raeburn 19422: $chgtext .= '</ul>';
19423: } else {
1.303 raeburn 19424: $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 19425: }
19426: } else {
1.303 raeburn 19427: $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 19428: }
19429: }
19430: }
19431: }
19432: } elsif ($type eq 'notify') {
1.303 raeburn 19433: my $numapprove = 0;
1.224 raeburn 19434: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19435: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19436: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19437: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19438: $numapprove ++;
1.224 raeburn 19439: }
19440: }
1.43 raeburn 19441: }
1.303 raeburn 19442: unless ($numapprove) {
19443: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19444: }
1.34 raeburn 19445: }
1.224 raeburn 19446: if ($chgtext) {
19447: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19448: }
19449: }
19450: }
1.305 raeburn 19451: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19452: my ($emailrules,$emailruleorder) =
19453: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19454: foreach my $type (@{$changes{'email_rule'}}) {
19455: if (ref($email_rule{$type}) eq 'ARRAY') {
19456: my $chgtext = '<ul>';
19457: foreach my $rule (@{$email_rule{$type}}) {
19458: if (ref($emailrules->{$rule}) eq 'HASH') {
19459: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19460: }
19461: }
19462: $chgtext .= '</ul>';
1.310 raeburn 19463: my $typename;
1.305 raeburn 19464: if (@types) {
19465: if ($type eq 'default') {
19466: $typename = $othertitle;
19467: } else {
19468: $typename = $usertypes{$type};
1.425 raeburn 19469: }
1.305 raeburn 19470: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19471: }
19472: if (@{$email_rule{$type}} > 0) {
19473: $resulttext .= '<li>'.
19474: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19475: $usertypes{$type}).
19476: $chgtext.
19477: '</li>';
19478: } else {
19479: $resulttext .= '<li>'.
1.310 raeburn 19480: &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 19481: '</li>'.
1.310 raeburn 19482: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19483: }
1.43 raeburn 19484: }
19485: }
1.305 raeburn 19486: }
19487: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19488: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19489: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19490: my $chgtext = '<ul>';
19491: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19492: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19493: }
19494: $chgtext .= '</ul>';
19495: $resulttext .= '<li>'.
19496: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19497: $chgtext.
19498: '</li>';
19499: } else {
19500: $resulttext .= '<li>'.
19501: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19502: '</li>';
19503: }
1.43 raeburn 19504: }
19505: }
1.224 raeburn 19506: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19507: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19508: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19509: foreach my $type (@{$changes{'selfcreate'}}) {
19510: my $typename = $type;
1.303 raeburn 19511: if (keys(%usertypes) > 0) {
19512: if ($usertypes{$type} ne '') {
19513: $typename = $usertypes{$type};
1.224 raeburn 19514: }
19515: }
19516: my @modifiable;
19517: $resulttext .= '<li>'.
19518: &mt('Self-creation of account by users with status: [_1]',
19519: '<span class="LC_cusr_emph">'.$typename.'</span>').
19520: ' - '.&mt('modifiable fields (if institutional data blank): ');
19521: foreach my $field (@fields) {
19522: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19523: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19524: }
19525: }
1.224 raeburn 19526: if (@modifiable > 0) {
19527: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19528: } else {
1.224 raeburn 19529: $resulttext .= &mt('none');
1.43 raeburn 19530: }
1.224 raeburn 19531: $resulttext .= '</li>';
1.28 raeburn 19532: }
1.224 raeburn 19533: $resulttext .= '</ul></li>';
1.28 raeburn 19534: }
1.27 raeburn 19535: $resulttext .= '</ul>';
1.305 raeburn 19536: my $cachetime = 24*60*60;
19537: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19538: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19539: if (ref($lastactref) eq 'HASH') {
19540: $lastactref->{'domdefaults'} = 1;
19541: }
1.27 raeburn 19542: } else {
1.224 raeburn 19543: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19544: }
19545: } else {
19546: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19547: &mt('An error occurred: [_1]',$putresult).'</span>';
19548: }
1.43 raeburn 19549: if ($warningmsg ne '') {
19550: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19551: }
1.23 raeburn 19552: return $resulttext;
19553: }
19554:
1.165 raeburn 19555: sub process_captcha {
1.369 raeburn 19556: my ($container,$changes,$newsettings,$currsettings) = @_;
19557: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19558: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19559: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19560: $newsettings->{'captcha'} = 'original';
19561: }
1.369 raeburn 19562: my %current;
19563: if (ref($currsettings) eq 'HASH') {
19564: %current = %{$currsettings};
19565: }
19566: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19567: if ($container eq 'cancreate') {
1.169 raeburn 19568: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19569: push(@{$changes->{'cancreate'}},'captcha');
19570: } elsif (!defined($changes->{'cancreate'})) {
19571: $changes->{'cancreate'} = ['captcha'];
19572: }
1.368 raeburn 19573: } elsif ($container eq 'passwords') {
19574: $changes->{'reset'} = 1;
1.169 raeburn 19575: } else {
19576: $changes->{'captcha'} = 1;
1.165 raeburn 19577: }
19578: }
1.269 raeburn 19579: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19580: if ($newsettings->{'captcha'} eq 'recaptcha') {
19581: $newpub = $env{'form.'.$container.'_recaptchapub'};
19582: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19583: $newpub =~ s/[^\w\-]//g;
19584: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19585: $newsettings->{'recaptchakeys'} = {
19586: public => $newpub,
19587: private => $newpriv,
19588: };
1.269 raeburn 19589: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19590: $newversion =~ s/\D//g;
19591: if ($newversion ne '2') {
19592: $newversion = 1;
19593: }
19594: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19595: }
1.369 raeburn 19596: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19597: $currpub = $current{'recaptchakeys'}{'public'};
19598: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19599: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19600: $newsettings->{'recaptchakeys'} = {
19601: public => '',
19602: private => '',
19603: }
19604: }
1.165 raeburn 19605: }
1.369 raeburn 19606: if ($current{'captcha'} eq 'recaptcha') {
19607: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19608: if ($currversion ne '2') {
19609: $currversion = 1;
19610: }
19611: }
19612: if ($currversion ne $newversion) {
19613: if ($container eq 'cancreate') {
19614: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19615: push(@{$changes->{'cancreate'}},'recaptchaversion');
19616: } elsif (!defined($changes->{'cancreate'})) {
19617: $changes->{'cancreate'} = ['recaptchaversion'];
19618: }
1.368 raeburn 19619: } elsif ($container eq 'passwords') {
19620: $changes->{'reset'} = 1;
1.269 raeburn 19621: } else {
19622: $changes->{'recaptchaversion'} = 1;
19623: }
19624: }
1.165 raeburn 19625: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19626: if ($container eq 'cancreate') {
19627: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19628: push(@{$changes->{'cancreate'}},'recaptchakeys');
19629: } elsif (!defined($changes->{'cancreate'})) {
19630: $changes->{'cancreate'} = ['recaptchakeys'];
19631: }
1.368 raeburn 19632: } elsif ($container eq 'passwords') {
19633: $changes->{'reset'} = 1;
1.169 raeburn 19634: } else {
1.210 raeburn 19635: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19636: }
19637: }
19638: return;
19639: }
19640:
1.33 raeburn 19641: sub modify_usermodification {
19642: my ($dom,%domconfig) = @_;
1.224 raeburn 19643: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19644: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19645: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19646: if ($key eq 'selfcreate') {
19647: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19648: } else {
19649: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19650: }
1.33 raeburn 19651: }
19652: }
1.224 raeburn 19653: my @contexts = ('author','course');
1.33 raeburn 19654: my %context_title = (
19655: author => 'In author context',
19656: course => 'In course context',
19657: );
19658: my @fields = ('lastname','firstname','middlename','generation',
19659: 'permanentemail','id');
19660: my %roles = (
19661: author => ['ca','aa'],
19662: course => ['st','ep','ta','in','cr'],
19663: );
19664: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19665: foreach my $context (@contexts) {
19666: foreach my $role (@{$roles{$context}}) {
19667: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
19668: foreach my $item (@fields) {
19669: if (grep(/^\Q$item\E$/,@modifiable)) {
19670: $modifyhash{$context}{$role}{$item} = 1;
19671: } else {
19672: $modifyhash{$context}{$role}{$item} = 0;
19673: }
19674: }
19675: }
19676: if (ref($curr_usermodification{$context}) eq 'HASH') {
19677: foreach my $role (@{$roles{$context}}) {
19678: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19679: foreach my $field (@fields) {
19680: if ($modifyhash{$context}{$role}{$field} ne
19681: $curr_usermodification{$context}{$role}{$field}) {
19682: push(@{$changes{$context}},$role);
19683: last;
19684: }
19685: }
19686: }
19687: }
19688: } else {
19689: foreach my $context (@contexts) {
19690: foreach my $role (@{$roles{$context}}) {
19691: push(@{$changes{$context}},$role);
19692: }
19693: }
19694: }
19695: }
19696: my %usermodification_hash = (
19697: usermodification => \%modifyhash,
19698: );
19699: my $putresult = &Apache::lonnet::put_dom('configuration',
19700: \%usermodification_hash,$dom);
19701: if ($putresult eq 'ok') {
19702: if (keys(%changes) > 0) {
19703: $resulttext = &mt('Changes made: ').'<ul>';
19704: foreach my $context (@contexts) {
19705: if (ref($changes{$context}) eq 'ARRAY') {
19706: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19707: if (ref($changes{$context}) eq 'ARRAY') {
19708: foreach my $role (@{$changes{$context}}) {
19709: my $rolename;
1.224 raeburn 19710: if ($role eq 'cr') {
19711: $rolename = &mt('Custom');
1.33 raeburn 19712: } else {
1.224 raeburn 19713: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19714: }
19715: my @modifiable;
1.224 raeburn 19716: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19717: foreach my $field (@fields) {
19718: if ($modifyhash{$context}{$role}{$field}) {
19719: push(@modifiable,$fieldtitles{$field});
19720: }
19721: }
19722: if (@modifiable > 0) {
19723: $resulttext .= join(', ',@modifiable);
19724: } else {
19725: $resulttext .= &mt('none');
19726: }
19727: $resulttext .= '</li>';
19728: }
19729: $resulttext .= '</ul></li>';
19730: }
19731: }
19732: }
19733: $resulttext .= '</ul>';
19734: } else {
19735: $resulttext = &mt('No changes made to user modification settings');
19736: }
19737: } else {
19738: $resulttext = '<span class="LC_error">'.
19739: &mt('An error occurred: [_1]',$putresult).'</span>';
19740: }
19741: return $resulttext;
19742: }
19743:
1.43 raeburn 19744: sub modify_defaults {
1.212 raeburn 19745: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19746: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19747: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19748: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19749: 'portal_def');
1.325 raeburn 19750: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19751: foreach my $item (@items) {
19752: $newvalues{$item} = $env{'form.'.$item};
19753: if ($item eq 'auth_def') {
19754: if ($newvalues{$item} ne '') {
19755: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19756: push(@errors,$item);
19757: }
19758: }
19759: } elsif ($item eq 'lang_def') {
19760: if ($newvalues{$item} ne '') {
19761: if ($newvalues{$item} =~ /^(\w+)/) {
19762: my $langcode = $1;
1.103 raeburn 19763: if ($langcode ne 'x_chef') {
19764: if (code2language($langcode) eq '') {
19765: push(@errors,$item);
19766: }
1.43 raeburn 19767: }
19768: } else {
19769: push(@errors,$item);
19770: }
19771: }
1.54 raeburn 19772: } elsif ($item eq 'timezone_def') {
19773: if ($newvalues{$item} ne '') {
1.62 raeburn 19774: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 19775: push(@errors,$item);
19776: }
19777: }
1.68 raeburn 19778: } elsif ($item eq 'datelocale_def') {
19779: if ($newvalues{$item} ne '') {
19780: my @datelocale_ids = DateTime::Locale->ids();
19781: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
19782: push(@errors,$item);
19783: }
19784: }
1.141 raeburn 19785: } elsif ($item eq 'portal_def') {
19786: if ($newvalues{$item} ne '') {
1.414 raeburn 19787: 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])\/?$/) {
19788: foreach my $field ('email','web') {
19789: if ($env{'form.'.$item.'_'.$field}) {
19790: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
19791: }
19792: }
19793: } else {
1.141 raeburn 19794: push(@errors,$item);
19795: }
19796: }
1.43 raeburn 19797: }
19798: if (grep(/^\Q$item\E$/,@errors)) {
19799: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 19800: if ($item eq 'portal_def') {
19801: if ($domdefaults{$item}) {
19802: foreach my $field ('email','web') {
19803: if (exists($domdefaults{$item.'_'.$field})) {
19804: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
19805: }
19806: }
19807: }
19808: }
1.43 raeburn 19809: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
19810: $changes{$item} = 1;
19811: }
1.414 raeburn 19812: if ($item eq 'portal_def') {
19813: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 19814: if ($newvalues{$item} eq '') {
1.414 raeburn 19815: foreach my $field ('email','web') {
19816: if (exists($domdefaults{$item.'_'.$field})) {
19817: delete($domdefaults{$item.'_'.$field});
19818: }
19819: }
19820: } else {
19821: unless ($changes{$item}) {
19822: foreach my $field ('email','web') {
19823: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
19824: $changes{$item} = 1;
19825: last;
19826: }
19827: }
19828: }
19829: foreach my $field ('email','web') {
19830: if ($newvalues{$item.'_'.$field}) {
19831: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
19832: } elsif (exists($domdefaults{$item.'_'.$field})) {
19833: delete($domdefaults{$item.'_'.$field});
19834: }
19835: }
19836: }
19837: }
19838: }
1.72 raeburn 19839: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 19840: }
1.354 raeburn 19841: my %staticdefaults = (
19842: 'intauth_cost' => 10,
19843: 'intauth_check' => 0,
19844: 'intauth_switch' => 0,
19845: );
19846: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
19847: if (exists($domdefaults{$item})) {
19848: $newvalues{$item} = $domdefaults{$item};
19849: } else {
19850: $newvalues{$item} = $staticdefaults{$item};
19851: }
19852: }
1.409 raeburn 19853: my ($unamemaprules,$ruleorder);
19854: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
19855: if (@possunamemaprules) {
19856: ($unamemaprules,$ruleorder) =
19857: &Apache::lonnet::inst_userrules($dom,'unamemap');
19858: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
19859: if (@{$ruleorder} > 0) {
19860: my %possrules;
19861: map { $possrules{$_} = 1; } @possunamemaprules;
19862: foreach my $rule (@{$ruleorder}) {
19863: if ($possrules{$rule}) {
19864: push(@{$newvalues{'unamemap_rule'}},$rule);
19865: }
19866: }
19867: }
19868: }
19869: }
19870: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
19871: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19872: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
19873: $newvalues{'unamemap_rule'});
19874: if (@rulediffs) {
19875: $changes{'unamemap_rule'} = 1;
19876: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
19877: }
19878: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
19879: $changes{'unamemap_rule'} = 1;
19880: delete($domdefaults{'unamemap_rule'});
19881: }
19882: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19883: if (@{$newvalues{'unamemap_rule'}} > 0) {
19884: $changes{'unamemap_rule'} = 1;
19885: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
19886: }
19887: }
1.43 raeburn 19888: my %defaults_hash = (
1.72 raeburn 19889: defaults => \%newvalues,
19890: );
1.43 raeburn 19891: my $title = &defaults_titles();
1.236 raeburn 19892:
19893: my $currinststatus;
19894: if (ref($domconfig{'inststatus'}) eq 'HASH') {
19895: $currinststatus = $domconfig{'inststatus'};
19896: } else {
19897: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
19898: $currinststatus = {
19899: inststatustypes => $usertypes,
19900: inststatusorder => $types,
19901: inststatusguest => [],
19902: };
19903: }
19904: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
19905: my @allpos;
19906: my %alltypes;
1.305 raeburn 19907: my @inststatusguest;
19908: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
19909: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
19910: unless (grep(/^\Q$type\E$/,@todelete)) {
19911: push(@inststatusguest,$type);
19912: }
19913: }
19914: }
19915: my ($currtitles,$currorder);
1.236 raeburn 19916: if (ref($currinststatus) eq 'HASH') {
19917: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
19918: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
19919: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
19920: if ($currinststatus->{inststatustypes}->{$type} ne '') {
19921: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
19922: }
19923: }
19924: unless (grep(/^\Q$type\E$/,@todelete)) {
19925: my $position = $env{'form.inststatus_pos_'.$type};
19926: $position =~ s/\D+//g;
19927: $allpos[$position] = $type;
19928: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
19929: $alltypes{$type} =~ s/`//g;
19930: }
19931: }
19932: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
19933: $currtitles =~ s/,$//;
19934: }
19935: }
19936: if ($env{'form.addinststatus'}) {
19937: my $newtype = $env{'form.addinststatus'};
19938: $newtype =~ s/\W//g;
19939: unless (exists($alltypes{$newtype})) {
19940: $alltypes{$newtype} = $env{'form.addinststatus_title'};
19941: $alltypes{$newtype} =~ s/`//g;
19942: my $position = $env{'form.addinststatus_pos'};
19943: $position =~ s/\D+//g;
19944: if ($position ne '') {
19945: $allpos[$position] = $newtype;
19946: }
19947: }
19948: }
1.305 raeburn 19949: my @orderedstatus;
1.236 raeburn 19950: foreach my $type (@allpos) {
19951: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
19952: push(@orderedstatus,$type);
19953: }
19954: }
19955: foreach my $type (keys(%alltypes)) {
19956: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
19957: delete($alltypes{$type});
19958: }
19959: }
19960: $defaults_hash{'inststatus'} = {
19961: inststatustypes => \%alltypes,
19962: inststatusorder => \@orderedstatus,
1.305 raeburn 19963: inststatusguest => \@inststatusguest,
1.236 raeburn 19964: };
19965: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
19966: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
19967: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
19968: }
19969: }
19970: if ($currorder ne join(',',@orderedstatus)) {
19971: $changes{'inststatus'}{'inststatusorder'} = 1;
19972: }
19973: my $newtitles;
19974: foreach my $item (@orderedstatus) {
19975: $newtitles .= $alltypes{$item}.',';
19976: }
19977: $newtitles =~ s/,$//;
19978: if ($currtitles ne $newtitles) {
19979: $changes{'inststatus'}{'inststatustypes'} = 1;
19980: }
1.43 raeburn 19981: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
19982: $dom);
19983: if ($putresult eq 'ok') {
19984: if (keys(%changes) > 0) {
19985: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 19986: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 19987: 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";
19988: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 19989: if ($item eq 'inststatus') {
19990: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 19991: if (@orderedstatus) {
1.236 raeburn 19992: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
19993: foreach my $type (@orderedstatus) {
19994: $resulttext .= $alltypes{$type}.', ';
19995: }
19996: $resulttext =~ s/, $//;
19997: $resulttext .= '</li>';
1.305 raeburn 19998: } else {
1.425 raeburn 19999: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20000: }
20001: }
1.409 raeburn 20002: } elsif ($item eq 'unamemap_rule') {
20003: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20004: my @rulenames;
20005: if (ref($unamemaprules) eq 'HASH') {
20006: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20007: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20008: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20009: }
20010: }
20011: }
20012: if (@rulenames) {
20013: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20014: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20015: '</li>';
20016: } else {
20017: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20018: }
20019: } else {
20020: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20021: }
1.236 raeburn 20022: } else {
20023: my $value = $env{'form.'.$item};
20024: if ($value eq '') {
20025: $value = &mt('none');
20026: } elsif ($item eq 'auth_def') {
20027: my %authnames = &authtype_names();
20028: my %shortauth = (
20029: internal => 'int',
20030: krb4 => 'krb4',
20031: krb5 => 'krb5',
20032: localauth => 'loc',
1.325 raeburn 20033: lti => 'lti',
1.236 raeburn 20034: );
20035: $value = $authnames{$shortauth{$value}};
20036: }
20037: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20038: $mailmsgtext .= "$title->{$item} set to $value\n";
20039: if ($item eq 'portal_def') {
20040: if ($env{'form.'.$item} ne '') {
20041: foreach my $field ('email','web') {
20042: $value = $env{'form.'.$item.'_'.$field};
20043: if ($value) {
20044: $value = &mt('Yes');
20045: } else {
20046: $value = &mt('No');
20047: }
20048: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20049: }
20050: }
20051: }
1.43 raeburn 20052: }
20053: }
20054: $resulttext .= '</ul>';
20055: $mailmsgtext .= "\n";
20056: my $cachetime = 24*60*60;
1.72 raeburn 20057: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20058: if (ref($lastactref) eq 'HASH') {
20059: $lastactref->{'domdefaults'} = 1;
20060: }
1.68 raeburn 20061: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20062: my $notify = 1;
20063: if (ref($domconfig{'contacts'}) eq 'HASH') {
20064: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20065: $notify = 0;
20066: }
20067: }
20068: if ($notify) {
20069: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20070: "LON-CAPA Domain Settings Change - $dom",
20071: $mailmsgtext);
20072: }
1.54 raeburn 20073: }
1.43 raeburn 20074: } else {
1.54 raeburn 20075: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20076: }
20077: } else {
20078: $resulttext = '<span class="LC_error">'.
20079: &mt('An error occurred: [_1]',$putresult).'</span>';
20080: }
20081: if (@errors > 0) {
20082: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20083: foreach my $item (@errors) {
20084: $resulttext .= ' "'.$title->{$item}.'",';
20085: }
20086: $resulttext =~ s/,$//;
20087: }
20088: return $resulttext;
20089: }
20090:
1.46 raeburn 20091: sub modify_scantron {
1.205 raeburn 20092: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20093: my ($resulttext,%confhash,%changes,$errors);
20094: my $custom = 'custom.tab';
20095: my $default = 'default.tab';
20096: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20097: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20098: &config_check($dom,$confname,$servadm);
20099: if ($env{'form.scantronformat.filename'} ne '') {
20100: my $error;
20101: if ($configuserok eq 'ok') {
20102: if ($switchserver) {
1.130 raeburn 20103: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20104: } else {
20105: if ($author_ok eq 'ok') {
1.421 raeburn 20106: my $modified = [];
1.46 raeburn 20107: my ($result,$scantronurl) =
1.421 raeburn 20108: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20109: $confname,'scantron','','',$custom,
20110: $modified);
1.46 raeburn 20111: if ($result eq 'ok') {
20112: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20113: $changes{'scantronformat'} = 1;
1.421 raeburn 20114: &update_modify_urls($r,$modified);
1.46 raeburn 20115: } else {
20116: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20117: }
20118: } else {
20119: $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);
20120: }
20121: }
20122: } else {
20123: $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);
20124: }
20125: if ($error) {
20126: &Apache::lonnet::logthis($error);
20127: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20128: }
20129: }
1.48 raeburn 20130: if (ref($domconfig{'scantron'}) eq 'HASH') {
20131: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20132: if ($env{'form.scantronformat_del'}) {
20133: $confhash{'scantron'}{'scantronformat'} = '';
20134: $changes{'scantronformat'} = 1;
1.347 raeburn 20135: } else {
20136: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20137: }
20138: }
20139: }
1.347 raeburn 20140: my @options = ('hdr','pad','rem');
1.346 raeburn 20141: my @fields = &scantroncsv_fields();
20142: my %titles = &scantronconfig_titles();
1.347 raeburn 20143: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20144: my ($newdat,$currdat,%newcol,%currcol);
20145: if (grep(/^dat$/,@formats)) {
20146: $confhash{'scantron'}{config}{dat} = 1;
20147: $newdat = 1;
20148: } else {
20149: $newdat = 0;
20150: }
20151: if (grep(/^csv$/,@formats)) {
20152: my %bynum;
20153: foreach my $field (@fields) {
20154: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20155: my $posscol = $1;
20156: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20157: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20158: $bynum{$posscol} = $field;
20159: $newcol{$field} = $posscol;
20160: }
20161: }
20162: }
1.347 raeburn 20163: if (keys(%newcol)) {
20164: foreach my $option (@options) {
20165: if ($env{'form.scantroncsv_'.$option}) {
20166: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20167: }
20168: }
20169: }
1.346 raeburn 20170: }
20171: $currdat = 1;
20172: if (ref($domconfig{'scantron'}) eq 'HASH') {
20173: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20174: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20175: $currdat = 0;
20176: }
20177: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20178: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20179: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20180: }
1.346 raeburn 20181: }
20182: }
20183: }
20184: if ($currdat != $newdat) {
20185: $changes{'config'} = 1;
20186: } else {
20187: foreach my $field (@fields) {
20188: if ($currcol{$field} ne '') {
20189: if ($currcol{$field} ne $newcol{$field}) {
20190: $changes{'config'} = 1;
20191: last;
1.347 raeburn 20192: }
1.346 raeburn 20193: } elsif ($newcol{$field} ne '') {
20194: $changes{'config'} = 1;
20195: last;
20196: }
20197: }
20198: }
1.46 raeburn 20199: if (keys(%confhash) > 0) {
20200: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20201: $dom);
20202: if ($putresult eq 'ok') {
20203: if (keys(%changes) > 0) {
1.48 raeburn 20204: if (ref($confhash{'scantron'}) eq 'HASH') {
20205: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20206: if ($changes{'scantronformat'}) {
20207: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20208: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20209: } else {
20210: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20211: }
20212: }
1.347 raeburn 20213: if ($changes{'config'}) {
1.346 raeburn 20214: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20215: if ($confhash{'scantron'}{'config'}{'dat'}) {
20216: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20217: }
20218: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20219: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20220: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20221: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20222: foreach my $field (@fields) {
20223: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20224: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20225: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20226: }
20227: }
20228: $resulttext .= '</ul></li>';
20229: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20230: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20231: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20232: foreach my $option (@options) {
20233: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20234: $resulttext .= '<li>'.$titles{$option}.'</li>';
20235: }
20236: }
20237: $resulttext .= '</ul></li>';
20238: }
1.346 raeburn 20239: }
20240: }
20241: }
20242: }
20243: } else {
20244: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20245: }
1.46 raeburn 20246: }
1.48 raeburn 20247: $resulttext .= '</ul>';
20248: } else {
1.130 raeburn 20249: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20250: }
20251: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20252: if (ref($lastactref) eq 'HASH') {
20253: $lastactref->{'domainconfig'} = 1;
20254: }
1.46 raeburn 20255: } else {
1.346 raeburn 20256: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20257: }
20258: } else {
20259: $resulttext = '<span class="LC_error">'.
20260: &mt('An error occurred: [_1]',$putresult).'</span>';
20261: }
20262: } else {
1.130 raeburn 20263: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20264: }
20265: if ($errors) {
1.353 raeburn 20266: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20267: $errors.'</ul></p>';
1.46 raeburn 20268: }
20269: return $resulttext;
20270: }
20271:
1.48 raeburn 20272: sub modify_coursecategories {
1.239 raeburn 20273: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20274: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20275: $cathash);
1.48 raeburn 20276: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20277: my @catitems = ('unauth','auth');
20278: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20279: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20280: $cathash = $domconfig{'coursecategories'}{'cats'};
20281: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20282: $changes{'togglecats'} = 1;
20283: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20284: }
20285: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20286: $changes{'categorize'} = 1;
20287: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20288: }
1.120 raeburn 20289: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20290: $changes{'togglecatscomm'} = 1;
20291: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20292: }
20293: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20294: $changes{'categorizecomm'} = 1;
20295: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20296:
20297: }
20298: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20299: $changes{'togglecatsplace'} = 1;
20300: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20301: }
20302: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20303: $changes{'categorizeplace'} = 1;
20304: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20305: }
1.238 raeburn 20306: foreach my $item (@catitems) {
20307: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20308: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20309: $changes{$item} = 1;
20310: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20311: }
20312: }
20313: }
1.57 raeburn 20314: } else {
20315: $changes{'togglecats'} = 1;
20316: $changes{'categorize'} = 1;
1.124 raeburn 20317: $changes{'togglecatscomm'} = 1;
20318: $changes{'categorizecomm'} = 1;
1.272 raeburn 20319: $changes{'togglecatsplace'} = 1;
20320: $changes{'categorizeplace'} = 1;
1.87 raeburn 20321: $domconfig{'coursecategories'} = {
20322: togglecats => $env{'form.togglecats'},
20323: categorize => $env{'form.categorize'},
1.124 raeburn 20324: togglecatscomm => $env{'form.togglecatscomm'},
20325: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20326: togglecatsplace => $env{'form.togglecatsplace'},
20327: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20328: };
1.238 raeburn 20329: foreach my $item (@catitems) {
20330: if ($env{'form.coursecat_'.$item} ne 'std') {
20331: $changes{$item} = 1;
20332: }
20333: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20334: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20335: }
20336: }
1.57 raeburn 20337: }
20338: if (ref($cathash) eq 'HASH') {
20339: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20340: push (@deletecategory,'instcode::0');
20341: }
1.120 raeburn 20342: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20343: push(@deletecategory,'communities::0');
20344: }
1.272 raeburn 20345: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20346: push(@deletecategory,'placement::0');
20347: }
1.48 raeburn 20348: }
1.57 raeburn 20349: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20350: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20351: if (@deletecategory > 0) {
20352: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20353: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20354: foreach my $item (@deletecategory) {
1.57 raeburn 20355: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20356: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20357: $deletions{$item} = 1;
1.57 raeburn 20358: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20359: }
20360: }
20361: }
1.57 raeburn 20362: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20363: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20364: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20365: $reorderings{$item} = 1;
1.57 raeburn 20366: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20367: }
20368: if ($env{'form.addcategory_name_'.$item} ne '') {
20369: my $newcat = $env{'form.addcategory_name_'.$item};
20370: my $newdepth = $depth+1;
20371: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20372: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20373: $adds{$newitem} = 1;
20374: }
20375: if ($env{'form.subcat_'.$item} ne '') {
20376: my $newcat = $env{'form.subcat_'.$item};
20377: my $newdepth = $depth+1;
20378: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20379: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20380: $adds{$newitem} = 1;
20381: }
20382: }
20383: }
20384: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20385: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20386: my $newitem = 'instcode::0';
1.57 raeburn 20387: if ($cathash->{$newitem} eq '') {
20388: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20389: $adds{$newitem} = 1;
20390: }
20391: } else {
20392: my $newitem = 'instcode::0';
1.57 raeburn 20393: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20394: $adds{$newitem} = 1;
20395: }
20396: }
1.120 raeburn 20397: if ($env{'form.communities'} eq '1') {
20398: if (ref($cathash) eq 'HASH') {
20399: my $newitem = 'communities::0';
20400: if ($cathash->{$newitem} eq '') {
20401: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20402: $adds{$newitem} = 1;
20403: }
20404: } else {
20405: my $newitem = 'communities::0';
20406: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20407: $adds{$newitem} = 1;
20408: }
20409: }
1.272 raeburn 20410: if ($env{'form.placement'} eq '1') {
20411: if (ref($cathash) eq 'HASH') {
20412: my $newitem = 'placement::0';
20413: if ($cathash->{$newitem} eq '') {
20414: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20415: $adds{$newitem} = 1;
20416: }
20417: } else {
20418: my $newitem = 'placement::0';
20419: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20420: $adds{$newitem} = 1;
20421: }
20422: }
1.48 raeburn 20423: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20424: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20425: ($env{'form.addcategory_name'} ne 'communities') &&
20426: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20427: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20428: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20429: $adds{$newitem} = 1;
20430: }
1.48 raeburn 20431: }
1.57 raeburn 20432: my $putresult;
1.48 raeburn 20433: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20434: if (keys(%deletions) > 0) {
20435: foreach my $key (keys(%deletions)) {
20436: if ($predelallitems{$key} ne '') {
20437: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20438: }
20439: }
20440: }
20441: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20442: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20443: if (ref($chkcats[0]) eq 'ARRAY') {
20444: my $depth = 0;
20445: my $chg = 0;
20446: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20447: my $name = $chkcats[0][$i];
20448: my $item;
20449: if ($name eq '') {
20450: $chg ++;
20451: } else {
20452: $item = &escape($name).'::0';
20453: if ($chg) {
1.57 raeburn 20454: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20455: }
20456: $depth ++;
1.57 raeburn 20457: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20458: $depth --;
20459: }
20460: }
20461: }
1.57 raeburn 20462: }
20463: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20464: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20465: if ($putresult eq 'ok') {
1.57 raeburn 20466: my %title = (
1.120 raeburn 20467: togglecats => 'Show/Hide a course in catalog',
20468: categorize => 'Assign a category to a course',
20469: togglecatscomm => 'Show/Hide a community in catalog',
20470: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20471: );
20472: my %level = (
1.120 raeburn 20473: dom => 'set in Domain ("Modify Course/Community")',
20474: crs => 'set in Course ("Course Configuration")',
20475: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20476: none => 'No catalog',
20477: std => 'Standard catalog',
20478: domonly => 'Domain-only catalog',
20479: codesrch => 'Code search form',
1.57 raeburn 20480: );
1.48 raeburn 20481: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20482: if ($changes{'togglecats'}) {
20483: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20484: }
20485: if ($changes{'categorize'}) {
20486: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20487: }
1.120 raeburn 20488: if ($changes{'togglecatscomm'}) {
20489: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20490: }
20491: if ($changes{'categorizecomm'}) {
20492: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20493: }
1.238 raeburn 20494: if ($changes{'unauth'}) {
20495: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20496: }
20497: if ($changes{'auth'}) {
20498: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20499: }
1.57 raeburn 20500: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20501: my $cathash;
20502: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20503: $cathash = $domconfig{'coursecategories'}{'cats'};
20504: } else {
20505: $cathash = {};
20506: }
20507: my (@cats,@trails,%allitems);
20508: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20509: if (keys(%deletions) > 0) {
20510: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20511: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20512: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20513: }
20514: $resulttext .= '</ul></li>';
20515: }
20516: if (keys(%reorderings) > 0) {
20517: my %sort_by_trail;
20518: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20519: foreach my $key (keys(%reorderings)) {
20520: if ($allitems{$key} ne '') {
20521: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20522: }
1.48 raeburn 20523: }
1.57 raeburn 20524: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20525: $resulttext .= '<li>'.$trails[$trail].'</li>';
20526: }
20527: $resulttext .= '</ul></li>';
1.48 raeburn 20528: }
1.57 raeburn 20529: if (keys(%adds) > 0) {
20530: my %sort_by_trail;
20531: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20532: foreach my $key (keys(%adds)) {
20533: if ($allitems{$key} ne '') {
20534: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20535: }
20536: }
20537: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20538: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20539: }
1.57 raeburn 20540: $resulttext .= '</ul></li>';
1.48 raeburn 20541: }
1.364 raeburn 20542: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20543: if (ref($lastactref) eq 'HASH') {
20544: $lastactref->{'cats'} = 1;
20545: }
1.48 raeburn 20546: }
20547: $resulttext .= '</ul>';
1.239 raeburn 20548: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20549: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20550: if ($changes{'auth'}) {
20551: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20552: }
20553: if ($changes{'unauth'}) {
20554: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20555: }
20556: my $cachetime = 24*60*60;
20557: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20558: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20559: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20560: }
20561: }
1.48 raeburn 20562: } else {
20563: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20564: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20565: }
20566: } else {
1.120 raeburn 20567: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20568: }
20569: return $resulttext;
20570: }
20571:
1.69 raeburn 20572: sub modify_serverstatuses {
20573: my ($dom,%domconfig) = @_;
20574: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20575: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20576: %currserverstatus = %{$domconfig{'serverstatuses'}};
20577: }
20578: my @pages = &serverstatus_pages();
20579: foreach my $type (@pages) {
20580: $newserverstatus{$type}{'namedusers'} = '';
20581: $newserverstatus{$type}{'machines'} = '';
20582: if (defined($env{'form.'.$type.'_namedusers'})) {
20583: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20584: my @okusers;
20585: foreach my $user (@users) {
20586: my ($uname,$udom) = split(/:/,$user);
20587: if (($udom =~ /^$match_domain$/) &&
20588: (&Apache::lonnet::domain($udom)) &&
20589: ($uname =~ /^$match_username$/)) {
20590: if (!grep(/^\Q$user\E/,@okusers)) {
20591: push(@okusers,$user);
20592: }
20593: }
20594: }
20595: if (@okusers > 0) {
20596: @okusers = sort(@okusers);
20597: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20598: }
20599: }
20600: if (defined($env{'form.'.$type.'_machines'})) {
20601: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20602: my @okmachines;
20603: foreach my $ip (@machines) {
20604: my @parts = split(/\./,$ip);
20605: next if (@parts < 4);
20606: my $badip = 0;
20607: for (my $i=0; $i<4; $i++) {
20608: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20609: $badip = 1;
20610: last;
20611: }
20612: }
20613: if (!$badip) {
20614: push(@okmachines,$ip);
20615: }
20616: }
20617: @okmachines = sort(@okmachines);
20618: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20619: }
20620: }
20621: my %serverstatushash = (
20622: serverstatuses => \%newserverstatus,
20623: );
20624: foreach my $type (@pages) {
1.83 raeburn 20625: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20626: my (@current,@new);
1.83 raeburn 20627: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20628: if ($currserverstatus{$type}{$setting} ne '') {
20629: @current = split(/,/,$currserverstatus{$type}{$setting});
20630: }
20631: }
20632: if ($newserverstatus{$type}{$setting} ne '') {
20633: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20634: }
20635: if (@current > 0) {
20636: if (@new > 0) {
20637: foreach my $item (@current) {
20638: if (!grep(/^\Q$item\E$/,@new)) {
20639: $changes{$type}{$setting} = 1;
1.82 raeburn 20640: last;
20641: }
20642: }
1.84 raeburn 20643: foreach my $item (@new) {
20644: if (!grep(/^\Q$item\E$/,@current)) {
20645: $changes{$type}{$setting} = 1;
20646: last;
1.82 raeburn 20647: }
20648: }
20649: } else {
1.83 raeburn 20650: $changes{$type}{$setting} = 1;
1.69 raeburn 20651: }
1.83 raeburn 20652: } elsif (@new > 0) {
20653: $changes{$type}{$setting} = 1;
1.69 raeburn 20654: }
20655: }
20656: }
20657: if (keys(%changes) > 0) {
1.81 raeburn 20658: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20659: my $putresult = &Apache::lonnet::put_dom('configuration',
20660: \%serverstatushash,$dom);
20661: if ($putresult eq 'ok') {
20662: $resulttext .= &mt('Changes made:').'<ul>';
20663: foreach my $type (@pages) {
1.84 raeburn 20664: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20665: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20666: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20667: if ($newserverstatus{$type}{'namedusers'} eq '') {
20668: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20669: } else {
20670: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20671: }
1.84 raeburn 20672: }
20673: if ($changes{$type}{'machines'}) {
1.69 raeburn 20674: if ($newserverstatus{$type}{'machines'} eq '') {
20675: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20676: } else {
20677: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20678: }
20679:
20680: }
20681: $resulttext .= '</ul></li>';
20682: }
20683: }
20684: $resulttext .= '</ul>';
20685: } else {
20686: $resulttext = '<span class="LC_error">'.
20687: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20688:
20689: }
20690: } else {
20691: $resulttext = &mt('No changes made to access to server status pages');
20692: }
20693: return $resulttext;
20694: }
20695:
1.118 jms 20696: sub modify_helpsettings {
1.285 raeburn 20697: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20698: my ($resulttext,$errors,%changes,%helphash);
20699: my %defaultchecked = ('submitbugs' => 'on');
20700: my @offon = ('off','on');
1.118 jms 20701: my @toggles = ('submitbugs');
1.285 raeburn 20702: my %current = ('submitbugs' => '',
20703: 'adhoc' => {},
20704: );
1.118 jms 20705: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20706: %current = %{$domconfig{'helpsettings'}};
20707: }
1.285 raeburn 20708: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20709: foreach my $item (@toggles) {
20710: if ($defaultchecked{$item} eq 'on') {
20711: if ($current{$item} eq '') {
20712: if ($env{'form.'.$item} eq '0') {
20713: $changes{$item} = 1;
20714: }
20715: } elsif ($current{$item} ne $env{'form.'.$item}) {
20716: $changes{$item} = 1;
20717: }
20718: } elsif ($defaultchecked{$item} eq 'off') {
20719: if ($current{$item} eq '') {
20720: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20721: $changes{$item} = 1;
20722: }
1.282 raeburn 20723: } elsif ($current{$item} ne $env{'form.'.$item}) {
20724: $changes{$item} = 1;
20725: }
20726: }
20727: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20728: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20729: }
20730: }
1.285 raeburn 20731: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20732: my $confname = $dom.'-domainconfig';
20733: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20734: my (@allpos,%newsettings,%changedprivs,$newrole);
20735: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20736: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20737: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20738: my %lt = &Apache::lonlocal::texthash(
20739: s => 'system',
20740: d => 'domain',
20741: order => 'Display order',
20742: access => 'Role usage',
1.291 raeburn 20743: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20744: dh => 'All with domain helpdesk role',
20745: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20746: none => 'None',
20747: status => 'Determined based on institutional status',
20748: inc => 'Include all, but exclude specific personnel',
20749: exc => 'Exclude all, but include specific personnel',
20750: );
20751: for (my $num=0; $num<=$maxnum; $num++) {
20752: my ($prefix,$identifier,$rolename,%curr);
20753: if ($num == $maxnum) {
20754: next unless ($env{'form.newcusthelp'} == $maxnum);
20755: $identifier = 'custhelp'.$num;
20756: $prefix = 'helproles_'.$num;
20757: $rolename = $env{'form.custhelpname'.$num};
20758: $rolename=~s/[^A-Za-z0-9]//gs;
20759: next if ($rolename eq '');
20760: next if (exists($existing{'rolesdef_'.$rolename}));
20761: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20762: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20763: $newprivs{'c'},$confname,$dom);
20764: if ($result ne 'ok') {
20765: $errors .= '<li><span class="LC_error">'.
20766: &mt('An error occurred storing the new custom role: [_1]',
20767: $result).'</span></li>';
20768: next;
20769: } else {
20770: $changedprivs{$rolename} = \%newprivs;
20771: $newrole = $rolename;
20772: }
20773: } else {
20774: $prefix = 'helproles_'.$num;
20775: $rolename = $env{'form.'.$prefix};
20776: next if ($rolename eq '');
20777: next unless (exists($existing{'rolesdef_'.$rolename}));
20778: $identifier = 'custhelp'.$num;
20779: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20780: my %currprivs;
1.289 raeburn 20781: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 20782: split(/\_/,$existing{'rolesdef_'.$rolename});
20783: foreach my $level ('c','d','s') {
20784: if ($newprivs{$level} ne $currprivs{$level}) {
20785: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20786: $newprivs{'c'},$confname,$dom);
20787: if ($result ne 'ok') {
20788: $errors .= '<li><span class="LC_error">'.
20789: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
20790: $rolename,$result).'</span></li>';
20791: } else {
20792: $changedprivs{$rolename} = \%newprivs;
20793: }
20794: last;
20795: }
20796: }
20797: if (ref($current{'adhoc'}) eq 'HASH') {
20798: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20799: %curr = %{$current{'adhoc'}{$rolename}};
20800: }
20801: }
20802: }
20803: my $newpos = $env{'form.'.$prefix.'_pos'};
20804: $newpos =~ s/\D+//g;
20805: $allpos[$newpos] = $rolename;
20806: my $newdesc = $env{'form.'.$prefix.'_desc'};
20807: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
20808: if ($curr{'desc'}) {
20809: if ($curr{'desc'} ne $newdesc) {
20810: $changes{'customrole'}{$rolename}{'desc'} = 1;
20811: $newsettings{$rolename}{'desc'} = $newdesc;
20812: }
20813: } elsif ($newdesc ne '') {
20814: $changes{'customrole'}{$rolename}{'desc'} = 1;
20815: $newsettings{$rolename}{'desc'} = $newdesc;
20816: }
20817: my $access = $env{'form.'.$prefix.'_access'};
20818: if (grep(/^\Q$access\E$/,@accesstypes)) {
20819: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
20820: if ($access eq 'status') {
20821: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
20822: if (scalar(@statuses) == 0) {
1.289 raeburn 20823: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 20824: } else {
20825: my (@shownstatus,$numtypes);
20826: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20827: if (ref($types) eq 'ARRAY') {
20828: $numtypes = scalar(@{$types});
20829: foreach my $type (sort(@statuses)) {
20830: if ($type eq 'default') {
20831: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20832: } elsif (grep(/^\Q$type\E$/,@{$types})) {
20833: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20834: push(@shownstatus,$usertypes->{$type});
20835: }
20836: }
20837: }
20838: if (grep(/^default$/,@statuses)) {
20839: push(@shownstatus,$othertitle);
20840: }
20841: if (scalar(@shownstatus) == 1+$numtypes) {
20842: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
20843: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
20844: } else {
20845: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
20846: if (ref($curr{'status'}) eq 'ARRAY') {
20847: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20848: if (@diffs) {
20849: $changes{'customrole'}{$rolename}{$access} = 1;
20850: }
20851: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20852: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 20853: }
1.166 raeburn 20854: }
20855: }
1.285 raeburn 20856: } elsif (($access eq 'inc') || ($access eq 'exc')) {
20857: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
20858: my @newspecstaff;
20859: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20860: foreach my $person (sort(@personnel)) {
20861: if ($domhelpdesk{$person}) {
20862: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
20863: }
20864: }
20865: if (ref($curr{$access}) eq 'ARRAY') {
20866: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20867: if (@diffs) {
20868: $changes{'customrole'}{$rolename}{$access} = 1;
20869: }
20870: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20871: $changes{'customrole'}{$rolename}{$access} = 1;
20872: }
20873: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20874: my ($uname,$udom) = split(/:/,$person);
20875: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
20876: }
20877: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 20878: }
1.285 raeburn 20879: } else {
20880: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
20881: }
20882: unless ($curr{'access'} eq $access) {
20883: $changes{'customrole'}{$rolename}{'access'} = 1;
20884: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 20885: }
20886: }
1.285 raeburn 20887: if (@allpos > 0) {
20888: my $idx = 0;
20889: foreach my $rolename (@allpos) {
20890: if ($rolename ne '') {
20891: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
20892: if (ref($current{'adhoc'}) eq 'HASH') {
20893: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20894: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
20895: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 20896: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 20897: }
20898: }
1.282 raeburn 20899: }
1.285 raeburn 20900: $idx ++;
1.166 raeburn 20901: }
20902: }
1.118 jms 20903: }
1.123 jms 20904: my $putresult;
20905: if (keys(%changes) > 0) {
1.166 raeburn 20906: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 20907: if ($putresult eq 'ok') {
1.285 raeburn 20908: if (ref($helphash{'helpsettings'}) eq 'HASH') {
20909: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
20910: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
20911: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
20912: }
20913: }
20914: my $cachetime = 24*60*60;
20915: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20916: if (ref($lastactref) eq 'HASH') {
20917: $lastactref->{'domdefaults'} = 1;
20918: }
20919: } else {
20920: $errors .= '<li><span class="LC_error">'.
20921: &mt('An error occurred storing the settings: [_1]',
20922: $putresult).'</span></li>';
20923: }
20924: }
20925: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
20926: $resulttext = &mt('Changes made:').'<ul>';
20927: my (%shownprivs,@levelorder);
20928: @levelorder = ('c','d','s');
20929: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 20930: foreach my $item (sort(keys(%changes))) {
20931: if ($item eq 'submitbugs') {
20932: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
20933: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
20934: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 20935: } elsif ($item eq 'customrole') {
20936: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 20937: my @keyorder = ('order','desc','access','status','exc','inc');
20938: my %keytext = &Apache::lonlocal::texthash(
20939: order => 'Order',
20940: desc => 'Role description',
20941: access => 'Role usage',
1.300 droeschl 20942: status => 'Allowed institutional types',
1.285 raeburn 20943: exc => 'Allowed personnel',
20944: inc => 'Disallowed personnel',
20945: );
1.282 raeburn 20946: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 20947: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
20948: if ($role eq $newrole) {
20949: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
20950: $role).'<ul>';
20951: } else {
20952: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20953: $role).'<ul>';
20954: }
20955: foreach my $key (@keyorder) {
20956: if ($changes{'customrole'}{$role}{$key}) {
20957: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
20958: $keytext{$key},$newsettings{$role}{$key}).
20959: '</li>';
20960: }
20961: }
20962: if (ref($changedprivs{$role}) eq 'HASH') {
20963: $shownprivs{$role} = 1;
20964: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
20965: foreach my $level (@levelorder) {
20966: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20967: next if ($item eq '');
20968: my ($priv) = split(/\&/,$item,2);
20969: if (&Apache::lonnet::plaintext($priv)) {
20970: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20971: unless ($level eq 'c') {
20972: $resulttext .= ' ('.$lt{$level}.')';
20973: }
20974: $resulttext .= '</li>';
20975: }
20976: }
20977: }
20978: $resulttext .= '</ul>';
20979: }
20980: $resulttext .= '</ul></li>';
20981: }
20982: }
20983: }
20984: }
20985: }
20986: }
20987: if (keys(%changedprivs)) {
20988: foreach my $role (sort(keys(%changedprivs))) {
20989: unless ($shownprivs{$role}) {
20990: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20991: $role).'<ul>'.
20992: '<li>'.&mt('Privileges set to :').'<ul>';
20993: foreach my $level (@levelorder) {
20994: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20995: next if ($item eq '');
20996: my ($priv) = split(/\&/,$item,2);
20997: if (&Apache::lonnet::plaintext($priv)) {
20998: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20999: unless ($level eq 'c') {
21000: $resulttext .= ' ('.$lt{$level}.')';
21001: }
21002: $resulttext .= '</li>';
21003: }
1.282 raeburn 21004: }
21005: }
1.285 raeburn 21006: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21007: }
21008: }
21009: }
1.285 raeburn 21010: $resulttext .= '</ul>';
21011: } else {
21012: $resulttext = &mt('No changes made to help settings');
1.118 jms 21013: }
21014: if ($errors) {
1.168 raeburn 21015: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21016: $errors.'</ul>';
1.118 jms 21017: }
21018: return $resulttext;
21019: }
21020:
1.121 raeburn 21021: sub modify_coursedefaults {
1.212 raeburn 21022: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21023: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21024: my %defaultchecked = (
21025: 'canuse_pdfforms' => 'off',
21026: 'uselcmath' => 'on',
1.398 raeburn 21027: 'usejsme' => 'on',
21028: 'inline_chem' => 'on',
1.404 raeburn 21029: 'ltiauth' => 'off',
1.257 raeburn 21030: );
1.404 raeburn 21031: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21032: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21033: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21034: 'coursequota_official','coursequota_unofficial','coursequota_community',
21035: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21036: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21037: 'mysqltables_placement');
1.271 raeburn 21038: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21039: my %staticdefaults = (
21040: anonsurvey_threshold => 10,
21041: uploadquota => 500,
1.428 raeburn 21042: coursequota => 20,
1.257 raeburn 21043: postsubmit => 60,
1.276 raeburn 21044: mysqltables => 172800,
1.422 raeburn 21045: domexttool => 1,
1.432 ! raeburn 21046: crsauthor => 1,
1.198 raeburn 21047: );
1.314 raeburn 21048: my %texoptions = (
21049: MathJax => 'MathJax',
21050: mimetex => &mt('Convert to Images'),
21051: tth => &mt('TeX to HTML'),
21052: );
1.121 raeburn 21053: $defaultshash{'coursedefaults'} = {};
21054:
21055: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21056: if ($domconfig{'coursedefaults'} eq '') {
21057: $domconfig{'coursedefaults'} = {};
21058: }
21059: }
21060:
21061: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21062: foreach my $item (@toggles) {
21063: if ($defaultchecked{$item} eq 'on') {
21064: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21065: ($env{'form.'.$item} eq '0')) {
21066: $changes{$item} = 1;
1.192 raeburn 21067: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21068: $changes{$item} = 1;
21069: }
21070: } elsif ($defaultchecked{$item} eq 'off') {
21071: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21072: ($env{'form.'.$item} eq '1')) {
21073: $changes{$item} = 1;
21074: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21075: $changes{$item} = 1;
21076: }
21077: }
21078: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21079: }
1.198 raeburn 21080: foreach my $item (@numbers) {
21081: my ($currdef,$newdef);
1.208 raeburn 21082: $newdef = $env{'form.'.$item};
1.198 raeburn 21083: if ($item eq 'anonsurvey_threshold') {
21084: $currdef = $domconfig{'coursedefaults'}{$item};
21085: $newdef =~ s/\D//g;
21086: if ($newdef eq '' || $newdef < 1) {
21087: $newdef = 1;
21088: }
21089: $defaultshash{'coursedefaults'}{$item} = $newdef;
21090: } else {
1.428 raeburn 21091: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21092: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21093: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21094: }
21095: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21096: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21097: }
21098: if ($currdef ne $newdef) {
21099: if ($item eq 'anonsurvey_threshold') {
21100: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21101: $changes{$item} = 1;
21102: }
1.428 raeburn 21103: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21104: my $setting = $1;
1.276 raeburn 21105: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21106: $changes{$setting} = 1;
1.198 raeburn 21107: }
21108: }
1.139 raeburn 21109: }
21110: }
1.314 raeburn 21111: my $texengine;
21112: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21113: $texengine = $env{'form.texengine'};
1.349 raeburn 21114: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21115: if ($currdef eq '') {
21116: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21117: $changes{'texengine'} = 1;
21118: }
1.349 raeburn 21119: } elsif ($currdef ne $texengine) {
1.314 raeburn 21120: $changes{'texengine'} = 1;
21121: }
21122: }
21123: if ($texengine ne '') {
21124: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21125: }
1.264 raeburn 21126: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21127: my @currclonecode;
21128: if (ref($currclone) eq 'HASH') {
21129: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21130: @currclonecode = @{$currclone->{'instcode'}};
21131: }
21132: }
21133: my $newclone;
1.289 raeburn 21134: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21135: $newclone = $env{'form.canclone'};
21136: }
21137: if ($newclone eq 'instcode') {
21138: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21139: my (%codedefaults,@code_order,@clonecode);
21140: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21141: \@code_order);
21142: foreach my $item (@code_order) {
21143: if (grep(/^\Q$item\E$/,@newcodes)) {
21144: push(@clonecode,$item);
21145: }
21146: }
21147: if (@clonecode) {
21148: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21149: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21150: if (@diffs) {
21151: $changes{'canclone'} = 1;
21152: }
21153: } else {
21154: $newclone eq '';
21155: }
21156: } elsif ($newclone ne '') {
1.289 raeburn 21157: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21158: }
1.264 raeburn 21159: if ($newclone ne $currclone) {
21160: $changes{'canclone'} = 1;
21161: }
1.257 raeburn 21162: my %credits;
21163: foreach my $type (@types) {
21164: unless ($type eq 'community') {
21165: $credits{$type} = $env{'form.'.$type.'_credits'};
21166: $credits{$type} =~ s/[^\d.]+//g;
21167: }
21168: }
21169: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21170: ($env{'form.coursecredits'} eq '1')) {
21171: $changes{'coursecredits'} = 1;
21172: foreach my $type (keys(%credits)) {
21173: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21174: }
21175: } else {
1.289 raeburn 21176: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21177: foreach my $type (@types) {
21178: unless ($type eq 'community') {
1.289 raeburn 21179: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21180: $changes{'coursecredits'} = 1;
21181: }
21182: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21183: }
21184: }
21185: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21186: foreach my $type (@types) {
21187: unless ($type eq 'community') {
21188: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21189: $changes{'coursecredits'} = 1;
21190: last;
21191: }
21192: }
21193: }
21194: }
21195: }
21196: if ($env{'form.postsubmit'} eq '1') {
21197: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21198: my %currtimeout;
21199: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21200: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21201: $changes{'postsubmit'} = 1;
21202: }
21203: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21204: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21205: }
21206: } else {
21207: $changes{'postsubmit'} = 1;
21208: }
21209: foreach my $type (@types) {
21210: my $timeout = $env{'form.'.$type.'_timeout'};
21211: $timeout =~ s/\D//g;
21212: if ($timeout == $staticdefaults{'postsubmit'}) {
21213: $timeout = '';
21214: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21215: $timeout = '0';
21216: }
21217: unless ($timeout eq '') {
21218: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21219: }
21220: if (exists($currtimeout{$type})) {
21221: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21222: $changes{'postsubmit'} = 1;
1.257 raeburn 21223: }
21224: } elsif ($timeout ne '') {
21225: $changes{'postsubmit'} = 1;
21226: }
21227: }
21228: } else {
21229: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21230: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21231: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21232: $changes{'postsubmit'} = 1;
21233: }
21234: } else {
21235: $changes{'postsubmit'} = 1;
21236: }
1.192 raeburn 21237: }
1.432 ! raeburn 21238: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor);
1.422 raeburn 21239: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21240: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 ! raeburn 21241: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.422 raeburn 21242: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21243: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21244: } else {
21245: foreach my $type (@types) {
21246: if ($staticdefaults{'domexttool'}) {
21247: $olddomexttool{$type} = 1;
21248: } else {
21249: $olddomexttool{$type} = 0;
21250: }
21251: }
21252: }
21253: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21254: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21255: } else {
21256: foreach my $type (@types) {
21257: if ($staticdefaults{'exttool'}) {
21258: $oldexttool{$type} = 1;
21259: } else {
21260: $oldexttool{$type} = 0;
21261: }
21262: }
21263: }
1.432 ! raeburn 21264: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
! 21265: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
! 21266: } else {
! 21267: foreach my $type (@types) {
! 21268: if ($staticdefaults{'crsauthor'}) {
! 21269: $oldcrsauthor{$type} = 1;
! 21270: } else {
! 21271: $oldcrsauthor{$type} = 0;
! 21272: }
! 21273: }
! 21274: }
1.422 raeburn 21275: foreach my $type (@types) {
21276: unless ($newdomexttool{$type}) {
21277: $newdomexttool{$type} = 0;
21278: }
21279: unless ($newexttool{$type}) {
21280: $newexttool{$type} = 0;
21281: }
1.432 ! raeburn 21282: unless ($newcrsauthor{$type}) {
! 21283: $newcrsauthor{$type} = 0;
! 21284: }
1.422 raeburn 21285: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21286: $changes{'domexttool'} = 1;
21287: }
21288: if ($newexttool{$type} != $oldexttool{$type}) {
21289: $changes{'exttool'} = 1;
21290: }
1.432 ! raeburn 21291: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
! 21292: $changes{'crsauthor'} = 1;
! 21293: }
1.422 raeburn 21294: }
21295: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21296: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 ! raeburn 21297: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.121 raeburn 21298: }
21299: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21300: $dom);
21301: if ($putresult eq 'ok') {
21302: if (keys(%changes) > 0) {
1.213 raeburn 21303: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21304: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21305: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21306: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21307: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 ! raeburn 21308: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21309: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21310: 'ltiauth') {
1.257 raeburn 21311: if ($changes{$item}) {
21312: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21313: }
1.289 raeburn 21314: }
1.192 raeburn 21315: if ($changes{'coursecredits'}) {
21316: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21317: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21318: $domdefaults{$type.'credits'} =
21319: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21320: }
21321: }
21322: }
21323: if ($changes{'postsubmit'}) {
21324: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21325: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21326: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21327: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21328: $domdefaults{$type.'postsubtimeout'} =
21329: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21330: }
21331: }
1.192 raeburn 21332: }
21333: }
1.198 raeburn 21334: if ($changes{'uploadquota'}) {
21335: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21336: foreach my $type (@types) {
21337: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21338: }
21339: }
21340: }
1.428 raeburn 21341: if ($changes{'coursequota'}) {
21342: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21343: foreach my $type (@types) {
21344: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21345: }
21346: }
21347: }
1.264 raeburn 21348: if ($changes{'canclone'}) {
21349: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21350: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21351: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21352: if (@clonecodes) {
21353: $domdefaults{'canclone'} = join('+',@clonecodes);
21354: }
21355: }
21356: } else {
21357: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21358: }
21359: }
1.422 raeburn 21360: if ($changes{'domexttool'}) {
21361: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21362: foreach my $type (@types) {
21363: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21364: }
21365: }
21366: }
21367: if ($changes{'exttool'}) {
21368: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21369: foreach my $type (@types) {
21370: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21371: }
21372: }
21373: }
1.432 ! raeburn 21374: if ($changes{'crsauthor'}) {
! 21375: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
! 21376: foreach my $type (@types) {
! 21377: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
! 21378: }
! 21379: }
! 21380: }
1.121 raeburn 21381: my $cachetime = 24*60*60;
21382: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21383: if (ref($lastactref) eq 'HASH') {
21384: $lastactref->{'domdefaults'} = 1;
21385: }
1.121 raeburn 21386: }
21387: $resulttext = &mt('Changes made:').'<ul>';
21388: foreach my $item (sort(keys(%changes))) {
21389: if ($item eq 'canuse_pdfforms') {
21390: if ($env{'form.'.$item} eq '1') {
21391: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21392: } else {
21393: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21394: }
1.257 raeburn 21395: } elsif ($item eq 'uselcmath') {
21396: if ($env{'form.'.$item} eq '1') {
21397: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21398: } else {
21399: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21400: }
21401: } elsif ($item eq 'usejsme') {
21402: if ($env{'form.'.$item} eq '1') {
21403: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21404: } else {
1.289 raeburn 21405: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21406: }
1.398 raeburn 21407: } elsif ($item eq 'inline_chem') {
21408: if ($env{'form.'.$item} eq '1') {
21409: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21410: } else {
21411: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21412: }
1.314 raeburn 21413: } elsif ($item eq 'texengine') {
21414: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21415: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21416: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21417: }
1.139 raeburn 21418: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21419: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21420: } elsif ($item eq 'uploadquota') {
21421: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21422: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21423: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21424: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21425: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21426: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21427: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21428: '</ul>'.
21429: '</li>';
21430: } else {
21431: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21432: }
1.428 raeburn 21433: } elsif ($item eq 'coursequota') {
21434: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21435: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21436: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21437: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21438: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21439: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21440: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21441: '</ul>'.
21442: '</li>';
21443: } else {
21444: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21445: }
1.276 raeburn 21446: } elsif ($item eq 'mysqltables') {
21447: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21448: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21449: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21450: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21451: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21452: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21453: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21454: '</ul>'.
21455: '</li>';
21456: } else {
21457: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21458: }
1.257 raeburn 21459: } elsif ($item eq 'postsubmit') {
21460: if ($domdefaults{'postsubmit'} eq 'off') {
21461: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21462: } else {
21463: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21464: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21465: $resulttext .= &mt('durations:').'<ul>';
21466: foreach my $type (@types) {
21467: $resulttext .= '<li>';
21468: my $timeout;
21469: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21470: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21471: }
21472: my $display;
21473: if ($timeout eq '0') {
21474: $display = &mt('unlimited');
21475: } elsif ($timeout eq '') {
21476: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21477: } else {
21478: $display = &mt('[quant,_1,second]',$timeout);
21479: }
21480: if ($type eq 'community') {
21481: $resulttext .= &mt('Communities');
21482: } elsif ($type eq 'official') {
21483: $resulttext .= &mt('Official courses');
21484: } elsif ($type eq 'unofficial') {
21485: $resulttext .= &mt('Unofficial courses');
21486: } elsif ($type eq 'textbook') {
21487: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21488: } elsif ($type eq 'placement') {
21489: $resulttext .= &mt('Placement tests');
1.257 raeburn 21490: }
21491: $resulttext .= ' -- '.$display.'</li>';
21492: }
21493: $resulttext .= '</ul>';
21494: }
1.289 raeburn 21495: $resulttext .= '</li>';
1.257 raeburn 21496: }
1.192 raeburn 21497: } elsif ($item eq 'coursecredits') {
21498: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21499: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21500: ($domdefaults{'unofficialcredits'} eq '') &&
21501: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21502: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21503: } else {
21504: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21505: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21506: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21507: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21508: '</ul>'.
21509: '</li>';
21510: }
21511: } else {
21512: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21513: }
1.264 raeburn 21514: } elsif ($item eq 'canclone') {
21515: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21516: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21517: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21518: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21519: }
21520: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21521: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21522: } else {
1.289 raeburn 21523: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21524: }
1.404 raeburn 21525: } elsif ($item eq 'ltiauth') {
21526: if ($env{'form.'.$item} eq '1') {
21527: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21528: } else {
21529: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21530: }
1.432 ! raeburn 21531: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21532: my @noyes = (&mt('no'),&mt('yes'));
1.432 ! raeburn 21533: my %status = (
! 21534: domexttool => {
! 21535: ishash => &mt('External Tools defined in the domain may be used as follows:'),
! 21536: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
! 21537: },
! 21538: exttool => {
! 21539: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
! 21540: default => &mt('External Tools can not be defined in any course types, by default'),
! 21541: },
! 21542: crsauthor => {
! 21543: ishash => &mt('Standard Problems can be created within course containers as follows:'),
! 21544: default => &mt('Standard Problems can be created within any course type, by default'),
! 21545: },
! 21546: );
! 21547:
! 21548: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
! 21549: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
! 21550: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
! 21551: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
! 21552: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
! 21553: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
! 21554: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21555: '</ul>'.
21556: '</li>';
21557: } else {
1.432 ! raeburn 21558: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21559: }
1.140 raeburn 21560: }
1.121 raeburn 21561: }
21562: $resulttext .= '</ul>';
21563: } else {
21564: $resulttext = &mt('No changes made to course defaults');
21565: }
21566: } else {
21567: $resulttext = '<span class="LC_error">'.
21568: &mt('An error occurred: [_1]',$putresult).'</span>';
21569: }
21570: return $resulttext;
21571: }
21572:
1.231 raeburn 21573: sub modify_selfenrollment {
21574: my ($dom,$lastactref,%domconfig) = @_;
21575: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21576: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21577: my %titles = &tool_titles();
1.232 raeburn 21578: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21579: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21580: $ordered{'default'} = ['types','registered','approval','limit'];
21581:
21582: my (%roles,%shown,%toplevel);
21583: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21584:
21585: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21586: if ($domconfig{'selfenrollment'} eq '') {
21587: $domconfig{'selfenrollment'} = {};
21588: }
21589: }
21590: %toplevel = (
21591: admin => 'Configuration Rights',
21592: default => 'Default settings',
21593: validation => 'Validation of self-enrollment requests',
21594: );
1.233 raeburn 21595: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21596:
21597: if (ref($ordered{'admin'}) eq 'ARRAY') {
21598: foreach my $item (@{$ordered{'admin'}}) {
21599: foreach my $type (@types) {
21600: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21601: $selfenrollhash{'admin'}{$type}{$item} = 1;
21602: } else {
21603: $selfenrollhash{'admin'}{$type}{$item} = 0;
21604: }
21605: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21606: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21607: if ($selfenrollhash{'admin'}{$type}{$item} ne
21608: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21609: push(@{$changes{'admin'}{$type}},$item);
21610: }
21611: } else {
21612: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21613: push(@{$changes{'admin'}{$type}},$item);
21614: }
21615: }
21616: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21617: push(@{$changes{'admin'}{$type}},$item);
21618: }
21619: }
21620: }
21621: }
21622:
21623: foreach my $item (@{$ordered{'default'}}) {
21624: foreach my $type (@types) {
21625: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21626: if ($item eq 'types') {
21627: unless (($value eq 'all') || ($value eq 'dom')) {
21628: $value = '';
21629: }
21630: } elsif ($item eq 'registered') {
21631: unless ($value eq '1') {
21632: $value = 0;
21633: }
21634: } elsif ($item eq 'approval') {
21635: unless ($value =~ /^[012]$/) {
21636: $value = 0;
21637: }
21638: } else {
21639: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21640: $value = 'none';
21641: }
21642: }
21643: $selfenrollhash{'default'}{$type}{$item} = $value;
21644: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21645: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21646: if ($selfenrollhash{'default'}{$type}{$item} ne
21647: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21648: push(@{$changes{'default'}{$type}},$item);
21649: }
21650: } else {
21651: push(@{$changes{'default'}{$type}},$item);
21652: }
21653: } else {
21654: push(@{$changes{'default'}{$type}},$item);
21655: }
21656: if ($item eq 'limit') {
21657: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21658: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21659: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21660: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21661: }
21662: } else {
21663: $selfenrollhash{'default'}{$type}{'cap'} = '';
21664: }
21665: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21666: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21667: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21668: push(@{$changes{'default'}{$type}},'cap');
21669: }
21670: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21671: push(@{$changes{'default'}{$type}},'cap');
21672: }
21673: }
21674: }
21675: }
21676:
21677: foreach my $item (@{$itemsref}) {
21678: if ($item eq 'fields') {
21679: my @changed;
21680: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21681: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21682: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21683: }
21684: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21685: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21686: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21687: $domconfig{'selfenrollment'}{'validation'}{$item});
21688: } else {
21689: @changed = @{$selfenrollhash{'validation'}{$item}};
21690: }
21691: } else {
21692: @changed = @{$selfenrollhash{'validation'}{$item}};
21693: }
21694: if (@changed) {
21695: if ($selfenrollhash{'validation'}{$item}) {
21696: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21697: } else {
21698: $changes{'validation'}{$item} = &mt('None');
21699: }
21700: }
21701: } else {
21702: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21703: if ($item eq 'markup') {
21704: if ($env{'form.selfenroll_validation_'.$item}) {
21705: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21706: }
21707: }
21708: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21709: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21710: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21711: }
21712: }
21713: }
21714: }
21715:
21716: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21717: $dom);
21718: if ($putresult eq 'ok') {
21719: if (keys(%changes) > 0) {
21720: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21721: $resulttext = &mt('Changes made:').'<ul>';
21722: foreach my $key ('admin','default','validation') {
21723: if (ref($changes{$key}) eq 'HASH') {
21724: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
21725: if ($key eq 'validation') {
21726: foreach my $item (@{$itemsref}) {
21727: if (exists($changes{$key}{$item})) {
21728: if ($item eq 'markup') {
21729: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21730: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
21731: } else {
21732: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21733: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
21734: }
21735: }
21736: }
21737: } else {
21738: foreach my $type (@types) {
21739: if ($type eq 'community') {
21740: $roles{'1'} = &mt('Community personnel');
21741: } else {
21742: $roles{'1'} = &mt('Course personnel');
21743: }
21744: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 21745: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21746: if ($key eq 'admin') {
21747: my @mgrdc = ();
21748: if (ref($ordered{$key}) eq 'ARRAY') {
21749: foreach my $item (@{$ordered{'admin'}}) {
21750: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21751: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
21752: push(@mgrdc,$item);
21753: }
21754: }
21755: }
21756: if (@mgrdc) {
21757: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
21758: } else {
21759: delete($domdefaults{$type.'selfenrolladmdc'});
21760: }
21761: }
21762: } else {
21763: if (ref($ordered{$key}) eq 'ARRAY') {
21764: foreach my $item (@{$ordered{$key}}) {
21765: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21766: $domdefaults{$type.'selfenroll'.$item} =
21767: $selfenrollhash{$key}{$type}{$item};
21768: }
21769: }
21770: }
21771: }
21772: }
1.231 raeburn 21773: $resulttext .= '<li>'.$titles{$type}.'<ul>';
21774: foreach my $item (@{$ordered{$key}}) {
21775: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21776: $resulttext .= '<li>';
21777: if ($key eq 'admin') {
21778: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
21779: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
21780: } else {
21781: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
21782: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
21783: }
21784: $resulttext .= '</li>';
21785: }
21786: }
21787: $resulttext .= '</ul></li>';
21788: }
21789: }
21790: $resulttext .= '</ul></li>';
21791: }
21792: }
1.305 raeburn 21793: }
21794: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
21795: my $cachetime = 24*60*60;
21796: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21797: if (ref($lastactref) eq 'HASH') {
21798: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 21799: }
1.231 raeburn 21800: }
21801: $resulttext .= '</ul>';
21802: } else {
21803: $resulttext = &mt('No changes made to self-enrollment settings');
21804: }
21805: } else {
21806: $resulttext = '<span class="LC_error">'.
21807: &mt('An error occurred: [_1]',$putresult).'</span>';
21808: }
21809: return $resulttext;
21810: }
21811:
1.373 raeburn 21812: sub modify_wafproxy {
21813: my ($dom,$action,$lastactref,%domconfig) = @_;
21814: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 21815: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
21816: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 21817: foreach my $server (sort(keys(%servers))) {
21818: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21819: if ($serverhome eq $server) {
21820: my $serverdom = &Apache::lonnet::host_domain($server);
21821: if ($serverdom eq $dom) {
21822: $canset{$server} = 1;
21823: }
21824: }
21825: }
1.381 raeburn 21826: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
21827: %{$values{$dom}} = ();
21828: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
21829: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
21830: }
1.388 raeburn 21831: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
21832: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
21833: }
1.382 raeburn 21834: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 21835: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
21836: }
21837: }
1.373 raeburn 21838: my $output;
21839: if (keys(%canset)) {
21840: %{$wafproxy{'alias'}} = ();
1.388 raeburn 21841: %{$wafproxy{'saml'}} = ();
1.373 raeburn 21842: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 21843: if ($env{'form.wafproxy_'.$dom}) {
21844: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
21845: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
21846: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
21847: $changes{'alias'} = 1;
21848: }
1.388 raeburn 21849: if ($env{'form.wafproxy_alias_saml_'.$key}) {
21850: $wafproxy{'saml'}{$key} = 1;
21851: }
21852: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
21853: $changes{'saml'} = 1;
21854: }
1.381 raeburn 21855: } else {
21856: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 21857: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 21858: if ($curralias{$key}) {
21859: $changes{'alias'} = 1;
21860: }
1.388 raeburn 21861: if ($currsaml{$key}) {
21862: $changes{'saml'} = 1;
21863: }
1.373 raeburn 21864: }
21865: if ($wafproxy{'alias'}{$key} eq '') {
21866: if ($curralias{$key}) {
21867: $expirecache{$key} = 1;
21868: }
21869: delete($wafproxy{'alias'}{$key});
21870: }
1.388 raeburn 21871: if ($wafproxy{'saml'}{$key} eq '') {
21872: if ($currsaml{$key}) {
21873: $expiresaml{$key} = 1;
21874: }
21875: delete($wafproxy{'saml'}{$key});
21876: }
1.373 raeburn 21877: }
21878: unless (keys(%{$wafproxy{'alias'}})) {
21879: delete($wafproxy{'alias'});
21880: }
1.388 raeburn 21881: unless (keys(%{$wafproxy{'saml'}})) {
21882: delete($wafproxy{'saml'});
21883: }
21884: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 21885: my %warn = (
21886: trusted => 'trusted IP range(s)',
1.381 raeburn 21887: vpnint => 'internal IP range(s) for VPN sessions(s)',
21888: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 21889: );
1.382 raeburn 21890: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21891: my $possible = $env{'form.wafproxy_'.$item};
21892: $possible =~ s/^\s+|\s+$//g;
21893: if ($possible ne '') {
1.381 raeburn 21894: if ($item eq 'remoteip') {
21895: if ($possible =~ /^[mhn]$/) {
21896: $wafproxy{$item} = $possible;
21897: }
21898: } elsif ($item eq 'ipheader') {
21899: if ($wafproxy{'remoteip'} eq 'h') {
21900: $wafproxy{$item} = $possible;
21901: }
1.382 raeburn 21902: } elsif ($item eq 'sslopt') {
21903: if ($possible =~ /^0|1$/) {
21904: $wafproxy{$item} = $possible;
21905: }
1.373 raeburn 21906: } else {
21907: my (@ok,$count);
1.381 raeburn 21908: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
21909: unless ($env{'form.wafproxy_vpnaccess'}) {
21910: $possible = '';
21911: }
21912: } elsif ($item eq 'trusted') {
21913: unless ($wafproxy{'remoteip'} eq 'h') {
21914: $possible = '';
21915: }
21916: }
21917: unless ($possible eq '') {
21918: $possible =~ s/[\r\n]+/\s/g;
21919: $possible =~ s/\s*-\s*/-/g;
21920: $possible =~ s/\s+/,/g;
1.393 raeburn 21921: $possible =~ s/,+/,/g;
1.381 raeburn 21922: }
1.373 raeburn 21923: $count = 0;
1.381 raeburn 21924: if ($possible ne '') {
1.373 raeburn 21925: foreach my $poss (split(/\,/,$possible)) {
21926: $count ++;
1.393 raeburn 21927: $poss = &validate_ip_pattern($poss);
21928: if ($poss ne '') {
1.373 raeburn 21929: push(@ok,$poss);
21930: }
21931: }
21932: my $diff = $count - scalar(@ok);
21933: if ($diff) {
21934: push(@warnings,'<li>'.
21935: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
21936: $diff,$warn{$item}).
21937: '</li>');
21938: }
1.393 raeburn 21939: if (@ok) {
21940: my @cidr_list;
21941: foreach my $item (@ok) {
21942: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
21943: }
21944: $wafproxy{$item} = join(',',@cidr_list);
21945: }
1.373 raeburn 21946: }
21947: }
1.381 raeburn 21948: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 21949: $changes{$item} = 1;
21950: }
1.381 raeburn 21951: } elsif ($currvalue{$item}) {
21952: $changes{$item} = 1;
1.425 raeburn 21953: }
1.381 raeburn 21954: }
21955: } else {
21956: if (keys(%curralias)) {
21957: $changes{'alias'} = 1;
1.388 raeburn 21958: }
21959: if (keys(%currsaml)) {
21960: $changes{'saml'} = 1;
1.425 raeburn 21961: }
1.381 raeburn 21962: if (keys(%currvalue)) {
21963: foreach my $key (keys(%currvalue)) {
21964: $changes{$key} = 1;
1.373 raeburn 21965: }
21966: }
21967: }
21968: if (keys(%changes)) {
21969: my %defaultshash = (
21970: wafproxy => \%wafproxy,
1.425 raeburn 21971: );
1.373 raeburn 21972: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21973: $dom);
21974: if ($putresult eq 'ok') {
21975: my $cachetime = 24*60*60;
21976: my (%domdefaults,$updatedomdefs);
1.382 raeburn 21977: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21978: if ($changes{$item}) {
21979: unless ($updatedomdefs) {
21980: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
21981: $updatedomdefs = 1;
21982: }
21983: if ($wafproxy{$item}) {
21984: $domdefaults{'waf_'.$item} = $wafproxy{$item};
21985: } elsif (exists($domdefaults{'waf_'.$item})) {
21986: delete($domdefaults{'waf_'.$item});
1.425 raeburn 21987: }
1.373 raeburn 21988: }
21989: }
21990: if ($updatedomdefs) {
21991: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21992: if (ref($lastactref) eq 'HASH') {
21993: $lastactref->{'domdefaults'} = 1;
21994: }
21995: }
21996: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
21997: my %updates = %expirecache;
21998: foreach my $key (keys(%expirecache)) {
21999: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22000: }
22001: if (ref($wafproxy{'alias'}) eq 'HASH') {
22002: my $cachetime = 24*60*60;
22003: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22004: $updates{$key} = 1;
22005: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22006: $cachetime);
22007: }
22008: }
22009: if (ref($lastactref) eq 'HASH') {
22010: $lastactref->{'proxyalias'} = \%updates;
22011: }
22012: }
1.388 raeburn 22013: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22014: my %samlupdates = %expiresaml;
22015: foreach my $key (keys(%expiresaml)) {
22016: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22017: }
22018: if (ref($wafproxy{'saml'}) eq 'HASH') {
22019: my $cachetime = 24*60*60;
22020: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22021: $samlupdates{$key} = 1;
22022: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22023: $cachetime);
22024: }
22025: }
22026: if (ref($lastactref) eq 'HASH') {
22027: $lastactref->{'proxysaml'} = \%samlupdates;
22028: }
22029: }
1.373 raeburn 22030: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22031: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22032: if ($changes{$item}) {
22033: if ($item eq 'alias') {
22034: my $numaliased = 0;
22035: if (ref($wafproxy{'alias'}) eq 'HASH') {
22036: my $shown;
22037: if (keys(%{$wafproxy{'alias'}})) {
22038: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22039: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22040: &Apache::lonnet::hostname($server),
22041: $wafproxy{'alias'}{$server}).'</li>';
22042: $numaliased ++;
22043: }
22044: if ($numaliased) {
22045: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22046: '<ul>'.$shown.'</ul>').'</li>';
22047: }
22048: }
22049: }
22050: unless ($numaliased) {
22051: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22052: }
1.388 raeburn 22053: } elsif ($item eq 'saml') {
1.425 raeburn 22054: my $shown;
1.388 raeburn 22055: if (ref($wafproxy{'saml'}) eq 'HASH') {
22056: if (keys(%{$wafproxy{'saml'}})) {
22057: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22058: }
22059: }
22060: if ($shown) {
1.396 raeburn 22061: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22062: $shown).'</li>';
22063: } else {
1.396 raeburn 22064: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22065: }
1.373 raeburn 22066: } else {
1.381 raeburn 22067: if ($item eq 'remoteip') {
22068: my %ip_methods = &remoteip_methods();
22069: if ($wafproxy{$item} =~ /^[mh]$/) {
22070: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22071: $ip_methods{$wafproxy{$item}}).'</li>';
22072: } else {
22073: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22074: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22075: '</li>';
22076: } else {
22077: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22078: }
22079: }
22080: } elsif ($item eq 'ipheader') {
1.373 raeburn 22081: if ($wafproxy{$item}) {
1.381 raeburn 22082: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22083: $wafproxy{$item}).'</li>';
22084: } else {
1.381 raeburn 22085: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22086: }
22087: } elsif ($item eq 'trusted') {
22088: if ($wafproxy{$item}) {
1.381 raeburn 22089: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22090: $wafproxy{$item}).'</li>';
22091: } else {
22092: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22093: }
1.381 raeburn 22094: } elsif ($item eq 'vpnint') {
22095: if ($wafproxy{$item}) {
22096: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22097: $wafproxy{$item}).'</li>';
22098: } else {
22099: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22100: }
22101: } elsif ($item eq 'vpnext') {
1.373 raeburn 22102: if ($wafproxy{$item}) {
1.381 raeburn 22103: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22104: $wafproxy{$item}).'</li>';
22105: } else {
1.381 raeburn 22106: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22107: }
1.382 raeburn 22108: } elsif ($item eq 'sslopt') {
22109: if ($wafproxy{$item}) {
22110: $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>';
22111: } else {
22112: $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>';
22113: }
1.373 raeburn 22114: }
22115: }
22116: }
22117: }
1.420 raeburn 22118: $output .= '</ul>';
1.373 raeburn 22119: } else {
22120: $output = '<span class="LC_error">'.
22121: &mt('An error occurred: [_1]',$putresult).'</span>';
22122: }
22123: } elsif (keys(%canset)) {
22124: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22125: }
22126: if (@warnings) {
22127: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22128: join("\n",@warnings).'</ul>';
22129: }
22130: return $output;
22131: }
22132:
22133: sub validate_ip_pattern {
22134: my ($pattern) = @_;
22135: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22136: my ($start,$end) = ($1,$2);
22137: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22138: if (($start !~ m{/}) && ($end !~ m{/})) {
22139: return $start.'-'.$end;
22140: }
22141: }
22142: } elsif ($pattern ne '') {
22143: $pattern = &Net::CIDR::cidrvalidate($pattern);
22144: if ($pattern ne '') {
22145: return $pattern;
1.373 raeburn 22146: }
22147: }
1.393 raeburn 22148: return;
1.373 raeburn 22149: }
22150:
1.137 raeburn 22151: sub modify_usersessions {
1.212 raeburn 22152: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22153: my @hostingtypes = ('version','excludedomain','includedomain');
22154: my @offloadtypes = ('primary','default');
22155: my %types = (
22156: remote => \@hostingtypes,
22157: hosted => \@hostingtypes,
22158: spares => \@offloadtypes,
22159: );
22160: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22161: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22162: my (%by_ip,%by_location,@intdoms,@instdoms);
22163: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22164: my @locations = sort(keys(%by_location));
1.137 raeburn 22165: my (%defaultshash,%changes);
22166: foreach my $prefix (@prefixes) {
22167: $defaultshash{'usersessions'}{$prefix} = {};
22168: }
1.212 raeburn 22169: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22170: my $resulttext;
1.138 raeburn 22171: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22172: foreach my $prefix (@prefixes) {
1.145 raeburn 22173: next if ($prefix eq 'spares');
22174: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22175: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22176: if ($type eq 'version') {
22177: my $value = $env{'form.'.$prefix.'_'.$type};
22178: my $okvalue;
22179: if ($value ne '') {
22180: if (grep(/^\Q$value\E$/,@lcversions)) {
22181: $okvalue = $value;
22182: }
22183: }
22184: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22185: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22186: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22187: if ($inuse == 0) {
22188: $changes{$prefix}{$type} = 1;
22189: } else {
22190: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22191: $changes{$prefix}{$type} = 1;
22192: }
22193: if ($okvalue ne '') {
22194: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22195: }
22196: }
22197: } else {
22198: if (($inuse == 1) && ($okvalue ne '')) {
22199: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22200: $changes{$prefix}{$type} = 1;
22201: }
22202: }
22203: } else {
22204: if (($inuse == 1) && ($okvalue ne '')) {
22205: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22206: $changes{$prefix}{$type} = 1;
22207: }
22208: }
22209: } else {
22210: if (($inuse == 1) && ($okvalue ne '')) {
22211: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22212: $changes{$prefix}{$type} = 1;
22213: }
22214: }
22215: } else {
22216: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22217: my @okvals;
22218: foreach my $val (@vals) {
1.138 raeburn 22219: if ($val =~ /:/) {
22220: my @items = split(/:/,$val);
22221: foreach my $item (@items) {
22222: if (ref($by_location{$item}) eq 'ARRAY') {
22223: push(@okvals,$item);
22224: }
22225: }
22226: } else {
22227: if (ref($by_location{$val}) eq 'ARRAY') {
22228: push(@okvals,$val);
22229: }
1.137 raeburn 22230: }
22231: }
22232: @okvals = sort(@okvals);
22233: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22234: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22235: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22236: if ($inuse == 0) {
22237: $changes{$prefix}{$type} = 1;
22238: } else {
22239: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22240: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22241: if (@changed > 0) {
22242: $changes{$prefix}{$type} = 1;
22243: }
22244: }
22245: } else {
22246: if ($inuse == 1) {
22247: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22248: $changes{$prefix}{$type} = 1;
22249: }
22250: }
22251: } else {
22252: if ($inuse == 1) {
22253: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22254: $changes{$prefix}{$type} = 1;
22255: }
22256: }
22257: } else {
22258: if ($inuse == 1) {
22259: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22260: $changes{$prefix}{$type} = 1;
22261: }
22262: }
22263: }
22264: }
22265: }
1.145 raeburn 22266:
22267: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22268: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22269: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22270: my $savespares;
22271:
22272: foreach my $lonhost (sort(keys(%servers))) {
22273: my $serverhomeID =
22274: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22275: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22276: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22277: my %spareschg;
22278: foreach my $type (@{$types{'spares'}}) {
22279: my @okspares;
22280: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22281: foreach my $server (@checked) {
1.152 raeburn 22282: if (&Apache::lonnet::hostname($server) ne '') {
22283: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22284: unless (grep(/^\Q$server\E$/,@okspares)) {
22285: push(@okspares,$server);
22286: }
1.145 raeburn 22287: }
22288: }
22289: }
22290: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22291: my $newspare;
1.152 raeburn 22292: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22293: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22294: $newspare = $new;
22295: }
22296: }
1.152 raeburn 22297: my @spares;
22298: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22299: @spares = sort(@okspares,$newspare);
22300: } else {
22301: @spares = sort(@okspares);
22302: }
22303: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22304: if (ref($spareid{$lonhost}) eq 'HASH') {
22305: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22306: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22307: if (@diffs > 0) {
22308: $spareschg{$type} = 1;
22309: }
22310: }
22311: }
22312: }
22313: if (keys(%spareschg) > 0) {
22314: $changes{'spares'}{$lonhost} = \%spareschg;
22315: }
22316: }
1.261 raeburn 22317: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22318: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22319: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22320: my @okoffload;
22321: if (@offloadnow) {
22322: foreach my $server (@offloadnow) {
22323: if (&Apache::lonnet::hostname($server) ne '') {
22324: unless (grep(/^\Q$server\E$/,@okoffload)) {
22325: push(@okoffload,$server);
22326: }
22327: }
22328: }
22329: if (@okoffload) {
22330: foreach my $lonhost (@okoffload) {
22331: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22332: }
22333: }
22334: }
1.371 raeburn 22335: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22336: my @okoffloadoth;
22337: if (@offloadoth) {
22338: foreach my $server (@offloadoth) {
22339: if (&Apache::lonnet::hostname($server) ne '') {
22340: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22341: push(@okoffloadoth,$server);
22342: }
22343: }
22344: }
22345: if (@okoffloadoth) {
22346: foreach my $lonhost (@okoffloadoth) {
22347: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22348: }
22349: }
22350: }
1.145 raeburn 22351: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22352: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22353: if (ref($changes{'spares'}) eq 'HASH') {
22354: if (keys(%{$changes{'spares'}}) > 0) {
22355: $savespares = 1;
22356: }
22357: }
22358: } else {
22359: $savespares = 1;
22360: }
1.371 raeburn 22361: foreach my $offload ('offloadnow','offloadoth') {
22362: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22363: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22364: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22365: $changes{$offload} = 1;
22366: last;
22367: }
1.261 raeburn 22368: }
1.371 raeburn 22369: unless ($changes{$offload}) {
22370: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22371: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22372: $changes{$offload} = 1;
22373: last;
22374: }
1.261 raeburn 22375: }
22376: }
1.371 raeburn 22377: } else {
22378: if (($offload eq 'offloadnow') && (@okoffload)) {
22379: $changes{'offloadnow'} = 1;
22380: }
22381: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22382: $changes{'offloadoth'} = 1;
22383: }
1.425 raeburn 22384: }
1.371 raeburn 22385: }
22386: } else {
22387: if (@okoffload) {
1.261 raeburn 22388: $changes{'offloadnow'} = 1;
22389: }
1.371 raeburn 22390: if (@okoffloadoth) {
22391: $changes{'offloadoth'} = 1;
22392: }
1.145 raeburn 22393: }
1.147 raeburn 22394: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22395: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22396: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22397: $dom);
22398: if ($putresult eq 'ok') {
22399: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22400: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22401: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22402: }
22403: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22404: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22405: }
1.261 raeburn 22406: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22407: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22408: }
1.371 raeburn 22409: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22410: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22411: }
1.137 raeburn 22412: }
22413: my $cachetime = 24*60*60;
22414: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22415: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22416: if (ref($lastactref) eq 'HASH') {
22417: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22418: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22419: }
1.147 raeburn 22420: if (keys(%changes) > 0) {
22421: my %lt = &usersession_titles();
22422: $resulttext = &mt('Changes made:').'<ul>';
22423: foreach my $prefix (@prefixes) {
22424: if (ref($changes{$prefix}) eq 'HASH') {
22425: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22426: if ($prefix eq 'spares') {
22427: if (ref($changes{$prefix}) eq 'HASH') {
22428: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22429: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22430: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22431: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22432: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22433: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22434: foreach my $type (@{$types{$prefix}}) {
22435: if ($changes{$prefix}{$lonhost}{$type}) {
22436: my $offloadto = &mt('None');
22437: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22438: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22439: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22440: }
1.145 raeburn 22441: }
1.147 raeburn 22442: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22443: }
1.137 raeburn 22444: }
22445: }
1.147 raeburn 22446: $resulttext .= '</li>';
1.137 raeburn 22447: }
22448: }
1.147 raeburn 22449: } else {
22450: foreach my $type (@{$types{$prefix}}) {
22451: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22452: my ($newvalue,$notinuse);
1.147 raeburn 22453: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22454: if (ref($defaultshash{'usersessions'}{$prefix})) {
22455: if ($type eq 'version') {
22456: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22457: } else {
22458: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22459: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22460: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22461: }
22462: } else {
22463: $notinuse = 1;
1.147 raeburn 22464: }
1.145 raeburn 22465: }
22466: }
22467: }
1.147 raeburn 22468: if ($newvalue eq '') {
22469: if ($type eq 'version') {
22470: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22471: } elsif ($notinuse) {
22472: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22473: } else {
22474: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22475: }
1.145 raeburn 22476: } else {
1.147 raeburn 22477: if ($type eq 'version') {
1.344 raeburn 22478: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22479: }
22480: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22481: }
1.137 raeburn 22482: }
22483: }
22484: }
1.147 raeburn 22485: $resulttext .= '</ul>';
1.137 raeburn 22486: }
22487: }
1.261 raeburn 22488: if ($changes{'offloadnow'}) {
22489: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22490: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22491: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22492: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22493: $resulttext .= '<li>'.$lonhost.'</li>';
22494: }
22495: $resulttext .= '</ul>';
22496: } else {
1.371 raeburn 22497: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22498: }
22499: } else {
22500: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22501: }
22502: }
22503: if ($changes{'offloadoth'}) {
22504: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22505: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22506: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22507: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22508: $resulttext .= '<li>'.$lonhost.'</li>';
22509: }
22510: $resulttext .= '</ul>';
22511: } else {
22512: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22513: }
22514: } else {
1.371 raeburn 22515: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22516: }
22517: }
1.147 raeburn 22518: $resulttext .= '</ul>';
22519: } else {
22520: $resulttext = $nochgmsg;
1.137 raeburn 22521: }
22522: } else {
22523: $resulttext = '<span class="LC_error">'.
22524: &mt('An error occurred: [_1]',$putresult).'</span>';
22525: }
22526: } else {
1.147 raeburn 22527: $resulttext = $nochgmsg;
1.137 raeburn 22528: }
22529: return $resulttext;
22530: }
22531:
1.275 raeburn 22532: sub modify_ssl {
22533: my ($dom,$lastactref,%domconfig) = @_;
22534: my (%by_ip,%by_location,@intdoms,@instdoms);
22535: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22536: my @locations = sort(keys(%by_location));
22537: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22538: my (%defaultshash,%changes);
22539: my $action = 'ssl';
1.293 raeburn 22540: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22541: foreach my $prefix (@prefixes) {
22542: $defaultshash{$action}{$prefix} = {};
22543: }
22544: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22545: my $resulttext;
22546: my %iphost = &Apache::lonnet::get_iphost();
22547: my @reptypes = ('certreq','nocertreq');
22548: my @connecttypes = ('dom','intdom','other');
22549: my %types = (
1.293 raeburn 22550: connto => \@connecttypes,
22551: connfrom => \@connecttypes,
22552: replication => \@reptypes,
1.275 raeburn 22553: );
22554: foreach my $prefix (sort(keys(%types))) {
22555: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22556: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22557: my $value = 'yes';
22558: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22559: $value = $env{'form.'.$prefix.'_'.$type};
22560: }
1.335 raeburn 22561: if (ref($domconfig{$action}) eq 'HASH') {
22562: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22563: if ($domconfig{$action}{$prefix}{$type} ne '') {
22564: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22565: $changes{$prefix}{$type} = 1;
22566: }
22567: $defaultshash{$action}{$prefix}{$type} = $value;
22568: } else {
22569: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22570: $changes{$prefix}{$type} = 1;
22571: }
22572: } else {
22573: $defaultshash{$action}{$prefix}{$type} = $value;
22574: $changes{$prefix}{$type} = 1;
22575: }
22576: } else {
22577: $defaultshash{$action}{$prefix}{$type} = $value;
22578: $changes{$prefix}{$type} = 1;
22579: }
22580: if (($type eq 'dom') && (keys(%servers) == 1)) {
22581: delete($changes{$prefix}{$type});
22582: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22583: delete($changes{$prefix}{$type});
22584: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22585: delete($changes{$prefix}{$type});
22586: }
22587: } elsif ($prefix eq 'replication') {
22588: if (@locations > 0) {
22589: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22590: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22591: my @okvals;
22592: foreach my $val (@vals) {
22593: if ($val =~ /:/) {
22594: my @items = split(/:/,$val);
22595: foreach my $item (@items) {
22596: if (ref($by_location{$item}) eq 'ARRAY') {
22597: push(@okvals,$item);
22598: }
22599: }
22600: } else {
22601: if (ref($by_location{$val}) eq 'ARRAY') {
22602: push(@okvals,$val);
22603: }
22604: }
22605: }
22606: @okvals = sort(@okvals);
22607: if (ref($domconfig{$action}) eq 'HASH') {
22608: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22609: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22610: if ($inuse == 0) {
22611: $changes{$prefix}{$type} = 1;
22612: } else {
22613: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22614: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22615: if (@changed > 0) {
22616: $changes{$prefix}{$type} = 1;
22617: }
22618: }
22619: } else {
22620: if ($inuse == 1) {
22621: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22622: $changes{$prefix}{$type} = 1;
22623: }
22624: }
22625: } else {
22626: if ($inuse == 1) {
22627: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22628: $changes{$prefix}{$type} = 1;
22629: }
22630: }
22631: } else {
22632: if ($inuse == 1) {
22633: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22634: $changes{$prefix}{$type} = 1;
22635: }
22636: }
22637: }
22638: }
22639: }
22640: }
1.336 raeburn 22641: if (keys(%changes)) {
22642: foreach my $prefix (keys(%changes)) {
22643: if (ref($changes{$prefix}) eq 'HASH') {
22644: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22645: delete($changes{$prefix});
22646: }
22647: } else {
22648: delete($changes{$prefix});
22649: }
22650: }
22651: }
1.275 raeburn 22652: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22653: if (keys(%changes) > 0) {
22654: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22655: $dom);
22656: if ($putresult eq 'ok') {
22657: if (ref($defaultshash{$action}) eq 'HASH') {
22658: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22659: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22660: }
1.293 raeburn 22661: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22662: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22663: }
22664: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22665: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22666: }
22667: }
22668: my $cachetime = 24*60*60;
22669: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22670: if (ref($lastactref) eq 'HASH') {
22671: $lastactref->{'domdefaults'} = 1;
22672: }
22673: if (keys(%changes) > 0) {
22674: my %titles = &ssl_titles();
22675: $resulttext = &mt('Changes made:').'<ul>';
22676: foreach my $prefix (@prefixes) {
22677: if (ref($changes{$prefix}) eq 'HASH') {
22678: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22679: foreach my $type (@{$types{$prefix}}) {
22680: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22681: my ($newvalue,$notinuse);
1.275 raeburn 22682: if (ref($defaultshash{$action}) eq 'HASH') {
22683: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22684: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22685: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22686: } else {
22687: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22688: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22689: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22690: }
22691: } else {
22692: $notinuse = 1;
1.275 raeburn 22693: }
22694: }
22695: }
1.344 raeburn 22696: if ($notinuse) {
22697: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22698: } elsif ($newvalue eq '') {
1.275 raeburn 22699: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22700: } else {
22701: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22702: }
22703: }
22704: }
22705: }
22706: $resulttext .= '</ul>';
22707: }
22708: }
22709: } else {
22710: $resulttext = $nochgmsg;
22711: }
22712: } else {
22713: $resulttext = '<span class="LC_error">'.
22714: &mt('An error occurred: [_1]',$putresult).'</span>';
22715: }
22716: } else {
22717: $resulttext = $nochgmsg;
22718: }
22719: return $resulttext;
22720: }
22721:
1.279 raeburn 22722: sub modify_trust {
22723: my ($dom,$lastactref,%domconfig) = @_;
22724: my (%by_ip,%by_location,@intdoms,@instdoms);
22725: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22726: my @locations = sort(keys(%by_location));
22727: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
22728: my @types = ('exc','inc');
22729: my (%defaultshash,%changes);
22730: foreach my $prefix (@prefixes) {
22731: $defaultshash{'trust'}{$prefix} = {};
22732: }
22733: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22734: my $resulttext;
22735: foreach my $prefix (@prefixes) {
22736: foreach my $type (@types) {
22737: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22738: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22739: my @okvals;
22740: foreach my $val (@vals) {
22741: if ($val =~ /:/) {
22742: my @items = split(/:/,$val);
22743: foreach my $item (@items) {
22744: if (ref($by_location{$item}) eq 'ARRAY') {
22745: push(@okvals,$item);
22746: }
22747: }
22748: } else {
22749: if (ref($by_location{$val}) eq 'ARRAY') {
22750: push(@okvals,$val);
22751: }
22752: }
22753: }
22754: @okvals = sort(@okvals);
22755: if (ref($domconfig{'trust'}) eq 'HASH') {
22756: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
22757: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22758: if ($inuse == 0) {
22759: $changes{$prefix}{$type} = 1;
22760: } else {
22761: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22762: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
22763: if (@changed > 0) {
22764: $changes{$prefix}{$type} = 1;
22765: }
22766: }
22767: } else {
22768: if ($inuse == 1) {
22769: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22770: $changes{$prefix}{$type} = 1;
22771: }
22772: }
22773: } else {
22774: if ($inuse == 1) {
22775: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22776: $changes{$prefix}{$type} = 1;
22777: }
22778: }
22779: } else {
22780: if ($inuse == 1) {
22781: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22782: $changes{$prefix}{$type} = 1;
22783: }
22784: }
22785: }
22786: }
22787: my $nochgmsg = &mt('No changes made to trust settings.');
22788: if (keys(%changes) > 0) {
22789: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22790: $dom);
22791: if ($putresult eq 'ok') {
22792: if (ref($defaultshash{'trust'}) eq 'HASH') {
22793: foreach my $prefix (@prefixes) {
22794: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
22795: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
22796: }
22797: }
22798: }
22799: my $cachetime = 24*60*60;
22800: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 22801: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 22802: if (ref($lastactref) eq 'HASH') {
22803: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 22804: $lastactref->{'trust'} = 1;
1.279 raeburn 22805: }
22806: if (keys(%changes) > 0) {
22807: my %lt = &trust_titles();
22808: $resulttext = &mt('Changes made:').'<ul>';
22809: foreach my $prefix (@prefixes) {
22810: if (ref($changes{$prefix}) eq 'HASH') {
22811: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22812: foreach my $type (@types) {
22813: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22814: my ($newvalue,$notinuse);
1.279 raeburn 22815: if (ref($defaultshash{'trust'}) eq 'HASH') {
22816: if (ref($defaultshash{'trust'}{$prefix})) {
22817: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22818: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
22819: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
22820: }
1.344 raeburn 22821: } else {
22822: $notinuse = 1;
1.279 raeburn 22823: }
22824: }
22825: }
1.344 raeburn 22826: if ($notinuse) {
22827: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
22828: } elsif ($newvalue eq '') {
1.279 raeburn 22829: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22830: } else {
22831: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
22832: }
22833: }
22834: }
22835: $resulttext .= '</ul>';
22836: }
22837: }
22838: $resulttext .= '</ul>';
22839: } else {
22840: $resulttext = $nochgmsg;
22841: }
22842: } else {
22843: $resulttext = '<span class="LC_error">'.
22844: &mt('An error occurred: [_1]',$putresult).'</span>';
22845: }
22846: } else {
22847: $resulttext = $nochgmsg;
22848: }
22849: return $resulttext;
22850: }
22851:
1.150 raeburn 22852: sub modify_loadbalancing {
22853: my ($dom,%domconfig) = @_;
22854: my $primary_id = &Apache::lonnet::domain($dom,'primary');
22855: my $intdom = &Apache::lonnet::internet_dom($primary_id);
22856: my ($othertitle,$usertypes,$types) =
22857: &Apache::loncommon::sorted_inst_types($dom);
22858: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 22859: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 22860: my @sparestypes = ('primary','default');
22861: my %typetitles = &sparestype_titles();
22862: my $resulttext;
1.342 raeburn 22863: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 22864: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22865: %existing = %{$domconfig{'loadbalancing'}};
22866: }
22867: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 22868: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 22869: my ($saveloadbalancing,%defaultshash,%changes);
22870: my ($alltypes,$othertypes,$titles) =
22871: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
22872: my %ruletitles = &offloadtype_text();
22873: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
22874: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
22875: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
22876: if ($balancer eq '') {
22877: next;
22878: }
1.210 raeburn 22879: if (!exists($servers{$balancer})) {
1.171 raeburn 22880: if (exists($currbalancer{$balancer})) {
22881: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 22882: }
1.171 raeburn 22883: next;
22884: }
22885: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
22886: push(@{$changes{'delete'}},$balancer);
22887: next;
22888: }
22889: if (!exists($currbalancer{$balancer})) {
22890: push(@{$changes{'add'}},$balancer);
22891: }
22892: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
22893: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
22894: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
22895: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22896: $saveloadbalancing = 1;
22897: }
22898: foreach my $sparetype (@sparestypes) {
22899: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
22900: my @offloadto;
22901: foreach my $target (@targets) {
22902: if (($servers{$target}) && ($target ne $balancer)) {
22903: if ($sparetype eq 'default') {
22904: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
22905: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 22906: }
22907: }
1.171 raeburn 22908: unless(grep(/^\Q$target\E$/,@offloadto)) {
22909: push(@offloadto,$target);
22910: }
1.150 raeburn 22911: }
22912: }
1.284 raeburn 22913: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
22914: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
22915: push(@offloadto,$balancer);
22916: }
22917: }
22918: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 22919: }
1.342 raeburn 22920: if ($env{'form.loadbalancing_cookie_'.$i}) {
22921: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 22922: if (exists($currbalancer{$balancer})) {
1.342 raeburn 22923: unless ($currcookies{$balancer}) {
22924: $changes{'curr'}{$balancer}{'cookie'} = 1;
22925: }
22926: }
22927: } elsif (exists($currbalancer{$balancer})) {
22928: if ($currcookies{$balancer}) {
22929: $changes{'curr'}{$balancer}{'cookie'} = 1;
22930: }
22931: }
1.171 raeburn 22932: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 22933: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22934: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
22935: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 22936: if (@targetdiffs > 0) {
1.171 raeburn 22937: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22938: }
1.171 raeburn 22939: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22940: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22941: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22942: }
22943: }
22944: }
22945: } else {
1.171 raeburn 22946: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 22947: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22948: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22949: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22950: $changes{'curr'}{$balancer}{'targets'} = 1;
22951: }
1.150 raeburn 22952: }
22953: }
1.210 raeburn 22954: }
1.150 raeburn 22955: }
22956: my $ishomedom;
1.171 raeburn 22957: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
22958: $ishomedom = 1;
1.150 raeburn 22959: }
22960: if (ref($alltypes) eq 'ARRAY') {
22961: foreach my $type (@{$alltypes}) {
22962: my $rule;
1.210 raeburn 22963: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 22964: (!$ishomedom)) {
1.171 raeburn 22965: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
22966: }
22967: if ($rule eq 'specific') {
1.255 raeburn 22968: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 22969: if (exists($servers{$specifiedhost})) {
1.255 raeburn 22970: $rule = $specifiedhost;
22971: }
1.150 raeburn 22972: }
1.171 raeburn 22973: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
22974: if (ref($currrules{$balancer}) eq 'HASH') {
22975: if ($rule ne $currrules{$balancer}{$type}) {
22976: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22977: }
22978: } elsif ($rule ne '') {
1.171 raeburn 22979: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22980: }
22981: }
22982: }
1.171 raeburn 22983: }
22984: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
22985: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
22986: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
22987: $defaultshash{'loadbalancing'} = {};
22988: }
22989: my $putresult = &Apache::lonnet::put_dom('configuration',
22990: \%defaultshash,$dom);
22991: if ($putresult eq 'ok') {
22992: if (keys(%changes) > 0) {
1.252 raeburn 22993: my %toupdate;
1.171 raeburn 22994: if (ref($changes{'delete'}) eq 'ARRAY') {
22995: foreach my $balancer (sort(@{$changes{'delete'}})) {
22996: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 22997: $toupdate{$balancer} = 1;
1.150 raeburn 22998: }
1.171 raeburn 22999: }
23000: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23001: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23002: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23003: $toupdate{$balancer} = 1;
1.171 raeburn 23004: }
23005: }
23006: if (ref($changes{'curr'}) eq 'HASH') {
23007: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23008: $toupdate{$balancer} = 1;
1.171 raeburn 23009: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23010: if ($changes{'curr'}{$balancer}{'targets'}) {
23011: my %offloadstr;
23012: foreach my $sparetype (@sparestypes) {
23013: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23014: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23015: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23016: }
23017: }
1.150 raeburn 23018: }
1.171 raeburn 23019: if (keys(%offloadstr) == 0) {
23020: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23021: } else {
1.171 raeburn 23022: my $showoffload;
23023: foreach my $sparetype (@sparestypes) {
23024: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23025: if (defined($offloadstr{$sparetype})) {
23026: $showoffload .= $offloadstr{$sparetype};
23027: } else {
23028: $showoffload .= &mt('None');
23029: }
23030: $showoffload .= (' 'x3);
23031: }
23032: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23033: }
23034: }
23035: }
1.171 raeburn 23036: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23037: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23038: foreach my $type (@{$alltypes}) {
23039: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23040: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23041: my $balancetext;
23042: if ($rule eq '') {
23043: $balancetext = $ruletitles{'default'};
1.209 raeburn 23044: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23045: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23046: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23047: foreach my $sparetype (@sparestypes) {
23048: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23049: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23050: }
23051: }
1.253 raeburn 23052: foreach my $item (@{$alltypes}) {
23053: next if ($item =~ /^_LC_ipchange/);
23054: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23055: if ($hasrule eq 'homeserver') {
23056: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23057: } else {
23058: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23059: if ($servers{$hasrule}) {
23060: $toupdate{$hasrule} = 1;
23061: }
23062: }
23063: }
23064: }
1.254 raeburn 23065: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23066: $balancetext = $ruletitles{$rule};
23067: } else {
23068: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23069: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23070: if ($receiver) {
23071: $toupdate{$receiver};
23072: }
23073: }
23074: } else {
23075: $balancetext = $ruletitles{$rule};
1.252 raeburn 23076: }
1.171 raeburn 23077: } else {
23078: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23079: }
1.210 raeburn 23080: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23081: }
23082: }
23083: }
23084: }
1.342 raeburn 23085: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23086: if ($currcookies{$balancer}) {
23087: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23088: $balancer).'</li>';
23089: } else {
23090: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23091: $balancer).'</li>';
23092: }
1.342 raeburn 23093: }
1.375 raeburn 23094: }
23095: }
23096: if (keys(%toupdate)) {
23097: my %thismachine;
23098: my $updatedhere;
23099: my $cachetime = 60*60*24;
23100: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23101: foreach my $lonhost (keys(%toupdate)) {
23102: if ($thismachine{$lonhost}) {
23103: unless ($updatedhere) {
23104: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23105: $defaultshash{'loadbalancing'},
23106: $cachetime);
23107: $updatedhere = 1;
1.252 raeburn 23108: }
1.375 raeburn 23109: } else {
23110: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23111: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23112: }
1.150 raeburn 23113: }
1.171 raeburn 23114: }
23115: if ($resulttext ne '') {
23116: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23117: } else {
23118: $resulttext = $nochgmsg;
23119: }
23120: } else {
1.171 raeburn 23121: $resulttext = $nochgmsg;
1.150 raeburn 23122: }
23123: } else {
1.171 raeburn 23124: $resulttext = '<span class="LC_error">'.
23125: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23126: }
23127: } else {
1.171 raeburn 23128: $resulttext = $nochgmsg;
1.150 raeburn 23129: }
23130: return $resulttext;
23131: }
23132:
1.48 raeburn 23133: sub recurse_check {
23134: my ($chkcats,$categories,$depth,$name) = @_;
23135: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23136: my $chg = 0;
23137: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23138: my $category = $chkcats->[$depth]{$name}[$j];
23139: my $item;
23140: if ($category eq '') {
23141: $chg ++;
23142: } else {
23143: my $deeper = $depth + 1;
23144: $item = &escape($category).':'.&escape($name).':'.$depth;
23145: if ($chg) {
23146: $categories->{$item} -= $chg;
23147: }
23148: &recurse_check($chkcats,$categories,$deeper,$category);
23149: $deeper --;
23150: }
23151: }
23152: }
23153: return;
23154: }
23155:
23156: sub recurse_cat_deletes {
23157: my ($item,$coursecategories,$deletions) = @_;
23158: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23159: my $subdepth = $depth + 1;
23160: if (ref($coursecategories) eq 'HASH') {
23161: foreach my $subitem (keys(%{$coursecategories})) {
23162: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23163: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23164: delete($coursecategories->{$subitem});
23165: $deletions->{$subitem} = 1;
23166: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23167: }
1.48 raeburn 23168: }
23169: }
23170: return;
23171: }
23172:
1.125 raeburn 23173: sub active_dc_picker {
1.191 raeburn 23174: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23175: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23176: my @domcoord = keys(%domcoords);
23177: if (keys(%currhash)) {
23178: foreach my $dc (keys(%currhash)) {
23179: unless (exists($domcoords{$dc})) {
23180: push(@domcoord,$dc);
23181: }
23182: }
23183: }
23184: @domcoord = sort(@domcoord);
1.210 raeburn 23185: my $numdcs = scalar(@domcoord);
1.191 raeburn 23186: my $rows = 0;
23187: my $table;
1.125 raeburn 23188: if ($numdcs > 1) {
1.191 raeburn 23189: $table = '<table>';
23190: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23191: my $rem = $i%($numinrow);
23192: if ($rem == 0) {
23193: if ($i > 0) {
1.191 raeburn 23194: $table .= '</tr>';
1.125 raeburn 23195: }
1.191 raeburn 23196: $table .= '<tr>';
23197: $rows ++;
1.125 raeburn 23198: }
1.191 raeburn 23199: my $check = '';
23200: if ($inputtype eq 'radio') {
23201: if (keys(%currhash) == 0) {
23202: if (!$i) {
23203: $check = ' checked="checked"';
23204: }
23205: } elsif (exists($currhash{$domcoord[$i]})) {
23206: $check = ' checked="checked"';
23207: }
23208: } else {
23209: if (exists($currhash{$domcoord[$i]})) {
23210: $check = ' checked="checked"';
1.125 raeburn 23211: }
23212: }
1.191 raeburn 23213: if ($i == @domcoord - 1) {
1.125 raeburn 23214: my $colsleft = $numinrow - $rem;
23215: if ($colsleft > 1) {
1.191 raeburn 23216: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23217: } else {
1.191 raeburn 23218: $table .= '<td class="LC_left_item">';
1.125 raeburn 23219: }
23220: } else {
1.191 raeburn 23221: $table .= '<td class="LC_left_item">';
23222: }
23223: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23224: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23225: $table .= '<span class="LC_nobreak"><label>'.
23226: '<input type="'.$inputtype.'" name="'.$name.'"'.
23227: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23228: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23229: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23230: }
1.219 raeburn 23231: $table .= '</label></span></td>';
1.191 raeburn 23232: }
23233: $table .= '</tr></table>';
23234: } elsif ($numdcs == 1) {
1.219 raeburn 23235: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23236: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23237: if ($inputtype eq 'radio') {
1.247 raeburn 23238: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23239: if ($user ne $dcname.':'.$dcdom) {
23240: $table .= ' ('.$dcname.':'.$dcdom.')';
23241: }
1.191 raeburn 23242: } else {
23243: my $check;
23244: if (exists($currhash{$domcoord[0]})) {
23245: $check = ' checked="checked"';
1.125 raeburn 23246: }
1.247 raeburn 23247: $table = '<span class="LC_nobreak"><label>'.
23248: '<input type="checkbox" name="'.$name.'" '.
23249: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23250: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23251: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23252: }
1.220 raeburn 23253: $table .= '</label></span>';
1.191 raeburn 23254: $rows ++;
1.125 raeburn 23255: }
23256: }
1.191 raeburn 23257: return ($numdcs,$table,$rows);
1.125 raeburn 23258: }
23259:
1.137 raeburn 23260: sub usersession_titles {
23261: return &Apache::lonlocal::texthash(
23262: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23263: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23264: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23265: version => 'LON-CAPA version requirement',
1.138 raeburn 23266: excludedomain => 'Allow all, but exclude specific domains',
23267: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23268: primary => 'Primary (checked first)',
1.154 raeburn 23269: default => 'Default',
1.137 raeburn 23270: );
23271: }
23272:
1.152 raeburn 23273: sub id_for_thisdom {
23274: my (%servers) = @_;
23275: my %altids;
23276: foreach my $server (keys(%servers)) {
23277: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23278: if ($serverhome ne $server) {
23279: $altids{$serverhome} = $server;
23280: }
23281: }
23282: return %altids;
23283: }
23284:
1.150 raeburn 23285: sub count_servers {
23286: my ($currbalancer,%servers) = @_;
23287: my (@spares,$numspares);
23288: foreach my $lonhost (sort(keys(%servers))) {
23289: next if ($currbalancer eq $lonhost);
23290: push(@spares,$lonhost);
23291: }
23292: if ($currbalancer) {
23293: $numspares = scalar(@spares);
23294: } else {
23295: $numspares = scalar(@spares) - 1;
23296: }
23297: return ($numspares,@spares);
23298: }
23299:
23300: sub lonbalance_targets_js {
1.171 raeburn 23301: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23302: my $select = &mt('Select');
23303: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23304: if (ref($servers) eq 'HASH') {
23305: $alltargets = join("','",sort(keys(%{$servers})));
23306: my @homedoms;
23307: foreach my $server (sort(keys(%{$servers}))) {
23308: if (&Apache::lonnet::host_domain($server) eq $dom) {
23309: push(@homedoms,'1');
23310: } else {
23311: push(@homedoms,'0');
23312: }
23313: }
23314: $allishome = join("','",@homedoms);
23315: }
23316: if (ref($types) eq 'ARRAY') {
23317: if (@{$types} > 0) {
23318: @alltypes = @{$types};
23319: }
23320: }
23321: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23322: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23323: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23324: if (ref($settings) eq 'HASH') {
23325: %existing = %{$settings};
23326: }
23327: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23328: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23329: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23330: return <<"END";
23331:
23332: <script type="text/javascript">
23333: // <![CDATA[
23334:
1.171 raeburn 23335: currBalancers = new Array('$balancers');
23336:
23337: function toggleTargets(balnum) {
23338: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23339: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23340: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23341: var prevbalancer = prevhostitem.value;
23342: var baltotal = document.getElementById('loadbalancing_total').value;
23343: prevhostitem.value = balancer;
23344: if (prevbalancer != '') {
23345: var prevIdx = currBalancers.indexOf(prevbalancer);
23346: if (prevIdx != -1) {
23347: currBalancers.splice(prevIdx,1);
23348: }
23349: }
1.150 raeburn 23350: if (balancer == '') {
1.171 raeburn 23351: hideSpares(balnum);
1.150 raeburn 23352: } else {
1.171 raeburn 23353: var currIdx = currBalancers.indexOf(balancer);
23354: if (currIdx == -1) {
23355: currBalancers.push(balancer);
23356: }
1.150 raeburn 23357: var homedoms = new Array('$allishome');
1.171 raeburn 23358: var ishomedom = homedoms[lonhostitem.selectedIndex];
23359: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23360: }
1.171 raeburn 23361: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23362: return;
23363: }
23364:
1.171 raeburn 23365: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23366: var alltargets = new Array('$alltargets');
23367: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23368: var offloadtypes = new Array('primary','default');
23369:
1.171 raeburn 23370: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23371: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23372:
1.151 raeburn 23373: for (var i=0; i<offloadtypes.length; i++) {
23374: var count = 0;
23375: for (var j=0; j<alltargets.length; j++) {
23376: if (alltargets[j] != balancer) {
1.171 raeburn 23377: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23378: item.value = alltargets[j];
23379: item.style.textAlign='left';
23380: item.style.textFace='normal';
23381: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23382: if (currBalancers.indexOf(alltargets[j]) == -1) {
23383: item.disabled = '';
23384: } else {
23385: item.disabled = 'disabled';
23386: item.checked = false;
23387: }
1.151 raeburn 23388: count ++;
23389: }
1.150 raeburn 23390: }
23391: }
1.151 raeburn 23392: for (var k=0; k<insttypes.length; k++) {
23393: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23394: if (ishomedom == 1) {
1.171 raeburn 23395: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23396: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23397: } else {
1.171 raeburn 23398: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23399: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23400: }
23401: } else {
1.171 raeburn 23402: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23403: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23404: }
1.151 raeburn 23405: if ((insttypes[k] != '_LC_external') &&
23406: ((insttypes[k] != '_LC_internetdom') ||
23407: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23408: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23409: item.options.length = 0;
23410: item.options[0] = new Option("","",true,true);
1.210 raeburn 23411: var idx = 0;
1.151 raeburn 23412: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23413: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23414: idx ++;
23415: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23416: }
23417: }
23418: }
23419: }
23420: return;
23421: }
23422:
1.171 raeburn 23423: function hideSpares(balnum) {
1.150 raeburn 23424: var alltargets = new Array('$alltargets');
23425: var insttypes = new Array('$allinsttypes');
23426: var offloadtypes = new Array('primary','default');
23427:
1.171 raeburn 23428: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23429: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23430:
23431: var total = alltargets.length - 1;
23432: for (var i=0; i<offloadtypes; i++) {
23433: for (var j=0; j<total; j++) {
1.171 raeburn 23434: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23435: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23436: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23437: }
1.150 raeburn 23438: }
23439: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23440: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23441: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23442: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23443: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23444: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23445: }
23446: }
23447: return;
23448: }
23449:
1.171 raeburn 23450: function checkOffloads(item,balnum,type) {
1.150 raeburn 23451: var alltargets = new Array('$alltargets');
23452: var offloadtypes = new Array('primary','default');
23453: if (item.checked) {
23454: var total = alltargets.length - 1;
23455: var other;
23456: if (type == offloadtypes[0]) {
1.151 raeburn 23457: other = offloadtypes[1];
1.150 raeburn 23458: } else {
1.151 raeburn 23459: other = offloadtypes[0];
1.150 raeburn 23460: }
23461: for (var i=0; i<total; i++) {
1.171 raeburn 23462: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23463: if (server == item.value) {
1.171 raeburn 23464: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23465: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23466: }
23467: }
23468: }
23469: }
23470: return;
23471: }
23472:
1.171 raeburn 23473: function singleServerToggle(balnum,type) {
23474: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23475: if (offloadtoSelIdx == 0) {
1.171 raeburn 23476: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23477: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23478:
23479: } else {
1.171 raeburn 23480: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23481: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23482: }
23483: return;
23484: }
23485:
1.171 raeburn 23486: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23487: if (type == '_LC_external') {
1.171 raeburn 23488: return;
1.150 raeburn 23489: }
1.171 raeburn 23490: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23491: for (var i=0; i<typesRules.length; i++) {
23492: if (formname.elements[typesRules[i]].checked) {
23493: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23494: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23495: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23496: } else {
1.171 raeburn 23497: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23498: }
23499: }
23500: }
23501: return;
23502: }
23503:
23504: function balancerDeleteChange(balnum) {
23505: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23506: var baltotal = document.getElementById('loadbalancing_total').value;
23507: var addtarget;
23508: var removetarget;
23509: var action = 'delete';
23510: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23511: var lonhost = hostitem.value;
23512: var currIdx = currBalancers.indexOf(lonhost);
23513: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23514: if (currIdx != -1) {
23515: currBalancers.splice(currIdx,1);
23516: }
23517: addtarget = lonhost;
23518: } else {
23519: if (currIdx == -1) {
23520: currBalancers.push(lonhost);
23521: }
23522: removetarget = lonhost;
23523: action = 'undelete';
23524: }
23525: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23526: }
23527: return;
23528: }
23529:
23530: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23531: if (baltotal > 1) {
23532: var offloadtypes = new Array('primary','default');
23533: var alltargets = new Array('$alltargets');
23534: var insttypes = new Array('$allinsttypes');
23535: for (var i=0; i<baltotal; i++) {
23536: if (i != balnum) {
23537: for (var j=0; j<offloadtypes.length; j++) {
23538: var total = alltargets.length - 1;
23539: for (var k=0; k<total; k++) {
23540: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23541: var server = serveritem.value;
23542: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23543: if (server == addtarget) {
23544: serveritem.disabled = '';
23545: }
23546: }
23547: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23548: if (server == removetarget) {
23549: serveritem.disabled = 'disabled';
23550: serveritem.checked = false;
23551: }
23552: }
23553: }
23554: }
23555: for (var j=0; j<insttypes.length; j++) {
23556: if (insttypes[j] != '_LC_external') {
23557: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23558: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23559: var currSel = singleserver.selectedIndex;
23560: var currVal = singleserver.options[currSel].value;
23561: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23562: var numoptions = singleserver.options.length;
23563: var needsnew = 1;
23564: for (var k=0; k<numoptions; k++) {
23565: if (singleserver.options[k] == addtarget) {
23566: needsnew = 0;
23567: break;
23568: }
23569: }
23570: if (needsnew == 1) {
23571: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23572: }
23573: }
23574: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23575: singleserver.options.length = 0;
23576: if ((currVal) && (currVal != removetarget)) {
23577: singleserver.options[0] = new Option("","",false,false);
23578: } else {
23579: singleserver.options[0] = new Option("","",true,true);
23580: }
23581: var idx = 0;
23582: for (var m=0; m<alltargets.length; m++) {
23583: if (currBalancers.indexOf(alltargets[m]) == -1) {
23584: idx ++;
23585: if (currVal == alltargets[m]) {
23586: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23587: } else {
23588: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23589: }
23590: }
23591: }
23592: }
23593: }
23594: }
23595: }
1.150 raeburn 23596: }
23597: }
23598: }
23599: return;
23600: }
23601:
1.152 raeburn 23602: // ]]>
23603: </script>
23604:
23605: END
23606: }
23607:
23608: sub new_spares_js {
23609: my @sparestypes = ('primary','default');
23610: my $types = join("','",@sparestypes);
23611: my $select = &mt('Select');
23612: return <<"END";
23613:
23614: <script type="text/javascript">
23615: // <![CDATA[
23616:
23617: function updateNewSpares(formname,lonhost) {
23618: var types = new Array('$types');
23619: var include = new Array();
23620: var exclude = new Array();
23621: for (var i=0; i<types.length; i++) {
23622: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23623: for (var j=0; j<spareboxes.length; j++) {
23624: if (formname.elements[spareboxes[j]].checked) {
23625: exclude.push(formname.elements[spareboxes[j]].value);
23626: } else {
23627: include.push(formname.elements[spareboxes[j]].value);
23628: }
23629: }
23630: }
23631: for (var i=0; i<types.length; i++) {
23632: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23633: var selIdx = newSpare.selectedIndex;
23634: var currnew = newSpare.options[selIdx].value;
23635: var okSpares = new Array();
23636: for (var j=0; j<newSpare.options.length; j++) {
23637: var possible = newSpare.options[j].value;
23638: if (possible != '') {
23639: if (exclude.indexOf(possible) == -1) {
23640: okSpares.push(possible);
23641: } else {
23642: if (currnew == possible) {
23643: selIdx = 0;
23644: }
23645: }
23646: }
23647: }
23648: for (var k=0; k<include.length; k++) {
23649: if (okSpares.indexOf(include[k]) == -1) {
23650: okSpares.push(include[k]);
23651: }
23652: }
23653: okSpares.sort();
23654: newSpare.options.length = 0;
23655: if (selIdx == 0) {
23656: newSpare.options[0] = new Option("$select","",true,true);
23657: } else {
23658: newSpare.options[0] = new Option("$select","",false,false);
23659: }
23660: for (var m=0; m<okSpares.length; m++) {
23661: var idx = m+1;
23662: var selThis = 0;
23663: if (selIdx != 0) {
23664: if (okSpares[m] == currnew) {
23665: selThis = 1;
23666: }
23667: }
23668: if (selThis == 1) {
23669: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23670: } else {
23671: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23672: }
23673: }
23674: }
23675: return;
23676: }
23677:
23678: function checkNewSpares(lonhost,type) {
23679: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23680: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23681: if (chosen != '') {
1.152 raeburn 23682: var othertype;
23683: var othernewSpare;
23684: if (type == 'primary') {
23685: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23686: }
23687: if (type == 'default') {
23688: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23689: }
23690: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23691: othernewSpare.selectedIndex = 0;
23692: }
23693: }
23694: return;
23695: }
23696:
23697: // ]]>
23698: </script>
23699:
23700: END
23701:
23702: }
23703:
23704: sub common_domprefs_js {
23705: return <<"END";
23706:
23707: <script type="text/javascript">
23708: // <![CDATA[
23709:
1.150 raeburn 23710: function getIndicesByName(formname,item) {
1.152 raeburn 23711: var group = new Array();
1.150 raeburn 23712: for (var i=0;i<formname.elements.length;i++) {
23713: if (formname.elements[i].name == item) {
1.152 raeburn 23714: group.push(formname.elements[i].id);
1.150 raeburn 23715: }
23716: }
1.152 raeburn 23717: return group;
1.150 raeburn 23718: }
23719:
23720: // ]]>
23721: </script>
23722:
23723: END
1.152 raeburn 23724:
1.150 raeburn 23725: }
23726:
1.165 raeburn 23727: sub recaptcha_js {
23728: my %lt = &captcha_phrases();
23729: return <<"END";
23730:
23731: <script type="text/javascript">
23732: // <![CDATA[
23733:
23734: function updateCaptcha(caller,context) {
23735: var privitem;
23736: var pubitem;
23737: var privtext;
23738: var pubtext;
1.269 raeburn 23739: var versionitem;
23740: var versiontext;
1.165 raeburn 23741: if (document.getElementById(context+'_recaptchapub')) {
23742: pubitem = document.getElementById(context+'_recaptchapub');
23743: } else {
23744: return;
23745: }
23746: if (document.getElementById(context+'_recaptchapriv')) {
23747: privitem = document.getElementById(context+'_recaptchapriv');
23748: } else {
23749: return;
23750: }
23751: if (document.getElementById(context+'_recaptchapubtxt')) {
23752: pubtext = document.getElementById(context+'_recaptchapubtxt');
23753: } else {
23754: return;
23755: }
23756: if (document.getElementById(context+'_recaptchaprivtxt')) {
23757: privtext = document.getElementById(context+'_recaptchaprivtxt');
23758: } else {
23759: return;
23760: }
1.269 raeburn 23761: if (document.getElementById(context+'_recaptchaversion')) {
23762: versionitem = document.getElementById(context+'_recaptchaversion');
23763: } else {
23764: return;
23765: }
23766: if (document.getElementById(context+'_recaptchavertxt')) {
23767: versiontext = document.getElementById(context+'_recaptchavertxt');
23768: } else {
23769: return;
23770: }
1.165 raeburn 23771: if (caller.checked) {
23772: if (caller.value == 'recaptcha') {
23773: pubitem.type = 'text';
23774: privitem.type = 'text';
23775: pubitem.size = '40';
23776: privitem.size = '40';
23777: pubtext.innerHTML = "$lt{'pub'}";
23778: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 23779: versionitem.type = 'text';
23780: versionitem.size = '3';
1.289 raeburn 23781: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 23782: } else {
23783: pubitem.type = 'hidden';
23784: privitem.type = 'hidden';
1.269 raeburn 23785: versionitem.type = 'hidden';
1.165 raeburn 23786: pubtext.innerHTML = '';
23787: privtext.innerHTML = '';
1.269 raeburn 23788: versiontext.innerHTML = '';
1.165 raeburn 23789: }
23790: }
23791: return;
23792: }
23793:
23794: // ]]>
23795: </script>
23796:
23797: END
23798:
23799: }
23800:
1.236 raeburn 23801: sub toggle_display_js {
1.192 raeburn 23802: return <<"END";
23803:
23804: <script type="text/javascript">
23805: // <![CDATA[
23806:
1.236 raeburn 23807: function toggleDisplay(domForm,caller) {
23808: if (document.getElementById(caller)) {
23809: var divitem = document.getElementById(caller);
23810: var optionsElement = domForm.coursecredits;
1.264 raeburn 23811: var checkval = 1;
23812: var dispval = 'block';
1.303 raeburn 23813: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 23814: if (caller == 'emailoptions') {
1.372 raeburn 23815: optionsElement = domForm.cancreate_email;
1.236 raeburn 23816: }
1.257 raeburn 23817: if (caller == 'studentsubmission') {
23818: optionsElement = domForm.postsubmit;
23819: }
1.264 raeburn 23820: if (caller == 'cloneinstcode') {
23821: optionsElement = domForm.canclone;
23822: checkval = 'instcode';
23823: }
1.303 raeburn 23824: if (selfcreateRegExp.test(caller)) {
23825: optionsElement = domForm.elements[caller];
23826: checkval = 'other';
23827: dispval = 'inline'
23828: }
1.236 raeburn 23829: if (optionsElement.length) {
1.192 raeburn 23830: var currval;
1.236 raeburn 23831: for (var i=0; i<optionsElement.length; i++) {
23832: if (optionsElement[i].checked) {
23833: currval = optionsElement[i].value;
1.192 raeburn 23834: }
23835: }
1.264 raeburn 23836: if (currval == checkval) {
23837: divitem.style.display = dispval;
1.192 raeburn 23838: } else {
1.236 raeburn 23839: divitem.style.display = 'none';
1.192 raeburn 23840: }
23841: }
23842: }
23843: return;
23844: }
23845:
23846: // ]]>
23847: </script>
23848:
23849: END
23850:
23851: }
23852:
1.165 raeburn 23853: sub captcha_phrases {
23854: return &Apache::lonlocal::texthash (
23855: priv => 'Private key',
23856: pub => 'Public key',
23857: original => 'original (CAPTCHA)',
23858: recaptcha => 'successor (ReCAPTCHA)',
23859: notused => 'unused',
1.289 raeburn 23860: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 23861: );
23862: }
23863:
1.205 raeburn 23864: sub devalidate_remote_domconfs {
1.212 raeburn 23865: my ($dom,$cachekeys) = @_;
23866: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 23867: my %servers = &Apache::lonnet::internet_dom_servers($dom);
23868: my %thismachine;
23869: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 23870: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 23871: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 23872: 'ipaccess','trust');
1.386 raeburn 23873: my %cache_by_lonhost;
23874: if (exists($cachekeys->{'samllanding'})) {
23875: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
23876: my %landing = %{$cachekeys->{'samllanding'}};
23877: my %domservers = &Apache::lonnet::get_servers($dom);
23878: if (keys(%domservers)) {
23879: foreach my $server (keys(%domservers)) {
23880: my @cached;
23881: next if ($thismachine{$server});
23882: if ($landing{$server}) {
23883: push(@cached,&escape('samllanding').':'.&escape($server));
23884: }
23885: if (@cached) {
23886: $cache_by_lonhost{$server} = \@cached;
23887: }
23888: }
23889: }
23890: }
23891: }
1.260 raeburn 23892: if (keys(%servers)) {
1.205 raeburn 23893: foreach my $server (keys(%servers)) {
23894: next if ($thismachine{$server});
1.212 raeburn 23895: my @cached;
23896: foreach my $name (@posscached) {
23897: if ($cachekeys->{$name}) {
1.388 raeburn 23898: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 23899: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 23900: foreach my $key (keys(%{$cachekeys->{$name}})) {
23901: push(@cached,&escape($name).':'.&escape($key));
23902: }
23903: }
23904: } else {
23905: push(@cached,&escape($name).':'.&escape($dom));
23906: }
1.212 raeburn 23907: }
23908: }
1.386 raeburn 23909: if ((exists($cache_by_lonhost{$server})) &&
23910: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
23911: push(@cached,@{$cache_by_lonhost{$server}});
23912: }
1.212 raeburn 23913: if (@cached) {
23914: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
23915: }
1.205 raeburn 23916: }
23917: }
23918: return;
23919: }
23920:
1.3 raeburn 23921: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>